@tmlmobilidade/go-interfaces-locationsdb 20261001.1834.21 → 20261006.1041.13

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.
@@ -28,6 +28,8 @@ declare class LocationsDbClass {
28
28
  * @param adminLevel OSM admin_level (e.g. `"7"` for Portuguese municipalities).
29
29
  */
30
30
  findLocationsWithGeojsonByCountryAndAdminLevel(countryCode: CountryCode, adminLevel: number | string): Promise<LocationWithGeojson[]>;
31
+ /** Reads the last completely published tree, including during an OSM import. */
32
+ findCacheValue<T>(key: string): Promise<null | T>;
31
33
  /**
32
34
  * Executes a SQL query against the locations database.
33
35
  * @param text The SQL query text (supports `$1`, `$2`, … placeholders).
package/dist/interface.js CHANGED
@@ -49,6 +49,11 @@ class LocationsDbClass {
49
49
  const result = await this.postgresClient.query(FIND_LOCATIONS_WITH_GEOJSON_BY_COUNTRY_AND_ADMIN_LEVEL, [String(adminLevel), countryCode]);
50
50
  return result.rows;
51
51
  }
52
+ /** Reads the last completely published tree, including during an OSM import. */
53
+ async findCacheValue(key) {
54
+ const result = await this.postgresClient.query('SELECT cache_value AS value FROM public.cache WHERE cache_key = $1', [key]);
55
+ return result.rows[0]?.value ?? null;
56
+ }
52
57
  /**
53
58
  * Executes a SQL query against the locations database.
54
59
  * @param text The SQL query text (supports `$1`, `$2`, … placeholders).
package/dist/queries.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  /** List locations at a given admin_level ($1) inside a country ($2), without geometry. */
2
- export declare const FIND_LOCATIONS_BY_COUNTRY_AND_ADMIN_LEVEL = "\nSELECT\n\tabs(p.osm_id) AS id,\n\tCOALESCE(p.tags->>'int_name', p.name) AS name,\n\tp.admin_level,\n\tp.tags->>'ref:ine' AS code,\n\tp.tags\nFROM planet_osm_polygon p\nWHERE p.boundary = 'administrative'\n\tAND p.admin_level = $1\n\tAND p.way && (\n\tSELECT c.way\n\tFROM planet_osm_polygon c\n\tWHERE c.boundary = 'administrative'\n\t\tAND c.admin_level = '2'\n\t\tAND c.tags->>'ISO3166-1' = $2\n\tLIMIT 1\n)\n\tAND ST_Within(p.way, (\n\tSELECT c.way\n\tFROM planet_osm_polygon c\n\tWHERE c.boundary = 'administrative'\n\t\tAND c.admin_level = '2'\n\t\tAND c.tags->>'ISO3166-1' = $2\n\tLIMIT 1\n))\nORDER BY name;\n";
3
- /** List locations at a given admin_level ($1) inside a country ($2), with GeoJSON geometry. */
4
- export declare const FIND_LOCATIONS_WITH_GEOJSON_BY_COUNTRY_AND_ADMIN_LEVEL = "\nSELECT\n\tabs(p.osm_id) AS id,\n\tCOALESCE(p.tags->>'int_name', p.name) AS name,\n\tp.admin_level,\n\tp.tags->>'ref:ine' AS code,\n\tp.tags,\n\tjson_build_object(\n\t\t'type', 'FeatureCollection',\n\t\t'features', json_agg(\n\t\t\tjson_build_object(\n\t\t\t\t'type', 'Feature',\n\t\t\t\t'id', abs(osm_id),\n\t\t\t\t'properties', json_build_object(\n\t\t\t\t\t'name', name,\n\t\t\t\t\t'admin_level', admin_level,\n\t\t\t\t\t'code', tags->>'ref:ine',\n\t\t\t\t\t'tags', tags\n\t\t\t\t),\n\t\t\t\t'geometry', ST_AsGeoJSON(\n\t\t\t\t\tST_Transform(way, 4326)\n\t\t\t\t)::json\n\t\t\t)\n\t\t)\n\t) AS geojson\nFROM planet_osm_polygon p\nWHERE p.boundary = 'administrative'\n\tAND p.admin_level = $1\n\tAND p.way && (\n\tSELECT c.way\n\tFROM planet_osm_polygon c\n\tWHERE c.boundary = 'administrative'\n\t\tAND c.admin_level = '2'\n\t\tAND c.tags->>'ISO3166-1' = $2\n\tLIMIT 1\n)\n\tAND ST_Within(p.way, (\n\tSELECT c.way\n\tFROM planet_osm_polygon c\n\tWHERE c.boundary = 'administrative'\n\t\tAND c.admin_level = '2'\n\t\tAND c.tags->>'ISO3166-1' = $2\n\tLIMIT 1\n))\nGROUP BY id, name, admin_level, code, tags;\n";
2
+ export declare const FIND_LOCATIONS_BY_COUNTRY_AND_ADMIN_LEVEL = "\nSELECT\n\tabs(p.osm_id) AS id,\n\tCOALESCE(p.tags->>'int_name', p.name) AS name,\n\tp.admin_level,\n\tp.tags->>'ref:ine' AS code,\n\tp.tags\nFROM planet_osm_polygon p\nWHERE p.boundary = 'administrative'\n\tAND p.admin_level = $1\n\tAND ST_Within(p.way, (\n\tSELECT c.way\n\tFROM planet_osm_polygon c\n\tWHERE c.boundary = 'administrative'\n\t\tAND c.admin_level = '2'\n\t\tAND c.tags->>'ISO3166-1' = $2\n\tLIMIT 1\n))\nORDER BY name;\n";
3
+ /**
4
+ * Lists one GeoJSON feature per OSM relation. The post-import migration enforces
5
+ * unique osm_id values; flex imports these geometries in SRID 4326.
6
+ */
7
+ export declare const FIND_LOCATIONS_WITH_GEOJSON_BY_COUNTRY_AND_ADMIN_LEVEL = "\nSELECT\n\tabs(p.osm_id) AS id,\n\tCOALESCE(p.tags->>'int_name', p.name) AS name,\n\tp.admin_level,\n\tp.tags->>'ref:ine' AS code,\n\tp.tags,\n\tjson_build_object(\n\t\t'type', 'FeatureCollection',\n\t\t'features', json_build_array(\n\t\t\tjson_build_object(\n\t\t\t\t'type', 'Feature',\n\t\t\t\t'id', abs(osm_id),\n\t\t\t\t'properties', json_build_object(\n\t\t\t\t\t'name', name,\n\t\t\t\t\t'admin_level', admin_level,\n\t\t\t\t\t'code', tags->>'ref:ine',\n\t\t\t\t\t'tags', tags\n\t\t\t\t),\n\t\t\t\t'geometry', ST_AsGeoJSON(way)::json\n\t\t\t)\n\t\t)\n\t) AS geojson\nFROM planet_osm_polygon p\nWHERE p.boundary = 'administrative'\n\tAND p.admin_level = $1\n\tAND ST_Within(p.way, (\n\tSELECT c.way\n\tFROM planet_osm_polygon c\n\tWHERE c.boundary = 'administrative'\n\t\tAND c.admin_level = '2'\n\t\tAND c.tags->>'ISO3166-1' = $2\n\tLIMIT 1\n));\n";
5
8
  /**
6
9
  * Find the administrative locations that cover a WGS84 point ($1 lon, $2 lat), plus the nearest
7
10
  * `place=locality` point within $3 metres (returned with `admin_level = 'neighbourhood'`), in one round-trip.
package/dist/queries.js CHANGED
@@ -19,11 +19,13 @@ SELECT
19
19
  FROM planet_osm_polygon p
20
20
  WHERE p.boundary = 'administrative'
21
21
  AND p.admin_level = $1
22
- AND p.way && (${COUNTRY_WAY})
23
22
  AND ST_Within(p.way, (${COUNTRY_WAY}))
24
23
  ORDER BY name;
25
24
  `;
26
- /** List locations at a given admin_level ($1) inside a country ($2), with GeoJSON geometry. */
25
+ /**
26
+ * Lists one GeoJSON feature per OSM relation. The post-import migration enforces
27
+ * unique osm_id values; flex imports these geometries in SRID 4326.
28
+ */
27
29
  export const FIND_LOCATIONS_WITH_GEOJSON_BY_COUNTRY_AND_ADMIN_LEVEL = `
28
30
  SELECT
29
31
  abs(p.osm_id) AS id,
@@ -33,7 +35,7 @@ SELECT
33
35
  p.tags,
34
36
  json_build_object(
35
37
  'type', 'FeatureCollection',
36
- 'features', json_agg(
38
+ 'features', json_build_array(
37
39
  json_build_object(
38
40
  'type', 'Feature',
39
41
  'id', abs(osm_id),
@@ -43,18 +45,14 @@ SELECT
43
45
  'code', tags->>'ref:ine',
44
46
  'tags', tags
45
47
  ),
46
- 'geometry', ST_AsGeoJSON(
47
- ST_Transform(way, 4326)
48
- )::json
48
+ 'geometry', ST_AsGeoJSON(way)::json
49
49
  )
50
50
  )
51
51
  ) AS geojson
52
52
  FROM planet_osm_polygon p
53
53
  WHERE p.boundary = 'administrative'
54
54
  AND p.admin_level = $1
55
- AND p.way && (${COUNTRY_WAY})
56
- AND ST_Within(p.way, (${COUNTRY_WAY}))
57
- GROUP BY id, name, admin_level, code, tags;
55
+ AND ST_Within(p.way, (${COUNTRY_WAY}));
58
56
  `;
59
57
  /**
60
58
  * Find the administrative locations that cover a WGS84 point ($1 lon, $2 lat), plus the nearest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-interfaces-locationsdb",
3
- "version": "20261001.1834.21",
3
+ "version": "20261006.1041.13",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"
@@ -37,6 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@tmlmobilidade/go-clients-postgres": "*",
40
+ "@tmlmobilidade/go-types-locations": "*",
40
41
  "@tmlmobilidade/go-utils-exec": "*"
41
42
  },
42
43
  "devDependencies": {