File tree Expand file tree Collapse file tree 4 files changed +11
-12
lines changed
Expand file tree Collapse file tree 4 files changed +11
-12
lines changed Original file line number Diff line number Diff line change 11import * as validate from '../helpers/validate.js'
22import { forceArray , rejectObsoleteInterface } from '../utils/utils.js'
33import type { EntityPageTitle } from '../types/entity.js'
4- import type { ApiQueryParameters , UrlResultFormat } from '../types/options.js'
5- import type { BuildUrlFunction } from '../utils/build_url.js'
4+ import type { UrlResultFormat } from '../types/options.js'
5+ import type { ApiQueryParameters , BuildUrlFunction } from '../utils/build_url.js'
66
77// See https://www.wikidata.org/w/api.php?action=help&modules=query+revisions
88
Original file line number Diff line number Diff line change @@ -11,8 +11,6 @@ export type Props = 'info' | 'sitelinks' | 'sitelinks/urls' | 'aliases' | 'label
1111export type UrlResultFormat = 'xml' | 'json'
1212export type WmLanguageCode = typeof languages [ number ]
1313
14- export type ApiQueryParameters = Record < string , string | number | true >
15-
1614// export type Url = `http${string}`
1715export type Url = string
1816
Original file line number Diff line number Diff line change 11import type { UrlResultFormat } from './options.js'
22
3- // TODO: not sure why this fails as an interface
4- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
5- export type WbGetEntities = {
3+ export interface WbGetEntities {
64 action : 'wbgetentities'
75 titles ?: string
86 sites ?: string
Original file line number Diff line number Diff line change 1- import type { ApiQueryParameters , Url } from '../types/options.js'
1+ import type { Url } from '../types/options.js'
22
33const isBrowser = typeof location !== 'undefined' && typeof document !== 'undefined'
44
5+ type ApiQueryValue = string | number | true
6+ export type ApiQueryParameters = Record < string , ApiQueryValue >
7+
8+ export type BuildUrlFunction = < T extends string > ( options : Readonly < Partial < Record < T , ApiQueryValue > > > ) => Url
9+
510export function buildUrlFactory ( instanceApiEndpoint : Url ) : BuildUrlFunction {
6- return function ( queryObj : ApiQueryParameters ) : Url {
11+ return queryObj => {
712 // Request CORS headers if the request is made from a browser
813 // See https://www.wikidata.org/w/api.php ('origin' parameter)
9- if ( isBrowser ) queryObj . origin = '*'
14+ if ( isBrowser ) queryObj = { ... queryObj , origin : '*' }
1015
1116 const queryEntries = Object . entries ( queryObj )
1217 // Remove null or undefined parameters
@@ -16,5 +21,3 @@ export function buildUrlFactory (instanceApiEndpoint: Url): BuildUrlFunction {
1621 return instanceApiEndpoint + '?' + query
1722 }
1823}
19-
20- export type BuildUrlFunction = ( options : ApiQueryParameters ) => Url
You can’t perform that action at this time.
0 commit comments