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.
- package/README.md +1 -1
- 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} +6 -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 +3 -4
- package/lib/edit/validate_instance_credentials.js +2 -2
- package/lib/entity_attribute_command.js +10 -10
- package/lib/entity_attribute_parser.js +9 -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 +13 -26
- 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 +11 -8
- 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 +11 -6
- 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 +31 -22
- 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
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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 ||
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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 =
|
|
15
|
-
jsModule =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
}
|
package/lib/common_errors.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { red } from '#lib/chalk'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
}
|
package/lib/common_options.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
}
|
package/lib/config/config.js
CHANGED
|
@@ -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
|
-
|
|
5
|
+
|
|
6
|
+
export let config = {}
|
|
7
|
+
|
|
3
8
|
// Neutralize the local config for tests
|
|
4
|
-
|
|
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
|
-
|
|
11
|
+
if (configFilePath) {
|
|
12
|
+
config = readJsonFile(configFilePath)
|
|
13
|
+
}
|
|
9
14
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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 => {
|
package/lib/config/file_path.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
10
|
+
configFilePath = path.join(configFolder, 'config.json')
|
|
7
11
|
|
|
8
12
|
try {
|
|
9
|
-
|
|
13
|
+
accessSync(configFilePath)
|
|
10
14
|
} catch (err) {
|
|
11
15
|
// Initialize if it doesn't exist
|
|
12
|
-
|
|
16
|
+
writeFileSync(configFilePath, '{}', { mode: 0o600 })
|
|
13
17
|
}
|
|
14
|
-
module.exports = configPath
|
|
15
18
|
} else {
|
|
16
|
-
|
|
19
|
+
configFilePath = null
|
|
17
20
|
}
|
package/lib/config/parameters.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
32
|
+
export default {
|
|
32
33
|
clipboard: boolean,
|
|
33
34
|
json: boolean,
|
|
34
35
|
lang: {
|
|
35
36
|
type: 'lang',
|
|
36
|
-
default:
|
|
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
|
}
|
package/lib/convert_ids.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// Convert external ids to Wikibase ids
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { pick } from 'lodash-es'
|
|
2
2
|
|
|
3
|
-
|
|
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] =
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
import { yellow } from '#lib/chalk'
|
|
2
|
+
import { initCredentials } from './init_credentials.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export default async ({ instance, credentials, batch }) => {
|
|
5
5
|
if (!credentials) return requestCredentials(instance, batch)
|
|
6
6
|
|
|
7
7
|
const instanceCredentials = credentials[instance]
|
package/lib/edit/edit_command.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
+
import parse from 'shell-quote/parse.js'
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
11
|
+
export default value => {
|
|
11
12
|
if (isPlainObject(value)) {
|
|
12
13
|
stringValueKeys.forEach(parseObjKeyValue(value))
|
|
13
14
|
return value
|
package/lib/edit/prompt.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { blue, yellow, grey } = require('chalk')
|
|
1
|
+
import read from 'read'
|
|
2
|
+
import { blue, yellow, grey } from '#lib/chalk'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
export default readsData => {
|
|
6
5
|
const results = {}
|
|
7
6
|
|
|
8
7
|
const promptSequentially = async () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import wbEdit from 'wikibase-edit'
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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 =
|
|
18
|
+
const entitiesList = values(entities)
|
|
19
19
|
const multiEntities = entitiesList.length > 1
|
|
20
|
-
const maxLength =
|
|
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(
|
|
41
|
+
console.log(grey(padEnd(entity.id, maxLength)), value || grey('not found'))
|
|
42
42
|
} else {
|
|
43
43
|
output(value)
|
|
44
44
|
}
|