@tmlmobilidade/go-interfaces-pcgi-legacy 20260723.1350.16

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,8 @@
1
+ import { MongoInterfaceTemplate } from '../interface.template.js';
2
+ import { type MongoClient } from '@tmlmobilidade/go-clients-mongo';
3
+ export declare class CoreManagementDatabase {
4
+ readonly vehicleEvents: MongoInterfaceTemplate<any>;
5
+ private readonly database;
6
+ private readonly databaseName;
7
+ constructor(instance: MongoClient);
8
+ }
@@ -0,0 +1,15 @@
1
+ /* * */
2
+ import { MongoInterfaceTemplate } from '../interface.template.js';
3
+ /* * */
4
+ export class CoreManagementDatabase {
5
+ //
6
+ vehicleEvents;
7
+ database;
8
+ databaseName = 'CoreManagement';
9
+ constructor(instance) {
10
+ // Create the database instance
11
+ this.database = instance.db(this.databaseName);
12
+ // Create collection interfaces
13
+ this.vehicleEvents = new MongoInterfaceTemplate('VehicleEvents', this.database);
14
+ }
15
+ }
@@ -0,0 +1,8 @@
1
+ import { MongoInterfaceTemplate } from '../interface.template.js';
2
+ import { type MongoClient } from '@tmlmobilidade/go-clients-mongo';
3
+ export declare class OfferApiLogDatabase {
4
+ readonly vehicleEvents: MongoInterfaceTemplate<any>;
5
+ private readonly database;
6
+ private readonly databaseName;
7
+ constructor(instance: MongoClient);
8
+ }
@@ -0,0 +1,15 @@
1
+ /* * */
2
+ import { MongoInterfaceTemplate } from '../interface.template.js';
3
+ /* * */
4
+ export class OfferApiLogDatabase {
5
+ //
6
+ vehicleEvents;
7
+ database;
8
+ databaseName = 'OfferApiLog';
9
+ constructor(instance) {
10
+ // Create the database instance
11
+ this.database = instance.db(this.databaseName);
12
+ // Create collection interfaces
13
+ this.vehicleEvents = new MongoInterfaceTemplate('VehicleEvents', this.database);
14
+ }
15
+ }
@@ -0,0 +1,16 @@
1
+ import { CoreManagementDatabase } from './databases/core-management.js';
2
+ import { OfferApiLogDatabase } from './databases/offer-api-log.js';
3
+ declare class PCGILegacyClass {
4
+ private static _instance;
5
+ readonly coreManagement: CoreManagementDatabase;
6
+ readonly offerApiLog: OfferApiLogDatabase;
7
+ private constructor();
8
+ /**
9
+ * Establishes a connection to the Mongo database and initializes the collection.
10
+ * @param options Optional Mongo client connection options.
11
+ * @throws Error if the environment variable for the database URI is missing or if the connection fails.
12
+ */
13
+ static getInstance(): Promise<PCGILegacyClass>;
14
+ }
15
+ export declare const pcgiLegacy: PCGILegacyClass;
16
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ /* * */
2
+ import { MongoDatabaseClient } from '@tmlmobilidade/go-clients-mongo';
3
+ import { asyncSingletonProxy } from '@tmlmobilidade/utils';
4
+ import { CoreManagementDatabase } from './databases/core-management.js';
5
+ import { OfferApiLogDatabase } from './databases/offer-api-log.js';
6
+ /* * */
7
+ class PCGILegacyClass {
8
+ //
9
+ static _instance;
10
+ coreManagement;
11
+ offerApiLog;
12
+ constructor(mongoClient) {
13
+ this.coreManagement = new CoreManagementDatabase(mongoClient);
14
+ this.offerApiLog = new OfferApiLogDatabase(mongoClient);
15
+ }
16
+ /**
17
+ * Establishes a connection to the Mongo database and initializes the collection.
18
+ * @param options Optional Mongo client connection options.
19
+ * @throws Error if the environment variable for the database URI is missing or if the connection fails.
20
+ */
21
+ static async getInstance() {
22
+ if (!PCGILegacyClass._instance) {
23
+ const mongoClient = await MongoDatabaseClient.getClient({ prefix: 'PCGI_LEGACY', tunnelType: 'PCGI' });
24
+ PCGILegacyClass._instance = new PCGILegacyClass(mongoClient);
25
+ }
26
+ return PCGILegacyClass._instance;
27
+ }
28
+ }
29
+ /* * */
30
+ export const pcgiLegacy = asyncSingletonProxy(PCGILegacyClass);
@@ -0,0 +1,44 @@
1
+ import { type Collection, type Db, type Document, type Filter, type FindOptions, type WithId } from '@tmlmobilidade/go-clients-mongo';
2
+ export declare class MongoInterfaceTemplate<T extends Document> {
3
+ private readonly collection;
4
+ /**
5
+ * @param collectionName The name of the collection to create the interface for.
6
+ * @param database The database to create the interface for.
7
+ */
8
+ constructor(collectionName: string, database: Db);
9
+ /**
10
+ * Counts documents matching the filter criteria.
11
+ * @param filter The filter criteria to match documents.
12
+ * @returns A promise that resolves to the count of matching documents.
13
+ */
14
+ count(filter?: Filter<T>): Promise<number>;
15
+ /**
16
+ * Finds all distinct values for a key in the collection.
17
+ * @param key The key to find distinct values for.
18
+ * @param filter Optional filter criteria to match documents before extracting distinct values.
19
+ * @returns A promise that resolves to an array of distinct values for the given key.
20
+ */
21
+ distinct<Key extends keyof WithId<T>>(key: Key, filter: Filter<T>): Promise<import("mongodb").Flatten<WithId<T>[Key]>[]>;
22
+ /**
23
+ * Finds multiple documents matching the filter criteria,
24
+ * with optional pagination and sorting.
25
+ * @param filter (Optional) filter criteria to match documents.
26
+ * @param options (Optional) find options.
27
+ * @returns A promise that resolves to an array of matching documents.
28
+ */
29
+ findMany(filter: Filter<T>, options?: FindOptions): Promise<WithId<T>[]>;
30
+ /**
31
+ * Finds a single document matching the filter criteria.
32
+ * @param filter The filter criteria to match the document.
33
+ * @param options Optional options.
34
+ * @returns A promise that resolves to the matching document or null if not found.
35
+ */
36
+ findOne(filter: Filter<T>, options?: FindOptions): Promise<T | null>;
37
+ /**
38
+ * Provides access to the MongoDB collection instance,
39
+ * initializing it if it has not already been created.
40
+ * @returns A promise that resolves to the MongoDB collection instance.
41
+ * @warning Use with caution: direct access to the collection allows for executing arbitrary queries.
42
+ */
43
+ getCollection(): Promise<Collection<T>>;
44
+ }
@@ -0,0 +1,58 @@
1
+ /* * */
2
+ /* * */
3
+ export class MongoInterfaceTemplate {
4
+ //
5
+ collection;
6
+ /**
7
+ * @param collectionName The name of the collection to create the interface for.
8
+ * @param database The database to create the interface for.
9
+ */
10
+ constructor(collectionName, database) {
11
+ this.collection = database.collection(collectionName);
12
+ }
13
+ /**
14
+ * Counts documents matching the filter criteria.
15
+ * @param filter The filter criteria to match documents.
16
+ * @returns A promise that resolves to the count of matching documents.
17
+ */
18
+ async count(filter) {
19
+ return await this.collection.countDocuments(filter);
20
+ }
21
+ /**
22
+ * Finds all distinct values for a key in the collection.
23
+ * @param key The key to find distinct values for.
24
+ * @param filter Optional filter criteria to match documents before extracting distinct values.
25
+ * @returns A promise that resolves to an array of distinct values for the given key.
26
+ */
27
+ async distinct(key, filter) {
28
+ return this.collection.distinct(key, filter);
29
+ }
30
+ /**
31
+ * Finds multiple documents matching the filter criteria,
32
+ * with optional pagination and sorting.
33
+ * @param filter (Optional) filter criteria to match documents.
34
+ * @param options (Optional) find options.
35
+ * @returns A promise that resolves to an array of matching documents.
36
+ */
37
+ async findMany(filter, options) {
38
+ return await this.collection.find(filter, options).toArray();
39
+ }
40
+ /**
41
+ * Finds a single document matching the filter criteria.
42
+ * @param filter The filter criteria to match the document.
43
+ * @param options Optional options.
44
+ * @returns A promise that resolves to the matching document or null if not found.
45
+ */
46
+ async findOne(filter, options) {
47
+ return await this.collection.findOne(filter, options);
48
+ }
49
+ /**
50
+ * Provides access to the MongoDB collection instance,
51
+ * initializing it if it has not already been created.
52
+ * @returns A promise that resolves to the MongoDB collection instance.
53
+ * @warning Use with caution: direct access to the collection allows for executing arbitrary queries.
54
+ */
55
+ async getCollection() {
56
+ return this.collection;
57
+ }
58
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@tmlmobilidade/go-interfaces-pcgi-legacy",
3
+ "version": "20260723.1350.16",
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/go-clients-mongo": "*",
40
+ "@tmlmobilidade/go-types-vehicle-events": "*",
41
+ "@tmlmobilidade/logger": "*",
42
+ "@tmlmobilidade/utils": "*",
43
+ "luxon": "3.7.2",
44
+ "zod": "3.25.76"
45
+ },
46
+ "devDependencies": {
47
+ "@tmlmobilidade/tsconfig": "*",
48
+ "@types/luxon": "3.7.2",
49
+ "@types/node": "26.1.1",
50
+ "resolve-tspaths": "0.8.23",
51
+ "tsc-watch": "7.2.1",
52
+ "typescript": "6.0.3"
53
+ }
54
+ }