@mikkelscheike/email-provider-links 5.0.0 → 5.1.0

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/dist/loader.js DELETED
@@ -1,121 +0,0 @@
1
- "use strict";
2
- /**
3
- * Provider Data Loader
4
- *
5
- * Handles loading email provider data with performance optimizations.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.buildDomainMap = buildDomainMap;
9
- exports.clearCache = clearCache;
10
- exports.getLoadingStats = getLoadingStats;
11
- exports.loadProviders = loadProviders;
12
- exports.loadProvidersDebug = loadProvidersDebug;
13
- const path_1 = require("path");
14
- const provider_store_1 = require("./provider-store");
15
- /**
16
- * Internal cached data
17
- */
18
- let cachedProviders = null;
19
- let cachedDomainMap = null;
20
- let loadingStats = null;
21
- /**
22
- * Default loader configuration
23
- */
24
- const DEFAULT_CONFIG = {
25
- debug: false
26
- };
27
- /**
28
- * Internal provider data loader with configuration
29
- */
30
- function loadProvidersInternal(config = {}) {
31
- const mergedConfig = { ...DEFAULT_CONFIG, ...config };
32
- const startTime = Date.now();
33
- // Return cached data if available
34
- if (cachedProviders && !mergedConfig.debug) {
35
- return {
36
- providers: cachedProviders,
37
- stats: loadingStats
38
- };
39
- }
40
- try {
41
- // Determine file path
42
- const basePath = (0, path_1.join)(__dirname, '..', 'providers');
43
- const dataPath = mergedConfig.path || (0, path_1.join)(basePath, 'emailproviders.json');
44
- if (mergedConfig.debug)
45
- console.log('🔄 Loading provider data...');
46
- const { data, fileSize } = (0, provider_store_1.readProvidersDataFile)(dataPath);
47
- const providers = data.providers.map(provider_store_1.convertProviderToEmailProviderShared);
48
- if (mergedConfig.debug) {
49
- console.log(`✅ Loaded ${providers.length} providers`);
50
- console.log(`📊 File size: ${(fileSize / 1024).toFixed(1)} KB`);
51
- }
52
- const loadTime = Date.now() - startTime;
53
- const domainCount = providers.reduce((sum, p) => sum + p.domains.length, 0);
54
- // Cache the results
55
- cachedProviders = providers;
56
- loadingStats = {
57
- fileSize,
58
- loadTime,
59
- providerCount: providers.length,
60
- domainCount
61
- };
62
- if (mergedConfig.debug) {
63
- console.log(`⚡ Loading completed in ${loadTime}ms`);
64
- console.log(`📊 Stats: ${providers.length} providers, ${domainCount} domains`);
65
- }
66
- if (process.env.NODE_ENV === 'development') {
67
- const memoryUsageInMB = process.memoryUsage().heapUsed / 1024 / 1024;
68
- console.log(`🚀 Current memory usage: ${memoryUsageInMB.toFixed(2)} MB`);
69
- }
70
- return {
71
- providers,
72
- stats: loadingStats
73
- };
74
- }
75
- catch (error) {
76
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
77
- throw new Error(`Failed to load provider data: ${errorMessage}`);
78
- }
79
- }
80
- /**
81
- * Build optimized domain-to-provider lookup map
82
- */
83
- function buildDomainMap(providers) {
84
- if (cachedDomainMap) {
85
- return cachedDomainMap;
86
- }
87
- cachedDomainMap = (0, provider_store_1.buildDomainMapShared)(providers);
88
- return cachedDomainMap;
89
- }
90
- /**
91
- * Clear all caches (useful for testing or hot reloading)
92
- */
93
- function clearCache() {
94
- cachedProviders = null;
95
- cachedDomainMap = null;
96
- loadingStats = null;
97
- }
98
- /**
99
- * Get loading statistics from the last load operation
100
- */
101
- function getLoadingStats() {
102
- return loadingStats;
103
- }
104
- /**
105
- * Load all providers with optimized domain map for production
106
- */
107
- function loadProviders() {
108
- const { providers, stats } = loadProvidersInternal({ debug: false });
109
- const domainMap = buildDomainMap(providers);
110
- return { providers, domainMap, stats };
111
- }
112
- /**
113
- * Load providers with debug information
114
- */
115
- function loadProvidersDebug() {
116
- clearCache(); // Always reload in debug mode
117
- const { providers, stats } = loadProvidersInternal({ debug: true });
118
- const domainMap = buildDomainMap(providers);
119
- return { providers, domainMap, stats };
120
- }
121
- //# sourceMappingURL=loader.js.map