pip_services3_commons 1.0.11

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

Pip.Services Logo #

Portable Abstractions and Patterns for Dart #

This framework is part of the Pip.Services project. It provides portable abstractions and patterns that can be used to implement non-trivial business logic in applications and services.

This framework's key difference is its portable implementation across a variety of different languages. It currently supports Java, .NET, Python, Node.js, Dart, and Golang. The code provides a reasonably thin abstraction layer over most fundamental functions and delivers symmetric implementation that can be quickly ported between different platforms.

The framework's functionality is decomposed into several packages:

  • Commands - commanding and eventing patterns
  • Config - configuration framework
  • Convert - soft value converters
  • Data - data patterns
  • Errors - application errors
  • Random - random data generators
  • Refer - locator (IoC) pattern
  • Reflect - reflection framework
  • Run - execution framework
  • Validate - validation framework

Quick Links:

Acknowledgements #

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

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.1 #

  • Fix docs and code style, created by Dmitry Levichev

1.0.2 #

  • More fixes docs and code style, created by Dmitry Levichev

1.0.3 #

  • Fix all code style by Dmitry Levichev

1.0.4 #

  • Fix getOneOptional method in References

1.0.5 #

  • Fix toNullableString method in StringConverter for properly works with Lists. Was added tests.

1.0.6 #

  • Optimize toNullableString method in StringConverter for properly works with Lists. Added examples.

1.0.7 #

  • Fix methods [fromJson] in classes from data package.

1.0.8 #

  • Fix work with time, make convert to UTC.

1.0.9 #

  • Add converting to/from JSON for ApplicationException

1.0.10 #

  • Fix setInterval and setDelay methods in FixedRateTimer

1.0.11 #

  • Fix ApplicationException to JSON converting issue

example/README.md

Examples for Commons #

It provides portable abstractions and patterns that can be used to implement non-trivial business logic in applications and services.

This framework's key difference is its portable implementation across a variety of different languages. It currently supports Java, .NET, Python, Node.js, Dart, and Golang. The code provides a reasonably thin abstraction layer over most fundamental functions and delivers symmetric implementation that can be quickly ported between different platforms.

The framework's functionality is decomposed into several packages:

  • Commands - commanding and eventing patterns
  • Example:

var command = Command('name', null, CommandExec());
var map = {};
map[8] = 'title 8';
map[11] = 'title 11';
var param = Parameters(map);
var result = await command.execute('a', param); // Result 123

  • Config - configuration framework
  • Example:
 var config = ConfigParams.fromTuples([
        'Section1.Key1',
        'Value1',
        'Section1.Key2',
        'Value2',
        'Section1.Key3',
        'Value3'
      ]);

config.get('Section1.Key1'); // 'Value1'
config.get('Section1.Key2'); // 'Value2'
config.get('Section1.Key3'); // 'Value3'
config.get('Section1.Key4'); //  null
  • Convert - soft value converters
  • Example:
StringConverter.toNullableString(null);     // null);
StringConverter.toNullableString([1, 2, 3]);// '1,2,3';
StringConverter.toString2('xyz');           // 'xyz'
StringConverter.toString2(123);             // '123'
StringConverter.toString2(true);            // 'true'
  • Data - data patterns
  • Example:
var array = AnyValueArray();
array = AnyValueArray([1, 2, 3]);
array = AnyValueArray.fromString('Fatal,Error,Info,', ',');

  • Errors - application errors
  • Example:
ApplicationException _appEx;
Exception _ex;
var Category = 'category';
var CorrelationId = 'correlationId';
var Code = 'code';
var Message = 'message';
_ex = Exception('Cause exception');
_appEx = ApplicationException(Category, CorrelationId, Code, Message);
_appEx.withCause(_ex);
var newCorrelationId = 'newCorrelationId';
var appEx = _appEx.withCorrelationId(newCorrelationId);
  • Random - random data generators
  • Example:
var value = RandomInteger.nextInteger(5);
value = RandomInteger.nextInteger(2, 5);
//-------------------------------------------
var interval = RandomDuration.nextDuration(
          Duration(milliseconds: 10000), Duration(milliseconds: 15000));
//-------------------------------------------
var value = RandomBoolean.chance(5, 10);
//-------------------------------------------
var array = [1, 2];
var value = RandomArray.pick<int>(array);
  • Refer - locator (IoC) pattern
  • Example:
var descriptor =
          Descriptor('pip-dummies', 'controller', 'default', 'default', '1.0');
var res = descriptor1.toString(); // pip-dummies:controller:default:default:1.0
//-----------------------------------------------------------------------------

var ref1 = {'test': 'val1'};
      var ref2 = {'temp': 'value'};
      var refs = References.fromTuples([
        'Reference1',
        ref1,
        Descriptor(
            'pip-services-commons', 'reference', 'object', 'ref2', '1.0'),
        ref2
      ]);
 var resolver = DependencyResolver.fromTuples([
        'ref1',
        'Reference1',
        'ref2',
        Descriptor('pip-services-commons', 'reference', '*', '*', '*')
      ]);
      resolver.setReferences(refs);

resolver.getOneRequired('ref1'); // ref1
resolver.getOneRequired('ref2'); // ref2
resolver.getOneOptional('ref3'); // null

  • Reflect - reflection framework
  • Example:
var obj = TestClass();
var value = ObjectReader.getProperty(obj, 'privateField'); // null

value = ObjectReader.getProperty(obj, 'publicField'); // 'ABC'
value = ObjectReader.getProperty(obj, 'PublicProp');  // not null
  • Run - execution framework
  • Example:
// FixedRateTimer
class TestTimer implements INotifiable {
  int counter = 0;
  void notify(String correlationId, Parameters args) {
    counter++;
  }
}

var notifier = TestTimer();
var timer = FixedRateTimer(notifier, 100, 0);
timer.start();
//-------------------------------------------------
// Parameters
var result = Parameters.fromTuples(['value1', 123, 'value2', 234]);
var defaults = Parameters.fromTuples(['value2', 432, 'value3', 345]);
result = result.setDefaults(defaults, false);
result['value1'] // 123
result['value2'] // 234
result['value3'] // 345

  • Validate - validation framework
  • Example:
class TestObject {
  TestObject() {
    mapProperty['Key1'] = 111;
    mapProperty['Key2'] = 222;
  }

  int _privateField = 124;
  String _privateProperty = 'XYZ';

  int intField = 12345;
  String stringProperty = 'ABC';
  dynamic nullProperty;
  List<int> intArrayProperty = [1, 2, 3];
  List<String> stringListProperty = ['AAA', 'BBB'];
  Map<String, int> mapProperty = {};
  TestSubObject subObjectProperty = TestSubObject('1');
  List<TestSubObject> subArrayProperty = [
    TestSubObject('2'),
    TestSubObject('3')
  ];
}
//------------------------------------------
var schema = ObjectSchema()
          .withOptionalProperty('intField')
          .withOptionalProperty('stringProperty')
          .withOptionalProperty('nullProperty')
          .withOptionalProperty('intArrayProperty')
          .withOptionalProperty('stringListProperty')
          .withOptionalProperty('mapProperty')
          .withOptionalProperty('subObjectProperty')
          .withOptionalProperty('subArrayProperty');

var obj = TestObject();
var results = schema.validate(obj); // results.length is 0, all rules good

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_commons: ^1.0.11

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_commons/pip_services3_commons.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
99
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_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_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_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_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_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_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_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_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/reflect/RecursiveObjectReader.dart. (-1 points)

Analysis of lib/src/reflect/RecursiveObjectReader.dart reported 2 hints:

line 99 col 15: Use contains instead of indexOf

line 153 col 15: Use contains instead of indexOf

Fix lib/src/validate/Schema.dart. (-0.50 points)

Analysis of lib/src/validate/Schema.dart reported 1 hint:

line 166 col 20: Unnecessary cast.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
uuid >=2.0.4 <3.0.0 2.2.0
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
test >=1.14.2 <2.0.0