Skip to content

Commit

Permalink
Merge pull request entur#227 from entur/explicit-client-types
Browse files Browse the repository at this point in the history
Add and export explicit client types
  • Loading branch information
draperunner authored Jun 25, 2021
2 parents e55891f + 93fcbc1 commit d3ceadd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'regenerator-runtime/runtime'

import EnturService from './service'
import createEnturService from './service'
export type { EnturService } from './service'

export {
convertFeatureToLocation,
Expand All @@ -9,7 +10,10 @@ export {
} from './utils'

export * as MobilityTypes from './mobility/types'
export type { MobilityClient } from './mobility'

export * as NsrTypes from './nsr/types'
export type { NsrClient } from './nsr'

export { TypeName } from './nearest/types'
export type { NearestPlace } from './nearest/types'
Expand Down Expand Up @@ -40,7 +44,7 @@ export type { DeparturesById } from './departure'
export { County } from './geocoder/countyIds'
export type { GetFeaturesParams, GetFeaturesReverseParam } from './geocoder'

export default EnturService
export default createEnturService

export type { Authority } from './fields/Authority'
export type { BikeRentalStation } from './fields/BikeRentalStation'
Expand Down
8 changes: 7 additions & 1 deletion src/mobility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { default as createGetStations } from './getStations'
import { default as createGetVehicles } from './getVehicles'
import { default as createGetOperators } from './getOperators'

export default function createClient(config: ArgumentConfig) {
export interface MobilityClient {
getOperators: ReturnType<typeof createGetOperators>
getStations: ReturnType<typeof createGetStations>
getVehicles: ReturnType<typeof createGetVehicles>
}

export default function createClient(config: ArgumentConfig): MobilityClient {
return {
getOperators: createGetOperators(config),
getStations: createGetStations(config),
Expand Down
14 changes: 13 additions & 1 deletion src/nsr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import { default as createGetStopPlaceForQuay } from './getStopPlaceForQuay'
import { default as createGetTariffZone } from './getTariffZone'
import { default as createGetTopographicPlace } from './getTopographicPlace'

export default function createClient(config: ArgumentConfig) {
export interface NsrClient {
getFareZone: ReturnType<typeof createGetFareZone>
getGroupOfStopPlaces: ReturnType<typeof createGetGroupOfStopPlaces>
getParking: ReturnType<typeof createGetParking>
getParkingsForStopPlace: ReturnType<typeof createGetParkingsForStopPlace>
getQuay: ReturnType<typeof createGetQuay>
getStopPlace: ReturnType<typeof createGetStopPlace>
getStopPlaceForQuay: ReturnType<typeof createGetStopPlaceForQuay>
getTariffZone: ReturnType<typeof createGetTariffZone>
getTopographicPlace: ReturnType<typeof createGetTopographicPlace>
}

export default function createClient(config: ArgumentConfig): NsrClient {
return {
getFareZone: createGetFareZone(config),
getGroupOfStopPlaces: createGetGroupOfStopPlaces(config),
Expand Down
62 changes: 59 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
createGetQuaysForStopPlace,
} from './stopPlace'

import { default as createMobilityClient } from './mobility'
import { default as createMobilityClient, MobilityClient } from './mobility'

import { default as createNsrClient } from './nsr'
import { default as createNsrClient, NsrClient } from './nsr'

import {
createGetBikeRentalStation,
Expand All @@ -39,7 +39,63 @@ import { createGetFeatures, createGetFeaturesReverse } from './geocoder'

import { ArgumentConfig, getServiceConfig, ServiceConfig } from './config'

function createEnturService(config: ArgumentConfig) {
export interface EnturService {
journeyPlannerQuery: <T>(
query: string,
variables: Record<string, unknown>,
config: ServiceConfig,
) => Promise<T>
queryJourneyPlanner: <T>(
queryObj: string,
variables: Record<string, unknown>,
options?: RequestOptions,
) => Promise<T>
nsrQuery: <T>(
query: string,
variables: Record<string, unknown>,
config: ServiceConfig,
) => Promise<T>
queryNsr: <T>(
queryObj: string,
variables: Record<string, unknown>,
options?: RequestOptions,
) => Promise<T>
getFeatures: ReturnType<typeof createGetFeatures>
getFeaturesReverse: ReturnType<typeof createGetFeaturesReverse>
getTripPatterns: ReturnType<typeof createGetTripPatterns>
findTrips: ReturnType<typeof createFindTrips>
getStopPlaceDepartures: typeof getStopPlaceDeparturesDEPRECATED
getDeparturesFromStopPlace: ReturnType<
typeof createGetDeparturesFromStopPlace
>
getDeparturesFromStopPlaces: ReturnType<
typeof createGetDeparturesFromStopPlaces
>
getDeparturesFromQuays: ReturnType<typeof createGetDeparturesFromQuays>
getDeparturesBetweenStopPlaces: ReturnType<
typeof createGetDeparturesBetweenStopPlaces
>
getDeparturesForServiceJourney: ReturnType<
typeof createGetDeparturesForServiceJourney
>
getNearestPlaces: ReturnType<typeof createGetNearestPlaces>
getStopPlace: ReturnType<typeof createGetStopPlace>
getStopPlaces: ReturnType<typeof createGetStopPlaces>
getParentStopPlace: ReturnType<typeof createGetParentStopPlace>
getStopPlacesByPosition: ReturnType<typeof createGetStopPlacesByPosition>
getStopPlaceFacilities: ReturnType<typeof createGetStopPlaceFacilities>
getQuaysForStopPlace: ReturnType<typeof createGetQuaysForStopPlace>
getBikeRentalStation: ReturnType<typeof createGetBikeRentalStation>
getBikeRentalStations: ReturnType<typeof createGetBikeRentalStations>
getBikeRentalStationsByPosition: ReturnType<
typeof createGetBikeRentalStationsByPosition
>
getScootersByPosition: ReturnType<typeof createGetScootersByPosition>
mobility: MobilityClient
nsr: NsrClient
}

function createEnturService(config: ArgumentConfig): EnturService {
return {
journeyPlannerQuery: <T>(
query: string,
Expand Down

0 comments on commit d3ceadd

Please sign in to comment.