@zodic/shared 0.0.310 → 0.0.312

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.
@@ -733,28 +733,26 @@ export class ArchetypeService {
733
733
  );
734
734
  }
735
735
 
736
- async recycleArchetypeNameDumpsBatch(
737
- compositions: Composition[]
738
- ): Promise<void> {
736
+ async recycleArchetypeNameDumpsBatch(compositions: Composition[]): Promise<void> {
739
737
  console.log('🔁 [Recycle] Starting recycling of archetype name dumps');
740
-
738
+
741
739
  if (compositions.length === 0) {
742
740
  console.log('✅ [Recycle] No compositions provided for recycling');
743
741
  return;
744
742
  }
745
-
743
+
746
744
  console.log(
747
745
  `📦 [Recycle] Total compositions to recycle: ${compositions.length}`
748
746
  );
749
-
747
+
750
748
  // Step 1: Process each composition
751
749
  const db = this.context.drizzle();
752
750
  for (const comp of compositions) {
753
751
  const combination = [comp.sun, comp.ascendant, comp.moon].join('-');
754
752
  const indexes = comp.indexesToGenerate ?? [1, 2, 3];
755
-
756
- console.log(`🔄 [Recycle] Processing: ${combination}`);
757
-
753
+
754
+ console.log(`🔄 [Recycle] Processing combination: ${combination} with indexes: [${indexes.join(', ')}]`);
755
+
758
756
  // Fetch all dump entries for this combination
759
757
  const dumpEntries = await db
760
758
  .select({
@@ -764,37 +762,50 @@ export class ArchetypeService {
764
762
  .from(schema.archetypeNameDumps)
765
763
  .where(eq(schema.archetypeNameDumps.combination, combination))
766
764
  .execute();
767
-
765
+
766
+ console.log(
767
+ `[Recycle] Retrieved ${dumpEntries.length} dump entries for ${combination}: ${JSON.stringify(dumpEntries, null, 2)}`
768
+ );
769
+
768
770
  if (dumpEntries.length === 0) {
769
771
  console.log(
770
772
  `⚠️ [Recycle] No dump entries found for combination: ${combination}`
771
773
  );
772
774
  continue;
773
775
  }
774
-
776
+
775
777
  // Step 2: Process each missing index
776
778
  for (const index of indexes) {
779
+ console.log(`[Recycle] Processing index ${index} for ${combination}`);
780
+
777
781
  // Find a dump entry that contains the specific index
778
782
  let rawText: string | null = null;
783
+ let selectedEntryId: string | null = null;
779
784
  for (const entry of dumpEntries) {
780
- if (entry.rawText.includes(`-EN ${index}.`)) {
785
+ if (entry.rawText && entry.rawText.includes(`-EN ${index}.`)) {
781
786
  rawText = entry.rawText;
787
+ selectedEntryId = entry.id;
788
+ console.log(
789
+ `[Recycle] Selected dump entry for index ${index} with id ${selectedEntryId}: ${rawText}`
790
+ );
782
791
  break;
783
792
  }
784
793
  }
785
-
794
+
786
795
  if (!rawText) {
787
796
  console.log(
788
797
  `⚠️ [Recycle] No dump entry contains index ${index} for combination: ${combination}`
789
798
  );
790
799
  continue;
791
800
  }
792
-
801
+
793
802
  // Clean up the raw text
803
+ console.log(`[Recycle] Cleaning rawText for index ${index}: ${rawText}`);
794
804
  const cleanedText = rawText
795
805
  .replace(/###|---\s*###|-\s*###/g, '')
796
806
  .trim();
797
-
807
+ console.log(`[Recycle] Cleaned text for index ${index}: ${cleanedText}`);
808
+
798
809
  // Extract the specific index sections
799
810
  const enSectionMatch = cleanedText.match(
800
811
  new RegExp(`-EN ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
@@ -802,45 +813,77 @@ export class ArchetypeService {
802
813
  const ptSectionMatch = cleanedText.match(
803
814
  new RegExp(`-PT ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
804
815
  );
805
-
806
- if (!enSectionMatch || !ptSectionMatch) {
816
+
817
+ console.log(
818
+ `[Recycle] Extracted sections for index ${index} - enSectionMatch: ${JSON.stringify(enSectionMatch)}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
819
+ );
820
+
821
+ if (!enSectionMatch || !ptSectionMatch || !enSectionMatch[0] || !ptSectionMatch[0]) {
807
822
  console.log(
808
- `⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}`
823
+ `⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}. enSectionMatch: ${JSON.stringify(enSectionMatch)}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
809
824
  );
810
825
  continue;
811
826
  }
812
-
827
+
813
828
  // Combine the extracted sections into a block for parsing
814
- const block = `-EN\n${enSectionMatch[0]
815
- .replace(/-EN\s*/, '')
816
- .trim()}\n\n-PT\n${ptSectionMatch[0].replace(/-PT\s*/, '').trim()}`;
817
-
829
+ const block = `-EN\n${enSectionMatch[0].replace(/-EN\s*/, '').trim()}\n\n-PT\n${ptSectionMatch[0].replace(/-PT\s*/, '').trim()}`;
830
+ console.log(`[Recycle] Constructed block for index ${index}: ${block}`);
831
+
818
832
  // Step 3: Parse the block
819
833
  const { english, portuguese } = this.parseArchetypeNameBlocks(block);
820
-
834
+ console.log(
835
+ `[Recycle] Parsed results for index ${index} - English: ${JSON.stringify(english, null, 2)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
836
+ );
837
+
821
838
  if (english.length === 0 || portuguese.length === 0) {
822
839
  console.error(
823
- `❌ [Recycle] Parsing failed for index ${index} of combination: ${combination}`
840
+ `❌ [Recycle] Parsing failed for index ${index} of combination: ${combination}. Block: ${block}`
824
841
  );
842
+ if (block) {
843
+ await this.context
844
+ .drizzle()
845
+ .insert(schema.archetypeNameDumps)
846
+ .values({
847
+ id: `${combination}:${index}:${Date.now()}`,
848
+ combination,
849
+ rawText: block,
850
+ parsedSuccessfully: 0,
851
+ createdAt: Date.now(),
852
+ });
853
+ console.log(
854
+ `[Recycle] Logged failed parse to archetype_name_dumps for index ${index} of ${combination}`
855
+ );
856
+ } else {
857
+ console.error(
858
+ `❌ [Recycle] Cannot log failed parse to archetype_name_dumps: block is undefined`
859
+ );
860
+ }
825
861
  continue;
826
862
  }
827
-
863
+
828
864
  const englishEntry = english[0];
829
865
  const ptEntry = portuguese[0];
830
-
866
+
867
+ console.log(
868
+ `[Recycle] Extracted entries for index ${index} - englishEntry: ${JSON.stringify(englishEntry, null, 2)}, ptEntry: ${JSON.stringify(ptEntry, null, 2)}`
869
+ );
870
+
831
871
  if (!englishEntry || !ptEntry) {
832
872
  console.warn(
833
- `⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data`
873
+ `⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data. englishEntry: ${JSON.stringify(englishEntry)}, ptEntry: ${JSON.stringify(ptEntry)}`
834
874
  );
835
875
  continue;
836
876
  }
837
-
877
+
838
878
  // Step 4: Insert the parsed data into archetypes_data
839
879
  for (const gender of ['male', 'female']) {
840
880
  const enId = `${combination}:${gender}:${index}`;
841
881
  const ptId = `${combination}:${gender}:${index}:pt`;
842
882
  const ptName = gender === 'female' ? ptEntry.fem : ptEntry.masc;
843
-
883
+
884
+ console.log(
885
+ `[Recycle] Inserting English entry for ${combination}, index ${index}, gender ${gender}: id=${enId}, name=${englishEntry.name}, essenceLine=${englishEntry.essenceLine}`
886
+ );
844
887
  await this.context
845
888
  .drizzle()
846
889
  .insert(schema.archetypesData)
@@ -862,7 +905,10 @@ export class ArchetypeService {
862
905
  updatedAt: new Date().getTime(),
863
906
  },
864
907
  });
865
-
908
+
909
+ console.log(
910
+ `[Recycle] Inserting Portuguese entry for ${combination}, index ${index}, gender ${gender}: id=${ptId}, name=${ptName}, essenceLine=${ptEntry.essenceLine}`
911
+ );
866
912
  await this.context
867
913
  .drizzle()
868
914
  .insert(schema.archetypesData)
@@ -884,25 +930,33 @@ export class ArchetypeService {
884
930
  updatedAt: new Date().getTime(),
885
931
  },
886
932
  });
887
-
888
- await db
889
- .delete(schema.archetypeNameDumps)
890
- .where(
891
- eq(
892
- schema.archetypeNameDumps.id,
893
- dumpEntries.find((e) => e.rawText === rawText)?.id || ''
894
- )
933
+
934
+ // Delete the processed dump entry
935
+ if (selectedEntryId) {
936
+ console.log(
937
+ `[Recycle] Deleting dump entry with id ${selectedEntryId} for ${combination}, index ${index}`
895
938
  );
896
-
939
+ await db
940
+ .delete(schema.archetypeNameDumps)
941
+ .where(eq(schema.archetypeNameDumps.id, selectedEntryId));
942
+ console.log(
943
+ `[Recycle] Successfully deleted dump entry with id ${selectedEntryId}`
944
+ );
945
+ } else {
946
+ console.warn(
947
+ `[Recycle] Could not delete dump entry for ${combination}, index ${index}: selectedEntryId is null`
948
+ );
949
+ }
950
+
897
951
  console.log(
898
952
  `✅ [Recycle] Saved archetype ${index} (${gender}) for ${combination}`
899
953
  );
900
954
  }
901
955
  }
902
-
956
+
903
957
  console.log(`🏁 [Recycle] Finished combination: ${combination}`);
904
958
  }
905
-
959
+
906
960
  console.log(
907
961
  `🎉 [Recycle] Completed recycling for ${compositions.length} combinations`
908
962
  );
@@ -963,77 +1017,100 @@ export class ArchetypeService {
963
1017
  return compositions;
964
1018
  }
965
1019
 
966
- private parseArchetypeNameBlocks(block: string): {
967
- english: { name: string; essenceLine: string }[];
968
- portuguese: { masc: string; fem: string; essenceLine: string }[];
1020
+ parseArchetypeNameBlocks(block: string): {
1021
+ english: any[];
1022
+ portuguese: any[];
969
1023
  } {
970
- const result = {
971
- english: [] as { name: string; essenceLine: string }[],
972
- portuguese: [] as { masc: string; fem: string; essenceLine: string }[],
973
- };
974
-
975
- try {
976
- // Normalize the block by replacing multiple spaces with a single space and ensuring newlines
977
- const normalizedBlock = block
978
- .replace(/\s+/g, ' ')
979
- .replace(/-EN\s*/, '-EN\n')
980
- .replace(/-PT\s*/, '\n-PT\n')
981
- .trim();
982
-
983
- // Split into EN and PT sections
984
- const sections = normalizedBlock.split(/\n?-PT\n/);
985
- const enSection = sections[0]?.replace(/-EN\n/, '').trim() ?? '';
986
- const ptSection = sections[1]?.trim() ?? '';
987
-
988
- // Parse English entries
989
- result.english = enSection
990
- .split(/\n?\d+\.\s*\n?/)
991
- .filter(Boolean)
992
- .map((entry, i) => {
993
- const nameMatch = entry.match(/• Name:\s*([^•]+)/);
994
- const essenceMatch = entry.match(/• Essence:\s*([^•]+)/);
995
- const name = nameMatch?.[1]?.trim() ?? '';
996
- const essenceLine = essenceMatch?.[1]?.trim() ?? '';
997
- if (!name || !essenceLine) {
998
- console.warn(
999
- `⚠️ [Parse] Incomplete English entry ${i + 1}:`,
1000
- entry
1001
- );
1002
- }
1003
- return { name, essenceLine };
1004
- });
1005
-
1006
- // Parse Portuguese entries
1007
- result.portuguese = ptSection
1008
- .split(/\n?\d+\.\s*\n?/)
1009
- .filter(Boolean)
1010
- .map((entry, i) => {
1011
- const mascMatch = entry.match(/• Masculino:\s*([^•]+)/);
1012
- const femMatch = entry.match(/• Feminino:\s*([^•]+)/);
1013
- const essenceMatch = entry.match(/• Essência:\s*([^•]+)/);
1014
- const masc = mascMatch?.[1]?.trim() ?? '';
1015
- const fem = femMatch?.[1]?.trim() ?? '';
1016
- const essenceLine = essenceMatch?.[1]?.trim() ?? '';
1017
- if (!masc || !fem || !essenceLine) {
1018
- console.warn(
1019
- `⚠️ [Parse] Incomplete Portuguese entry ${i + 1}:`,
1020
- entry
1021
- );
1022
- }
1023
- // Validate gender consistency
1024
- if (masc.startsWith('A ') && fem.startsWith('O ')) {
1025
- console.warn(
1026
- `⚠️ [Parse] Gender mismatch in Portuguese entry ${i + 1}:`,
1027
- entry
1028
- );
1029
- return { masc: fem, fem: masc, essenceLine }; // Swap to correct the mismatch
1030
- }
1031
- return { masc, fem, essenceLine };
1032
- });
1033
- } catch (error) {
1034
- console.error('❌ [Parse] Failed to parse block:', error);
1024
+ console.log(`[Parse] Starting parsing of block: ${block}`);
1025
+
1026
+ const sections = block.split(/^-EN|^-PT/m).filter((s) => s.trim());
1027
+ console.log(
1028
+ `[Parse] Split block into ${sections.length} sections: ${JSON.stringify(sections, null, 2)}`
1029
+ );
1030
+
1031
+ const english: any[] = [];
1032
+ const portuguese: any[] = [];
1033
+
1034
+ for (const section of sections) {
1035
+ console.log(`[Parse] Processing section: ${section}`);
1036
+
1037
+ if (section.startsWith('EN')) {
1038
+ const lines = section.split('\n').filter((l) => l.trim());
1039
+ console.log(
1040
+ `[Parse] Extracted ${lines.length} lines from English section: ${JSON.stringify(lines, null, 2)}`
1041
+ );
1042
+
1043
+ const nameMatch = lines
1044
+ .find((l) => l.includes('• Name:'))
1045
+ ?.split('• Name:')[1]
1046
+ ?.trim();
1047
+ console.log(`[Parse] English nameMatch: ${nameMatch}`);
1048
+
1049
+ const essenceMatch = lines
1050
+ .find((l) => l.includes('• Essence:'))
1051
+ ?.split('• Essence:')[1]
1052
+ ?.trim();
1053
+ console.log(`[Parse] English essenceMatch: ${essenceMatch}`);
1054
+
1055
+ if (nameMatch && essenceMatch) {
1056
+ const entry = { name: nameMatch, essenceLine: essenceMatch };
1057
+ english.push(entry);
1058
+ console.log(
1059
+ `[Parse] Added English entry: ${JSON.stringify(entry, null, 2)}`
1060
+ );
1061
+ } else {
1062
+ console.warn(
1063
+ `[Parse] Skipping English section due to missing fields. nameMatch: ${nameMatch}, essenceMatch: ${essenceMatch}`
1064
+ );
1065
+ }
1066
+ } else if (section.startsWith('PT')) {
1067
+ const lines = section.split('\n').filter((l) => l.trim());
1068
+ console.log(
1069
+ `[Parse] Extracted ${lines.length} lines from Portuguese section: ${JSON.stringify(lines, null, 2)}`
1070
+ );
1071
+
1072
+ const mascMatch = lines
1073
+ .find((l) => l.includes('• Masculino:'))
1074
+ ?.split('• Masculino:')[1]
1075
+ ?.trim();
1076
+ console.log(`[Parse] Portuguese mascMatch: ${mascMatch}`);
1077
+
1078
+ const femMatch = lines
1079
+ .find((l) => l.includes('• Feminino:'))
1080
+ ?.split('• Feminino:')[1]
1081
+ ?.trim();
1082
+ console.log(`[Parse] Portuguese femMatch: ${femMatch}`);
1083
+
1084
+ const essenceMatch = lines
1085
+ .find((l) => l.includes('• Essência:'))
1086
+ ?.split('• Essência:')[1]
1087
+ ?.trim();
1088
+ console.log(`[Parse] Portuguese essenceMatch: ${essenceMatch}`);
1089
+
1090
+ if (mascMatch && femMatch && essenceMatch) {
1091
+ const entry = {
1092
+ masc: mascMatch,
1093
+ fem: femMatch,
1094
+ essenceLine: essenceMatch,
1095
+ };
1096
+ portuguese.push(entry);
1097
+ console.log(
1098
+ `[Parse] Added Portuguese entry: ${JSON.stringify(entry, null, 2)}`
1099
+ );
1100
+ } else {
1101
+ console.warn(
1102
+ `[Parse] Skipping Portuguese section due to missing fields. mascMatch: ${mascMatch}, femMatch: ${femMatch}, essenceMatch: ${essenceMatch}`
1103
+ );
1104
+ }
1105
+ } else {
1106
+ console.warn(`[Parse] Unrecognized section: ${section}`);
1107
+ }
1035
1108
  }
1036
-
1037
- return result;
1109
+
1110
+ console.log(
1111
+ `[Parse] Final parsed results - English: ${JSON.stringify(english, null, 2)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
1112
+ );
1113
+
1114
+ return { english, portuguese };
1038
1115
  }
1039
1116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.310",
3
+ "version": "0.0.312",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {