web / lib/services/geocoding/types
lib/services/geocoding/types
Defines the core TypeScript types, interfaces, and constants for the geocoding service.
This file serves as a central repository for the data structures and contracts used throughout the geocoding system. It ensures type safety and consistency across different modules, including the main service, provider manager, cache manager, and operations.
It defines:
- The structure of a geocoding result.
- The shape of batch geocoding results.
- A custom
GeocodingErrorclass for standardized error handling. - Configuration interfaces for providers and the overall service settings.
- Shared constants like collection slugs and default URLs.
Classes
GeocodingError
Extends
Error
Constructors
Constructor
new GeocodingError(
message,code,retryable?):GeocodingError
Parameters
message
string
code
string
retryable?
boolean = false
Returns
Overrides
Error.constructor
Properties
stackTraceLimit
staticstackTraceLimit:number
The Error.stackTraceLimit property specifies the number of stack frames
collected by a stack trace (whether generated by new Error().stack or
Error.captureStackTrace(obj)).
The default value is 10 but may be set to any valid JavaScript number. Changes
will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Inherited from
Error.stackTraceLimit
cause?
optionalcause:unknown
Inherited from
Error.cause
name
name:
string
Inherited from
Error.name
message
message:
string
Inherited from
Error.message
stack?
optionalstack:string
Inherited from
Error.stack
code
code:
string
retryable
retryable:
boolean=false
Methods
captureStackTrace()
staticcaptureStackTrace(targetObject,constructorOpt?):void
Creates a .stack property on targetObject, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames
above constructorOpt, including constructorOpt, will be omitted from the
generated stack trace.
The constructorOpt argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
targetObject
object
constructorOpt?
Function
Returns
void
Inherited from
Error.captureStackTrace
prepareStackTrace()
staticprepareStackTrace(err,stackTraces):any
Parameters
err
Error
stackTraces
CallSite[]
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTrace
Interfaces
GeocodingResult
Extends
Pick<LocationCache,"latitude"|"longitude"|"confidence"|"provider"|"normalizedAddress">
Properties
components
components:
{ streetNumber?: string \| null; streetName?: string \| null; city?: string \| null; region?: string \| null; postalCode?: string \| null; country?: string \| null; }|undefined
Type Declaration
{ streetNumber?: string \| null; streetName?: string \| null; city?: string \| null; region?: string \| null; postalCode?: string \| null; country?: string \| null; }
streetNumber?
optionalstreetNumber:string|null
Street number
streetName?
optionalstreetName:string|null
Street name
city?
optionalcity:string|null
City name
region?
optionalregion:string|null
State/Region/Province
postalCode?
optionalpostalCode:string|null
Postal/ZIP code
country?
optionalcountry:string|null
Country name
undefined
metadata
metadata:
string|number|boolean|unknown[] |{ \[k: string\]: unknown; }|null|undefined
fromCache?
optionalfromCache:boolean
normalizedAddress
normalizedAddress:
string
Normalized address for better matching
Inherited from
Pick.normalizedAddress
latitude
latitude:
number
Latitude coordinate (WGS84)
Inherited from
Pick.latitude
longitude
longitude:
number
Longitude coordinate (WGS84)
Inherited from
Pick.longitude
provider
provider:
string
Name of the geocoding provider used
Inherited from
Pick.provider
confidence?
optionalconfidence:number|null
Confidence score (0-1)
Inherited from
Pick.confidence
BatchGeocodingResult
Properties
results
results:
Map<string,GeocodingResult|GeocodingError>
summary
summary:
object
total
total:
number
successful
successful:
number
failed
failed:
number
cached
cached:
number
ProviderConfig
Properties
name
name:
string
geocoder
geocoder:
Geocoder
priority
priority:
number
enabled
enabled:
boolean
rateLimit
rateLimit:
number
GeocodingSettings
Properties
enabled
enabled:
boolean
fallbackEnabled
fallbackEnabled:
boolean
providerSelection
providerSelection:
object
strategy
strategy:
string
requiredTags
requiredTags:
string[]
caching
caching:
object
enabled
enabled:
boolean
ttlDays
ttlDays:
number
Variables
DEFAULT_NOMINATIM_RATE_LIMIT
constDEFAULT_NOMINATIM_RATE_LIMIT:1=1
Default rate limit for Nominatim public instance (1 request/second per OSM policy)
LOCATION_CACHE_COLLECTION
constLOCATION_CACHE_COLLECTION:"location-cache"="location-cache"
NOMINATIM_BASE_URL
constNOMINATIM_BASE_URL:"https://nominatim.openstreetmap.org"="https://nominatim.openstreetmap.org"
TIMETILES_USER_AGENT
constTIMETILES_USER_AGENT:"TimeTiles/1.0 (https://github.com/jfilter/timetiles)"="TimeTiles/1.0 (https://github.com/jfilter/timetiles)"