@zodic/shared 0.0.311 → 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
  );
@@ -967,50 +1021,96 @@ export class ArchetypeService {
967
1021
  english: any[];
968
1022
  portuguese: any[];
969
1023
  } {
1024
+ console.log(`[Parse] Starting parsing of block: ${block}`);
1025
+
970
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
+
971
1031
  const english: any[] = [];
972
1032
  const portuguese: any[] = [];
973
-
1033
+
974
1034
  for (const section of sections) {
1035
+ console.log(`[Parse] Processing section: ${section}`);
1036
+
975
1037
  if (section.startsWith('EN')) {
976
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
+
977
1043
  const nameMatch = lines
978
1044
  .find((l) => l.includes('• Name:'))
979
1045
  ?.split('• Name:')[1]
980
1046
  ?.trim();
1047
+ console.log(`[Parse] English nameMatch: ${nameMatch}`);
1048
+
981
1049
  const essenceMatch = lines
982
1050
  .find((l) => l.includes('• Essence:'))
983
1051
  ?.split('• Essence:')[1]
984
1052
  ?.trim();
985
-
1053
+ console.log(`[Parse] English essenceMatch: ${essenceMatch}`);
1054
+
986
1055
  if (nameMatch && essenceMatch) {
987
- english.push({ name: nameMatch, essenceLine: 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
+ );
988
1065
  }
989
1066
  } else if (section.startsWith('PT')) {
990
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
+
991
1072
  const mascMatch = lines
992
1073
  .find((l) => l.includes('• Masculino:'))
993
1074
  ?.split('• Masculino:')[1]
994
1075
  ?.trim();
1076
+ console.log(`[Parse] Portuguese mascMatch: ${mascMatch}`);
1077
+
995
1078
  const femMatch = lines
996
1079
  .find((l) => l.includes('• Feminino:'))
997
1080
  ?.split('• Feminino:')[1]
998
1081
  ?.trim();
1082
+ console.log(`[Parse] Portuguese femMatch: ${femMatch}`);
1083
+
999
1084
  const essenceMatch = lines
1000
1085
  .find((l) => l.includes('• Essência:'))
1001
1086
  ?.split('• Essência:')[1]
1002
1087
  ?.trim();
1003
-
1088
+ console.log(`[Parse] Portuguese essenceMatch: ${essenceMatch}`);
1089
+
1004
1090
  if (mascMatch && femMatch && essenceMatch) {
1005
- portuguese.push({
1091
+ const entry = {
1006
1092
  masc: mascMatch,
1007
1093
  fem: femMatch,
1008
1094
  essenceLine: essenceMatch,
1009
- });
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
+ );
1010
1104
  }
1105
+ } else {
1106
+ console.warn(`[Parse] Unrecognized section: ${section}`);
1011
1107
  }
1012
1108
  }
1013
-
1109
+
1110
+ console.log(
1111
+ `[Parse] Final parsed results - English: ${JSON.stringify(english, null, 2)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
1112
+ );
1113
+
1014
1114
  return { english, portuguese };
1015
1115
  }
1016
1116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.311",
3
+ "version": "0.0.312",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {