Skip to content

Commit 14c6fdb

Browse files
committed
unify store schema into one
1 parent 111bed9 commit 14c6fdb

File tree

4 files changed

+71
-89
lines changed

4 files changed

+71
-89
lines changed

packages/store/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"main": "./src/index.ts",
77
"exports": {
88
".": "./src/index.ts",
9-
"./schema-external": "./src/schema-external.ts",
10-
"./schema-internal": "./src/schema-internal.ts",
9+
"./schema": "./src/schema.ts",
1110
"./shared": "./src/shared.ts"
1211
},
1312
"types": "./src/index.ts",

packages/store/src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import type { TablesSchema, ValuesSchema } from "tinybase/with-schemas";
22

3-
import { externalTableSchemaForTinybase } from "./schema-external";
4-
import { internalSchemaForTinybase } from "./schema-internal";
3+
import { tableSchemaForTinybase, valueSchemaForTinybase } from "./schema";
54

6-
export * from "./schema-external";
7-
export * from "./schema-internal";
5+
export * from "./schema";
86
export * from "./shared";
97

108
export const SCHEMA = {
119
value: {
12-
...internalSchemaForTinybase.value,
10+
...valueSchemaForTinybase,
1311
} satisfies ValuesSchema,
1412
table: {
15-
...externalTableSchemaForTinybase,
16-
...internalSchemaForTinybase.table,
13+
...tableSchemaForTinybase,
1714
} satisfies TablesSchema,
1815
} as const;
1916

packages/store/src/schema-internal.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,39 @@ export const providerSpeakerIndexSchema = z.object({
206206
channel: z.number().optional(),
207207
});
208208

209+
export const generalSchema = z.object({
210+
user_id: z.string(),
211+
autostart: z.boolean().default(false),
212+
telemetry_consent: z.boolean().default(true),
213+
save_recordings: z.boolean().default(true),
214+
notification_event: z.boolean().default(true),
215+
notification_detect: z.boolean().default(true),
216+
respect_dnd: z.boolean().default(false),
217+
quit_intercept: z.boolean().default(false),
218+
ai_language: z.string().default("en"),
219+
spoken_languages: jsonObject(z.array(z.string()).default(["en"])),
220+
ignored_platforms: jsonObject(z.array(z.string()).default([])),
221+
ignored_recurring_series: jsonObject(z.array(z.string()).default([])),
222+
current_llm_provider: z.string().optional(),
223+
current_llm_model: z.string().optional(),
224+
current_stt_provider: z.string().optional(),
225+
current_stt_model: z.string().optional(),
226+
});
227+
228+
export const aiProviderSchema = z
229+
.object({
230+
type: z.enum(["stt", "llm"]),
231+
base_url: z.url().min(1),
232+
api_key: z.string(),
233+
})
234+
.refine(
235+
(data) => !data.base_url.startsWith("https:") || data.api_key.length > 0,
236+
{
237+
message: "API key is required for HTTPS URLs",
238+
path: ["api_key"],
239+
},
240+
);
241+
209242
export type ProviderSpeakerIndexHint = z.infer<
210243
typeof providerSpeakerIndexSchema
211244
>;
@@ -233,6 +266,8 @@ export type Memory = z.infer<typeof memorySchema>;
233266
export type ChatShortcut = z.infer<typeof chatShortcutSchema>;
234267
export type EnhancedNote = z.infer<typeof enhancedNoteSchema>;
235268
export type Prompt = z.infer<typeof promptSchema>;
269+
export type AIProvider = z.infer<typeof aiProviderSchema>;
270+
export type General = z.infer<typeof generalSchema>;
236271

237272
export type SessionStorage = ToStorageType<typeof sessionSchema>;
238273
export type TranscriptStorage = ToStorageType<typeof transcriptSchema>;
@@ -251,8 +286,10 @@ export type EventStorage = ToStorageType<typeof eventSchema>;
251286
export type MappingSessionParticipantStorage = ToStorageType<
252287
typeof mappingSessionParticipantSchema
253288
>;
289+
export type AIProviderStorage = ToStorageType<typeof aiProviderSchema>;
290+
export type GeneralStorage = ToStorageType<typeof generalSchema>;
254291

255-
export const externalTableSchemaForTinybase = {
292+
export const tableSchemaForTinybase = {
256293
folders: {
257294
user_id: { type: "string" },
258295
created_at: { type: "string" },
@@ -402,4 +439,32 @@ export const externalTableSchemaForTinybase = {
402439
title: { type: "string" },
403440
content: { type: "string" },
404441
} as const satisfies InferTinyBaseSchema<typeof chatShortcutSchema>,
442+
ai_providers: {
443+
type: { type: "string" },
444+
base_url: { type: "string" },
445+
api_key: { type: "string" },
446+
} as const satisfies InferTinyBaseSchema<typeof aiProviderSchema>,
447+
extension_state: {
448+
counter: { type: "number" },
449+
last_updated: { type: "string" },
450+
} as const,
405451
} as const satisfies TablesSchema;
452+
453+
export const valueSchemaForTinybase = {
454+
user_id: { type: "string" },
455+
autostart: { type: "boolean" },
456+
save_recordings: { type: "boolean" },
457+
notification_event: { type: "boolean" },
458+
notification_detect: { type: "boolean" },
459+
respect_dnd: { type: "boolean" },
460+
quit_intercept: { type: "boolean" },
461+
telemetry_consent: { type: "boolean" },
462+
ai_language: { type: "string" },
463+
spoken_languages: { type: "string" },
464+
ignored_platforms: { type: "string" },
465+
ignored_recurring_series: { type: "string" },
466+
current_llm_provider: { type: "string" },
467+
current_llm_model: { type: "string" },
468+
current_stt_provider: { type: "string" },
469+
current_stt_model: { type: "string" },
470+
} as const satisfies InferTinyBaseSchema<typeof generalSchema>;

0 commit comments

Comments
 (0)