@hebcal/geo-sqlite 5.10.0 → 5.10.2

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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/geo-sqlite v5.10.0 */
1
+ /*! @hebcal/geo-sqlite v5.10.2 */
2
2
  import { DatabaseSync } from 'node:sqlite';
3
3
  import fs$1, { existsSync } from 'node:fs';
4
4
  import QuickLRU from 'quick-lru';
@@ -512,7 +512,7 @@ function munge(s) {
512
512
  }
513
513
 
514
514
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
515
- const version = '5.10.0';
515
+ const version = '5.10.2';
516
516
 
517
517
  const GEONAME_SQL = `SELECT
518
518
  g.name as name,
@@ -819,9 +819,6 @@ class GeoDb {
819
819
  if (admin1) {
820
820
  location.admin1 = admin1;
821
821
  }
822
- if (result.cc === 'IL' && admin1.startsWith('Jerusalem') && result.name.startsWith('Jerualem')) {
823
- location.jersualem = true;
824
- }
825
822
  if (result.population) {
826
823
  location.population = result.population;
827
824
  }
package/geo-sqlite.d.ts CHANGED
@@ -1,28 +1,161 @@
1
- /// <reference types="node"/>
2
-
3
1
  import {Location} from '@hebcal/core';
4
2
 
5
- declare module '@hebcal/geo-sqlite' {
6
- export type AutoComplete = {
7
- id: number | string;
8
- value: string;
9
- geo: 'geoname' | 'zip';
10
- asciiname: string;
11
- admin1?: string;
12
- country?: string;
13
- population?: number;
14
- latitude?: number;
15
- longitude?: number;
16
- timezone?: string;
17
- };
18
- export class GeoDb {
19
- constructor(logger: any, zipsFilename: string, geonamesFilename: string);
20
- close(): void;
21
- lookupZip(zip: string): Location;
22
- lookupGeoname(geonameid: number): Location;
23
- lookupLegacyCity(cityName: string): Location;
24
- autoComplete(qraw: string, latlong?: boolean): AutoComplete[];
25
- cacheZips(): void;
26
- cacheGeonames(): void;
27
- }
3
+ export type AutoComplete = {
4
+ id: number | string;
5
+ value: string;
6
+ geo: 'geoname' | 'zip';
7
+ name?: string;
8
+ asciiname?: string;
9
+ admin1?: string;
10
+ country?: string;
11
+ cc?: string;
12
+ population?: number;
13
+ latitude?: number;
14
+ longitude?: number;
15
+ timezone?: string;
16
+ elevation?: number;
17
+ };
18
+
19
+ /**
20
+ * Options for configuring the GeoDb constructor.
21
+ */
22
+ export type GeoDbOptions = {
23
+ /** Maximum number of entries in the ZIP code LRU cache. Default is 150. */
24
+ zipsCacheSize?: number;
25
+ /** Maximum number of entries in the geonames LRU cache. Default is 750. */
26
+ geonamesCacheSize?: number;
27
+ };
28
+
29
+ /**
30
+ * Options for `buildGeonamesSqlite`.
31
+ */
32
+ export type BuildGeonamesSqliteOptions = {
33
+ /** Path to the output SQLite database file. */
34
+ dbFilename: string;
35
+ /** Path to countryInfo.txt from geonames.org. */
36
+ countryInfotxt: string;
37
+ /** Path to cities5000.txt (or similar) from geonames.org. */
38
+ cities5000txt: string;
39
+ /** Path to a TSV patch file with additional city rows. */
40
+ citiesPatch: string;
41
+ /** Path to admin1CodesASCII.txt from geonames.org. */
42
+ admin1CodesASCIItxt: string;
43
+ /** Path to IL.txt (Israel geonames) from geonames.org. */
44
+ ILtxt: string;
45
+ /** Path to IL alternate names file from geonames.org. */
46
+ ILalternate: string;
47
+ /** Logger instance (e.g. pino). */
48
+ logger: any;
49
+ /** Minimum population filter for PPL feature codes. */
50
+ population?: number;
51
+ };
52
+
53
+ /**
54
+ * Wrapper around SQLite databases for looking up geographic locations
55
+ * by ZIP code, geoname ID, or legacy Hebcal city name.
56
+ */
57
+ export class GeoDb {
58
+ /**
59
+ * Opens the ZIP code and geonames SQLite databases.
60
+ * @param logger - Logger instance (e.g. pino), or `null` to disable logging
61
+ * @param zipsFilename - Path to the ZIP codes SQLite database file
62
+ * @param geonamesFilename - Path to the geonames SQLite database file
63
+ * @param options - Optional cache size configuration
64
+ */
65
+ constructor(logger: any, zipsFilename: string, geonamesFilename: string, options?: GeoDbOptions);
66
+
67
+ /** Closes both database handles. */
68
+ close(): void;
69
+
70
+ /**
71
+ * Looks up a US ZIP code and returns the corresponding location.
72
+ * @param zip - 5-digit US ZIP code (leading zeros preserved as string)
73
+ * @returns The location, or `null` if not found
74
+ */
75
+ lookupZip(zip: string): Location;
76
+
77
+ /**
78
+ * Looks up a geonames.org ID and returns the corresponding location.
79
+ * @param geonameid - Numeric geoname ID from geonames.org
80
+ * @returns The location, or `null` if not found
81
+ */
82
+ lookupGeoname(geonameid: number): Location;
83
+
84
+ /**
85
+ * Looks up a legacy Hebcal city name (e.g. "Jerusalem" or "New York")
86
+ * and returns the corresponding location.
87
+ * @param cityName - Legacy city name string
88
+ * @returns The location, or `null` if not found
89
+ */
90
+ lookupLegacyCity(cityName: string): Location;
91
+
92
+ /**
93
+ * Generates autocomplete suggestions for a query string.
94
+ * Numeric queries search ZIP codes; alphabetic queries search geonames
95
+ * and ZIP city names via full-text search.
96
+ * @param qraw - Raw query string from user input
97
+ * @param latlong - If `true`, include latitude, longitude, timezone, and population in results
98
+ * @returns Array of autocomplete suggestion objects, sorted by population
99
+ */
100
+ autoComplete(qraw: string, latlong?: boolean): AutoComplete[];
101
+
102
+ /**
103
+ * Reads the entire ZIP code database into an in-memory cache,
104
+ * replacing the default LRU cache. Useful for high-throughput servers.
105
+ */
106
+ cacheZips(): void;
107
+
108
+ /**
109
+ * Reads the entire geonames database into an in-memory cache,
110
+ * replacing the default LRU cache. Useful for high-throughput servers.
111
+ */
112
+ cacheGeonames(): void;
113
+
114
+ /**
115
+ * Returns the version string of the `@hebcal/geo-sqlite` package.
116
+ */
117
+ static version(): string;
118
+
119
+ /**
120
+ * Tests whether the given string begins with exactly 5 ASCII digits
121
+ * (a valid US ZIP code format).
122
+ * @param str - String to test
123
+ * @returns `true` if the string starts with 5 digits
124
+ */
125
+ static is5DigitZip(str: string): boolean;
126
+
127
+ /**
128
+ * Convenience wrapper around the `transliterate` function from the
129
+ * `transliteration` npm package. Converts Unicode text to ASCII.
130
+ * @param source - String to transliterate
131
+ * @param options - Options passed to the underlying `transliterate` function
132
+ * @returns Transliterated ASCII string
133
+ */
134
+ static transliterate(source: string, options?: any): string;
135
+
136
+ /**
137
+ * Builds a display string for a city from its name components.
138
+ * Applies special formatting for US ("USA") and UK ("UK") country names,
139
+ * and omits the admin1 subdivision when it duplicates the city name.
140
+ * @param cityName - City name, e.g. "Tel Aviv" or "Chicago"
141
+ * @param admin1 - First-level administrative subdivision, e.g. "Illinois"
142
+ * @param countryName - Full country name, e.g. "United States" or "Israel"
143
+ * @returns Formatted city description, e.g. "Chicago, Illinois, USA"
144
+ */
145
+ static geonameCityDescr(cityName: string, admin1: string, countryName: string): string;
28
146
  }
147
+
148
+ /**
149
+ * Builds the `geonames.sqlite3` database from raw text files
150
+ * downloaded from geonames.org.
151
+ * @param opts - Paths to input files and configuration
152
+ * @returns Resolves when the database has been built and closed
153
+ */
154
+ export function buildGeonamesSqlite(opts: BuildGeonamesSqliteOptions): Promise<boolean>;
155
+
156
+ /**
157
+ * Builds the `zips.sqlite3` database from a bundled SQL schema file.
158
+ * @param dbFilename - Path to the output SQLite database file
159
+ * @param sqlFile - Path to the SQL schema file to execute
160
+ */
161
+ export function makeZipsSqlite(dbFilename: string, sqlFile: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/geo-sqlite",
3
- "version": "5.10.0",
3
+ "version": "5.10.2",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "hebcal"
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@hebcal/cities": "^6.1.0",
42
- "@hebcal/core": "^6.3.3",
42
+ "@hebcal/core": "^6.5.0",
43
43
  "minimist": "^1.2.8",
44
44
  "pino": "^10.3.1",
45
45
  "pino-pretty": "^13.1.3",