@ti-engine/core 1.2.3 → 1.2.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  This document will contain the list of changes made to the framework. The format is based on the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
4
4
 
5
+ ## Version 1.2.4
6
+ * feat(cache): expose the cache module as export in `package.json`
7
+ * feat(cache): add method `hashDeleteField` to remove a hash-set field. This implements the `hdel` Redis command
8
+ * fix(tools): optimize method `stringifyJSON` not to call unnecessary decycling of the value if it's not an object
9
+ * fix(cache): replace `hmset` with `hset` Redis command in both methods that set hash-set values. Also remove unnecessary `_.isObjectLike` call in `hashSetFields` method
10
+
5
11
  ## Version 1.2.3
6
12
  * feat(start instance): add support for providing a custom path to the `.env` file to be used at service startup as process argument. Accepted arguments are `--env`, `--env-file`, `--dotenv`, `--dotenv-path`, and `-e`. The path itself should be relative to the working directory and should include the file name
7
13
 
Binary file
Binary file
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@ti-engine/core",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.",
5
5
  "author": "Boris Kostadinov <kostadinov.boris@gmail.com>",
6
6
  "license": "GPL-3.0-or-later",
7
7
  "exports": {
8
8
  ".": "./bin/start-instance.js",
9
+ "./cache": "./utils/cache.js",
9
10
  "./exceptions": "./utils/exceptions.js",
10
11
  "./localization": "./utils/localization.js",
11
12
  "./logger": "./utils/logger.js",
package/utils/cache.js CHANGED
@@ -508,7 +508,7 @@ class CommonMemoryCache extends ConnectionObserver {
508
508
  hashSetField( key, name, value ) {
509
509
  return new Promise( ( resolve, reject ) => {
510
510
  if ( this.#isOperational === true ) {
511
- let commandHashSetField = [ redis.cacheCommands.HASH_SET_MANY, key, name, tools.stringifyJSON( value ) ];
511
+ let commandHashSetField = [ redis.cacheCommands.HASH_SET, key, name, tools.stringifyJSON( value ) ];
512
512
  this.#redisClient.executeCommands( [ commandHashSetField ] ).then( () => {
513
513
  resolve();
514
514
  } ).catch( ( error ) => {
@@ -535,10 +535,10 @@ class CommonMemoryCache extends ConnectionObserver {
535
535
  hashSetFields( key, fields ) {
536
536
  return new Promise( ( resolve, reject ) => {
537
537
  if ( this.#isOperational === true ) {
538
- let commandHashSetFields = [ redis.cacheCommands.HASH_SET_MANY, key ];
538
+ let commandHashSetFields = [ redis.cacheCommands.HASH_SET, key ];
539
539
  _.forEach( fields, ( field ) => {
540
540
  commandHashSetFields.push( field.name );
541
- commandHashSetFields.push( _.isObjectLike( field.value ) ? tools.stringifyJSON( field.value ) : field.value );
541
+ commandHashSetFields.push( tools.stringifyJSON( field.value ) );
542
542
  } );
543
543
  this.#redisClient.executeCommands( [ commandHashSetFields ] ).then( () => {
544
544
  resolve();
@@ -576,6 +576,31 @@ class CommonMemoryCache extends ConnectionObserver {
576
576
  } );
577
577
  }
578
578
 
579
+ /**
580
+ * Used to remove a single field from a hash.
581
+ *
582
+ * @method
583
+ * @param {string} key
584
+ * @param {string} field
585
+ * @return {Promise<boolean>} Will return 'true' if the field was removed, 'false' otherwise.
586
+ * @public
587
+ */
588
+ hashDeleteField( key, field ) {
589
+ return new Promise( ( resolve, reject ) => {
590
+ if ( this.#isOperational === true ) {
591
+ let commandHashGetField = [ redis.cacheCommands.HASH_REMOVE, key, field ];
592
+ this.#redisClient.executeCommands( [ commandHashGetField ] ).then( ( results ) => {
593
+ results = results[ 0 ];
594
+ resolve( ( results && results.length > 1 ) ? tools.toBool( results[ 1 ] ) : false );
595
+ } ).catch( ( error ) => {
596
+ reject( error );
597
+ } );
598
+ } else {
599
+ reject( exceptions.raise( exceptions.exceptionCode.E_GEN_SYSTEM_CACHE_UNAVAILABLE ) );
600
+ }
601
+ } );
602
+ }
603
+
579
604
  /**
580
605
  * Used to store a JSON variable.
581
606
  * <br/>
@@ -248,4 +248,4 @@ module.exports.raise = ( source, data, exceptionID ) => {
248
248
  */
249
249
  module.exports.isException = ( object ) => {
250
250
  return ( object instanceof Exception );
251
- };
251
+ };
package/utils/tools.js CHANGED
@@ -319,8 +319,7 @@ module.exports.retrocycle = ( $ ) => {
319
319
  * @public
320
320
  */
321
321
  module.exports.stringifyJSON = ( value ) => {
322
- let transformed = module.exports.decycle( value );
323
- return _.isObjectLike( transformed ) ? JSON.stringify( _.toPlainObject( transformed ) ) : value;
322
+ return _.isObjectLike( value ) ? JSON.stringify( _.toPlainObject( module.exports.decycle( value ) ) ) : value;
324
323
  };
325
324
 
326
325
  /**
@@ -537,4 +536,4 @@ class RetryPolicy {
537
536
 
538
537
  }
539
538
 
540
- module.exports.RetryPolicy = RetryPolicy;
539
+ module.exports.RetryPolicy = RetryPolicy;