@geospatial-sdk/geocoding 0.0.5-dev.13 → 0.0.5-dev.14

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.
@@ -1 +1 @@
1
- {"version":3,"file":"geonames.provider.d.ts","sourceRoot":"","sources":["../../lib/providers/geonames.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAK3C;;;;;;;;;GASG;AAEH,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAQD,wBAAgB,aAAa,CACzB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,eAAe,EAAE,CAAC,CAuD5B"}
1
+ {"version":3,"file":"geonames.provider.d.ts","sourceRoot":"","sources":["../../lib/providers/geonames.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAK3C;;;;;;;;;GASG;AAEH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAQD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,eAAe,EAAE,CAAC,CAiE5B"}
@@ -13,26 +13,30 @@ export function queryGeonames(input, options) {
13
13
  const url = new URL(baseUrl);
14
14
  url.searchParams.set("q", input.trim());
15
15
  url.searchParams.set("username", finalOptions.username);
16
- finalOptions.maxRows && url.searchParams.set("maxRows", finalOptions.maxRows.toString());
16
+ finalOptions.maxRows &&
17
+ url.searchParams.set("maxRows", finalOptions.maxRows.toString());
17
18
  if (typeof finalOptions.country === "string") {
18
19
  url.searchParams.set("country", finalOptions.country);
19
20
  }
20
21
  else if (Array.isArray(finalOptions.country)) {
21
- finalOptions.country.forEach(c => url.searchParams.append("country", c));
22
+ finalOptions.country.forEach((c) => url.searchParams.append("country", c));
22
23
  }
23
24
  finalOptions.lang && url.searchParams.set("lang", finalOptions.lang);
24
25
  finalOptions.style && url.searchParams.set("style", finalOptions.style);
25
26
  url.searchParams.set("type", "json");
26
- if (finalOptions.east !== undefined && finalOptions.west !== undefined &&
27
- finalOptions.north !== undefined && finalOptions.south !== undefined &&
28
- finalOptions.east > finalOptions.west && finalOptions.north > finalOptions.south) {
27
+ if (finalOptions.east !== undefined &&
28
+ finalOptions.west !== undefined &&
29
+ finalOptions.north !== undefined &&
30
+ finalOptions.south !== undefined &&
31
+ finalOptions.east > finalOptions.west &&
32
+ finalOptions.north > finalOptions.south) {
29
33
  url.searchParams.set("east", finalOptions.east.toString());
30
34
  url.searchParams.set("west", finalOptions.west.toString());
31
35
  url.searchParams.set("north", finalOptions.north.toString());
32
36
  url.searchParams.set("south", finalOptions.south.toString());
33
37
  }
34
38
  return fetch(url.toString())
35
- .then(response => {
39
+ .then((response) => {
36
40
  if (!response.ok) {
37
41
  throw new Error(`Geonames API returned ${response.status}: ${response.statusText}`);
38
42
  }
@@ -40,9 +44,9 @@ export function queryGeonames(input, options) {
40
44
  })
41
45
  .then((data) => {
42
46
  if (!data.geonames) {
43
- throw new Error('Invalid response from Geonames API: no geonames property');
47
+ throw new Error("Invalid response from Geonames API: no geonames property");
44
48
  }
45
- return data.geonames.map(geoname => ({
49
+ return data.geonames.map((geoname) => ({
46
50
  label: geoname.name,
47
51
  geom: {
48
52
  type: "Point",
@@ -1,129 +1,137 @@
1
- import {queryGeonames} from "./geonames.provider";
1
+ import { queryGeonames } from "./geonames.provider";
2
2
  import { GeocodingResult } from "../model";
3
- import {describe} from "vitest";
3
+ import { describe } from "vitest";
4
4
 
5
5
  const MOCK_DATA = {
6
- totalResultsCount: 35,
7
- geonames: [
8
- {
9
- adminCode1: "ZH",
10
- lng: "8.55",
11
- geonameId: 2657896,
12
- toponymName: "Zürich",
13
- countryId: "2658434",
14
- fcl: "P",
15
- population: 341730,
16
- countryCode: "CH",
17
- name: "Zurich",
18
- fclName: "city, village...",
19
- adminCodes1: { ISO3166_2: "ZH" },
20
- countryName: "Switzerland",
21
- fcodeName: "seat of a first-order administrative division",
22
- adminName1: "Zurich",
23
- lat: "47.36667",
24
- fcode: "PPLA"
25
- },
26
- {
27
- adminCode1: "ZH",
28
- lng: "8.66667",
29
- geonameId: 2657895,
30
- toponymName: "Kanton Zürich",
31
- countryId: "2658434",
32
- fcl: "A",
33
- population: 1553423,
34
- countryCode: "CH",
35
- name: "Zurich",
36
- fclName: "country, state, region...",
37
- adminCodes1: { ISO3166_2: "ZH" },
38
- countryName: "Switzerland",
39
- fcodeName: "first-order administrative division",
40
- adminName1: "Zurich",
41
- lat: "47.41667",
42
- fcode: "ADM1"
43
- }
44
- ]
6
+ totalResultsCount: 35,
7
+ geonames: [
8
+ {
9
+ adminCode1: "ZH",
10
+ lng: "8.55",
11
+ geonameId: 2657896,
12
+ toponymName: "Zürich",
13
+ countryId: "2658434",
14
+ fcl: "P",
15
+ population: 341730,
16
+ countryCode: "CH",
17
+ name: "Zurich",
18
+ fclName: "city, village...",
19
+ adminCodes1: { ISO3166_2: "ZH" },
20
+ countryName: "Switzerland",
21
+ fcodeName: "seat of a first-order administrative division",
22
+ adminName1: "Zurich",
23
+ lat: "47.36667",
24
+ fcode: "PPLA",
25
+ },
26
+ {
27
+ adminCode1: "ZH",
28
+ lng: "8.66667",
29
+ geonameId: 2657895,
30
+ toponymName: "Kanton Zürich",
31
+ countryId: "2658434",
32
+ fcl: "A",
33
+ population: 1553423,
34
+ countryCode: "CH",
35
+ name: "Zurich",
36
+ fclName: "country, state, region...",
37
+ adminCodes1: { ISO3166_2: "ZH" },
38
+ countryName: "Switzerland",
39
+ fcodeName: "first-order administrative division",
40
+ adminName1: "Zurich",
41
+ lat: "47.41667",
42
+ fcode: "ADM1",
43
+ },
44
+ ],
45
45
  };
46
46
 
47
- vi.stubGlobal('fetch', vi.fn(() =>
48
- Promise.resolve({
47
+ vi.stubGlobal(
48
+ "fetch",
49
+ vi.fn(
50
+ () =>
51
+ Promise.resolve({
49
52
  ok: true, // Ensure the mock reflects a successful response
50
53
  json: () => Promise.resolve(MOCK_DATA),
51
- }) as unknown as Response
52
- ));
53
-
54
+ }) as unknown as Response,
55
+ ),
56
+ );
54
57
 
55
58
  describe("queryGeonames", () => {
56
- let results: GeocodingResult[];
59
+ let results: GeocodingResult[];
57
60
 
58
- beforeEach(() => {
59
- vi.clearAllMocks();
60
- });
61
+ beforeEach(() => {
62
+ vi.clearAllMocks();
63
+ });
61
64
 
62
- describe("results parsing", () => {
63
- beforeEach(async () => {
64
- results = await queryGeonames("Zurich");
65
- });
66
- it("correctly processes Geonames API response", () => {
67
- expect(results).toEqual([
68
- {
69
- label: "Zurich",
70
- geom: {
71
- type: "Point",
72
- coordinates: [8.55, 47.36667],
73
- },
74
- },
75
- {
76
- label: "Zurich",
77
- geom: {
78
- type: "Point",
79
- coordinates: [8.66667, 47.41667],
80
- },
81
- },
82
- ]);
83
- });
65
+ describe("results parsing", () => {
66
+ beforeEach(async () => {
67
+ results = await queryGeonames("Zurich");
68
+ });
69
+ it("correctly processes Geonames API response", () => {
70
+ expect(results).toEqual([
71
+ {
72
+ label: "Zurich",
73
+ geom: {
74
+ type: "Point",
75
+ coordinates: [8.55, 47.36667],
76
+ },
77
+ },
78
+ {
79
+ label: "Zurich",
80
+ geom: {
81
+ type: "Point",
82
+ coordinates: [8.66667, 47.41667],
83
+ },
84
+ },
85
+ ]);
84
86
  });
85
- describe("default options", () => {
86
- beforeEach(async () => {
87
- results = await queryGeonames("Zurich");
88
- });
89
- it("uses default options", () => {
90
- expect(global.fetch).toHaveBeenCalledWith(
91
- expect.stringContaining("https://secure.geonames.org/searchJSON?q=Zurich&username=gn_ui&maxRows=10")
92
- );
93
- });
87
+ });
88
+ describe("default options", () => {
89
+ beforeEach(async () => {
90
+ results = await queryGeonames("Zurich");
94
91
  });
95
-
96
- describe("custom options", () => {
97
- beforeEach(async () => {
98
- results = await queryGeonames("Zurich", {
99
- lang: "de",
100
- maxRows: 5,
101
- country: "CH",
102
- username: "customUser",
103
- });
104
- });
105
- it("uses given options for custom search", () => {
106
- expect(global.fetch).toHaveBeenCalledWith(
107
- expect.stringContaining("https://secure.geonames.org/searchJSON?q=Zurich&username=customUser&maxRows=5&country=CH&lang=de&style=FULL&type=json")
108
- );
109
- });
92
+ it("uses default options", () => {
93
+ expect(global.fetch).toHaveBeenCalledWith(
94
+ expect.stringContaining(
95
+ "https://secure.geonames.org/searchJSON?q=Zurich&username=gn_ui&maxRows=10",
96
+ ),
97
+ );
110
98
  });
99
+ });
111
100
 
112
- describe("bounding box search", () => {
113
- beforeEach(async () => {
114
- results = await queryGeonames("Zurich", {
115
- east: 10,
116
- west: 5,
117
- north: 50,
118
- south: 45,
119
- username: "customUser",
120
- });
121
- });
122
- it("uses given options for bounding box search", () => {
123
- expect(global.fetch).toHaveBeenCalledWith(
124
- expect.stringContaining("https://secure.geonames.org/searchJSON?q=Zurich&username=customUser&maxRows=10&lang=en&style=FULL&type=json&east=10&west=5&north=50&south=45")
125
- );
126
- });
101
+ describe("custom options", () => {
102
+ beforeEach(async () => {
103
+ results = await queryGeonames("Zurich", {
104
+ lang: "de",
105
+ maxRows: 5,
106
+ country: "CH",
107
+ username: "customUser",
108
+ });
127
109
  });
110
+ it("uses given options for custom search", () => {
111
+ expect(global.fetch).toHaveBeenCalledWith(
112
+ expect.stringContaining(
113
+ "https://secure.geonames.org/searchJSON?q=Zurich&username=customUser&maxRows=5&country=CH&lang=de&style=FULL&type=json",
114
+ ),
115
+ );
116
+ });
117
+ });
128
118
 
129
- });
119
+ describe("bounding box search", () => {
120
+ beforeEach(async () => {
121
+ results = await queryGeonames("Zurich", {
122
+ east: 10,
123
+ west: 5,
124
+ north: 50,
125
+ south: 45,
126
+ username: "customUser",
127
+ });
128
+ });
129
+ it("uses given options for bounding box search", () => {
130
+ expect(global.fetch).toHaveBeenCalledWith(
131
+ expect.stringContaining(
132
+ "https://secure.geonames.org/searchJSON?q=Zurich&username=customUser&maxRows=10&lang=en&style=FULL&type=json&east=10&west=5&north=50&south=45",
133
+ ),
134
+ );
135
+ });
136
+ });
137
+ });
@@ -15,79 +15,89 @@ const baseUrl = "https://secure.geonames.org/searchJSON";
15
15
  */
16
16
 
17
17
  export interface GeonamesOptions {
18
- lang?: string;
19
- maxRows?: number;
20
- country?: string | string[]; // Now supports multiple countries
21
- style?: "SHORT" | "MEDIUM" | "LONG" | "FULL";
22
- username: string;
23
- east?: number;
24
- west?: number;
25
- north?: number;
26
- south?: number;
18
+ lang?: string;
19
+ maxRows?: number;
20
+ country?: string | string[]; // Now supports multiple countries
21
+ style?: "SHORT" | "MEDIUM" | "LONG" | "FULL";
22
+ username: string;
23
+ east?: number;
24
+ west?: number;
25
+ north?: number;
26
+ south?: number;
27
27
  }
28
28
 
29
29
  interface GeonameResponse {
30
- name: string;
31
- lng: string;
32
- lat: string;
30
+ name: string;
31
+ lng: string;
32
+ lat: string;
33
33
  }
34
34
 
35
35
  export function queryGeonames(
36
- input: string,
37
- options?: GeonamesOptions,
36
+ input: string,
37
+ options?: GeonamesOptions,
38
38
  ): Promise<GeocodingResult[]> {
39
- if (!input.trim()) {
40
- throw new Error("Input query is required and cannot be empty.");
41
- }
39
+ if (!input.trim()) {
40
+ throw new Error("Input query is required and cannot be empty.");
41
+ }
42
42
 
43
- const baseOptions: GeonamesOptions = {
44
- lang: "en",
45
- maxRows: 10,
46
- style: "FULL",
47
- username: "gn_ui",
48
- };
43
+ const baseOptions: GeonamesOptions = {
44
+ lang: "en",
45
+ maxRows: 10,
46
+ style: "FULL",
47
+ username: "gn_ui",
48
+ };
49
49
 
50
- const finalOptions = { ...baseOptions, ...options };
50
+ const finalOptions = { ...baseOptions, ...options };
51
51
 
52
- const url = new URL(baseUrl);
53
- url.searchParams.set("q", input.trim());
54
- url.searchParams.set("username", finalOptions.username);
55
- finalOptions.maxRows && url.searchParams.set("maxRows", finalOptions.maxRows.toString());
56
- if (typeof finalOptions.country === "string") {
57
- url.searchParams.set("country", finalOptions.country);
58
- } else if (Array.isArray(finalOptions.country)) {
59
- finalOptions.country.forEach(c => url.searchParams.append("country", c));
60
- }
61
- finalOptions.lang && url.searchParams.set("lang", finalOptions.lang);
62
- finalOptions.style && url.searchParams.set("style", finalOptions.style);
63
- url.searchParams.set("type", "json");
52
+ const url = new URL(baseUrl);
53
+ url.searchParams.set("q", input.trim());
54
+ url.searchParams.set("username", finalOptions.username);
55
+ finalOptions.maxRows &&
56
+ url.searchParams.set("maxRows", finalOptions.maxRows.toString());
57
+ if (typeof finalOptions.country === "string") {
58
+ url.searchParams.set("country", finalOptions.country);
59
+ } else if (Array.isArray(finalOptions.country)) {
60
+ finalOptions.country.forEach((c) => url.searchParams.append("country", c));
61
+ }
62
+ finalOptions.lang && url.searchParams.set("lang", finalOptions.lang);
63
+ finalOptions.style && url.searchParams.set("style", finalOptions.style);
64
+ url.searchParams.set("type", "json");
64
65
 
65
- if (finalOptions.east !== undefined && finalOptions.west !== undefined &&
66
- finalOptions.north !== undefined && finalOptions.south !== undefined &&
67
- finalOptions.east > finalOptions.west && finalOptions.north > finalOptions.south) {
68
- url.searchParams.set("east", finalOptions.east.toString());
69
- url.searchParams.set("west", finalOptions.west.toString());
70
- url.searchParams.set("north", finalOptions.north.toString());
71
- url.searchParams.set("south", finalOptions.south.toString());
72
- }
66
+ if (
67
+ finalOptions.east !== undefined &&
68
+ finalOptions.west !== undefined &&
69
+ finalOptions.north !== undefined &&
70
+ finalOptions.south !== undefined &&
71
+ finalOptions.east > finalOptions.west &&
72
+ finalOptions.north > finalOptions.south
73
+ ) {
74
+ url.searchParams.set("east", finalOptions.east.toString());
75
+ url.searchParams.set("west", finalOptions.west.toString());
76
+ url.searchParams.set("north", finalOptions.north.toString());
77
+ url.searchParams.set("south", finalOptions.south.toString());
78
+ }
73
79
 
74
- return fetch(url.toString())
75
- .then(response => {
76
- if (!response.ok) {
77
- throw new Error(`Geonames API returned ${response.status}: ${response.statusText}`);
78
- }
79
- return response.json();
80
- })
81
- .then((data: { geonames: GeonameResponse[] }) => {
82
- if (!data.geonames) {
83
- throw new Error('Invalid response from Geonames API: no geonames property');
84
- }
85
- return data.geonames.map(geoname => ({
86
- label: geoname.name,
87
- geom: {
88
- type: "Point",
89
- coordinates: [parseFloat(geoname.lng), parseFloat(geoname.lat)],
90
- } as Geometry,
91
- }));
92
- });
93
- }
80
+ return fetch(url.toString())
81
+ .then((response) => {
82
+ if (!response.ok) {
83
+ throw new Error(
84
+ `Geonames API returned ${response.status}: ${response.statusText}`,
85
+ );
86
+ }
87
+ return response.json();
88
+ })
89
+ .then((data: { geonames: GeonameResponse[] }) => {
90
+ if (!data.geonames) {
91
+ throw new Error(
92
+ "Invalid response from Geonames API: no geonames property",
93
+ );
94
+ }
95
+ return data.geonames.map((geoname) => ({
96
+ label: geoname.name,
97
+ geom: {
98
+ type: "Point",
99
+ coordinates: [parseFloat(geoname.lng), parseFloat(geoname.lat)],
100
+ } as Geometry,
101
+ }));
102
+ });
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geospatial-sdk/geocoding",
3
- "version": "0.0.5-dev.13+4cd825d",
3
+ "version": "0.0.5-dev.14+cde890f",
4
4
  "description": "Geocoding-related components",
5
5
  "keywords": [
6
6
  "geocoding"
@@ -32,5 +32,5 @@
32
32
  "bugs": {
33
33
  "url": "https://github.com/jahow/geospatial-sdk/issues"
34
34
  },
35
- "gitHead": "4cd825d11d70758c227ca0b955bcf571282bfea7"
35
+ "gitHead": "cde890ff1c4f9dc9bb07b1c33bcbed68e06550c9"
36
36
  }