i18ntk 2.3.8 ā 2.5.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/README.md +10 -6
- package/main/i18ntk-backup-class.js +35 -423
- package/main/manage/commands/BackupCommand.js +62 -62
- package/main/manage/commands/FixerCommand.js +97 -97
- package/main/manage/managers/DebugMenu.js +10 -9
- package/main/manage/services/SetupService.js +444 -462
- package/package.json +61 -32
- package/runtime/index.js +14 -8
- package/utils/admin-auth.js +594 -576
- package/utils/config-manager.js +72 -72
- package/utils/env-manager.js +117 -26
- package/utils/i18n-helper.js +50 -49
- package/utils/json-output.js +13 -12
- package/utils/logger.js +7 -6
- package/utils/npm-version-warning.js +12 -141
- package/utils/prompt-helper.js +44 -41
- package/utils/secure-errors.js +156 -154
- package/utils/security.js +235 -233
- package/utils/setup-enforcer.js +110 -109
- package/utils/terminal-icons.js +164 -163
- package/settings/i18ntk-config.json +0 -283
- package/utils/admin-pin.js +0 -520
- package/utils/arg-parser.js +0 -40
- package/utils/cli-args.js +0 -210
- package/utils/mini-commander.js +0 -179
- package/utils/missing-key-validator.js +0 -858
- package/utils/path-utils.js +0 -33
- package/utils/performance-optimizer.js +0 -246
- package/utils/prompt-new.js +0 -55
- package/utils/promptPin.js +0 -76
- package/utils/safe-json.js +0 -40
- package/utils/secure-backup.js +0 -340
- package/utils/security-check-improved.js +0 -393
- package/utils/security-config.js +0 -239
- package/utils/setup-validator.js +0 -717
- package/utils/ultra-performance-optimizer.js +0 -352
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ultra Performance Optimizer
|
|
3
|
-
* Advanced performance optimization for extreme i18n processing
|
|
4
|
-
* Targets: 35ms processing for 200k keys with <10MB memory
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs').promises;
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const perf = (globalThis.performance && typeof globalThis.performance.now === 'function')
|
|
10
|
-
? globalThis.performance
|
|
11
|
-
: { now: () => Date.now() };
|
|
12
|
-
|
|
13
|
-
class UltraPerformanceOptimizer {
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
this.config = {
|
|
16
|
-
batchSize: options.batchSize || 2000,
|
|
17
|
-
concurrency: options.concurrency || 32,
|
|
18
|
-
memoryLimit: options.memoryLimit || 256 * 1024 * 1024,
|
|
19
|
-
cacheEnabled: options.cacheEnabled !== false,
|
|
20
|
-
cacheTTL: options.cacheTTL || 180000,
|
|
21
|
-
compression: options.compression || 'brotli',
|
|
22
|
-
streaming: options.streaming !== false,
|
|
23
|
-
gcInterval: options.gcInterval || 250,
|
|
24
|
-
...options
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
this.cache = new Map();
|
|
28
|
-
this.stats = {
|
|
29
|
-
startTime: null,
|
|
30
|
-
endTime: null,
|
|
31
|
-
memoryStart: null,
|
|
32
|
-
memoryEnd: null,
|
|
33
|
-
operations: 0,
|
|
34
|
-
cacheHits: 0,
|
|
35
|
-
cacheMisses: 0
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
this.pool = new Array(this.config.concurrency).fill(null);
|
|
39
|
-
this.gcTimer = null;
|
|
40
|
-
this.isOptimized = false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Initialize ultra-optimization
|
|
45
|
-
*/
|
|
46
|
-
async initialize() {
|
|
47
|
-
this.stats.startTime = perf.now();
|
|
48
|
-
this.stats.memoryStart = process.memoryUsage();
|
|
49
|
-
|
|
50
|
-
// Force garbage collection if available
|
|
51
|
-
if (global.gc) {
|
|
52
|
-
global.gc();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Start aggressive GC timer
|
|
56
|
-
this.startGCTimer();
|
|
57
|
-
|
|
58
|
-
// Pre-allocate memory pools
|
|
59
|
-
this.preallocateMemory();
|
|
60
|
-
|
|
61
|
-
this.isOptimized = true;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Pre-allocate memory for ultra-fast processing
|
|
67
|
-
*/
|
|
68
|
-
preallocateMemory() {
|
|
69
|
-
// Pre-allocate string buffers
|
|
70
|
-
this.stringPool = new Array(1000).fill(null).map(() => Buffer.allocUnsafe(1024));
|
|
71
|
-
this.objectPool = new Array(500).fill(null).map(() => ({}));
|
|
72
|
-
this.arrayPool = new Array(500).fill(null).map(() => []);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Start aggressive GC timer
|
|
77
|
-
*/
|
|
78
|
-
startGCTimer() {
|
|
79
|
-
this.gcTimer = setInterval(() => {
|
|
80
|
-
if (global.gc) {
|
|
81
|
-
global.gc();
|
|
82
|
-
}
|
|
83
|
-
}, this.config.gcInterval);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Ultra-fast file processing with streaming
|
|
88
|
-
*/
|
|
89
|
-
async processFiles(filePaths) {
|
|
90
|
-
if (!this.isOptimized) await this.initialize();
|
|
91
|
-
|
|
92
|
-
const results = [];
|
|
93
|
-
const chunks = this.chunkArray(filePaths, this.config.batchSize);
|
|
94
|
-
|
|
95
|
-
for (const chunk of chunks) {
|
|
96
|
-
const chunkResults = await this.processChunk(chunk);
|
|
97
|
-
results.push(...chunkResults);
|
|
98
|
-
|
|
99
|
-
// Aggressive cleanup
|
|
100
|
-
this.cleanupMemory();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return results;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Process a chunk of files with maximum concurrency
|
|
108
|
-
*/
|
|
109
|
-
async processChunk(filePaths) {
|
|
110
|
-
const promises = filePaths.map(filePath => this.processFileUltra(filePath));
|
|
111
|
-
return Promise.all(promises);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Ultra-fast single file processing
|
|
116
|
-
*/
|
|
117
|
-
async processFileUltra(filePath) {
|
|
118
|
-
try {
|
|
119
|
-
// Check cache first
|
|
120
|
-
const cacheKey = this.getCacheKey(filePath);
|
|
121
|
-
if (this.config.cacheEnabled && this.cache.has(cacheKey)) {
|
|
122
|
-
this.stats.cacheHits++;
|
|
123
|
-
return this.cache.get(cacheKey);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this.stats.cacheMisses++;
|
|
127
|
-
|
|
128
|
-
// Ultra-fast read with minimal overhead
|
|
129
|
-
const data = await this.readFileUltra(filePath);
|
|
130
|
-
|
|
131
|
-
// Ultra-fast parse with streaming
|
|
132
|
-
const parsed = await this.parseDataUltra(data);
|
|
133
|
-
|
|
134
|
-
// Cache result
|
|
135
|
-
if (this.config.cacheEnabled) {
|
|
136
|
-
this.cache.set(cacheKey, parsed, this.config.cacheTTL);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
this.stats.operations++;
|
|
140
|
-
return parsed;
|
|
141
|
-
|
|
142
|
-
} catch (error) {
|
|
143
|
-
// Ultra-fast error handling (minimal overhead)
|
|
144
|
-
return { error: error.message, file: filePath };
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Ultra-fast file reading with minimal overhead
|
|
150
|
-
*/
|
|
151
|
-
async readFileUltra(filePath) {
|
|
152
|
-
const buffer = Buffer.allocUnsafe(64 * 1024); // 64KB buffer
|
|
153
|
-
const fd = await fs.open(filePath, 'r');
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
const { bytesRead } = await fd.read(buffer, 0, buffer.length, 0);
|
|
157
|
-
return buffer.slice(0, bytesRead);
|
|
158
|
-
} finally {
|
|
159
|
-
await fd.close();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Ultra-fast JSON parsing with streaming
|
|
165
|
-
*/
|
|
166
|
-
async parseDataUltra(buffer) {
|
|
167
|
-
// Use ultra-fast JSON parse
|
|
168
|
-
const str = buffer.toString('utf8');
|
|
169
|
-
|
|
170
|
-
// Ultra-fast JSON parse with minimal validation
|
|
171
|
-
try {
|
|
172
|
-
return JSON.parse(str);
|
|
173
|
-
} catch (parseError) {
|
|
174
|
-
// Ultra-fast fallback parsing
|
|
175
|
-
return this.parsePartialJSON(str);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Ultra-fast partial JSON parsing for corrupted files
|
|
181
|
-
*/
|
|
182
|
-
parsePartialJSON(str) {
|
|
183
|
-
const lines = str.split('\n');
|
|
184
|
-
const result = {};
|
|
185
|
-
|
|
186
|
-
for (const line of lines) {
|
|
187
|
-
const trimmed = line.trim();
|
|
188
|
-
if (trimmed.startsWith('"') && trimmed.includes(':')) {
|
|
189
|
-
const colonIndex = trimmed.indexOf(':');
|
|
190
|
-
const key = trimmed.substring(1, colonIndex - 1);
|
|
191
|
-
const value = trimmed.substring(colonIndex + 1).trim();
|
|
192
|
-
|
|
193
|
-
if (value.startsWith('"') && value.endsWith('"')) {
|
|
194
|
-
result[key] = value.slice(1, -1);
|
|
195
|
-
} else if (value === 'true' || value === 'false') {
|
|
196
|
-
result[key] = value === 'true';
|
|
197
|
-
} else if (!isNaN(value)) {
|
|
198
|
-
result[key] = Number(value);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Ultra-fast cache implementation
|
|
208
|
-
*/
|
|
209
|
-
createUltraCache() {
|
|
210
|
-
const cache = new Map();
|
|
211
|
-
let hits = 0;
|
|
212
|
-
let misses = 0;
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
get: (key) => {
|
|
216
|
-
const value = cache.get(key);
|
|
217
|
-
if (value) {
|
|
218
|
-
hits++;
|
|
219
|
-
return value;
|
|
220
|
-
}
|
|
221
|
-
misses++;
|
|
222
|
-
return null;
|
|
223
|
-
},
|
|
224
|
-
set: (key, value, ttl) => {
|
|
225
|
-
cache.set(key, value);
|
|
226
|
-
setTimeout(() => cache.delete(key), ttl);
|
|
227
|
-
},
|
|
228
|
-
stats: () => ({ hits, misses, size: cache.size })
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Aggressive memory cleanup
|
|
234
|
-
*/
|
|
235
|
-
cleanupMemory() {
|
|
236
|
-
// Clear unused variables
|
|
237
|
-
if (global.gc) {
|
|
238
|
-
global.gc();
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Clear cache if too large
|
|
242
|
-
if (this.cache.size > 1000) {
|
|
243
|
-
const keys = Array.from(this.cache.keys()).slice(0, 500);
|
|
244
|
-
keys.forEach(key => this.cache.delete(key));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Chunk array for batch processing
|
|
250
|
-
*/
|
|
251
|
-
chunkArray(array, size) {
|
|
252
|
-
const chunks = [];
|
|
253
|
-
for (let i = 0; i < array.length; i += size) {
|
|
254
|
-
chunks.push(array.slice(i, i + size));
|
|
255
|
-
}
|
|
256
|
-
return chunks;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Generate cache key
|
|
261
|
-
*/
|
|
262
|
-
getCacheKey(filePath) {
|
|
263
|
-
return `${filePath}:${fs.statSync(filePath).mtime.getTime()}`;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Get performance statistics
|
|
268
|
-
*/
|
|
269
|
-
getStats() {
|
|
270
|
-
this.stats.endTime = perf.now();
|
|
271
|
-
this.stats.memoryEnd = process.memoryUsage();
|
|
272
|
-
|
|
273
|
-
const processingTime = this.stats.endTime - this.stats.startTime;
|
|
274
|
-
const memoryUsed = this.stats.memoryEnd.heapUsed - this.stats.memoryStart.heapUsed;
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
processingTime: Math.round(processingTime * 100) / 100,
|
|
278
|
-
memoryUsed: Math.round(memoryUsed / 1024 / 1024 * 100) / 100,
|
|
279
|
-
operations: this.stats.operations,
|
|
280
|
-
cacheHitRate: this.stats.operations > 0 ?
|
|
281
|
-
Math.round((this.stats.cacheHits / (this.stats.cacheHits + this.stats.cacheMisses)) * 10000) / 100 : 0,
|
|
282
|
-
throughput: this.stats.operations > 0 ?
|
|
283
|
-
Math.round((this.stats.operations / (processingTime / 1000))) : 0,
|
|
284
|
-
timestamp: new Date().toISOString()
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Run ultra-extreme benchmark
|
|
290
|
-
*/
|
|
291
|
-
async runUltraBenchmark(filePaths) {
|
|
292
|
-
console.log('š Starting Ultra-Extreme Performance Benchmark...');
|
|
293
|
-
|
|
294
|
-
const start = perf.now();
|
|
295
|
-
const results = await this.processFiles(filePaths);
|
|
296
|
-
const end = perf.now();
|
|
297
|
-
|
|
298
|
-
const stats = this.getStats();
|
|
299
|
-
|
|
300
|
-
console.log('\nš Ultra-Extreme Results:');
|
|
301
|
-
console.log(`Processing Time: ${stats.processingTime}ms`);
|
|
302
|
-
console.log(`Memory Used: ${stats.memoryUsed}MB`);
|
|
303
|
-
console.log(`Throughput: ${(stats.throughput / 1000000).toFixed(2)}M keys/sec`);
|
|
304
|
-
console.log(`Cache Hit Rate: ${stats.cacheHitRate}%`);
|
|
305
|
-
console.log(`Total Operations: ${stats.operations}`);
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
...stats,
|
|
309
|
-
results,
|
|
310
|
-
improvement: Math.round(((300 - stats.processingTime) / 300) * 100 * 100) / 100
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Shutdown and cleanup
|
|
316
|
-
*/
|
|
317
|
-
async shutdown() {
|
|
318
|
-
if (this.gcTimer) {
|
|
319
|
-
clearInterval(this.gcTimer);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
this.cache.clear();
|
|
323
|
-
this.cleanupMemory();
|
|
324
|
-
|
|
325
|
-
if (global.gc) {
|
|
326
|
-
global.gc();
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return this.getStats();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// Export for use
|
|
334
|
-
module.exports = UltraPerformanceOptimizer;
|
|
335
|
-
|
|
336
|
-
// CLI usage
|
|
337
|
-
if (require.main === module) {
|
|
338
|
-
const optimizer = new UltraPerformanceOptimizer();
|
|
339
|
-
|
|
340
|
-
// Mock test data
|
|
341
|
-
const mockFiles = Array.from({ length: 1000 }, (_, i) =>
|
|
342
|
-
`mock-locale-${i}.json`
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
optimizer.runUltraBenchmark(mockFiles).then(results => {
|
|
346
|
-
console.log('\nā
Ultra-Extreme benchmark completed!');
|
|
347
|
-
process.exit(0);
|
|
348
|
-
}).catch(error => {
|
|
349
|
-
console.error('ā Benchmark failed:', error);
|
|
350
|
-
process.exit(1);
|
|
351
|
-
});
|
|
352
|
-
}
|