@hebcal/geo-sqlite 5.7.4 → 5.9.0

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.
@@ -39,6 +39,8 @@ $CURDIR/node_modules/.bin/build-geonames-sqlite \
39
39
 
40
40
  rm -rf $TMPDIR
41
41
 
42
- sqlite3 -echo zips.sqlite3 < "$CURDIR/node_modules/@hebcal/geo-sqlite/zips-dummy.sql"
42
+ $CURDIR/node_modules/.bin/make-zips-sqlite \
43
+ $CURDIR/zips.sqlite3 \
44
+ "$CURDIR/node_modules/@hebcal/geo-sqlite/zips-dummy.sql"
43
45
 
44
46
  ls -lh geonames.sqlite3 zips.sqlite3
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {makeZipsSqlite} from '@hebcal/geo-sqlite';
4
+ import {createRequire} from 'module';
5
+ import path from 'path';
6
+
7
+ const require = createRequire(import.meta.url);
8
+ const pkgPath = require.resolve('@hebcal/geo-sqlite/package.json');
9
+ const defaultSqlFile = path.join(path.dirname(pkgPath), 'zips-dummy.sql');
10
+
11
+ const args = process.argv.slice(2);
12
+ if (args.length < 1 || args.length > 2) {
13
+ console.log('Usage: make-zips-sqlite zips.sqlite3 [zips-dummy.sql]');
14
+ process.exit(1);
15
+ }
16
+
17
+ const dbFilename = args[0];
18
+ const sqlFile = args[1] || defaultSqlFile;
19
+ makeZipsSqlite(dbFilename, sqlFile);
20
+ console.log('Done!');
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/geo-sqlite v5.7.4 */
1
+ /*! @hebcal/geo-sqlite v5.9.0 */
2
2
  import Database from 'better-sqlite3';
3
3
  import QuickLRU from 'quick-lru';
4
4
  import { Location, Locale } from '@hebcal/core';
@@ -511,7 +511,7 @@ function munge(s) {
511
511
  }
512
512
 
513
513
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
514
- const version = '5.7.4';
514
+ const version = '5.9.0';
515
515
 
516
516
  const GEONAME_SQL = `SELECT
517
517
  g.name as name,
@@ -635,19 +635,22 @@ class GeoDb {
635
635
  * @param {any} logger
636
636
  * @param {string} zipsFilename
637
637
  * @param {string} geonamesFilename
638
+ * @param {any} options
638
639
  */
639
- constructor(logger, zipsFilename, geonamesFilename) {
640
+ constructor(logger, zipsFilename, geonamesFilename, options) {
640
641
  this.logger = logger;
641
642
  if (logger) logger.info(`GeoDb: opening ${zipsFilename}...`);
642
643
  this.zipsDb = new Database(zipsFilename, {fileMustExist: true});
643
644
  if (logger) logger.info(`GeoDb: opening ${geonamesFilename}...`);
644
645
  this.geonamesDb = new Database(geonamesFilename, {fileMustExist: true});
645
646
  this.zipStmt = this.zipsDb.prepare(ZIPCODE_SQL);
647
+ const zipsCacheSize = options?.zipsCacheSize || 150;
646
648
  /** @type {Map<string, Location>} */
647
- this.zipCache = new QuickLRU({maxSize: 150});
649
+ this.zipCache = new QuickLRU({maxSize: zipsCacheSize});
648
650
  this.geonamesStmt = this.geonamesDb.prepare(GEONAME_SQL);
651
+ const geonamesCacheSize = options?.geonamesCacheSize || 750;
649
652
  /** @type {Map<number, Location>} */
650
- this.geonamesCache = new QuickLRU({maxSize: 750});
653
+ this.geonamesCache = new QuickLRU({maxSize: geonamesCacheSize});
651
654
  /** @type {Map<string, number>} */
652
655
  this.legacyCities = new Map();
653
656
  for (const [name, id] of Object.entries(city2geonameid)) {
@@ -690,7 +693,7 @@ class GeoDb {
690
693
  lookupZip(zip) {
691
694
  const zip5 = zip.trim().substring(0, 5);
692
695
  const found = this.zipCache.get(zip5);
693
- if (typeof found !== 'undefined') return found;
696
+ if (found !== undefined) return found;
694
697
  const result = this.zipStmt.get(zip5);
695
698
  if (!result) {
696
699
  if (this.logger) this.logger.warn(`GeoDb: unknown zipcode=${zip5}`);
@@ -735,7 +738,7 @@ class GeoDb {
735
738
  geonameid = 293397;
736
739
  }
737
740
  const found = this.geonamesCache.get(geonameid);
738
- if (typeof found !== 'undefined') return found;
741
+ if (found !== undefined) return found;
739
742
  const result = this.geonamesStmt.get(geonameid);
740
743
  if (!result) {
741
744
  if (this.logger) this.logger.warn(`GeoDb: unknown geonameid=${geonameid}`);
@@ -884,7 +887,7 @@ class GeoDb {
884
887
  if (!this.geonamesCompStmt) {
885
888
  this.geonamesCompStmt = this.geonamesDb.prepare(GEONAME_COMPLETE_SQL);
886
889
  }
887
- qraw = qraw.replace(/"/g, '""');
890
+ qraw = qraw.replaceAll('"', '""');
888
891
  const geoRows0 = this.geonamesCompStmt.all(`{longname} : "${qraw}" *`);
889
892
  const ids = new Set();
890
893
  const geoRows = [];
@@ -1433,4 +1436,16 @@ async function doFile(logger, db, infile, tableName, expectedFields, callback) {
1433
1436
  });
1434
1437
  }
1435
1438
 
1436
- export { GeoDb, buildGeonamesSqlite };
1439
+ /**
1440
+ * Builds `zips.sqlite3` from the bundled zips-dummy.sql schema file
1441
+ * @param {string} dbFilename path to the output SQLite database file
1442
+ * @param {string} sqlFile path to the SQL schema file
1443
+ */
1444
+ function makeZipsSqlite(dbFilename, sqlFile) {
1445
+ const sql = fs.readFileSync(sqlFile, 'utf8');
1446
+ const db = new Database(dbFilename);
1447
+ db.exec(sql);
1448
+ db.close();
1449
+ }
1450
+
1451
+ export { GeoDb, buildGeonamesSqlite, makeZipsSqlite };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/geo-sqlite",
3
- "version": "5.7.4",
3
+ "version": "5.9.0",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "hebcal"
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "bin": {
16
16
  "build-geonames-sqlite": "bin/build-geonames-sqlite",
17
- "download-and-make-dbs": "bin/download-and-make-dbs"
17
+ "download-and-make-dbs": "bin/download-and-make-dbs",
18
+ "make-zips-sqlite": "bin/make-zips-sqlite"
18
19
  },
19
20
  "repository": {
20
21
  "type": "git",
@@ -60,16 +61,16 @@
60
61
  },
61
62
  "license": "BSD-2-Clause",
62
63
  "devDependencies": {
63
- "@eslint/js": "^9.39.2",
64
+ "@eslint/js": "^10.0.1",
64
65
  "@rollup/plugin-json": "^6.1.0",
65
66
  "@rollup/plugin-node-resolve": "^16.0.3",
66
67
  "ava": "^6.4.1",
67
- "eslint": "^9.39.2",
68
+ "eslint": "^10.0.2",
68
69
  "eslint-config-google": "^0.14.0",
69
- "eslint-plugin-n": "^17.23.2",
70
+ "eslint-plugin-n": "^17.24.0",
70
71
  "globals": "^17.3.0",
71
72
  "jsdoc": "^4.0.5",
72
73
  "jsdoc-to-markdown": "^9.1.3",
73
- "rollup": "^4.57.1"
74
+ "rollup": "^4.59.0"
74
75
  }
75
76
  }