spine_client library
The entry point for a Spine client.
This library provides the API for constructing and executing actor requests, such as commands and queries.
The library provides an interface for a firebase client. Two implementations are included in this package but not in the library.
Also, the package contains all the generated from Protobuf types, as well as many utilities which make constructing requests easier.
Example:
// Import `spine_client` and helper libraries.
import 'package:spine_client/spine_client.dart';
import 'package:spine_client/web_firebase_client.dart';
import 'package:spine_client/time.dart';
// Import the Firebase client library.
import 'package:firebase/firebase.dart' as fb;
// Import your model types, generated from Protobuf.
import 'example/acme/task/commands.pb.dart';
import 'example/acme/task/view.pb.dart';
// Import the type registry which contains all your model types.
// Generated by Spine Proto Dart Gradle plugin.
import 'types.dart' as exampleTypes;
void main() async {
var actorId = UserId()
..value = '$myUserId';
var requests = ActorRequestFactory(actorId);
var firebase = RestClient(
fb.Database.getInstance(myFirebaseDbJsObject()),
'https://example-org-42.firebaseio.com'
);
var client = BackendClient('https://example.org',
firebase,
typeRegistries: [myTypes.types()]);
// Listen for all `TaskListView` updates and display them.
Subscription<TaskListView> subscription =
await client.subscribeTo(requests.topic().all(TaskListView()));
subscription.itemChanged.listen(taskListView => updateDisplay(taskListView));
// Fetch all `TaskView` projections and mark all tasks as done.
client.fetch(requests.query().all(TaskView()))
.forEach((taskView) {
var markDone = MarkTaskDone()
..id = taskView.id
..who_completed = actorId;
client.post(requests.command().create(markDone));
});
}
Classes
- Client
- A client which connects to a Spine-based backend, posts commands, sends queries, and creates and managed subscriptions on behalf of a certain user.
- Clients
- A factory of Clients.
-
CommandRequest<
M extends GeneratedMessage> - A request to the server to post a command.
- Composite
- A composite field filter.
- DayOfWeek
- Endpoints
- URL paths to which the client should send requests.
-
EventSubscription<
T extends GeneratedMessage> - A subscription for events.
-
EventSubscriptionRequest<
M extends GeneratedMessage> - A request to subscribe to events.
- FilterOrComposite
- A simple or a composite field filter.
- FirebaseClient
- A client of a Firebase Realtime Database.
- LocalDate
- LocalDateTime
- LocalTime
- Month
- OffsetDateTime
- OffsetTime
-
QueryRequest<
M extends GeneratedMessage> - A request to query the server for data.
- SimpleFilter
- A simple field filter.
-
StateSubscription<
T extends GeneratedMessage> - A subscription for entity state changes.
-
StateSubscriptionRequest<
M extends GeneratedMessage> - A request to subscribe to entity state updates.
-
Subscription<
T extends GeneratedMessage> - A subscription to updates from server.
- SubscriptionEndpoints
- URL paths to which the client should send requests regarding entity and event subscriptions.
- TenantId
- UserId
- YearMonth
- ZonedDateTime
- ZoneId
- ZoneOffset
Enums
- QueryMode
- The mode in which the backend serves query responses.
- TenantId_Kind
Functions
-
all(
Iterable< SimpleFilter> filters) → Composite -
Creates a composite filter which groups one or more field filters with the
ALL
operator. -
either(
Iterable< SimpleFilter> filters) → Composite -
Creates a composite filter which groups one or more field filters with the
EITHER
operator. -
eq(
String fieldPath, Object value) → SimpleFilter -
Creates a field filter with the
=
operator. -
ge(
String fieldPath, Object value) → SimpleFilter -
Creates a field filter with the
>=
operator. -
gt(
String fieldPath, Object value) → SimpleFilter -
Creates a field filter with the
>
operator. -
le(
String fieldPath, Object value) → SimpleFilter -
Creates a field filter with the
<=
operator. -
lt(
String fieldPath, Object value) → SimpleFilter -
Creates a field filter with the
<
operator.
Typedefs
- CommandErrorCallback = void Function(Error error)
- A callback which notifies the user about an error when posting a command.
- UrlPath = String
- A part of URL path, specifying a destination of client requests of some type.