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
package/README.md CHANGED
@@ -54,7 +54,7 @@ See [CHANGELOG.md](CHANGELOG.md) for version info
54
54
  ## Dependencies
55
55
 
56
56
  ### General
57
- * [NodeJs](https://nodejs.org) **>= v10** (recommended way to install it: use the awesome [NVM](https://github.com/creationix/nvm) to install the latest LTS version `nvm install --lts`)
57
+ * [NodeJs](https://nodejs.org) **>= v14** (recommended way to install it: use the awesome [NVM](https://github.com/creationix/nvm) to install the latest LTS version `nvm install --lts`)
58
58
  * [Git](https://git-scm.com/)
59
59
 
60
60
  ### Per feature
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { termCommandArgsParser } from '#lib/common_command_args_parser'
5
+ import { execEditCommand } from '#lib/edit/edit_command'
6
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
7
+
8
+ program.customArgsParser = polymorphicCommandArgsParser({
9
+ inlineArgsParser: termCommandArgsParser('alias'),
10
+ })
11
+ program.customHelpOption = commandWithTemplateCustomHelp
12
+ execEditCommand('alias', 'add')
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { badgesCommandArgsParser } from '#lib/common_command_args_parser'
5
+ import { execEditCommand } from '#lib/edit/edit_command'
6
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
7
+
8
+ program.customArgsParser = polymorphicCommandArgsParser({
9
+ inlineArgsParser: badgesCommandArgsParser,
10
+ })
11
+ program.customHelpOption = commandWithTemplateCustomHelp
12
+ execEditCommand('badge', 'add')
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
6
+
7
+ const inlineArgsParser = ([ id, property, value ]) => {
8
+ const data = { id, property, value }
9
+ if (program.rank) data.rank = program.rank
10
+ return [ data ]
11
+ }
12
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
13
+ program.customHelpOption = commandWithTemplateCustomHelp
14
+ execEditCommand('claim', 'add')
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { parseGuid } from '#lib/parse_command_utils'
6
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
7
+
8
+ const inlineArgsParser = ([ guid, property, value ]) => {
9
+ guid = parseGuid(guid)
10
+ return [ { guid, property, value } ]
11
+ }
12
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
13
+ program.customHelpOption = commandWithTemplateCustomHelp
14
+ execEditCommand('qualifier', 'add')
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { parseGuid } from '#lib/parse_command_utils'
6
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
7
+
8
+ const inlineArgsParser = ([ guid, property, value ]) => {
9
+ guid = parseGuid(guid)
10
+ return [ { guid, property, value } ]
11
+ }
12
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
13
+ program.customHelpOption = commandWithTemplateCustomHelp
14
+ execEditCommand('reference', 'add')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { entityAttributeCommand } from '#lib/entity_attribute_command'
3
+
4
+ entityAttributeCommand('aliases')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ import { entityAttributeCommand } from '#lib/entity_attribute_command'
3
+ import errors_ from '#lib/errors'
4
+ import { exitOnMissingInstance } from '#lib/exit_on_missing'
5
+ import program from '#lib/program'
6
+ import { get } from '#lib/request'
7
+
8
+ await program.process('badges')
9
+
10
+ const { instance } = program
11
+
12
+ exitOnMissingInstance(instance)
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)
@@ -1,19 +1,23 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
2
+ import { getStatementsKey } from 'wikibase-edit/lib/parse_instance.js'
3
+ import { isPropertyId, simplifyClaims, simplifyPropertyClaims } from 'wikibase-sdk'
4
+ import { yellow } from '#lib/chalk'
5
+ import errors_ from '#lib/errors'
6
+ import { exitOnMissingInstance } from '#lib/exit_on_missing'
7
+ import getEntities from '#lib/get_entities'
8
+ import { getEntityLabel } from '#lib/get_entities_labels'
9
+ import logClaims from '#lib/log_claims'
10
+ import { outputFactory } from '#lib/output'
11
+ import program from '#lib/program'
12
+ import { tolerantIdParserFactory } from '#lib/tolerant_id_parser'
3
13
 
4
- program
14
+ await program
5
15
  .option('-a, --all', 'include all claims, not only the truthy ones')
6
16
  .option('-t, --type <type>', 'Keep only claims with the specified datatype')
7
17
  .process('claims')
8
18
 
9
- const { yellow } = require('chalk')
10
- const parseId = require('../lib/tolerant_id_parser')()
11
- const logClaims = require('../lib/log_claims')
12
- const getEntities = require('../lib/get_entities')
13
- const { getEntityLabel } = require('../lib/get_entities_labels')
14
- const errors_ = require('../lib/errors')
15
- require('../lib/exit_on_missing').instance(program.instance)
16
- const { isPropertyId, simplify } = require('../lib/wbk')(program)
19
+ const parseId = tolerantIdParserFactory()
20
+ exitOnMissingInstance(program.instance)
17
21
 
18
22
  let [ id, ...filter ] = program.args
19
23
  id = id && parseId(id)
@@ -27,7 +31,7 @@ if (isPropertyId(filter[0])) {
27
31
  }
28
32
 
29
33
  const { lang } = program
30
- const output = require('../lib/output')(program)
34
+ const output = outputFactory(program)
31
35
 
32
36
  if (!(id && lang)) program.helpAndExit(0)
33
37
 
@@ -44,17 +48,18 @@ const run = async () => {
44
48
  errors_.exitMessage(`entity not found: ${program.instance}/entity/${id}`)
45
49
  }
46
50
 
51
+ const statementsKey = getStatementsKey(program.instance)
47
52
  const keepNonTruthy = program.all === true
48
53
  if (isPropertyId(prop) && value != null) {
49
- const propClaims = entity.claims[prop]
54
+ const propClaims = entity[statementsKey][prop]
50
55
  if (!propClaims) throw new Error(`no claims found for this property: ${prop}`)
51
- const ids = simplify.propertyClaims(propClaims, { keepIds: true, keepNonTruthy })
56
+ const ids = simplifyPropertyClaims(propClaims, { keepIds: true, keepNonTruthy })
52
57
  .filter(simplifyClaim => simplifyClaim.value === value)
53
58
  .map(simplifyClaim => simplifyClaim.id)
54
59
  return output(ids)
55
60
  }
56
61
 
57
- const simplifiedClaims = simplify.claims(entity.claims, { keepNonTruthy })
62
+ const simplifiedClaims = simplifyClaims(entity[statementsKey], { keepNonTruthy })
58
63
  if (!prop) return logClaims({ program, simplifiedClaims, pattern, resort: true })
59
64
 
60
65
  value = simplifiedClaims[prop]
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
3
- program.process('config')
4
- const { green } = require('chalk')
5
- const fileOps = require('../lib/config/file_operations')
6
- const config = require('../lib/config/config')
2
+ import { green } from '#lib/chalk'
3
+ import { config } from '#lib/config/config'
4
+ import { configurateCredentials } from '#lib/config/credentials_config'
5
+ import fileOps from '#lib/config/file_operations'
6
+ import program from '#lib/program'
7
+
8
+ await program.process('config')
7
9
 
8
10
  const { args, json } = program
9
11
 
@@ -25,7 +27,7 @@ if (key === 'path') {
25
27
  } else if (key === 'clear' || key === 'reset') {
26
28
  fileOps.clear()
27
29
  } else if (key === 'credentials') {
28
- require('../lib/config/credentials_config')(value, value2)
30
+ configurateCredentials(value, value2)
29
31
  } else if (value == null) {
30
32
  console.log(fileOps.get(key))
31
33
  } else {
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
3
- const errors_ = require('../lib/errors')
4
- const convertIds = require('../lib/convert_ids')
5
- const { isPropertyId } = require('wikibase-sdk')
2
+ import { isPropertyId } from 'wikibase-sdk'
3
+ import convertIds from '#lib/convert_ids'
4
+ import errors_ from '#lib/errors'
5
+ import { getStdinInput } from '#lib/get_stdin_input'
6
+ import program from '#lib/program'
6
7
 
7
- program
8
+ await program
8
9
  .option('-s, --subjects [subjects...]', 'set a subject')
9
10
  .option('-p, --property <property>', 'set a property')
10
11
  .option('-o, --objects [objects...]', 'set an object')
@@ -36,11 +37,9 @@ if (ids && ids.length > 0) {
36
37
  } else if (process.stdin.isTTY) {
37
38
  errors_.bundle('no ids provided', { property })
38
39
  } else {
39
- require('../lib/get_stdin_input')()
40
- .then(input => {
41
- input = input.trim()
42
- let ids = input.split(/\s+/)
43
- if (ids.length === 1 && ids[0] === '') ids = []
44
- convertIds(property, ids, fromWdIds)
45
- })
40
+ let input = await getStdinInput()
41
+ input = input.trim()
42
+ let ids = input.split(/\s+/)
43
+ if (ids.length === 1 && ids[0] === '') ids = []
44
+ await convertIds(property, ids, fromWdIds)
46
45
  }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { objectArgParser } from '#lib/object_arg_parser'
6
+
7
+ program.customArgsParser = objectArgParser
8
+
9
+ program.customHelpOption = commandWithTemplateCustomHelp
10
+ execEditCommand('entity', 'create')
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
2
+ import { isGuid, isPropertyClaimsId } from 'wikibase-sdk'
3
+ import { parseGuid } from '#lib/parse_command_utils'
4
+ import program from '#lib/program'
5
+ import { tolerantIdParserFactory } from '#lib/tolerant_id_parser'
3
6
 
4
- program
7
+ await program
5
8
  .option('-s, --simplify', 'get simplified entities data')
6
9
  .option('-k, --keep <props>', 'data to keep when simplifying claims (ids,richvalues,types,references,qualifiers,hashes,nontruthy,nondeprecated,ranks)')
7
10
  .option('--time-converter <converter>', 'specify which time format should be used when simplifying')
@@ -10,26 +13,26 @@ program
10
13
  .option('-f, --format <format>', 'Default: ndjson. Alternatives: ttl')
11
14
  .process('data')
12
15
 
13
- const { isGuid, isPropertyClaimsId } = require('wikibase-sdk')
14
- const { parseGuid } = require('../lib/parse_command_utils')
15
-
16
16
  const firstArg = program.args[0]
17
17
 
18
18
  let guid
19
19
  if (firstArg && isGuid(parseGuid(firstArg))) guid = parseGuid(firstArg)
20
20
 
21
21
  if (program.args.length === 1 && guid) {
22
- require('../lib/fetch_and_log_guid_data')(guid)
22
+ const { fetchAndLogGuidData } = await import('#lib/fetch_and_log_guid_data')
23
+ fetchAndLogGuidData(guid)
23
24
  } else if (program.args.length === 1 && isPropertyClaimsId(firstArg)) {
24
- require('../lib/fetch_and_log_property_claims_data')(firstArg)
25
+ const { fetchAndLogPropertyClaimsData } = await import('#lib/fetch_and_log_property_claims_data')
26
+ fetchAndLogPropertyClaimsData(firstArg)
25
27
  } else {
26
- const parseId = require('../lib/tolerant_id_parser')({ allowEntitiesSchemasIds: true })
28
+ const parseId = tolerantIdParserFactory({ allowEntitiesSchemasIds: true })
27
29
  const ids = program.args.map(parseId)
28
30
  const { revision } = program
29
31
 
30
32
  if (revision) {
31
33
  if (ids.length === 1) {
32
- require('../lib/fetch_and_log_entity_revision')(ids[0], revision)
34
+ const { fetchAndLogEntityRevision } = await import('#lib/fetch_and_log_entity_revision')
35
+ fetchAndLogEntityRevision(ids[0], revision)
33
36
  } else {
34
37
  throw new Error('a revision can be specified when only one entity is fetched')
35
38
  }
@@ -38,12 +41,13 @@ if (program.args.length === 1 && guid) {
38
41
  // its stdin from another process
39
42
  if (ids.length === 0 && process.stdin.isTTY) program.helpAndExit(0)
40
43
 
41
- const fetchAndLogIdsData = require('../lib/fetch_and_log_ids_data')
44
+ const { fetchAndLogIdsData } = await import('#lib/fetch_and_log_ids_data')
42
45
 
43
46
  if (ids.length > 0) {
44
47
  fetchAndLogIdsData(ids)
45
48
  } else {
46
- require('../lib/read_ids_from_stdin')(fetchAndLogIdsData)
49
+ const { readIdsFromStdin } = await import('#lib/read_ids_from_stdin')
50
+ readIdsFromStdin(fetchAndLogIdsData)
47
51
  }
48
52
  }
49
53
  }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
6
+
7
+ const inlineArgsParser = args => [ { id: args[0] } ]
8
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
9
+ program.customHelpOption = commandWithTemplateCustomHelp
10
+ execEditCommand('entity', 'delete')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { entityAttributeCommand } from '#lib/entity_attribute_command'
3
+
4
+ entityAttributeCommand('description')
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { objectArgParser } from '#lib/object_arg_parser'
6
+
7
+ program.customArgsParser = objectArgParser
8
+
9
+ program.customHelpOption = commandWithTemplateCustomHelp
10
+ execEditCommand('entity', 'edit')
@@ -1,7 +1,15 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
2
+ import { isEntityId } from 'wikibase-sdk'
3
+ import { exitOnMissingInstance } from '#lib/exit_on_missing'
4
+ import { getEntitiesByBatches } from '#lib/get_entities_by_batches'
5
+ import { outputTemplatesFactory } from '#lib/output_templates'
6
+ import parseProps from '#lib/parse_props'
7
+ import program from '#lib/program'
8
+ import { readIdsFromStdin } from '#lib/read_ids_from_stdin'
9
+ import { tolerantIdParserFactory } from '#lib/tolerant_id_parser'
10
+ import wbk from '#lib/wbk'
3
11
 
4
- program
12
+ await program
5
13
  .option('-p, --props <props>', 'request only certain properties (info, sitelinks, aliases, labels, descriptions, claims, datatype)')
6
14
  .option('-r, --revision <id>', 'request a specific revision')
7
15
  .option('-f, --format <format>', 'Default: js when fetching a single entity, json otherwise. Note that the -j, --json option is equivalent to "--format json"')
@@ -9,16 +17,16 @@ program
9
17
  .option('-z, --no-minimize', 'disable claims minimization, making the output format more predictable; i.e. single claims will still be in arrays')
10
18
  .process('generate-template')
11
19
 
12
- const parseId = require('../lib/tolerant_id_parser')()
20
+ const parseId = tolerantIdParserFactory()
21
+
13
22
  const ids = program.args.map(parseId)
14
- require('../lib/exit_on_missing').instance(program.instance)
15
- const { isEntityId, getEntityRevision, getManyEntities } = require('../lib/wbk')(program)
16
- const parseProps = require('../lib/parse_props')
23
+ exitOnMissingInstance(program.instance)
24
+
25
+ const { getEntityRevision, getManyEntities } = wbk(program)
26
+
17
27
  const { revision, minimize } = program
18
28
  let { format, json } = program
19
29
  if (format == null && json) format = 'json'
20
- const getEntitiesByBatches = require('../lib/get_entities_by_batches')
21
- const outputTemplates = require('../lib/output_templates')
22
30
 
23
31
  const requestedPropsAndSubProps = parseProps(program.props)
24
32
  const requestedProps = Object.keys(requestedPropsAndSubProps)
@@ -26,8 +34,11 @@ const requestedProps = Object.keys(requestedPropsAndSubProps)
26
34
  const requiredKeys = [ 'id', 'type', 'datatype', 'labels', 'descriptions', 'aliases', 'claims', 'sitelinks' ]
27
35
 
28
36
  let propsToPick
29
- if (revision && requestedProps.length > 0) propsToPick = [ 'id' ].concat(requestedProps)
30
- else propsToPick = requiredKeys
37
+ if (revision && requestedProps.length > 0) {
38
+ propsToPick = [ 'id' ].concat(requestedProps)
39
+ } else {
40
+ propsToPick = requiredKeys
41
+ }
31
42
 
32
43
  const handleIds = async ids => {
33
44
  ids.forEach(id => {
@@ -45,19 +56,19 @@ const handleIds = async ids => {
45
56
  let urls
46
57
  if (revision) {
47
58
  if (ids.length !== 1) throw new Error(`requesting a revision for several entities isn't supported: ${ids}`)
48
- urls = [ getEntityRevision(ids[0], revision) ]
59
+ urls = [ getEntityRevision({ id: ids[0], revision }) ]
49
60
  } else {
50
61
  urls = getManyEntities({ ids, props: requestedProps })
51
62
  }
52
63
 
53
64
  return getEntitiesByBatches({
54
65
  urls,
55
- onResponse: outputTemplates({ batchMode, format, propsToPick, requestedPropsAndSubProps, minimize })
66
+ onResponse: outputTemplatesFactory({ batchMode, format, propsToPick, requestedPropsAndSubProps, minimize }),
56
67
  })
57
68
  }
58
69
 
59
70
  if (ids.length > 0) {
60
71
  handleIds(ids)
61
72
  } else {
62
- require('../lib/read_ids_from_stdin')(handleIds)
73
+ readIdsFromStdin(handleIds)
63
74
  }
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
2
+ import errors_ from '#lib/errors'
3
+ import { openUrl } from '#lib/open'
4
+ import { outputFactory } from '#lib/output'
5
+ import program from '#lib/program'
6
+ import { get } from '#lib/request'
3
7
 
4
- program
8
+ await program
5
9
  .option('-o, --open', 'open the found URL in a web browser')
6
10
  .option('-u, --url', 'simply generate the url')
7
11
  .process('hub')
@@ -21,13 +25,11 @@ if (!(open || urlOnly)) argsString += ' format=json'
21
25
  const query = encodeURIComponent(argsString)
22
26
  const url = `https://hub.toolforge.org/query?q=${query}`
23
27
 
24
- const errors_ = require('../lib/errors')
25
-
26
28
  if (open || urlOnly) {
27
- require('../lib/open')(url)
29
+ openUrl(url)
28
30
  } else {
29
- const output = require('../lib/output')(program)
30
- require('../lib/request').get(url)
31
+ const output = outputFactory(program)
32
+ get(url)
31
33
  .then(body => {
32
34
  if (json) return output(body)
33
35
  const { url: destinationUrl } = body.destination
@@ -1,17 +1,21 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
2
+ import { values, map } from 'lodash-es'
3
+ import errors_ from '#lib/errors'
4
+ import { exitOnMissingInstance } from '#lib/exit_on_missing'
5
+ import getRedirectedSitelinkTitle from '#lib/get_redirected_sitelink_title'
6
+ import { outputFactory } from '#lib/output'
7
+ import program from '#lib/program'
8
+ import { get } from '#lib/request'
9
+ import wbk from '#lib/wbk'
3
10
 
4
- program.process('id')
11
+ await program.process('id')
5
12
 
6
- require('../lib/exit_on_missing').instance(program.instance)
7
- const { getEntitiesFromSitelinks } = require('../lib/wbk')(program)
8
- const { get } = require('../lib/request')
9
- const errors_ = require('../lib/errors')
10
- const _ = require('lodash')
11
- const getRedirectedSitelinkTitle = require('../lib/get_redirected_sitelink_title')
13
+ exitOnMissingInstance(program.instance)
14
+
15
+ const { getEntitiesFromSitelinks } = wbk(program)
12
16
 
13
17
  let { lang } = program
14
- const output = require('../lib/output')(program)
18
+ const output = outputFactory(program)
15
19
 
16
20
  // allow to pass a title without having to put it in ""
17
21
  let title = program.args.join(' ')
@@ -53,8 +57,7 @@ const parseIds = ({ body, context }) => {
53
57
  }
54
58
 
55
59
  const formatDescriptions = descriptions => {
56
- return _.values(descriptions)
57
- .map(_.property('value'))
60
+ return map(values(descriptions), 'value')
58
61
  .join('\n')
59
62
  }
60
63
 
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { entityAttributeCommand } from '#lib/entity_attribute_command'
3
+
4
+ entityAttributeCommand('label')
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
- const program = require('../lib/program')
2
+ import wdLang from 'wikidata-lang'
3
+ import { findMatchingLang, formatLangs } from '#lib/matching_langs'
4
+ import { outputFactory } from '#lib/output'
5
+ import program from '#lib/program'
3
6
 
4
- program
5
- .process('lang')
7
+ await program.process('lang')
6
8
 
7
- const wdLang = require('wikidata-lang')
8
- const output = require('../lib/output')(program)
9
+ const output = outputFactory(program)
9
10
 
10
11
  const { args, json } = program
11
12
 
@@ -24,10 +25,9 @@ if (input.match(/Q\d+/) != null) {
24
25
  if (langData != null) {
25
26
  output(langData)
26
27
  } else {
27
- const { find, format } = require('../lib/matching_langs')
28
- let matchingLangs = find(input)
28
+ let matchingLangs = findMatchingLang(input)
29
29
  if (matchingLangs.length > 0) {
30
- if (!json) matchingLangs = format(matchingLangs)
30
+ if (!json) matchingLangs = formatLangs(matchingLangs)
31
31
  output(matchingLangs)
32
32
  } else {
33
33
  console.error("couldn't find a language from input", input)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { entityAttributeCommand } from '#lib/entity_attribute_command'
3
+
4
+ entityAttributeCommand('lemma')
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
- const program = require('commander')
3
- const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
2
+ import program from 'commander'
3
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
4
+ import { execEditCommand } from '#lib/edit/edit_command'
5
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
4
6
 
5
7
  const inlineArgsParser = args => {
6
8
  if (program.keepOldest) {
@@ -20,5 +22,5 @@ const getSortedEntitiesIds = args => {
20
22
  const getNumericId = id => parseInt(id.replace(/^[A-Z]+/i, ''))
21
23
 
22
24
  program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
23
- program.customHelpOption = require('../lib/command_with_template_custom_help')
24
- require('../lib/edit/edit_command')('entity', 'merge')
25
+ program.customHelpOption = commandWithTemplateCustomHelp
26
+ execEditCommand('entity', 'merge')
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { isPropertyClaimsId } from 'wikibase-sdk'
4
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
5
+ import { execEditCommand } from '#lib/edit/edit_command'
6
+ import { parseGuid } from '#lib/parse_command_utils'
7
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
8
+
9
+ const inlineArgsParser = args => {
10
+ let [ guid, id, property ] = args
11
+ if (isPropertyClaimsId(guid)) {
12
+ return [ { propertyClaimsId: guid, id, property } ]
13
+ } else {
14
+ guid = parseGuid(guid)
15
+ return [ { guid, id, property } ]
16
+ }
17
+ }
18
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
19
+ program.customHelpOption = commandWithTemplateCustomHelp
20
+ execEditCommand('claim', 'move')
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import program from 'commander'
3
+ import { isHash } from 'wikibase-sdk'
4
+ import { commandWithTemplateCustomHelp } from '#lib/command_with_template_custom_help'
5
+ import { execEditCommand } from '#lib/edit/edit_command'
6
+ import { parseGuid } from '#lib/parse_command_utils'
7
+ import { polymorphicCommandArgsParser } from '#lib/polymorphic_command_args_parser'
8
+
9
+ const inlineArgsParser = args => {
10
+ let [ guid, hash, oldProperty, newProperty ] = args
11
+ guid = parseGuid(guid)
12
+ if (isHash(hash)) {
13
+ return [ { guid, hash, oldProperty, newProperty } ]
14
+ } else {
15
+ ([ oldProperty, newProperty ] = [ hash, oldProperty ])
16
+ return [ { guid, oldProperty, newProperty } ]
17
+ }
18
+ }
19
+ program.customArgsParser = polymorphicCommandArgsParser({ inlineArgsParser })
20
+ program.customHelpOption = commandWithTemplateCustomHelp
21
+ execEditCommand('qualifier', 'move')