feat(SW-2859): Create trpc package * Add isEdge, safeTry and dataCache to new common package * Add eslint and move prettier config * Clean up tests * Create trpc package and move initialization * Move errors and a few procedures * Move telemetry to common package * Move tokenManager to common package * Add Sentry to procedures * Clean up procedures * Fix self-referencing imports * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * Fix lang imports Approved-by: Linus Flood
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { Lang } from "@scandic-hotels/common/constants/language"
|
|
|
|
import { warmupAutoComplete } from "./wamupAutoCompleteLocations"
|
|
import { warmupCountry } from "./warmupCountries"
|
|
import { warmupHotelData } from "./warmupHotelData"
|
|
import { warmupHotelIdsByCountry } from "./warmupHotelIdsByCountry"
|
|
|
|
import type { WarmupFunctionsKey } from "./warmupKeys"
|
|
|
|
export type WarmupFunction = () => Promise<WarmupResult>
|
|
|
|
type BaseWarmup = {
|
|
status: "skipped" | "completed"
|
|
}
|
|
|
|
type FailedWarmup = {
|
|
status: "error"
|
|
error: Error
|
|
}
|
|
|
|
export type WarmupResult = BaseWarmup | FailedWarmup
|
|
|
|
export const warmupFunctions: Record<WarmupFunctionsKey, WarmupFunction> = {
|
|
countries_en: warmupCountry(Lang.en),
|
|
countries_da: warmupCountry(Lang.da),
|
|
countries_de: warmupCountry(Lang.de),
|
|
countries_fi: warmupCountry(Lang.fi),
|
|
countries_sv: warmupCountry(Lang.sv),
|
|
countries_no: warmupCountry(Lang.no),
|
|
|
|
hotelsByCountry: warmupHotelIdsByCountry(),
|
|
|
|
hotelData_en: warmupHotelData(Lang.en),
|
|
hotelData_da: warmupHotelData(Lang.da),
|
|
hotelData_de: warmupHotelData(Lang.de),
|
|
hotelData_fi: warmupHotelData(Lang.fi),
|
|
hotelData_sv: warmupHotelData(Lang.sv),
|
|
hotelData_no: warmupHotelData(Lang.no),
|
|
|
|
autoComplete_en: warmupAutoComplete(Lang.en),
|
|
autoComplete_da: warmupAutoComplete(Lang.da),
|
|
autoComplete_de: warmupAutoComplete(Lang.de),
|
|
autoComplete_fi: warmupAutoComplete(Lang.fi),
|
|
autoComplete_sv: warmupAutoComplete(Lang.sv),
|
|
autoComplete_no: warmupAutoComplete(Lang.no),
|
|
}
|
|
|
|
export async function warmup(key: WarmupFunctionsKey): Promise<WarmupResult> {
|
|
const func = warmupFunctions[key]
|
|
if (!func) {
|
|
return {
|
|
status: "error",
|
|
error: new Error(`Warmup function ${key} not found`),
|
|
}
|
|
}
|
|
|
|
return func()
|
|
}
|