65 lines
1.2 KiB
TypeScript
65 lines
1.2 KiB
TypeScript
// services.ts
|
|
|
|
import { AuthService } from "../auth";
|
|
import { getCurrentUser } from "../context";
|
|
import { db, migrate, migrationStatus, PostgresAuthStore } from "../database";
|
|
import { getLogs, log } from "../logging";
|
|
import type { MaybeUser } from "../user";
|
|
import nunjucks from 'nunjucks'
|
|
|
|
const conf = {
|
|
templateEngine: () => {
|
|
return {
|
|
renderTemplate: (template: string, context: object) => {
|
|
return nunjucks.renderString(template, context);
|
|
},
|
|
}
|
|
}
|
|
};
|
|
|
|
const database = {
|
|
db,
|
|
migrate,
|
|
migrationStatus,
|
|
};
|
|
|
|
const logging = {
|
|
log,
|
|
getLogs,
|
|
};
|
|
|
|
const random = {
|
|
randomNumber: () => {
|
|
return Math.random();
|
|
},
|
|
};
|
|
|
|
const misc = {
|
|
sleep: (ms: number) => {
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
},
|
|
};
|
|
|
|
const session = {
|
|
getUser: (): MaybeUser => {
|
|
return getCurrentUser();
|
|
},
|
|
};
|
|
|
|
// Initialize auth with PostgreSQL store
|
|
const authStore = new PostgresAuthStore();
|
|
const auth = new AuthService(authStore);
|
|
|
|
// Keep this asciibetically sorted
|
|
const services = {
|
|
auth,
|
|
conf,
|
|
database,
|
|
logging,
|
|
misc,
|
|
random,
|
|
session,
|
|
};
|
|
|
|
export { services };
|