File size: 2,496 Bytes
cfb0fa4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import { convex, api } from '$lib/convexClient';
// βββ Settings ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const syncSettings = async (userId: string, data: object): Promise<void> => {
try {
await convex.mutation(api.settings.save, { userId, data });
} catch (e) {
console.error('[Convex] Failed to sync settings:', e);
}
};
export const loadSettings = async (userId: string): Promise<object | null> => {
try {
const doc = await convex.query(api.settings.get, { userId });
return doc?.data ?? null;
} catch (e) {
console.error('[Convex] Failed to load settings:', e);
return null;
}
};
// βββ Conversations ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const syncConversation = async (
userId: string,
chatId: string,
title: string,
data: object
): Promise<void> => {
try {
await convex.mutation(api.conversations.save, { userId, chatId, title, data });
} catch (e) {
console.error('[Convex] Failed to sync conversation:', e);
}
};
export const loadConversations = async (userId: string): Promise<object[]> => {
try {
return await convex.query(api.conversations.list, { userId });
} catch (e) {
console.error('[Convex] Failed to load conversations:', e);
return [];
}
};
export const removeConversation = async (chatId: string): Promise<void> => {
try {
await convex.mutation(api.conversations.remove, { chatId });
} catch (e) {
console.error('[Convex] Failed to remove conversation:', e);
}
};
// βββ Connections ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const syncConnections = async (userId: string, data: object): Promise<void> => {
try {
await convex.mutation(api.connections.save, { userId, data });
} catch (e) {
console.error('[Convex] Failed to sync connections:', e);
}
};
export const loadConnections = async (userId: string): Promise<object | null> => {
try {
const doc = await convex.query(api.connections.get, { userId });
return doc?.data ?? null;
} catch (e) {
console.error('[Convex] Failed to load connections:', e);
return null;
}
};
|