wikibase-cli 15.15.1 → 15.15.5

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-data CHANGED
@@ -3,9 +3,9 @@ const program = require('../lib/program')
3
3
 
4
4
  program
5
5
  .option('-s, --simplify', 'get simplified entities data')
6
- .option('-k, --keep <props>', 'data to keep when simplifying claims')
6
+ .option('-k, --keep <props>', 'data to keep when simplifying claims (ids,richvalues,types,references,qualifiers,hashes,nontruthy,nondeprecated,ranks)')
7
7
  .option('--time-converter <converter>', 'specify which time format should be used when simplifying')
8
- .option('-p, --props <props>', 'request only certain properties (info, sitelinks, aliases, labels, descriptions, claims, datatype)')
8
+ .option('-p, --props <props>', 'request only certain properties (info,sitelinks,aliases,labels,descriptions,claims,datatype)')
9
9
  .option('-r, --revision <id>', 'request a specific revision')
10
10
  .option('-f, --format <format>', 'Default: ndjson. Alternatives: ttl')
11
11
  .process('data')
package/bin/wb-query CHANGED
@@ -5,6 +5,8 @@ program
5
5
  .option('-s, --subject <subject>', 'set a subject')
6
6
  .option('-p, --property <property>', 'set a property')
7
7
  .option('-o, --object <object>', 'set an object')
8
+ .option('-qp, --qualifier-property <property>', 'set a qualifier property')
9
+ .option('-qo, --qualifier-object <object>', 'set a qualifier value')
8
10
  .option('--describe <node>', 'make a DESCRIBE request')
9
11
  .option('--sample', 'select a sample of triples')
10
12
  .option('-a, --labels', 'requests results labels')
@@ -9,7 +9,7 @@ if (configFolder != null) {
9
9
  fs.accessSync(configPath)
10
10
  } catch (err) {
11
11
  // Initialize if it doesn't exist
12
- fs.writeFileSync(configPath, '{}')
12
+ fs.writeFileSync(configPath, '{}', { mode: 0o600 })
13
13
  }
14
14
  module.exports = configPath
15
15
  } else {
@@ -1,29 +1,39 @@
1
1
  const { isEntityId, isPropertyId } = require('wikibase-sdk')
2
2
  const errors_ = require('../lib/errors')
3
3
 
4
+ const prefixedProperty = prefix => value => {
5
+ if (isPropertyId(value)) return `${prefix}:${value}`
6
+ if (isUrlValue(value)) return formatUrlValue(value)
7
+ errors_.exit(`invalid property: ${value}`)
8
+ }
9
+
10
+ const object = value => {
11
+ // entity
12
+ if (value[0] === 'Q') return `wd:${value}`
13
+ // property
14
+ if (value[0] === 'P') return `wdt:${value}`
15
+ // number
16
+ if (/^\d+(\.\d+)?$/.test(value)) return value
17
+ // URL
18
+ if (isUrlValue(value)) return formatUrlValue(value)
19
+ // string
20
+ return `"${value}"`.replace(/""/g, '"')
21
+ }
22
+
4
23
  module.exports = {
5
24
  subject: value => {
6
25
  if (isEntityId(value)) return `wd:${value}`
7
26
  if (isUrlValue(value)) return formatUrlValue(value)
8
27
  errors_.exit(`invalid subject: ${value}`)
9
28
  },
10
- property: value => {
11
- if (isPropertyId(value)) return `wdt:${value}`
12
- if (isUrlValue(value)) return formatUrlValue(value)
13
- errors_.exit(`invalid property: ${value}`)
14
- },
15
- object: value => {
16
- // entity
17
- if (value[0] === 'Q') return `wd:${value}`
18
- // property
19
- if (value[0] === 'P') return `wdt:${value}`
20
- // number
21
- if (/^\d+(\.\d+)?$/.test(value)) return value
22
- // URL
23
- if (isUrlValue(value)) return formatUrlValue(value)
24
- // string
25
- return `"${value}"`.replace(/""/g, '"')
26
- }
29
+
30
+ property: prefixedProperty('wdt'),
31
+ pProperty: prefixedProperty('p'),
32
+ psProperty: prefixedProperty('ps'),
33
+ pqProperty: prefixedProperty('pq'),
34
+
35
+ object,
36
+ pqObject: object,
27
37
  }
28
38
 
29
39
  const isUrlValue = value => /^<?(https?|ftp):\/\/.+/.test(value)
@@ -1,20 +1,29 @@
1
1
  const formatStatementElementValue = require('./format_statement_element_value')
2
2
 
3
3
  module.exports = program => {
4
- let { count: countResults, labels: selectLabels, lang } = program
4
+ let { count: countResults, labels: selectLabels, lang, qualifierProperty, qualifierObject } = program
5
+
6
+ const useSubSnaks = (qualifierProperty != null || qualifierObject != null)
5
7
 
6
8
  selectLabels = selectLabels && !countResults
7
9
 
8
10
  if (program.subject && program.property && program.object) {
9
- console.log('At maximum two statement element should be set')
11
+ console.log('At maximum two main statement elements should be set')
10
12
  process.exit(1)
11
13
  }
12
14
 
13
15
  let select = ''
14
- let triple = '?subject ?property ?object .'
16
+ let triple
17
+ if (useSubSnaks) {
18
+ triple = `?subject ?pProperty ?statement .
19
+ ?statement ?psProperty ?object .
20
+ ?statement ?pqProperty ?pqObject .`
21
+ } else {
22
+ triple = '?subject ?property ?object .'
23
+ }
15
24
 
16
- const setElement = elName => {
17
- let value = program[elName]
25
+ const setElement = (elName, value) => {
26
+ value = value || program[elName]
18
27
  if (value) {
19
28
  value = formatStatementElementValue[elName](value)
20
29
  triple = triple.replace(`?${elName}`, value)
@@ -36,7 +45,14 @@ module.exports = program => {
36
45
  }
37
46
 
38
47
  setElement('subject')
39
- setElement('property')
48
+ if (useSubSnaks) {
49
+ setElement('pProperty', program.property)
50
+ setElement('psProperty', program.property)
51
+ if (qualifierProperty) setElement('pqProperty', qualifierProperty)
52
+ if (qualifierObject) setElement('pqObject', qualifierObject)
53
+ } else {
54
+ setElement('property')
55
+ }
40
56
  setElement('object')
41
57
 
42
58
  if (selectLabels) {
@@ -9,12 +9,15 @@ module.exports = (fn, inputArgs, metadata) => {
9
9
  const minArgs = minimumRequiredArgs(metadata.args)
10
10
  if (metadata.args && inputArgs.length < minArgs) {
11
11
  const message = `the passed function expects at least ${minArgs} arguments`
12
- errors_.bundle(message, { expectedArgs: metadata.args, inputArgs })
12
+ errors_.bundle(message, { expectedArgs: metadata.args, inputArgs, fn: fn.toString() })
13
13
  }
14
14
  } else {
15
- if (fn.length !== inputArgs.length) {
16
- const message = `the passed function expects ${fn.length} arguments`
17
- errors_.bundle(message, { inputArgs })
15
+ const minArgs = fn.length
16
+ // It might be that the function accepts more than fn.length arguments
17
+ // as rest parameters aren't counted
18
+ if (inputArgs.length < minArgs) {
19
+ const message = `the passed function expects at least ${fn.length} arguments`
20
+ errors_.bundle(message, { inputArgs, fn: fn.toString() })
18
21
  }
19
22
  }
20
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "15.15.1",
3
+ "version": "15.15.5",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,7 +13,7 @@
13
13
  "lint-staged": "./scripts/lint_staged",
14
14
  "prepublishOnly": "npm run lint && npm test",
15
15
  "postpublish": "npm run docker:publish && git push --tags",
16
- "test": "mocha --exit",
16
+ "test": "mocha --exit --timeout 20000",
17
17
  "update-toc": "./scripts/update_toc"
18
18
  },
19
19
  "repository": {
@@ -50,7 +50,7 @@
50
50
  "split": "^1.0.1",
51
51
  "through": "^2.3.8",
52
52
  "wikibase-edit": "^4.14.2",
53
- "wikibase-sdk": "^7.14.0",
53
+ "wikibase-sdk": "^7.14.1",
54
54
  "wikidata-lang": "^2.0.11"
55
55
  },
56
56
  "devDependencies": {
@@ -62,7 +62,7 @@
62
62
  "eslint-plugin-promise": "^4.2.1",
63
63
  "eslint-plugin-standard": "^4.0.1",
64
64
  "git-hooks": "^1.1.10",
65
- "mocha": "^5.2.0",
65
+ "mocha": "^9.1.3",
66
66
  "should": "^13.2.3"
67
67
  },
68
68
  "engines": {