@zodic/shared 0.0.308 → 0.0.310

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,6 +733,181 @@ export class ArchetypeService {
733
733
  );
734
734
  }
735
735
 
736
+ async recycleArchetypeNameDumpsBatch(
737
+ compositions: Composition[]
738
+ ): Promise<void> {
739
+ console.log('🔁 [Recycle] Starting recycling of archetype name dumps');
740
+
741
+ if (compositions.length === 0) {
742
+ console.log('✅ [Recycle] No compositions provided for recycling');
743
+ return;
744
+ }
745
+
746
+ console.log(
747
+ `📦 [Recycle] Total compositions to recycle: ${compositions.length}`
748
+ );
749
+
750
+ // Step 1: Process each composition
751
+ const db = this.context.drizzle();
752
+ for (const comp of compositions) {
753
+ const combination = [comp.sun, comp.ascendant, comp.moon].join('-');
754
+ const indexes = comp.indexesToGenerate ?? [1, 2, 3];
755
+
756
+ console.log(`🔄 [Recycle] Processing: ${combination}`);
757
+
758
+ // Fetch all dump entries for this combination
759
+ const dumpEntries = await db
760
+ .select({
761
+ id: schema.archetypeNameDumps.id,
762
+ rawText: schema.archetypeNameDumps.rawText,
763
+ })
764
+ .from(schema.archetypeNameDumps)
765
+ .where(eq(schema.archetypeNameDumps.combination, combination))
766
+ .execute();
767
+
768
+ if (dumpEntries.length === 0) {
769
+ console.log(
770
+ `⚠️ [Recycle] No dump entries found for combination: ${combination}`
771
+ );
772
+ continue;
773
+ }
774
+
775
+ // Step 2: Process each missing index
776
+ for (const index of indexes) {
777
+ // Find a dump entry that contains the specific index
778
+ let rawText: string | null = null;
779
+ for (const entry of dumpEntries) {
780
+ if (entry.rawText.includes(`-EN ${index}.`)) {
781
+ rawText = entry.rawText;
782
+ break;
783
+ }
784
+ }
785
+
786
+ if (!rawText) {
787
+ console.log(
788
+ `⚠️ [Recycle] No dump entry contains index ${index} for combination: ${combination}`
789
+ );
790
+ continue;
791
+ }
792
+
793
+ // Clean up the raw text
794
+ const cleanedText = rawText
795
+ .replace(/###|---\s*###|-\s*###/g, '')
796
+ .trim();
797
+
798
+ // Extract the specific index sections
799
+ const enSectionMatch = cleanedText.match(
800
+ new RegExp(`-EN ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
801
+ );
802
+ const ptSectionMatch = cleanedText.match(
803
+ new RegExp(`-PT ${index}\\.\\s*[^-]*(?=-EN|-PT|$)`, 's')
804
+ );
805
+
806
+ if (!enSectionMatch || !ptSectionMatch) {
807
+ console.log(
808
+ `⚠️ [Recycle] Could not extract index ${index} sections for combination: ${combination}`
809
+ );
810
+ continue;
811
+ }
812
+
813
+ // 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
+
818
+ // Step 3: Parse the block
819
+ const { english, portuguese } = this.parseArchetypeNameBlocks(block);
820
+
821
+ if (english.length === 0 || portuguese.length === 0) {
822
+ console.error(
823
+ `❌ [Recycle] Parsing failed for index ${index} of combination: ${combination}`
824
+ );
825
+ continue;
826
+ }
827
+
828
+ const englishEntry = english[0];
829
+ const ptEntry = portuguese[0];
830
+
831
+ if (!englishEntry || !ptEntry) {
832
+ console.warn(
833
+ `⚠️ [Recycle] Skipping index ${index} for ${combination} due to missing parsed data`
834
+ );
835
+ continue;
836
+ }
837
+
838
+ // Step 4: Insert the parsed data into archetypes_data
839
+ for (const gender of ['male', 'female']) {
840
+ const enId = `${combination}:${gender}:${index}`;
841
+ const ptId = `${combination}:${gender}:${index}:pt`;
842
+ const ptName = gender === 'female' ? ptEntry.fem : ptEntry.masc;
843
+
844
+ await this.context
845
+ .drizzle()
846
+ .insert(schema.archetypesData)
847
+ .values({
848
+ id: enId,
849
+ combination,
850
+ gender,
851
+ archetypeIndex: index.toString(),
852
+ language: 'en-us',
853
+ name: englishEntry.name,
854
+ essenceLine: englishEntry.essenceLine,
855
+ status: 'idle',
856
+ })
857
+ .onConflictDoUpdate({
858
+ target: [schema.archetypesData.id],
859
+ set: {
860
+ name: englishEntry.name,
861
+ essenceLine: englishEntry.essenceLine,
862
+ updatedAt: new Date().getTime(),
863
+ },
864
+ });
865
+
866
+ await this.context
867
+ .drizzle()
868
+ .insert(schema.archetypesData)
869
+ .values({
870
+ id: ptId,
871
+ combination,
872
+ gender,
873
+ archetypeIndex: index.toString(),
874
+ language: 'pt-br',
875
+ name: ptName,
876
+ essenceLine: ptEntry.essenceLine,
877
+ status: 'idle',
878
+ })
879
+ .onConflictDoUpdate({
880
+ target: [schema.archetypesData.id],
881
+ set: {
882
+ name: ptName,
883
+ essenceLine: ptEntry.essenceLine,
884
+ updatedAt: new Date().getTime(),
885
+ },
886
+ });
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
+ )
895
+ );
896
+
897
+ console.log(
898
+ `✅ [Recycle] Saved archetype ${index} (${gender}) for ${combination}`
899
+ );
900
+ }
901
+ }
902
+
903
+ console.log(`🏁 [Recycle] Finished combination: ${combination}`);
904
+ }
905
+
906
+ console.log(
907
+ `🎉 [Recycle] Completed recycling for ${compositions.length} combinations`
908
+ );
909
+ }
910
+
736
911
  async fetchMissingArchetypeCompositions(): Promise<Composition[]> {
737
912
  const db = this.context.drizzle();
738
913
  const incomplete = await this.findIncompleteCombinations();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.308",
3
+ "version": "0.0.310",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/utils/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { jwtVerify } from 'jose';
2
2
  import { AuthCtx, JWKS, Provider, ProviderInfo } from '../types';
3
+ export { eq } from 'drizzle-orm';
3
4
 
4
5
  const base64UrlDecode = (input: string) => {
5
6
  const base64 = input.replace(/-/g, '+').replace(/_/g, '/');