wikibase-sdk
Advanced tools
Comparing version 9.0.4 to 9.0.5
@@ -15,8 +15,3 @@ import type { Entities, SimplifiedEntities } from '../types/entity.js'; | ||
} | ||
declare function entities(res: WbGetEntitiesResponse): SimplifiedEntities; | ||
declare function pagesTitles(res: CirrusSearchPagesResponse): Titles; | ||
export declare const parse: { | ||
readonly entities: typeof entities; | ||
readonly pagesTitles: typeof pagesTitles; | ||
}; | ||
export {}; | ||
export declare function entities(res: WbGetEntitiesResponse): SimplifiedEntities; | ||
export declare function pagesTitles(res: CirrusSearchPagesResponse): Titles; |
import { simplifyEntities } from './simplify_entity.js'; | ||
function entities(res) { | ||
export function entities(res) { | ||
// @ts-expect-error Legacy convenience for the time the 'request' lib was all the rage | ||
@@ -8,3 +8,3 @@ res = res.body || res; | ||
} | ||
function pagesTitles(res) { | ||
export function pagesTitles(res) { | ||
// @ts-expect-error Same behavior as above | ||
@@ -14,3 +14,2 @@ res = res.body || res; | ||
} | ||
export const parse = { entities, pagesTitles }; | ||
//# sourceMappingURL=parse_responses.js.map |
import type { Entities, Entity, SimplifiedEntity } from '../types/entity.js'; | ||
import type { SimplifyEntityOptions } from '../types/options.js'; | ||
export declare const simplifyEntity: (entity: Entity, options?: SimplifyEntityOptions) => SimplifiedEntity; | ||
export declare const simplifyEntities: (entities: Entities, options?: SimplifyEntityOptions) => any; | ||
export declare const simplifyEntities: (entities: Entities, options?: SimplifyEntityOptions) => Record<string, SimplifiedEntity>; |
@@ -1,2 +0,2 @@ | ||
import { simplify } from './simplify.js'; | ||
import * as simplify from './simplify.js'; | ||
export const simplifyEntity = (entity, options = {}) => { | ||
@@ -43,15 +43,11 @@ const { type } = entity; | ||
const { entityPrefix } = options; | ||
return Object.keys(entities).reduce((obj, key) => { | ||
const entity = entities[key]; | ||
if (entityPrefix) | ||
key = `${entityPrefix}:${key}`; | ||
obj[key] = simplifyEntity(entity, options); | ||
return obj; | ||
}, {}); | ||
// TODO: key as string is only a best effort. | ||
// key is either EntityID or `${prefix}:${EntityId}` based on options.entityPrefix | ||
const result = {}; | ||
for (const [key, entity] of Object.entries(entities)) { | ||
const resultKey = entityPrefix ? `${entityPrefix}:${key}` : key; | ||
result[resultKey] = simplifyEntity(entity, options); | ||
} | ||
return result; | ||
}; | ||
// Set those here instead of in ./simplify to avoid a circular dependency | ||
// @ts-expect-error | ||
simplify.entity = simplifyEntity; | ||
// @ts-expect-error | ||
simplify.entities = simplifyEntities; | ||
//# sourceMappingURL=simplify_entity.js.map |
@@ -1,29 +0,8 @@ | ||
import { simplifyClaim as claim, simplifyPropertyClaims as propertyClaims, simplifyClaims as claims, simplifyQualifier as qualifier, simplifyPropertyQualifiers as propertyQualifiers, simplifyQualifiers as qualifiers, simplifyReferences as references } from './simplify_claims.js'; | ||
import { simplifySenses as senses } from './simplify_senses.js'; | ||
import { simplifySitelinks as sitelinks } from './simplify_sitelinks.js'; | ||
import { simplifySparqlResults as sparqlResults } from './simplify_sparql_results.js'; | ||
import { simplifyLabels as labels, simplifyDescriptions as descriptions, simplifyAliases as aliases, simplifyLemmas as lemmas, simplifyRepresentations as representations, simplifyGlosses as glosses } from './simplify_text_attributes.js'; | ||
export declare const simplify: { | ||
labels: typeof labels; | ||
descriptions: typeof descriptions; | ||
aliases: typeof aliases; | ||
claim: typeof claim; | ||
propertyClaims: typeof propertyClaims; | ||
claims: typeof claims; | ||
qualifier: typeof qualifier; | ||
propertyQualifiers: typeof propertyQualifiers; | ||
qualifiers: typeof qualifiers; | ||
references: typeof references; | ||
sitelinks: typeof sitelinks; | ||
snak: typeof claim; | ||
propertySnaks: typeof propertyClaims; | ||
snaks: typeof claims; | ||
lemmas: typeof lemmas; | ||
representations: typeof representations; | ||
glosses: typeof glosses; | ||
form: (form: import("../types/lexeme.js").Form, options?: import("../types/simplify_claims.js").SimplifySnaksOptions) => import("../types/lexeme.js").SimplifiedForm; | ||
forms: (forms: any, options: any) => any; | ||
sense: (sense: import("../types/lexeme.js").Sense, options?: import("../types/simplify_claims.js").SimplifySnaksOptions) => import("../types/lexeme.js").SimplifiedSense; | ||
senses: typeof senses; | ||
sparqlResults: typeof sparqlResults; | ||
}; | ||
export { simplifyClaim as claim, simplifyClaims as claims, simplifyPropertyClaims as propertyClaims, simplifyPropertyQualifiers as propertyQualifiers, simplifyQualifier as qualifier, simplifyQualifiers as qualifiers, simplifyReferences as references, } from './simplify_claims.js'; | ||
export { simplifyForm as form, simplifyForms as forms, } from './simplify_forms.js'; | ||
export { simplifySense as sense, simplifySenses as senses, } from './simplify_senses.js'; | ||
export { simplifySitelinks as sitelinks } from './simplify_sitelinks.js'; | ||
export { simplifySparqlResults as sparqlResults } from './simplify_sparql_results.js'; | ||
export { simplifyAliases as aliases, simplifyDescriptions as descriptions, simplifyGlosses as glosses, simplifyLabels as labels, simplifyLemmas as lemmas, simplifyRepresentations as representations, } from './simplify_text_attributes.js'; | ||
export { simplifyEntities as entities, simplifyEntity as entity, } from './simplify_entity.js'; | ||
export { simplifyClaim as snak, simplifyClaims as snaks, simplifyPropertyClaims as propertySnaks, } from './simplify_claims.js'; |
@@ -1,36 +0,10 @@ | ||
import { simplifyClaim as claim, simplifyPropertyClaims as propertyClaims, simplifyClaims as claims, simplifyQualifier as qualifier, simplifyPropertyQualifiers as propertyQualifiers, simplifyQualifiers as qualifiers, simplifyReferences as references, } from './simplify_claims.js'; | ||
import { simplifyForm as form, simplifyForms as forms, } from './simplify_forms.js'; | ||
import { simplifySense as sense, simplifySenses as senses, } from './simplify_senses.js'; | ||
import { simplifySitelinks as sitelinks } from './simplify_sitelinks.js'; | ||
import { simplifySparqlResults as sparqlResults } from './simplify_sparql_results.js'; | ||
import { simplifyLabels as labels, simplifyDescriptions as descriptions, simplifyAliases as aliases, simplifyLemmas as lemmas, simplifyRepresentations as representations, simplifyGlosses as glosses, } from './simplify_text_attributes.js'; | ||
export const simplify = { | ||
labels, | ||
descriptions, | ||
aliases, | ||
claim, | ||
propertyClaims, | ||
claims, | ||
qualifier, | ||
propertyQualifiers, | ||
qualifiers, | ||
references, | ||
sitelinks, | ||
// Aliases | ||
snak: claim, | ||
propertySnaks: propertyClaims, | ||
snaks: claims, | ||
// Lexemes | ||
lemmas, | ||
representations, | ||
glosses, | ||
form, | ||
forms, | ||
sense, | ||
senses, | ||
sparqlResults, | ||
// Set in ./simplify_entity | ||
// entity, | ||
// entities, | ||
}; | ||
export { simplifyClaim as claim, simplifyClaims as claims, simplifyPropertyClaims as propertyClaims, simplifyPropertyQualifiers as propertyQualifiers, simplifyQualifier as qualifier, simplifyQualifiers as qualifiers, simplifyReferences as references, } from './simplify_claims.js'; | ||
export { simplifyForm as form, simplifyForms as forms, } from './simplify_forms.js'; | ||
export { simplifySense as sense, simplifySenses as senses, } from './simplify_senses.js'; | ||
export { simplifySitelinks as sitelinks } from './simplify_sitelinks.js'; | ||
export { simplifySparqlResults as sparqlResults } from './simplify_sparql_results.js'; | ||
export { simplifyAliases as aliases, simplifyDescriptions as descriptions, simplifyGlosses as glosses, simplifyLabels as labels, simplifyLemmas as lemmas, simplifyRepresentations as representations, } from './simplify_text_attributes.js'; | ||
export { simplifyEntities as entities, simplifyEntity as entity, } from './simplify_entity.js'; | ||
// Aliases | ||
export { simplifyClaim as snak, simplifyClaims as snaks, simplifyPropertyClaims as propertySnaks, } from './simplify_claims.js'; | ||
//# sourceMappingURL=simplify.js.map |
@@ -17,4 +17,4 @@ import type { Url, WmLanguageCode } from '../types/options.js'; | ||
export declare const isSitelinkKey: (site: string) => boolean; | ||
declare const projectNames: readonly ("commons" | "mediawiki" | "meta" | "specieswiki" | "wikidata" | "wikimania" | "wikipedia" | "wikisource" | "wikiquote" | "wiktionary" | "wikibooks" | "wikiversity" | "wikivoyage" | "wikinews")[]; | ||
declare const projectNames: readonly ("specieswiki" | "commons" | "mediawiki" | "meta" | "wikidata" | "wikimania" | "wikipedia" | "wikisource" | "wikiquote" | "wiktionary" | "wikibooks" | "wikiversity" | "wikivoyage" | "wikinews")[]; | ||
export type Project = typeof projectNames[number]; | ||
export {}; |
@@ -1,4 +0,4 @@ | ||
export declare const entityId: (value: import("../types/entity.js").EntityId) => void; | ||
export declare const entityId: (value: import("../index.js").EntityId) => void; | ||
export declare const propertyId: (value: `P${number}`) => void; | ||
export declare const entityPageTitle: (value: import("../types/entity.js").EntityPageTitle) => void; | ||
export declare const entityPageTitle: (value: import("../index.js").EntityPageTitle) => void; | ||
export declare const revisionId: (value: `${number}`) => void; |
@@ -1,8 +0,24 @@ | ||
import { WBK as _WBK } from './wikibase-sdk.js'; | ||
export default _WBK; | ||
export declare const WBK: typeof _WBK; | ||
import { WBK } from './wikibase-sdk.js'; | ||
export default WBK; | ||
export * from './wikibase-sdk.js'; | ||
export * from './helpers/helpers.js'; | ||
export * from './helpers/rank.js'; | ||
export * from './helpers/sitelinks.js'; | ||
export { parse } from './helpers/parse_responses.js'; | ||
export { simplify } from './helpers/simplify.js'; | ||
export * as parse from './helpers/parse_responses.js'; | ||
export * as simplify from './helpers/simplify.js'; | ||
export * from './helpers/simplify_claims.js'; | ||
export * from './helpers/simplify_entity.js'; | ||
export * from './helpers/simplify_forms.js'; | ||
export * from './helpers/simplify_senses.js'; | ||
export * from './helpers/simplify_sitelinks.js'; | ||
export * from './helpers/simplify_sparql_results.js'; | ||
export * from './helpers/simplify_text_attributes.js'; | ||
export * from './types/claim.js'; | ||
export * from './types/entity.js'; | ||
export * from './types/lexeme.js'; | ||
export * from './types/options.js'; | ||
export * from './types/search.js'; | ||
export * from './types/simplify_claims.js'; | ||
export * from './types/sitelinks.js'; | ||
export * from './types/sparql.js'; | ||
export * from './types/terms.js'; |
@@ -1,9 +0,25 @@ | ||
import { WBK as _WBK } from './wikibase-sdk.js'; | ||
export default _WBK; | ||
export const WBK = _WBK; | ||
import { WBK } from './wikibase-sdk.js'; | ||
export default WBK; | ||
export * from './wikibase-sdk.js'; | ||
export * from './helpers/helpers.js'; | ||
export * from './helpers/rank.js'; | ||
export * from './helpers/sitelinks.js'; | ||
export { parse } from './helpers/parse_responses.js'; | ||
export { simplify } from './helpers/simplify.js'; | ||
export * as parse from './helpers/parse_responses.js'; | ||
export * as simplify from './helpers/simplify.js'; | ||
export * from './helpers/simplify_claims.js'; | ||
export * from './helpers/simplify_entity.js'; | ||
export * from './helpers/simplify_forms.js'; | ||
export * from './helpers/simplify_senses.js'; | ||
export * from './helpers/simplify_sitelinks.js'; | ||
export * from './helpers/simplify_sparql_results.js'; | ||
export * from './helpers/simplify_text_attributes.js'; | ||
export * from './types/claim.js'; | ||
export * from './types/entity.js'; | ||
export * from './types/lexeme.js'; | ||
export * from './types/options.js'; | ||
export * from './types/search.js'; | ||
export * from './types/simplify_claims.js'; | ||
export * from './types/sitelinks.js'; | ||
export * from './types/sparql.js'; | ||
export * from './types/terms.js'; | ||
//# sourceMappingURL=index.js.map |
import type { ItemId } from './entity.js'; | ||
import type { Url } from './options.js'; | ||
import type { sites } from '../helpers/sitelinks_sites.js'; | ||
declare const multilangSitesNames: ("commons" | "mediawiki" | "meta" | "specieswiki" | "wikidata" | "wikimania")[]; | ||
export type Site = typeof sites[number] | typeof multilangSitesNames[number]; | ||
import type { specialSites } from '../helpers/special_sites.js'; | ||
type ValueOf<T> = T[keyof T]; | ||
type SpecialSiteName = ValueOf<typeof specialSites>; | ||
export type Site = typeof sites[number] | SpecialSiteName; | ||
export interface Sitelink { | ||
@@ -7,0 +9,0 @@ site: Site; |
@@ -1,3 +0,2 @@ | ||
import { specialSites } from '../helpers/special_sites.js'; | ||
const multilangSitesNames = Object.values(specialSites); | ||
export {}; | ||
//# sourceMappingURL=sitelinks.js.map |
@@ -61,2 +61,26 @@ import type { Claim, Claims, PropertyClaims, PropertyQualifiers, PropertySnaks, Qualifier, Qualifiers, References, Snak, Snaks } from './claim.js'; | ||
}; | ||
simplifyLabels(labels: Labels): SimplifiedLabels; | ||
simplifyDescriptions(descriptions: Descriptions): SimplifiedDescriptions; | ||
simplifyAliases(aliases: Aliases): SimplifiedAliases; | ||
simplifyClaim(claim: Claim): SimplifiedClaim; | ||
simplifyPropertyClaims(propertyClaims: PropertyClaims): SimplifiedPropertyClaims; | ||
simplifyClaims(claims: Claims): SimplifiedClaims; | ||
simplifyQualifier(qualifier: Qualifier): SimplifiedQualifier; | ||
simplifyPropertyQualifiers(propertyQualifiers: PropertyQualifiers): SimplifiedPropertyQualifiers; | ||
simplifyQualifiers(qualifiers: Qualifiers): SimplifiedQualifiers; | ||
simplifyReferences(references: References): SimplifiedReferences; | ||
simplifySitelinks(sitelinks: Sitelinks): SimplifiedSitelinks; | ||
simplifySnak(snak: Snak): SimplifiedSnak; | ||
simplifyPropertySnaks(propertySnaks: PropertySnaks): SimplifiedPropertySnaks; | ||
simplifySnaks(snaks: Snaks): SimplifiedSnaks; | ||
simplifyLemmas(lemmas: Lemmas): SimplifiedLemmas; | ||
simplifyRepresentations(representations: Representations): SimplifiedRepresentations; | ||
simplifyGlosses(glosses: Glosses): SimplifiedGlosses; | ||
simplifyForm(form: Form): SimplifiedForm; | ||
simplifyForms(forms: Forms): SimplifiedForms; | ||
simplifySense(sense: Sense): SimplifiedSense; | ||
simplifySenses(senses: Senses): SimplifiedSenses; | ||
simplifySparqlResults(sparqlResults: SparqlResults): SimplifiedSparqlResults; | ||
simplifyEntity(entity: Entity): SimplifiedEntity; | ||
simplifyEntities(entities: Entities): SimplifiedEntities; | ||
parse: { | ||
@@ -63,0 +87,0 @@ entities(res: WbGetEntitiesResponse): SimplifiedEntities; |
@@ -1,2 +0,2 @@ | ||
export declare const wdk: import("../types/wbk.js").Wbk; | ||
export declare const wdk: import("../wikibase-sdk.js").Wbk; | ||
export default wdk; |
@@ -1,2 +0,2 @@ | ||
import WBK from '../wikibase-sdk.js'; | ||
import { WBK } from '../wikibase-sdk.js'; | ||
export const wdk = WBK({ | ||
@@ -3,0 +3,0 @@ instance: 'https://www.wikidata.org', |
@@ -1,4 +0,69 @@ | ||
import type { InstanceConfig } from './types/options.js'; | ||
import type { Wbk } from './types/wbk.js'; | ||
import * as helpers from './helpers/helpers.js'; | ||
import * as parse from './helpers/parse_responses.js'; | ||
import * as rankHelpers from './helpers/rank.js'; | ||
import * as simplify from './helpers/simplify.js'; | ||
import * as sitelinksHelpers from './helpers/sitelinks.js'; | ||
import { cirrusSearchPagesFactory } from './queries/cirrus_search.js'; | ||
import { getEntitiesFactory } from './queries/get_entities.js'; | ||
import { getEntitiesFromSitelinksFactory } from './queries/get_entities_from_sitelinks.js'; | ||
import { getEntityRevisionFactory } from './queries/get_entity_revision.js'; | ||
import { getManyEntitiesFactory } from './queries/get_many_entities.js'; | ||
import { getReverseClaimsFactory } from './queries/get_reverse_claims.js'; | ||
import { getRevisionsFactory } from './queries/get_revisions.js'; | ||
import { searchEntitiesFactory } from './queries/search_entities.js'; | ||
import { sparqlQueryFactory } from './queries/sparql_query.js'; | ||
import type { InstanceConfig, Url } from './types/options.js'; | ||
declare const common: { | ||
readonly truthyPropertyClaims: typeof rankHelpers.truthyPropertyClaims; | ||
readonly nonDeprecatedPropertyClaims: typeof rankHelpers.nonDeprecatedPropertyClaims; | ||
readonly truthyClaims: typeof rankHelpers.truthyClaims; | ||
readonly getSitelinkUrl: typeof sitelinksHelpers.getSitelinkUrl; | ||
readonly getSitelinkData: typeof sitelinksHelpers.getSitelinkData; | ||
readonly isSitelinkKey: (site: string) => boolean; | ||
readonly isPropertyClaimsId: typeof helpers.isPropertyClaimsId; | ||
readonly isEntityPageTitle: typeof helpers.isEntityPageTitle; | ||
readonly getNumericId: typeof helpers.getNumericId; | ||
readonly getImageUrl: typeof helpers.getImageUrl; | ||
readonly getEntityIdFromGuid: typeof helpers.getEntityIdFromGuid; | ||
readonly isNumericId: (id: string) => id is `${number}`; | ||
readonly isEntityId: (id: string) => id is import("./index.js").EntityId; | ||
readonly isEntitySchemaId: (id: string) => id is `E${number}`; | ||
readonly isItemId: (id: string) => id is `Q${number}`; | ||
readonly isPropertyId: (id: string) => id is `P${number}`; | ||
readonly isLexemeId: (id: string) => id is `L${number}`; | ||
readonly isFormId: (id: string) => id is `L${number}-F${number}`; | ||
readonly isSenseId: (id: string) => id is `L${number}-S${number}`; | ||
readonly isMediaInfoId: (id: string) => id is `M${number}`; | ||
readonly isGuid: (id: string) => id is string; | ||
readonly isHash: (id: string) => id is string; | ||
readonly isRevisionId: (id: string) => id is `${number}`; | ||
readonly isNonNestedEntityId: (id: string) => id is import("./index.js").NonNestedEntityId; | ||
readonly wikibaseTimeToEpochTime: (value: helpers.TimeInputValue) => string | number; | ||
readonly wikibaseTimeToISOString: (value: helpers.TimeInputValue) => string; | ||
readonly wikibaseTimeToSimpleDay: (value: helpers.TimeInputValue) => string; | ||
readonly wikibaseTimeToDateObject: typeof import("./helpers/wikibase_time_to_date_object.js").wikibaseTimeToDateObject; | ||
readonly simplify: typeof simplify; | ||
readonly parse: typeof parse; | ||
}; | ||
type ApiQueries = { | ||
readonly searchEntities: ReturnType<typeof searchEntitiesFactory>; | ||
readonly cirrusSearchPages: ReturnType<typeof cirrusSearchPagesFactory>; | ||
readonly getEntities: ReturnType<typeof getEntitiesFactory>; | ||
readonly getManyEntities: ReturnType<typeof getManyEntitiesFactory>; | ||
readonly getRevisions: ReturnType<typeof getRevisionsFactory>; | ||
readonly getEntityRevision: ReturnType<typeof getEntityRevisionFactory>; | ||
readonly getEntitiesFromSitelinks: ReturnType<typeof getEntitiesFromSitelinksFactory>; | ||
}; | ||
type SparqlQueries = { | ||
readonly sparqlQuery: ReturnType<typeof sparqlQueryFactory>; | ||
readonly getReverseClaims: ReturnType<typeof getReverseClaimsFactory>; | ||
}; | ||
type Instance = { | ||
readonly root: Url; | ||
readonly apiEndpoint: Url; | ||
}; | ||
export type Wbk = { | ||
readonly instance: Instance; | ||
} & ApiQueries & SparqlQueries & typeof common; | ||
export declare function WBK(config: InstanceConfig): Wbk; | ||
export default WBK; | ||
export {}; |
import * as helpers from './helpers/helpers.js'; | ||
import { parse } from './helpers/parse_responses.js'; | ||
import * as parse from './helpers/parse_responses.js'; | ||
import * as rankHelpers from './helpers/rank.js'; | ||
import { simplify } from './helpers/simplify.js'; | ||
import * as simplify from './helpers/simplify.js'; | ||
import * as sitelinksHelpers from './helpers/sitelinks.js'; | ||
@@ -20,3 +20,4 @@ import { cirrusSearchPagesFactory } from './queries/cirrus_search.js'; | ||
import { isItemId, simplify } from 'wikibase-sdk'`; | ||
const common = Object.assign({ simplify, parse }, helpers, sitelinksHelpers, rankHelpers); | ||
const common = Object.assign(Object.assign(Object.assign({ simplify, | ||
parse }, helpers), sitelinksHelpers), rankHelpers); | ||
export function WBK(config) { | ||
@@ -31,3 +32,5 @@ if (!isPlainObject(config)) | ||
} | ||
let wikibaseApiFunctions, instanceRoot, instanceApiEndpoint; | ||
let wikibaseApiFunctions; | ||
let instanceRoot; | ||
let instanceApiEndpoint; | ||
if (instance) { | ||
@@ -90,3 +93,2 @@ validateEndpoint('instance', instance); | ||
const missingInstance = missingConfig('an instance'); | ||
export default WBK; | ||
//# sourceMappingURL=wikibase-sdk.js.map |
{ | ||
"name": "wikibase-sdk", | ||
"version": "9.0.4", | ||
"version": "9.0.5", | ||
"type": "module", | ||
@@ -74,3 +74,2 @@ "description": "utils functions to query a Wikibase instance and simplify its results", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"lodash-es": "^4.17.21", | ||
@@ -77,0 +76,0 @@ "mocha": "^10.2.0", |
@@ -16,10 +16,9 @@ # wikibase-sdk | ||
[![NPM](https://nodei.co/npm/wikibase-sdk.png?stars&downloads&downloadRank)](https://npmjs.com/package/wikibase-sdk/) | ||
[![License](https://img.shields.io/npm/l/wikibase-sdk)](https://opensource.org/licenses/MIT) | ||
[![npm version](https://img.shields.io/npm/v/wikibase-sdk)](https://www.npmjs.com/package/wikibase-sdk) | ||
[![Required Node.js version](https://img.shields.io/node/v/wikibase-sdk)](http://nodejs.org) | ||
[![npm downloads](https://img.shields.io/npm/dw/wikibase-sdk)](https://npm-stat.com/charts.html?package=wikibase-sdk) | ||
[![code style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
[![type definitions](https://img.shields.io/npm/types/wikibase-sdk)](https://www.typescriptlang.org/) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
[![Node](https://img.shields.io/badge/node-%3E=%20v6.4.0-brightgreen.svg)](http://nodejs.org) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
[download stats](https://npm-stat.com/charts.html?package=wikibase-sdk) | ||
## Summary | ||
@@ -26,0 +25,0 @@ |
@@ -21,3 +21,3 @@ import { wikibaseTimeToDateObject as toDateObject } from './wikibase_time_to_date_object.js' | ||
function isIdBuilder<T extends string> (regex: {readonly source: string, readonly flags: string}) { | ||
function isIdBuilder<T extends string> (regex: { readonly source: string, readonly flags: string }) { | ||
return (id: string): id is T => typeof id === 'string' && new RegExp(regex.source, regex.flags).test(id) | ||
@@ -24,0 +24,0 @@ } |
@@ -21,3 +21,3 @@ import { simplifyEntities } from './simplify_entity.js' | ||
function entities (res: WbGetEntitiesResponse): SimplifiedEntities { | ||
export function entities (res: WbGetEntitiesResponse): SimplifiedEntities { | ||
// @ts-expect-error Legacy convenience for the time the 'request' lib was all the rage | ||
@@ -29,3 +29,3 @@ res = res.body || res | ||
function pagesTitles (res: CirrusSearchPagesResponse): Titles { | ||
export function pagesTitles (res: CirrusSearchPagesResponse): Titles { | ||
// @ts-expect-error Same behavior as above | ||
@@ -35,3 +35,1 @@ res = res.body || res | ||
} | ||
export const parse = { entities, pagesTitles } as const |
@@ -1,2 +0,2 @@ | ||
import { simplify } from './simplify.js' | ||
import * as simplify from './simplify.js' | ||
import type { Entities, Entity, SimplifiedEntity } from '../types/entity.js' | ||
@@ -47,14 +47,13 @@ import type { SimplifyEntityOptions } from '../types/options.js' | ||
const { entityPrefix } = options | ||
return Object.keys(entities).reduce<any>((obj, key) => { | ||
const entity = entities[key] | ||
if (entityPrefix) key = `${entityPrefix}:${key}` | ||
obj[key] = simplifyEntity(entity, options) | ||
return obj | ||
}, {}) | ||
// TODO: key as string is only a best effort. | ||
// key is either EntityID or `${prefix}:${EntityId}` based on options.entityPrefix | ||
const result: Record<string, SimplifiedEntity> = {} | ||
for (const [ key, entity ] of Object.entries(entities)) { | ||
const resultKey = entityPrefix ? `${entityPrefix}:${key}` : key | ||
result[resultKey] = simplifyEntity(entity, options) | ||
} | ||
return result | ||
} | ||
// Set those here instead of in ./simplify to avoid a circular dependency | ||
// @ts-expect-error | ||
simplify.entity = simplifyEntity | ||
// @ts-expect-error | ||
simplify.entities = simplifyEntities |
@@ -6,5 +6,3 @@ import type { WmLanguageCode } from '../types/options.js' | ||
function singleValue<V> ( | ||
data: Partial<Readonly<Record<WmLanguageCode, InValue<V>>>> | ||
) { | ||
function singleValue<V> (data: Partial<Readonly<Record<WmLanguageCode, InValue<V>>>>) { | ||
const simplified: Partial<Record<WmLanguageCode, V>> = {} | ||
@@ -17,5 +15,3 @@ for (const [ lang, obj ] of Object.entries(data)) { | ||
function multiValue<V> ( | ||
data: Partial<Readonly<Record<WmLanguageCode, ReadonlyArray<InValue<V>>>>> | ||
) { | ||
function multiValue<V> (data: Partial<Readonly<Record<WmLanguageCode, ReadonlyArray<InValue<V>>>>>) { | ||
const simplified: Partial<Record<WmLanguageCode, readonly V[]>> = {} | ||
@@ -22,0 +18,0 @@ for (const [ lang, obj ] of Object.entries(data)) { |
@@ -1,62 +0,38 @@ | ||
import { | ||
export { | ||
simplifyClaim as claim, | ||
simplifyClaims as claims, | ||
simplifyPropertyClaims as propertyClaims, | ||
simplifyClaims as claims, | ||
simplifyPropertyQualifiers as propertyQualifiers, | ||
simplifyQualifier as qualifier, | ||
simplifyPropertyQualifiers as propertyQualifiers, | ||
simplifyQualifiers as qualifiers, | ||
simplifyReferences as references, | ||
} from './simplify_claims.js' | ||
import { | ||
export { | ||
simplifyForm as form, | ||
simplifyForms as forms, | ||
} from './simplify_forms.js' | ||
import { | ||
export { | ||
simplifySense as sense, | ||
simplifySenses as senses, | ||
} from './simplify_senses.js' | ||
import { simplifySitelinks as sitelinks } from './simplify_sitelinks.js' | ||
import { simplifySparqlResults as sparqlResults } from './simplify_sparql_results.js' | ||
import { | ||
export { simplifySitelinks as sitelinks } from './simplify_sitelinks.js' | ||
export { simplifySparqlResults as sparqlResults } from './simplify_sparql_results.js' | ||
export { | ||
simplifyAliases as aliases, | ||
simplifyDescriptions as descriptions, | ||
simplifyGlosses as glosses, | ||
simplifyLabels as labels, | ||
simplifyDescriptions as descriptions, | ||
simplifyAliases as aliases, | ||
simplifyLemmas as lemmas, | ||
simplifyRepresentations as representations, | ||
simplifyGlosses as glosses, | ||
} from './simplify_text_attributes.js' | ||
export { | ||
simplifyEntities as entities, | ||
simplifyEntity as entity, | ||
} from './simplify_entity.js' | ||
export const simplify = { | ||
labels, | ||
descriptions, | ||
aliases, | ||
claim, | ||
propertyClaims, | ||
claims, | ||
qualifier, | ||
propertyQualifiers, | ||
qualifiers, | ||
references, | ||
sitelinks, | ||
// Aliases | ||
snak: claim, | ||
propertySnaks: propertyClaims, | ||
snaks: claims, | ||
// Lexemes | ||
lemmas, | ||
representations, | ||
glosses, | ||
form, | ||
forms, | ||
sense, | ||
senses, | ||
sparqlResults, | ||
// Set in ./simplify_entity | ||
// entity, | ||
// entities, | ||
} | ||
// Aliases | ||
export { | ||
simplifyClaim as snak, | ||
simplifyClaims as snaks, | ||
simplifyPropertyClaims as propertySnaks, | ||
} from './simplify_claims.js' |
@@ -1,9 +0,26 @@ | ||
import { WBK as _WBK } from './wikibase-sdk.js' | ||
import { WBK } from './wikibase-sdk.js' | ||
export default _WBK | ||
export const WBK = _WBK | ||
export default WBK | ||
export * from './wikibase-sdk.js' | ||
export * from './helpers/helpers.js' | ||
export * from './helpers/rank.js' | ||
export * from './helpers/sitelinks.js' | ||
export { parse } from './helpers/parse_responses.js' | ||
export { simplify } from './helpers/simplify.js' | ||
export * as parse from './helpers/parse_responses.js' | ||
export * as simplify from './helpers/simplify.js' | ||
export * from './helpers/simplify_claims.js' | ||
export * from './helpers/simplify_entity.js' | ||
export * from './helpers/simplify_forms.js' | ||
export * from './helpers/simplify_senses.js' | ||
export * from './helpers/simplify_sitelinks.js' | ||
export * from './helpers/simplify_sparql_results.js' | ||
export * from './helpers/simplify_text_attributes.js' | ||
export * from './types/claim.js' | ||
export * from './types/entity.js' | ||
export * from './types/lexeme.js' | ||
export * from './types/options.js' | ||
export * from './types/search.js' | ||
export * from './types/simplify_claims.js' | ||
export * from './types/sitelinks.js' | ||
export * from './types/sparql.js' | ||
export * from './types/terms.js' |
@@ -1,9 +0,10 @@ | ||
import { specialSites } from '../helpers/special_sites.js' | ||
import type { ItemId } from './entity.js' | ||
import type { Url } from './options.js' | ||
import type { sites } from '../helpers/sitelinks_sites.js' | ||
import type { specialSites } from '../helpers/special_sites.js' | ||
const multilangSitesNames = Object.values(specialSites) | ||
type ValueOf<T> = T[keyof T] | ||
type SpecialSiteName = ValueOf<typeof specialSites> | ||
export type Site = typeof sites[number] | typeof multilangSitesNames[number] | ||
export type Site = typeof sites[number] | SpecialSiteName | ||
@@ -10,0 +11,0 @@ export interface Sitelink { |
@@ -1,2 +0,2 @@ | ||
import WBK from '../wikibase-sdk.js' | ||
import { WBK } from '../wikibase-sdk.js' | ||
@@ -3,0 +3,0 @@ export const wdk = WBK({ |
import * as helpers from './helpers/helpers.js' | ||
import { parse } from './helpers/parse_responses.js' | ||
import * as parse from './helpers/parse_responses.js' | ||
import * as rankHelpers from './helpers/rank.js' | ||
import { simplify } from './helpers/simplify.js' | ||
import * as simplify from './helpers/simplify.js' | ||
import * as sitelinksHelpers from './helpers/sitelinks.js' | ||
@@ -18,3 +18,2 @@ import { cirrusSearchPagesFactory } from './queries/cirrus_search.js' | ||
import type { InstanceConfig, Url } from './types/options.js' | ||
import type { Wbk } from './types/wbk.js' | ||
@@ -25,4 +24,29 @@ const tip = `Tip: if you just want to access functions that don't need an instance or a sparqlEndpoint, | ||
const common = Object.assign({ simplify, parse }, helpers, sitelinksHelpers, rankHelpers) | ||
const common = { | ||
simplify, | ||
parse, | ||
...helpers, | ||
...sitelinksHelpers, | ||
...rankHelpers, | ||
} as const | ||
type ApiQueries = { | ||
readonly searchEntities: ReturnType<typeof searchEntitiesFactory> | ||
readonly cirrusSearchPages: ReturnType<typeof cirrusSearchPagesFactory> | ||
readonly getEntities: ReturnType<typeof getEntitiesFactory> | ||
readonly getManyEntities: ReturnType<typeof getManyEntitiesFactory> | ||
readonly getRevisions: ReturnType<typeof getRevisionsFactory> | ||
readonly getEntityRevision: ReturnType<typeof getEntityRevisionFactory> | ||
readonly getEntitiesFromSitelinks: ReturnType<typeof getEntitiesFromSitelinksFactory> | ||
} | ||
type SparqlQueries = { | ||
readonly sparqlQuery: ReturnType<typeof sparqlQueryFactory> | ||
readonly getReverseClaims: ReturnType<typeof getReverseClaimsFactory> | ||
} | ||
type Instance = { | ||
readonly root: Url | ||
readonly apiEndpoint: Url | ||
} | ||
export type Wbk = { readonly instance: Instance } & ApiQueries & SparqlQueries & typeof common | ||
export function WBK (config: InstanceConfig): Wbk { | ||
@@ -39,3 +63,5 @@ if (!isPlainObject(config)) throw new Error('invalid config') | ||
let wikibaseApiFunctions, instanceRoot, instanceApiEndpoint | ||
let wikibaseApiFunctions: ApiQueries | ||
let instanceRoot: string | undefined | ||
let instanceApiEndpoint: string | undefined | ||
if (instance) { | ||
@@ -73,3 +99,3 @@ validateEndpoint('instance', instance) | ||
let wikibaseQueryServiceFunctions | ||
let wikibaseQueryServiceFunctions: SparqlQueries | ||
if (sparqlEndpoint) { | ||
@@ -111,3 +137,1 @@ validateEndpoint('sparqlEndpoint', sparqlEndpoint) | ||
const missingInstance = missingConfig('an instance') | ||
export default WBK |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
297694
18
174
6579
163