@better-i18n/schemas 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,240 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * Schema for listing translation keys.
5
- */
6
- export const listTranslationKeysSchema = z.object({
7
- projectId: z.string().uuid(),
8
- page: z.number().min(1).default(1),
9
- limit: z.number().min(1).max(5000).default(30),
10
- search: z.string().optional(),
11
- languageCodes: z.array(z.string()).optional(),
12
- namespaces: z.array(z.string()).optional(),
13
- });
14
-
15
- /**
16
- * Schema for getting a specific translation key.
17
- */
18
- export const getTranslationKeySchema = z.object({
19
- keyId: z.string().uuid(),
20
- });
21
-
22
- /**
23
- * Schema for creating a translation key.
24
- */
25
- export const createTranslationKeySchema = z.object({
26
- projectId: z.string().uuid(),
27
- key: z.string().min(1),
28
- sourceValue: z.string().optional(),
29
- description: z.string().optional(),
30
- context: z.string().optional(),
31
- maxLength: z.number().positive().optional(),
32
- });
33
-
34
- /**
35
- * Schema for updating a translation key.
36
- */
37
- export const updateTranslationKeySchema = z.object({
38
- keyId: z.string().uuid(),
39
- key: z.string().min(1).optional(),
40
- description: z.string().optional(),
41
- context: z.string().optional(),
42
- maxLength: z.number().positive().optional(),
43
- });
44
-
45
- /**
46
- * Schema for deleting a translation key.
47
- */
48
- export const deleteTranslationKeySchema = z.object({
49
- keyId: z.string().uuid(),
50
- });
51
-
52
- /**
53
- * Schema for updating a translation.
54
- * Supports both target language translations and source language edits.
55
- */
56
- export const updateTranslationSchema = z.object({
57
- keyId: z.string().uuid(),
58
- languageCode: z.string().min(1),
59
- value: z.string(),
60
- status: z
61
- .enum([
62
- "draft",
63
- "pending",
64
- "needs_review",
65
- "reviewed",
66
- "approved",
67
- "ai_generated",
68
- ])
69
- .default("approved"), // ✅ Updated status model
70
- // Source language editing fields
71
- isSourceLanguage: z.boolean().optional().default(false),
72
- reason: z.string().optional(), // For audit trail: why source was edited
73
- });
74
-
75
- /**
76
- * Schema for bulk updating translations.
77
- * Allows updating multiple translations in a single request.
78
- */
79
- export const bulkUpdateTranslationsSchema = z.object({
80
- projectId: z.string().uuid(),
81
- translations: z
82
- .array(
83
- z.object({
84
- keyId: z.string().uuid(),
85
- languageCode: z.string().min(1),
86
- value: z.string(),
87
- status: z
88
- .enum([
89
- "draft",
90
- "pending",
91
- "needs_review",
92
- "reviewed",
93
- "approved",
94
- "ai_generated",
95
- ])
96
- .default("approved"),
97
- // Source language editing: when true, updates translationKey.sourceText instead of translation table
98
- isSourceLanguage: z.boolean().optional().default(false),
99
- }),
100
- )
101
- .min(1),
102
- });
103
-
104
- /**
105
- * Types for translation operations.
106
- */
107
- export type ListTranslationKeysInput = z.infer<
108
- typeof listTranslationKeysSchema
109
- >;
110
- export type GetTranslationKeyInput = z.infer<typeof getTranslationKeySchema>;
111
- export type CreateTranslationKeyInput = z.infer<
112
- typeof createTranslationKeySchema
113
- >;
114
- export type UpdateTranslationKeyInput = z.infer<
115
- typeof updateTranslationKeySchema
116
- >;
117
- export type DeleteTranslationKeyInput = z.infer<
118
- typeof deleteTranslationKeySchema
119
- >;
120
- export type UpdateTranslationInput = z.infer<typeof updateTranslationSchema>;
121
- export type BulkUpdateTranslationsInput = z.infer<
122
- typeof bulkUpdateTranslationsSchema
123
- >;
124
-
125
- /**
126
- * Schema for generating AI translation suggestion.
127
- */
128
- export const generateSuggestionSchema = z.object({
129
- keyId: z.string().uuid(),
130
- languageCode: z.string().min(1),
131
- model: z
132
- .enum([
133
- "gemini-2.5-pro",
134
- "gemini-2.5-flash",
135
- "gemini-2.5-flash-lite",
136
- "gemini-2.5-flash-lite-preview-06-17",
137
- "gemini-2.0-flash",
138
- ])
139
- .default("gemini-2.5-flash"),
140
- });
141
-
142
- /**
143
- * Schema for AI suggestion (simplified, uses project system prompt).
144
- */
145
- export const aiSuggestSchema = z.object({
146
- keyId: z.string().uuid(),
147
- sourceText: z.string(),
148
- targetLanguage: z.string().min(1),
149
- projectId: z.string().uuid(),
150
- });
151
-
152
- /**
153
- * Schema for publishing translations (changing status from draft to approved).
154
- */
155
- export const publishTranslationsSchema = z.object({
156
- projectId: z.string().uuid(),
157
- translations: z
158
- .array(
159
- z.object({
160
- keyId: z.string().uuid(),
161
- languageCode: z.string().min(1),
162
- }),
163
- )
164
- .min(1),
165
- });
166
-
167
- /**
168
- * Schema for batch sync of translations.
169
- */
170
- export const batchSyncTranslationsSchema = z.object({
171
- projectId: z.string().uuid(),
172
- translations: z
173
- .array(
174
- z.object({
175
- keyId: z.string().uuid(),
176
- languageCode: z.string().min(1),
177
- value: z.string(),
178
- baselineValue: z.string(), // Original value when loaded
179
- status: z
180
- .enum(["pending", "reviewed", "approved", "conflict", "synced"])
181
- .default("pending"),
182
- lastModified: z.string().datetime(), // ISO string
183
- }),
184
- )
185
- .min(1),
186
- createBaseline: z.boolean().default(true), // Whether to create new baseline after sync
187
- });
188
-
189
- /**
190
- * Schema for conflict detection.
191
- */
192
- export const detectConflictsSchema = z.object({
193
- projectId: z.string().uuid(),
194
- translations: z
195
- .array(
196
- z.object({
197
- keyId: z.string().uuid(),
198
- languageCode: z.string().min(1),
199
- value: z.string(),
200
- baselineValue: z.string(),
201
- lastModified: z.string().datetime(),
202
- }),
203
- )
204
- .optional(), // Optional - if not provided, will fetch from server
205
- });
206
-
207
- /**
208
- * Schema for resolving conflicts.
209
- */
210
- export const resolveConflictsSchema = z.object({
211
- projectId: z.string().uuid(),
212
- resolutions: z.array(
213
- z.object({
214
- keyId: z.string().uuid(),
215
- languageCode: z.string().min(1),
216
- resolution: z.enum(["local", "server", "merged"]),
217
- mergedValue: z.string().optional(), // Required if resolution is "merged"
218
- }),
219
- ),
220
- });
221
-
222
- /**
223
- * Schema for getting translation health statistics.
224
- */
225
- export const getHealthStatsSchema = z.object({
226
- projectId: z.string().uuid(),
227
- repositoryId: z.string().uuid().optional(),
228
- });
229
-
230
- export type GenerateSuggestionInput = z.infer<typeof generateSuggestionSchema>;
231
- export type AiSuggestInput = z.infer<typeof aiSuggestSchema>;
232
- export type PublishTranslationsInput = z.infer<
233
- typeof publishTranslationsSchema
234
- >;
235
- export type BatchSyncTranslationsInput = z.infer<
236
- typeof batchSyncTranslationsSchema
237
- >;
238
- export type DetectConflictsInput = z.infer<typeof detectConflictsSchema>;
239
- export type ResolveConflictsInput = z.infer<typeof resolveConflictsSchema>;
240
- export type GetHealthStatsInput = z.infer<typeof getHealthStatsSchema>;