Merged in fix/common-package-fix (pull request #2355)
fix: Tiny fixes in common package * Fix self-referencing and circular imports * Fix env isServer Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { env } from "../../env/server"
|
|
||||||
import { cacheOrGet } from "./cacheOrGet"
|
import { cacheOrGet } from "./cacheOrGet"
|
||||||
import { deleteKey } from "./deleteKey"
|
import { deleteKey } from "./deleteKey"
|
||||||
import { get } from "./get"
|
import { get } from "./get"
|
||||||
@@ -6,7 +5,6 @@ import { set } from "./set"
|
|||||||
|
|
||||||
import type { DataCache } from "../Cache"
|
import type { DataCache } from "../Cache"
|
||||||
|
|
||||||
export const API_KEY = env.REDIS_API_KEY ?? ""
|
|
||||||
export async function createDistributedCache(): Promise<DataCache> {
|
export async function createDistributedCache(): Promise<DataCache> {
|
||||||
return {
|
return {
|
||||||
type: "redis",
|
type: "redis",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import * as Sentry from "@sentry/nextjs"
|
import * as Sentry from "@sentry/nextjs"
|
||||||
|
|
||||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
import { env } from "../../env/server"
|
||||||
|
import { safeTry } from "../../utils/safeTry"
|
||||||
import { cacheLogger } from "../logger"
|
import { cacheLogger } from "../logger"
|
||||||
import { API_KEY } from "./client"
|
|
||||||
import { getCacheEndpoint } from "./endpoints"
|
import { getCacheEndpoint } from "./endpoints"
|
||||||
|
|
||||||
|
const API_KEY = env.REDIS_API_KEY ?? ""
|
||||||
export async function deleteKey(key: string, opts?: { fuzzy?: boolean }) {
|
export async function deleteKey(key: string, opts?: { fuzzy?: boolean }) {
|
||||||
const perf = performance.now()
|
const perf = performance.now()
|
||||||
const endpoint = getCacheEndpoint(key)
|
const endpoint = getCacheEndpoint(key)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import * as Sentry from "@sentry/nextjs"
|
import * as Sentry from "@sentry/nextjs"
|
||||||
|
|
||||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
import { env } from "../../env/server"
|
||||||
|
import { safeTry } from "../../utils/safeTry"
|
||||||
import { cacheLogger } from "../logger"
|
import { cacheLogger } from "../logger"
|
||||||
import { API_KEY } from "./client"
|
|
||||||
import { deleteKey } from "./deleteKey"
|
import { deleteKey } from "./deleteKey"
|
||||||
import { getCacheEndpoint } from "./endpoints"
|
import { getCacheEndpoint } from "./endpoints"
|
||||||
|
|
||||||
|
const API_KEY = env.REDIS_API_KEY ?? ""
|
||||||
export async function get<T>(key: string) {
|
export async function get<T>(key: string) {
|
||||||
const perf = performance.now()
|
const perf = performance.now()
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import * as Sentry from "@sentry/nextjs"
|
import * as Sentry from "@sentry/nextjs"
|
||||||
|
|
||||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
import { env } from "../../env/server"
|
||||||
|
import { safeTry } from "../../utils/safeTry"
|
||||||
import { type CacheTime, getCacheTimeInSeconds } from "../Cache"
|
import { type CacheTime, getCacheTimeInSeconds } from "../Cache"
|
||||||
import { API_KEY } from "./client"
|
|
||||||
import { getCacheEndpoint } from "./endpoints"
|
import { getCacheEndpoint } from "./endpoints"
|
||||||
|
|
||||||
|
const API_KEY = env.REDIS_API_KEY ?? ""
|
||||||
export async function set<T>(key: string, value: T, ttl: CacheTime) {
|
export async function set<T>(key: string, value: T, ttl: CacheTime) {
|
||||||
const [response, error] = await safeTry(
|
const [response, error] = await safeTry(
|
||||||
fetch(getCacheEndpoint(key), {
|
fetch(getCacheEndpoint(key), {
|
||||||
|
|||||||
2
packages/common/env/server.ts
vendored
2
packages/common/env/server.ts
vendored
@@ -7,7 +7,7 @@ export const env = createEnv({
|
|||||||
* and Netlify running Deno, window is never "undefined"
|
* and Netlify running Deno, window is never "undefined"
|
||||||
* https://github.com/t3-oss/t3-env/issues/154
|
* https://github.com/t3-oss/t3-env/issues/154
|
||||||
*/
|
*/
|
||||||
isServer: true,
|
isServer: typeof window === "undefined" || "Deno" in window,
|
||||||
server: {
|
server: {
|
||||||
NODE_ENV: z.enum(["development", "test", "production"]),
|
NODE_ENV: z.enum(["development", "test", "production"]),
|
||||||
REDIS_API_HOST: z.string().optional(),
|
REDIS_API_HOST: z.string().optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user