eventory 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Eventory #

Work in progress

An event sourcing-inspired library targeting offline-first use, with automatic synchronization with remote instances when connection is available.

Design Principles #

  • All events are acceptable. Errors are managed when looking at the data, not when writing.
  • Writers control the instant events happen.
  • Event value serialization mechanism can be chosen by library users.
  • EventSource is immutable and represents the state of the world at a precise moment in time.
  • EventorySink must be able to write as fast as possible.
  • Snapshots allow EventSources to be extremely efficient at querying data.
  • EventSource and EventorySink are always separate entities even when using the same storage mechanism.
  • Reloading an EventSource with new events from an EventorySink or remote stream must be extremely cheap.

0.1.0 #

  • Created an initial API and implementation that can be evolved into the vision of this library.

0.0.0 #

  • Initial version, created by Stagehand

example/eventory_example.dart

import 'dart:io';

import 'package:eventory/eventory.dart';
import 'package:eventory/src/file_event_sink.dart';

void main(List<String> args) async {
  int eventsPerCycle = args.isNotEmpty ? int.parse(args[0]) : 100000;
  int batchSize = args.length > 1 ? int.parse(args[1]) : 0;
  print(
      "Creating $eventsPerCycle events${batchSize > 0 ? ' using batches of $batchSize events' : ''}");

  var events = <Event>[];
  for (var i = 0; i < eventsPerCycle; i++) {
    events.add(Event(i.toString(), 'value', i));
  }

  final dir = await Directory.systemTemp.createTemp('file_example');
  final tempFile = File("${dir.path}/my_test.txt");
  final watch = Stopwatch();
  var sink = FileEventSink(tempFile);

  print("Starting to write events to file ${tempFile.path}.");

  watch.start();
  if (batchSize > 0) {
    await sendEventsInBatches(events, sink, batchSize);
  } else {
    await sendEventsOneByOne(events, sink);
  }
  print(
      "Done sending events in ${watch.elapsedMilliseconds} ms. Flushing events.");

  // will close and wait for file handle to get flushed
  await sink.close();
  watch.stop();

  events = null;
  sink = null;

  print("All events written in ${watch.elapsedMilliseconds} ms total.");
  print("Write throughput: "
      "${(await tempFile.length()).toDouble() * 1.0e-6 /
      (watch.elapsed.inMilliseconds * 1e-3)}"
      " MB/sec");

  print("Checking for correctness...");
  final source = await FileEventSource.load(tempFile);

  for (var i = 0; i < eventsPerCycle; i++) {
    final entity = await source.getEntity(i.toString());
    if (entity['value'] != i) {
      throw Exception("Error, expected entity with value $i, got $entity");
    }
  }
  print("OK!");
}

void sendEventsOneByOne(List<Event> events, Sink<Event> sink) async {
  for (var event in events) {
    await sink.add(event);
  }
}

void sendEventsInBatches(
    List<Event> events, EventorySink sink, int batchSize) async {
  final batch = <Event>[];
  for (var i = 0; i < events.length; i++) {
    batch.add(events[i]);
    if (i != 0 && i % batchSize == 0) {
      await sink.addBatch(batch);
      batch.clear();
    }
  }
  await sink.addBatch(batch);
}

Use this package as a library

1. Depend on it

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


dependencies:
  eventory: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:eventory/eventory.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:eventory/eventory.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
collection ^1.14.12 1.14.12
meta ^1.1.7 1.1.7
synchronized ^2.1.0 2.1.0+1
Dev dependencies
actors ^0.6.0
pedantic ^1.7.0
test ^1.6.0