@zodic/shared 0.0.312 → 0.0.313

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.
@@ -449,18 +449,36 @@ export class ArchetypeService {
449
449
 
450
450
  const { english, portuguese } = this.parseArchetypeNameBlocks(block);
451
451
 
452
+ // Check if parsing produced the expected number of entries
453
+ if (english.length !== 3 || portuguese.length !== 3) {
454
+ console.error(
455
+ `[Batch] Parsing failed for ${combination}. Expected 3 entries, got English: ${english.length}, Portuguese: ${portuguese.length}`
456
+ );
457
+ continue; // Skip this combination if parsing failed
458
+ }
459
+
452
460
  for (let j = 0; j < 3; j++) {
453
461
  const index = (j + 1).toString();
454
462
  const englishEntry = english[j];
455
463
  const ptEntry = portuguese[j];
456
464
 
457
- if (await isEnglishNameDuplicate(englishEntry.name)) {
465
+ // Skip if either entry is missing (shouldn't happen with the above check, but added for safety)
466
+ if (!englishEntry || !ptEntry) {
458
467
  console.warn(
459
- `⚠️ [Batch] Duplicate name skipped: ${englishEntry.name}`
468
+ `[Batch] Skipping index ${index} for ${combination} due to missing parsed data. English: ${JSON.stringify(
469
+ englishEntry
470
+ )}, Portuguese: ${JSON.stringify(ptEntry)}`
460
471
  );
461
472
  continue;
462
473
  }
463
474
 
475
+ // if (await isEnglishNameDuplicate(englishEntry.name)) {
476
+ // console.warn(
477
+ // `⚠️ [Batch] Duplicate name skipped: ${englishEntry.name}`
478
+ // );
479
+ // continue;
480
+ // }
481
+
464
482
  for (const gender of ['male', 'female']) {
465
483
  const enId = `${combination}:${gender}:${index}`;
466
484
  const ptId = `${combination}:${gender}:${index}:pt`;
@@ -733,26 +751,32 @@ export class ArchetypeService {
733
751
  );
734
752
  }
735
753
 
736
- async recycleArchetypeNameDumpsBatch(compositions: Composition[]): Promise<void> {
754
+ async recycleArchetypeNameDumpsBatch(
755
+ compositions: Composition[]
756
+ ): Promise<void> {
737
757
  console.log('🔁 [Recycle] Starting recycling of archetype name dumps');
738
-
758
+
739
759
  if (compositions.length === 0) {
740
760
  console.log('✅ [Recycle] No compositions provided for recycling');
741
761
  return;
742
762
  }
743
-
763
+
744
764
  console.log(
745
765
  `📦 [Recycle] Total compositions to recycle: ${compositions.length}`
746
766
  );
747
-
767
+
748
768
  // Step 1: Process each composition
749
769
  const db = this.context.drizzle();
750
770
  for (const comp of compositions) {
751
771
  const combination = [comp.sun, comp.ascendant, comp.moon].join('-');
752
772
  const indexes = comp.indexesToGenerate ?? [1, 2, 3];
753
-
754
- console.log(`🔄 [Recycle] Processing combination: ${combination} with indexes: [${indexes.join(', ')}]`);
755
-
773
+
774
+ console.log(
775
+ `🔄 [Recycle] Processing combination: ${combination} with indexes: [${indexes.join(
776
+ ', '
777
+ )}]`
778
+ );
779
+
756
780
  // Fetch all dump entries for this combination
757
781
  const dumpEntries = await db
758
782
  .select({
@@ -762,22 +786,28 @@ export class ArchetypeService {
762
786
  .from(schema.archetypeNameDumps)
763
787
  .where(eq(schema.archetypeNameDumps.combination, combination))
764
788
  .execute();
765
-
789
+
766
790
  console.log(
767
- `[Recycle] Retrieved ${dumpEntries.length} dump entries for ${combination}: ${JSON.stringify(dumpEntries, null, 2)}`
791
+ `[Recycle] Retrieved ${
792
+ dumpEntries.length
793
+ } dump entries for ${combination}: ${JSON.stringify(
794
+ dumpEntries,
795
+ null,
796
+ 2
797
+ )}`
768
798
  );
769
-
799
+
770
800
  if (dumpEntries.length === 0) {
771
801
  console.log(
772
802
  `⚠️ [Recycle] No dump entries found for combination: ${combination}`
773
803
  );
774
804
  continue;
775
805
  }
776
-
806
+
777
807
  // Step 2: Process each missing index
778
808
  for (const index of indexes) {
779
809
  console.log(`[Recycle] Processing index ${index} for ${combination}`);
780
-
810
+
781
811
  // Find a dump entry that contains the specific index
782
812
  let rawText: string | null = null;
783
813
  let selectedEntryId: string | null = null;
@@ -791,21 +821,25 @@ export class ArchetypeService {
791
821
  break;
792
822
  }
793
823
  }
794
-
824
+
795
825
  if (!rawText) {
796
826
  console.log(
797
827
  `⚠️ [Recycle] No dump entry contains index ${index} for combination: ${combination}`
798
828
  );
799
829
  continue;
800
830
  }
801
-
831
+
802
832
  // Clean up the raw text
803
- console.log(`[Recycle] Cleaning rawText for index ${index}: ${rawText}`);
833
+ console.log(
834
+ `[Recycle] Cleaning rawText for index ${index}: ${rawText}`
835
+ );
804
836
  const cleanedText = rawText
805
837
  .replace(/###|---\s*###|-\s*###/g, '')
806
838
  .trim();
807
- console.log(`[Recycle] Cleaned text for index ${index}: ${cleanedText}`);
808
-
839
+ console.log(
840
+ `[Recycle] Cleaned text for index ${index}: ${cleanedText}`
841
+ );
842
+
809
843
  // Extract the specific index sections
810
844
  const enSectionMatch = cleanedText.match(
811
845
  new RegExp(`-EN ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
@@ -813,28 +847,43 @@ export class ArchetypeService {
813
847
  const ptSectionMatch = cleanedText.match(
814
848
  new RegExp(`-PT ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
815
849
  );
816
-
850
+
817
851
  console.log(
818
- `[Recycle] Extracted sections for index ${index} - enSectionMatch: ${JSON.stringify(enSectionMatch)}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
852
+ `[Recycle] Extracted sections for index ${index} - enSectionMatch: ${JSON.stringify(
853
+ enSectionMatch
854
+ )}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
819
855
  );
820
-
821
- if (!enSectionMatch || !ptSectionMatch || !enSectionMatch[0] || !ptSectionMatch[0]) {
856
+
857
+ if (
858
+ !enSectionMatch ||
859
+ !ptSectionMatch ||
860
+ !enSectionMatch[0] ||
861
+ !ptSectionMatch[0]
862
+ ) {
822
863
  console.log(
823
- `⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}. enSectionMatch: ${JSON.stringify(enSectionMatch)}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
864
+ `⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}. enSectionMatch: ${JSON.stringify(
865
+ enSectionMatch
866
+ )}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
824
867
  );
825
868
  continue;
826
869
  }
827
-
870
+
828
871
  // Combine the extracted sections into a block for parsing
829
- const block = `-EN\n${enSectionMatch[0].replace(/-EN\s*/, '').trim()}\n\n-PT\n${ptSectionMatch[0].replace(/-PT\s*/, '').trim()}`;
872
+ const block = `-EN\n${enSectionMatch[0]
873
+ .replace(/-EN\s*/, '')
874
+ .trim()}\n\n-PT\n${ptSectionMatch[0].replace(/-PT\s*/, '').trim()}`;
830
875
  console.log(`[Recycle] Constructed block for index ${index}: ${block}`);
831
-
876
+
832
877
  // Step 3: Parse the block
833
878
  const { english, portuguese } = this.parseArchetypeNameBlocks(block);
834
879
  console.log(
835
- `[Recycle] Parsed results for index ${index} - English: ${JSON.stringify(english, null, 2)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
880
+ `[Recycle] Parsed results for index ${index} - English: ${JSON.stringify(
881
+ english,
882
+ null,
883
+ 2
884
+ )}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
836
885
  );
837
-
886
+
838
887
  if (english.length === 0 || portuguese.length === 0) {
839
888
  console.error(
840
889
  `❌ [Recycle] Parsing failed for index ${index} of combination: ${combination}. Block: ${block}`
@@ -860,27 +909,33 @@ export class ArchetypeService {
860
909
  }
861
910
  continue;
862
911
  }
863
-
912
+
864
913
  const englishEntry = english[0];
865
914
  const ptEntry = portuguese[0];
866
-
915
+
867
916
  console.log(
868
- `[Recycle] Extracted entries for index ${index} - englishEntry: ${JSON.stringify(englishEntry, null, 2)}, ptEntry: ${JSON.stringify(ptEntry, null, 2)}`
917
+ `[Recycle] Extracted entries for index ${index} - englishEntry: ${JSON.stringify(
918
+ englishEntry,
919
+ null,
920
+ 2
921
+ )}, ptEntry: ${JSON.stringify(ptEntry, null, 2)}`
869
922
  );
870
-
923
+
871
924
  if (!englishEntry || !ptEntry) {
872
925
  console.warn(
873
- `⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data. englishEntry: ${JSON.stringify(englishEntry)}, ptEntry: ${JSON.stringify(ptEntry)}`
926
+ `⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data. englishEntry: ${JSON.stringify(
927
+ englishEntry
928
+ )}, ptEntry: ${JSON.stringify(ptEntry)}`
874
929
  );
875
930
  continue;
876
931
  }
877
-
932
+
878
933
  // Step 4: Insert the parsed data into archetypes_data
879
934
  for (const gender of ['male', 'female']) {
880
935
  const enId = `${combination}:${gender}:${index}`;
881
936
  const ptId = `${combination}:${gender}:${index}:pt`;
882
937
  const ptName = gender === 'female' ? ptEntry.fem : ptEntry.masc;
883
-
938
+
884
939
  console.log(
885
940
  `[Recycle] Inserting English entry for ${combination}, index ${index}, gender ${gender}: id=${enId}, name=${englishEntry.name}, essenceLine=${englishEntry.essenceLine}`
886
941
  );
@@ -905,7 +960,7 @@ export class ArchetypeService {
905
960
  updatedAt: new Date().getTime(),
906
961
  },
907
962
  });
908
-
963
+
909
964
  console.log(
910
965
  `[Recycle] Inserting Portuguese entry for ${combination}, index ${index}, gender ${gender}: id=${ptId}, name=${ptName}, essenceLine=${ptEntry.essenceLine}`
911
966
  );
@@ -930,7 +985,7 @@ export class ArchetypeService {
930
985
  updatedAt: new Date().getTime(),
931
986
  },
932
987
  });
933
-
988
+
934
989
  // Delete the processed dump entry
935
990
  if (selectedEntryId) {
936
991
  console.log(
@@ -947,16 +1002,16 @@ export class ArchetypeService {
947
1002
  `[Recycle] Could not delete dump entry for ${combination}, index ${index}: selectedEntryId is null`
948
1003
  );
949
1004
  }
950
-
1005
+
951
1006
  console.log(
952
1007
  `✅ [Recycle] Saved archetype ${index} (${gender}) for ${combination}`
953
1008
  );
954
1009
  }
955
1010
  }
956
-
1011
+
957
1012
  console.log(`🏁 [Recycle] Finished combination: ${combination}`);
958
1013
  }
959
-
1014
+
960
1015
  console.log(
961
1016
  `🎉 [Recycle] Completed recycling for ${compositions.length} combinations`
962
1017
  );
@@ -1022,95 +1077,139 @@ export class ArchetypeService {
1022
1077
  portuguese: any[];
1023
1078
  } {
1024
1079
  console.log(`[Parse] Starting parsing of block: ${block}`);
1025
-
1080
+
1081
+ // Split the block into sections based on -EN and -PT markers
1026
1082
  const sections = block.split(/^-EN|^-PT/m).filter((s) => s.trim());
1027
1083
  console.log(
1028
- `[Parse] Split block into ${sections.length} sections: ${JSON.stringify(sections, null, 2)}`
1084
+ `[Parse] Split block into ${sections.length} sections: ${JSON.stringify(
1085
+ sections,
1086
+ null,
1087
+ 2
1088
+ )}`
1029
1089
  );
1030
-
1090
+
1031
1091
  const english: any[] = [];
1032
1092
  const portuguese: any[] = [];
1033
-
1034
- for (const section of sections) {
1093
+
1094
+ // Track whether we're in an EN or PT section
1095
+ let currentLang: 'EN' | 'PT' | null = null;
1096
+
1097
+ for (let i = 0; i < block.length; i++) {
1098
+ if (block.startsWith('-EN', i)) {
1099
+ currentLang = 'EN';
1100
+ i += 3; // Skip past "-EN"
1101
+ } else if (block.startsWith('-PT', i)) {
1102
+ currentLang = 'PT';
1103
+ i += 3; // Skip past "-PT"
1104
+ }
1105
+ }
1106
+
1107
+ // Process each section
1108
+ for (let i = 0; i < sections.length; i++) {
1109
+ const section = sections[i].trim();
1035
1110
  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());
1111
+
1112
+ // Determine the language based on the section's position relative to -EN and -PT markers
1113
+ const lang = i === 0 ? 'EN' : 'PT'; // First section after -EN, second after -PT
1114
+
1115
+ // Split the section into individual entries based on numbered markers (1., 2., 3.)
1116
+ const entries = section.split(/\n(?=\d+\.\s*)/).filter((e) => e.trim());
1117
+ console.log(
1118
+ `[Parse] Split section into ${entries.length} entries: ${JSON.stringify(
1119
+ entries,
1120
+ null,
1121
+ 2
1122
+ )}`
1123
+ );
1124
+
1125
+ for (const entry of entries) {
1126
+ const lines = entry.split('\n').filter((l) => l.trim());
1068
1127
  console.log(
1069
- `[Parse] Extracted ${lines.length} lines from Portuguese section: ${JSON.stringify(lines, null, 2)}`
1128
+ `[Parse] Extracted ${lines.length} lines from entry: ${JSON.stringify(
1129
+ lines,
1130
+ null,
1131
+ 2
1132
+ )}`
1070
1133
  );
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
- );
1134
+
1135
+ if (lang === 'EN') {
1136
+ const nameMatch = lines
1137
+ .find((l) => l.includes('• Name:'))
1138
+ ?.split('• Name:')[1]
1139
+ ?.trim();
1140
+ console.log(`[Parse] English nameMatch: ${nameMatch}`);
1141
+
1142
+ const essenceMatch = lines
1143
+ .find((l) => l.includes('• Essence:'))
1144
+ ?.split('• Essence:')[1]
1145
+ ?.trim();
1146
+ console.log(`[Parse] English essenceMatch: ${essenceMatch}`);
1147
+
1148
+ if (nameMatch && essenceMatch) {
1149
+ const englishEntry = { name: nameMatch, essenceLine: essenceMatch };
1150
+ english.push(englishEntry);
1151
+ console.log(
1152
+ `[Parse] Added English entry: ${JSON.stringify(
1153
+ englishEntry,
1154
+ null,
1155
+ 2
1156
+ )}`
1157
+ );
1158
+ } else {
1159
+ console.warn(
1160
+ `[Parse] Skipping English entry due to missing fields. nameMatch: ${nameMatch}, essenceMatch: ${essenceMatch}`
1161
+ );
1162
+ }
1163
+ } else if (lang === 'PT') {
1164
+ const mascMatch = lines
1165
+ .find((l) => l.includes('• Masculino:'))
1166
+ ?.split('• Masculino:')[1]
1167
+ ?.trim();
1168
+ console.log(`[Parse] Portuguese mascMatch: ${mascMatch}`);
1169
+
1170
+ const femMatch = lines
1171
+ .find((l) => l.includes('• Feminino:'))
1172
+ ?.split('• Feminino:')[1]
1173
+ ?.trim();
1174
+ console.log(`[Parse] Portuguese femMatch: ${femMatch}`);
1175
+
1176
+ const essenceMatch = lines
1177
+ .find((l) => l.includes('• Essência:'))
1178
+ ?.split('• Essência:')[1]
1179
+ ?.trim();
1180
+ console.log(`[Parse] Portuguese essenceMatch: ${essenceMatch}`);
1181
+
1182
+ if (mascMatch && femMatch && essenceMatch) {
1183
+ const ptEntry = {
1184
+ masc: mascMatch,
1185
+ fem: femMatch,
1186
+ essenceLine: essenceMatch,
1187
+ };
1188
+ portuguese.push(ptEntry);
1189
+ console.log(
1190
+ `[Parse] Added Portuguese entry: ${JSON.stringify(
1191
+ ptEntry,
1192
+ null,
1193
+ 2
1194
+ )}`
1195
+ );
1196
+ } else {
1197
+ console.warn(
1198
+ `[Parse] Skipping Portuguese entry due to missing fields. mascMatch: ${mascMatch}, femMatch: ${femMatch}, essenceMatch: ${essenceMatch}`
1199
+ );
1200
+ }
1104
1201
  }
1105
- } else {
1106
- console.warn(`[Parse] Unrecognized section: ${section}`);
1107
1202
  }
1108
1203
  }
1109
-
1204
+
1110
1205
  console.log(
1111
- `[Parse] Final parsed results - English: ${JSON.stringify(english, null, 2)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
1206
+ `[Parse] Final parsed results - English: ${JSON.stringify(
1207
+ english,
1208
+ null,
1209
+ 2
1210
+ )}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
1112
1211
  );
1113
-
1212
+
1114
1213
  return { english, portuguese };
1115
1214
  }
1116
1215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.312",
3
+ "version": "0.0.313",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {