@mailwoman/timezone-lookup 10.0.0 → 10.1.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-timezone` — build the polygon DB, or look up a coordinate's IANA timezone.
7
+ * `mailwoman-timezone` — build the polygon DB, or look up a coordinate's iana timezone.
8
8
  *
9
9
  * ```sh
10
10
  * mailwoman-timezone build --geojson combined-with-oceans.json --out timezone.db
@@ -14,6 +14,7 @@
14
14
  * The `--` separates flags from coordinates so negative longitudes parse as positionals.
15
15
  */
16
16
 
17
+ import { stringifyJSON } from "@mailwoman/core/json"
17
18
  import { parseArguments } from "@mailwoman/core/scripting/arguments"
18
19
 
19
20
  import { buildTimezoneDB } from "#build"
@@ -49,8 +50,8 @@ if (positionals[0] === "build") {
49
50
  }
50
51
 
51
52
  using lookup = new TimezoneLookup({ databasePath: values.db })
52
- // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe, not Array#find
53
+ // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe rather than Array#find
53
54
  const tzid = lookup.explore(lat, lon)
54
55
 
55
- console.log(JSON.stringify({ timezone: tzid, offsetSec: tzid ? offsetSecForTimezone(tzid) : null }))
56
+ console.log(stringifyJSON({ timezone: tzid, offsetSec: tzid ? offsetSecForTimezone(tzid) : null }))
56
57
  }
package/lib/build.ts CHANGED
@@ -10,10 +10,11 @@
10
10
  */
11
11
 
12
12
  import { readLocalJSONFile } from "@mailwoman/core/fs/readers"
13
+ import { stringifyJSON } from "@mailwoman/core/json"
13
14
  import type { GeoFeature, InferGeoFeatureCollection, MultiPolygonLiteral, PolygonLiteral } from "@mailwoman/spatial"
15
+ import type { MultiPolygonRings } from "@mailwoman/spatial/geometries/polygon"
14
16
  import { DatabaseClient } from "@mailwoman/sqlite/client"
15
17
 
16
- import type { MultiPolygonCoords } from "#index"
17
18
  import type { TimezoneDatabase } from "#schema"
18
19
 
19
20
  export type TimezoneFeature = GeoFeature<PolygonLiteral | MultiPolygonLiteral, { tzid: string }>
@@ -41,10 +42,8 @@ export async function buildTimezoneDB(geojsonPath: string, dbPath: string): Prom
41
42
  db.exec("BEGIN")
42
43
 
43
44
  for (const feature of data.features) {
44
- const polygons: MultiPolygonCoords =
45
- feature.geometry.type === "Polygon"
46
- ? [feature.geometry.coordinates as number[][][]]
47
- : (feature.geometry.coordinates as number[][][][])
45
+ const polygons: MultiPolygonRings =
46
+ feature.geometry.type === "Polygon" ? [feature.geometry.coordinates] : feature.geometry.coordinates
48
47
 
49
48
  let minLat = 90
50
49
  let maxLat = -90
@@ -76,7 +75,7 @@ export async function buildTimezoneDB(geojsonPath: string, dbPath: string): Prom
76
75
  }
77
76
  }
78
77
 
79
- insert.run(feature.properties.tzid, minLat, maxLat, minLon, maxLon, JSON.stringify(polygons))
78
+ insert.run(feature.properties.tzid, minLat, maxLat, minLon, maxLon, stringifyJSON(polygons))
80
79
  }
81
80
 
82
81
  db.exec("COMMIT")
package/lib/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/timezone-lookup` — coordinate → IANA timezone, server-side. Point-in-polygon over the
6
+ * `@mailwoman/timezone-lookup` — coordinate → iana timezone, server-side. Point-in-polygon over the
7
7
  * timezone-boundary-builder polygons stored in a `node:sqlite` DB (bbox-prefilter + ray-cast),
8
8
  * mirroring the resolver's PIP pattern. The UTC offset comes from `Intl.DateTimeFormat` — no tz
9
9
  * database dependency. Build the DB with `mailwoman-timezone build` (see `./build.ts`).
@@ -11,68 +11,16 @@
11
11
 
12
12
  import type { AnnotationSet, Annotator } from "@mailwoman/annotations"
13
13
  import { parseJSONStrict } from "@mailwoman/core/json"
14
- import { DatabaseClient } from "@mailwoman/sqlite/client"
14
+ import { pointInMultiPolygon, type MultiPolygonRings } from "@mailwoman/spatial/geometries/polygon"
15
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
16
+ import { SQLiteLookup, type SQLiteLookupOptions } from "@mailwoman/sqlite/lookup"
15
17
 
16
18
  import type { TimezoneDatabase } from "#schema"
17
19
 
18
20
  /**
19
- * Normalized geometry: an array of polygons, each `[outerRing, ...holes]`, each ring `[[lon,lat],…]`.
20
- */
21
- export type MultiPolygonCoords = number[][][][]
22
-
23
- /**
24
- * Ray-cast point-in-ring (even-odd rule). `ring` is `[[lon, lat], …]`.
25
- *
26
- * DELIBERATE DUPLICATE of `@mailwoman/spatial`'s `pointInRing`, kept local on purpose. This package has exactly one
27
- * dependency — zero-dep `@mailwoman/annotations` — and importing spatial to reach a fifteen-line ray cast would pull
28
- * `@mailwoman/core` with it, whose published tarball carries ~11 MB of libpostal/WOF/chromium-i18n data. Eleven
29
- * megabytes for fifteen lines is the wrong trade for a leaf lookup package. If this package ever gains a real spatial
30
- * dependency, delete these and import them.
31
- *
32
- * Repo-health-ignore private-name-shadows-export -- kept local so a leaf lookup package stays off @mailwoman/core's ~11
33
- * MB of shipped data; see the docstring
34
- */
35
- function pointInRing(lon: number, lat: number, ring: number[][]): boolean {
36
- let inside = false
37
-
38
- for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
39
- const xi = ring[i]![0]!
40
- const yi = ring[i]![1]!
41
- const xj = ring[j]![0]!
42
- const yj = ring[j]![1]!
43
-
44
- if (yi > lat !== yj > lat && lon < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) {
45
- inside = !inside
46
- }
47
- }
48
-
49
- return inside
50
- }
51
-
52
- /**
53
- * Inside the outer ring and outside every hole.
21
+ * The current UTC offset (seconds) for an iana timezone, via `Intl` (no tz-db dependency).
54
22
  *
55
- * Repo-health-ignore private-name-shadows-export -- kept local so a leaf lookup package stays off @mailwoman/core's ~11
56
- * MB of shipped data; see the docstring
57
- */
58
- function pointInPolygon(lon: number, lat: number, polygon: number[][][]): boolean {
59
- if (!polygon[0] || !pointInRing(lon, lat, polygon[0])) return false
60
-
61
- for (let i = 1; i < polygon.length; i++) if (pointInRing(lon, lat, polygon[i]!)) return false
62
-
63
- return true
64
- }
65
-
66
- /**
67
- * Inside any polygon of a (multi)polygon feature.
68
- */
69
- export function pointInMultiPolygon(lon: number, lat: number, polygons: MultiPolygonCoords): boolean {
70
- return polygons.some((polygon) => pointInPolygon(lon, lat, polygon))
71
- }
72
-
73
- /**
74
- * The current UTC offset (seconds) for an IANA timezone, via `Intl` (no tz-db dependency). Returns `undefined` if the
75
- * runtime can't resolve the zone.
23
+ * @returns `undefined` if the runtime can't resolve the zone.
76
24
  */
77
25
  export function offsetSecForTimezone(tzid: string, date: Date = new Date()): number | undefined {
78
26
  try {
@@ -94,48 +42,36 @@ export function offsetSecForTimezone(tzid: string, date: Date = new Date()): num
94
42
  /**
95
43
  * A timezone lookup over a built `node:sqlite` polygon DB.
96
44
  */
97
- export class TimezoneLookup implements Disposable {
98
- #db: DatabaseClient<TimezoneDatabase>
99
- /**
100
- * Resources this instance opened. A connection handed in by a caller is NOT in here, so disposal cannot reach it —
101
- * ownership is membership rather than a flag a later branch has to check.
102
- */
103
- readonly #resources = new DisposableStack()
45
+ export class TimezoneLookup extends SQLiteLookup<TimezoneDatabase> {
104
46
  #stmt: ReturnType<DatabaseClient["prepare"]>
105
47
 
106
- constructor(opts: { databasePath: string } | { database: DatabaseClient<TimezoneDatabase> }) {
107
- this.#db =
108
- "database" in opts
109
- ? opts.database
110
- : this.#resources.use(new DatabaseClient<TimezoneDatabase>(opts.databasePath, { readOnly: true }))
48
+ constructor(opts: SQLiteLookupOptions<TimezoneDatabase>) {
49
+ super(opts)
111
50
 
112
- // Candidate features whose bbox contains the point; PIP picks the exact one.
113
- this.#stmt = this.#db.prepare(
51
+ // Candidate features whose bbox contains the point.
52
+ // PIP picks the exact one.
53
+ this.#stmt = this.database.prepare(
114
54
  `SELECT tzid, geom FROM timezone_polygons
115
55
  WHERE minLat <= ? AND maxLat >= ? AND minLon <= ? AND maxLon >= ?`
116
56
  )
117
57
  }
118
58
 
119
59
  /**
120
- * The IANA timezone id containing `(lat, lon)`, or `null` if none (shouldn't happen with oceans).
60
+ * The iana timezone id containing `(lat, lon)`, or `null` if none (shouldn't happen with oceans).
121
61
  */
122
62
  explore(lat: number, lon: number): string | null {
123
63
  const rows = this.#stmt.all(lat, lat, lon, lon) as Array<{ tzid: string; geom: string }>
124
64
 
125
65
  for (const row of rows) {
126
- const multiPolygonCoords = parseJSONStrict<MultiPolygonCoords>(row.geom)
66
+ const polygons = parseJSONStrict<MultiPolygonRings>(row.geom)
127
67
 
128
- if (pointInMultiPolygon(lon, lat, multiPolygonCoords)) {
68
+ if (pointInMultiPolygon(lon, lat, polygons)) {
129
69
  return row.tzid
130
70
  }
131
71
  }
132
72
 
133
73
  return null
134
74
  }
135
-
136
- [Symbol.dispose](): void {
137
- this.#resources[Symbol.dispose]()
138
- }
139
75
  }
140
76
 
141
77
  /**
@@ -143,7 +79,7 @@ export class TimezoneLookup implements Disposable {
143
79
  */
144
80
  export function makeTimezoneAnnotator(lookup: TimezoneLookup): Annotator {
145
81
  return ({ lat, lon, date }): Partial<AnnotationSet> => {
146
- // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe, not Array#find
82
+ // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe rather than Array#find
147
83
  const name = lookup.explore(lat, lon)
148
84
 
149
85
  if (!name) return {}
package/lib/paths.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Where the timezone database lives under the data root's `db/` group.
7
+ */
8
+
9
+ import { databaseRootPath, dataRootPath } from "@mailwoman/core/data-root"
10
+ import type { PathBuilder } from "path-ts"
11
+
12
+ /**
13
+ * `$MAILWOMAN_DATA_ROOT/db/timezone`, read when a path is requested.
14
+ */
15
+ export const timezoneDatabasePath: PathBuilder = databaseRootPath(dataRootPath())("timezone")
package/lib/schema.ts CHANGED
@@ -3,12 +3,12 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The `timezone.db` read contract. Declared beside the reader and the builder that writes it, so a column added to
6
+ * The `timezone.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 timezone polygon: its IANA identifier, bounding box, and encoded geometry.
11
+ * One timezone polygon: its IANA identifier, bounding box and encoded geometry.
12
12
  */
13
13
  export interface TimezonePolygonTable {
14
14
  tzid: string
@@ -20,7 +20,7 @@ export interface TimezonePolygonTable {
20
20
  }
21
21
 
22
22
  /**
23
- * The tables `timezone.db` carries.
23
+ * The tables included in `timezone.db`.
24
24
  */
25
25
  export interface TimezoneDatabase {
26
26
  timezone_polygons: TimezonePolygonTable
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../lib/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,UAAU,EAA6B,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAMpH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,cAAc,GAAG,mBAAmB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEhG;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA4DxG"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../lib/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,UAAU,EAA6B,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAMpH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,cAAc,GAAG,mBAAmB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEhG;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA0DxG"}
package/out/build.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * prefilter), and the geometry normalized to MultiPolygon coordinates as JSON.
10
10
  */
11
11
  import { readLocalJSONFile } from "@mailwoman/core/fs/readers";
12
+ import { stringifyJSON } from "@mailwoman/core/json";
12
13
  import { DatabaseClient } from "@mailwoman/sqlite/client";
13
14
  /**
14
15
  * Read the GeoJSON at `geojsonPath` and write the polygon DB to `dbPath` (overwriting its table).
@@ -23,9 +24,7 @@ export async function buildTimezoneDB(geojsonPath, dbPath) {
23
24
  const insert = db.prepare("INSERT INTO timezone_polygons (tzid, minLat, maxLat, minLon, maxLon, geom) VALUES (?,?,?,?,?,?)");
24
25
  db.exec("BEGIN");
25
26
  for (const feature of data.features) {
26
- const polygons = feature.geometry.type === "Polygon"
27
- ? [feature.geometry.coordinates]
28
- : feature.geometry.coordinates;
27
+ const polygons = feature.geometry.type === "Polygon" ? [feature.geometry.coordinates] : feature.geometry.coordinates;
29
28
  let minLat = 90;
30
29
  let maxLat = -90;
31
30
  let minLon = 180;
@@ -50,7 +49,7 @@ export async function buildTimezoneDB(geojsonPath, dbPath) {
50
49
  }
51
50
  }
52
51
  }
53
- insert.run(feature.properties.tzid, minLat, maxLat, minLon, maxLon, JSON.stringify(polygons));
52
+ insert.run(feature.properties.tzid, minLat, maxLat, minLon, maxLon, stringifyJSON(polygons));
54
53
  }
55
54
  db.exec("COMMIT");
56
55
  db.exec("CREATE INDEX idx_tz_bbox ON timezone_polyg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AC;wBAClB,MAAM,GAAG,GAAG,CAAA;oBACb,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC7F,CAAC;IAED,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjB,EAAE,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAA;IAEzF,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;AAC1C,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * @license AGPL-3.0
5
5
  * @author Teffen Ellis, et al.
6
6
  *
7
- * `mailwoman-timezone` — build the polygon DB, or look up a coordinate's IANA timezone.
7
+ * `mailwoman-timezone` — build the polygon DB, or look up a coordinate's iana timezone.
8
8
  *
9
9
  * ```sh
10
10
  * mailwoman-timezone build --geojson combined-with-oceans.json --out timezone.db
@@ -14,4 +14,4 @@
14
14
  * The `--` separates flags from coordinates so negative longitudes parse as positionals.
15
15
  */
16
16
  export {};
17
- //# sourceMappingURL=cli.d.ts.map
17
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG"}
@@ -4,7 +4,7 @@
4
4
  * @license AGPL-3.0
5
5
  * @author Teffen Ellis, et al.
6
6
  *
7
- * `mailwoman-timezone` — build the polygon DB, or look up a coordinate's IANA timezone.
7
+ * `mailwoman-timezone` — build the polygon DB, or look up a coordinate's iana timezone.
8
8
  *
9
9
  * ```sh
10
10
  * mailwoman-timezone build --geojson combined-with-oceans.json --out timezone.db
@@ -13,6 +13,7 @@
13
13
  *
14
14
  * The `--` separates flags from coordinates so negative longitudes parse as positionals.
15
15
  */
16
+ import { stringifyJSON } from "@mailwoman/core/json";
16
17
  import { parseArguments } from "@mailwoman/core/scripting/arguments";
17
18
  import { buildTimezoneDB } from "#build";
18
19
  import { offsetSecForTimezone, TimezoneLookup } from "#index";
@@ -40,8 +41,8 @@ else {
40
41
  process.exit(1);
41
42
  }
42
43
  using lookup = new TimezoneLookup({ databasePath: values.db });
43
- // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe, not Array#find
44
+ // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe rather than Array#find
44
45
  const tzid = lookup.explore(lat, lon);
45
- console.log(JSON.stringify({ timezone: tzid, offsetSec: tzid ? offsetSecForTimezone(tzid) : null }));
46
+ console.log(stringifyJSON({ timezone: tzid, offsetSec: tzid ? offsetSecForTimezone(tzid) : null }));
46
47
  }
47
- //# sourceMappingURL=cli.js.map
48
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAE7D,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,CAAC;IAC9C,OAAO,EAAE;QACR,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvB,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KACtB;IACD,gBAAgB,EAAE,IAAI;CACtB,CAAC,CAAA;AAEF,IAAI,WAAW,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pG,CAAC"}
package/out/index.d.ts CHANGED
@@ -3,42 +3,30 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/timezone-lookup` — coordinate → IANA timezone, server-side. Point-in-polygon over the
6
+ * `@mailwoman/timezone-lookup` — coordinate → iana timezone, server-side. Point-in-polygon over the
7
7
  * timezone-boundary-builder polygons stored in a `node:sqlite` DB (bbox-prefilter + ray-cast),
8
8
  * mirroring the resolver's PIP pattern. The UTC offset comes from `Intl.DateTimeFormat` — no tz
9
9
  * database dependency. Build the DB with `mailwoman-timezone build` (see `./build.ts`).
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 { TimezoneDatabase } from "#schema";
14
14
  /**
15
- * Normalized geometry: an array of polygons, each `[outerRing, ...holes]`, each ring `[[lon,lat],…]`.
16
- */
17
- export type MultiPolygonCoords = number[][][][];
18
- /**
19
- * Inside any polygon of a (multi)polygon feature.
20
- */
21
- export declare function pointInMultiPolygon(lon: number, lat: number, polygons: MultiPolygonCoords): boolean;
22
- /**
23
- * The current UTC offset (seconds) for an IANA timezone, via `Intl` (no tz-db dependency). Returns `undefined` if the
24
- * runtime can't resolve the zone.
15
+ * The current UTC offset (seconds) for an iana timezone, via `Intl` (no tz-db dependency).
16
+ *
17
+ * @returns `undefined` if the runtime can't resolve the zone.
25
18
  */
26
19
  export declare function offsetSecForTimezone(tzid: string, date?: Date): number | undefined;
27
20
  /**
28
21
  * A timezone lookup over a built `node:sqlite` polygon DB.
29
22
  */
30
- export declare class TimezoneLookup implements Disposable {
23
+ export declare class TimezoneLookup extends SQLiteLookup<TimezoneDatabase> {
31
24
  #private;
32
- constructor(opts: {
33
- databasePath: string;
34
- } | {
35
- database: DatabaseClient<TimezoneDatabase>;
36
- });
25
+ constructor(opts: SQLiteLookupOptions<TimezoneDatabase>);
37
26
  /**
38
- * The IANA timezone id containing `(lat, lon)`, or `null` if none (shouldn't happen with oceans).
27
+ * The iana timezone id containing `(lat, lon)`, or `null` if none (shouldn't happen with oceans).
39
28
  */
40
29
  explore(lat: number, lon: number): string | null;
41
- [Symbol.dispose](): void;
42
30
  }
43
31
  /**
44
32
  * Build an `Annotator` that fills `AnnotationSet.timezone` (name + current offset) from a lookup.
@@ -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,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,CAAA;AA6C/C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAEnG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,IAAiB,GAAG,MAAM,GAAG,SAAS,CAe9F;AAED;;GAEG;AACH,qBAAa,cAAe,YAAW,UAAU;;IAShD,YAAY,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,QAAQ,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAA;KAAE,EAW1F;IAED;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY/C;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAEvB;CACD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAUvE"}
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;AAItE,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAEjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,IAAiB,GAAG,MAAM,GAAG,SAAS,CAe9F;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY,CAAC,gBAAgB,CAAC;;IAGjE,YAAY,IAAI,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,EAStD;IAED;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY/C;CACD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAUvE"}
package/out/index.js CHANGED
@@ -3,61 +3,18 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/timezone-lookup` — coordinate → IANA timezone, server-side. Point-in-polygon over the
6
+ * `@mailwoman/timezone-lookup` — coordinate → iana timezone, server-side. Point-in-polygon over the
7
7
  * timezone-boundary-builder polygons stored in a `node:sqlite` DB (bbox-prefilter + ray-cast),
8
8
  * mirroring the resolver's PIP pattern. The UTC offset comes from `Intl.DateTimeFormat` — no tz
9
9
  * database dependency. Build the DB with `mailwoman-timezone build` (see `./build.ts`).
10
10
  */
11
11
  import { parseJSONStrict } from "@mailwoman/core/json";
12
- import { DatabaseClient } from "@mailwoman/sqlite/client";
12
+ import { pointInMultiPolygon } from "@mailwoman/spatial/geometries/polygon";
13
+ import { SQLiteLookup } from "@mailwoman/sqlite/lookup";
13
14
  /**
14
- * Ray-cast point-in-ring (even-odd rule). `ring` is `[[lon, lat], …]`.
15
+ * The current UTC offset (seconds) for an iana timezone, via `Intl` (no tz-db dependency).
15
16
  *
16
- * DELIBERATE DUPLICATE of `@mailwoman/spatial`'s `pointInRing`, kept local on purpose. This package has exactly one
17
- * dependency — zero-dep `@mailwoman/annotations` — and importing spatial to reach a fifteen-line ray cast would pull
18
- * `@mailwoman/core` with it, whose published tarball carries ~11 MB of libpostal/WOF/chromium-i18n data. Eleven
19
- * megabytes for fifteen lines is the wrong trade for a leaf lookup package. If this package ever gains a real spatial
20
- * dependency, delete these and import them.
21
- *
22
- * Repo-health-ignore private-name-shadows-export -- kept local so a leaf lookup package stays off @mailwoman/core's ~11
23
- * MB of shipped data; see the docstring
24
- */
25
- function pointInRing(lon, lat, ring) {
26
- let inside = false;
27
- for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
28
- const xi = ring[i][0];
29
- const yi = ring[i][1];
30
- const xj = ring[j][0];
31
- const yj = ring[j][1];
32
- if (yi > lat !== yj > lat && lon < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) {
33
- inside = !inside;
34
- }
35
- }
36
- return inside;
37
- }
38
- /**
39
- * Inside the outer ring and outside every hole.
40
- *
41
- * Repo-health-ignore private-name-shadows-export -- kept local so a leaf lookup package stays off @mailwoman/core's ~11
42
- * MB of shipped data; see the docstring
43
- */
44
- function pointInPolygon(lon, lat, polygon) {
45
- if (!polygon[0] || !pointInRing(lon, lat, polygon[0]))
46
- return false;
47
- for (let i = 1; i < polygon.length; i++)
48
- if (pointInRing(lon, lat, polygon[i]))
49
- return false;
50
- return true;
51
- }
52
- /**
53
- * Inside any polygon of a (multi)polygon feature.
54
- */
55
- export function pointInMultiPolygon(lon, lat, polygons) {
56
- return polygons.some((polygon) => pointInPolygon(lon, lat, polygon));
57
- }
58
- /**
59
- * The current UTC offset (seconds) for an IANA timezone, via `Intl` (no tz-db dependency). Returns `undefined` if the
60
- * runtime can't resolve the zone.
17
+ * @returns `undefined` if the runtime can't resolve the zone.
61
18
  */
62
19
  export function offsetSecForTimezone(tzid, date = new Date()) {
63
20
  try {
@@ -78,46 +35,35 @@ export function offsetSecForTimezone(tzid, date = new Date()) {
78
35
  /**
79
36
  * A timezone lookup over a built `node:sqlite` polygon DB.
80
37
  */
81
- export class TimezoneLookup {
82
- #db;
83
- /**
84
- * Resources this instance opened. A connection handed in by a caller is NOT in here, so disposal cannot reach it —
85
- * ownership is membership rather than a flag a later branch has to check.
86
- */
87
- #resources = new DisposableStack();
38
+ export class TimezoneLookup extends SQLiteLookup {
88
39
  #stmt;
89
40
  constructor(opts) {
90
- this.#db =
91
- "database" in opts
92
- ? opts.database
93
- : this.#resources.use(new DatabaseClient(opts.databasePath, { readOnly: true }));
94
- // Candidate features whose bbox contains the point; PIP picks the exact one.
95
- this.#stmt = this.#db.prepare(`SELECT tzid, geom FROM timezone_polygons
41
+ super(opts);
42
+ // Candidate features whose bbox contains the point.
43
+ // PIP picks the exact one.
44
+ this.#stmt = this.database.prepare(`SELECT tzid, geom FROM timezone_polygons
96
45
  WHERE minLat <= ? AND maxLat >= ? AND minLon <= ? AND maxLon >= ?`);
97
46
  }
98
47
  /**
99
- * The IANA timezone id containing `(lat, lon)`, or `null` if none (shouldn't happen with oceans).
48
+ * The iana timezone id containing `(lat, lon)`, or `null` if none (shouldn't happen with oceans).
100
49
  */
101
50
  explore(lat, lon) {
102
51
  const rows = this.#stmt.all(lat, lat, lon, lon);
103
52
  for (const row of rows) {
104
- const multiPolygonCoords = parseJSONStrict(row.geom);
105
- if (pointInMultiPolygon(lon, lat, multiPolygonCoords)) {
53
+ const polygons = parseJSONStrict(row.geom);
54
+ if (pointInMultiPolygon(lon, lat, polygons)) {
106
55
  return row.tzid;
107
56
  }
108
57
  }
109
58
  return null;
110
59
  }
111
- [Symbol.dispose]() {
112
- this.#resources[Symbol.dispose]();
113
- }
114
60
  }
115
61
  /**
116
62
  * Build an `Annotator` that fills `AnnotationSet.timezone` (name + current offset) from a lookup.
117
63
  */
118
64
  export function makeTimezoneAnnotator(lookup) {
119
65
  return ({ lat, lon, date }) => {
120
- // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe, not Array#find
66
+ // oxlint-disable-next-line unicorn/no-array-method-this-argument -- `lookup.find(lat, lon)` is a two-argument gazetteer probe rather than Array#find
121
67
  const name = lookup.explore(lat, lon);
122
68
  if (!name)
123
69
  return {};
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,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AASzD;;;;;;;;;;;GAWG;AACH,SAAS,WAAW,CAAC,GAAW,EAAE,GAAW,EAAE,IAAgB;IAC9D,IAAI,MAAM,GAAG,KAAK,CAAA;IAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QAC/D,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QAEvB,IAAI,EAAE,GAAG,GAAG,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,EAAE,GA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AAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CACjC;sEACmE,CACnE,CAAA;IACF,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,GAAW,EAAE,GAAW;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAA0C,CAAA;QAExF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,QAAQ,GAAG,eAAe,CAAoB,GAAG,CAAC,IAAI,CAAC,CAAA;YAE7D,IAAI,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC;gBAC7C,OAAO,GAAG,CAAC,IAAI,CAAA;YAChB,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAsB;IAC3D,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAA0B,EAAE;QACrD,qJAAqJ;QACrJ,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAErC,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAA;QACpB,MAAM,SAAS,GAAG,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAElD,OAAO,EAAE,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAA;IACxE,CAAC,CAAA;AACF,CAAC"}
package/out/paths.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Where the timezone database lives under the data root's `db/` group.
7
+ */
8
+ import type { PathBuilder } from "path-ts";
9
+ /**
10
+ * `$MAILWOMAN_DATA_ROOT/db/timezone`, read when a path is requested.
11
+ */
12
+ export declare const timezoneDatabasePath: PathBuilder;
13
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../lib/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAA0D,CAAA"}
package/out/paths.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Where the timezone database lives under the data root's `db/` group.
7
+ */
8
+ import { databaseRootPath, dataRootPath } from "@mailwoman/core/data-root";
9
+ /**
10
+ * `$MAILWOMAN_DATA_ROOT/db/timezone`, read when a path is requested.
11
+ */
12
+ export const timezoneDatabasePath = databaseRootPath(dataRootPath())("timezone");
13
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../lib/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAG1E;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgB,gBAAgB,CAAC,YAAY,EAAE,CAAC,CAAC,UAAU,CAAC,CAAA"}
package/out/schema.d.ts CHANGED
@@ -3,11 +3,11 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The `timezone.db` read contract. Declared beside the reader and the builder that writes it, so a column added to
6
+ * The `timezone.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 timezone polygon: its IANA identifier, bounding box, and encoded geometry.
10
+ * One timezone polygon: its IANA identifier, bounding box and encoded geometry.
11
11
  */
12
12
  export interface TimezonePolygonTable {
13
13
  tzid: string;
@@ -18,7 +18,7 @@ export interface TimezonePolygonTable {
18
18
  geom: string;
19
19
  }
20
20
  /**
21
- * The tables `timezone.db` carries.
21
+ * The tables included in `timezone.db`.
22
22
  */
23
23
  export interface TimezoneDatabase {
24
24
  timezone_polygons: TimezonePolygonTable;
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 `timezone.db` read contract. Declared beside the reader and the builder that writes it, so a column added to
6
+ * The `timezone.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/timezone-lookup",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "description": "Coordinate → IANA timezone, server-side. Point-in-polygon over timezone-boundary-builder polygons in a node:sqlite DB; UTC offset via Intl (no tz-db dependency). 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/timezone-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,11 +87,10 @@
81
87
  }
82
88
  },
83
89
  "dependencies": {
84
- "@mailwoman/annotations": "10.0.0",
85
- "@mailwoman/core": "10.0.0",
86
- "@mailwoman/sqlite": "10.0.0"
87
- },
88
- "devDependencies": {
89
- "@mailwoman/spatial": "10.0.0"
90
+ "@mailwoman/annotations": "10.1.0",
91
+ "@mailwoman/core": "10.1.0",
92
+ "@mailwoman/spatial": "10.1.0",
93
+ "@mailwoman/sqlite": "10.1.0",
94
+ "path-ts": "^2.5.0"
90
95
  }
91
96
  }
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;;;;;;;;;;;;;GAaG"}
package/out/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../lib/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAE7D,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,CAAC;IAC9C,OAAO,EAAE;QACR,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvB,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KACtB;IACD,gBAAgB,EAAE,IAAI;CACtB,CAAC,CAAA;AAEF,IAAI,WAAW,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAA;QAE5E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;IAED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