@mailwoman/un-locode-lookup 10.0.0 → 10.2.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.
@@ -4,7 +4,7 @@
4
4
  * @license AGPL-3.0
5
5
  * @author Teffen Ellis, et al.
6
6
  *
7
- * `mailwoman-un-locode` — build the lookup DB, or look up a UN/LOCODE by name or coordinate.
7
+ * `mailwoman-un-locode` — build the lookup DB, or look up a UN/locode by name or coordinate.
8
8
  *
9
9
  * ```sh
10
10
  * mailwoman-un-locode build --csv code-list.csv --out un-locode.db
package/lib/build.ts CHANGED
@@ -3,9 +3,9 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Build the UN/LOCODE lookup DB from the UNECE code list CSV (datasets/un-locode `code-list.csv`:
6
+ * Build the UN/locode lookup DB from the unece code list CSV (datasets/un-locode `code-list.csv`:
7
7
  * columns Change, Country, Location, Name, NameWoDiacritics, Subdivision, Status, Function, Date,
8
- * IATA, Coordinates, Remarks). One row per assigned location; coordinates parsed where present.
8
+ * iata, Coordinates, Remarks). One row per assigned location. coordinates parsed where present.
9
9
  */
10
10
 
11
11
  import { DatabaseClient } from "@mailwoman/sqlite/client"
@@ -26,8 +26,8 @@ interface CSVRow {
26
26
  * Read the code-list CSV at `csvPath` and write the lookup DB to `dbPath`.
27
27
  */
28
28
  export async function buildUNLocodeDB(csvPath: string, dbPath: string): Promise<{ rows: number; withCoords: number }> {
29
- // `normalizeKeys: false` keeps the UNECE header casing the row shape above is written against
30
- // (`NameWoDiacritics`, not `name_wo_diacritics`).
29
+ // `normalizeKeys: false` keeps the unece header casing the row shape above is
30
+ // written against (`NameWoDiacritics`, not `name_wo_diacritics`).
31
31
  const records = CSVSpliterator.fromAsync<CSVRow>(csvPath, {
32
32
  normalizeKeys: false,
33
33
  })
@@ -48,7 +48,7 @@ export async function buildUNLocodeDB(csvPath: string, dbPath: string): Promise<
48
48
  for await (const r of records) {
49
49
  rows++
50
50
 
51
- if (!r.Country || !r.Location) continue // header/country rows carry no Location
51
+ if (!r.Country || !r.Location) continue // header/country rows have no Location
52
52
  const coords = r.Coordinates ? parseUNLocodeCoords(r.Coordinates) : null
53
53
 
54
54
  if (coords) {
package/lib/index.ts CHANGED
@@ -3,15 +3,16 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/un-locode-lookup` — place → UN/LOCODE (UNECE Code for Trade and Transport Locations).
6
+ * `@mailwoman/un-locode-lookup` — place → UN/locode (unece Code for Trade and Transport Locations).
7
7
  * Two ways in: by country + place name (exact, diacritic-folded), or by nearest coordinate (for
8
- * the ~⅓ of entries that carry one). Backed by a `node:sqlite` table built from the UNECE code
8
+ * the ~⅓ of entries that have one). Backed by a `node:sqlite` table built from the unece code
9
9
  * list. An `@mailwoman/annotations` `Annotator`.
10
10
  */
11
11
 
12
12
  import type { AnnotationSet, Annotator } from "@mailwoman/annotations"
13
13
  import { haversineKm } from "@mailwoman/spatial"
14
- import { DatabaseClient } from "@mailwoman/sqlite/client"
14
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
15
+ import { SQLiteLookup, type SQLiteLookupOptions } from "@mailwoman/sqlite/lookup"
15
16
 
16
17
  import type { UNLocodeDatabase } from "#schema"
17
18
 
@@ -28,7 +29,7 @@ export function foldName(name: string): string {
28
29
  }
29
30
 
30
31
  /**
31
- * Parse a UN/LOCODE coordinate (`"4923N 01522E"`) to decimal degrees, or null if absent/malformed.
32
+ * Parse a UN/locode coordinate (`"4923N 01522E"`) to decimal degrees, or null if absent/malformed.
32
33
  */
33
34
  export function parseUNLocodeCoords(raw: string): { lat: number; lon: number } | null {
34
35
  const m = raw.trim().match(/^(\d{2})(\d{2})([NS])\s+(\d{3})(\d{2})([EW])$/)
@@ -41,35 +42,31 @@ export function parseUNLocodeCoords(raw: string): { lat: number; lon: number } |
41
42
  }
42
43
 
43
44
  /**
44
- * A UN/LOCODE lookup over a built `node:sqlite` table.
45
+ * Where a {@link UNLocodeLookup} reads from.
45
46
  */
46
- export class UNLocodeLookup implements Disposable {
47
- #db: DatabaseClient<UNLocodeDatabase>
48
- /**
49
- * Resources this instance opened. A connection handed in by a caller is NOT in here, so disposal cannot reach it —
50
- * ownership is membership rather than a flag a later branch has to check.
51
- */
52
- readonly #resources = new DisposableStack()
47
+ export type UNLocodeLookupOptions = SQLiteLookupOptions<UNLocodeDatabase>
48
+
49
+ /**
50
+ * A UN/locode lookup over a built `node:sqlite` table.
51
+ */
52
+ export class UNLocodeLookup extends SQLiteLookup<UNLocodeDatabase> {
53
53
  #byName: ReturnType<DatabaseClient["prepare"]>
54
54
  #byBox: ReturnType<DatabaseClient["prepare"]>
55
55
 
56
- constructor(opts: { databasePath: string } | { db: DatabaseClient<UNLocodeDatabase> }) {
57
- this.#db =
58
- "db" in opts
59
- ? opts.db
60
- : this.#resources.use(new DatabaseClient<UNLocodeDatabase>(opts.databasePath, { readOnly: true }))
56
+ constructor(opts: UNLocodeLookupOptions) {
57
+ super(opts)
61
58
 
62
- this.#byName = this.#db.prepare(
59
+ this.#byName = this.database.prepare(
63
60
  "SELECT country, location FROM un_locode WHERE country = ? AND nameNorm = ? LIMIT 1"
64
61
  )
65
62
 
66
- this.#byBox = this.#db.prepare(
63
+ this.#byBox = this.database.prepare(
67
64
  "SELECT location, country, lat, lon FROM un_locode WHERE lat BETWEEN ? AND ? AND lon BETWEEN ? AND ?"
68
65
  )
69
66
  }
70
67
 
71
68
  /**
72
- * The UN/LOCODE (`"US NYC"`) for a country + place name, or null.
69
+ * The UN/locode (`"US NYC"`) for a country + place name, or null.
73
70
  */
74
71
  byName(country: string, name: string): string | null {
75
72
  const row = this.#byName.get(country.toUpperCase(), foldName(name)) as
@@ -80,7 +77,7 @@ export class UNLocodeLookup implements Disposable {
80
77
  }
81
78
 
82
79
  /**
83
- * The nearest coordinate-bearing UN/LOCODE within `maxKm`, or null.
80
+ * The nearest coordinate-containing UN/locode within `maxKm`, or null.
84
81
  */
85
82
  nearest(lat: number, lon: number, maxKm = 25): string | null {
86
83
  const dLat = maxKm / 111
@@ -105,15 +102,13 @@ export class UNLocodeLookup implements Disposable {
105
102
 
106
103
  return best?.code ?? null
107
104
  }
108
-
109
- [Symbol.dispose](): void {
110
- this.#resources[Symbol.dispose]()
111
- }
112
105
  }
113
106
 
114
107
  /**
115
- * Build an `Annotator` filling `AnnotationSet.unLocode`. Prefers a country + place-name match (when the resolver
116
- * supplies them via `countryCode` / `placeName`), and falls back to the nearest coordinate.
108
+ * Build an `Annotator` filling `AnnotationSet.unLocode`.
109
+ *
110
+ * Prefers a country + place-name match (when the resolver supplies them via `countryCode` / `placeName`),
111
+ * and falls back to the nearest coordinate.
117
112
  */
118
113
  export function makeUNLocodeAnnotator(lookup: UNLocodeLookup, opts: { maxKm?: number } = {}): Annotator {
119
114
  return ({ lat, lon, countryCode, placeName }): Partial<AnnotationSet> => {
package/lib/schema.ts CHANGED
@@ -3,13 +3,13 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The `un-locode.db` read contract. Declared beside the reader and the builder that writes it, so a column added to
6
+ * The `un-locode.db` read interface. Declared beside the reader and the builder that writes it, so a column added to
7
7
  * one is a compile error against the other.
8
8
  */
9
9
 
10
10
  /**
11
- * One UN/LOCODE entry: the country and location codes that form its key, the place name in raw and folded form, and the
12
- * coordinate pair when the source carries one.
11
+ * One UN/locode entry: the country and location codes that form its key, the place name in raw
12
+ * and folded form, plus the coordinate pair when the source provides one.
13
13
  */
14
14
  export interface UNLocodeTable {
15
15
  country: string
@@ -21,7 +21,7 @@ export interface UNLocodeTable {
21
21
  }
22
22
 
23
23
  /**
24
- * The tables `un-locode.db` carries.
24
+ * The tables in `un-locode.db`.
25
25
  */
26
26
  export interface UNLocodeDatabase {
27
27
  un_locode: UNLocodeTable
package/out/build.d.ts CHANGED
@@ -3,9 +3,9 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Build the UN/LOCODE lookup DB from the UNECE code list CSV (datasets/un-locode `code-list.csv`:
6
+ * Build the UN/locode lookup DB from the unece code list CSV (datasets/un-locode `code-list.csv`:
7
7
  * columns Change, Country, Location, Name, NameWoDiacritics, Subdivision, Status, Function, Date,
8
- * IATA, Coordinates, Remarks). One row per assigned location; coordinates parsed where present.
8
+ * iata, Coordinates, Remarks). One row per assigned location. coordinates parsed where present.
9
9
  */
10
10
  /**
11
11
  * Read the code-list CSV at `csvPath` and write the lookup DB to `dbPath`.
package/out/build.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Build the UN/LOCODE lookup DB from the UNECE code list CSV (datasets/un-locode `code-list.csv`:
6
+ * Build the UN/locode lookup DB from the unece code list CSV (datasets/un-locode `code-list.csv`:
7
7
  * columns Change, Country, Location, Name, NameWoDiacritics, Subdivision, Status, Function, Date,
8
- * IATA, Coordinates, Remarks). One row per assigned location; coordinates parsed where present.
8
+ * iata, Coordinates, Remarks). One row per assigned location. coordinates parsed where present.
9
9
  */
10
10
  import { DatabaseClient } from "@mailwoman/sqlite/client";
11
11
  import { CSVSpliterator } from "spliterator";
@@ -14,8 +14,8 @@ import { foldName, parseUNLocodeCoords } from "#index";
14
14
  * Read the code-list CSV at `csvPath` and write the lookup DB to `dbPath`.
15
15
  */
16
16
  export async function buildUNLocodeDB(csvPath, dbPath) {
17
- // `normalizeKeys: false` keeps the UNECE header casing the row shape above is written against
18
- // (`NameWoDiacritics`, not `name_wo_diacritics`).
17
+ // `normalizeKeys: false` keeps the unece header casing the row shape above is
18
+ // written against (`NameWoDiacritics`, not `name_wo_diacritics`).
19
19
  const records = CSVSpliterator.fromAsync(csvPath, {
20
20
  normalizeKeys: false,
21
21
  });
@@ -29,7 +29,7 @@ export async function buildUNLocodeDB(csvPath, dbPath) {
29
29
  for await (const r of records) {
30
30
  rows++;
31
31
  if (!r.Country || !r.Location)
32
- continue; // header/country rows carry no Location
32
+ continue; // header/country rows have no Location
33
33
  const coords = r.Coordinates ? parseUNLocodeCoords(r.Coordinates) : null;
34
34
  if (coords) {
35
35
  withCoords++;
package/out/build.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../lib/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAWtD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAe,EAAE,MAAc;IACpE,8FAA8F;IAC9F,kDAAkD;IAClD,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,CAAS,OAAO,EAAE;QACzD,aAAa,EAAE,KAAK;KACpB,CAAC,CAAA;IAEF,MAAM,EAAE,GAAG,IAAI,cAAc,CAAmB,MAAM,CAAC,CAAA;IACvD,EAAE,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;IAEzC,EAAE,CAAC,IAAI,CACN,sHAAsH,CACtH,CAAA;IAED,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,0FAA0F,CAAC,CAAA;IAErH,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEhB,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QAC/B,IAAI,EAAE,CAAA;QAEN,IAAI,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ;YAAE,SAAQ,CAAC,wCAAwC;QAChF,MAAM,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,C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-locode` — build the lookup DB, or look up a UN/LOCODE by name or coordinate.
7
+ * `mailwoman-un-locode` — build the lookup DB, or look up a UN/locode by name or coordinate.
8
8
  *
9
9
  * ```sh
10
10
  * mailwoman-un-locode build --csv code-list.csv --out un-locode.db
@@ -16,4 +16,4 @@
16
16
  * coordinate form is the nearest-code lookup, formerly `--near`).
17
17
  */
18
18
  export {};
19
- //# sourceMappingURL=cli.d.ts.map
19
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG"}
@@ -4,7 +4,7 @@
4
4
  * @license AGPL-3.0
5
5
  * @author Teffen Ellis, et al.
6
6
  *
7
- * `mailwoman-un-locode` — build the lookup DB, or look up a UN/LOCODE by name or coordinate.
7
+ * `mailwoman-un-locode` — build the lookup DB, or look up a UN/locode by name or coordinate.
8
8
  *
9
9
  * ```sh
10
10
  * mailwoman-un-locode build --csv code-list.csv --out un-locode.db
@@ -49,4 +49,4 @@ else {
49
49
  const code = byName ? lookup.byName(values.country, values.name) : lookup.nearest(lat, lon);
50
50
  console.log(JSON.stringify({ unLocode: code }));
51
51
  }
52
- //# sourceMappingURL=cli.js.map
52
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAEvC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,CAAC;IAC9C,OAAO,EAAE;QACR,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvB,GAAG,EAAE,EAAE,IAA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AC,CAAC,CAAC,CAAA;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAC9D,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAQ,EAAE,MAAM,CAAC,IAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAE7F,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAChD,CAAC"}
package/out/index.d.ts CHANGED
@@ -3,48 +3,49 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/un-locode-lookup` — place → UN/LOCODE (UNECE Code for Trade and Transport Locations).
6
+ * `@mailwoman/un-locode-lookup` — place → UN/locode (unece Code for Trade and Transport Locations).
7
7
  * Two ways in: by country + place name (exact, diacritic-folded), or by nearest coordinate (for
8
- * the ~⅓ of entries that carry one). Backed by a `node:sqlite` table built from the UNECE code
8
+ * the ~⅓ of entries that have one). Backed by a `node:sqlite` table built from the unece code
9
9
  * list. An `@mailwoman/annotations` `Annotator`.
10
10
  */
11
11
  import type { Annotator } from "@mailwoman/annotations";
12
- import { DatabaseClient } from "@mailwoman/sqlite/client";
12
+ import { SQLiteLookup, type SQLiteLookupOptions } from "@mailwoman/sqlite/lookup";
13
13
  import type { UNLocodeDatabase } from "#schema";
14
14
  /**
15
15
  * Fold a place name to its match key: strip diacritics, lowercase, collapse whitespace.
16
16
  */
17
17
  export declare function foldName(name: string): string;
18
18
  /**
19
- * Parse a UN/LOCODE coordinate (`"4923N 01522E"`) to decimal degrees, or null if absent/malformed.
19
+ * Parse a UN/locode coordinate (`"4923N 01522E"`) to decimal degrees, or null if absent/malformed.
20
20
  */
21
21
  export declare function parseUNLocodeCoords(raw: string): {
22
22
  lat: number;
23
23
  lon: number;
24
24
  } | null;
25
25
  /**
26
- * A UN/LOCODE lookup over a built `node:sqlite` table.
26
+ * Where a {@link UNLocodeLookup} reads from.
27
27
  */
28
- export declare class UNLocodeLookup implements Disposable {
28
+ export type UNLocodeLookupOptions = SQLiteLookupOptions<UNLocodeDatabase>;
29
+ /**
30
+ * A UN/locode lookup over a built `node:sqlite` table.
31
+ */
32
+ export declare class UNLocodeLookup extends SQLiteLookup<UNLocodeDatabase> {
29
33
  #private;
30
- constructor(opts: {
31
- databasePath: string;
32
- } | {
33
- db: DatabaseClient<UNLocodeDatabase>;
34
- });
34
+ constructor(opts: UNLocodeLookupOptions);
35
35
  /**
36
- * The UN/LOCODE (`"US NYC"`) for a country + place name, or null.
36
+ * The UN/locode (`"US NYC"`) for a country + place name, or null.
37
37
  */
38
38
  byName(country: string, name: string): string | null;
39
39
  /**
40
- * The nearest coordinate-bearing UN/LOCODE within `maxKm`, or null.
40
+ * The nearest coordinate-containing UN/locode within `maxKm`, or null.
41
41
  */
42
42
  nearest(lat: number, lon: number, maxKm?: number): string | null;
43
- [Symbol.dispose](): void;
44
43
  }
45
44
  /**
46
- * Build an `Annotator` filling `AnnotationSet.unLocode`. Prefers a country + place-name match (when the resolver
47
- * supplies them via `countryCode` / `placeName`), and falls back to the nearest coordinate.
45
+ * Build an `Annotator` filling `AnnotationSet.unLocode`.
46
+ *
47
+ * Prefers a country + place-name match (when the resolver supplies them via `countryCode` / `placeName`),
48
+ * and falls back to the nearest coordinate.
48
49
  */
49
50
  export declare function makeUNLocodeAnnotator(lookup: UNLocodeLookup, opts?: {
50
51
  maxKm?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEtE,OAAO,EAAE,cAA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EAAE,MAAM,GAAG,MAAM,CAO7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQpF;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,CAAA;AAEzE;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY,CAAC,gBAAgB,CAAC;;IAIjE,YAAY,IAAI,EAAE,qBAAqB,EAUtC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMnD;IAED;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,GAAG,IAAI,CAsB3D;CACD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,CAOtG"}
package/out/index.js CHANGED
@@ -3,13 +3,13 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/un-locode-lookup` — place → UN/LOCODE (UNECE Code for Trade and Transport Locations).
6
+ * `@mailwoman/un-locode-lookup` — place → UN/locode (unece Code for Trade and Transport Locations).
7
7
  * Two ways in: by country + place name (exact, diacritic-folded), or by nearest coordinate (for
8
- * the ~⅓ of entries that carry one). Backed by a `node:sqlite` table built from the UNECE code
8
+ * the ~⅓ of entries that have one). Backed by a `node:sqlite` table built from the unece code
9
9
  * list. An `@mailwoman/annotations` `Annotator`.
10
10
  */
11
11
  import { haversineKm } from "@mailwoman/spatial";
12
- import { DatabaseClient } from "@mailwoman/sqlite/client";
12
+ import { SQLiteLookup } from "@mailwoman/sqlite/lookup";
13
13
  /**
14
14
  * Fold a place name to its match key: strip diacritics, lowercase, collapse whitespace.
15
15
  */
@@ -22,7 +22,7 @@ export function foldName(name) {
22
22
  .replaceAll(/\s+/g, " ");
23
23
  }
24
24
  /**
25
- * Parse a UN/LOCODE coordinate (`"4923N 01522E"`) to decimal degrees, or null if absent/malformed.
25
+ * Parse a UN/locode coordinate (`"4923N 01522E"`) to decimal degrees, or null if absent/malformed.
26
26
  */
27
27
  export function parseUNLocodeCoords(raw) {
28
28
  const m = raw.trim().match(/^(\d{2})(\d{2})([NS])\s+(\d{3})(\d{2})([EW])$/);
@@ -33,34 +33,25 @@ export function parseUNLocodeCoords(raw) {
33
33
  return { lat, lon };
34
34
  }
35
35
  /**
36
- * A UN/LOCODE lookup over a built `node:sqlite` table.
36
+ * A UN/locode lookup over a built `node:sqlite` table.
37
37
  */
38
- export class UNLocodeLookup {
39
- #db;
40
- /**
41
- * Resources this instance opened. A connection handed in by a caller is NOT in here, so disposal cannot reach it —
42
- * ownership is membership rather than a flag a later branch has to check.
43
- */
44
- #resources = new DisposableStack();
38
+ export class UNLocodeLookup extends SQLiteLookup {
45
39
  #byName;
46
40
  #byBox;
47
41
  constructor(opts) {
48
- this.#db =
49
- "db" in opts
50
- ? opts.db
51
- : this.#resources.use(new DatabaseClient(opts.databasePath, { readOnly: true }));
52
- this.#byName = this.#db.prepare("SELECT country, location FROM un_locode WHERE country = ? AND nameNorm = ? LIMIT 1");
53
- this.#byBox = this.#db.prepare("SELECT location, country, lat, lon FROM un_locode WHERE lat BETWEEN ? AND ? AND lon BETWEEN ? AND ?");
42
+ super(opts);
43
+ this.#byName = this.database.prepare("SELECT country, location FROM un_locode WHERE country = ? AND nameNorm = ? LIMIT 1");
44
+ this.#byBox = this.database.prepare("SELECT location, country, lat, lon FROM un_locode WHERE lat BETWEEN ? AND ? AND lon BETWEEN ? AND ?");
54
45
  }
55
46
  /**
56
- * The UN/LOCODE (`"US NYC"`) for a country + place name, or null.
47
+ * The UN/locode (`"US NYC"`) for a country + place name, or null.
57
48
  */
58
49
  byName(country, name) {
59
50
  const row = this.#byName.get(country.toUpperCase(), foldName(name));
60
51
  return row ? `${row.country} ${row.location}` : null;
61
52
  }
62
53
  /**
63
- * The nearest coordinate-bearing UN/LOCODE within `maxKm`, or null.
54
+ * The nearest coordinate-containing UN/locode within `maxKm`, or null.
64
55
  */
65
56
  nearest(lat, lon, maxKm = 25) {
66
57
  const dLat = maxKm / 111;
@@ -75,13 +66,12 @@ export class UNLocodeLookup {
75
66
  }
76
67
  return best?.code ?? null;
77
68
  }
78
- [Symbol.dispose]() {
79
- this.#resources[Symbol.dispose]();
80
- }
81
69
  }
82
70
  /**
83
- * Build an `Annotator` filling `AnnotationSet.unLocode`. Prefers a country + place-name match (when the resolver
84
- * supplies them via `countryCode` / `placeName`), and falls back to the nearest coordinate.
71
+ * Build an `Annotator` filling `AnnotationSet.unLocode`.
72
+ *
73
+ * Prefers a country + place-name match (when the resolver supplies them via `countryCode` / `placeName`),
74
+ * and falls back to the nearest coordinate.
85
75
  */
86
76
  export function makeUNLocodeAnnotator(lookup, opts = {}) {
87
77
  return ({ lat, lon, countryCode, placeName }) => {
package/out/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAIzD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACpC,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC;SAChB,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;SACxB,WAAW,EAAE;SACb,IAAI,EAAE;SACN,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC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AO,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,EAA0B,EAAE;QACvE,MAAM,MAAM,GAAG,WAAW,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QACtF,MAAM,IAAI,GAAG,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QAE3D,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtC,CAAC,CAAA;AACF,CAAC"}
package/out/schema.d.ts CHANGED
@@ -3,12 +3,12 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The `un-locode.db` read contract. Declared beside the reader and the builder that writes it, so a column added to
6
+ * The `un-locode.db` read interface. Declared beside the reader and the builder that writes it, so a column added to
7
7
  * one is a compile error against the other.
8
8
  */
9
9
  /**
10
- * One UN/LOCODE entry: the country and location codes that form its key, the place name in raw and folded form, and the
11
- * coordinate pair when the source carries one.
10
+ * One UN/locode entry: the country and location codes that form its key, the place name in raw
11
+ * and folded form, plus the coordinate pair when the source provides one.
12
12
  */
13
13
  export interface UNLocodeTable {
14
14
  country: string;
@@ -19,7 +19,7 @@ export interface UNLocodeTable {
19
19
  lon: number | null;
20
20
  }
21
21
  /**
22
- * The tables `un-locode.db` carries.
22
+ * The tables in `un-locode.db`.
23
23
  */
24
24
  export interface UNLocodeDatabase {
25
25
  un_locode: UNLocodeTable;
package/out/schema.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The `un-locode.db` read contract. Declared beside the reader and the builder that writes it, so a column added to
6
+ * The `un-locode.db` read interface. Declared beside the reader and the builder that writes it, so a column added to
7
7
  * one is a compile error against the other.
8
8
  */
9
9
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailwoman/un-locode-lookup",
3
- "version": "10.0.0",
3
+ "version": "10.2.0",
4
4
  "description": "Place → UN/LOCODE (UNECE Code for Trade and Transport Locations), by country + name or nearest coordinate. node:sqlite over the UNECE code list. An @mailwoman/annotations Annotator.",
5
5
  "license": "AGPL-3.0-only OR LicenseRef-Commercial",
6
6
  "repository": {
@@ -8,26 +8,27 @@
8
8
  "url": "https://github.com/sister-software/mailwoman.git",
9
9
  "directory": "packages/un-locode-lookup"
10
10
  },
11
- "bin": "./out/cli.js",
11
+ "bin": "./out/cli/main.js",
12
12
  "files": [
13
13
  "out/**/*.js",
14
14
  "out/**/*.js.map",
15
15
  "out/**/*.d.ts",
16
16
  "out/**/*.d.ts.map",
17
17
  "README.md",
18
- "*.ts",
19
- "*.tsx",
20
- "**/*.ts",
21
- "**/*.tsx",
22
- "!*.test.ts",
23
- "!*.test.tsx",
18
+ "lib/**/*.ts",
19
+ "lib/**/*.tsx",
20
+ "cli/**/*.ts",
24
21
  "!**/*.test.ts",
25
- "!**/*.test.tsx",
26
- "!test/**"
22
+ "!**/*.test.tsx"
27
23
  ],
28
24
  "type": "module",
29
25
  "sideEffects": false,
30
26
  "imports": {
27
+ "#cli/*": {
28
+ "types": "./out/cli/*.d.ts",
29
+ "node": "./out/cli/*.js",
30
+ "default": "./out/cli/*.js"
31
+ },
31
32
  "#*": {
32
33
  "types": "./out/*.d.ts",
33
34
  "node": "./out/*.js",
@@ -41,15 +42,15 @@
41
42
  "node": "./out/index.js",
42
43
  "default": "./out/index.js"
43
44
  },
44
- "./build": {
45
- "types": "./out/build.d.ts",
46
- "node": "./out/build.js",
47
- "default": "./out/build.js"
45
+ "./cli/*": {
46
+ "types": "./out/cli/*.d.ts",
47
+ "node": "./out/cli/*.js",
48
+ "default": "./out/cli/*.js"
48
49
  },
49
- "./schema": {
50
- "types": "./out/schema.d.ts",
51
- "node": "./out/schema.js",
52
- "default": "./out/schema.js"
50
+ "./*": {
51
+ "types": "./out/*.d.ts",
52
+ "node": "./out/*.js",
53
+ "default": "./out/*.js"
53
54
  }
54
55
  },
55
56
  "publishConfig": {
@@ -61,18 +62,23 @@
61
62
  "node": "./out/index.js",
62
63
  "default": "./out/index.js"
63
64
  },
64
- "./build": {
65
- "types": "./out/build.d.ts",
66
- "node": "./out/build.js",
67
- "default": "./out/build.js"
65
+ "./cli/*": {
66
+ "types": "./out/cli/*.d.ts",
67
+ "node": "./out/cli/*.js",
68
+ "default": "./out/cli/*.js"
68
69
  },
69
- "./schema": {
70
- "types": "./out/schema.d.ts",
71
- "node": "./out/schema.js",
72
- "default": "./out/schema.js"
70
+ "./*": {
71
+ "types": "./out/*.d.ts",
72
+ "node": "./out/*.js",
73
+ "default": "./out/*.js"
73
74
  }
74
75
  },
75
76
  "imports": {
77
+ "#cli/*": {
78
+ "types": "./out/cli/*.d.ts",
79
+ "node": "./out/cli/*.js",
80
+ "default": "./out/cli/*.js"
81
+ },
76
82
  "#*": {
77
83
  "types": "./out/*.d.ts",
78
84
  "node": "./out/*.js",
@@ -81,9 +87,9 @@
81
87
  }
82
88
  },
83
89
  "dependencies": {
84
- "@mailwoman/annotations": "10.0.0",
85
- "@mailwoman/spatial": "10.0.0",
86
- "@mailwoman/sqlite": "10.0.0",
87
- "spliterator": "^7.5.1"
90
+ "@mailwoman/annotations": "10.2.0",
91
+ "@mailwoman/spatial": "10.2.0",
92
+ "@mailwoman/sqlite": "10.2.0",
93
+ "spliterator": "^9.2.0"
88
94
  }
89
95
  }
package/out/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../lib/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG"}
package/out/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../lib/cli.ts"],"names":[],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