wikibase-cli 16.3.3 → 17.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.
Files changed (219) hide show
  1. package/README.md +1 -1
  2. package/bin/wb-add-alias.js +12 -0
  3. package/bin/wb-add-badge.js +12 -0
  4. package/bin/wb-add-claim.js +14 -0
  5. package/bin/wb-add-qualifier.js +14 -0
  6. package/bin/wb-add-reference.js +14 -0
  7. package/bin/wb-aliases.js +4 -0
  8. package/bin/wb-badges.js +18 -0
  9. package/bin/{wb-claims → wb-claims.js} +19 -14
  10. package/bin/{wb-config → wb-config.js} +8 -6
  11. package/bin/{wb-convert → wb-convert.js} +11 -12
  12. package/bin/wb-create-entity.js +10 -0
  13. package/bin/{wb-data → wb-data.js} +15 -11
  14. package/bin/wb-delete-entity.js +10 -0
  15. package/bin/wb-description.js +4 -0
  16. package/bin/wb-edit-entity.js +10 -0
  17. package/bin/{wb-generate-template → wb-generate-template.js} +24 -13
  18. package/bin/{wb-hub → wb-hub.js} +9 -7
  19. package/bin/{wb-id → wb-id.js} +14 -11
  20. package/bin/wb-label.js +4 -0
  21. package/bin/{wb-lang → wb-lang.js} +8 -8
  22. package/bin/wb-lemma.js +4 -0
  23. package/bin/{wb-merge-entity → wb-merge-entity.js} +6 -4
  24. package/bin/wb-move-claim.js +20 -0
  25. package/bin/wb-move-qualifier.js +21 -0
  26. package/bin/{wb-open → wb-open.js} +23 -22
  27. package/bin/{wb-props → wb-props.js} +8 -9
  28. package/bin/{wb-query → wb-query.js} +13 -9
  29. package/bin/wb-remove-alias.js +12 -0
  30. package/bin/wb-remove-badge.js +12 -0
  31. package/bin/wb-remove-claim.js +11 -0
  32. package/bin/wb-remove-description.js +16 -0
  33. package/bin/wb-remove-label.js +16 -0
  34. package/bin/wb-remove-qualifier.js +15 -0
  35. package/bin/wb-remove-reference.js +15 -0
  36. package/bin/wb-remove-sitelink.js +16 -0
  37. package/bin/{wb-revisions → wb-revisions.js} +15 -11
  38. package/bin/{wb-search → wb-search.js} +17 -15
  39. package/bin/wb-set-alias.js +12 -0
  40. package/bin/wb-set-description.js +12 -0
  41. package/bin/wb-set-label.js +12 -0
  42. package/bin/wb-set-sitelink.js +17 -0
  43. package/bin/{wb-sparql → wb-sparql.js} +16 -12
  44. package/bin/{wb-summary → wb-summary.js} +3 -3
  45. package/bin/{wb-update-claim → wb-update-claim.js} +9 -6
  46. package/bin/wb-update-qualifier.js +14 -0
  47. package/bin/wb.js +27 -0
  48. package/bin/{wd → wd.js} +6 -3
  49. package/index.js +7 -1
  50. package/lib/apply_env_and_config_default.js +7 -5
  51. package/lib/chalk.js +12 -0
  52. package/lib/command_with_template_custom_help.js +7 -7
  53. package/lib/common_command_args_parser.js +7 -10
  54. package/lib/common_errors.js +5 -7
  55. package/lib/common_options.js +23 -24
  56. package/lib/config/config.js +10 -5
  57. package/lib/config/credentials_config.js +7 -6
  58. package/lib/config/file_operations.js +9 -8
  59. package/lib/config/file_path.js +11 -8
  60. package/lib/config/parameters.js +11 -10
  61. package/lib/convert_ids.js +10 -8
  62. package/lib/copy.js +2 -2
  63. package/lib/drop_non_selected_subprops.js +3 -3
  64. package/lib/edit/assert_credentials.js +3 -3
  65. package/lib/edit/edit_command.js +19 -19
  66. package/lib/edit/init_credentials.js +11 -11
  67. package/lib/edit/parse_batch_line.js +2 -2
  68. package/lib/edit/parse_object_value.js +6 -5
  69. package/lib/edit/prompt.js +3 -4
  70. package/lib/edit/validate_instance_credentials.js +2 -2
  71. package/lib/entity_attribute_command.js +10 -10
  72. package/lib/entity_attribute_parser.js +9 -8
  73. package/lib/entity_data_parser.js +14 -11
  74. package/lib/errors.js +3 -3
  75. package/lib/execute_function.js +4 -4
  76. package/lib/exit_on_missing.js +11 -12
  77. package/lib/fetch_and_log_entity_revision.js +18 -15
  78. package/lib/fetch_and_log_guid_data.js +19 -11
  79. package/lib/fetch_and_log_ids_data.js +17 -16
  80. package/lib/fetch_and_log_property_claims_data.js +18 -10
  81. package/lib/fetch_lang_props.js +13 -12
  82. package/lib/filter_claims_properties.js +4 -4
  83. package/lib/format_properties_data.js +2 -2
  84. package/lib/format_statement_element_value.js +3 -3
  85. package/lib/fs.js +13 -26
  86. package/lib/generate_describe_sparql_query.js +3 -3
  87. package/lib/generate_sample_sparql_query.js +1 -1
  88. package/lib/generate_select_sparql_query.js +2 -2
  89. package/lib/get_cache_folder_path.js +11 -8
  90. package/lib/get_claims_texts.js +8 -7
  91. package/lib/get_entities.js +6 -5
  92. package/lib/get_entities_by_batches.js +12 -7
  93. package/lib/get_entities_labels.js +3 -5
  94. package/lib/get_entities_schemas.js +7 -7
  95. package/lib/get_folder_path.js +8 -6
  96. package/lib/get_lang_props.js +17 -16
  97. package/lib/get_pattern_filter.js +4 -3
  98. package/lib/get_properties_data.js +5 -5
  99. package/lib/get_redirected_sitelink_title.js +4 -4
  100. package/lib/get_sitelink_url.js +9 -8
  101. package/lib/get_stdin_input.js +1 -1
  102. package/lib/get_ttl_entities.js +8 -8
  103. package/lib/global_options_help.js +1 -1
  104. package/lib/hash_string.js +4 -2
  105. package/lib/json.js +5 -0
  106. package/lib/local_lang.js +2 -1
  107. package/lib/log_claims.js +12 -12
  108. package/lib/log_command_examples.js +11 -6
  109. package/lib/log_ndjson.js +1 -1
  110. package/lib/make_sparql_query.js +29 -25
  111. package/lib/matching_langs.js +4 -6
  112. package/lib/minimize_claims.js +3 -5
  113. package/lib/object_arg_parser.js +12 -17
  114. package/lib/open.js +7 -7
  115. package/lib/output.js +37 -35
  116. package/lib/output_templates.js +41 -31
  117. package/lib/parse_command_utils.js +14 -15
  118. package/lib/parse_entity_type.js +2 -2
  119. package/lib/parse_props.js +7 -4
  120. package/lib/parse_simplify_options.js +1 -1
  121. package/lib/path.js +3 -2
  122. package/lib/pluralize.js +2 -2
  123. package/lib/polymorphic_command_args_parser.js +11 -9
  124. package/lib/program.js +9 -9
  125. package/lib/properties.js +22 -23
  126. package/lib/queries/all_instances.js +2 -2
  127. package/lib/queries/all_properties.js +1 -1
  128. package/lib/read_ids_from_stdin.js +3 -3
  129. package/lib/request.js +22 -23
  130. package/lib/request_headers.js +8 -2
  131. package/lib/reset_properties.js +4 -4
  132. package/lib/sparql_query_command.js +10 -8
  133. package/lib/stringify_as_js_function.js +3 -3
  134. package/lib/summary_parser.js +43 -13
  135. package/lib/tabularize.js +7 -7
  136. package/lib/tolerant_id_parser.js +21 -18
  137. package/lib/types.js +4 -6
  138. package/lib/utils.js +11 -13
  139. package/lib/validate.js +2 -0
  140. package/lib/validate_function_args.js +2 -2
  141. package/lib/value_parsers.js +2 -2
  142. package/lib/wbk.js +4 -3
  143. package/lib/wellknown_queries.js +6 -5
  144. package/metadata/add-alias.js +6 -4
  145. package/metadata/add-badge.js +5 -3
  146. package/metadata/add-claim.js +5 -5
  147. package/metadata/add-qualifier.js +6 -4
  148. package/metadata/add-reference.js +6 -4
  149. package/metadata/aliases.js +6 -4
  150. package/metadata/badges.js +3 -3
  151. package/metadata/claims.js +4 -4
  152. package/metadata/config.js +5 -5
  153. package/metadata/convert.js +4 -4
  154. package/metadata/create-entity.js +8 -8
  155. package/metadata/data.js +4 -4
  156. package/metadata/delete-entity.js +7 -7
  157. package/metadata/description.js +6 -4
  158. package/metadata/edit-entity.js +10 -10
  159. package/metadata/generate-template.js +4 -4
  160. package/metadata/hub.js +3 -3
  161. package/metadata/id.js +4 -4
  162. package/metadata/label.js +5 -3
  163. package/metadata/lang.js +4 -4
  164. package/metadata/lemma.js +6 -4
  165. package/metadata/merge-entity.js +6 -6
  166. package/metadata/move-claim.js +6 -4
  167. package/metadata/move-qualifier.js +6 -4
  168. package/metadata/open.js +4 -4
  169. package/metadata/props.js +4 -4
  170. package/metadata/query.js +3 -3
  171. package/metadata/remove-alias.js +6 -4
  172. package/metadata/remove-badge.js +5 -3
  173. package/metadata/remove-claim.js +6 -4
  174. package/metadata/remove-description.js +5 -3
  175. package/metadata/remove-label.js +5 -3
  176. package/metadata/remove-qualifier.js +6 -4
  177. package/metadata/remove-reference.js +6 -4
  178. package/metadata/remove-sitelink.js +5 -3
  179. package/metadata/revisions.js +4 -4
  180. package/metadata/search.js +3 -3
  181. package/metadata/set-alias.js +6 -4
  182. package/metadata/set-description.js +6 -4
  183. package/metadata/set-label.js +6 -4
  184. package/metadata/set-sitelink.js +5 -3
  185. package/metadata/sparql.js +4 -4
  186. package/metadata/summary.js +5 -5
  187. package/metadata/update-claim.js +5 -5
  188. package/metadata/update-qualifier.js +6 -4
  189. package/package.json +31 -22
  190. package/bin/wb +0 -22
  191. package/bin/wb-add-alias +0 -9
  192. package/bin/wb-add-badge +0 -9
  193. package/bin/wb-add-claim +0 -11
  194. package/bin/wb-add-qualifier +0 -11
  195. package/bin/wb-add-reference +0 -11
  196. package/bin/wb-aliases +0 -2
  197. package/bin/wb-badges +0 -18
  198. package/bin/wb-create-entity +0 -5
  199. package/bin/wb-delete-entity +0 -7
  200. package/bin/wb-description +0 -2
  201. package/bin/wb-edit-entity +0 -5
  202. package/bin/wb-label +0 -2
  203. package/bin/wb-lemma +0 -2
  204. package/bin/wb-move-claim +0 -17
  205. package/bin/wb-move-qualifier +0 -18
  206. package/bin/wb-remove-alias +0 -9
  207. package/bin/wb-remove-badge +0 -9
  208. package/bin/wb-remove-claim +0 -8
  209. package/bin/wb-remove-description +0 -13
  210. package/bin/wb-remove-label +0 -13
  211. package/bin/wb-remove-qualifier +0 -12
  212. package/bin/wb-remove-reference +0 -12
  213. package/bin/wb-remove-sitelink +0 -13
  214. package/bin/wb-set-alias +0 -9
  215. package/bin/wb-set-description +0 -9
  216. package/bin/wb-set-label +0 -9
  217. package/bin/wb-set-sitelink +0 -14
  218. package/bin/wb-update-qualifier +0 -11
  219. package/lib/valide.js +0 -4
@@ -1,4 +1,7 @@
1
- const config = require('./config/config')
1
+ import { camelCase, snakeCase } from 'lodash-es'
2
+ import { localLang } from '#lib/local_lang'
3
+ import { config } from './config/config.js'
4
+
2
5
  const fallbackConfigOptions = [
3
6
  'bot',
4
7
  'clipboard',
@@ -7,15 +10,14 @@ const fallbackConfigOptions = [
7
10
  'lang',
8
11
  'maxlag',
9
12
  'sparql-endpoint',
10
- 'verbose'
13
+ 'verbose',
11
14
  ]
12
- const { camelCase, snakeCase } = require('lodash')
13
15
 
14
- module.exports = program => {
16
+ export function applyEnvAndConfigDefault (program) {
15
17
  // If a --lang option is passed, it should be considered a request to not fallback on other langs
16
18
  if (program.lang != null) program.strictLang = program.lang
17
19
  fallbackConfigOptions.forEach(fallbackToConfigOption(program))
18
- program.lang = program.lang || config.lang || require('./local_lang')
20
+ program.lang = program.lang || config.lang || localLang
19
21
  }
20
22
 
21
23
  const fallbackToConfigOption = program => parameter => {
package/lib/chalk.js ADDED
@@ -0,0 +1,12 @@
1
+ import chalk from 'chalk'
2
+
3
+ export const bgBlue = chalk.bgBlue
4
+ export const bgGreen = chalk.bgGreen
5
+ export const bgMagenta = chalk.bgMagenta
6
+ export const blue = chalk.blue
7
+ export const green = chalk.green
8
+ export const grey = chalk.grey
9
+ export const inverse = chalk.inverse
10
+ export const red = chalk.red
11
+ export const white = chalk.white
12
+ export const yellow = chalk.yellow
@@ -1,18 +1,18 @@
1
- const program = require('commander')
2
- const path = require('path')
3
- const logCommandExamples = require('./log_command_examples')
4
- const { validateTemplateCommand } = require('./utils')
1
+ import { resolve } from 'node:path'
2
+ import program from 'commander'
3
+ import { validateTemplateCommand } from '#lib/utils'
4
+ import logCommandExamples from './log_command_examples.js'
5
5
 
6
6
  // Called when the -h,--help flag was set, and we now need to figure out what to display
7
- module.exports = () => {
7
+ export async function commandWithTemplateCustomHelp () {
8
8
  const { args } = program
9
9
  if (args.length === 0) return program.helpAndExit()
10
10
 
11
11
  let filePath, jsPath, jsModule
12
12
  try {
13
13
  filePath = args[0]
14
- jsPath = path.resolve(filePath)
15
- jsModule = require(jsPath)
14
+ jsPath = resolve(filePath)
15
+ ;({ default: jsModule } = await import(jsPath))
16
16
  } catch (err) {
17
17
  console.error("Couldn't parse template file metadata", err, { filePath, jsPath, jsModule })
18
18
  process.exit(1)
@@ -1,7 +1,9 @@
1
- const termCommandArgsParser = termType => ([ id, language, ...value ]) => {
2
- value = dropQuotes(value.join(' '))
3
- if (termType === 'alias') value = value.split('|')
4
- return [ { id, language, value } ]
1
+ export function termCommandArgsParser (termType) {
2
+ return function ([ id, language, ...value ]) {
3
+ value = dropQuotes(value.join(' '))
4
+ if (termType === 'alias') value = value.split('|')
5
+ return [ { id, language, value } ]
6
+ }
5
7
  }
6
8
 
7
9
  const dropQuotes = value => {
@@ -10,12 +12,7 @@ const dropQuotes = value => {
10
12
  return value
11
13
  }
12
14
 
13
- const badgesCommandArgsParser = ([ id, site, badges ]) => {
15
+ export function badgesCommandArgsParser ([ id, site, badges ]) {
14
16
  badges = badges.split(/[,|]/)
15
17
  return [ { id, site, badges } ]
16
18
  }
17
-
18
- module.exports = {
19
- termCommandArgsParser,
20
- badgesCommandArgsParser,
21
- }
@@ -1,9 +1,7 @@
1
- const { red } = require('chalk')
1
+ import { red } from '#lib/chalk'
2
2
 
3
- module.exports = {
4
- missingProperty: property => {
5
- console.error(red(`the property ${property} could not be found\n`) +
6
- 'run `wb props --reset` to refresh the local properties list')
7
- process.exit(1)
8
- }
3
+ export const missingProperty = property => {
4
+ console.error(red(`the property ${property} could not be found\n`) +
5
+ 'run `wb props --reset` to refresh the local properties list')
6
+ process.exit(1)
9
7
  }
@@ -1,25 +1,24 @@
1
- module.exports = {
2
- editCommands: {
3
- lang: false,
4
- verbose: true,
5
- dry: true,
6
- clipboard: false,
7
- json: false,
8
- instance: true,
9
- sparqlEndpoint: false,
10
- batch: true,
11
- noExitOnError: true,
12
- summary: true,
13
- baserevid: true,
14
- maxlag: true,
15
- },
16
- entityAttributeCommands: {
17
- lang: true,
18
- verbose: false,
19
- dry: false,
20
- clipboard: true,
21
- json: false,
22
- instance: true,
23
- sparqlEndpoint: false
24
- }
1
+ export const editCommandsOptions = {
2
+ lang: false,
3
+ verbose: true,
4
+ dry: true,
5
+ clipboard: false,
6
+ json: false,
7
+ instance: true,
8
+ sparqlEndpoint: false,
9
+ batch: true,
10
+ noExitOnError: true,
11
+ summary: true,
12
+ baserevid: true,
13
+ maxlag: true,
14
+ }
15
+
16
+ export const entityAttributeCommandsOptions = {
17
+ lang: true,
18
+ verbose: false,
19
+ dry: false,
20
+ clipboard: true,
21
+ json: false,
22
+ instance: true,
23
+ sparqlEndpoint: false,
25
24
  }
@@ -1,9 +1,14 @@
1
+ import { readJsonFile } from '#lib/json'
2
+ import { configFilePath } from './file_path.js'
3
+
1
4
  const isEnvTest = process.env.NODE_ENV === 'tests'
2
- if (isEnvTest) {
5
+
6
+ export let config = {}
7
+
3
8
  // Neutralize the local config for tests
4
- module.exports = {}
5
- } else {
6
- const filePath = require('./file_path')
9
+ if (!isEnvTest) {
7
10
  // Fallback to an empty config if no config path could be determined
8
- module.exports = filePath ? require(filePath) : {}
11
+ if (configFilePath) {
12
+ config = readJsonFile(configFilePath)
13
+ }
9
14
  }
@@ -1,9 +1,10 @@
1
- const fileOps = require('./file_operations')
2
- const errors_ = require('../errors')
3
- const { yellow, green } = require('chalk')
4
- const validateInstanceCredentials = require('../edit/validate_instance_credentials')
1
+ import { yellow, green } from '#lib/chalk'
2
+ import { initCredentials } from '#lib/edit/init_credentials'
3
+ import validateInstanceCredentials from '../edit/validate_instance_credentials.js'
4
+ import errors_ from '../errors.js'
5
+ import fileOps from './file_operations.js'
5
6
 
6
- module.exports = async (instance, arg) => {
7
+ export async function configurateCredentials (instance, arg) {
7
8
  const credentials = fileOps.get('credentials') || {}
8
9
  const knownInstance = Object.keys(credentials)
9
10
 
@@ -17,7 +18,7 @@ module.exports = async (instance, arg) => {
17
18
  console.log(yellow(`credentials for instance ${instance} not found`))
18
19
  if (knownInstance.length > 0) console.log(`\nKnown instance(s):\n\n${knownInstance.join('\n')}\n`)
19
20
  else console.log()
20
- return require('../edit/init_credentials')(instance)
21
+ return initCredentials(instance)
21
22
  }
22
23
 
23
24
  if (!arg) return console.log(JSON.stringify(instanceCredentials, null, 2))
@@ -1,13 +1,14 @@
1
1
  // Could be replaced by fs.promises.writeFile once we drop support for NodeJS <= v10
2
- const { writeFileSync } = require('fs')
3
- const errors_ = require('../errors')
4
- const valueParsers = require('../value_parsers')
5
- const parameters = require('./parameters')
2
+ import { writeFileSync } from 'node:fs'
3
+ import errors_ from '../errors.js'
4
+ import valueParsers from '../value_parsers.js'
5
+ import { config } from './config.js'
6
+ import { configFilePath } from './file_path.js'
7
+ import parameters from './parameters.js'
8
+
6
9
  const parametersKeys = Object.keys(parameters)
7
- const configFilePath = require('./file_path')
8
- const config = require('./config')
9
10
 
10
- module.exports = {
11
+ export default {
11
12
  get: key => {
12
13
  validateKey(key)
13
14
  const param = parameters[key]
@@ -37,7 +38,7 @@ module.exports = {
37
38
  configFilePath,
38
39
  clear: async () => {
39
40
  if (configFilePath) writeFileSync(configFilePath, '{}')
40
- }
41
+ },
41
42
  }
42
43
 
43
44
  const validateKey = key => {
@@ -1,17 +1,20 @@
1
- const fs = require('fs')
2
- const path = require('../path')
3
- const configFolder = require('../get_folder_path')('config')
1
+ import { accessSync, writeFileSync } from 'node:fs'
2
+ import configFolderFactory from '../get_folder_path.js'
3
+ import path from '../path.js'
4
+
5
+ const configFolder = configFolderFactory('config')
6
+
7
+ export let configFilePath
4
8
 
5
9
  if (configFolder != null) {
6
- const configPath = path.join(configFolder, 'config.json')
10
+ configFilePath = path.join(configFolder, 'config.json')
7
11
 
8
12
  try {
9
- fs.accessSync(configPath)
13
+ accessSync(configFilePath)
10
14
  } catch (err) {
11
15
  // Initialize if it doesn't exist
12
- fs.writeFileSync(configPath, '{}', { mode: 0o600 })
16
+ writeFileSync(configFilePath, '{}', { mode: 0o600 })
13
17
  }
14
- module.exports = configPath
15
18
  } else {
16
- module.exports = null
19
+ configFilePath = null
17
20
  }
@@ -1,45 +1,46 @@
1
- const { isPlainObject } = require('lodash')
1
+ import { isPlainObject } from 'lodash-es'
2
+ import { localLang } from '#lib/local_lang'
2
3
 
3
4
  const boolean = {
4
5
  type: 'boolean',
5
- default: false
6
+ default: false,
6
7
  }
7
8
 
8
9
  const integer = {
9
10
  type: 'number',
10
11
  default: 5,
11
- test: num => Number.isInteger(num) && num >= 0
12
+ test: num => Number.isInteger(num) && num >= 0,
12
13
  }
13
14
 
14
15
  const nonEmptyString = {
15
16
  type: 'string',
16
- test: str => typeof str === 'string' && str.length > 0
17
+ test: str => typeof str === 'string' && str.length > 0,
17
18
  }
18
19
 
19
20
  const object = {
20
21
  managed: true,
21
22
  type: 'object',
22
- test: isPlainObject
23
+ test: isPlainObject,
23
24
  }
24
25
 
25
26
  const url = defaultUrl => ({
26
27
  type: 'string',
27
28
  default: defaultUrl,
28
- test: url => nonEmptyString.test(url) && url.startsWith('http')
29
+ test: url => nonEmptyString.test(url) && url.startsWith('http'),
29
30
  })
30
31
 
31
- module.exports = {
32
+ export default {
32
33
  clipboard: boolean,
33
34
  json: boolean,
34
35
  lang: {
35
36
  type: 'lang',
36
- default: require('../local_lang'),
37
- test: str => typeof str === 'string' && str.length <= 3
37
+ default: localLang,
38
+ test: str => typeof str === 'string' && str.length <= 3,
38
39
  },
39
40
  verbose: boolean,
40
41
  credentials: object,
41
42
  bot: boolean,
42
43
  maxlag: integer,
43
44
  instance: url('https://wikidata.org'),
44
- 'sparql-endpoint': url('https://query.wikidata.org/sparql')
45
+ 'sparql-endpoint': url('https://query.wikidata.org/sparql'),
45
46
  }
@@ -1,13 +1,15 @@
1
1
  // Convert external ids to Wikibase ids
2
2
 
3
- const { chunk, uniq } = require('lodash')
4
- const makeSparqlQuery = require('./make_sparql_query')
5
- const program = require('./program')
6
- const { average } = require('./utils')
7
- const output = require('./output')(program)
8
- const errors_ = require('./errors')
9
-
10
- module.exports = async (property, ids, fromWdIds) => {
3
+ import { chunk, uniq } from 'lodash-es'
4
+ import errors_ from './errors.js'
5
+ import makeSparqlQuery from './make_sparql_query.js'
6
+ import { outputFactory } from './output.js'
7
+ import program from './program.js'
8
+ import { average } from './utils.js'
9
+
10
+ const output = outputFactory(program)
11
+
12
+ export default async (property, ids, fromWdIds) => {
11
13
  ids = uniq(ids)
12
14
  if (ids.length === 0) return output({})
13
15
  const sparqlBuilder = fromWdIds ? fromWbIds : fromExternalIds
package/lib/copy.js CHANGED
@@ -1,6 +1,6 @@
1
- const { copy } = require('copy-paste')
1
+ import { copy } from 'copy-paste'
2
2
 
3
- module.exports = text => {
3
+ export function copyAndExit (text) {
4
4
  copy(text, () => {
5
5
  console.log(text)
6
6
  process.exit(0)
@@ -1,13 +1,13 @@
1
- const _ = require('lodash')
1
+ import { pick } from 'lodash-es'
2
2
 
3
- module.exports = (entity, requestedPropsAndSubProps) => {
3
+ export default (entity, requestedPropsAndSubProps) => {
4
4
  if (!requestedPropsAndSubProps) return
5
5
 
6
6
  const requestedProps = Object.keys(requestedPropsAndSubProps)
7
7
  requestedProps.forEach(prop => {
8
8
  const subkeys = Object.keys(requestedPropsAndSubProps[prop])
9
9
  if (subkeys && subkeys.length > 0) {
10
- entity[prop] = _.pick(entity[prop], subkeys)
10
+ entity[prop] = pick(entity[prop], subkeys)
11
11
  subkeys.forEach(subkey => {
12
12
  if (!entity[prop][subkey]) entity[prop][subkey] = null
13
13
  })
@@ -1,7 +1,7 @@
1
- const { yellow } = require('chalk')
2
- const initCredentials = require('./init_credentials')
1
+ import { yellow } from '#lib/chalk'
2
+ import { initCredentials } from './init_credentials.js'
3
3
 
4
- module.exports = async ({ instance, credentials, batch }) => {
4
+ export default async ({ instance, credentials, batch }) => {
5
5
  if (!credentials) return requestCredentials(instance, batch)
6
6
 
7
7
  const instanceCredentials = credentials[instance]
@@ -1,15 +1,15 @@
1
- const program = require('../program')
2
- const wbEdit = require('wikibase-edit')
3
- const parseObjectValue = require('./parse_object_value')
4
- const parseBatchLine = require('./parse_batch_line')
5
- const assertCredentials = require('./assert_credentials')
6
- const split = require('split')
7
- const config = require('../config/config')
8
- const errors_ = require('../errors')
9
- const { red } = require('chalk')
10
- const { inspect } = require('util')
11
-
12
- module.exports = async (section, action) => {
1
+ import { inspect } from 'node:util'
2
+ import split from 'split'
3
+ import wbEdit from 'wikibase-edit'
4
+ import { red } from '#lib/chalk'
5
+ import { config } from '../config/config.js'
6
+ import errors_ from '../errors.js'
7
+ import program from '../program.js'
8
+ import assertCredentials from './assert_credentials.js'
9
+ import parseBatchLine from './parse_batch_line.js'
10
+ import parseObjectValue from './parse_object_value.js'
11
+
12
+ export async function execEditCommand (section, action) {
13
13
  let name
14
14
  if (typeof section === 'object') {
15
15
  // Pass a name when it can not be deduced from the wikibase-edit section
@@ -19,7 +19,7 @@ module.exports = async (section, action) => {
19
19
  } else {
20
20
  name = `${action}-${section}`
21
21
  }
22
- program.process(name)
22
+ await program.process(name)
23
23
 
24
24
  if (program.showHelp) return program.customHelpOption()
25
25
 
@@ -58,13 +58,13 @@ const instanceHint = `* Wikidata: use the 'wd' executable
58
58
  * set the '--instance <http://my.instance>' option
59
59
  * or set the instance in config: 'wb config instance http://my.instance'`
60
60
 
61
- const runOnce = async (section, action, args) => {
61
+ async function runOnce (section, action, args) {
62
62
  // Allow to define a customArgsParser on program to convert the command-line input
63
63
  // into what the wikibase-edit interface expects.
64
64
  // Running this after program.process allows to pass after the options
65
65
  // where removed from the args array
66
66
  if (program.customArgsParser) {
67
- args = program.customArgsParser(args)
67
+ args = await program.customArgsParser(args)
68
68
  }
69
69
 
70
70
  // Resolve arguments that might be promises
@@ -78,7 +78,7 @@ const runOnce = async (section, action, args) => {
78
78
  // and keep cached data such as properties
79
79
  let wbEditConfig
80
80
 
81
- const runEditCommand = async (section, action, args) => {
81
+ async function runEditCommand (section, action, args) {
82
82
  if (program.dry) {
83
83
  if (args.length > 0) console.log(JSON.stringify({ section, action, args }))
84
84
  return
@@ -100,7 +100,7 @@ const runEditCommand = async (section, action, args) => {
100
100
  }
101
101
  }
102
102
 
103
- const getWbEditConfig = () => {
103
+ function getWbEditConfig () {
104
104
  const { editGroup } = program
105
105
  let { summary, baserevid, maxlag } = program
106
106
 
@@ -135,11 +135,11 @@ const getWbEditConfig = () => {
135
135
  bot: config.bot,
136
136
  maxlag,
137
137
  // maxlag=-1 can be used for testing that passing maxlag does work
138
- autoRetry: maxlag !== -1
138
+ autoRetry: maxlag !== -1,
139
139
  }
140
140
  }
141
141
 
142
- const runInBatch = (section, action, exitOnError) => {
142
+ function runInBatch (section, action, exitOnError) {
143
143
  let counter = 0
144
144
  let successes = 0
145
145
  let errors = 0
@@ -1,9 +1,9 @@
1
- const prompt = require('./prompt')
2
- const { green, red } = require('chalk')
3
- const configOps = require('../config/file_operations')
4
- const validateInstanceCredentials = require('./validate_instance_credentials')
1
+ import { green, red } from '#lib/chalk'
2
+ import configOps from '../config/file_operations.js'
3
+ import prompt from './prompt.js'
4
+ import validateInstanceCredentials from './validate_instance_credentials.js'
5
5
 
6
- module.exports = instance => {
6
+ export async function initCredentials (instance) {
7
7
  return chooseCredentialsType(instance)
8
8
  .catch(cleanExitOnPromptCancelation)
9
9
  }
@@ -14,8 +14,8 @@ const chooseCredentialsType = async instance => {
14
14
  key: 'type',
15
15
  label: `Which authentication mechanism would you like to use to login to ${instance} ?`,
16
16
  info: '/!\\ Beware that those will be stored in plain text on your computer',
17
- options: [ 'username - password', 'OAuth tokens' ]
18
- }
17
+ options: [ 'username - password', 'OAuth tokens' ],
18
+ },
19
19
  ])
20
20
  if (type === '1') {
21
21
  await requestUsernameAndPassword(instance)
@@ -47,7 +47,7 @@ In case you don't have a sufficiant authorization level and thus can't create an
47
47
  { key: 'consumer_key', label: 'Consumer token', pattern: patterns.key },
48
48
  { key: 'consumer_secret', label: 'Consumer secret', pattern: patterns.secret },
49
49
  { key: 'token', label: 'Access token', pattern: patterns.key },
50
- { key: 'token_secret', label: 'Access secret', pattern: patterns.secret }
50
+ { key: 'token_secret', label: 'Access secret', pattern: patterns.secret },
51
51
  ])
52
52
  const credentials = { oauth: oauthTokens }
53
53
  return getTokenOrRetry({ instance, credentials })
@@ -55,13 +55,13 @@ In case you don't have a sufficiant authorization level and thus can't create an
55
55
 
56
56
  const patterns = {
57
57
  key: /^[0-9a-f]{32}$/,
58
- secret: /^[0-9a-f]{40}$/
58
+ secret: /^[0-9a-f]{40}$/,
59
59
  }
60
60
 
61
61
  const prefilledParams = [
62
62
  'wpname=wikibase-cli-myusername',
63
63
  'wpdescription=tokens%20for%20wikibase-cli%20%28https%3A%2F%2Fgithub.com%2Fmaxlath%2Fwikibase-cli%29',
64
- 'wpownerOnly=1'
64
+ 'wpownerOnly=1',
65
65
  ].join('&')
66
66
 
67
67
  const oauthConsumerRegistrationPathname = `/wiki/Special:OAuthConsumerRegistration/propose/oauth1a?${prefilledParams}`
@@ -80,7 +80,7 @@ This is especially recommended as those credentials will be saved in plain text
80
80
  `)
81
81
  return prompt([
82
82
  { key: 'username', pattern: nonEmptyStringPattern },
83
- { key: 'password', pattern: nonEmptyStringPattern }
83
+ { key: 'password', pattern: nonEmptyStringPattern },
84
84
  ])
85
85
  .then(({ username, password }) => {
86
86
  const credentials = { username, password }
@@ -1,9 +1,9 @@
1
1
  // Args can't be just a line splitted on spaces
2
2
  // as there are JSON strings arguments, and signle or double quoted strings args
3
3
 
4
- const { parse } = require('shell-quote')
4
+ import parse from 'shell-quote/parse.js'
5
5
 
6
- module.exports = line => {
6
+ export default line => {
7
7
  // One JSON object as single argument
8
8
  // typically for (create|edit)-entity commands
9
9
  // ex: { "id": "Q1", "labels": { "en": "foo" } }
@@ -1,13 +1,14 @@
1
- const qs = require('querystring')
2
- const errors_ = require('../errors')
3
- const { isPlainObject } = require('lodash')
1
+ import qs from 'node:querystring'
2
+ import { isPlainObject } from 'lodash-es'
3
+ import errors_ from '../errors.js'
4
+
4
5
  const stringValueKeys = [
5
6
  'value',
6
7
  'oldValue',
7
- 'newValue'
8
+ 'newValue',
8
9
  ]
9
10
 
10
- module.exports = value => {
11
+ export default value => {
11
12
  if (isPlainObject(value)) {
12
13
  stringValueKeys.forEach(parseObjKeyValue(value))
13
14
  return value
@@ -1,8 +1,7 @@
1
- const { promisify } = require('util')
2
- const read = promisify(require('read'))
3
- const { blue, yellow, grey } = require('chalk')
1
+ import read from 'read'
2
+ import { blue, yellow, grey } from '#lib/chalk'
4
3
 
5
- module.exports = readsData => {
4
+ export default readsData => {
6
5
  const results = {}
7
6
 
8
7
  const promptSequentially = async () => {
@@ -1,6 +1,6 @@
1
- const wbEdit = require('wikibase-edit')
1
+ import wbEdit from 'wikibase-edit'
2
2
 
3
- module.exports = async ({ instance, credentials }) => {
3
+ export default async ({ instance, credentials }) => {
4
4
  const { token } = await wbEdit({ instance, credentials }).getAuthData()()
5
5
  if (token.length !== 42) throw new Error('invalid credentials')
6
6
  }
@@ -1,10 +1,10 @@
1
- const entityDataParser = require('./entity_data_parser')
2
- const entityAttributeParser = require('./entity_attribute_parser')
3
- const pluralize = require('./pluralize')
4
- const { grey, red } = require('chalk')
5
- const _ = require('lodash')
1
+ import { max, padEnd, values } from 'lodash-es'
2
+ import { grey, red } from '#lib/chalk'
3
+ import entityAttributeParser from './entity_attribute_parser.js'
4
+ import { entityDataParser } from './entity_data_parser.js'
5
+ import pluralize from './pluralize.js'
6
6
 
7
- module.exports = (attribute, extraParams) => {
7
+ export async function entityAttributeCommand (attribute, extraParams) {
8
8
  let commandName, ids
9
9
  if (extraParams) {
10
10
  ids = extraParams.ids
@@ -15,13 +15,13 @@ module.exports = (attribute, extraParams) => {
15
15
  const props = [ pluarlizedAttribute ]
16
16
 
17
17
  const parser = async ({ lang, strictLang, output, entities }) => {
18
- const entitiesList = _.values(entities)
18
+ const entitiesList = values(entities)
19
19
  const multiEntities = entitiesList.length > 1
20
- const maxLength = _.max(entitiesList.map(entity => entity.id.length)) + 1
20
+ const maxLength = max(entitiesList.map(entity => entity.id.length)) + 1
21
21
  entitiesList.forEach(logAttribute(attribute, lang, strictLang, multiEntities, maxLength, output))
22
22
  }
23
23
 
24
- entityDataParser({ commandName, props, parser, ids })
24
+ await entityDataParser({ commandName, props, parser, ids })
25
25
  }
26
26
 
27
27
  const logAttribute = (attribute, lang, strictLang, multiEntities, maxLength, output) => entity => {
@@ -38,7 +38,7 @@ const logAttribute = (attribute, lang, strictLang, multiEntities, maxLength, out
38
38
  }
39
39
  // Prefix value with the id if there are multiple entities
40
40
  if (multiEntities) {
41
- console.log(grey(_.padEnd(entity.id, maxLength)), value || grey('not found'))
41
+ console.log(grey(padEnd(entity.id, maxLength)), value || grey('not found'))
42
42
  } else {
43
43
  output(value)
44
44
  }