@zodic/shared 0.0.311 → 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.
- package/app/services/ArchetypeService.ts +250 -51
- package/package.json +1 -1
|
@@ -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 (
|
|
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
|
-
|
|
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`;
|
|
@@ -753,7 +771,11 @@ export class ArchetypeService {
|
|
|
753
771
|
const combination = [comp.sun, comp.ascendant, comp.moon].join('-');
|
|
754
772
|
const indexes = comp.indexesToGenerate ?? [1, 2, 3];
|
|
755
773
|
|
|
756
|
-
console.log(
|
|
774
|
+
console.log(
|
|
775
|
+
`🔄 [Recycle] Processing combination: ${combination} with indexes: [${indexes.join(
|
|
776
|
+
', '
|
|
777
|
+
)}]`
|
|
778
|
+
);
|
|
757
779
|
|
|
758
780
|
// Fetch all dump entries for this combination
|
|
759
781
|
const dumpEntries = await db
|
|
@@ -765,6 +787,16 @@ export class ArchetypeService {
|
|
|
765
787
|
.where(eq(schema.archetypeNameDumps.combination, combination))
|
|
766
788
|
.execute();
|
|
767
789
|
|
|
790
|
+
console.log(
|
|
791
|
+
`[Recycle] Retrieved ${
|
|
792
|
+
dumpEntries.length
|
|
793
|
+
} dump entries for ${combination}: ${JSON.stringify(
|
|
794
|
+
dumpEntries,
|
|
795
|
+
null,
|
|
796
|
+
2
|
|
797
|
+
)}`
|
|
798
|
+
);
|
|
799
|
+
|
|
768
800
|
if (dumpEntries.length === 0) {
|
|
769
801
|
console.log(
|
|
770
802
|
`⚠️ [Recycle] No dump entries found for combination: ${combination}`
|
|
@@ -774,11 +806,18 @@ export class ArchetypeService {
|
|
|
774
806
|
|
|
775
807
|
// Step 2: Process each missing index
|
|
776
808
|
for (const index of indexes) {
|
|
809
|
+
console.log(`[Recycle] Processing index ${index} for ${combination}`);
|
|
810
|
+
|
|
777
811
|
// Find a dump entry that contains the specific index
|
|
778
812
|
let rawText: string | null = null;
|
|
813
|
+
let selectedEntryId: string | null = null;
|
|
779
814
|
for (const entry of dumpEntries) {
|
|
780
|
-
if (entry.rawText.includes(`-EN ${index}.`)) {
|
|
815
|
+
if (entry.rawText && entry.rawText.includes(`-EN ${index}.`)) {
|
|
781
816
|
rawText = entry.rawText;
|
|
817
|
+
selectedEntryId = entry.id;
|
|
818
|
+
console.log(
|
|
819
|
+
`[Recycle] Selected dump entry for index ${index} with id ${selectedEntryId}: ${rawText}`
|
|
820
|
+
);
|
|
782
821
|
break;
|
|
783
822
|
}
|
|
784
823
|
}
|
|
@@ -791,9 +830,15 @@ export class ArchetypeService {
|
|
|
791
830
|
}
|
|
792
831
|
|
|
793
832
|
// Clean up the raw text
|
|
833
|
+
console.log(
|
|
834
|
+
`[Recycle] Cleaning rawText for index ${index}: ${rawText}`
|
|
835
|
+
);
|
|
794
836
|
const cleanedText = rawText
|
|
795
837
|
.replace(/###|---\s*###|-\s*###/g, '')
|
|
796
838
|
.trim();
|
|
839
|
+
console.log(
|
|
840
|
+
`[Recycle] Cleaned text for index ${index}: ${cleanedText}`
|
|
841
|
+
);
|
|
797
842
|
|
|
798
843
|
// Extract the specific index sections
|
|
799
844
|
const enSectionMatch = cleanedText.match(
|
|
@@ -803,9 +848,22 @@ export class ArchetypeService {
|
|
|
803
848
|
new RegExp(`-PT ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
|
|
804
849
|
);
|
|
805
850
|
|
|
806
|
-
|
|
851
|
+
console.log(
|
|
852
|
+
`[Recycle] Extracted sections for index ${index} - enSectionMatch: ${JSON.stringify(
|
|
853
|
+
enSectionMatch
|
|
854
|
+
)}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
|
|
855
|
+
);
|
|
856
|
+
|
|
857
|
+
if (
|
|
858
|
+
!enSectionMatch ||
|
|
859
|
+
!ptSectionMatch ||
|
|
860
|
+
!enSectionMatch[0] ||
|
|
861
|
+
!ptSectionMatch[0]
|
|
862
|
+
) {
|
|
807
863
|
console.log(
|
|
808
|
-
`⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}
|
|
864
|
+
`⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}. enSectionMatch: ${JSON.stringify(
|
|
865
|
+
enSectionMatch
|
|
866
|
+
)}, ptSectionMatch: ${JSON.stringify(ptSectionMatch)}`
|
|
809
867
|
);
|
|
810
868
|
continue;
|
|
811
869
|
}
|
|
@@ -814,23 +872,60 @@ export class ArchetypeService {
|
|
|
814
872
|
const block = `-EN\n${enSectionMatch[0]
|
|
815
873
|
.replace(/-EN\s*/, '')
|
|
816
874
|
.trim()}\n\n-PT\n${ptSectionMatch[0].replace(/-PT\s*/, '').trim()}`;
|
|
875
|
+
console.log(`[Recycle] Constructed block for index ${index}: ${block}`);
|
|
817
876
|
|
|
818
877
|
// Step 3: Parse the block
|
|
819
878
|
const { english, portuguese } = this.parseArchetypeNameBlocks(block);
|
|
879
|
+
console.log(
|
|
880
|
+
`[Recycle] Parsed results for index ${index} - English: ${JSON.stringify(
|
|
881
|
+
english,
|
|
882
|
+
null,
|
|
883
|
+
2
|
|
884
|
+
)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
|
|
885
|
+
);
|
|
820
886
|
|
|
821
887
|
if (english.length === 0 || portuguese.length === 0) {
|
|
822
888
|
console.error(
|
|
823
|
-
`❌ [Recycle] Parsing failed for index ${index} of combination: ${combination}`
|
|
889
|
+
`❌ [Recycle] Parsing failed for index ${index} of combination: ${combination}. Block: ${block}`
|
|
824
890
|
);
|
|
891
|
+
if (block) {
|
|
892
|
+
await this.context
|
|
893
|
+
.drizzle()
|
|
894
|
+
.insert(schema.archetypeNameDumps)
|
|
895
|
+
.values({
|
|
896
|
+
id: `${combination}:${index}:${Date.now()}`,
|
|
897
|
+
combination,
|
|
898
|
+
rawText: block,
|
|
899
|
+
parsedSuccessfully: 0,
|
|
900
|
+
createdAt: Date.now(),
|
|
901
|
+
});
|
|
902
|
+
console.log(
|
|
903
|
+
`[Recycle] Logged failed parse to archetype_name_dumps for index ${index} of ${combination}`
|
|
904
|
+
);
|
|
905
|
+
} else {
|
|
906
|
+
console.error(
|
|
907
|
+
`❌ [Recycle] Cannot log failed parse to archetype_name_dumps: block is undefined`
|
|
908
|
+
);
|
|
909
|
+
}
|
|
825
910
|
continue;
|
|
826
911
|
}
|
|
827
912
|
|
|
828
913
|
const englishEntry = english[0];
|
|
829
914
|
const ptEntry = portuguese[0];
|
|
830
915
|
|
|
916
|
+
console.log(
|
|
917
|
+
`[Recycle] Extracted entries for index ${index} - englishEntry: ${JSON.stringify(
|
|
918
|
+
englishEntry,
|
|
919
|
+
null,
|
|
920
|
+
2
|
|
921
|
+
)}, ptEntry: ${JSON.stringify(ptEntry, null, 2)}`
|
|
922
|
+
);
|
|
923
|
+
|
|
831
924
|
if (!englishEntry || !ptEntry) {
|
|
832
925
|
console.warn(
|
|
833
|
-
`⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data
|
|
926
|
+
`⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data. englishEntry: ${JSON.stringify(
|
|
927
|
+
englishEntry
|
|
928
|
+
)}, ptEntry: ${JSON.stringify(ptEntry)}`
|
|
834
929
|
);
|
|
835
930
|
continue;
|
|
836
931
|
}
|
|
@@ -841,6 +936,9 @@ export class ArchetypeService {
|
|
|
841
936
|
const ptId = `${combination}:${gender}:${index}:pt`;
|
|
842
937
|
const ptName = gender === 'female' ? ptEntry.fem : ptEntry.masc;
|
|
843
938
|
|
|
939
|
+
console.log(
|
|
940
|
+
`[Recycle] Inserting English entry for ${combination}, index ${index}, gender ${gender}: id=${enId}, name=${englishEntry.name}, essenceLine=${englishEntry.essenceLine}`
|
|
941
|
+
);
|
|
844
942
|
await this.context
|
|
845
943
|
.drizzle()
|
|
846
944
|
.insert(schema.archetypesData)
|
|
@@ -863,6 +961,9 @@ export class ArchetypeService {
|
|
|
863
961
|
},
|
|
864
962
|
});
|
|
865
963
|
|
|
964
|
+
console.log(
|
|
965
|
+
`[Recycle] Inserting Portuguese entry for ${combination}, index ${index}, gender ${gender}: id=${ptId}, name=${ptName}, essenceLine=${ptEntry.essenceLine}`
|
|
966
|
+
);
|
|
866
967
|
await this.context
|
|
867
968
|
.drizzle()
|
|
868
969
|
.insert(schema.archetypesData)
|
|
@@ -885,14 +986,22 @@ export class ArchetypeService {
|
|
|
885
986
|
},
|
|
886
987
|
});
|
|
887
988
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
.
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
)
|
|
989
|
+
// Delete the processed dump entry
|
|
990
|
+
if (selectedEntryId) {
|
|
991
|
+
console.log(
|
|
992
|
+
`[Recycle] Deleting dump entry with id ${selectedEntryId} for ${combination}, index ${index}`
|
|
993
|
+
);
|
|
994
|
+
await db
|
|
995
|
+
.delete(schema.archetypeNameDumps)
|
|
996
|
+
.where(eq(schema.archetypeNameDumps.id, selectedEntryId));
|
|
997
|
+
console.log(
|
|
998
|
+
`[Recycle] Successfully deleted dump entry with id ${selectedEntryId}`
|
|
895
999
|
);
|
|
1000
|
+
} else {
|
|
1001
|
+
console.warn(
|
|
1002
|
+
`[Recycle] Could not delete dump entry for ${combination}, index ${index}: selectedEntryId is null`
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
896
1005
|
|
|
897
1006
|
console.log(
|
|
898
1007
|
`✅ [Recycle] Saved archetype ${index} (${gender}) for ${combination}`
|
|
@@ -967,50 +1076,140 @@ export class ArchetypeService {
|
|
|
967
1076
|
english: any[];
|
|
968
1077
|
portuguese: any[];
|
|
969
1078
|
} {
|
|
1079
|
+
console.log(`[Parse] Starting parsing of block: ${block}`);
|
|
1080
|
+
|
|
1081
|
+
// Split the block into sections based on -EN and -PT markers
|
|
970
1082
|
const sections = block.split(/^-EN|^-PT/m).filter((s) => s.trim());
|
|
1083
|
+
console.log(
|
|
1084
|
+
`[Parse] Split block into ${sections.length} sections: ${JSON.stringify(
|
|
1085
|
+
sections,
|
|
1086
|
+
null,
|
|
1087
|
+
2
|
|
1088
|
+
)}`
|
|
1089
|
+
);
|
|
1090
|
+
|
|
971
1091
|
const english: any[] = [];
|
|
972
1092
|
const portuguese: any[] = [];
|
|
973
1093
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
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();
|
|
1110
|
+
console.log(`[Parse] Processing section: ${section}`);
|
|
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());
|
|
1127
|
+
console.log(
|
|
1128
|
+
`[Parse] Extracted ${lines.length} lines from entry: ${JSON.stringify(
|
|
1129
|
+
lines,
|
|
1130
|
+
null,
|
|
1131
|
+
2
|
|
1132
|
+
)}`
|
|
1133
|
+
);
|
|
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
|
+
}
|
|
1010
1201
|
}
|
|
1011
1202
|
}
|
|
1012
1203
|
}
|
|
1013
1204
|
|
|
1205
|
+
console.log(
|
|
1206
|
+
`[Parse] Final parsed results - English: ${JSON.stringify(
|
|
1207
|
+
english,
|
|
1208
|
+
null,
|
|
1209
|
+
2
|
|
1210
|
+
)}, Portuguese: ${JSON.stringify(portuguese, null, 2)}`
|
|
1211
|
+
);
|
|
1212
|
+
|
|
1014
1213
|
return { english, portuguese };
|
|
1015
1214
|
}
|
|
1016
1215
|
}
|