wikibase-cli 17.0.6 → 17.0.8
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.js +3 -3
- package/lib/fetch_and_log_entity_revision.js +4 -0
- package/lib/fetch_and_log_ids_data.js +2 -2
- package/lib/fs.js +2 -1
- package/lib/output_templates.js +4 -3
- package/lib/pick_selected_subprops.js +42 -0
- package/package.json +2 -2
- package/lib/drop_non_selected_subprops.js +0 -21
package/bin/wb.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { readdirSync } from 'node:fs'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
4
|
import program from 'commander'
|
|
5
5
|
import { debug } from '#lib/debug'
|
|
6
6
|
import { getDirname } from '#lib/fs'
|
|
@@ -17,7 +17,7 @@ debug('program:metadata', { name: pkg.name, version: pkg.version })
|
|
|
17
17
|
// To add a new command, create a file in ../metadata/${new-command-name}
|
|
18
18
|
// and add an executable at ./wb-${new-command-name}
|
|
19
19
|
|
|
20
|
-
const commandsNames =
|
|
20
|
+
const commandsNames = readdirSync(resolve(dirname, '../metadata'))
|
|
21
21
|
.map(filename => filename.replace('.js', ''))
|
|
22
22
|
|
|
23
23
|
await Promise.all(commandsNames.map(async commandName => {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { values } from 'lodash-es'
|
|
2
2
|
import { simplifyEntity } from 'wikibase-sdk'
|
|
3
3
|
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
4
|
+
import parseProps from '#lib/parse_props'
|
|
4
5
|
import optionsFactory from '#lib/parse_simplify_options'
|
|
6
|
+
import pickSelectedSubprops from '#lib/pick_selected_subprops'
|
|
5
7
|
import { get } from '#lib/request'
|
|
6
8
|
import { getWbk } from '#lib/wbk'
|
|
7
9
|
import program from './program.js'
|
|
@@ -15,6 +17,8 @@ export async function fetchAndLogEntityRevision (id, revision) {
|
|
|
15
17
|
const url = getEntityRevision({ id, revision })
|
|
16
18
|
const body = await get(url)
|
|
17
19
|
let entity = values(body.entities)[0]
|
|
20
|
+
const requestedPropsAndSubProps = parseProps(program.props)
|
|
21
|
+
entity = pickSelectedSubprops(entity, requestedPropsAndSubProps)
|
|
18
22
|
if (simplifyOption) entity = simplifyEntity(entity, options)
|
|
19
23
|
console.log(JSON.stringify(entity))
|
|
20
24
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isEntitySchemaId, simplifyEntity } from 'wikibase-sdk'
|
|
2
2
|
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
3
3
|
import optionsFactory from '#lib/parse_simplify_options'
|
|
4
|
-
import dropNonSelectedSubprops from './drop_non_selected_subprops.js'
|
|
5
4
|
import { getEntitiesByBatches } from './get_entities_by_batches.js'
|
|
6
5
|
import { getEntitiesSchemas } from './get_entities_schemas.js'
|
|
7
6
|
import getTtlEntities from './get_ttl_entities.js'
|
|
8
7
|
import logNdjson from './log_ndjson.js'
|
|
9
8
|
import parseProps from './parse_props.js'
|
|
9
|
+
import pickSelectedSubprops from './pick_selected_subprops.js'
|
|
10
10
|
import program from './program.js'
|
|
11
11
|
|
|
12
12
|
export function fetchAndLogIdsData (ids) {
|
|
@@ -23,7 +23,7 @@ export function fetchAndLogIdsData (ids) {
|
|
|
23
23
|
if (entitiesSchemasIds.length > 0) return getEntitiesSchemas(entitiesSchemasIds)
|
|
24
24
|
|
|
25
25
|
const onResponse = entities => {
|
|
26
|
-
entities.
|
|
26
|
+
entities = entities.map(entity => pickSelectedSubprops(entity, requestedPropsAndSubProps))
|
|
27
27
|
if (simplifyFlag) {
|
|
28
28
|
entities = entities.map(entity => simplifyEntity(entity, options))
|
|
29
29
|
}
|
package/lib/fs.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { accessSync, constants } from 'node:fs'
|
|
2
2
|
import { access } from 'node:fs/promises'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
3
4
|
|
|
4
5
|
export const exists = path => access(path)
|
|
5
6
|
|
|
@@ -11,5 +12,5 @@ export const assertWriteAccessSync = path => {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export function getDirname (fileUrl) {
|
|
14
|
-
return new URL('.', fileUrl)
|
|
15
|
+
return fileURLToPath(new URL('.', fileUrl))
|
|
15
16
|
}
|
package/lib/output_templates.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { pick } from 'lodash-es'
|
|
2
2
|
import { getStatementsKey } from 'wikibase-edit/lib/parse_instance.js'
|
|
3
3
|
import { simplifyEntity } from 'wikibase-sdk'
|
|
4
|
-
import dropNonSelectedSubprops from './drop_non_selected_subprops.js'
|
|
5
4
|
import { minimizeClaimsOrSnaks } from './minimize_claims.js'
|
|
5
|
+
import pickSelectedSubprops from './pick_selected_subprops.js'
|
|
6
6
|
import program from './program.js'
|
|
7
7
|
import stringifyAsJsFunction from './stringify_as_js_function.js'
|
|
8
8
|
|
|
@@ -43,10 +43,11 @@ function FormatEntity (batchMode, propsToPick, requestedPropsAndSubProps, minimi
|
|
|
43
43
|
propsToPick[propsToPick.indexOf('claims')] = statementsKey
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// Always include type, for the needs of simplifyEntity
|
|
47
|
+
entity = pick(entity, propsToPick.concat([ 'type' ]))
|
|
47
48
|
entity = simplifyEntity(entity, simplifyOptions)
|
|
48
49
|
if (createMode) delete entity.id
|
|
49
|
-
|
|
50
|
+
entity = pickSelectedSubprops(entity, requestedPropsAndSubProps)
|
|
50
51
|
if (!batchMode && minimize !== false) {
|
|
51
52
|
minimizeClaimsOrSnaks(entity[statementsKey])
|
|
52
53
|
minimizeSitelinks(entity.sitelinks)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { pick } from 'lodash-es'
|
|
2
|
+
|
|
3
|
+
export default (entity, requestedPropsAndSubProps) => {
|
|
4
|
+
if (!requestedPropsAndSubProps || Object.keys(requestedPropsAndSubProps).length === 0) return entity
|
|
5
|
+
|
|
6
|
+
if (requestedPropsAndSubProps.claims && entity.statements) {
|
|
7
|
+
requestedPropsAndSubProps.statements = requestedPropsAndSubProps.claims
|
|
8
|
+
delete requestedPropsAndSubProps.claims
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const trimedEntity = {
|
|
12
|
+
id: entity.id,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Preserve info key/values, as some are needed downstream
|
|
16
|
+
// Ex: type is required by simplifyEntity
|
|
17
|
+
for (const key of Object.keys(entity)) {
|
|
18
|
+
if (!requestedPropsAndSubProps[key] && !key.includes(omittableProps)) {
|
|
19
|
+
trimedEntity[key] = entity[key]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const requestedProps = Object.keys(requestedPropsAndSubProps)
|
|
24
|
+
for (const prop of requestedProps) {
|
|
25
|
+
const subkeys = Object.keys(requestedPropsAndSubProps[prop])
|
|
26
|
+
if (subkeys && subkeys.length > 0) {
|
|
27
|
+
trimedEntity[prop] = pick(entity[prop], subkeys)
|
|
28
|
+
subkeys.forEach(subkey => {
|
|
29
|
+
if (!entity[prop]?.[subkey]) {
|
|
30
|
+
trimedEntity[prop] = trimedEntity[prop] || {}
|
|
31
|
+
trimedEntity[prop][subkey] = null
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
} else {
|
|
35
|
+
trimedEntity[prop] = entity[prop]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return trimedEntity
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const omittableProps = [ 'info', 'sitelinks', 'aliases', 'labels', 'descriptions', 'claims', 'datatype' ]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikibase-cli",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.8",
|
|
4
4
|
"description": "A command-line interface to Wikibase",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"shell-quote": "^1.8.1",
|
|
59
59
|
"split": "^1.0.1",
|
|
60
60
|
"through": "^2.3.8",
|
|
61
|
-
"wikibase-edit": "^6.0.
|
|
61
|
+
"wikibase-edit": "^6.0.4",
|
|
62
62
|
"wikibase-sdk": "^9.2.3",
|
|
63
63
|
"wikidata-lang": "^2.0.11"
|
|
64
64
|
},
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { pick } from 'lodash-es'
|
|
2
|
-
|
|
3
|
-
export default (entity, requestedPropsAndSubProps) => {
|
|
4
|
-
if (!requestedPropsAndSubProps) return
|
|
5
|
-
|
|
6
|
-
if (requestedPropsAndSubProps.claims && entity.statements) {
|
|
7
|
-
requestedPropsAndSubProps.statements = requestedPropsAndSubProps.claims
|
|
8
|
-
delete requestedPropsAndSubProps.claims
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const requestedProps = Object.keys(requestedPropsAndSubProps)
|
|
12
|
-
requestedProps.forEach(prop => {
|
|
13
|
-
const subkeys = Object.keys(requestedPropsAndSubProps[prop])
|
|
14
|
-
if (subkeys && subkeys.length > 0) {
|
|
15
|
-
entity[prop] = pick(entity[prop], subkeys)
|
|
16
|
-
subkeys.forEach(subkey => {
|
|
17
|
-
if (!entity[prop][subkey]) entity[prop][subkey] = null
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
}
|