@zodic/shared 0.0.306 → 0.0.307

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,3 +1,4 @@
1
+
1
2
  import { and, eq, sql } from 'drizzle-orm';
2
3
  import { inject, injectable } from 'inversify';
3
4
  import { ChatMessages, Composition, schema } from '../..';
@@ -312,44 +313,7 @@ export class ArchetypeService {
312
313
  return;
313
314
  }
314
315
 
315
- let blocks: string[] = [];
316
- let ptBlocks: string[] = [];
317
-
318
- try {
319
- blocks = response
320
- .split('-EN')[1]
321
- .split('-PT')[0]
322
- .trim()
323
- .split(/\n\d\.\s*\n?/)
324
- .filter(Boolean);
325
-
326
- ptBlocks = response
327
- .split('-PT')[1]
328
- .trim()
329
- .split(/\n\d\.\s*\n?/)
330
- .filter(Boolean);
331
- } catch (err) {
332
- console.error(`❌ [Single] Parsing failed for ${combination}`, err);
333
- await db.insert(schema.archetypeNameDumps).values({
334
- id: combination,
335
- combination,
336
- rawText: response,
337
- parsedSuccessfully: 0,
338
- createdAt: Date.now(),
339
- });
340
- return;
341
- }
342
-
343
- const englishNames = blocks.map((block) => ({
344
- name: block.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
345
- essenceLine: block.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
346
- }));
347
-
348
- const portugueseVariants = ptBlocks.map((block) => ({
349
- masc: block.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '',
350
- fem: block.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
351
- essenceLine: block.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
352
- }));
316
+ const { english: englishNames, portuguese: portugueseVariants } = this.parseArchetypeNameBlocks(response);
353
317
 
354
318
  async function isEnglishNameDuplicate(name: string): Promise<boolean> {
355
319
  const result = await db
@@ -483,39 +447,7 @@ export class ArchetypeService {
483
447
  const block = blocks[i];
484
448
  console.log(`📦 [Batch] Processing: ${combination}`);
485
449
 
486
- let en = '';
487
- let pt = '';
488
- try {
489
- en = block.split('-EN')[1].split('-PT')[0].trim();
490
- pt = block.split('-PT')[1].trim();
491
- } catch (err) {
492
- console.error(`❌ [Batch] Parsing failed for: ${combination}`, err);
493
- await db.insert(schema.archetypeNameDumps).values({
494
- id: combination,
495
- combination,
496
- rawText: block,
497
- parsedSuccessfully: 0,
498
- createdAt: Date.now(),
499
- });
500
- continue;
501
- }
502
-
503
- const english = en
504
- .split(/\n\d\.\s*\n?/)
505
- .filter(Boolean)
506
- .map((line) => ({
507
- name: line.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
508
- essenceLine: line.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
509
- }));
510
-
511
- const portuguese = pt
512
- .split(/\n\d\.\s*\n?/)
513
- .filter(Boolean)
514
- .map((line) => ({
515
- masc: line.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '',
516
- fem: line.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
517
- essenceLine: line.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
518
- }));
450
+ const { english, portuguese } = this.parseArchetypeNameBlocks(block);
519
451
 
520
452
  for (let j = 0; j < 3; j++) {
521
453
  const index = (j + 1).toString();
@@ -853,4 +785,52 @@ export class ArchetypeService {
853
785
 
854
786
  return compositions;
855
787
  }
788
+
789
+ private parseArchetypeNameBlocks(block: string): {
790
+ english: { name: string; essenceLine: string }[];
791
+ portuguese: { masc: string; fem: string; essenceLine: string }[];
792
+ } {
793
+ const result = {
794
+ english: [] as { name: string; essenceLine: string }[],
795
+ portuguese: [] as { masc: string; fem: string; essenceLine: string }[],
796
+ };
797
+
798
+ try {
799
+ const enMatch = block.match(/-EN[\s\S]*?-PT/);
800
+ const ptMatch = block.match(/-PT[\s\S]*/);
801
+
802
+ const enBlock = enMatch?.[0].replace(/-EN/, '').replace(/-PT/, '').trim() ?? '';
803
+ const ptBlock = ptMatch?.[0].replace(/-PT/, '').trim() ?? '';
804
+
805
+ result.english = enBlock
806
+ .split(/\n\d\.\s*\n?/)
807
+ .filter(Boolean)
808
+ .map((entry, i) => {
809
+ const name = entry.match(/• Name:\s*(.+)/)?.[1]?.trim() ?? '';
810
+ const essenceLine = entry.match(/• Essence:\s*(.+)/)?.[1]?.trim() ?? '';
811
+ if (!name || !essenceLine) {
812
+ console.warn(`⚠️ [Parse] Incomplete English entry ${i + 1}:`, entry);
813
+ }
814
+ return { name, essenceLine };
815
+ });
816
+
817
+ result.portuguese = ptBlock
818
+ .split(/\n\d\.\s*\n?/)
819
+ .filter(Boolean)
820
+ .map((entry, i) => {
821
+ const masc = entry.match(/• Masculino:\s*(.+)/)?.[1]?.trim() ?? '';
822
+ const fem = entry.match(/• Feminino:\s*(.+)/)?.[1]?.trim() ?? '';
823
+ const essenceLine = entry.match(/• Essência:\s*(.+)/)?.[1]?.trim() ?? '';
824
+ if (!masc || !fem || !essenceLine) {
825
+ console.warn(`⚠️ [Parse] Incomplete Portuguese entry ${i + 1}:`, entry);
826
+ }
827
+ return { masc, fem, essenceLine };
828
+ });
829
+
830
+ } catch (error) {
831
+ console.error('❌ [Parse] Failed to parse block:', error);
832
+ }
833
+
834
+ return result;
835
+ }
856
836
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.306",
3
+ "version": "0.0.307",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {