@golemio/core 1.21.1-dev.1981658744 → 1.21.1-rc.2016563575
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/helpers/tools/memory/MemoryMonitor.d.ts +78 -0
- package/dist/helpers/tools/memory/MemoryMonitor.js +176 -0
- package/dist/helpers/tools/memory/MemoryMonitor.js.map +1 -0
- package/dist/helpers/tools/memory/MemoryMonitoringDecorator.d.ts +8 -0
- package/dist/helpers/tools/memory/MemoryMonitoringDecorator.js +96 -0
- package/dist/helpers/tools/memory/MemoryMonitoringDecorator.js.map +1 -0
- package/dist/helpers/tools/memory/examples/MemoryMonitoringExamples.d.ts +45 -0
- package/dist/helpers/tools/memory/examples/MemoryMonitoringExamples.js +222 -0
- package/dist/helpers/tools/memory/examples/MemoryMonitoringExamples.js.map +1 -0
- package/dist/helpers/tools/memory/index.d.ts +3 -0
- package/dist/helpers/tools/memory/index.js +9 -0
- package/dist/helpers/tools/memory/index.js.map +1 -0
- package/dist/shared/fast-csv.d.ts +1 -0
- package/dist/shared/fast-csv.js +18 -0
- package/dist/shared/fast-csv.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface MemoryUsage {
|
|
3
|
+
rss: number;
|
|
4
|
+
heapTotal: number;
|
|
5
|
+
heapUsed: number;
|
|
6
|
+
external: number;
|
|
7
|
+
arrayBuffers: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MemoryStats {
|
|
10
|
+
timestamp: Date;
|
|
11
|
+
usage: MemoryUsage;
|
|
12
|
+
heapUtilization: number;
|
|
13
|
+
rssInMB: number;
|
|
14
|
+
heapUsedInMB: number;
|
|
15
|
+
heapTotalInMB: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class MemoryMonitor {
|
|
18
|
+
private static instance;
|
|
19
|
+
private measurements;
|
|
20
|
+
private maxMeasurements;
|
|
21
|
+
private constructor();
|
|
22
|
+
static getInstance(): MemoryMonitor;
|
|
23
|
+
/**
|
|
24
|
+
* Get current memory usage
|
|
25
|
+
*/
|
|
26
|
+
getCurrentMemoryUsage(): MemoryUsage;
|
|
27
|
+
/**
|
|
28
|
+
* Get detailed memory statistics
|
|
29
|
+
*/
|
|
30
|
+
getMemoryStats(): MemoryStats;
|
|
31
|
+
/**
|
|
32
|
+
* Log current memory usage to console
|
|
33
|
+
*/
|
|
34
|
+
logMemoryUsage(label?: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Monitor memory usage over time with periodic logging
|
|
37
|
+
*/
|
|
38
|
+
startPeriodicMonitoring(intervalMs?: number, label?: string): NodeJS.Timeout;
|
|
39
|
+
/**
|
|
40
|
+
* Stop periodic monitoring
|
|
41
|
+
*/
|
|
42
|
+
stopPeriodicMonitoring(intervalId: NodeJS.Timeout): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get memory usage trend (last N measurements)
|
|
45
|
+
*/
|
|
46
|
+
getMemoryTrend(count?: number): MemoryStats[];
|
|
47
|
+
/**
|
|
48
|
+
* Check if memory usage is above threshold
|
|
49
|
+
*/
|
|
50
|
+
isMemoryUsageHigh(thresholdMB?: number): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get memory usage summary
|
|
53
|
+
*/
|
|
54
|
+
getMemorySummary(): {
|
|
55
|
+
current: MemoryStats;
|
|
56
|
+
average: {
|
|
57
|
+
rssInMB: number;
|
|
58
|
+
heapUsedInMB: number;
|
|
59
|
+
heapUtilization: number;
|
|
60
|
+
};
|
|
61
|
+
peak: {
|
|
62
|
+
rssInMB: number;
|
|
63
|
+
heapUsedInMB: number;
|
|
64
|
+
timestamp: Date;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Clear stored measurements
|
|
69
|
+
*/
|
|
70
|
+
clearMeasurements(): void;
|
|
71
|
+
static logMaxHeapSize(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Force garbage collection (if available)
|
|
74
|
+
*/
|
|
75
|
+
forceGarbageCollection(): void;
|
|
76
|
+
private static bytesToMB;
|
|
77
|
+
private addMeasurement;
|
|
78
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.MemoryMonitor = void 0;
|
|
27
|
+
const v8 = __importStar(require("v8"));
|
|
28
|
+
class MemoryMonitor {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.measurements = [];
|
|
31
|
+
this.maxMeasurements = 1000; // Keep last 1000 measurements
|
|
32
|
+
}
|
|
33
|
+
static getInstance() {
|
|
34
|
+
if (!MemoryMonitor.instance) {
|
|
35
|
+
MemoryMonitor.instance = new MemoryMonitor();
|
|
36
|
+
MemoryMonitor.logMaxHeapSize();
|
|
37
|
+
}
|
|
38
|
+
return MemoryMonitor.instance;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get current memory usage
|
|
42
|
+
*/
|
|
43
|
+
getCurrentMemoryUsage() {
|
|
44
|
+
return process.memoryUsage();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get detailed memory statistics
|
|
48
|
+
*/
|
|
49
|
+
getMemoryStats() {
|
|
50
|
+
const usage = this.getCurrentMemoryUsage();
|
|
51
|
+
const heapUtilization = (usage.heapUsed / usage.heapTotal) * 100;
|
|
52
|
+
const stats = {
|
|
53
|
+
timestamp: new Date(),
|
|
54
|
+
usage,
|
|
55
|
+
heapUtilization,
|
|
56
|
+
rssInMB: MemoryMonitor.bytesToMB(usage.rss),
|
|
57
|
+
heapUsedInMB: MemoryMonitor.bytesToMB(usage.heapUsed),
|
|
58
|
+
heapTotalInMB: MemoryMonitor.bytesToMB(usage.heapTotal),
|
|
59
|
+
};
|
|
60
|
+
this.addMeasurement(stats);
|
|
61
|
+
return stats;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Log current memory usage to console
|
|
65
|
+
*/
|
|
66
|
+
logMemoryUsage(label) {
|
|
67
|
+
const stats = this.getMemoryStats();
|
|
68
|
+
const prefix = label ? `[${label}] ` : "";
|
|
69
|
+
console.log(`${prefix}Memory Usage:`, {
|
|
70
|
+
RSS: `${stats.rssInMB.toFixed(2)} MB`,
|
|
71
|
+
"Heap Used": `${stats.heapUsedInMB.toFixed(2)} MB`,
|
|
72
|
+
"Heap Total": `${stats.heapTotalInMB.toFixed(2)} MB`,
|
|
73
|
+
"Heap Utilization": `${stats.heapUtilization.toFixed(2)}%`,
|
|
74
|
+
External: `${MemoryMonitor.bytesToMB(stats.usage.external).toFixed(2)} MB`,
|
|
75
|
+
"Array Buffers": `${MemoryMonitor.bytesToMB(stats.usage.arrayBuffers).toFixed(2)} MB`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Monitor memory usage over time with periodic logging
|
|
80
|
+
*/
|
|
81
|
+
startPeriodicMonitoring(intervalMs = 30000, label) {
|
|
82
|
+
return setInterval(() => {
|
|
83
|
+
this.logMemoryUsage(label);
|
|
84
|
+
}, intervalMs);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Stop periodic monitoring
|
|
88
|
+
*/
|
|
89
|
+
stopPeriodicMonitoring(intervalId) {
|
|
90
|
+
clearInterval(intervalId);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get memory usage trend (last N measurements)
|
|
94
|
+
*/
|
|
95
|
+
getMemoryTrend(count = 10) {
|
|
96
|
+
return this.measurements.slice(-count);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if memory usage is above threshold
|
|
100
|
+
*/
|
|
101
|
+
isMemoryUsageHigh(thresholdMB = 500) {
|
|
102
|
+
const stats = this.getMemoryStats();
|
|
103
|
+
return stats.rssInMB > thresholdMB;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get memory usage summary
|
|
107
|
+
*/
|
|
108
|
+
getMemorySummary() {
|
|
109
|
+
const current = this.getMemoryStats();
|
|
110
|
+
if (this.measurements.length === 0) {
|
|
111
|
+
return {
|
|
112
|
+
current,
|
|
113
|
+
average: {
|
|
114
|
+
rssInMB: current.rssInMB,
|
|
115
|
+
heapUsedInMB: current.heapUsedInMB,
|
|
116
|
+
heapUtilization: current.heapUtilization,
|
|
117
|
+
},
|
|
118
|
+
peak: {
|
|
119
|
+
rssInMB: current.rssInMB,
|
|
120
|
+
heapUsedInMB: current.heapUsedInMB,
|
|
121
|
+
timestamp: current.timestamp,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const avgRss = this.measurements.reduce((sum, m) => sum + m.rssInMB, 0) / this.measurements.length;
|
|
126
|
+
const avgHeapUsed = this.measurements.reduce((sum, m) => sum + m.heapUsedInMB, 0) / this.measurements.length;
|
|
127
|
+
const avgHeapUtilization = this.measurements.reduce((sum, m) => sum + m.heapUtilization, 0) / this.measurements.length;
|
|
128
|
+
const peak = this.measurements.reduce((max, m) => (m.rssInMB > max.rssInMB ? m : max), this.measurements[0]);
|
|
129
|
+
return {
|
|
130
|
+
current,
|
|
131
|
+
average: {
|
|
132
|
+
rssInMB: avgRss,
|
|
133
|
+
heapUsedInMB: avgHeapUsed,
|
|
134
|
+
heapUtilization: avgHeapUtilization,
|
|
135
|
+
},
|
|
136
|
+
peak: {
|
|
137
|
+
rssInMB: peak.rssInMB,
|
|
138
|
+
heapUsedInMB: peak.heapUsedInMB,
|
|
139
|
+
timestamp: peak.timestamp,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Clear stored measurements
|
|
145
|
+
*/
|
|
146
|
+
clearMeasurements() {
|
|
147
|
+
this.measurements = [];
|
|
148
|
+
}
|
|
149
|
+
static logMaxHeapSize() {
|
|
150
|
+
console.log("Max heap size (MB):", this.bytesToMB(v8.getHeapStatistics().heap_size_limit));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Force garbage collection (if available)
|
|
154
|
+
*/
|
|
155
|
+
forceGarbageCollection() {
|
|
156
|
+
if (global.gc) {
|
|
157
|
+
global.gc();
|
|
158
|
+
console.log("Garbage collection triggered");
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.log("Garbage collection not available. Run with --expose-gc flag");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
static bytesToMB(bytes) {
|
|
165
|
+
return bytes / (1024 * 1024);
|
|
166
|
+
}
|
|
167
|
+
addMeasurement(stats) {
|
|
168
|
+
this.measurements.push(stats);
|
|
169
|
+
// Keep only the last N measurements
|
|
170
|
+
if (this.measurements.length > this.maxMeasurements) {
|
|
171
|
+
this.measurements = this.measurements.slice(-this.maxMeasurements);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.MemoryMonitor = MemoryMonitor;
|
|
176
|
+
//# sourceMappingURL=MemoryMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryMonitor.js","sourceRoot":"","sources":["../../../../src/helpers/tools/memory/MemoryMonitor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAmBzB,MAAa,aAAa;IAKtB;QAHQ,iBAAY,GAAkB,EAAE,CAAC;QACjC,oBAAe,GAAW,IAAI,CAAC,CAAC,8BAA8B;IAE/C,CAAC;IAEjB,MAAM,CAAC,WAAW;QACrB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YACzB,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;YAC7C,aAAa,CAAC,cAAc,EAAE,CAAC;SAClC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,qBAAqB;QACxB,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,cAAc;QACjB,MAAM,KAAK,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3C,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC;QAEjE,MAAM,KAAK,GAAgB;YACvB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,KAAK;YACL,eAAe;YACf,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;YAC3C,YAAY,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC;YACrD,aAAa,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC;SAC1D,CAAC;QAEF,IAAI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AK,CAAC,CAAC;QAE9B,oCAAoC;QACpC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE;YACjD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SACtE;IACL,CAAC;CACJ;AApLD,sCAoLC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator to monitor memory usage before and after method execution
|
|
3
|
+
*/
|
|
4
|
+
export declare function MonitorMemory(label?: string): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to monitor memory usage with custom thresholds
|
|
7
|
+
*/
|
|
8
|
+
export declare function MonitorMemoryWithThreshold(thresholdMB?: number, label?: string): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MonitorMemoryWithThreshold = exports.MonitorMemory = void 0;
|
|
4
|
+
const MemoryMonitor_1 = require("./MemoryMonitor");
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to monitor memory usage before and after method execution
|
|
7
|
+
*/
|
|
8
|
+
function MonitorMemory(label) {
|
|
9
|
+
return function (target, propertyName, descriptor) {
|
|
10
|
+
const method = descriptor.value;
|
|
11
|
+
descriptor.value = async function (...args) {
|
|
12
|
+
const monitor = MemoryMonitor_1.MemoryMonitor.getInstance();
|
|
13
|
+
const methodLabel = label || `${target.constructor.name}.${propertyName}`;
|
|
14
|
+
// Log memory before execution
|
|
15
|
+
console.log(`[${methodLabel}] Starting execution...`);
|
|
16
|
+
monitor.logMemoryUsage(`${methodLabel} - Before`);
|
|
17
|
+
const startTime = Date.now();
|
|
18
|
+
const startMemory = monitor.getMemoryStats();
|
|
19
|
+
try {
|
|
20
|
+
// Execute the original method
|
|
21
|
+
const result = await method.apply(this, args);
|
|
22
|
+
const endTime = Date.now();
|
|
23
|
+
const endMemory = monitor.getMemoryStats();
|
|
24
|
+
const executionTime = endTime - startTime;
|
|
25
|
+
// Calculate memory differences
|
|
26
|
+
const memoryDiff = {
|
|
27
|
+
rssDiff: endMemory.rssInMB - startMemory.rssInMB,
|
|
28
|
+
heapUsedDiff: endMemory.heapUsedInMB - startMemory.heapUsedInMB,
|
|
29
|
+
heapTotalDiff: endMemory.heapTotalInMB - startMemory.heapTotalInMB,
|
|
30
|
+
};
|
|
31
|
+
// Log memory after execution
|
|
32
|
+
console.log(`[${methodLabel}] Execution completed in ${executionTime}ms`);
|
|
33
|
+
monitor.logMemoryUsage(`${methodLabel} - After`);
|
|
34
|
+
console.log(`[${methodLabel}] Memory Changes:`, {
|
|
35
|
+
"RSS Change": `${memoryDiff.rssDiff > 0 ? "+" : ""}${memoryDiff.rssDiff.toFixed(2)} MB`,
|
|
36
|
+
"Heap Used Change": `${memoryDiff.heapUsedDiff > 0 ? "+" : ""}${memoryDiff.heapUsedDiff.toFixed(2)} MB`,
|
|
37
|
+
"Heap Total Change": `${memoryDiff.heapTotalDiff > 0 ? "+" : ""}${memoryDiff.heapTotalDiff.toFixed(2)} MB`,
|
|
38
|
+
"Execution Time": `${executionTime}ms`,
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const endTime = Date.now();
|
|
44
|
+
const endMemory = monitor.getMemoryStats();
|
|
45
|
+
const executionTime = endTime - startTime;
|
|
46
|
+
console.log(`[${methodLabel}] Execution failed after ${executionTime}ms`);
|
|
47
|
+
monitor.logMemoryUsage(`${methodLabel} - After Error`);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.MonitorMemory = MonitorMemory;
|
|
54
|
+
/**
|
|
55
|
+
* Decorator to monitor memory usage with custom thresholds
|
|
56
|
+
*/
|
|
57
|
+
function MonitorMemoryWithThreshold(thresholdMB = 500, label) {
|
|
58
|
+
return function (target, propertyName, descriptor) {
|
|
59
|
+
const method = descriptor.value;
|
|
60
|
+
descriptor.value = async function (...args) {
|
|
61
|
+
const monitor = MemoryMonitor_1.MemoryMonitor.getInstance();
|
|
62
|
+
const methodLabel = label || `${target.constructor.name}.${propertyName}`;
|
|
63
|
+
const startMemory = monitor.getMemoryStats();
|
|
64
|
+
// Check if memory usage is already high
|
|
65
|
+
if (startMemory.rssInMB > thresholdMB) {
|
|
66
|
+
console.warn(`[${methodLabel}] WARNING: High memory usage detected before execution: ${startMemory.rssInMB.toFixed(2)} MB`);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const result = await method.apply(this, args);
|
|
70
|
+
const endMemory = monitor.getMemoryStats();
|
|
71
|
+
// Check memory usage after execution
|
|
72
|
+
if (endMemory.rssInMB > thresholdMB) {
|
|
73
|
+
console.warn(`[${methodLabel}] WARNING: High memory usage detected after execution: ${endMemory.rssInMB.toFixed(2)} MB`);
|
|
74
|
+
// Log memory summary if usage is high
|
|
75
|
+
const summary = monitor.getMemorySummary();
|
|
76
|
+
console.log(`[${methodLabel}] Memory Summary:`, {
|
|
77
|
+
"Current RSS": `${summary.current.rssInMB.toFixed(2)} MB`,
|
|
78
|
+
"Peak RSS": `${summary.peak.rssInMB.toFixed(2)} MB`,
|
|
79
|
+
"Average RSS": `${summary.average.rssInMB.toFixed(2)} MB`,
|
|
80
|
+
"Heap Utilization": `${summary.current.heapUtilization.toFixed(2)}%`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const endMemory = monitor.getMemoryStats();
|
|
87
|
+
if (endMemory.rssInMB > thresholdMB) {
|
|
88
|
+
console.warn(`[${methodLabel}] WARNING: High memory usage detected after error: ${endMemory.rssInMB.toFixed(2)} MB`);
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
exports.MonitorMemoryWithThreshold = MonitorMemoryWithThreshold;
|
|
96
|
+
//# sourceMappingURL=MemoryMonitoringDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryMonitoringDecorator.js","sourceRoot":"","sources":["../../../../src/helpers/tools/memory/MemoryMonitoringDecorator.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAEhD;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc;IACxC,OAAO,UAAU,MAAW,EAAE,YAAoB,EAAE,UAA8B;QAC9E,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;QAEhC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAC7C,MAAM,OAAO,GAAG,6BAAa,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,WAAW,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,YAAY,EAAE,CAAC;YAE1E,8BAA8B;YAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,WAAW,yBAAyB,CAAC,CAAC;YACtD,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,WAAW,CAAC,CAAC;YAElD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;YAE7C,IAAI;gBACA,8BAA8B;gBAC9B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE9C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC3B,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;gBAC3C,MAAM,aAAa,GAAG,OAAO,GAAG,SAAS,CAAC;gBAE1C,+BAA+B;gBAC/B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AC3C,OAAO,CAAC,GAAG,CAAC,IAAI,WAAW,mBAAmB,EAAE;wBAC5C,aAAa,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;wBACzD,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;wBACnD,aAAa,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;wBACzD,kBAAkB,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;qBACvE,CAAC,CAAC;iBACN;gBAED,OAAO,MAAM,CAAC;aACjB;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;gBAE3C,IAAI,SAAS,CAAC,OAAO,GAAG,WAAW,EAAE;oBACjC,OAAO,CAAC,IAAI,CACR,IAAI,WAAW,sDAAsD,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CACzG,CAAC;iBACL;gBAED,MAAM,KAAK,CAAC;aACf;QACL,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AApDD,gEAoDC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example 1: Basic memory monitoring in a worker task
|
|
3
|
+
*/
|
|
4
|
+
export declare class ExampleWorkerTask {
|
|
5
|
+
processData(data: any[]): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Example 2: Memory monitoring with threshold warnings
|
|
9
|
+
*/
|
|
10
|
+
export declare class ExampleDataProcessor {
|
|
11
|
+
transformLargeDataset(data: any[]): Promise<any[]>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Example 3: Manual memory monitoring
|
|
15
|
+
*/
|
|
16
|
+
export declare class ExampleManualMonitoring {
|
|
17
|
+
processWithManualMonitoring(data: any[]): Promise<void>;
|
|
18
|
+
private processChunk;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Example 4: Periodic memory monitoring
|
|
22
|
+
*/
|
|
23
|
+
export declare class ExamplePeriodicMonitoring {
|
|
24
|
+
private monitoringInterval?;
|
|
25
|
+
startMonitoring(): void;
|
|
26
|
+
stopMonitoring(): void;
|
|
27
|
+
longRunningTask(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Example 5: Memory monitoring in API endpoints
|
|
31
|
+
*/
|
|
32
|
+
export declare class ExampleApiController {
|
|
33
|
+
getParkingData(parkingId: string): Promise<any>;
|
|
34
|
+
private fetchParkingData;
|
|
35
|
+
private transformParkingData;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Example 6: Memory leak detection
|
|
39
|
+
*/
|
|
40
|
+
export declare class ExampleMemoryLeakDetection {
|
|
41
|
+
private cache;
|
|
42
|
+
processWithCache(key: string, data: any): Promise<void>;
|
|
43
|
+
clearCache(): void;
|
|
44
|
+
private processData;
|
|
45
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ExampleMemoryLeakDetection = exports.ExampleApiController = exports.ExamplePeriodicMonitoring = exports.ExampleManualMonitoring = exports.ExampleDataProcessor = exports.ExampleWorkerTask = void 0;
|
|
13
|
+
const index_1 = require("../index");
|
|
14
|
+
/**
|
|
15
|
+
* Example 1: Basic memory monitoring in a worker task
|
|
16
|
+
*/
|
|
17
|
+
class ExampleWorkerTask {
|
|
18
|
+
async processData(data) {
|
|
19
|
+
// Simulate data processing
|
|
20
|
+
const processedData = data.map((item) => ({
|
|
21
|
+
...item,
|
|
22
|
+
processed: true,
|
|
23
|
+
timestamp: new Date(),
|
|
24
|
+
}));
|
|
25
|
+
// Simulate some memory-intensive operation
|
|
26
|
+
const largeArray = new Array(1000000).fill(0);
|
|
27
|
+
console.log(`Processed ${processedData.length} items`);
|
|
28
|
+
// Clean up
|
|
29
|
+
largeArray.length = 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ExampleWorkerTask = ExampleWorkerTask;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, index_1.MonitorMemory)("ExampleWorkerTask.processData"),
|
|
35
|
+
__metadata("design:type", Function),
|
|
36
|
+
__metadata("design:paramtypes", [Array]),
|
|
37
|
+
__metadata("design:returntype", Promise)
|
|
38
|
+
], ExampleWorkerTask.prototype, "processData", null);
|
|
39
|
+
/**
|
|
40
|
+
* Example 2: Memory monitoring with threshold warnings
|
|
41
|
+
*/
|
|
42
|
+
class ExampleDataProcessor {
|
|
43
|
+
async transformLargeDataset(data) {
|
|
44
|
+
// This will trigger warnings if memory usage exceeds 100MB
|
|
45
|
+
const transformed = data.map((item) => ({
|
|
46
|
+
...item,
|
|
47
|
+
transformed: true,
|
|
48
|
+
metadata: {
|
|
49
|
+
processedAt: new Date(),
|
|
50
|
+
version: "1.0",
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
return transformed;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ExampleDataProcessor = ExampleDataProcessor;
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, index_1.MonitorMemoryWithThreshold)(100, "ExampleDataProcessor.transformLargeDataset"),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", [Array]),
|
|
61
|
+
__metadata("design:returntype", Promise)
|
|
62
|
+
], ExampleDataProcessor.prototype, "transformLargeDataset", null);
|
|
63
|
+
/**
|
|
64
|
+
* Example 3: Manual memory monitoring
|
|
65
|
+
*/
|
|
66
|
+
class ExampleManualMonitoring {
|
|
67
|
+
async processWithManualMonitoring(data) {
|
|
68
|
+
const monitor = index_1.MemoryMonitor.getInstance();
|
|
69
|
+
// Log initial memory state
|
|
70
|
+
monitor.logMemoryUsage("Before processing");
|
|
71
|
+
// Process data in chunks to monitor memory
|
|
72
|
+
const chunkSize = 1000;
|
|
73
|
+
for (let i = 0; i < data.length; i += chunkSize) {
|
|
74
|
+
const chunk = data.slice(i, i + chunkSize);
|
|
75
|
+
// Process chunk
|
|
76
|
+
await this.processChunk(chunk);
|
|
77
|
+
// Check memory every 10 chunks
|
|
78
|
+
if (i % (chunkSize * 10) === 0) {
|
|
79
|
+
monitor.logMemoryUsage(`After processing ${i + chunk.length} items`);
|
|
80
|
+
// Force garbage collection if memory usage is high
|
|
81
|
+
if (monitor.isMemoryUsageHigh(200)) {
|
|
82
|
+
console.log("High memory usage detected, triggering garbage collection...");
|
|
83
|
+
monitor.forceGarbageCollection();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Final memory check
|
|
88
|
+
monitor.logMemoryUsage("After processing");
|
|
89
|
+
// Get memory summary
|
|
90
|
+
const summary = monitor.getMemorySummary();
|
|
91
|
+
console.log("Final Memory Summary:", {
|
|
92
|
+
"Peak RSS": `${summary.peak.rssInMB.toFixed(2)} MB`,
|
|
93
|
+
"Average RSS": `${summary.average.rssInMB.toFixed(2)} MB`,
|
|
94
|
+
"Current Heap Utilization": `${summary.current.heapUtilization.toFixed(2)}%`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async processChunk(chunk) {
|
|
98
|
+
// Simulate chunk processing
|
|
99
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ExampleManualMonitoring = ExampleManualMonitoring;
|
|
103
|
+
/**
|
|
104
|
+
* Example 4: Periodic memory monitoring
|
|
105
|
+
*/
|
|
106
|
+
class ExamplePeriodicMonitoring {
|
|
107
|
+
startMonitoring() {
|
|
108
|
+
const monitor = index_1.MemoryMonitor.getInstance();
|
|
109
|
+
// Start periodic monitoring every 30 seconds
|
|
110
|
+
this.monitoringInterval = monitor.startPeriodicMonitoring(30000, "PeriodicMonitor");
|
|
111
|
+
console.log("Periodic memory monitoring started (every 30 seconds)");
|
|
112
|
+
}
|
|
113
|
+
stopMonitoring() {
|
|
114
|
+
if (this.monitoringInterval) {
|
|
115
|
+
const monitor = index_1.MemoryMonitor.getInstance();
|
|
116
|
+
monitor.stopPeriodicMonitoring(this.monitoringInterval);
|
|
117
|
+
this.monitoringInterval = undefined;
|
|
118
|
+
console.log("Periodic memory monitoring stopped");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async longRunningTask() {
|
|
122
|
+
// Start monitoring
|
|
123
|
+
this.startMonitoring();
|
|
124
|
+
try {
|
|
125
|
+
// Simulate long-running task
|
|
126
|
+
for (let i = 0; i < 10; i++) {
|
|
127
|
+
console.log(`Processing batch ${i + 1}/10`);
|
|
128
|
+
// Simulate work
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
130
|
+
// Create some temporary data
|
|
131
|
+
const tempData = new Array(10000).fill(0).map((_, index) => ({
|
|
132
|
+
id: index,
|
|
133
|
+
data: `item-${index}`,
|
|
134
|
+
timestamp: new Date(),
|
|
135
|
+
}));
|
|
136
|
+
// Clean up
|
|
137
|
+
tempData.length = 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
// Stop monitoring
|
|
142
|
+
this.stopMonitoring();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.ExamplePeriodicMonitoring = ExamplePeriodicMonitoring;
|
|
147
|
+
/**
|
|
148
|
+
* Example 5: Memory monitoring in API endpoints
|
|
149
|
+
*/
|
|
150
|
+
class ExampleApiController {
|
|
151
|
+
async getParkingData(parkingId) {
|
|
152
|
+
// Simulate API call with memory monitoring
|
|
153
|
+
const data = await this.fetchParkingData(parkingId);
|
|
154
|
+
// Transform data
|
|
155
|
+
const transformed = this.transformParkingData(data);
|
|
156
|
+
return transformed;
|
|
157
|
+
}
|
|
158
|
+
async fetchParkingData(parkingId) {
|
|
159
|
+
// Simulate database query
|
|
160
|
+
return {
|
|
161
|
+
id: parkingId,
|
|
162
|
+
name: "Sample Parking",
|
|
163
|
+
capacity: 100,
|
|
164
|
+
occupied: 75,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
transformParkingData(data) {
|
|
168
|
+
return {
|
|
169
|
+
...data,
|
|
170
|
+
utilization: (data.occupied / data.capacity) * 100,
|
|
171
|
+
status: data.occupied > data.capacity * 0.9 ? "FULL" : "AVAILABLE",
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.ExampleApiController = ExampleApiController;
|
|
176
|
+
__decorate([
|
|
177
|
+
(0, index_1.MonitorMemory)("ApiController.getParkingData"),
|
|
178
|
+
__metadata("design:type", Function),
|
|
179
|
+
__metadata("design:paramtypes", [String]),
|
|
180
|
+
__metadata("design:returntype", Promise)
|
|
181
|
+
], ExampleApiController.prototype, "getParkingData", null);
|
|
182
|
+
/**
|
|
183
|
+
* Example 6: Memory leak detection
|
|
184
|
+
*/
|
|
185
|
+
class ExampleMemoryLeakDetection {
|
|
186
|
+
constructor() {
|
|
187
|
+
this.cache = new Map();
|
|
188
|
+
}
|
|
189
|
+
async processWithCache(key, data) {
|
|
190
|
+
// Simulate processing with caching
|
|
191
|
+
if (!this.cache.has(key)) {
|
|
192
|
+
this.cache.set(key, this.processData(data));
|
|
193
|
+
}
|
|
194
|
+
// Simulate work
|
|
195
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
196
|
+
}
|
|
197
|
+
clearCache() {
|
|
198
|
+
const monitor = index_1.MemoryMonitor.getInstance();
|
|
199
|
+
console.log("Clearing cache...");
|
|
200
|
+
monitor.logMemoryUsage("Before cache clear");
|
|
201
|
+
this.cache.clear();
|
|
202
|
+
// Force garbage collection
|
|
203
|
+
monitor.forceGarbageCollection();
|
|
204
|
+
monitor.logMemoryUsage("After cache clear");
|
|
205
|
+
}
|
|
206
|
+
processData(data) {
|
|
207
|
+
// Simulate data processing
|
|
208
|
+
return {
|
|
209
|
+
...data,
|
|
210
|
+
processed: true,
|
|
211
|
+
timestamp: new Date(),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.ExampleMemoryLeakDetection = ExampleMemoryLeakDetection;
|
|
216
|
+
__decorate([
|
|
217
|
+
(0, index_1.MonitorMemory)("MemoryLeakDetection.processWithCache"),
|
|
218
|
+
__metadata("design:type", Function),
|
|
219
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
220
|
+
__metadata("design:returntype", Promise)
|
|
221
|
+
], ExampleMemoryLeakDetection.prototype, "processWithCache", null);
|
|
222
|
+
//# sourceMappingURL=MemoryMonitoringExamples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryMonitoringExamples.js","sourceRoot":"","sources":["../../../../../src/helpers/tools/memory/examples/MemoryMonitoringExamples.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoF;AAEpF;;GAEG;AACH,MAAa,iBAAiB;IAEb,AAAN,KAAK,CAAC,WAAW,CAAC,IAAW;QAChC,2BAA2B;QAC3B,M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AChD,mCAAmC;QACnC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;SAC/C;QAED,gBAAgB;QAChB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,UAAU;QACb,MAAM,OAAO,GAAG,qBAAa,CAAC,WAAW,EAAE,CAAC;QAE5C,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACjC,OAAO,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QAE7C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAEnB,2BAA2B;QAC3B,OAAO,CAAC,sBAAsB,EAAE,CAAC;QAEjC,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAChD,CAAC;IAEO,WAAW,CAAC,IAAS;QACzB,2BAA2B;QAC3B,OAAO;YACH,GAAG,IAAI;YACP,SAAS,EAAE,IAAI;YACf,SAAS,EAAE,IAAI,IAAI,EAAE;SACxB,CAAC;IACN,CAAC;CACJ;AApCD,gEAoCC;AAhCgB;IADZ,IAAA,qBAAa,EAAC,sCAAsC,CAAC;;;;kEASrD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MonitorMemoryWithThreshold = exports.MonitorMemory = exports.MemoryMonitor = void 0;
|
|
4
|
+
var MemoryMonitor_1 = require("./MemoryMonitor");
|
|
5
|
+
Object.defineProperty(exports, "MemoryMonitor", { enumerable: true, get: function () { return MemoryMonitor_1.MemoryMonitor; } });
|
|
6
|
+
var MemoryMonitoringDecorator_1 = require("./MemoryMonitoringDecorator");
|
|
7
|
+
Object.defineProperty(exports, "MonitorMemory", { enumerable: true, get: function () { return MemoryMonitoringDecorator_1.MonitorMemory; } });
|
|
8
|
+
Object.defineProperty(exports, "MonitorMemoryWithThreshold", { enumerable: true, get: function () { return MemoryMonitoringDecorator_1.MonitorMemoryWithThreshold; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/helpers/tools/memory/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,yEAAwF;AAA/E,0HAAA,aAAa,OAAA;AAAE,uIAAA,0BAA0B,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "fast-csv";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("fast-csv"), exports);
|
|
18
|
+
//# sourceMappingURL=fast-csv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-csv.js","sourceRoot":"","sources":["../../src/shared/fast-csv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemio/core",
|
|
3
|
-
"version": "1.21.1-
|
|
3
|
+
"version": "1.21.1-rc.2016563575",
|
|
4
4
|
"description": "Golemio Core Module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"@azure/data-tables": "^13.3.0",
|
|
71
71
|
"@azure/identity": "^4.5.0",
|
|
72
72
|
"@azure/storage-blob": "^12.26.0",
|
|
73
|
-
"@golemio/errors": "2.0.
|
|
74
|
-
"@golemio/validator": "0.3.
|
|
73
|
+
"@golemio/errors": "2.0.6",
|
|
74
|
+
"@golemio/validator": "0.3.5",
|
|
75
75
|
"@google-cloud/storage": "^7.16.0",
|
|
76
76
|
"@opentelemetry/api": "^1.9.0",
|
|
77
77
|
"@opentelemetry/exporter-jaeger": "^2.0.1",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"express": "^4.21.2",
|
|
101
101
|
"express-validator": "^7.0.1",
|
|
102
102
|
"fast-csv": "^4.3.6",
|
|
103
|
+
"fast-glob": "^3.2.5",
|
|
103
104
|
"geojson": "^0.5.0",
|
|
104
105
|
"html-entities": "^2.4.0",
|
|
105
106
|
"iconv-lite": "^0.6.2",
|