wikibase-cli 19.0.1 → 19.1.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-open.js CHANGED
@@ -6,7 +6,7 @@ import { getSitelinkUrlFactory } from '#lib/get_sitelink_url'
6
6
  import { getMediaInfoEntityTitle } from '#lib/mediainfo'
7
7
  import { openUrl } from '#lib/open'
8
8
  import program from '#lib/program'
9
- import { tolerantIdParserFactory } from '#lib/tolerant_id_parser'
9
+ import { guidPattern, tolerantIdParserFactory } from '#lib/tolerant_id_parser'
10
10
 
11
11
  await program
12
12
  .option('-p, --wikipedia', 'open the Wikipedia article')
@@ -17,7 +17,11 @@ await program
17
17
  .process('open')
18
18
 
19
19
  const getSitelinkUrl = getSitelinkUrlFactory(program)
20
- const parseId = tolerantIdParserFactory()
20
+ const parseId = tolerantIdParserFactory({
21
+ allowStatementsIds: true,
22
+ allowEntitiesSchemasIds: true,
23
+ allowNestedIds: true,
24
+ })
21
25
 
22
26
  const { instance, args, lang } = program
23
27
  exitOnMissingInstance(instance)
@@ -25,6 +29,7 @@ exitOnMissingInstance(instance)
25
29
  let ids
26
30
  try {
27
31
  ids = args.map(parseId).filter(id => id != null)
32
+ // eslint-disable-next-line no-unused-vars
28
33
  } catch (err) {
29
34
  // invalid ids: trigger a search
30
35
  }
@@ -68,6 +73,9 @@ if (!ids || ids.length === 0) {
68
73
  }
69
74
  } else if (program.revision) {
70
75
  openUrl(`${instance}/w/index.php?title=${id}&oldid=${program.revision}`)
76
+ } else if (guidPattern.test(id)) {
77
+ const urlStatementId = id.replace('$', '-')
78
+ openUrl(`${instance}/entity/statement/${urlStatementId}`)
71
79
  } else {
72
80
  openUrl(`${instance}/entity/${id}`)
73
81
  }
@@ -25,7 +25,7 @@ export default {
25
25
  } else {
26
26
  value = valueParsers[param.type](value)
27
27
  // Reject invalid value
28
- const valid = param.test ? param.test(value) : typeof value === param.type // eslint-disable-line valid-typeof
28
+ const valid = param.test ? param.test(value) : typeof value === param.type
29
29
  if (!valid) return errors_.bundle('invalid parameter', value)
30
30
  config[key] = value
31
31
  }
@@ -32,9 +32,13 @@ const parseStringValue = value => {
32
32
  value = JSON.parse(value)
33
33
  return value
34
34
  } catch (rawErr) {
35
- const err = errors_.new('invalid JSON value', value)
36
- err.statusCode = 400
37
- throw err
35
+ if (rawErr.name === 'SyntaxError') {
36
+ const err = errors_.new('invalid JSON value', value)
37
+ err.statusCode = 400
38
+ throw err
39
+ } else {
40
+ throw rawErr
41
+ }
38
42
  }
39
43
  }
40
44
 
@@ -16,6 +16,7 @@ export default async program => {
16
16
 
17
17
  try {
18
18
  return readJsonFile(langJsonFilePath)
19
+ // eslint-disable-next-line no-unused-vars
19
20
  } catch (err) {
20
21
  return refreshProps(program, langJsonFilePath)
21
22
  }
@@ -57,6 +57,7 @@ const isValidJson = line => {
57
57
  JSON.parse(line)
58
58
  return true
59
59
  } catch (err) {
60
- return false
60
+ if (err.name === 'SyntaxError') return false
61
+ else throw err
61
62
  }
62
63
  }
@@ -8,7 +8,7 @@ export default () => {
8
8
  // -f: ignore if there are no more files to delete
9
9
  // Use `-f` rather than `--force` to make it work on BusyBox
10
10
  // cf https://www.wikidata.org/wiki/User_talk:Maxlath#Small_fix and https://paste.toolforge.org/view/f40c24e5
11
- exec(`rm -f ${propsDir}/*.json`, (err, res) => {
11
+ exec(`rm -f ${propsDir}/*.json`, err => {
12
12
  if (err) console.error('reset properties failed', err)
13
13
  else console.log(green('properties reset'))
14
14
  })
@@ -13,11 +13,20 @@ import errors_ from './errors.js'
13
13
  const entityIdPattern = /(Q|P|L|M)[1-9][0-9]*/
14
14
  const nestedEntityIdPattern = /L[1-9][0-9]*-(F|S)[1-9][0-9]*/
15
15
  const entitySchemaIdPattern = /(E)[1-9][0-9]*/
16
+ export const guidPattern = /([QPLM]\d+(-[FS]\d+)?)[-$]([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i
16
17
 
17
18
  export function tolerantIdParserFactory (options = {}) {
19
+ const { allowNestedIds = false, allowEntitiesSchemasIds = false, allowStatementsIds = false } = options
20
+
18
21
  return function tolerantIdParser (input) {
22
+ if (allowStatementsIds) {
23
+ const guidMatch = input.match(guidPattern)
24
+ if (guidMatch) return guidMatch[0]
25
+ }
26
+
27
+ // Uppercase after checking statement ids, as they might need to stay lowercased
28
+ // Example: wds:q1059114-107F1AC7-1195-4137-A779-748D633CDA68
19
29
  input = input.toUpperCase()
20
- const { allowNestedIds = false, allowEntitiesSchemasIds = false } = options
21
30
 
22
31
  if (allowNestedIds) {
23
32
  const nestedEntityIdMatch = input.match(nestedEntityIdPattern)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "19.0.1",
3
+ "version": "19.1.0",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -11,12 +11,12 @@
11
11
  "scripts": {
12
12
  "docker:publish": "./scripts/docker_publish",
13
13
  "git-pre-commit": "./scripts/githooks/pre-commit",
14
- "lint": "eslint --config .eslintrc.cjs bin/* lib test",
15
- "lint-fix": "eslint --config .eslintrc.cjs --fix bin/* lib test",
14
+ "lint": "eslint",
15
+ "lint-fix": "eslint --fix",
16
16
  "lint-staged": "./scripts/lint_staged",
17
17
  "prepublishOnly": "export MOCHA_OPTIONS='--bail'; npm run lint && npm test",
18
18
  "postpublish": "npm run docker:publish && git push --tags",
19
- "test": "export FORCE_COLOR=false; mocha --exit --timeout 20000 $MOCHA_OPTIONS",
19
+ "test": "export FORCE_COLOR=false; mocha --exit --timeout 20000 $MOCHA_OPTIONS tests",
20
20
  "update-toc": "./scripts/update_toc"
21
21
  },
22
22
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "imports": {
32
32
  "#lib/*": "./lib/*.js",
33
33
  "#metadata/*": "./metadata/*.js",
34
- "#test/*": "./test/*.js"
34
+ "#tests/*": "./tests/*.js"
35
35
  },
36
36
  "keywords": [
37
37
  "wikidata",
@@ -62,14 +62,15 @@
62
62
  "wikidata-lang": "^2.0.11"
63
63
  },
64
64
  "devDependencies": {
65
+ "@eslint/config-helpers": "^0.4.1",
66
+ "@eslint/js": "^9.38.0",
67
+ "@stylistic/eslint-plugin": "^5.5.0",
65
68
  "@types/lodash-es": "^4.17.8",
66
69
  "@types/node": "^20.4.2",
67
70
  "@vercel/git-hooks": "^1.0.0",
68
- "eslint": "^8.57.0",
69
- "eslint-config-standard": "^17.1.0",
70
- "eslint-plugin-import": "^2.29.1",
71
- "eslint-plugin-n": "^16.6.2",
72
- "eslint-plugin-promise": "^6.1.1",
71
+ "eslint": "^9.38.0",
72
+ "eslint-plugin-import-x": "^4.16.1",
73
+ "eslint-plugin-n": "^17.23.1",
73
74
  "mocha": "^9.1.3",
74
75
  "should": "^13.2.3"
75
76
  },