@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.
35 lines (34 loc) • 1.15 kB
JavaScript
// /* * */
import { MongoCollectionClass } from '../../common/mongo-collection.js';
import { ProposedChangeSchema, UpdateProposedChangeSchema } from '@tmlmobilidade/types';
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
/* * */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
class ProposedChangesClass extends MongoCollectionClass {
static _instances = new Map();
createSchema = ProposedChangeSchema;
updateSchema = UpdateProposedChangeSchema;
constructor() {
super();
}
static async getInstance(typeName) {
const key = typeName ?? 'default';
if (!this._instances.has(key)) {
const instance = new ProposedChangesClass();
await instance.connect();
this._instances.set(key, instance);
}
return this._instances.get(key);
}
getCollectionIndexes() {
return [{ background: true, key: { name: 1 } }];
}
getCollectionName() {
return 'proposed_changes';
}
getEnvName() {
return 'DATABASE_URI';
}
}
/* * */
export const proposedChanges = asyncSingletonProxy(ProposedChangesClass);