wikibase-cli 18.0.0 → 18.0.1

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.
@@ -34,6 +34,7 @@ function makeRequest (url, format) {
34
34
  headers: {
35
35
  Accept: formatAcceptHeader[format],
36
36
  },
37
+ parseResponseAsJson: format === 'json',
37
38
  })
38
39
  } else {
39
40
  const [ postUrl, urlencodedSparql ] = url.split('?')
@@ -45,6 +46,7 @@ function makeRequest (url, format) {
45
46
  'Content-type': 'application/sparql-query',
46
47
  Accept: formatAcceptHeader[format],
47
48
  },
49
+ parseResponseAsJson: format === 'json',
48
50
  })
49
51
  }
50
52
  }
@@ -72,6 +74,9 @@ function parseResult (format) {
72
74
  results = minimizeSimplifiedSparqlResults(simplifySparqlResults(results))
73
75
  if (indexAttribute) results = indexBy(results, indexAttribute)
74
76
  }
77
+ if (format === 'csv') {
78
+ results = results.replace(/\r\n/g, '\n')
79
+ }
75
80
  return results
76
81
  } catch (err) {
77
82
  err.context = { results }
package/lib/request.js CHANGED
@@ -19,18 +19,18 @@ export const get = async url => {
19
19
  return handleResponse({ res, url })
20
20
  }
21
21
 
22
- export const customGet = async ({ url, headers }) => {
22
+ export const customGet = async ({ url, headers, parseResponseAsJson = true }) => {
23
23
  const res = await request(url, { headers: buildHeaders(headers) })
24
- return handleResponse({ res, url })
24
+ return handleResponse({ res, url, parseResponseAsJson })
25
25
  }
26
26
 
27
- export const post = async ({ url, body, headers }) => {
27
+ export const post = async ({ url, body, headers, parseResponseAsJson = true }) => {
28
28
  const method = 'post'
29
29
  const res = await request(url, { method, body, headers: buildHeaders(headers) })
30
- return handleResponse({ res, url, method })
30
+ return handleResponse({ res, url, method, parseResponseAsJson })
31
31
  }
32
32
 
33
- async function handleResponse ({ res, url, method }) {
33
+ async function handleResponse ({ res, url, method, parseResponseAsJson = true }) {
34
34
  let body = await res.text()
35
35
  const { logResponseHeaders } = program
36
36
  if (logResponseHeaders) {
@@ -43,11 +43,13 @@ async function handleResponse ({ res, url, method }) {
43
43
  }
44
44
  console.error(JSON.stringify({ request: { url, method }, response: { headers } }))
45
45
  }
46
- // When Wikibase crash it doesn't return JSON errors anymore
47
- try {
48
- body = JSON.parse(body)
49
- } catch (err) {
50
- console.error('could not parse response body as JSON', err, { body })
46
+ if (parseResponseAsJson) {
47
+ // When Wikibase crash it doesn't return JSON errors anymore
48
+ try {
49
+ body = JSON.parse(body)
50
+ } catch (err) {
51
+ console.error('could not parse response body as JSON', err, { body })
52
+ }
51
53
  }
52
54
  const { status: statusCode } = res
53
55
  if (statusCode >= 400) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "18.0.0",
3
+ "version": "18.0.1",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -14,7 +14,7 @@
14
14
  "lint": "eslint --config .eslintrc.cjs bin/* lib test",
15
15
  "lint-fix": "eslint --config .eslintrc.cjs --fix bin/* lib test",
16
16
  "lint-staged": "./scripts/lint_staged",
17
- "prepublishOnly": "npm run lint && npm test",
17
+ "prepublishOnly": "export MOCHA_OPTIONS='--bail'; npm run lint && npm test",
18
18
  "postpublish": "npm run docker:publish && git push --tags",
19
19
  "test": "mocha --exit --timeout 20000 $MOCHA_OPTIONS",
20
20
  "update-toc": "./scripts/update_toc"