@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.
41 lines (40 loc) • 1.25 kB
JavaScript
/* * */
import { MongoCollectionClass } from '../../common/mongo-collection.js';
import { CreateSessionSchema, UpdateSessionSchema } from '@tmlmobilidade/types';
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
/* * */
class SessionsClass extends MongoCollectionClass {
static _instance;
createSchema = CreateSessionSchema;
updateSchema = UpdateSessionSchema;
constructor() {
super();
}
static async getInstance() {
if (!SessionsClass._instance) {
const instance = new SessionsClass();
await instance.connect();
SessionsClass._instance = instance;
}
return SessionsClass._instance;
}
getCollectionIndexes() {
return [
{ background: true, key: { user_id: 1 } },
{ background: true, key: { expires: 1 } },
{ background: true, key: { token: 1 }, unique: true },
];
}
getCollectionName() {
return 'sessions';
}
getEnvName() {
return 'DATABASE_URI';
}
}
/* * */
/**
* @deprecated This class is deprecated and will be removed in the future.
* Use `@tmlmobilidade/go-interfaces-go-db` instead.
*/
export const sessions = asyncSingletonProxy(SessionsClass);