@naman_deep_singh/utils 2.4.0 → 2.6.1
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 +228 -129
- package/dist/cjs/errors/CompressionError.js +19 -0
- package/dist/cjs/errors/ConnectionError.js +21 -0
- package/dist/cjs/errors/PoolError.js +20 -0
- package/dist/cjs/errors/TimeoutError.js +24 -0
- package/dist/cjs/errors/ValidationError.js +22 -0
- package/dist/cjs/errors/index.js +13 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/utils/compression.js +455 -0
- package/dist/cjs/utils/index.js +23 -2
- package/dist/cjs/utils/pool.js +375 -0
- package/dist/cjs/utils/timeout.js +133 -0
- package/dist/esm/errors/CompressionError.js +15 -0
- package/dist/esm/errors/ConnectionError.js +17 -0
- package/dist/esm/errors/PoolError.js +16 -0
- package/dist/esm/errors/TimeoutError.js +20 -0
- package/dist/esm/errors/ValidationError.js +18 -0
- package/dist/esm/errors/index.js +5 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/utils/compression.js +415 -0
- package/dist/esm/utils/index.js +13 -1
- package/dist/esm/utils/pool.js +370 -0
- package/dist/esm/utils/timeout.js +128 -0
- package/dist/types/errors/CompressionError.d.ts +8 -0
- package/dist/types/errors/ConnectionError.d.ts +9 -0
- package/dist/types/errors/PoolError.d.ts +8 -0
- package/dist/types/errors/TimeoutError.d.ts +12 -0
- package/dist/types/errors/ValidationError.d.ts +9 -0
- package/dist/types/errors/index.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/compression.d.ts +164 -0
- package/dist/types/utils/index.d.ts +8 -0
- package/dist/types/utils/pool.d.ts +157 -0
- package/dist/types/utils/timeout.d.ts +64 -0
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
+
```bash
|
|
1
2
|
@naman_deep_singh/utils
|
|
2
3
|
|
|
3
|
-
Version: 2.
|
|
4
|
+
**Version: 2.6.1**
|
|
4
5
|
|
|
5
|
-
Universal JavaScript prototype extensions for common development utilities. Works in both Node.js and browser environments with 70+ utility methods.
|
|
6
|
+
Universal JavaScript prototype extensions for common development utilities. Works in both Node.js and browser environments with 70+ utility methods, plus timeout management, connection pooling, and compression utilities.
|
|
6
7
|
|
|
7
|
-
⚠️ This library extends native prototypes (String, Array, Object, Number). Use consciously in shared or library code.
|
|
8
|
+
⚠️ Note: This library extends native prototypes (String, Array, Object, Number). Use consciously in shared or library code.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
What's New in v2.6.0
|
|
11
|
+
✨ New Utility Modules
|
|
12
|
+
Timeout Management: Async operations with timeout support, retry logic, and delays
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
Connection Pooling: Generic connection pooling with health checks and statistics
|
|
15
|
+
|
|
16
|
+
Compression Utilities: GZIP, Deflate, and Brotli compression with streaming support
|
|
17
|
+
|
|
18
|
+
Error Integration: Proper integration with @naman_deep_singh/errors package
|
|
19
|
+
|
|
20
|
+
Installation
|
|
21
|
+
bash
|
|
13
22
|
npm install @naman_deep_singh/utils
|
|
14
23
|
# or
|
|
15
24
|
pnpm add @naman_deep_singh/utils
|
|
16
25
|
Quick Start
|
|
26
|
+
1. Prototype Extensions
|
|
27
|
+
typescript
|
|
17
28
|
import { initializeExtensions } from '@naman_deep_singh/utils';
|
|
18
29
|
|
|
19
30
|
// Initialize all extensions
|
|
@@ -22,60 +33,142 @@ initializeExtensions();
|
|
|
22
33
|
// String utilities
|
|
23
34
|
"hello world".toCapitalize(); // "Hello world"
|
|
24
35
|
"hello world".capitalizeWords(); // "Hello World"
|
|
25
|
-
"hello world".reverseWords(); // "world hello"
|
|
26
|
-
"test@email.com".isEmail(); // true
|
|
27
|
-
"hello world".words(); // ["hello", "world"]
|
|
28
36
|
|
|
29
|
-
// Array utilities
|
|
37
|
+
// Array utilities
|
|
30
38
|
[1, 2, 2, 3].unique(); // [1, 2, 3]
|
|
31
39
|
[1, 2, 3, 4, 5].chunk(2); // [[1,2],[3,4],[5]]
|
|
32
|
-
[1, 2, 3].sample(); // random element
|
|
33
|
-
[1,2,3,4].last(); // 4
|
|
34
|
-
[{id:1},{id:2},{id:1}].uniqueBy(x => x.id); // [{id:1},{id:2}]
|
|
35
|
-
[3,1,2].sortBy(x => x); // [1,2,3]
|
|
36
40
|
|
|
37
41
|
// Number utilities
|
|
38
|
-
(42).toOrdinal();
|
|
39
|
-
(0.75).toPercent();
|
|
40
|
-
(3.14159).toFixedNumber(2); // 3.14
|
|
41
|
-
(5).randomUpTo(); // 0..5 random number
|
|
42
|
-
(5).times(i => console.log(i)); // 0..4
|
|
42
|
+
(42).toOrdinal(); // "42nd"
|
|
43
|
+
(0.75).toPercent(); // "75.00%"
|
|
43
44
|
|
|
44
45
|
// Object utilities
|
|
45
|
-
({ a: 1, b: 2 }).pick(['a']);
|
|
46
|
-
({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
({ a: 1, b: 2 }).pick(['a']); // { a: 1 }
|
|
47
|
+
({}).isEmpty(); // true
|
|
48
|
+
2. Timeout Utilities
|
|
49
|
+
typescript
|
|
50
|
+
import { TimeoutManager } from '@naman_deep_singh/utils';
|
|
51
|
+
|
|
52
|
+
// Execute promise with timeout
|
|
53
|
+
const result = await TimeoutManager.withTimeout(
|
|
54
|
+
fetchData(),
|
|
55
|
+
5000,
|
|
56
|
+
'Fetch operation timed out'
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// Create delay
|
|
60
|
+
await TimeoutManager.delay(1000);
|
|
61
|
+
|
|
62
|
+
// Retry with timeout
|
|
63
|
+
const data = await TimeoutManager.retryWithTimeout(fetchData, {
|
|
64
|
+
maxAttempts: 3,
|
|
65
|
+
timeoutPerAttempt: 3000,
|
|
66
|
+
backoffMultiplier: 2
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Decorator for class methods
|
|
70
|
+
class ApiService {
|
|
71
|
+
@withTimeout(5000)
|
|
72
|
+
async fetchUser(id: string) {
|
|
73
|
+
// Method automatically times out after 5s
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
3. Connection Pooling
|
|
77
|
+
typescript
|
|
78
|
+
import { GenericPool, PoolManager } from '@naman_deep_singh/utils';
|
|
79
|
+
|
|
80
|
+
// Create a database connection pool
|
|
81
|
+
const dbPool = new GenericPool({
|
|
82
|
+
name: 'database',
|
|
83
|
+
minConnections: 2,
|
|
84
|
+
maxConnections: 10,
|
|
85
|
+
createConnection: async () => {
|
|
86
|
+
return await createDatabaseConnection();
|
|
87
|
+
},
|
|
88
|
+
validateConnection: (conn) => conn.isHealthy()
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Acquire and use connection
|
|
92
|
+
const connection = await dbPool.acquire();
|
|
93
|
+
try {
|
|
94
|
+
await connection.query('SELECT * FROM users');
|
|
95
|
+
} finally {
|
|
96
|
+
await dbPool.release(connection);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Or use helper method
|
|
100
|
+
const users = await dbPool.withConnection(async (conn) => {
|
|
101
|
+
return await conn.query('SELECT * FROM users');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Pool statistics
|
|
105
|
+
console.log(dbPool.getStats());
|
|
106
|
+
4. Compression Utilities
|
|
107
|
+
typescript
|
|
108
|
+
import { Compression, CompressionAlgorithm } from '@naman_deep_singh/utils';
|
|
109
|
+
|
|
110
|
+
// Basic compression
|
|
111
|
+
const compressed = await Compression.compress('Hello World', {
|
|
112
|
+
algorithm: CompressionAlgorithm.GZIP,
|
|
113
|
+
level: 6
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const decompressed = await Compression.decompress(compressed);
|
|
117
|
+
|
|
118
|
+
// Compression with metrics
|
|
119
|
+
const result = await Compression.compressWithMetrics(largeData, {
|
|
120
|
+
algorithm: CompressionAlgorithm.BROTLI,
|
|
121
|
+
level: 9
|
|
122
|
+
});
|
|
123
|
+
console.log(result.compressionRatio); // 0.45 (55% reduction)
|
|
124
|
+
|
|
125
|
+
// Streaming compression
|
|
126
|
+
await Compression.compressStream(readableStream, writableStream);
|
|
127
|
+
|
|
128
|
+
// Check supported algorithms
|
|
129
|
+
const supported = Compression.getSupportedAlgorithms();
|
|
130
|
+
// ['gzip', 'deflate', 'brotli'] (if Node.js 10.16.0+)
|
|
131
|
+
5. Error Handling with Custom Errors
|
|
132
|
+
typescript
|
|
133
|
+
import {
|
|
134
|
+
TimeoutError,
|
|
135
|
+
PoolError,
|
|
136
|
+
CompressionError
|
|
137
|
+
} from '@naman_deep_singh/utils';
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
await TimeoutManager.withTimeout(slowOperation(), 1000);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error instanceof TimeoutError) {
|
|
143
|
+
console.log(`Timeout after ${error.timeoutMs}ms`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
52
146
|
Error Handling & Validation
|
|
53
|
-
|
|
147
|
+
Prototype Methods
|
|
148
|
+
All prototype extension methods include strict runtime validation and throw clear native errors.
|
|
54
149
|
|
|
150
|
+
typescript
|
|
55
151
|
"hello".count(123);
|
|
56
152
|
// TypeError: count: substring must be a string, got number
|
|
57
153
|
|
|
58
|
-
"hello".count("");
|
|
59
|
-
// TypeError: count: substring cannot be empty
|
|
60
|
-
|
|
61
154
|
[].sum();
|
|
62
155
|
// TypeError: sum: array must contain at least one number
|
|
63
156
|
|
|
64
|
-
({ a: 1 }).pick(null as any);
|
|
65
|
-
// TypeError: pick: keys must be an array, got object
|
|
66
|
-
|
|
67
157
|
(3.14).round(-1);
|
|
68
158
|
// TypeError: round: decimals must be a non-negative integer, got -1
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
159
|
+
Utility Errors
|
|
160
|
+
New utilities throw specific error classes from @naman_deep_singh/errors:
|
|
161
|
+
|
|
162
|
+
typescript
|
|
163
|
+
import {
|
|
164
|
+
TimeoutError, // Operation timeout (408)
|
|
165
|
+
PoolError, // Pool exhaustion (503)
|
|
166
|
+
ConnectionError, // Connection failure (502)
|
|
167
|
+
CompressionError // Compression failure (500)
|
|
168
|
+
} from '@naman_deep_singh/utils';
|
|
77
169
|
Configuration
|
|
78
170
|
Selective Extension Loading
|
|
171
|
+
typescript
|
|
79
172
|
import { initializeExtensions, extend } from '@naman_deep_singh/utils';
|
|
80
173
|
|
|
81
174
|
// Enable only specific prototypes
|
|
@@ -90,7 +183,7 @@ initializeExtensions({
|
|
|
90
183
|
extend.string();
|
|
91
184
|
extend.array();
|
|
92
185
|
Performance Configuration
|
|
93
|
-
|
|
186
|
+
typescript
|
|
94
187
|
import { setPerformanceConfig } from '@naman_deep_singh/utils';
|
|
95
188
|
|
|
96
189
|
setPerformanceConfig({
|
|
@@ -101,90 +194,64 @@ Notes:
|
|
|
101
194
|
|
|
102
195
|
Validation cannot be disabled
|
|
103
196
|
|
|
104
|
-
Caching is optional
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
197
|
+
Caching is optional (LRU cache)
|
|
198
|
+
|
|
199
|
+
Pool utilities have built-in health checks
|
|
200
|
+
|
|
201
|
+
API Reference
|
|
202
|
+
Timeout Utilities
|
|
203
|
+
typescript
|
|
204
|
+
TimeoutManager.withTimeout(promise, timeoutMs, errorMessage?);
|
|
205
|
+
TimeoutManager.delay(delayMs);
|
|
206
|
+
TimeoutManager.createTimeoutSignal(timeoutMs);
|
|
207
|
+
TimeoutManager.retryWithTimeout(fn, options);
|
|
208
|
+
TimeoutManager.raceWithTimeout(promises, timeoutMs);
|
|
209
|
+
Connection Pooling
|
|
210
|
+
typescript
|
|
211
|
+
GenericPool<T extends Connection> // Generic connection pool
|
|
212
|
+
PoolManager // Multi-pool manager
|
|
213
|
+
interface PoolConfig // Pool configuration
|
|
214
|
+
interface Connection // Connection interface
|
|
215
|
+
Compression Utilities
|
|
216
|
+
typescript
|
|
217
|
+
Compression.compress(data, options)
|
|
218
|
+
Compression.decompress(data, options)
|
|
219
|
+
Compression.compressWithMetrics(data, options)
|
|
220
|
+
Compression.createCompressionStream(algorithm, options)
|
|
221
|
+
Compression.createDecompressionStream(algorithm)
|
|
222
|
+
Compression.isAlgorithmSupported(algorithm)
|
|
223
|
+
Compression.getSupportedAlgorithms()
|
|
224
|
+
Prototype Extensions (Summary)
|
|
108
225
|
String Extensions (21 methods)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Validation & Checks
|
|
118
|
-
|
|
119
|
-
"test@example.com".isEmail(); // true
|
|
120
|
-
"https://example.com".isUrl(); // true
|
|
121
|
-
"racecar".isPalindrome(); // true
|
|
122
|
-
Text Utilities
|
|
123
|
-
|
|
124
|
-
"Long text here".truncate(8); // "Long tex..."
|
|
125
|
-
"hello world".truncateWords(1); // "hello..."
|
|
126
|
-
"hello world".removeWhitespace(); // "helloworld"
|
|
127
|
-
"<p>Hello</p>".stripHtml(); // "Hello"
|
|
128
|
-
"hello".reverse(); // "olleh"
|
|
129
|
-
"hello world".reverseWords(); // "world hello"
|
|
130
|
-
"hello hello".count("hello"); // 2
|
|
131
|
-
"Hello World".slugify(); // "hello-world"
|
|
132
|
-
"hello world".words(); // ["hello", "world"]
|
|
133
|
-
"hello\nworld".lines(); // ["hello","world"]
|
|
226
|
+
typescript
|
|
227
|
+
.toCapitalize() .capitalizeWords() .toCamelCase()
|
|
228
|
+
.toKebabCase() .toSnakeCase() .toTitleCase()
|
|
229
|
+
.isEmail() .isUrl() .isPalindrome()
|
|
230
|
+
.truncate() .truncateWords() .removeWhitespace()
|
|
231
|
+
.stripHtml() .reverse() .reverseWords()
|
|
232
|
+
.count() .slugify() .words()
|
|
233
|
+
.lines()
|
|
134
234
|
Array Extensions (23 methods)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
[0,1,false,2,"",3].compact(); // [1,2,3] removes null, undefined, false, and empty strings
|
|
142
|
-
[1,2,3,4].last(); // 4
|
|
143
|
-
[3,1,2].sortBy(x => x); // [1,2,3]
|
|
144
|
-
Math
|
|
145
|
-
|
|
146
|
-
[1,2,3].sum(); // 6
|
|
147
|
-
[1,2,3].average(); // 2
|
|
148
|
-
Advanced
|
|
149
|
-
|
|
150
|
-
users.groupBy(u => u.age);
|
|
151
|
-
users.pluck('name');
|
|
152
|
-
[1,2,3,4].partition(n => n % 2 === 0);
|
|
153
|
-
// [[2,4],[1,3]]
|
|
154
|
-
Set Operations
|
|
155
|
-
|
|
156
|
-
[1,2,3].difference([2]); // [1,3]
|
|
157
|
-
[1,2,3].intersection([2,3]); // [2,3]
|
|
158
|
-
[1,2,3].union([3,4]); // [1,2,3,4]
|
|
159
|
-
Object Extensions (13 methods)
|
|
160
|
-
({}).isEmpty(); // true
|
|
161
|
-
({ a: 1, b: 2 }).pick(['a']); // { a: 1 }
|
|
162
|
-
({ a: 1, b: 2 }).omit(['b']); // { a: 1 }
|
|
163
|
-
({ a: 1, b: 2 }).mapValues(v => v*2); // { a: 2, b: 4 }
|
|
164
|
-
({ a: 1, b: 2 }).mapKeys(k => k+"_"); // { a_:1, b_:2 }
|
|
165
|
-
({ a: 1, b: 2 }).filterKeys(k => k==='a'); // { a:1 }
|
|
166
|
-
({ a: 1, b: 2 }).filterValues(v => v===1); // { a:1 }
|
|
167
|
-
({ a: { b: 2 } }).deepClone();
|
|
168
|
-
({ a: { b: 2 } }).deepFreeze();
|
|
169
|
-
data.hasPath('user.profile.name');
|
|
170
|
-
data.getPath('user.profile.email', 'N/A');
|
|
171
|
-
data.setPath('user.profile.email', 'john@example.com');
|
|
235
|
+
typescript
|
|
236
|
+
.unique() .uniqueBy() .shuffle()
|
|
237
|
+
.chunk() .compact() .last()
|
|
238
|
+
.sortBy() .sum() .average()
|
|
239
|
+
.groupBy() .pluck() .partition()
|
|
240
|
+
.difference() .intersection() .union()
|
|
172
241
|
Number Extensions (19 methods)
|
|
173
|
-
|
|
174
|
-
(
|
|
175
|
-
(
|
|
176
|
-
(
|
|
177
|
-
(
|
|
178
|
-
(
|
|
179
|
-
|
|
180
|
-
(
|
|
181
|
-
(
|
|
182
|
-
(
|
|
183
|
-
(
|
|
184
|
-
(123).sign(); // 1
|
|
242
|
+
typescript
|
|
243
|
+
.toPercent() .toFixedNumber() .toCurrency()
|
|
244
|
+
.clamp() .inRange() .isPrime()
|
|
245
|
+
.factorial() .randomUpTo() .times()
|
|
246
|
+
.toOrdinal() .sign()
|
|
247
|
+
Object Extensions (13 methods)
|
|
248
|
+
typescript
|
|
249
|
+
.isEmpty() .pick() .omit()
|
|
250
|
+
.mapValues() .mapKeys() .filterKeys()
|
|
251
|
+
.filterValues() .deepClone() .deepFreeze()
|
|
252
|
+
.hasPath() .getPath() .setPath()
|
|
185
253
|
Caching Details
|
|
186
254
|
Cached Methods (when enabled):
|
|
187
|
-
|
|
188
255
|
Number.isPrime()
|
|
189
256
|
|
|
190
257
|
Number.factorial()
|
|
@@ -192,27 +259,59 @@ Number.factorial()
|
|
|
192
259
|
Number.toRoman()
|
|
193
260
|
|
|
194
261
|
Custom Caching:
|
|
195
|
-
|
|
262
|
+
typescript
|
|
196
263
|
import { withCache } from '@naman_deep_singh/utils';
|
|
197
264
|
const result = withCache('key', () => expensiveFn());
|
|
265
|
+
Pool Health Checks:
|
|
266
|
+
Automatic idle connection cleanup
|
|
267
|
+
|
|
268
|
+
Maximum lifetime enforcement
|
|
269
|
+
|
|
270
|
+
Periodic health validation
|
|
271
|
+
|
|
272
|
+
Statistics tracking
|
|
273
|
+
|
|
198
274
|
TypeScript Support
|
|
199
|
-
Full
|
|
275
|
+
Full TypeScript support with:
|
|
276
|
+
|
|
277
|
+
Complete global augmentation
|
|
200
278
|
|
|
201
279
|
Strict typing for all methods
|
|
202
280
|
|
|
203
281
|
Zero any leakage in public APIs
|
|
204
282
|
|
|
205
|
-
|
|
283
|
+
Proper type imports/exports
|
|
284
|
+
|
|
285
|
+
typescript
|
|
286
|
+
const x: number[] = [1, 2, 2].unique();
|
|
206
287
|
const y: string = "hello".toCapitalize();
|
|
288
|
+
const z: CompressionResult = await compressWithMetrics(data);
|
|
207
289
|
Package Stats
|
|
208
|
-
|
|
290
|
+
70+ prototype utility methods
|
|
291
|
+
|
|
292
|
+
Timeout management utilities
|
|
293
|
+
|
|
294
|
+
Generic connection pooling
|
|
295
|
+
|
|
296
|
+
Multi-algorithm compression
|
|
209
297
|
|
|
210
|
-
Zero dependencies
|
|
298
|
+
Zero production dependencies (except peer deps)
|
|
211
299
|
|
|
212
|
-
Node.js + Browser
|
|
300
|
+
Node.js + Browser compatibility
|
|
213
301
|
|
|
214
|
-
TypeScript-first
|
|
302
|
+
TypeScript-first design
|
|
215
303
|
|
|
216
304
|
Optional LRU caching
|
|
217
305
|
|
|
218
|
-
Strict runtime validation
|
|
306
|
+
Strict runtime validation
|
|
307
|
+
|
|
308
|
+
Dependencies
|
|
309
|
+
json
|
|
310
|
+
{
|
|
311
|
+
"peerDependencies": {
|
|
312
|
+
"@naman_deep_singh/errors": "^2.3.0"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
License
|
|
316
|
+
ISC © Naman Deep Singh
|
|
317
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompressionError = void 0;
|
|
4
|
+
const errors_1 = require("@naman_deep_singh/errors");
|
|
5
|
+
/**
|
|
6
|
+
* Compression error - when compression/decompression fails
|
|
7
|
+
*/
|
|
8
|
+
class CompressionError extends errors_1.AppError {
|
|
9
|
+
constructor(message, algorithm, details, cause) {
|
|
10
|
+
super(errors_1.ERROR_CODES.FILE_ERROR, 500, {
|
|
11
|
+
message,
|
|
12
|
+
algorithm,
|
|
13
|
+
...(details ? { details } : {}),
|
|
14
|
+
}, cause);
|
|
15
|
+
this.algorithm = algorithm;
|
|
16
|
+
this.name = 'CompressionError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CompressionError = CompressionError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Connection error - when connection fails
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ConnectionError = void 0;
|
|
8
|
+
const errors_1 = require("@naman_deep_singh/errors");
|
|
9
|
+
class ConnectionError extends errors_1.AppError {
|
|
10
|
+
constructor(message, endpoint, details, cause) {
|
|
11
|
+
super(errors_1.ERROR_CODES.DEPENDENCY_FAILURE, 502, // 502 = Bad Gateway
|
|
12
|
+
{
|
|
13
|
+
message,
|
|
14
|
+
endpoint,
|
|
15
|
+
...(details ? { details } : {}),
|
|
16
|
+
}, cause);
|
|
17
|
+
this.endpoint = endpoint;
|
|
18
|
+
this.name = 'ConnectionError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ConnectionError = ConnectionError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PoolError = void 0;
|
|
4
|
+
const errors_1 = require("@naman_deep_singh/errors");
|
|
5
|
+
/**
|
|
6
|
+
* Pool error - when pool operations fail
|
|
7
|
+
*/
|
|
8
|
+
class PoolError extends errors_1.AppError {
|
|
9
|
+
constructor(message, poolName, details, cause) {
|
|
10
|
+
super(errors_1.ERROR_CODES.RESOURCE_EXHAUSTED, 503, // 503 = Service Unavailable
|
|
11
|
+
{
|
|
12
|
+
message,
|
|
13
|
+
poolName,
|
|
14
|
+
...(details ? { details } : {}),
|
|
15
|
+
}, cause);
|
|
16
|
+
this.poolName = poolName;
|
|
17
|
+
this.name = 'PoolError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PoolError = PoolError;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility-specific error classes
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.TimeoutError = void 0;
|
|
8
|
+
const errors_1 = require("@naman_deep_singh/errors");
|
|
9
|
+
/**
|
|
10
|
+
* Timeout error - when operation times out
|
|
11
|
+
*/
|
|
12
|
+
class TimeoutError extends errors_1.AppError {
|
|
13
|
+
constructor(message = 'Operation timed out', timeoutMs, details, cause) {
|
|
14
|
+
super(errors_1.ERROR_CODES.TIMEOUT_ERROR, 408, // 408 = Request Timeout
|
|
15
|
+
{
|
|
16
|
+
message,
|
|
17
|
+
timeoutMs,
|
|
18
|
+
...(details ? { details } : {}),
|
|
19
|
+
}, cause);
|
|
20
|
+
this.timeoutMs = timeoutMs;
|
|
21
|
+
this.name = 'TimeoutError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TimeoutError = TimeoutError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = void 0;
|
|
4
|
+
const errors_1 = require("@naman_deep_singh/errors");
|
|
5
|
+
/**
|
|
6
|
+
* Validation error - when utility input validation fails
|
|
7
|
+
*/
|
|
8
|
+
class ValidationError extends errors_1.AppError {
|
|
9
|
+
constructor(message, field, value, details, cause) {
|
|
10
|
+
super(errors_1.ERROR_CODES.VALIDATION_FAILED, 400, // 400 = Bad Request
|
|
11
|
+
{
|
|
12
|
+
message,
|
|
13
|
+
field,
|
|
14
|
+
value,
|
|
15
|
+
...(details ? { details } : {}),
|
|
16
|
+
}, cause);
|
|
17
|
+
this.field = field;
|
|
18
|
+
this.value = value;
|
|
19
|
+
this.name = 'ValidationError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ValidationError = ValidationError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = exports.TimeoutError = exports.PoolError = exports.ConnectionError = exports.CompressionError = void 0;
|
|
4
|
+
var CompressionError_js_1 = require("./CompressionError.js");
|
|
5
|
+
Object.defineProperty(exports, "CompressionError", { enumerable: true, get: function () { return CompressionError_js_1.CompressionError; } });
|
|
6
|
+
var ConnectionError_js_1 = require("./ConnectionError.js");
|
|
7
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return ConnectionError_js_1.ConnectionError; } });
|
|
8
|
+
var PoolError_js_1 = require("./PoolError.js");
|
|
9
|
+
Object.defineProperty(exports, "PoolError", { enumerable: true, get: function () { return PoolError_js_1.PoolError; } });
|
|
10
|
+
var TimeoutError_js_1 = require("./TimeoutError.js");
|
|
11
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return TimeoutError_js_1.TimeoutError; } });
|
|
12
|
+
var ValidationError_js_1 = require("./ValidationError.js");
|
|
13
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return ValidationError_js_1.ValidationError; } });
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,5 +27,7 @@ __exportStar(require("./utils/index.js"), exports);
|
|
|
27
27
|
// Initialization & setup
|
|
28
28
|
__exportStar(require("./init/index.js"), exports);
|
|
29
29
|
__exportStar(require("./extensions/index.js"), exports);
|
|
30
|
+
// Error handling
|
|
31
|
+
__exportStar(require("./errors/index.js"), exports);
|
|
30
32
|
// Types
|
|
31
33
|
__exportStar(require("./types/index.js"), exports);
|