Skip to content

Commit

Permalink
chore: plumb through publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce committed Dec 14, 2023
1 parent 27ccd27 commit 5523ce1
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 139 deletions.
2 changes: 1 addition & 1 deletion lib/client_sdk_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/// More dartdocs go here.
library;

export 'src/client_sdk_dart_base.dart';
export 'src/topic_client.dart';

// TODO: Export any libraries intended for clients of this package.
31 changes: 0 additions & 31 deletions lib/src/client_sdk_dart_base.dart

This file was deleted.

45 changes: 20 additions & 25 deletions lib/src/errors/errors.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
abstract class AbstractErrorResponseBase {
String _message;
Error? _innerException;
AbstractErrorResponseBase(this._message, this._innerException);

String get message => _message;
Error? get innerException => _innerException;
enum MomentoErrorCode {
INVALID_ARGUMENT_ERROR,
UNKNOWN_SERVICE_ERROR,
ALREADY_EXISTS_ERROR,
NOT_FOUND_ERROR,
}

class SdkError implements Error, AbstractErrorResponseBase {
@override
// TODO: implement stackTrace
StackTrace? get stackTrace => _innerException?.stackTrace;

@override
Error? _innerException;
abstract class AbstractExceptionResponseBase {
final String _message;
final Exception? _innerException;
AbstractExceptionResponseBase(this._message, this._innerException);

@override
String _message;

SdkError(this._message, this._innerException);
String get message => _message;
Exception? get innerException => _innerException;
}

@override
// TODO: implement innerException
Error? get innerException => _innerException;
class SdkException extends AbstractExceptionResponseBase implements Exception {
String _messageWrapper;
SdkException(String message, Exception? innerException, String messageWrapper) : _messageWrapper = messageWrapper, super(message, innerException);

@override
// TODO: implement message
String get message => _message;
String get messageWrapper => _messageWrapper;
}

}
class UnknownException extends SdkException {
UnknownException(String message, Exception? innerException) : super(message, innerException, "Unknown error has occurred");
}
28 changes: 11 additions & 17 deletions lib/src/internal/pubsub_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@ import 'dart:typed_data';
import 'package:client_sdk_dart/generated/cachepubsub.pb.dart';
import 'package:client_sdk_dart/generated/cachepubsub.pbgrpc.dart';
import 'package:client_sdk_dart/src/auth/credential_provider.dart';
import 'package:client_sdk_dart/src/errors/errors.dart';
import 'package:grpc/grpc.dart';
import 'package:protobuf/protobuf.dart';

import '../messages/Values.dart';
import '../messages/responses/topics/topic_publish.dart';

sealed class Value {}
class StringValue implements Value {
String _value;
StringValue(String v) : _value = v;
String get value => _value;
}

class BinaryValue implements Value {
List<int> _value;
BinaryValue(List<int> v) : _value = v;
List<int> get value => _value;
}

abstract class AbstractPubsubClient {
Future<TopicPublishResponse> publish(String cacheName, String topicName, Value value);
}
Expand All @@ -40,9 +28,15 @@ class ClientPubsub implements AbstractPubsubClient {
request.cacheName = cacheName;
request.topic = topicName;
request.value = _valueToTopicValue(value);
await _client.publish(request);
// TODO: implement publish
throw UnimplementedError();
try {
await _client.publish(request);
return TopicPublishSuccess();
} catch (e) {
if (e is SdkException) {
return TopicPublishError(e);
}
return TopicPublishError(UnknownException("Unexpected error: $e", null));
}
}

TopicValue_ _valueToTopicValue(Value v) {
Expand Down
12 changes: 12 additions & 0 deletions lib/src/messages/Values.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sealed class Value {}
class StringValue implements Value {
String _value;
StringValue(String v) : _value = v;
String get value => _value;
}

class BinaryValue implements Value {
List<int> _value;
BinaryValue(List<int> v) : _value = v;
List<int> get value => _value;
}
13 changes: 2 additions & 11 deletions lib/src/messages/responses/responses_base.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import '../../errors/errors.dart';

class ErrorResponseBase implements AbstractErrorResponseBase {
String _message;
Error? _innerException;

@override
Error? get innerException => _innerException;

@override
String get message => _message;

ErrorResponseBase(SdkError error) : _message = error.message, _innerException = error.innerException;
class ErrorResponseBase extends AbstractExceptionResponseBase {
ErrorResponseBase(SdkException exception) : super(exception.message, exception.innerException);
}
2 changes: 1 addition & 1 deletion lib/src/messages/responses/topics/topic_publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ sealed class TopicPublishResponse {}
class TopicPublishSuccess implements TopicPublishResponse { }

class TopicPublishError extends ErrorResponseBase implements TopicPublishResponse {
TopicPublishError(super.error);
TopicPublishError(super.exception);
}
48 changes: 11 additions & 37 deletions lib/src/topic_client.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
// TODO: Put public facing types in this file.

import 'dart:typed_data';

import '../generated/cachepubsub.pb.dart';
import 'package:grpc/grpc.dart';

sealed class Value {}
class StringValue implements Value {
String _value;
StringValue(String v) : _value = v;
String get value => _value;
}

class BinaryValue implements Value {
Uint8List _value;
BinaryValue(Uint8List v) : _value = v;
Uint8List get value => _value;
}
import 'package:client_sdk_dart/src/auth/credential_provider.dart';
import 'internal/pubsub_client.dart';
import 'messages/Values.dart';
import 'messages/responses/topics/topic_publish.dart';

abstract class ITopicClient {
void publish(String cacheName, String topicName, Value value);
Future<TopicPublishResponse> publish(String cacheName, String topicName, Value value);
}

class TopicClient implements ITopicClient {
ClientChannel _channel;

TopicClient() {
_channel = ClientChannel(host)
}
@override
void publish() {
// TODO: implement publish
}
ClientPubsub _pubsubClient;
CredentialProvider _credentialProvider;

void close() {
TopicClient(this._credentialProvider) : _pubsubClient = ClientPubsub(_credentialProvider);

@override
Future<TopicPublishResponse> publish(String cacheName, String topicName, Value value) {
return this._pubsubClient.publish(cacheName, topicName, value);
}
}

/// Checks if you are awesome. Spoiler: you are.
class Awesome {
bool get isAwesome => true;
}

PubsubApi api = PubsubApi();
16 changes: 0 additions & 16 deletions test/client_sdk_dart_test.dart

This file was deleted.

0 comments on commit 5523ce1

Please sign in to comment.