upstash.ts 755 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { SyncStore } from "@/app/store/sync";
  2. export type UpstashConfig = SyncStore["upstash"];
  3. export type UpStashClient = ReturnType<typeof createUpstashClient>;
  4. export function createUpstashClient(config: UpstashConfig) {
  5. return {
  6. async check() {
  7. return true;
  8. },
  9. async get() {
  10. throw Error("[Sync] not implemented");
  11. },
  12. async set() {
  13. throw Error("[Sync] not implemented");
  14. },
  15. headers() {
  16. return {
  17. Authorization: `Basic ${config.apiKey}`,
  18. };
  19. },
  20. path(path: string) {
  21. let url = config.endpoint;
  22. if (!url.endsWith("/")) {
  23. url += "/";
  24. }
  25. if (path.startsWith("/")) {
  26. path = path.slice(1);
  27. }
  28. return url + path;
  29. },
  30. };
  31. }