You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			34 lines
		
	
	
		
			787 B
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			34 lines
		
	
	
		
			787 B
		
	
	
	
		
			TypeScript
		
	
| 
											9 months ago
										 | import { createWebDavClient } from "./webdav"; | ||
|  | import { createUpstashClient } from "./upstash"; | ||
|  | 
 | ||
|  | export enum ProviderType { | ||
|  |   WebDAV = "webdav", | ||
|  |   UpStash = "upstash", | ||
|  | } | ||
|  | 
 | ||
|  | export const SyncClients = { | ||
|  |   [ProviderType.UpStash]: createUpstashClient, | ||
|  |   [ProviderType.WebDAV]: createWebDavClient, | ||
|  | } as const; | ||
|  | 
 | ||
|  | type SyncClientConfig = { | ||
|  |   [K in keyof typeof SyncClients]: (typeof SyncClients)[K] extends ( | ||
|  |     _: infer C, | ||
|  |   ) => any | ||
|  |     ? C | ||
|  |     : never; | ||
|  | }; | ||
|  | 
 | ||
|  | export type SyncClient = { | ||
|  |   get: (key: string) => Promise<string>; | ||
|  |   set: (key: string, value: string) => Promise<void>; | ||
|  |   check: () => Promise<boolean>; | ||
|  | }; | ||
|  | 
 | ||
|  | export function createSyncClient<T extends ProviderType>( | ||
|  |   provider: T, | ||
|  |   config: SyncClientConfig[T], | ||
|  | ): SyncClient { | ||
|  |   return SyncClients[provider](config as any) as any; | ||
|  | } |