wikibase-cli 16.3.2 → 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} +10 -8
- 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 +9 -6
- 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 +18 -9
- 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 +24 -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
package/lib/output.js
CHANGED
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { promisify } from 'node:util'
|
|
2
|
+
import { grey } from '#lib/chalk'
|
|
3
|
+
import { copyAndExit } from '#lib/copy'
|
|
4
|
+
import { tabularize } from '#lib/tabularize'
|
|
5
|
+
import { isArray, isCollection, isPlainObject } from '#lib/types'
|
|
6
|
+
|
|
3
7
|
const stdoutWrite = promisify(process.stdout.write).bind(process.stdout)
|
|
4
8
|
|
|
5
9
|
// Calling program just in time, so that code running
|
|
6
10
|
// after this first level function can still change the option
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const isCollection = types.isCollection(data)
|
|
11
|
-
|
|
12
|
-
program.json = program.json || program.format === 'json'
|
|
11
|
+
export function outputFactory (program) {
|
|
12
|
+
return async function (data, optional, customColors) {
|
|
13
|
+
program.json = program.json || program.format === 'json'
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// Flatten when data is one array in an array to get a chance
|
|
16
|
+
// to have a shell-friendly output
|
|
17
|
+
if (isArray(data) && data.length === 1 && isArray(data[0])) data = data[0]
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
await log(data)
|
|
22
|
-
} else {
|
|
23
|
-
if (isArray && !isCollection && !program.json) {
|
|
24
|
-
if (program.format === 'inline') data = data.join(' ')
|
|
25
|
-
else data = data.join('\n')
|
|
26
|
-
} else if (isCollection && program.format === 'table') {
|
|
27
|
-
data = require('./tabularize')(data)
|
|
28
|
-
} else if (program.json || isCollection || isPlainObject) {
|
|
29
|
-
// indent deep objects
|
|
30
|
-
data = JSON.stringify(data, null, 2)
|
|
31
|
-
// Do not copy to clipboard when the output is valid JSON
|
|
32
|
-
program.clipboard = false
|
|
33
|
-
}
|
|
34
|
-
if (data == null || (isArray && data.length === 0)) {
|
|
35
|
-
console.error('no result found')
|
|
36
|
-
return process.exit(1)
|
|
37
|
-
}
|
|
38
|
-
if (program.clipboard) {
|
|
39
|
-
require('./copy')(data)
|
|
40
|
-
} else {
|
|
19
|
+
if (optional) {
|
|
20
|
+
if (!program.verbose) return
|
|
21
|
+
if (!customColors) data = grey(data)
|
|
41
22
|
await log(data)
|
|
42
|
-
|
|
23
|
+
} else {
|
|
24
|
+
if (isArray(data) && !isCollection(data) && !program.json) {
|
|
25
|
+
if (program.format === 'inline') data = data.join(' ')
|
|
26
|
+
else data = data.join('\n')
|
|
27
|
+
} else if (isCollection(data) && program.format === 'table') {
|
|
28
|
+
data = tabularize(data)
|
|
29
|
+
} else if (program.json || isCollection(data) || isPlainObject(data)) {
|
|
30
|
+
// indent deep objects
|
|
31
|
+
data = JSON.stringify(data, null, 2)
|
|
32
|
+
// Do not copy to clipboard when the output is valid JSON
|
|
33
|
+
program.clipboard = false
|
|
34
|
+
}
|
|
35
|
+
if (data == null || (isArray(data) && data.length === 0)) {
|
|
36
|
+
console.error('no result found')
|
|
37
|
+
return process.exit(1)
|
|
38
|
+
}
|
|
39
|
+
if (program.clipboard) {
|
|
40
|
+
copyAndExit(data)
|
|
41
|
+
} else {
|
|
42
|
+
await log(data)
|
|
43
|
+
process.exit(0)
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
package/lib/output_templates.js
CHANGED
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const simplifyOptions = {
|
|
9
|
-
keepIds: !createMode,
|
|
10
|
-
keepQualifiers: true,
|
|
11
|
-
keepReferences: true,
|
|
12
|
-
keepRichValues: true,
|
|
13
|
-
keepNonTruthy: true,
|
|
14
|
-
keepSnaktypes: true,
|
|
15
|
-
keepRanks: true,
|
|
16
|
-
keepBadges: true,
|
|
17
|
-
// No need to keep the hashes as every edited claim (identified with a GUID)
|
|
18
|
-
// will have it's qualifiers and references fully overriden
|
|
19
|
-
keepHashes: false
|
|
20
|
-
}
|
|
1
|
+
import { pick } from 'lodash-es'
|
|
2
|
+
import { getStatementsKey } from 'wikibase-edit/lib/parse_instance.js'
|
|
3
|
+
import { simplifyEntity } from 'wikibase-sdk'
|
|
4
|
+
import dropNonSelectedSubprops from './drop_non_selected_subprops.js'
|
|
5
|
+
import { minimizeClaimsOrSnaks } from './minimize_claims.js'
|
|
6
|
+
import program from './program.js'
|
|
7
|
+
import stringifyAsJsFunction from './stringify_as_js_function.js'
|
|
21
8
|
|
|
22
|
-
|
|
9
|
+
export function outputTemplatesFactory ({ batchMode, format, propsToPick, requestedPropsAndSubProps, minimize }) {
|
|
23
10
|
const formatEntity = FormatEntity(batchMode, propsToPick, requestedPropsAndSubProps, minimize)
|
|
24
|
-
return async entities
|
|
11
|
+
return async function outputTemplates (entities) {
|
|
25
12
|
entities = entities.map(formatEntity)
|
|
26
13
|
if (format === 'js') {
|
|
27
14
|
const jsFile = await stringifyAsJsFunction(entities[0], program.lang)
|
|
@@ -33,16 +20,39 @@ module.exports = ({ batchMode, format, propsToPick, requestedPropsAndSubProps, m
|
|
|
33
20
|
}
|
|
34
21
|
}
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
function FormatEntity (batchMode, propsToPick, requestedPropsAndSubProps, minimize) {
|
|
24
|
+
const { createMode = false } = program
|
|
25
|
+
const simplifyOptions = {
|
|
26
|
+
keepIds: !createMode,
|
|
27
|
+
keepQualifiers: true,
|
|
28
|
+
keepReferences: true,
|
|
29
|
+
keepRichValues: true,
|
|
30
|
+
keepNonTruthy: true,
|
|
31
|
+
keepSnaktypes: true,
|
|
32
|
+
keepRanks: true,
|
|
33
|
+
keepBadges: true,
|
|
34
|
+
// No need to keep the hashes as every edited claim (identified with a GUID)
|
|
35
|
+
// will have it's qualifiers and references fully overriden
|
|
36
|
+
keepHashes: false,
|
|
37
|
+
}
|
|
38
|
+
const statementsKey = getStatementsKey(program.instance)
|
|
39
|
+
|
|
40
|
+
return function formatEntity (entity) {
|
|
41
|
+
if (statementsKey !== 'claims') {
|
|
42
|
+
if (propsToPick.includes('claims')) {
|
|
43
|
+
propsToPick[propsToPick.indexOf('claims')] = statementsKey
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
entity = pick(entity, propsToPick)
|
|
47
|
+
entity = simplifyEntity(entity, simplifyOptions)
|
|
48
|
+
if (createMode) delete entity.id
|
|
49
|
+
dropNonSelectedSubprops(entity, requestedPropsAndSubProps)
|
|
50
|
+
if (!batchMode && minimize !== false) {
|
|
51
|
+
minimizeClaimsOrSnaks(entity[statementsKey])
|
|
52
|
+
minimizeSitelinks(entity.sitelinks)
|
|
53
|
+
}
|
|
54
|
+
return entity
|
|
44
55
|
}
|
|
45
|
-
return entity
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
const minimizeSitelinks = sitelinks => {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
1
|
+
export const parseGuid = guid => {
|
|
2
|
+
guid = guid
|
|
3
|
+
// Normalize prefixed statements GUIDs as returned by SPARQL queries:
|
|
4
|
+
// to the format used by Wikibase API
|
|
5
|
+
// - from: wds:Q1827902-6706334E-D27E-4F4B-B6DA-ABE7544DF11C
|
|
6
|
+
// - to: Q1827902$6706334E-D27E-4F4B-B6DA-ABE7544DF11C
|
|
7
|
+
// Also accept Q1827902-6706334E-D27E-4F4B-B6DA-ABE7544DF11C
|
|
8
|
+
.replace(/^([a-z]+:)?([QPLM]\d+)-(.*)/i, '$2$$$3')
|
|
9
|
+
// Often required when getting guids from the command line, as passing a value with a $
|
|
10
|
+
// can be challenging, and require different quoting strategies
|
|
11
|
+
.replace(/("|')/g, '')
|
|
12
|
+
.replace('\\$', '$')
|
|
13
|
+
.trim()
|
|
14
|
+
return guid
|
|
16
15
|
}
|
package/lib/parse_entity_type.js
CHANGED
|
@@ -3,10 +3,10 @@ const shortTypes = {
|
|
|
3
3
|
i: 'item',
|
|
4
4
|
p: 'property',
|
|
5
5
|
l: 'lexeme',
|
|
6
|
-
s: 'sense'
|
|
6
|
+
s: 'sense',
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export default (type = 'item') => {
|
|
10
10
|
// Fix plural forms
|
|
11
11
|
type = type.replace(/s$/, '')
|
|
12
12
|
return shortTypes[type] || type
|
package/lib/parse_props.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { isPropertyId, isSitelinkKey } from 'wikibase-sdk'
|
|
2
|
+
|
|
2
3
|
const langPattern = /^\w{2,3}(-\w{2,4})?$/
|
|
3
4
|
const termSections = [
|
|
4
5
|
'labels',
|
|
5
6
|
'descriptions',
|
|
6
7
|
'aliases',
|
|
7
|
-
'lemmas'
|
|
8
|
+
'lemmas',
|
|
8
9
|
]
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
export default propsStr => {
|
|
11
12
|
if (!propsStr) return {}
|
|
12
13
|
|
|
13
14
|
// The Wikibase API doesn't accept lemmas, forms, senses props
|
|
@@ -27,13 +28,15 @@ const getPropsAndSubKeys = propStr => {
|
|
|
27
28
|
if (isPropertyId(prop)) return lazyProps.claims(prop)
|
|
28
29
|
else if (prop.match(langPattern)) return lazyProps.terms(prop)
|
|
29
30
|
else if (isSitelinkKey(prop)) return lazyProps.sitelinks(prop)
|
|
31
|
+
// Handle Wikimedia Commons weirdness: it uses entity.statements but wbgetentities expects a "claims" prop
|
|
32
|
+
else if (prop === 'statements') return [ { prop: 'claims', subkey } ]
|
|
30
33
|
else return [ { prop, subkey } ]
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
const lazyProps = {
|
|
34
37
|
claims: propertyId => [ { prop: 'claims', subkey: propertyId } ],
|
|
35
38
|
terms: lang => termSections.map(section => ({ prop: section, subkey: lang })),
|
|
36
|
-
sitelinks: site => [ { prop: 'sitelinks', subkey: site } ]
|
|
39
|
+
sitelinks: site => [ { prop: 'sitelinks', subkey: site } ],
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
const aggregate = (index, propsData) => {
|
|
@@ -13,7 +13,7 @@ const propsMap = {
|
|
|
13
13
|
badges: 'keepBadges',
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
export default ({ simplify: simplifyOption, keep: props, timeConverter }) => {
|
|
17
17
|
const options = {}
|
|
18
18
|
|
|
19
19
|
if (props != null) {
|
package/lib/path.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
export default process.platform === 'win32' ? path.win32 : path
|
package/lib/pluralize.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Attributes that can't be pluralized with `${attribute}s`
|
|
2
2
|
// or are already pluralized
|
|
3
3
|
const plurals = {
|
|
4
|
-
aliases: 'aliases'
|
|
4
|
+
aliases: 'aliases',
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export default attribute => plurals[attribute] || `${attribute}s`
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import program from 'commander'
|
|
2
|
+
import { objectArgParser } from '#lib/object_arg_parser'
|
|
3
|
+
import { isFilePathSync, isJsonString } from '#lib/utils'
|
|
4
4
|
|
|
5
5
|
const inlineOptions = [
|
|
6
|
-
'rank'
|
|
6
|
+
'rank',
|
|
7
7
|
]
|
|
8
8
|
|
|
9
9
|
const noInlineOptions = () => inlineOptions.filter(option => program[option] != null).length === 0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export function polymorphicCommandArgsParser ({ inlineArgsParser }) {
|
|
12
|
+
return async function (args) {
|
|
13
|
+
if ((args.length === 1 && isJsonString(args[0]) && noInlineOptions()) || isFilePathSync(args[0])) {
|
|
14
|
+
return objectArgParser(args)
|
|
15
|
+
} else {
|
|
16
|
+
return inlineArgsParser(args)
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
}
|
package/lib/program.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Extends commander with options and functions used by all subcommands.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import program from 'commander'
|
|
4
|
+
import { applyEnvAndConfigDefault } from './apply_env_and_config_default.js'
|
|
5
|
+
import globalOptionsHelp from './global_options_help.js'
|
|
6
|
+
import logCommandExamples from './log_command_examples.js'
|
|
7
7
|
|
|
8
|
-
program.process = command => {
|
|
8
|
+
program.process = async command => {
|
|
9
9
|
if (command) {
|
|
10
|
-
const metadata =
|
|
10
|
+
const { default: metadata } = await import(`../metadata/${command}.js`)
|
|
11
11
|
const { args, description, options, examples, doc } = metadata
|
|
12
12
|
program.arguments(args)
|
|
13
13
|
program.description(description)
|
|
@@ -42,12 +42,12 @@ const commandsAcceptingZeroArguments = [
|
|
|
42
42
|
'query',
|
|
43
43
|
'convert',
|
|
44
44
|
// Needs to also log the current config
|
|
45
|
-
'config'
|
|
45
|
+
'config',
|
|
46
46
|
]
|
|
47
47
|
|
|
48
48
|
const commandsTakingArgsOnStdin = [
|
|
49
49
|
'data',
|
|
50
|
-
'generate-template'
|
|
50
|
+
'generate-template',
|
|
51
51
|
]
|
|
52
52
|
|
|
53
53
|
const parseArgv = (argv, isCommandsWithCustomHelpMenu) => {
|
|
@@ -80,4 +80,4 @@ process.stdout.on('error', err => {
|
|
|
80
80
|
else throw err
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
export default program
|
package/lib/properties.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
1
|
+
export const mainProps = {
|
|
2
|
+
'https://www.wikidata.org': [ 'P31', 'P279' ],
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const propTypes = {
|
|
6
|
+
'external-id': { factor: 0.1, color: 'grey' },
|
|
7
|
+
string: { factor: 1 },
|
|
8
|
+
'wikibase-item': { factor: 1 },
|
|
9
|
+
time: { factor: 1 },
|
|
10
|
+
monolingualtext: { factor: 2 },
|
|
11
|
+
quantity: { factor: 1 },
|
|
12
|
+
'wikibase-property': { factor: 1 },
|
|
13
|
+
url: { factor: 0.5 },
|
|
14
|
+
commonsMedia: { factor: 0.5 },
|
|
15
|
+
'globe-coordinate': { factor: 0.5 },
|
|
16
|
+
math: { factor: 0.5 },
|
|
17
|
+
'geo-shape': { factor: 0.5 },
|
|
18
|
+
'tabular-data': { factor: 0.5 },
|
|
19
|
+
'wikibase-lexeme': { factor: 0.5 },
|
|
20
|
+
'wikibase-form': { factor: 0.5 },
|
|
21
|
+
'wikibase-sense': { factor: 0.5 },
|
|
22
|
+
'musical-notation': { factor: 0.5 },
|
|
24
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export default lang => {
|
|
2
2
|
return `SELECT ?property ?propertyLabel ?propertyType ?propertyDescription ?propertyAltLabel WHERE {
|
|
3
3
|
?property wikibase:propertyType ?propertyType .
|
|
4
4
|
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang},en". }
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import split from 'split'
|
|
2
|
+
import through from 'through'
|
|
3
3
|
|
|
4
4
|
let ids = []
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export function readIdsFromStdin (handleIdsBatch) {
|
|
7
7
|
const write = function (id) {
|
|
8
8
|
id = id.trim()
|
|
9
9
|
if (id === '') return
|
package/lib/request.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
const fetch = require('node-fetch')
|
|
2
|
-
const { logResponseHeaders } = require('./program')
|
|
3
1
|
// Using a custom agent to set keepAlive=true
|
|
4
2
|
// https://nodejs.org/api/http.html#http_class_http_agent
|
|
5
3
|
// https://github.com/bitinn/node-fetch#custom-agent
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import http from 'node:http'
|
|
5
|
+
import https from 'node:https'
|
|
6
|
+
import { pick } from 'lodash-es'
|
|
7
|
+
import fetch from 'node-fetch'
|
|
8
|
+
import program from './program.js'
|
|
9
|
+
import globalHeaders from './request_headers.js'
|
|
10
|
+
|
|
8
11
|
const httpAgent = new http.Agent({ keepAlive: true })
|
|
9
12
|
const httpsAgent = new https.Agent({ keepAlive: true })
|
|
10
13
|
// Useful to:
|
|
@@ -12,39 +15,35 @@ const httpsAgent = new https.Agent({ keepAlive: true })
|
|
|
12
15
|
// - accept certificates that would otherwise generate a UNABLE_TO_VERIFY_LEAF_SIGNATURE error
|
|
13
16
|
const insecureHttpsAgent = new https.Agent({ keepAlive: true, rejectUnauthorized: false })
|
|
14
17
|
const tlsErrorsHosts = new Set([ 'datos.bne.es' ])
|
|
15
|
-
const { pick } = require('lodash')
|
|
16
18
|
|
|
17
19
|
const agent = ({ host, protocol }) => {
|
|
18
20
|
if (tlsErrorsHosts.has(host)) return protocol === 'http:' ? httpAgent : insecureHttpsAgent
|
|
19
21
|
else return protocol === 'http:' ? httpAgent : httpsAgent
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
const globalHeaders = require('./request_headers')
|
|
23
23
|
const buildHeaders = customHeaders => {
|
|
24
24
|
if (customHeaders) return Object.assign({}, globalHeaders, customHeaders)
|
|
25
25
|
else return globalHeaders
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
28
|
+
export const get = async url => {
|
|
29
|
+
const res = await fetch(url, { headers: globalHeaders, agent })
|
|
30
|
+
return handleResponse({ res, url })
|
|
31
|
+
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
export const customGet = async ({ url, headers }) => {
|
|
34
|
+
const res = await fetch(url, { headers: buildHeaders(headers), agent })
|
|
35
|
+
return handleResponse({ res, url })
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
38
|
+
export const post = async ({ url, body, headers }) => {
|
|
39
|
+
const method = 'post'
|
|
40
|
+
const res = await fetch(url, { method, body, headers: buildHeaders(headers), agent })
|
|
41
|
+
return handleResponse({ res, url, method })
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
async function handleResponse ({ res, url, method }) {
|
|
47
45
|
let body = await res.text()
|
|
46
|
+
const { logResponseHeaders } = program
|
|
48
47
|
if (logResponseHeaders) {
|
|
49
48
|
let headers = res.headers.raw()
|
|
50
49
|
if (typeof logResponseHeaders === 'string') {
|
|
@@ -81,5 +80,5 @@ const newError = (statusCode, body, statusMessage) => {
|
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
const statusCodeByErrorCode = {
|
|
84
|
-
'no-such-entity': 404
|
|
83
|
+
'no-such-entity': 404,
|
|
85
84
|
}
|
package/lib/request_headers.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import { getDirname } from '#lib/fs'
|
|
3
|
+
import { readJsonFile } from '#lib/json'
|
|
4
|
+
|
|
5
|
+
const dirname = getDirname(import.meta.url)
|
|
6
|
+
const { name, version } = readJsonFile(resolve(dirname, '../package.json'))
|
|
7
|
+
|
|
8
|
+
export default { 'User-Agent': `${name}/v${version}` }
|
package/lib/reset_properties.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { exec } from 'node:child_process'
|
|
2
|
+
import { green } from '#lib/chalk'
|
|
3
|
+
import getCacheFolderPath from '#lib/get_cache_folder_path'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default () => {
|
|
6
6
|
return getCacheFolderPath('props')
|
|
7
7
|
.then(propsDir => {
|
|
8
8
|
// --force: ignore if there are no more files to delete
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { openUrl } from '#lib/open'
|
|
2
|
+
import wbk from '#lib/wbk'
|
|
3
|
+
import makeSparqlQuery from './make_sparql_query.js'
|
|
4
|
+
import { outputFactory } from './output.js'
|
|
5
|
+
import program from './program.js'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export function sparqlQueryCommand (sparql, format) {
|
|
8
|
+
const output = outputFactory(program)
|
|
8
9
|
if (program.open) {
|
|
9
10
|
openQueryServiceGUI(sparql)
|
|
10
11
|
} else if (program.dry) {
|
|
@@ -16,7 +17,8 @@ module.exports = (sparql, format) => {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
function openQueryServiceGUI (sparql) {
|
|
21
|
+
const { sparqlQuery } = wbk(program)
|
|
20
22
|
const queryServiceGUI = sparqlQuery(sparql).replace('sparql?format=json&query=', '#')
|
|
21
|
-
|
|
23
|
+
openUrl(queryServiceGUI)
|
|
22
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { uniq } from 'lodash-es'
|
|
2
|
+
import { getEntitiesLabels } from './get_entities_labels.js'
|
|
3
3
|
|
|
4
4
|
const formatJsObj = text => {
|
|
5
5
|
return text
|
|
@@ -70,7 +70,7 @@ const getPatternComment = (line, pattern, entitiesLabels) => {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
export default async (entity, lang) => {
|
|
74
74
|
const json = JSON.stringify(entity, null, 2)
|
|
75
75
|
// Use the classic syntax function to avoid the implicit return syntax
|
|
76
76
|
// which might be confusion to users unfamiliar with JS
|