pip_services3_components 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

Pip.Services Logo #

Component definitions for Dart #

This framework is part of the Pip.Services project. It defines standard component definitions that can be used to build applications and services:

  • Auth - authentication credential stores

  • Build - factories

  • Cache - distributed cache

  • Component - the root package

  • Config - configuration readers

  • Connect - connection discovery services

  • Count - performance counters

  • Info - context info

  • Lock - distributed locks

  • Log - logging components

  • Test - test components

  • Component - root package

Quick Links:

  • Warning! Config package now not work with condition {{#if var}} something {{/}} in config files. Use Mustache syntax, for example {{#var}} something {{/var}}

Acknowledgements #

The library is created and maintained by Sergey Seroukhov and Levichev Dmitry.

The documentation is written by Egor Nuzhnykh, Alexey Dvoykin, Mark Makarychev, Levichev Dmitry.

1.0.0 #

  • Initial version, created by Sergey Seroukhov and Dmitry Levichev

1.0.2 #

  • Fix registerAsType, create and canCreate method in Factory class.

1.0.3 #

  • Fix access level to field in CachedLogger class.

1.0.4 #

  • Fix json converter in LogMessage class.

1.0.5 #

  • Fix acquireLock method in Lock class.
  • Change type of error in ILoger interface methods. Make auto wraping exceptions in ApplicationException type.

1.0.6 #

  • Fix working wiith time, convert all to UTC.

example/README.md

Examples for Components #

This library has an extensive set of components for working in various fields when creating microservices, micro-applications and applications. It includes:

  • Auth - authentication credential store
  • Example:
void main(){
     var restConfig = ConfigParams.fromTuples([
      'credential.username',
      'Negrienko',
      'credential.password',
      'qwerty',
      'credential.access_key',
      'key',
      'credential.store_key',
      'store key'
    ]);
    var credentialResolver = CredentialResolver(restConfig);
    var configList = credentialResolver.getAll();
    configList[0].get('username'); // Returns 'Negrienko'
    configList[0].get('password'); // Returns 'qwerty'
    configList[0].get('access_key'); // Returns 'key'
    configList[0].get('store_key'); // Returns 'store key'
}
  • Build - factories

  • Cache - distributed cache

  • Example:
void main(){
    String KEY1 = 'key1';
    String VALUE1 = 'value1';

    MemoryCache _cache;
     try {
      await _cache.store('123', KEY1, VALUE1, 5000);
    } catch (err) {
      //...
    }

    try {
      var val = await _cache.retrieve('123', KEY1);
      // Expect VALUE1
    } catch (err) {
        //...
    }
}
  • Component - root package

  • Config - configuration reader

  • Example:
void main(){
     var parameters = ConfigParams.fromTuples(
          ['param1', 'Test Param 1', 'param2', 'Test Param 2']);
      var config =
          JsonConfigReader.readConfig_('123', './data/config.json', parameters);

      config.getAsInteger('field1.field11'); // Return 123
      config.get('field1.field12'); // Return 'ABC'
      config.getAsInteger('field2.0'); // Return  123
      config.get('field4'); // Return 'Test Param 1'
      config.get('field5'); // Return 'Test Param 2'
}
  • Connect - connection discovery services
  • Example:
void main(){
    var RestConfig = ConfigParams.fromTuples([
      'connection.protocol',
      'http',
      'connection.host',
      'localhost',
      'connection.port',
      3000
    ]);
    var connectionResolver = ConnectionResolver(RestConfig);
    var configList = connectionResolver.getAll();
    configList[0].get('protocol'); // Return 'http'
    configList[0].get('host'); // Return 'localhost'
    configList[0].get('port'); // Return '3000'
}
  • Count - performance counters
  • Example:
void main(){
    LogCounters counters;

    var log = NullLogger();
    var refs =
        References.fromTuples([DefaultLoggerFactory.NullLoggerDescriptor, log]);
    counters = LogCounters();
    counters.setReferences(refs);
    counters.last('Test.LastValue', 123);
    counters.last('Test.LastValue', 123456);

    var counter = counters.get('Test.LastValue', CounterType.LastValue);
    
    counter.last; // Return  123456
    counters.incrementOne('Test.Increment');
    counters.increment('Test.Increment', 3);
    counter = counters.get('Test.Increment', CounterType.Increment);
    counters.timestampNow('Test.Timestamp');
    counters.timestampNow('Test.Timestamp');
    counter = counters.get('Test.Timestamp', CounterType.Timestamp);
    counter.time; // Return time
    counters.stats('Test.Statistics', 1);
    counters.stats('Test.Statistics', 2);
    counters.stats('Test.Statistics', 3);
    counter = counters.get('Test.Statistics', CounterType.Statistics);
    counter.average;// Return 2
}
  • Information - contextual information
  • Example:
void main(){
    var config = ConfigParams.fromTuples([
        'name',
        'name',
        'description',
        'description',
        'properties.access_key',
        'key',
        'properties.store_key',
        'store key'
      ]);

      var contextInfo = ContextInfo.fromConfig(config);
      contextInfo.name; // Return 'name'
      contextInfo.description; // Return 'description'
}
  • Lock - distributed locks
  • Example:
void main() async {
    final String LOCK1 = 'lock_1';
    _lock = MemoryLock();
    // Try to acquire lock for the first time
    try {
      var result = await _lock.tryAcquireLock('123', LOCK1, 3000);
      // result True
    } catch (err) {
      //...
    }
    // Try to acquire lock for the second time
    try {
      var result = await _lock.tryAcquireLock('123', LOCK1, 3000);
      // result False
    } catch (err) {
      //...
    }
    // Release the lock
    await _lock.releaseLock('123', LOCK1);
    // Try to acquire lock for the third time
    try {
      var result = await _lock.tryAcquireLock('123', LOCK1, 3000);
      // result True
    } catch (err) {
     //...
    }
    await _lock.releaseLock('123', LOCK1);
}
  • Log - logging components
  • Example:
void main(){
    var _logger = ConsoleLogger();
    _logger.setLevel(LogLevel.Trace);
    _logger.fatal(null, null, 'Fatal error message');
    _logger.error(null, null, 'Error message');
    _logger.warn(null, 'Warning message');
    _logger.info(null, 'Information message');
    _logger.debug(null, 'Debug message');
    _logger.trace(null, 'Trace message');

    try {
        // Raise an exception
        throw Exception();
      } catch (err) {
        var ex = ApplicationException().wrap(err);
        _logger.fatal('123', ex, 'Fatal error');
        _logger.error('123', ex, 'Recoverable error');
      }
}
  • Test - component testing

In the help for each class there is a general example of its use. Also one of the quality sources are the source code for the tests.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pip_services3_components: ^1.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pip_services3_components/pip_services3_components.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
64
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime js

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime native-aot

Because:

  • package:pip_services3_components/pip_services3_components.dart that imports:
  • package:pip_services3_components/src/Component.dart that imports:
  • package:pip_services3_components/src/count/CompositeCounters.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Health suggestions

Fix lib/src/test/Shutdown.dart. (-0.50 points)

Analysis of lib/src/test/Shutdown.dart reported 1 hint:

line 85 col 11: The value of the local variable 'crash' isn't used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
mustache4dart2 ^0.1.0 0.1.0
pip_services3_commons >=1.0.2 <2.0.0 1.0.11
sprintf ^4.0.0 4.0.2
yaml ^2.2.0 2.2.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nnbd
convert 2.1.1
crypto 2.1.5
meta 1.2.1
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nnbd
uuid 2.2.0
Dev dependencies
test >=1.14.2 <2.0.0