eventsourcingdb 0.1.0-beta.1 copy "eventsourcingdb: ^0.1.0-beta.1" to clipboard
eventsourcingdb: ^0.1.0-beta.1 copied to clipboard

Community Dart client for EventSourcingDB with typed HTTP and NDJSON APIs.

example/example.dart

// Run against a local EventSourcingDB instance, e.g.:
//   docker run -it --rm -p 3000:3000 thenativeweb/eventsourcingdb:preview \
//     run --api-token secret --data-directory-temporary \
//     --http-enabled --https-enabled=false
//
// Then:
//   dart run example/example.dart

import 'package:eventsourcingdb/eventsourcingdb.dart';

void main() async {
  final client = Client(Uri.parse('http://localhost:3000'), 'secret');

  // Ping does not require authentication, so it may succeed even if the API
  // token is invalid.
  await client.ping();
  print('Server is reachable.');

  await client.verifyApiToken();
  print('API token is valid.');

  final writtenEvents = await client.writeEvents([
    EventCandidate(
      source: 'https://www.eventsourcingdb.io',
      subject: '/books/42',
      type: 'io.eventsourcingdb.library.book-acquired',
      data: {'title': 'Dune', 'author': 'Frank Herbert'},
    ),
  ]);
  print('Wrote event with id ${writtenEvents.single.id}.');

  final events = await client
      .readEvents('/books/42', const ReadEventsOptions(recursive: false))
      .toList();
  for (final event in events) {
    final data = event.getData(
      (json) => (json as Map<String, Object?>)['title'],
    );
    print('Read event ${event.id}: $data');
  }

  final rows = await client
      .runEventQlQuery(
        'FROM e IN events '
        'WHERE e.type == "io.eventsourcingdb.library.book-acquired" '
        'PROJECT INTO COUNT()',
      )
      .toList();
  print('Books acquired: ${rows.single}.');

  client.close();
}
0
likes
160
points
41
downloads

Documentation

API reference

Publisher

verified publisherdclimber.com

Weekly Downloads

Community Dart client for EventSourcingDB with typed HTTP and NDJSON APIs.

Homepage
Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

collection, crypto, ed25519_edwards, http, logging

More

Packages that depend on eventsourcingdb