@maschinenlesbar.org/ckan-cli 0.0.4 → 0.0.6
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 +28 -14
- package/dist/src/cli/commands/catalogue.d.ts.map +1 -1
- package/dist/src/cli/commands/catalogue.js +11 -6
- package/dist/src/cli/commands/catalogue.js.map +1 -1
- package/dist/src/cli/commands/portal.d.ts.map +1 -1
- package/dist/src/cli/commands/portal.js +8 -1
- package/dist/src/cli/commands/portal.js.map +1 -1
- package/dist/src/cli/index.js +2 -0
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/cli/io.d.ts +17 -0
- package/dist/src/cli/io.d.ts.map +1 -1
- package/dist/src/cli/io.js +22 -0
- package/dist/src/cli/io.js.map +1 -1
- package/dist/src/cli/program.d.ts.map +1 -1
- package/dist/src/cli/program.js +24 -5
- package/dist/src/cli/program.js.map +1 -1
- package/dist/src/cli/shared.d.ts +24 -5
- package/dist/src/cli/shared.d.ts.map +1 -1
- package/dist/src/cli/shared.js +70 -7
- package/dist/src/cli/shared.js.map +1 -1
- package/dist/src/client/client.d.ts +7 -1
- package/dist/src/client/client.d.ts.map +1 -1
- package/dist/src/client/client.js +67 -18
- package/dist/src/client/client.js.map +1 -1
- package/dist/src/client/engine.d.ts +53 -2
- package/dist/src/client/engine.d.ts.map +1 -1
- package/dist/src/client/engine.js +152 -48
- package/dist/src/client/engine.js.map +1 -1
- package/dist/src/client/errors.d.ts +6 -0
- package/dist/src/client/errors.d.ts.map +1 -1
- package/dist/src/client/errors.js +23 -2
- package/dist/src/client/errors.js.map +1 -1
- package/dist/src/client/http.js +3 -3
- package/dist/src/client/http.js.map +1 -1
- package/dist/src/client/index.d.ts +2 -2
- package/dist/src/client/index.d.ts.map +1 -1
- package/dist/src/client/index.js +2 -2
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/client/portals.d.ts.map +1 -1
- package/dist/src/client/portals.js +2 -0
- package/dist/src/client/portals.js.map +1 -1
- package/dist/src/client/types.d.ts +5 -0
- package/dist/src/client/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,10 +43,12 @@ ckan search elbe --rows 5
|
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
All administrative regulations (*Verwaltungsvorschriften*), using a filter
|
|
46
|
-
query on one of Hamburg's own fields
|
|
46
|
+
query on one of Hamburg's own fields. The filter takes the **stemmed** value
|
|
47
|
+
the search index holds: Hamburg's API page writes `verwaltungsvorschriften`,
|
|
48
|
+
which also matches the *Dienstanweisungen* and returns twice as many records.
|
|
47
49
|
|
|
48
50
|
```bash
|
|
49
|
-
ckan search --fq extras_registerobject_type:
|
|
51
|
+
ckan search --fq extras_registerobject_type:verwaltungsvorschrift --rows 5
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
The result is unwrapped from CKAN's `{ help, success, result }` envelope, so you
|
|
@@ -147,14 +149,16 @@ action <name> [--param key=value …] call any CKAN action (generic)
|
|
|
147
149
|
> **Several `--fq` filters** are sent as CKAN's `fq_list`, never as a repeated
|
|
148
150
|
> `fq` key, which CKAN answers with HTTP 409.
|
|
149
151
|
|
|
150
|
-
> **Blank values are refused.** `ckan search ""`, `--fq ""
|
|
151
|
-
> exit 1 before any request, instead of silently running an unfiltered search.
|
|
152
|
+
> **Blank values are refused.** `ckan search ""`, `--fq ""`, `tags --query ""` or
|
|
153
|
+
> `action … --param q=` exit 1 before any request, instead of silently running an unfiltered search.
|
|
154
|
+
> So does a forgotten value (`--fq --rows 5`): a value of `--fq`, `--facet`,
|
|
155
|
+
> `--sort` or `tags --query` cannot start with `--`.
|
|
152
156
|
|
|
153
157
|
### Paging and list flags
|
|
154
158
|
|
|
155
159
|
| Command | Flags |
|
|
156
160
|
| --- | --- |
|
|
157
|
-
| `packages` | `--limit <n
|
|
161
|
+
| `packages` | `--limit <n>` (1 or more; omit for the whole list), `--offset <n>` |
|
|
158
162
|
| `organizations`, `groups` | `--all-fields` (full objects instead of names), `--limit <n>`, `--offset <n>` |
|
|
159
163
|
|
|
160
164
|
> **`--all-fields` lists are complete.** CKAN caps them at 25 entries
|
|
@@ -175,14 +179,18 @@ before any request is sent.
|
|
|
175
179
|
- **Mostly documents, not datasets.** Hamburg publishes what the Hamburg
|
|
176
180
|
Transparency Act (HmbTG) requires: council papers, contracts, reports,
|
|
177
181
|
regulations, geodata. Most records have `type: "document"`.
|
|
178
|
-
- **The *Informationsgegenstand*** is in `extras_registerobject_type
|
|
179
|
-
|
|
180
|
-
`
|
|
181
|
-
<https://suche.transparenz.hamburg.de/api/rest/enums
|
|
182
|
-
|
|
182
|
+
- **The *Informationsgegenstand*** is in `extras_registerobject_type`. Filter
|
|
183
|
+
it with the **stemmed** value the search index holds (`verwaltungsvorschrift`,
|
|
184
|
+
`vertrageoffinteress`, `gutacht`, `geodat`, …). Hamburg's own value list at
|
|
185
|
+
<https://suche.transparenz.hamburg.de/api/rest/enums> (Hamburg-specific, not
|
|
186
|
+
part of the CKAN Action API) gives other spellings: `vertraege_oeff_interesse`
|
|
187
|
+
matches nothing, and a full word such as `verwaltungsvorschriften` over-matches.
|
|
188
|
+
List the values that work, with their counts:
|
|
189
|
+
`ckan --compact search --rows 0 --facet extras_registerobject_type --facet-limit -1`.
|
|
190
|
+
The [Glossary](GLOSSARY.md) has the details.
|
|
183
191
|
- **Several filters work.** Hamburg's API page says only one filter can be
|
|
184
192
|
used; with `fq_list` (repeat `--fq`) they combine:
|
|
185
|
-
`ckan search --fq extras_registerobject_type:
|
|
193
|
+
`ckan search --fq extras_registerobject_type:verwaltungsvorschrift --fq organization:workflows`.
|
|
186
194
|
- **Tags are free text.** Many tags are whole keyword lists in a single string,
|
|
187
195
|
so `tags --query` matches substrings of those strings.
|
|
188
196
|
|
|
@@ -225,14 +233,20 @@ ckan package bezirk-wandsbek-drucksache-22-3573-2 | jq '.resources[] | {format,
|
|
|
225
233
|
|
|
226
234
|
| Code | Meaning |
|
|
227
235
|
| --- | --- |
|
|
228
|
-
| `0` | success (also `--help`
|
|
229
|
-
| `4` | not found (HTTP `404`)
|
|
236
|
+
| `0` | success (also `--help`, `help [command]`, `--version` and a bare `ckan`) |
|
|
237
|
+
| `4` | not found (HTTP `404`): an unknown id on `package`/`resource`/`organization`/`group`, or, on any command, no CKAN at this URL (a wrong `--base-url`, a portal that left CKAN) |
|
|
230
238
|
| `1` | any other error — bad usage, validation error (`409`), unknown action (`400`), CKAN `success:false`, network failure |
|
|
231
239
|
|
|
232
240
|
CKAN's error text is shown on stderr, e.g.
|
|
233
241
|
`Validation Error: rows: Invalid integer` or
|
|
234
242
|
`Bad request - Action name not known: …`.
|
|
235
243
|
|
|
244
|
+
> **Numbers pass through JavaScript.** The output is the parsed and re-serialised
|
|
245
|
+
> JSON, so an integer above 2⁵³ (9,007,199,254,740,992) loses its last digits and a
|
|
246
|
+
> number beyond the double range (`1e400`) prints as `null`. CKAN metadata rarely
|
|
247
|
+
> holds such numbers; for an exact copy of the raw answer, use `curl` on
|
|
248
|
+
> `<site>/api/3/action/<name>`.
|
|
249
|
+
|
|
236
250
|
## Global options
|
|
237
251
|
|
|
238
252
|
| Option | Description |
|
|
@@ -244,7 +258,7 @@ CKAN's error text is shown on stderr, e.g.
|
|
|
244
258
|
| `--portal <id>` | a known portal by id (`ckan portals`); cannot be combined with `--base-url` |
|
|
245
259
|
| `--timeout <ms>` | Per-request timeout (default `30000`; at most `2147483647`) |
|
|
246
260
|
| `--user-agent <ua>` | `User-Agent` header value |
|
|
247
|
-
| `--max-retries <n>` | Retries for transient `429`/`503` responses (default `2`) |
|
|
261
|
+
| `--max-retries <n>` | Retries for transient `429`/`503` responses (`0`–`10`, default `2`). Each retry waits the server's `Retry-After` (up to 30 s; a longer one is not retried) or else backs off linearly |
|
|
248
262
|
| `--max-response-bytes <n>` | Cap response body size in bytes (`0` = unlimited; default 100 MiB) |
|
|
249
263
|
|
|
250
264
|
## Claude Code skills
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalogue.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/catalogue.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"catalogue.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/catalogue.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAsBxC,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAwI/E"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// Commands over the catalogue: datasets, their resources, publishers, themes
|
|
2
2
|
// and tags.
|
|
3
|
-
import { action, collectNonEmpty, parseIntArg, parseNonEmpty, renderJson } from "../shared.js";
|
|
3
|
+
import { action, collectNonEmpty, parseBoundedInt, parseIntArg, parseNonEmpty, parseOptionValue, renderJson, } from "../shared.js";
|
|
4
|
+
/**
|
|
5
|
+
* commander value-parser for a list --limit: 1 or more. CKAN reads `limit=0` as
|
|
6
|
+
* "no limit" and would send the whole list; leave --limit out for that.
|
|
7
|
+
*/
|
|
8
|
+
const parseLimit = parseBoundedInt(1, Number.MAX_SAFE_INTEGER);
|
|
4
9
|
/** commander value-parser for --facet-limit: a count, or -1 for every value. */
|
|
5
10
|
function parseFacetLimit(value) {
|
|
6
11
|
return value === "-1" ? -1 : parseIntArg(value);
|
|
@@ -12,7 +17,7 @@ export function registerCatalogueCommands(program, deps) {
|
|
|
12
17
|
.argument("[query]", "full-text query, e.g. elbe or title:haushalt", parseNonEmpty)
|
|
13
18
|
.option("--rows <n>", "max results (servers cap this, usually at 1000)", parseIntArg)
|
|
14
19
|
.option("--start <n>", "offset for paging", parseIntArg)
|
|
15
|
-
.option("--sort <expr>", 'e.g. "metadata_modified desc"',
|
|
20
|
+
.option("--sort <expr>", 'e.g. "metadata_modified desc"', parseOptionValue)
|
|
16
21
|
.option("--fq <filter>", "filter query, e.g. organization:allris (repeatable; all must match)", collectNonEmpty)
|
|
17
22
|
.option("--facet <field>", "count values of a field, e.g. res_format (repeatable)", collectNonEmpty)
|
|
18
23
|
.option("--facet-limit <n>", "max values per facet (default 50; -1 = all)", parseFacetLimit)
|
|
@@ -58,7 +63,7 @@ export function registerCatalogueCommands(program, deps) {
|
|
|
58
63
|
program
|
|
59
64
|
.command("packages")
|
|
60
65
|
.description("List dataset names")
|
|
61
|
-
.option("--limit <n>", "max names",
|
|
66
|
+
.option("--limit <n>", "max names (1 or more; omit for all)", parseLimit)
|
|
62
67
|
.option("--offset <n>", "offset for paging", parseIntArg)
|
|
63
68
|
.action(action(deps, async ({ client, global, opts }) => {
|
|
64
69
|
renderJson(deps, global, await client.packageList({
|
|
@@ -70,7 +75,7 @@ export function registerCatalogueCommands(program, deps) {
|
|
|
70
75
|
.command("organizations")
|
|
71
76
|
.description("List organizations (data publishers)")
|
|
72
77
|
.option("--all-fields", "return full objects instead of names")
|
|
73
|
-
.option("--limit <n>", "max entries",
|
|
78
|
+
.option("--limit <n>", "max entries (1 or more; omit for all)", parseLimit)
|
|
74
79
|
.option("--offset <n>", "offset for paging", parseIntArg)
|
|
75
80
|
.action(action(deps, async ({ client, global, opts }) => {
|
|
76
81
|
renderJson(deps, global, await client.organizationList({
|
|
@@ -83,7 +88,7 @@ export function registerCatalogueCommands(program, deps) {
|
|
|
83
88
|
.command("groups")
|
|
84
89
|
.description("List groups (themes/categories)")
|
|
85
90
|
.option("--all-fields", "return full objects instead of names")
|
|
86
|
-
.option("--limit <n>", "max entries",
|
|
91
|
+
.option("--limit <n>", "max entries (1 or more; omit for all)", parseLimit)
|
|
87
92
|
.option("--offset <n>", "offset for paging", parseIntArg)
|
|
88
93
|
.action(action(deps, async ({ client, global, opts }) => {
|
|
89
94
|
renderJson(deps, global, await client.groupList({
|
|
@@ -95,7 +100,7 @@ export function registerCatalogueCommands(program, deps) {
|
|
|
95
100
|
program
|
|
96
101
|
.command("tags")
|
|
97
102
|
.description("List tags")
|
|
98
|
-
.option("--query <substring>", "only tags containing this substring",
|
|
103
|
+
.option("--query <substring>", "only tags containing this substring", parseOptionValue)
|
|
99
104
|
.action(action(deps, async ({ client, global, opts }) => {
|
|
100
105
|
renderJson(deps, global, await client.tagList({ query: opts["query"] }));
|
|
101
106
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../../../../src/cli/commands/catalogue.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,YAAY;AAIZ,OAAO,
|
|
1
|
+
{"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../../../../src/cli/commands/catalogue.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,YAAY;AAIZ,OAAO,EACL,MAAM,EACN,eAAe,EACf,eAAe,EACf,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE/D,gFAAgF;AAChF,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAgB,EAAE,IAAa;IACvE,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,qCAAqC,CAAC;SAClD,QAAQ,CAAC,SAAS,EAAE,8CAA8C,EAAE,aAAa,CAAC;SAClF,MAAM,CAAC,YAAY,EAAE,iDAAiD,EAAE,WAAW,CAAC;SACpF,MAAM,CAAC,aAAa,EAAE,m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C,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;QAC9C,UAAU,CACR,IAAI,EACJ,MAAM,EACN,MAAM,MAAM,CAAC,SAAS,CAAC;YACrB,UAAU,EAAE,IAAI,CAAC,WAAW,CAAwB;YACpD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAuB;YAC1C,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAuB;SAC7C,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IAEJ,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,WAAW,CAAC;SACxB,MAAM,CAAC,qBAAqB,EAAE,qCAAqC,EAAE,gBAAgB,CAAC;SACtF,MAAM,CACL,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;QAC9C,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAuB,EAAE,CAAC,CAAC,CAAC;IACjG,CAAC,CAAC,CACH,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/portal.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/portal.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAmCxC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CA+C5E"}
|
|
@@ -19,7 +19,14 @@ function collectKeyValue(value, previous = {}) {
|
|
|
19
19
|
if (Object.prototype.hasOwnProperty.call(previous, key)) {
|
|
20
20
|
throw new InvalidArgumentError(`Duplicate --param key "${key}".`);
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
// A blank value would be dropped (CKAN reads an empty parameter as unset), so
|
|
23
|
+
// `--param q=` would silently run the action unfiltered.
|
|
24
|
+
const paramValue = value.slice(eq + 1);
|
|
25
|
+
if (paramValue.trim() === "") {
|
|
26
|
+
throw new InvalidArgumentError(`Invalid --param "${value}". The value must not be blank.`);
|
|
27
|
+
}
|
|
28
|
+
// A computed key in a literal is an own data property, even for `__proto__`.
|
|
29
|
+
return { ...previous, [key]: paramValue };
|
|
23
30
|
}
|
|
24
31
|
export function registerPortalCommands(program, deps) {
|
|
25
32
|
program
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../../src/cli/commands/portal.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAG7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAsB,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAEvD,yDAAyD;AACzD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,4EAA4E;AAC5E,SAAS,eAAe,CACtB,KAAa,EACb,QAAQ,GAA2B,EAAE;IAErC,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,6EAA6E;IAC7E,4EAA4E;IAC5E,wDAAwD;IACxD,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,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
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Binary entry point. Thin shim around run(); all logic lives in run.ts/program.ts.
|
|
3
|
+
import { handleOutputErrors } from "./io.js";
|
|
3
4
|
import { run } from "./run.js";
|
|
5
|
+
handleOutputErrors();
|
|
4
6
|
const exitCode = await run(process.argv.slice(2));
|
|
5
7
|
process.exitCode = exitCode;
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AACA,oFAAoF;AAEpF,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AACA,oFAAoF;AAEpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,kBAAkB,EAAE,CAAC;AACrB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC"}
|
package/dist/src/cli/io.d.ts
CHANGED
|
@@ -11,5 +11,22 @@ export interface CliDeps {
|
|
|
11
11
|
/** Build a client from the resolved global options (injectable for tests). */
|
|
12
12
|
createClient(options: EngineOptions): CkanClient;
|
|
13
13
|
}
|
|
14
|
+
/** The two process streams, as far as `handleOutputErrors` needs them. */
|
|
15
|
+
export interface OutputStreams {
|
|
16
|
+
stdout: Pick<NodeJS.WriteStream, "on">;
|
|
17
|
+
stderr: Pick<NodeJS.WriteStream, "on">;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Handle write errors on stdout/stderr, which Node otherwise reports as an
|
|
21
|
+
* unhandled 'error' event: a raw stack trace and exit 1.
|
|
22
|
+
*
|
|
23
|
+
* A reader that stops early — `| head`, `| jq` exiting on the first match, a closed
|
|
24
|
+
* pager — closes the pipe while the CLI is still writing, and the next write fails
|
|
25
|
+
* with EPIPE. That is ordinary use, so the process exits 0 at once, quietly. Any
|
|
26
|
+
* other stdout error prints one `Output error: <message>` line to stderr and exits
|
|
27
|
+
* 1; any other stderr error exits 1 silently (there is nowhere left to report it).
|
|
28
|
+
* The bin shim installs this once, before `run()`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function handleOutputErrors(streams?: OutputStreams, exit?: (code: number) => void): void;
|
|
14
31
|
export declare const defaultIO: CliIO;
|
|
15
32
|
//# sourceMappingURL=io.d.ts.map
|
package/dist/src/cli/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../../src/cli/io.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,KAAK;IACpB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,KAAK,CAAC;IACV,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,8EAA8E;IAC9E,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,CAAC;CAClD;AAED,eAAO,MAAM,SAAS,EAAE,KAGvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../../src/cli/io.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,KAAK;IACpB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,KAAK,CAAC;IACV,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,8EAA8E;IAC9E,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,CAAC;CAClD;AAED,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IACvC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,aAAuB,EAChC,IAAI,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAmC,GAC1D,IAAI,CASN;AAED,eAAO,MAAM,SAAS,EAAE,KAGvB,CAAC"}
|
package/dist/src/cli/io.js
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
// I/O seam for the CLI. Everything the CLI writes goes through a CliIO object so
|
|
2
2
|
// tests can capture output instead of hitting the real stdout/stderr, and the
|
|
3
3
|
// environment is injected so tests never depend on the real process.env.
|
|
4
|
+
/**
|
|
5
|
+
* Handle write errors on stdout/stderr, which Node otherwise reports as an
|
|
6
|
+
* unhandled 'error' event: a raw stack trace and exit 1.
|
|
7
|
+
*
|
|
8
|
+
* A reader that stops early — `| head`, `| jq` exiting on the first match, a closed
|
|
9
|
+
* pager — closes the pipe while the CLI is still writing, and the next write fails
|
|
10
|
+
* with EPIPE. That is ordinary use, so the process exits 0 at once, quietly. Any
|
|
11
|
+
* other stdout error prints one `Output error: <message>` line to stderr and exits
|
|
12
|
+
* 1; any other stderr error exits 1 silently (there is nowhere left to report it).
|
|
13
|
+
* The bin shim installs this once, before `run()`.
|
|
14
|
+
*/
|
|
15
|
+
export function handleOutputErrors(streams = process, exit = (code) => process.exit(code)) {
|
|
16
|
+
streams.stdout.on("error", (err) => {
|
|
17
|
+
if (err.code === "EPIPE")
|
|
18
|
+
return exit(0);
|
|
19
|
+
process.stderr.write(`Output error: ${err.message}\n`);
|
|
20
|
+
exit(1);
|
|
21
|
+
});
|
|
22
|
+
streams.stderr.on("error", (err) => {
|
|
23
|
+
exit(err.code === "EPIPE" ? 0 : 1);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
4
26
|
export const defaultIO = {
|
|
5
27
|
out: (text) => process.stdout.write(text + "\n"),
|
|
6
28
|
err: (text) => process.stderr.write(text + "\n"),
|
package/dist/src/cli/io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/cli/io.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,8EAA8E;AAC9E,yEAAyE;
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/cli/io.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,8EAA8E;AAC9E,yEAAyE;AAwBzE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAO,GAAkB,OAAO,EAChC,IAAI,GAA2B,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IAE3D,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAA0B,EAAE,EAAE;QACxD,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAA0B,EAAE,EAAE;QACxD,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAU;IAC9B,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;IAChD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;CACjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/cli/program.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAgC,MAAM,WAAW,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/cli/program.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAgC,MAAM,WAAW,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA0BvC,eAAO,MAAM,OAAO,QAAgB,CAAC;AAErC,iFAAiF;AACjF,eAAO,MAAM,WAAW,EAAE,OAIzB,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,GAAE,OAAqB,GAAG,OAAO,CAuEjE"}
|
package/dist/src/cli/program.js
CHANGED
|
@@ -6,9 +6,10 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
import { Command, InvalidArgumentError, Option } from "commander";
|
|
7
7
|
import { defaultIO } from "./io.js";
|
|
8
8
|
import { CkanClient } from "../client/client.js";
|
|
9
|
-
import { DEFAULT_BASE_URL } from "../client/engine.js";
|
|
9
|
+
import { DEFAULT_BASE_URL, MAX_RETRIES } from "../client/engine.js";
|
|
10
10
|
import { MAX_TIMEOUT_MS } from "../client/http.js";
|
|
11
|
-
import {
|
|
11
|
+
import { redactUrl } from "../client/errors.js";
|
|
12
|
+
import { parseBaseUrl, parseBoundedInt, parseHeaderValue, parseIntArg, parsePortal } from "./shared.js";
|
|
12
13
|
import { registerCatalogueCommands } from "./commands/catalogue.js";
|
|
13
14
|
import { registerPortalCommands } from "./commands/portal.js";
|
|
14
15
|
/**
|
|
@@ -36,24 +37,39 @@ export const defaultDeps = {
|
|
|
36
37
|
};
|
|
37
38
|
export function buildProgram(deps = defaultDeps) {
|
|
38
39
|
const program = new Command();
|
|
40
|
+
const baseUrlDefault = deps.env["CKAN_BASE_URL"] || DEFAULT_BASE_URL;
|
|
39
41
|
program
|
|
40
42
|
.name("ckan")
|
|
41
43
|
.description("CLI for any CKAN open-data portal (Action API v3)")
|
|
42
44
|
.version(VERSION)
|
|
43
|
-
.
|
|
45
|
+
.addOption(new Option("--base-url <url>", "CKAN site URL (env CKAN_BASE_URL)")
|
|
46
|
+
.argParser(parseBaseUrl)
|
|
47
|
+
// The help shows the default without userinfo: a password in
|
|
48
|
+
// CKAN_BASE_URL must not end up in `--help` output or CI logs.
|
|
49
|
+
.default(baseUrlDefault, JSON.stringify(redactUrl(baseUrlDefault))))
|
|
44
50
|
.addOption(new Option("--portal <id>", "a known portal by id (see `ckan portals`)")
|
|
45
51
|
.argParser(parsePortal)
|
|
46
52
|
.conflicts("baseUrl"))
|
|
47
53
|
.option("--timeout <ms>", "per-request timeout in milliseconds", parseBoundedInt(0, MAX_TIMEOUT_MS))
|
|
48
|
-
.option("--user-agent <ua>", "User-Agent header value")
|
|
49
|
-
.option("--max-retries <n>", "retries for transient 429/503 responses",
|
|
54
|
+
.option("--user-agent <ua>", "User-Agent header value", parseHeaderValue)
|
|
55
|
+
.option("--max-retries <n>", "retries for transient 429/503 responses (0..10; each waits the server's Retry-After, up to 30 s)", parseBoundedInt(0, MAX_RETRIES))
|
|
50
56
|
.option("--max-response-bytes <n>", "cap response body size in bytes (0 = unlimited; default 100 MiB)", parseIntArg)
|
|
51
57
|
.option("--compact", "print JSON on a single line instead of pretty-printed")
|
|
52
58
|
.showHelpAfterError();
|
|
53
59
|
// A bare invocation (no subcommand) should print help to stdout and exit 0,
|
|
54
60
|
// matching `ckan help` / `ckan --help`. Without an explicit root action,
|
|
55
61
|
// commander writes help to stderr and exits 1 for the empty-command case.
|
|
62
|
+
// A root action turns off two things commander otherwise does for a program
|
|
63
|
+
// with subcommands, so both are restored: the implicit `help [command]`
|
|
64
|
+
// subcommand (helpCommand(true)), and the "unknown command" error — the
|
|
65
|
+
// action receives the stray operand (allowExcessArguments below) and reports
|
|
66
|
+
// it, instead of commander's "too many arguments".
|
|
67
|
+
program.helpCommand(true);
|
|
56
68
|
program.action(() => {
|
|
69
|
+
const [unknown] = program.args;
|
|
70
|
+
if (unknown !== undefined) {
|
|
71
|
+
program.error(`error: unknown command '${unknown}'`, { code: "commander.unknownCommand" });
|
|
72
|
+
}
|
|
57
73
|
program.help();
|
|
58
74
|
});
|
|
59
75
|
// commander runs value parsers on flags but not on defaults, so a base URL
|
|
@@ -72,6 +88,9 @@ export function buildProgram(deps = defaultDeps) {
|
|
|
72
88
|
});
|
|
73
89
|
registerCatalogueCommands(program, deps);
|
|
74
90
|
registerPortalCommands(program, deps);
|
|
91
|
+
// Set after the subcommands exist (they copy this setting when created), so it
|
|
92
|
+
// applies to the root only: a stray operand reaches the root action above.
|
|
93
|
+
program.allowExcessArguments(true);
|
|
75
94
|
return program;
|
|
76
95
|
}
|
|
77
96
|
//# sourceMappingURL=program.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.js","sourceRoot":"","sources":["../../../src/cli/program.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,mBAAmB;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../../../src/cli/program.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,mBAAmB;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;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,OAAO,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,CAAC,GAAG,YAAY,oBAAoB,CAAC;gBAAE,MAAM,GAAG,CAAC;YACtD,OAAO,CAAC,KAAK,CAAC,yBAAyB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,yBAAyB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzC,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtC,+EAA+E;IAC/E,2EAA2E;IAC3E,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAEnC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/src/cli/shared.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CliDeps } from "./io.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type EngineOptions } from "../client/engine.js";
|
|
3
3
|
/** commander value-parser: a non-negative integer. */
|
|
4
4
|
export declare function parseIntArg(value: string): number;
|
|
5
5
|
/**
|
|
@@ -7,7 +7,25 @@ export declare function parseIntArg(value: string): number;
|
|
|
7
7
|
* otherwise be dropped and the command would silently run unfiltered.
|
|
8
8
|
*/
|
|
9
9
|
export declare function parseNonEmpty(value: string): string;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* commander value-parser for a value that ends up in an HTTP header (`--user-agent`).
|
|
12
|
+
* Node's HTTP layer throws an opaque "Invalid character in header content" at request
|
|
13
|
+
* time for a CR/LF (or any other C0 control or DEL) and for any character above
|
|
14
|
+
* U+00FF, which surfaced as "Unexpected error". Reject those here as a usage error,
|
|
15
|
+
* along with a blank value. Tab is allowed, as in HTTP. Checked by char code so the
|
|
16
|
+
* source stays free of control bytes.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseHeaderValue(value: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* commander value-parser for a text option's value: not blank, and not another
|
|
21
|
+
* long option. commander takes the next argument as the value of an option that
|
|
22
|
+
* needs one, even when it is a flag, so a forgotten value (`search --fq --rows 5`)
|
|
23
|
+
* silently shifted the rest into the query (`fq=--rows`, `q=5`) and still exited
|
|
24
|
+
* 0. No CKAN filter, sort, facet field or tag query starts with `--`; a single `-`
|
|
25
|
+
* (a negated Solr filter, `-organization:x`) stays allowed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseOptionValue(value: string): string;
|
|
28
|
+
/** commander accumulator for a repeatable option whose values are checked by parseOptionValue. */
|
|
11
29
|
export declare function collectNonEmpty(value: string, previous?: string[]): string[];
|
|
12
30
|
/** Build a commander value-parser for a non-negative integer within [min, max]. */
|
|
13
31
|
export declare function parseBoundedInt(min: number, max: number): (value: string) => number;
|
|
@@ -34,9 +52,10 @@ export interface GlobalOptions {
|
|
|
34
52
|
/** Translate resolved global CLI options into client EngineOptions. */
|
|
35
53
|
export declare function toEngineOptions(global: GlobalOptions): EngineOptions;
|
|
36
54
|
/**
|
|
37
|
-
* Escape the
|
|
38
|
-
* ESC) but not DEL
|
|
39
|
-
*
|
|
55
|
+
* Escape the characters JSON.stringify leaves raw although a terminal acts on them.
|
|
56
|
+
* It escapes C0 (including ESC) but not DEL, the C1 range U+0080–U+009F (U+009B is
|
|
57
|
+
* the 8-bit form of CSI) or the bidi formatting characters (isBidiControl), which
|
|
58
|
+
* reorder the text that follows. The output is server data, so escape them; the
|
|
40
59
|
* result is equivalent, valid JSON (these characters only occur inside strings).
|
|
41
60
|
* Checked by char code so the source stays free of control bytes.
|
|
42
61
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/cli/shared.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/cli/shared.ts"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;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWvD;AAyBD,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAGrF;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;IAC5C,MAAM,EAAE,aAAa,CAAC;IACtB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,CAAC,GAAG,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/D,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAQvC"}
|
package/dist/src/cli/shared.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Shared helpers used across CLI command groups: option parsers, the global
|
|
2
2
|
// option resolver, and the JSON result renderer.
|
|
3
3
|
import { InvalidArgumentError } from "commander";
|
|
4
|
+
import { isBidiControl } from "../client/engine.js";
|
|
5
|
+
import { CkanError } from "../client/errors.js";
|
|
4
6
|
import { findPortal } from "../client/portals.js";
|
|
5
7
|
import { PORTALS } from "../client/portals-list.js";
|
|
6
8
|
/** commander value-parser: a non-negative integer. */
|
|
@@ -28,9 +30,44 @@ export function parseNonEmpty(value) {
|
|
|
28
30
|
}
|
|
29
31
|
return value;
|
|
30
32
|
}
|
|
31
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* commander value-parser for a value that ends up in an HTTP header (`--user-agent`).
|
|
35
|
+
* Node's HTTP layer throws an opaque "Invalid character in header content" at request
|
|
36
|
+
* time for a CR/LF (or any other C0 control or DEL) and for any character above
|
|
37
|
+
* U+00FF, which surfaced as "Unexpected error". Reject those here as a usage error,
|
|
38
|
+
* along with a blank value. Tab is allowed, as in HTTP. Checked by char code so the
|
|
39
|
+
* source stays free of control bytes.
|
|
40
|
+
*/
|
|
41
|
+
export function parseHeaderValue(value) {
|
|
42
|
+
parseNonEmpty(value);
|
|
43
|
+
for (let i = 0; i < value.length; i++) {
|
|
44
|
+
const c = value.charCodeAt(i);
|
|
45
|
+
if ((c < 0x20 && c !== 0x09) || c === 0x7f) {
|
|
46
|
+
throw new InvalidArgumentError("Value contains control characters.");
|
|
47
|
+
}
|
|
48
|
+
if (c > 0xff) {
|
|
49
|
+
throw new InvalidArgumentError("Value contains characters outside Latin-1 (above U+00FF).");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* commander value-parser for a text option's value: not blank, and not another
|
|
56
|
+
* long option. commander takes the next argument as the value of an option that
|
|
57
|
+
* needs one, even when it is a flag, so a forgotten value (`search --fq --rows 5`)
|
|
58
|
+
* silently shifted the rest into the query (`fq=--rows`, `q=5`) and still exited
|
|
59
|
+
* 0. No CKAN filter, sort, facet field or tag query starts with `--`; a single `-`
|
|
60
|
+
* (a negated Solr filter, `-organization:x`) stays allowed.
|
|
61
|
+
*/
|
|
62
|
+
export function parseOptionValue(value) {
|
|
63
|
+
if (value.startsWith("--")) {
|
|
64
|
+
throw new InvalidArgumentError("Expected a value, got another option. Give the option its value first.");
|
|
65
|
+
}
|
|
66
|
+
return parseNonEmpty(value);
|
|
67
|
+
}
|
|
68
|
+
/** commander accumulator for a repeatable option whose values are checked by parseOptionValue. */
|
|
32
69
|
export function collectNonEmpty(value, previous = []) {
|
|
33
|
-
return previous.concat([
|
|
70
|
+
return previous.concat([parseOptionValue(value)]);
|
|
34
71
|
}
|
|
35
72
|
/** Build a commander value-parser for a non-negative integer within [min, max]. */
|
|
36
73
|
export function parseBoundedInt(min, max) {
|
|
@@ -64,6 +101,11 @@ export function parseBaseUrl(value) {
|
|
|
64
101
|
if (/[?#]/.test(value)) {
|
|
65
102
|
throw new InvalidArgumentError("Expected a site URL without a query string or fragment.");
|
|
66
103
|
}
|
|
104
|
+
// `new URL` trims, but the value is used as given: a trailing space would land in
|
|
105
|
+
// the request path (`/404%20/api/3/...`) or the host.
|
|
106
|
+
if (value !== value.trim()) {
|
|
107
|
+
throw new InvalidArgumentError("A base URL cannot have surrounding whitespace.");
|
|
108
|
+
}
|
|
67
109
|
return value;
|
|
68
110
|
}
|
|
69
111
|
/** commander value-parser for --portal: the URL of a portal in the built-in list. */
|
|
@@ -91,9 +133,10 @@ export function toEngineOptions(global) {
|
|
|
91
133
|
return options;
|
|
92
134
|
}
|
|
93
135
|
/**
|
|
94
|
-
* Escape the
|
|
95
|
-
* ESC) but not DEL
|
|
96
|
-
*
|
|
136
|
+
* Escape the characters JSON.stringify leaves raw although a terminal acts on them.
|
|
137
|
+
* It escapes C0 (including ESC) but not DEL, the C1 range U+0080–U+009F (U+009B is
|
|
138
|
+
* the 8-bit form of CSI) or the bidi formatting characters (isBidiControl), which
|
|
139
|
+
* reorder the text that follows. The output is server data, so escape them; the
|
|
97
140
|
* result is equivalent, valid JSON (these characters only occur inside strings).
|
|
98
141
|
* Checked by char code so the source stays free of control bytes.
|
|
99
142
|
*/
|
|
@@ -102,16 +145,36 @@ export function escapeControlChars(json) {
|
|
|
102
145
|
let from = 0;
|
|
103
146
|
for (let i = 0; i < json.length; i++) {
|
|
104
147
|
const c = json.charCodeAt(i);
|
|
105
|
-
if (c >= 0x7f && c <= 0x9f) {
|
|
148
|
+
if ((c >= 0x7f && c <= 0x9f) || isBidiControl(c)) {
|
|
106
149
|
result += json.slice(from, i) + "\\u" + c.toString(16).padStart(4, "0");
|
|
107
150
|
from = i + 1;
|
|
108
151
|
}
|
|
109
152
|
}
|
|
110
153
|
return from === 0 ? json : result + json.slice(from);
|
|
111
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* JSON.stringify, pretty or compact. A deeply nested value (a hostile or broken
|
|
157
|
+
* response) overflows the stack — the pretty form far sooner than the compact one,
|
|
158
|
+
* which is why the message suggests --compact. The RangeError becomes a CkanError so
|
|
159
|
+
* the CLI prints a clear message instead of "Unexpected error: Maximum call stack
|
|
160
|
+
* size exceeded".
|
|
161
|
+
*/
|
|
162
|
+
function stringifyJson(value, compact) {
|
|
163
|
+
try {
|
|
164
|
+
return compact ? JSON.stringify(value) : JSON.stringify(value, null, 2);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
if (err instanceof RangeError) {
|
|
168
|
+
throw new CkanError(compact
|
|
169
|
+
? "The response is nested too deeply to print."
|
|
170
|
+
: "The response is nested too deeply to pretty-print; try --compact.", { cause: err });
|
|
171
|
+
}
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
112
175
|
/** Render a JSON value to stdout, pretty by default, compact with --compact. */
|
|
113
176
|
export function renderJson(deps, global, value) {
|
|
114
|
-
const text = escapeControlChars(
|
|
177
|
+
const text = escapeControlChars(stringifyJson(value, global.compact === true));
|
|
115
178
|
deps.io.out(text);
|
|
116
179
|
}
|
|
117
180
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/cli/shared.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iDAAiD;AAGjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/cli/shared.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iDAAiD;AAGjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAsB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,UAAU,EA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S,CACjB,OAAO;gBACL,CAAC,CAAC,6CAA6C;gBAC/C,CAAC,CAAC,mEAAmE,EACvE,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,UAAU,CAAC,IAAa,EAAE,MAAqB,EAAE,KAAc;IAC7E,MAAM,IAAI,GAAG,kBAAkB,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC;IAC/E,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AASD;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CACpB,IAAa,EACb,EAAgE;IAEhE,OAAO,KAAK,EAAE,GAAG,IAAe,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAY,CAAC;QACjD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAa,CAAC;QAC5E,MAAM,MAAM,GAAG,OAAO,CAAC,eAAe,EAAmB,CAAC;QAC1D,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1D,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -15,6 +15,12 @@ export declare class CkanClient {
|
|
|
15
15
|
constructor(options?: EngineOptions);
|
|
16
16
|
/** Call any CKAN action by name and return its unwrapped `result`. */
|
|
17
17
|
action<T = JsonValue>(name: string, params?: QueryParams): Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* An action whose `result` must have a known top-level shape (never a deep
|
|
20
|
+
* schema): a broken or foreign answer becomes a CkanParseError naming the
|
|
21
|
+
* action, not a TypeError further down (`page is not iterable`).
|
|
22
|
+
*/
|
|
23
|
+
private typed;
|
|
18
24
|
/** Site title, CKAN version and enabled extensions of the portal. */
|
|
19
25
|
status(): Promise<Status>;
|
|
20
26
|
/**
|
|
@@ -36,7 +42,7 @@ export declare class CkanClient {
|
|
|
36
42
|
groupShow(id: string): Promise<Group>;
|
|
37
43
|
/** A single resource (distribution) by id. */
|
|
38
44
|
resourceShow(id: string): Promise<Resource>;
|
|
39
|
-
/** Dataset names, paged with limit/offset. */
|
|
45
|
+
/** Dataset names, paged with limit/offset (a positive limit; omit it for all). */
|
|
40
46
|
packageList(params?: ListParams): Promise<string[]>;
|
|
41
47
|
/**
|
|
42
48
|
* Organization names, or full objects with `all_fields`. See `groupOrOrgList`
|