@tmlmobilidade/interfaces
Version:
This package provides SDK-style connectors for interacting with databases (e.g., stops, plans, rides, alerts) and external providers (e.g., authentication, storage). It simplifies data access and integration across projects.
38 lines (37 loc) • 1.14 kB
JavaScript
/* * */
import { MongoCollectionClass } from '../../common/mongo-collection.js';
import { MetricSchema } from '@tmlmobilidade/types';
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
/* * */
class MetricsClass extends MongoCollectionClass {
static _instance;
createSchema = MetricSchema;
updateSchema = MetricSchema;
constructor() {
super();
}
static async getInstance() {
if (!MetricsClass._instance) {
const instance = new MetricsClass();
await instance.connect();
MetricsClass._instance = instance;
}
return MetricsClass._instance;
}
getCollectionIndexes() {
return [
{ background: true, key: { metric: 1 } },
{ background: true, key: { 'properties.year': 1 } },
{ background: true, key: { 'properties.month': 1 } },
{ background: true, key: { 'data.lineId': 1 } },
];
}
getCollectionName() {
return 'metrics';
}
getEnvName() {
return 'DATABASE_URI';
}
}
/* * */
export const metrics = asyncSingletonProxy(MetricsClass);