@zodic/shared 0.0.296 → 0.0.297

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.
@@ -289,15 +289,11 @@ export class ArchetypeService {
289
289
  combination: string,
290
290
  overrideExisting: boolean = false
291
291
  ) {
292
+ const db = this.context.drizzle();
292
293
  const [sun, ascendant, moon] = combination.split('-') as ZodiacSignSlug[];
293
294
 
294
295
  const prompt = generateArchetypePrompt([{ sun, ascendant, moon }]);
295
- const messages: ChatMessages = [
296
- {
297
- role: 'user',
298
- content: prompt,
299
- },
300
- ];
296
+ const messages: ChatMessages = [{ role: 'user', content: prompt }];
301
297
  const response = await this.context.api().callTogether.single(messages, {});
302
298
 
303
299
  if (!response) {
@@ -306,17 +302,33 @@ export class ArchetypeService {
306
302
  );
307
303
  }
308
304
 
309
- const blocks = response
310
- .split('-EN')[1]
311
- .split('-PT')[0]
312
- .trim()
313
- .split(/\n\d\.\s*\n?/)
314
- .filter(Boolean);
315
- const ptBlocks = response
316
- .split('-PT')[1]
317
- .trim()
318
- .split(/\n\d\.\s*\n?/)
319
- .filter(Boolean);
305
+ let blocks: string[] = [];
306
+ let ptBlocks: string[] = [];
307
+
308
+ try {
309
+ blocks = response
310
+ .split('-EN')[1]
311
+ .split('-PT')[0]
312
+ .trim()
313
+ .split(/\n\d\.\s*\n?/)
314
+ .filter(Boolean);
315
+
316
+ ptBlocks = response
317
+ .split('-PT')[1]
318
+ .trim()
319
+ .split(/\n\d\.\s*\n?/)
320
+ .filter(Boolean);
321
+ } catch (err) {
322
+ console.error(`Parsing failed for combination: ${combination}`, err);
323
+ await db.insert(schema.archetypeNameDumps).values({
324
+ id: combination,
325
+ combination,
326
+ rawText: response,
327
+ parsedSuccessfully: 0,
328
+ createdAt: Date.now(),
329
+ });
330
+ return;
331
+ }
320
332
 
321
333
  const englishNames = blocks.map((block) => {
322
334
  const nameMatch = block.match(/• Name:\s*(.+)/);
@@ -334,16 +346,37 @@ export class ArchetypeService {
334
346
  return { masc, fem, essenceLine: essence };
335
347
  });
336
348
 
337
- const db = this.context.drizzle();
349
+ // Duplicate helper
350
+ async function isEnglishNameDuplicate(name: string): Promise<boolean> {
351
+ const result = await db
352
+ .select({ name: schema.archetypesData.name })
353
+ .from(schema.archetypesData)
354
+ .where(
355
+ and(
356
+ eq(schema.archetypesData.language, 'en-us'),
357
+ eq(schema.archetypesData.name, name)
358
+ )
359
+ )
360
+ .limit(1)
361
+ .execute();
362
+
363
+ return result.length > 0;
364
+ }
338
365
 
339
366
  await Promise.all(
340
367
  englishNames.map(async (entry, i) => {
341
368
  const index = (i + 1).toString();
342
369
  const ptVariant = portugueseVariants[i];
343
370
 
371
+ if (await isEnglishNameDuplicate(entry.name)) {
372
+ console.warn(`Duplicate name detected: "${entry.name}" — skipping.`);
373
+ return;
374
+ }
375
+
344
376
  for (const gender of ['male', 'female']) {
345
377
  const enId = `${combination}:${gender}:${index}`;
346
378
  const ptId = `${combination}:${gender}:${index}:pt`;
379
+ const ptName = gender === 'female' ? ptVariant.fem : ptVariant.masc;
347
380
 
348
381
  const existingEn = await db
349
382
  .select({ id: schema.archetypesData.id })
@@ -374,8 +407,6 @@ export class ArchetypeService {
374
407
  });
375
408
  }
376
409
 
377
- const ptName = gender === 'female' ? ptVariant.fem : ptVariant.masc;
378
-
379
410
  const existingPt = await db
380
411
  .select({ id: schema.archetypesData.id })
381
412
  .from(schema.archetypesData)
@@ -0,0 +1,7 @@
1
+ CREATE TABLE `archetype_name_dumps` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `combination` text NOT NULL,
4
+ `raw_text` text NOT NULL,
5
+ `parsed_successfully` integer DEFAULT 0,
6
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP
7
+ );