@tmlmobilidade/go-providers-locations 20260723.1538.19

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.
@@ -0,0 +1 @@
1
+ export * from './provider.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './provider.js';
@@ -0,0 +1,33 @@
1
+ import { type District, type Locality, type Municipality, type Parish } from '@tmlmobilidade/types';
2
+ declare class LocationsProviderClass {
3
+ private static _instance;
4
+ private constructor();
5
+ static getInstance(): Promise<LocationsProviderClass>;
6
+ countDistricts(filter?: any): Promise<number>;
7
+ countLocalities(filter?: any): Promise<number>;
8
+ countMunicipalities(filter?: any): Promise<number>;
9
+ countParishes(filter?: any): Promise<number>;
10
+ findDistricts(filter?: any, options?: any): Promise<District[]>;
11
+ findLocalities(filter?: any, options?: any): Promise<Locality[]>;
12
+ findMunicipalities(filter?: any, options?: any): Promise<Municipality[]>;
13
+ findParishes(filter?: any, options?: any): Promise<Parish[]>;
14
+ findDistrictById(id: string): Promise<District | null>;
15
+ findLocalityById(id: string): Promise<Locality | null>;
16
+ findMunicipalityById(id: string): Promise<Municipality | null>;
17
+ findParishById(id: string): Promise<null | Parish>;
18
+ findDistrictByGeo(lat: number, lon: number): Promise<District | null>;
19
+ findLocalityByGeo(lat: number, lon: number): Promise<Locality | null>;
20
+ findLocationByGeo(lat: number, lon: number): Promise<{
21
+ district: District | null;
22
+ latitude: number;
23
+ locality: Locality | null;
24
+ longitude: number;
25
+ municipality: Municipality | null;
26
+ parish: Parish | null;
27
+ }>;
28
+ findMunicipalityByGeo(lat: number, lon: number): Promise<Municipality | null>;
29
+ findParishByGeo(lat: number, lon: number): Promise<null | Parish>;
30
+ private geoFilter;
31
+ }
32
+ export declare const locationsProvider: LocationsProviderClass;
33
+ export {};
@@ -0,0 +1,91 @@
1
+ /* * */
2
+ import { HTTP_STATUS, HttpException } from '@tmlmobilidade/consts';
3
+ import { goDb } from '@tmlmobilidade/go-interfaces-godb';
4
+ import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
+ /* * */
6
+ class LocationsProviderClass {
7
+ static _instance;
8
+ constructor() { }
9
+ static async getInstance() {
10
+ if (!LocationsProviderClass._instance) {
11
+ LocationsProviderClass._instance = new LocationsProviderClass();
12
+ }
13
+ return LocationsProviderClass._instance;
14
+ }
15
+ /* Count */
16
+ async countDistricts(filter) {
17
+ return goDb.locations.districts.count(filter);
18
+ }
19
+ async countLocalities(filter) {
20
+ return goDb.locations.localities.count(filter);
21
+ }
22
+ async countMunicipalities(filter) {
23
+ return goDb.locations.municipalities.count(filter);
24
+ }
25
+ async countParishes(filter) {
26
+ return goDb.locations.parishes.count(filter);
27
+ }
28
+ /* Find All */
29
+ async findDistricts(filter, options) {
30
+ return goDb.locations.districts.findMany(filter, options);
31
+ }
32
+ async findLocalities(filter, options) {
33
+ return goDb.locations.localities.findMany(filter, options);
34
+ }
35
+ async findMunicipalities(filter, options) {
36
+ return goDb.locations.municipalities.findMany(filter, options);
37
+ }
38
+ async findParishes(filter, options) {
39
+ return goDb.locations.parishes.findMany(filter, options);
40
+ }
41
+ /* Find By Id */
42
+ async findDistrictById(id) {
43
+ return goDb.locations.districts.findById(id);
44
+ }
45
+ async findLocalityById(id) {
46
+ return goDb.locations.localities.findById(id);
47
+ }
48
+ async findMunicipalityById(id) {
49
+ return goDb.locations.municipalities.findById(id);
50
+ }
51
+ async findParishById(id) {
52
+ return goDb.locations.parishes.findById(id);
53
+ }
54
+ /* Find By Geo */
55
+ async findDistrictByGeo(lat, lon) {
56
+ return goDb.locations.districts.findOne(this.geoFilter(lat, lon));
57
+ }
58
+ async findLocalityByGeo(lat, lon) {
59
+ return goDb.locations.localities.findOne(this.geoFilter(lat, lon));
60
+ }
61
+ async findLocationByGeo(lat, lon) {
62
+ if (!lat || !lon)
63
+ throw new HttpException(HTTP_STATUS.BAD_REQUEST, 'Missing latitude or longitude');
64
+ const [municipality, parish, district, locality] = await Promise.all([
65
+ this.findMunicipalityByGeo(lat, lon),
66
+ this.findParishByGeo(lat, lon),
67
+ this.findDistrictByGeo(lat, lon),
68
+ this.findLocalityByGeo(lat, lon),
69
+ ]);
70
+ return {
71
+ district,
72
+ latitude: lat,
73
+ locality,
74
+ longitude: lon,
75
+ municipality,
76
+ parish,
77
+ };
78
+ }
79
+ async findMunicipalityByGeo(lat, lon) {
80
+ return goDb.locations.municipalities.findOne(this.geoFilter(lat, lon));
81
+ }
82
+ async findParishByGeo(lat, lon) {
83
+ return goDb.locations.parishes.findOne(this.geoFilter(lat, lon));
84
+ }
85
+ /* Private */
86
+ geoFilter(lat, lon) {
87
+ return { geometry: { $geoIntersects: { $geometry: { coordinates: [lon, lat], type: 'Point' } } } };
88
+ }
89
+ }
90
+ /* * */
91
+ export const locationsProvider = asyncSingletonProxy(LocationsProviderClass);
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@tmlmobilidade/go-providers-locations",
3
+ "version": "20260723.1538.19",
4
+ "author": {
5
+ "email": "iso@tmlmobilidade.pt",
6
+ "name": "TML-ISO"
7
+ },
8
+ "license": "AGPL-3.0-or-later",
9
+ "homepage": "https://go.tmlmobilidade.pt",
10
+ "bugs": {
11
+ "url": "https://github.com/tmlmobilidade/go/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/tmlmobilidade/go.git"
16
+ },
17
+ "keywords": [
18
+ "public transit",
19
+ "tml",
20
+ "transportes metropolitanos de lisboa",
21
+ "go"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "type": "module",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "scripts": {
33
+ "build": "tsc && resolve-tspaths",
34
+ "lint": "eslint ./src/ && tsc --noEmit",
35
+ "lint:fix": "eslint ./src/ --fix",
36
+ "watch": "tsc-watch --onSuccess 'resolve-tspaths'"
37
+ },
38
+ "dependencies": {
39
+ "@tmlmobilidade/consts": "*",
40
+ "@tmlmobilidade/go-interfaces-godb": "*",
41
+ "@tmlmobilidade/types": "*",
42
+ "@tmlmobilidade/utils": "*"
43
+ },
44
+ "devDependencies": {
45
+ "@tmlmobilidade/tsconfig": "*",
46
+ "@types/node": "26.1.1",
47
+ "resolve-tspaths": "0.8.23",
48
+ "tsc-watch": "7.2.1",
49
+ "typescript": "6.0.3"
50
+ }
51
+ }