wikibase-cli 16.3.3 → 17.0.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.js +12 -0
- package/bin/wb-add-badge.js +12 -0
- package/bin/wb-add-claim.js +14 -0
- package/bin/wb-add-qualifier.js +14 -0
- package/bin/wb-add-reference.js +14 -0
- package/bin/wb-aliases.js +4 -0
- package/bin/wb-badges.js +18 -0
- package/bin/{wb-claims → wb-claims.js} +19 -14
- package/bin/{wb-config → wb-config.js} +8 -6
- package/bin/{wb-convert → wb-convert.js} +11 -12
- package/bin/wb-create-entity.js +10 -0
- package/bin/{wb-data → wb-data.js} +15 -11
- package/bin/wb-delete-entity.js +10 -0
- package/bin/wb-description.js +4 -0
- package/bin/wb-edit-entity.js +10 -0
- package/bin/{wb-generate-template → wb-generate-template.js} +24 -13
- package/bin/{wb-hub → wb-hub.js} +9 -7
- package/bin/{wb-id → wb-id.js} +14 -11
- package/bin/wb-label.js +4 -0
- package/bin/{wb-lang → wb-lang.js} +8 -8
- package/bin/wb-lemma.js +4 -0
- package/bin/{wb-merge-entity → wb-merge-entity.js} +6 -4
- package/bin/wb-move-claim.js +20 -0
- package/bin/wb-move-qualifier.js +21 -0
- package/bin/{wb-open → wb-open.js} +23 -22
- package/bin/{wb-props → wb-props.js} +8 -9
- package/bin/{wb-query → wb-query.js} +13 -9
- package/bin/wb-remove-alias.js +12 -0
- package/bin/wb-remove-badge.js +12 -0
- package/bin/wb-remove-claim.js +11 -0
- package/bin/wb-remove-description.js +16 -0
- package/bin/wb-remove-label.js +16 -0
- package/bin/wb-remove-qualifier.js +15 -0
- package/bin/wb-remove-reference.js +15 -0
- package/bin/wb-remove-sitelink.js +16 -0
- package/bin/{wb-revisions → wb-revisions.js} +15 -11
- package/bin/{wb-search → wb-search.js} +17 -15
- package/bin/wb-set-alias.js +12 -0
- package/bin/wb-set-description.js +12 -0
- package/bin/wb-set-label.js +12 -0
- package/bin/wb-set-sitelink.js +17 -0
- package/bin/{wb-sparql → wb-sparql.js} +16 -12
- package/bin/{wb-summary → wb-summary.js} +3 -3
- package/bin/{wb-update-claim → wb-update-claim.js} +9 -6
- package/bin/wb-update-qualifier.js +14 -0
- package/bin/wb.js +27 -0
- package/bin/{wd → wd.js} +2 -3
- package/index.js +7 -1
- package/lib/apply_env_and_config_default.js +7 -5
- package/lib/chalk.js +12 -0
- package/lib/command_with_template_custom_help.js +7 -7
- package/lib/common_command_args_parser.js +7 -10
- package/lib/common_errors.js +5 -7
- package/lib/common_options.js +23 -24
- package/lib/config/config.js +10 -5
- package/lib/config/credentials_config.js +7 -6
- package/lib/config/file_operations.js +9 -8
- package/lib/config/file_path.js +11 -8
- package/lib/config/parameters.js +11 -10
- package/lib/convert_ids.js +10 -8
- package/lib/copy.js +2 -2
- package/lib/drop_non_selected_subprops.js +3 -3
- package/lib/edit/assert_credentials.js +3 -3
- package/lib/edit/edit_command.js +19 -19
- package/lib/edit/init_credentials.js +11 -11
- package/lib/edit/parse_batch_line.js +2 -2
- package/lib/edit/parse_object_value.js +6 -5
- package/lib/edit/prompt.js +7 -5
- package/lib/edit/validate_instance_credentials.js +2 -2
- package/lib/entity_attribute_command.js +10 -10
- package/lib/entity_attribute_parser.js +8 -8
- package/lib/entity_data_parser.js +14 -11
- package/lib/errors.js +3 -3
- package/lib/execute_function.js +4 -4
- package/lib/exit_on_missing.js +11 -12
- package/lib/fetch_and_log_entity_revision.js +18 -15
- package/lib/fetch_and_log_guid_data.js +19 -11
- package/lib/fetch_and_log_ids_data.js +17 -16
- package/lib/fetch_and_log_property_claims_data.js +18 -10
- package/lib/fetch_lang_props.js +13 -12
- package/lib/filter_claims_properties.js +4 -4
- package/lib/format_properties_data.js +2 -2
- package/lib/format_statement_element_value.js +3 -3
- package/lib/fs.js +27 -25
- package/lib/generate_describe_sparql_query.js +3 -3
- package/lib/generate_sample_sparql_query.js +1 -1
- package/lib/generate_select_sparql_query.js +2 -2
- package/lib/get_cache_folder_path.js +5 -5
- package/lib/get_claims_texts.js +8 -7
- package/lib/get_entities.js +6 -5
- package/lib/get_entities_by_batches.js +12 -7
- package/lib/get_entities_labels.js +3 -5
- package/lib/get_entities_schemas.js +7 -7
- package/lib/get_folder_path.js +8 -6
- package/lib/get_lang_props.js +17 -16
- package/lib/get_pattern_filter.js +4 -3
- package/lib/get_properties_data.js +5 -5
- package/lib/get_redirected_sitelink_title.js +4 -4
- package/lib/get_sitelink_url.js +9 -8
- package/lib/get_stdin_input.js +1 -1
- package/lib/get_ttl_entities.js +8 -8
- package/lib/global_options_help.js +1 -1
- package/lib/hash_string.js +4 -2
- package/lib/json.js +5 -0
- package/lib/local_lang.js +2 -1
- package/lib/log_claims.js +12 -12
- package/lib/log_command_examples.js +3 -3
- package/lib/log_ndjson.js +1 -1
- package/lib/make_sparql_query.js +29 -25
- package/lib/matching_langs.js +4 -6
- package/lib/minimize_claims.js +3 -5
- package/lib/object_arg_parser.js +12 -17
- package/lib/open.js +7 -7
- package/lib/output.js +37 -35
- package/lib/output_templates.js +41 -31
- package/lib/parse_command_utils.js +14 -15
- package/lib/parse_entity_type.js +2 -2
- package/lib/parse_props.js +7 -4
- package/lib/parse_simplify_options.js +1 -1
- package/lib/path.js +3 -2
- package/lib/pluralize.js +2 -2
- package/lib/polymorphic_command_args_parser.js +11 -9
- package/lib/program.js +9 -9
- package/lib/properties.js +22 -23
- package/lib/queries/all_instances.js +2 -2
- package/lib/queries/all_properties.js +1 -1
- package/lib/read_ids_from_stdin.js +3 -3
- package/lib/request.js +22 -23
- package/lib/request_headers.js +8 -2
- package/lib/reset_properties.js +4 -4
- package/lib/sparql_query_command.js +10 -8
- package/lib/stringify_as_js_function.js +3 -3
- package/lib/summary_parser.js +43 -13
- package/lib/tabularize.js +7 -7
- package/lib/tolerant_id_parser.js +21 -18
- package/lib/types.js +4 -6
- package/lib/utils.js +11 -13
- package/lib/validate.js +2 -0
- package/lib/validate_function_args.js +2 -2
- package/lib/value_parsers.js +2 -2
- package/lib/wbk.js +4 -3
- package/lib/wellknown_queries.js +6 -5
- package/metadata/add-alias.js +6 -4
- package/metadata/add-badge.js +5 -3
- package/metadata/add-claim.js +5 -5
- package/metadata/add-qualifier.js +6 -4
- package/metadata/add-reference.js +6 -4
- package/metadata/aliases.js +6 -4
- package/metadata/badges.js +3 -3
- package/metadata/claims.js +4 -4
- package/metadata/config.js +5 -5
- package/metadata/convert.js +4 -4
- package/metadata/create-entity.js +8 -8
- package/metadata/data.js +4 -4
- package/metadata/delete-entity.js +7 -7
- package/metadata/description.js +6 -4
- package/metadata/edit-entity.js +10 -10
- package/metadata/generate-template.js +4 -4
- package/metadata/hub.js +3 -3
- package/metadata/id.js +4 -4
- package/metadata/label.js +5 -3
- package/metadata/lang.js +4 -4
- package/metadata/lemma.js +6 -4
- package/metadata/merge-entity.js +6 -6
- package/metadata/move-claim.js +6 -4
- package/metadata/move-qualifier.js +6 -4
- package/metadata/open.js +4 -4
- package/metadata/props.js +4 -4
- package/metadata/query.js +3 -3
- package/metadata/remove-alias.js +6 -4
- package/metadata/remove-badge.js +5 -3
- package/metadata/remove-claim.js +6 -4
- package/metadata/remove-description.js +5 -3
- package/metadata/remove-label.js +5 -3
- package/metadata/remove-qualifier.js +6 -4
- package/metadata/remove-reference.js +6 -4
- package/metadata/remove-sitelink.js +5 -3
- package/metadata/revisions.js +4 -4
- package/metadata/search.js +3 -3
- package/metadata/set-alias.js +6 -4
- package/metadata/set-description.js +6 -4
- package/metadata/set-label.js +6 -4
- package/metadata/set-sitelink.js +5 -3
- package/metadata/sparql.js +4 -4
- package/metadata/summary.js +5 -5
- package/metadata/update-claim.js +5 -5
- package/metadata/update-qualifier.js +6 -4
- package/package.json +25 -16
- package/bin/wb +0 -22
- package/bin/wb-add-alias +0 -9
- package/bin/wb-add-badge +0 -9
- package/bin/wb-add-claim +0 -11
- package/bin/wb-add-qualifier +0 -11
- package/bin/wb-add-reference +0 -11
- package/bin/wb-aliases +0 -2
- package/bin/wb-badges +0 -18
- package/bin/wb-create-entity +0 -5
- package/bin/wb-delete-entity +0 -7
- package/bin/wb-description +0 -2
- package/bin/wb-edit-entity +0 -5
- package/bin/wb-label +0 -2
- package/bin/wb-lemma +0 -2
- package/bin/wb-move-claim +0 -17
- package/bin/wb-move-qualifier +0 -18
- package/bin/wb-remove-alias +0 -9
- package/bin/wb-remove-badge +0 -9
- package/bin/wb-remove-claim +0 -8
- package/bin/wb-remove-description +0 -13
- package/bin/wb-remove-label +0 -13
- package/bin/wb-remove-qualifier +0 -12
- package/bin/wb-remove-reference +0 -12
- package/bin/wb-remove-sitelink +0 -13
- package/bin/wb-set-alias +0 -9
- package/bin/wb-set-description +0 -9
- package/bin/wb-set-label +0 -9
- package/bin/wb-set-sitelink +0 -14
- package/bin/wb-update-qualifier +0 -11
- package/lib/valide.js +0 -4
|
@@ -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')
|
package/bin/wb-badges.js
ADDED
|
@@ -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
|
-
|
|
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
|
|
10
|
-
|
|
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 =
|
|
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
|
|
54
|
+
const propClaims = entity[statementsKey][prop]
|
|
50
55
|
if (!propClaims) throw new Error(`no claims found for this property: ${prop}`)
|
|
51
|
-
const ids =
|
|
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 =
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
const { fetchAndLogPropertyClaimsData } = await import('#lib/fetch_and_log_property_claims_data')
|
|
26
|
+
fetchAndLogPropertyClaimsData(firstArg)
|
|
25
27
|
} else {
|
|
26
|
-
const parseId =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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,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
|
-
|
|
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 =
|
|
20
|
+
const parseId = tolerantIdParserFactory()
|
|
21
|
+
|
|
13
22
|
const ids = program.args.map(parseId)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
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)
|
|
30
|
-
|
|
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:
|
|
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
|
-
|
|
73
|
+
readIdsFromStdin(handleIds)
|
|
63
74
|
}
|
package/bin/{wb-hub → wb-hub.js}
RENAMED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
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
|
-
|
|
29
|
+
openUrl(url)
|
|
28
30
|
} else {
|
|
29
|
-
const output =
|
|
30
|
-
|
|
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
|
package/bin/{wb-id → wb-id.js}
RENAMED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
const {
|
|
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 =
|
|
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
|
|
57
|
-
.map(_.property('value'))
|
|
60
|
+
return map(values(descriptions), 'value')
|
|
58
61
|
.join('\n')
|
|
59
62
|
}
|
|
60
63
|
|
package/bin/wb-label.js
ADDED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
28
|
-
let matchingLangs = find(input)
|
|
28
|
+
let matchingLangs = findMatchingLang(input)
|
|
29
29
|
if (matchingLangs.length > 0) {
|
|
30
|
-
if (!json) 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)
|
package/bin/wb-lemma.js
ADDED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
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 =
|
|
24
|
-
|
|
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')
|