eip-cloud-services 1.1.1 → 1.1.3
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/package.json +1 -1
- package/src/redis.js +18 -18
- package/src/s3.js +39 -0
package/package.json
CHANGED
package/src/redis.js
CHANGED
|
@@ -119,7 +119,7 @@ exports.keys = async ( pattern ) => {
|
|
|
119
119
|
if ( typeof pattern === 'string' ) {
|
|
120
120
|
const client = await getClient ();
|
|
121
121
|
|
|
122
|
-
const fullPattern = pattern.startsWith ( config?.redis?.prefix ) ? pattern : config?.redis?.prefix + pattern;
|
|
122
|
+
const fullPattern = ( !config?.redis?.prefix || pattern.startsWith ( config?.redis?.prefix ) ) ? pattern : config?.redis?.prefix + pattern;
|
|
123
123
|
|
|
124
124
|
// Use the keys method directly instead of sendCommand
|
|
125
125
|
return await client.keys ( fullPattern );
|
|
@@ -150,7 +150,7 @@ exports.scan = async ( cursor, matchPattern = '*', count = 100 ) => {
|
|
|
150
150
|
try {
|
|
151
151
|
const client = await getClient ();
|
|
152
152
|
|
|
153
|
-
const fullMatchPattern = matchPattern.startsWith ( config?.redis?.prefix ) ? matchPattern : config?.redis?.prefix + matchPattern;
|
|
153
|
+
const fullMatchPattern = ( !config?.redis?.prefix || matchPattern.startsWith ( config?.redis?.prefix ) ) ? matchPattern : config?.redis?.prefix + matchPattern;
|
|
154
154
|
|
|
155
155
|
// Directly use the scan method provided by ioredis
|
|
156
156
|
const result = await client.scan ( cursor, 'MATCH', fullMatchPattern, 'COUNT', count );
|
|
@@ -177,7 +177,7 @@ exports.get = async ( key ) => {
|
|
|
177
177
|
if ( typeof key === 'string' ) {
|
|
178
178
|
const client = await getClient ();
|
|
179
179
|
|
|
180
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
180
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
181
181
|
|
|
182
182
|
// Use the get method directly
|
|
183
183
|
const data = await client.get ( fullKey );
|
|
@@ -212,7 +212,7 @@ exports.multiGet = async ( keys ) => {
|
|
|
212
212
|
if ( Array.isArray ( keys ) ) {
|
|
213
213
|
const client = await getClient ();
|
|
214
214
|
|
|
215
|
-
const fullKeys = keys.map ( key => key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key );
|
|
215
|
+
const fullKeys = ( !config?.redis?.prefix || keys.map ( key => key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key );
|
|
216
216
|
|
|
217
217
|
// Use the mget method directly
|
|
218
218
|
const data = await client.mget ( ...fullKeys );
|
|
@@ -254,7 +254,7 @@ exports.set = async ( key, value, ex, px ) => {
|
|
|
254
254
|
|
|
255
255
|
// Automatically convert objects or arrays to JSON strings
|
|
256
256
|
const serializedValue = ( typeof value === 'object' && value !== null ) ? JSON.stringify ( value ) : value;
|
|
257
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
257
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
258
258
|
|
|
259
259
|
// Use the set method directly with optional EX and PX parameters
|
|
260
260
|
return await client.set ( fullKey, serializedValue, ...( ex ? [ 'EX', ex ] : [] ), ...( px ? [ 'PX', px ] : [] ) );
|
|
@@ -282,7 +282,7 @@ exports.del = async ( key ) => {
|
|
|
282
282
|
if ( typeof key === 'string' ) {
|
|
283
283
|
const client = await getClient ();
|
|
284
284
|
|
|
285
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
285
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
286
286
|
|
|
287
287
|
// Use the del method directly
|
|
288
288
|
return await client.del ( fullKey );
|
|
@@ -313,7 +313,7 @@ exports.multiDel = async ( keys ) => {
|
|
|
313
313
|
const client = await getClient ();
|
|
314
314
|
|
|
315
315
|
// Prepend the Redis prefix to each key if necessary
|
|
316
|
-
const fullKeys = keys.map ( key => key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key );
|
|
316
|
+
const fullKeys = ( !config?.redis?.prefix || keys.map ( key => key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key );
|
|
317
317
|
|
|
318
318
|
// Use the del method with multiple keys
|
|
319
319
|
return await client.del ( ...fullKeys );
|
|
@@ -343,7 +343,7 @@ exports.setAdd = async ( key, members ) => {
|
|
|
343
343
|
if ( typeof key === 'string' ) {
|
|
344
344
|
const client = await getClient ();
|
|
345
345
|
|
|
346
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
346
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
347
347
|
const membersArray = Array.isArray ( members ) ? members : [ members ];
|
|
348
348
|
|
|
349
349
|
// Use the sadd method directly
|
|
@@ -373,7 +373,7 @@ exports.setRemove = async ( key, members ) => {
|
|
|
373
373
|
if ( typeof key === 'string' ) {
|
|
374
374
|
const client = await getClient ();
|
|
375
375
|
|
|
376
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
376
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
377
377
|
const membersArray = Array.isArray ( members ) ? members : [ members ];
|
|
378
378
|
|
|
379
379
|
// Use the srem method directly
|
|
@@ -401,7 +401,7 @@ exports.setMembers = async ( key ) => {
|
|
|
401
401
|
if ( typeof key === 'string' ) {
|
|
402
402
|
const client = await getClient ();
|
|
403
403
|
|
|
404
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
404
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
405
405
|
|
|
406
406
|
// Use the smembers method directly
|
|
407
407
|
return await client.smembers ( fullKey );
|
|
@@ -431,7 +431,7 @@ exports.setPop = async ( key ) => {
|
|
|
431
431
|
if ( typeof key === 'string' ) {
|
|
432
432
|
const client = await getClient ();
|
|
433
433
|
|
|
434
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
434
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
435
435
|
|
|
436
436
|
// Use the spop method directly
|
|
437
437
|
const member = await client.spop ( fullKey );
|
|
@@ -468,7 +468,7 @@ exports.listUnshift = async ( key, values ) => {
|
|
|
468
468
|
if ( typeof key === 'string' ) {
|
|
469
469
|
const client = await getClient ();
|
|
470
470
|
|
|
471
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
471
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
472
472
|
const valuesArray = Array.isArray ( values ) ? values : [ values ];
|
|
473
473
|
|
|
474
474
|
// Use the lpush method directly
|
|
@@ -499,7 +499,7 @@ exports.listPush = async ( key, values ) => {
|
|
|
499
499
|
if ( typeof key === 'string' ) {
|
|
500
500
|
const client = await getClient ();
|
|
501
501
|
|
|
502
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
502
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
503
503
|
const valuesArray = Array.isArray ( values ) ? values : [ values ];
|
|
504
504
|
|
|
505
505
|
// Use the rpush method directly
|
|
@@ -530,7 +530,7 @@ exports.listPop = async ( key, count = 1 ) => {
|
|
|
530
530
|
if ( typeof key === 'string' ) {
|
|
531
531
|
const client = await getClient ();
|
|
532
532
|
|
|
533
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
533
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
534
534
|
|
|
535
535
|
// Use the lpop method directly with the count parameter
|
|
536
536
|
return await client.lpop ( fullKey, count );
|
|
@@ -556,7 +556,7 @@ exports.listPopEnd = async ( key ) => {
|
|
|
556
556
|
if ( typeof key === 'string' ) {
|
|
557
557
|
const client = await getClient ();
|
|
558
558
|
|
|
559
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
559
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
560
560
|
|
|
561
561
|
return await client.rpop ( fullKey );
|
|
562
562
|
}
|
|
@@ -586,7 +586,7 @@ exports.listRange = async ( key, start = 0, end = -1 ) => {
|
|
|
586
586
|
if ( typeof key === 'string' ) {
|
|
587
587
|
const client = await getClient ();
|
|
588
588
|
|
|
589
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
589
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
590
590
|
|
|
591
591
|
// Use the lrange method directly
|
|
592
592
|
return await client.lrange ( fullKey, start, end );
|
|
@@ -615,7 +615,7 @@ exports.getExpiryInSeconds = async ( key ) => {
|
|
|
615
615
|
if ( typeof key === 'string' ) {
|
|
616
616
|
const client = await getClient ();
|
|
617
617
|
|
|
618
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
618
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
619
619
|
|
|
620
620
|
// Use the ttl method directly
|
|
621
621
|
return await client.ttl ( fullKey );
|
|
@@ -644,7 +644,7 @@ exports.setExpiry = async ( key, seconds = 0 ) => {
|
|
|
644
644
|
if ( typeof key === 'string' ) {
|
|
645
645
|
const client = await getClient ();
|
|
646
646
|
|
|
647
|
-
const fullKey = key.startsWith ( config?.redis?.prefix ) ? key : config?.redis?.prefix + key;
|
|
647
|
+
const fullKey = ( !config?.redis?.prefix || key.startsWith ( config?.redis?.prefix ) ) ? key : config?.redis?.prefix + key;
|
|
648
648
|
|
|
649
649
|
// Use the expire method directly
|
|
650
650
|
return await client.expire ( fullKey, seconds );
|
package/src/s3.js
CHANGED
|
@@ -326,6 +326,45 @@ exports.move = async ( sourceKey, destinationKey, sourceBucket = config?.s3?.Buc
|
|
|
326
326
|
}
|
|
327
327
|
};
|
|
328
328
|
|
|
329
|
+
/**
|
|
330
|
+
* List objects in an S3 bucket filtered by a prefix, with support for pagination.
|
|
331
|
+
*
|
|
332
|
+
* @param {string} prefix - The prefix to filter objects by.
|
|
333
|
+
* @param {string} [bucket=config?.s3?.Bucket] - The bucket name. Defaults to the configured bucket.
|
|
334
|
+
* @param {string} [continuationToken] - The continuation token for pagination (optional).
|
|
335
|
+
* @returns {Promise} A promise that resolves with the list of objects and potentially a continuation token for further pagination.
|
|
336
|
+
* @description Retrieves a list of objects from S3 that match the given prefix, with support for pagination.
|
|
337
|
+
*/
|
|
338
|
+
exports.listObjects = async ( prefix, bucket = config?.s3?.Bucket, continuationToken ) => {
|
|
339
|
+
try {
|
|
340
|
+
const params = {
|
|
341
|
+
Bucket: bucket,
|
|
342
|
+
Prefix: prefix,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
if ( continuationToken ) {
|
|
346
|
+
params.ContinuationToken = continuationToken;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const command = new ListObjectsV2Command ( params );
|
|
350
|
+
|
|
351
|
+
const data = await S3.send ( command );
|
|
352
|
+
|
|
353
|
+
if ( config?.s3?.logs === 'outputs' || config?.s3?.logs === 'verbose' ) {
|
|
354
|
+
log ( `S3 [LIST]: Retrieved list for prefix ${prefix} on ${bucket}${continuationToken ? ' with continuation token' : ''}.` );
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
objects: data.Contents,
|
|
359
|
+
isTruncated: data.IsTruncated,
|
|
360
|
+
nextContinuationToken: data.NextContinuationToken,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch ( error ) {
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
329
368
|
exports.getClient = S3;
|
|
330
369
|
|
|
331
370
|
const streamToBuffer = ( stream ) =>
|