@kitelev/exocortex-cli 17.17.3 → 17.18.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 +67 -0
- package/dist/index.js +297 -291
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -215,6 +215,7 @@ npx @kitelev/exocortex-cli query "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10" -
|
|
|
215
215
|
| `--template <name>` | — | Use a predefined query template |
|
|
216
216
|
| `--param <params>` | — | Template parameters (`key=value,key2=value2`) |
|
|
217
217
|
| `--strict` | off | Fail on unresolved label-form wikilinks in property paths (sets `EXOCORTEX_SPARQL_STRICT=1`) |
|
|
218
|
+
| `--batch <file>` | — | Many named queries from a JSON file over ONE graph load — see [Batch mode](#batch-mode) |
|
|
218
219
|
|
|
219
220
|
**Built-in templates:** `tasks-by-date`, `tasks-by-status`, `projects-active`, `concepts-by-domain`, `sleep-analysis`.
|
|
220
221
|
|
|
@@ -244,6 +245,72 @@ npx @kitelev/exocortex-cli query "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }" \
|
|
|
244
245
|
--format ntriples --vault ~/vault > vault.nt
|
|
245
246
|
```
|
|
246
247
|
|
|
248
|
+
#### Batch mode
|
|
249
|
+
|
|
250
|
+
`query --batch <file>` answers many queries over **one** graph load (a single `query` call pays a full load
|
|
251
|
+
every time). The file is a JSON array of entries `{"name": "...", "sparql": "..."}`; names are unique and match
|
|
252
|
+
`^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$`. Any path except a directory is accepted. `/dev/stdin` (a pipe)
|
|
253
|
+
works however the CLI is started; `<(...)` works only when the CLI runs directly (the installed
|
|
254
|
+
`exocortex-cli` bin or `node dist/index.js`) — under `npx` the descriptor is not passed on and the batch is
|
|
255
|
+
refused with `cannot be read (EBADF)`, so use `/dev/stdin` or a file there.
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
cat > batch.json <<'EOF'
|
|
259
|
+
[
|
|
260
|
+
{"name": "tasks", "sparql": "SELECT ?t WHERE { ?t exo:Instance_class ems:Task } LIMIT 5"},
|
|
261
|
+
{"name": "areas", "sparql": "SELECT ?a WHERE { ?a exo:Instance_class ems:Area }"}
|
|
262
|
+
]
|
|
263
|
+
EOF
|
|
264
|
+
npx @kitelev/exocortex-cli query --batch batch.json --vault ~/vault --no-cache
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Output — NDJSON on stdout, progress and notices on stderr:**
|
|
268
|
+
|
|
269
|
+
- one `{"type":"result","name":...}` line per entry, in the order of the file:
|
|
270
|
+
- success — `"ok":true` plus `"kind":"select"`, `"count"`, `"bindings"` (rows as `--format json` prints them)
|
|
271
|
+
or `"kind":"construct"`, `"triples"`;
|
|
272
|
+
- failure — `"ok":false`, `"error":{"type": ...}` with type `syntax`, `update-rejected`, `timeout`,
|
|
273
|
+
`execution` or `load` (the timeout answer also carries the CLI's own message);
|
|
274
|
+
- every line also carries `"durationMs"`; a successful one carries `"queryResultCacheHit"` (true / false);
|
|
275
|
+
- then one `{"type":"summary",...}` line: `queries`, `ok`, `failed`, `graphLoads` (0 or 1),
|
|
276
|
+
`queryResultCacheHits`, `loadMode`, `loadDurationMs`, `triples`, `durationMs`.
|
|
277
|
+
|
|
278
|
+
**Reading it:**
|
|
279
|
+
|
|
280
|
+
- Tell lines apart by `"type"`, never by `"name"` — an entry may be called `summary`.
|
|
281
|
+
- Split on `"\n"` only (U+2028, U+2029 and U+0085 inside values are written as JSON escapes).
|
|
282
|
+
- **No summary line ⇒ the batch did not finish** (killed, out of memory). Re-run the entries that have no
|
|
283
|
+
answer one by one (a single `query`, or a batch of one) and always put an external `timeout` over a batch.
|
|
284
|
+
- `--timeout` applies to each entry but does not interrupt a compute-bound query (bug `8fe905e9`): such a
|
|
285
|
+
query can take the whole batch down with it, where a series of single calls would lose only that query.
|
|
286
|
+
- Each line is written to the pipe before the next entry starts, so answers already printed survive a kill.
|
|
287
|
+
|
|
288
|
+
**Semantics:** an entry that fails does not stop the batch; `INSERT DATA` / `DELETE DATA` entries are refused,
|
|
289
|
+
not executed; no error quotes the content of the batch file. With the result cache on, the vault signature is
|
|
290
|
+
computed once per batch and entries are served from (and stored to) the same cache a single `query` uses;
|
|
291
|
+
under `--no-cache` no signature is computed at all. A failed write to the result cache keeps the computed
|
|
292
|
+
answer (a warning on stderr). As for a single `query`, an edit behind a directory symlink inside the vault does
|
|
293
|
+
not invalidate cached answers within the TTL (the signature does not follow links) — use `--no-cache` there.
|
|
294
|
+
If the graph cannot be loaded, every entry that needs it answers `load` (one attempt per batch).
|
|
295
|
+
|
|
296
|
+
**Exit codes:** `0` — every entry succeeded; `5` — at least one entry failed; `2` — refused before start
|
|
297
|
+
(the file is not a valid batch, is a directory or cannot be read — only the errno code is shown — or an
|
|
298
|
+
incompatible flag); `3` — no batch file, or no vault; `1` — the reader closed stdout (no further entry runs).
|
|
299
|
+
|
|
300
|
+
**Flags:** `--batch` cannot be combined with a positional query, `--template`, `--param`, `--dry-run`,
|
|
301
|
+
`--explain`, `--stats`, `--output json` or `--format csv|ntriples`. Allowed: `--vault`, `--use-cache`,
|
|
302
|
+
`--no-cache`, `--cache-ttl`, `--timeout`, `--no-optimize`, `--strict`, `--format table|json` (ignored — the
|
|
303
|
+
batch always prints NDJSON).
|
|
304
|
+
|
|
305
|
+
**`run-query --batch <file>`** — the same mode for named queries (`query__NamedQuery` assets): entries are
|
|
306
|
+
`{"name", "uid", "currentAsset"?, "params"?, "paramsIri"?}` — the context of a single `run-query <uid>`
|
|
307
|
+
moves into each entry (`params` are literals, `paramsIri` and `currentAsset` are vault paths passed as IRIs).
|
|
308
|
+
Each answer carries the same data `run-query <uid> --format json` prints (`kind` plus `rows` / `result` /
|
|
309
|
+
`triples`). Error types add `not-found` (no such query, or it has no `sparql` block) and `unset-token` (the
|
|
310
|
+
body keeps a `$parameter` the entry did not fill — a typo would otherwise match every row); errors carry the
|
|
311
|
+
type only, never a message. `--batch` cannot be combined with a positional uid, `--current-asset`, `--param`,
|
|
312
|
+
`--param-iri` or `--output json`; `run-query` with neither a uid nor `--batch` exits 2.
|
|
313
|
+
|
|
247
314
|
### index
|
|
248
315
|
|
|
249
316
|
Build or refresh the persistent triple cache used by `--use-cache` consumers. The cache lives at `<vault>/.exocortex/cache/triples.json`.
|