@zodic/shared 0.0.297 → 0.0.298

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,4 +1,4 @@
1
- import { eq } from 'drizzle-orm';
1
+ import { and, eq } from 'drizzle-orm';
2
2
  import { inject, injectable } from 'inversify';
3
3
  import { ChatMessages, schema } from '../..';
4
4
  import { KVArchetype, ZodiacSignSlug } from '../../types/scopes/legacy';
@@ -444,6 +444,8 @@ export class ArchetypeService {
444
444
  entries: Array<{ combination: string }>,
445
445
  overrideExisting: boolean = false
446
446
  ) {
447
+ const db = this.context.drizzle();
448
+
447
449
  const prompts = entries.map(({ combination }) => {
448
450
  const [sun, ascendant, moon] = combination.split('-') as ZodiacSignSlug[];
449
451
  return { sun, ascendant, moon };
@@ -457,18 +459,47 @@ export class ArchetypeService {
457
459
  throw new Error('No response when generating batch archetype names');
458
460
  }
459
461
 
460
- const db = this.context.drizzle();
461
-
462
462
  const blocks = response
463
463
  .split(/Composition \d+/)
464
464
  .slice(1)
465
465
  .map((b) => b.trim());
466
466
 
467
+ async function isEnglishNameDuplicate(name: string): Promise<boolean> {
468
+ const result = await db
469
+ .select({ name: schema.archetypesData.name })
470
+ .from(schema.archetypesData)
471
+ .where(
472
+ and(
473
+ eq(schema.archetypesData.language, 'en-us'),
474
+ eq(schema.archetypesData.name, name)
475
+ )
476
+ )
477
+ .limit(1)
478
+ .execute();
479
+
480
+ return result.length > 0;
481
+ }
482
+
467
483
  for (let i = 0; i < entries.length; i++) {
468
484
  const { combination } = entries[i];
469
485
  const block = blocks[i];
470
- const en = block.split('-EN')[1].split('-PT')[0].trim();
471
- const pt = block.split('-PT')[1].trim();
486
+
487
+ let en = '';
488
+ let pt = '';
489
+ try {
490
+ en = block.split('-EN')[1].split('-PT')[0].trim();
491
+ pt = block.split('-PT')[1].trim();
492
+ } catch (err) {
493
+ console.error(`Parsing failed for composition ${combination}`, err);
494
+ await db.insert(schema.archetypeNameDumps).values({
495
+ id: combination,
496
+ combination,
497
+ rawText: block,
498
+ parsedSuccessfully: 0,
499
+ createdAt: Date.now(),
500
+ });
501
+ continue;
502
+ }
472
503
 
473
504
  const english = en
474
505
  .split(/\n\d\.\s*\n?/)
@@ -492,6 +523,13 @@ export class ArchetypeService {
492
523
  const englishEntry = english[j];
493
524
  const ptEntry = portuguese[j];
494
525
 
526
+ if (await isEnglishNameDuplicate(englishEntry.name)) {
527
+ console.warn(
528
+ `Duplicate English name "${englishEntry.name}" — skipping.`
529
+ );
530
+ continue;
531
+ }
532
+
495
533
  for (const gender of ['male', 'female']) {
496
534
  const enId = `${combination}:${gender}:${index}`;
497
535
  const ptId = `${combination}:${gender}:${index}:pt`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.297",
3
+ "version": "0.0.298",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -38,6 +38,7 @@ export type CentralBindings = {
38
38
  AMULET_QUEUE: Queue;
39
39
  LANTERN_QUEUE: Queue;
40
40
  ORB_QUEUE: Queue;
41
+ ARCHETYPE_POPULATION_QUEUE: Queue;
41
42
 
42
43
  PROMPT_IMAGE_DESCRIBER: string;
43
44
  PROMPT_GENERATE_ARCHETYPE_BASIC_INFO: string;
@@ -136,6 +137,7 @@ export type BackendBindings = Env &
136
137
  | 'RING_QUEUE'
137
138
  | 'LANTERN_QUEUE'
138
139
  | 'ORB_QUEUE'
140
+ | 'ARCHETYPE_POPULATION_QUEUE'
139
141
  | 'KV_API_USAGE'
140
142
  | 'KV_CONCEPT_CACHE'
141
143
  | 'ENV'