wikibase-cli 16.2.1 → 16.3.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/bin/wb-add-alias CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
- const inlineArgsParser = require('../lib/term_command_args_parser')('alias')
5
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
4
+ const { termCommandArgsParser } = require('../lib/common_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: termCommandArgsParser('alias')
7
+ })
6
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
9
  require('../lib/edit/edit_command')('alias', 'add')
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ const program = require('commander')
3
+ const { badgesCommandArgsParser } = require('../lib/common_command_args_parser')
4
+ const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: badgesCommandArgsParser
7
+ })
8
+ program.customHelpOption = require('../lib/command_with_template_custom_help')
9
+ require('../lib/edit/edit_command')('badge', 'add')
package/bin/wb-add-claim CHANGED
@@ -6,6 +6,6 @@ const inlineArgsParser = ([ id, property, value ]) => {
6
6
  if (program.rank) data.rank = program.rank
7
7
  return [ data ]
8
8
  }
9
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
9
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
10
10
  program.customHelpOption = require('../lib/command_with_template_custom_help')
11
11
  require('../lib/edit/edit_command')('claim', 'add')
@@ -6,6 +6,6 @@ const inlineArgsParser = ([ guid, property, value ]) => {
6
6
  guid = parseGuid(guid)
7
7
  return [ { guid, property, value } ]
8
8
  }
9
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
9
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
10
10
  program.customHelpOption = require('../lib/command_with_template_custom_help')
11
11
  require('../lib/edit/edit_command')('qualifier', 'add')
@@ -6,6 +6,6 @@ const inlineArgsParser = ([ guid, property, value ]) => {
6
6
  guid = parseGuid(guid)
7
7
  return [ { guid, property, value } ]
8
8
  }
9
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
9
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
10
10
  program.customHelpOption = require('../lib/command_with_template_custom_help')
11
11
  require('../lib/edit/edit_command')('reference', 'add')
package/bin/wb-badges ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ const program = require('../lib/program')
3
+ const { get } = require('../lib/request')
4
+ const errors_ = require('../lib/errors')
5
+ const entityAttributeCommand = require('../lib/entity_attribute_command')
6
+
7
+ program
8
+ .process('badges')
9
+
10
+ const { instance } = program
11
+
12
+ if (!instance) throw new Error('no instance set')
13
+
14
+ get(`${instance}/w/api.php?action=wbavailablebadges&format=json`)
15
+ .then(({ badges: badgesIds }) => {
16
+ return entityAttributeCommand('label', { ids: badgesIds })
17
+ })
18
+ .catch(errors_.exit)
@@ -2,6 +2,6 @@
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
4
  const inlineArgsParser = args => [ { id: args[0] } ]
5
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
5
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
6
6
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
7
  require('../lib/edit/edit_command')('entity', 'delete')
@@ -19,6 +19,6 @@ const getSortedEntitiesIds = args => {
19
19
 
20
20
  const getNumericId = id => parseInt(id.replace(/^[A-Z]+/i, ''))
21
21
 
22
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
22
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
23
23
  program.customHelpOption = require('../lib/command_with_template_custom_help')
24
24
  require('../lib/edit/edit_command')('entity', 'merge')
package/bin/wb-move-claim CHANGED
@@ -12,6 +12,6 @@ const inlineArgsParser = args => {
12
12
  return [ { guid, id, property } ]
13
13
  }
14
14
  }
15
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
15
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
16
16
  program.customHelpOption = require('../lib/command_with_template_custom_help')
17
17
  require('../lib/edit/edit_command')('claim', 'move')
@@ -13,6 +13,6 @@ const inlineArgsParser = args => {
13
13
  return [ { guid, oldProperty, newProperty } ]
14
14
  }
15
15
  }
16
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
16
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
17
17
  program.customHelpOption = require('../lib/command_with_template_custom_help')
18
18
  require('../lib/edit/edit_command')('qualifier', 'move')
package/bin/wb-query CHANGED
@@ -18,6 +18,7 @@ program
18
18
  .option('-f, --format <format>', "set output format: json, xml, tsv, csv, binrdf, table. Default: 'table' when 1 value is selected, 'json' otherwise")
19
19
  .option('-n, --limit <num>', 'set the request results limit')
20
20
  .option('-x, --index <variable>', "return the result as an index, instead of a list, using the passed variable as key (can't be used with the 'raw' option)")
21
+ .option('--log-response-headers [comma-separated headers names]', 'request to output all or some HTTP header fields from the server response on stderr')
21
22
  .process('query')
22
23
 
23
24
  if (!(program.subject || program.property || program.object || program.describe || program.sample)) {
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
- const inlineArgsParser = require('../lib/term_command_args_parser')('alias')
5
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
4
+ const { termCommandArgsParser } = require('../lib/common_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: termCommandArgsParser('alias')
7
+ })
6
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
9
  require('../lib/edit/edit_command')('alias', 'remove')
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ const program = require('commander')
3
+ const { badgesCommandArgsParser } = require('../lib/common_command_args_parser')
4
+ const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: badgesCommandArgsParser
7
+ })
8
+ program.customHelpOption = require('../lib/command_with_template_custom_help')
9
+ require('../lib/edit/edit_command')('badge', 'remove')
@@ -3,6 +3,6 @@ const program = require('commander')
3
3
  const { parseGuid } = require('../lib/parse_command_utils')
4
4
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
5
5
  const inlineArgsParser = guids => [ { guid: guids.map(parseGuid) } ]
6
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
6
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
7
7
  program.customHelpOption = require('../lib/command_with_template_custom_help')
8
8
  require('../lib/edit/edit_command')('claim', 'remove')
@@ -4,7 +4,7 @@ const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_pa
4
4
  const inlineArgsParser = ([ id, language ]) => {
5
5
  return [ { id, language, value: null } ]
6
6
  }
7
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
7
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
8
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
9
9
  require('../lib/edit/edit_command')({
10
10
  name: 'remove-description',
@@ -4,7 +4,7 @@ const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_pa
4
4
  const inlineArgsParser = ([ id, language ]) => {
5
5
  return [ { id, language, value: null } ]
6
6
  }
7
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
7
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
8
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
9
9
  require('../lib/edit/edit_command')({
10
10
  name: 'remove-label',
@@ -7,6 +7,6 @@ const inlineArgsParser = ([ guid, hash ]) => {
7
7
  hash = hash && hash.split('|')
8
8
  return [ { guid, hash } ]
9
9
  }
10
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
10
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
11
11
  program.customHelpOption = require('../lib/command_with_template_custom_help')
12
12
  require('../lib/edit/edit_command')('qualifier', 'remove')
@@ -7,6 +7,6 @@ const inlineArgsParser = ([ guid, hash ]) => {
7
7
  hash = hash.split('|')
8
8
  return [ { guid, hash } ]
9
9
  }
10
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
10
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
11
11
  program.customHelpOption = require('../lib/command_with_template_custom_help')
12
12
  require('../lib/edit/edit_command')('reference', 'remove')
@@ -4,7 +4,7 @@ const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_pa
4
4
  const inlineArgsParser = ([ id, site ]) => {
5
5
  return [ { id, site, title: null } ]
6
6
  }
7
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
7
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
8
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
9
9
  require('../lib/edit/edit_command')({
10
10
  name: 'remove-sitelink',
package/bin/wb-set-alias CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
- const inlineArgsParser = require('../lib/term_command_args_parser')('alias')
5
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
4
+ const { termCommandArgsParser } = require('../lib/common_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: termCommandArgsParser('alias')
7
+ })
6
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
9
  require('../lib/edit/edit_command')('alias', 'set')
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
- const inlineArgsParser = require('../lib/term_command_args_parser')('description')
5
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
4
+ const { termCommandArgsParser } = require('../lib/common_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: termCommandArgsParser('description')
7
+ })
6
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
9
  require('../lib/edit/edit_command')('description', 'set')
package/bin/wb-set-label CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
- const inlineArgsParser = require('../lib/term_command_args_parser')('label')
5
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
4
+ const { termCommandArgsParser } = require('../lib/common_command_args_parser')
5
+ program.customArgsParser = polymorphicCommandArgsParser({
6
+ inlineArgsParser: termCommandArgsParser('label')
7
+ })
6
8
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
9
  require('../lib/edit/edit_command')('label', 'set')
@@ -9,6 +9,6 @@ const inlineArgsParser = ([ id, site, title, badges ]) => {
9
9
  }
10
10
  return [ { id, site, title, badges } ]
11
11
  }
12
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
12
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
13
13
  program.customHelpOption = require('../lib/command_with_template_custom_help')
14
14
  require('../lib/edit/edit_command')('sitelink', 'set')
package/bin/wb-sparql CHANGED
@@ -8,6 +8,7 @@ program
8
8
  .option('-o, --open', 'open the query in the Query Service GUI')
9
9
  .option('-f, --format <format>', "set output format: json, xml, tsv, csv, binrdf, table. Default: 'table' when 1 value is selected, 'json' otherwise")
10
10
  .option('-x, --index <variable>', "return the result as an index, instead of a list, using the passed variable as key (can't be used with the 'raw' option)")
11
+ .option('--log-response-headers [comma-separated headers names]', 'request to output all or some HTTP header fields from the server response on stderr')
11
12
  .process('sparql')
12
13
 
13
14
  const fs = require('fs')
@@ -16,6 +16,6 @@ const inlineArgsParser = args => {
16
16
  if (program.rank) data.rank = program.rank
17
17
  return [ data ]
18
18
  }
19
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
19
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
20
20
  program.customHelpOption = require('../lib/command_with_template_custom_help')
21
21
  require('../lib/edit/edit_command')('claim', 'update')
@@ -6,6 +6,6 @@ const inlineArgsParser = ([ guid, property, oldValue, newValue ]) => {
6
6
  guid = parseGuid(guid)
7
7
  return [ { guid, property, oldValue, newValue } ]
8
8
  }
9
- program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
9
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
10
10
  program.customHelpOption = require('../lib/command_with_template_custom_help')
11
11
  require('../lib/edit/edit_command')('qualifier', 'update')
@@ -1,4 +1,4 @@
1
- module.exports = termType => ([ id, language, ...value ]) => {
1
+ const termCommandArgsParser = termType => ([ id, language, ...value ]) => {
2
2
  value = dropQuotes(value.join(' '))
3
3
  if (termType === 'alias') value = value.split('|')
4
4
  return [ { id, language, value } ]
@@ -9,3 +9,13 @@ const dropQuotes = value => {
9
9
  if (value.startsWith('"') && value.endsWith('"')) return value.slice(1, -1)
10
10
  return value
11
11
  }
12
+
13
+ const badgesCommandArgsParser = ([ id, site, badges ]) => {
14
+ badges = badges.split(/[,|]/)
15
+ return [ { id, site, badges } ]
16
+ }
17
+
18
+ module.exports = {
19
+ termCommandArgsParser,
20
+ badgesCommandArgsParser,
21
+ }
@@ -80,7 +80,7 @@ let wbEditConfig
80
80
 
81
81
  const runEditCommand = async (section, action, args) => {
82
82
  if (program.dry) {
83
- if (args[0] != null) console.log(JSON.stringify(args[0]))
83
+ if (args.length > 0) console.log(JSON.stringify({ section, action, args }))
84
84
  return
85
85
  }
86
86
 
@@ -4,8 +4,13 @@ const pluralize = require('./pluralize')
4
4
  const { grey, red } = require('chalk')
5
5
  const _ = require('lodash')
6
6
 
7
- module.exports = attribute => {
8
- const commandName = attribute
7
+ module.exports = (attribute, extraParams) => {
8
+ let commandName, ids
9
+ if (extraParams) {
10
+ ids = extraParams.ids
11
+ } else {
12
+ commandName = attribute
13
+ }
9
14
  const pluarlizedAttribute = pluralize(attribute)
10
15
  const props = [ pluarlizedAttribute ]
11
16
 
@@ -16,7 +21,7 @@ module.exports = attribute => {
16
21
  entitiesList.forEach(logAttribute(attribute, lang, strictLang, multiEntities, maxLength, output))
17
22
  }
18
23
 
19
- entityDataParser({ commandName, props, parser })
24
+ entityDataParser({ commandName, props, parser, ids })
20
25
  }
21
26
 
22
27
  const logAttribute = (attribute, lang, strictLang, multiEntities, maxLength, output) => entity => {
@@ -8,7 +8,7 @@ const inlineOptions = [
8
8
 
9
9
  const noInlineOptions = () => inlineOptions.filter(option => program[option] != null).length === 0
10
10
 
11
- module.exports = inlineArgsParser => args => {
11
+ module.exports = ({ inlineArgsParser }) => args => {
12
12
  if ((args.length === 1 && isJsonString(args[0]) && noInlineOptions()) || isFilePathSync(args[0])) {
13
13
  return objectArgParser(args)
14
14
  } else {
package/lib/program.js CHANGED
@@ -36,6 +36,7 @@ program.process = command => {
36
36
  const commandsAcceptingZeroArguments = [
37
37
  // Can be called without argument
38
38
  'props',
39
+ 'badges',
39
40
  // All arguments are passed as options values
40
41
  // making program.args.length === 0 likely
41
42
  'query',
package/lib/request.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const fetch = require('node-fetch')
2
+ const { logResponseHeaders } = require('./program')
2
3
  // Using a custom agent to set keepAlive=true
3
4
  // https://nodejs.org/api/http.html#http_class_http_agent
4
5
  // https://github.com/bitinn/node-fetch#custom-agent
@@ -11,6 +12,7 @@ const httpsAgent = new https.Agent({ keepAlive: true })
11
12
  // - accept certificates that would otherwise generate a UNABLE_TO_VERIFY_LEAF_SIGNATURE error
12
13
  const insecureHttpsAgent = new https.Agent({ keepAlive: true, rejectUnauthorized: false })
13
14
  const tlsErrorsHosts = new Set([ 'datos.bne.es' ])
15
+ const { pick } = require('lodash')
14
16
 
15
17
  const agent = ({ host, protocol }) => {
16
18
  if (tlsErrorsHosts.has(host)) return protocol === 'http:' ? httpAgent : insecureHttpsAgent
@@ -24,24 +26,33 @@ const buildHeaders = customHeaders => {
24
26
  }
25
27
 
26
28
  module.exports = {
27
- get: url => {
28
- return fetch(url, { headers: globalHeaders, agent })
29
- .then(rejectErrors)
29
+ get: async url => {
30
+ const res = await fetch(url, { headers: globalHeaders, agent })
31
+ return handleResponse({ res, url })
30
32
  },
31
33
 
32
- customGet: ({ url, headers }) => {
33
- return fetch(url, { headers: buildHeaders(headers), agent })
34
- .then(rejectErrors)
34
+ customGet: async ({ url, headers }) => {
35
+ const res = await fetch(url, { headers: buildHeaders(headers), agent })
36
+ return handleResponse({ res, url })
35
37
  },
36
38
 
37
- post: ({ url, body, headers }) => {
38
- return fetch(url, { method: 'post', body, headers: buildHeaders(headers), agent })
39
- .then(rejectErrors)
39
+ post: async ({ url, body, headers }) => {
40
+ const method = 'post'
41
+ const res = await fetch(url, { method, body, headers: buildHeaders(headers), agent })
42
+ return handleResponse({ res, url, method })
40
43
  }
41
44
  }
42
45
 
43
- const rejectErrors = async res => {
46
+ const handleResponse = async ({ res, url, method }) => {
44
47
  let body = await res.text()
48
+ if (logResponseHeaders) {
49
+ let headers = res.headers.raw()
50
+ if (typeof logResponseHeaders === 'string') {
51
+ const headersSubset = logResponseHeaders.split(',')
52
+ headers = pick(headers, headersSubset)
53
+ }
54
+ console.error(JSON.stringify({ request: { url, method }, response: { headers } }))
55
+ }
45
56
  // When Wikibase crash it doesn't return JSON errors anymore
46
57
  if (body[0] === '{') body = JSON.parse(body)
47
58
  const { status: statusCode } = res
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ alias: 'ab',
3
+ args: '<entity> <site> [badges]',
4
+ description: 'add badges on an existing sitelink, without removing other badges that might already have been set',
5
+ options: require('../lib/common_options').editCommands,
6
+ examples: [
7
+ { args: 'Q4115189 enwikiquote Q17437796,Q17437798', comment: 'Add Q17437796 and Q17437798 badges on Q4115189 enwikiquote sitelink' },
8
+ ]
9
+ }
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ args: '',
3
+ description: 'list sitelink badges available on a Wikibase instance',
4
+ options: {
5
+ lang: false,
6
+ verbose: false,
7
+ clipboard: true,
8
+ json: true,
9
+ instance: true,
10
+ sparqlEndpoint: false
11
+ },
12
+ examples: [
13
+ { args: '', comment: 'List badges on the Wikibase instance set in config' },
14
+ { args: '--instance https://test.wikidata.org', comment: 'List badges on an explicit Wikibase instance' },
15
+ ]
16
+ }
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ alias: 'rb',
3
+ args: '<entity> <site> [badges]',
4
+ description: 'remove badges on an existing sitelink',
5
+ options: require('../lib/common_options').editCommands,
6
+ examples: [
7
+ { args: 'Q4115189 enwikiquote Q17437796,Q17437798', comment: 'Remove Q17437796 and Q17437798 badges on Q4115189 enwikiquote sitelink' },
8
+ ]
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "16.2.1",
3
+ "version": "16.3.0",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -50,7 +50,7 @@
50
50
  "shell-quote": "^1.7.3",
51
51
  "split": "^1.0.1",
52
52
  "through": "^2.3.8",
53
- "wikibase-edit": "^5.2.0",
53
+ "wikibase-edit": "^5.3.0",
54
54
  "wikibase-sdk": "^8.1.0",
55
55
  "wikidata-lang": "^2.0.11"
56
56
  },