-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bruuuuuuuce-patch-1
- Loading branch information
Showing
15 changed files
with
182 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'transport/grpc_configuration.dart'; | ||
import 'transport/transport_strategy.dart'; | ||
|
||
abstract interface class TopicConfiguration { | ||
/// Configures low-level options for network interactions with the Momento service | ||
late TransportStrategy transportStrategy; | ||
|
||
/// Constructor for a TopicConfiguration | ||
TopicConfiguration(this.transportStrategy); | ||
|
||
/// Copy constructor for overriding TransportStrategy | ||
TopicConfiguration withTransportStrategy(TransportStrategy transportStrategy); | ||
|
||
/// Convenience copy constructor that updates the client-side | ||
/// timeout setting in the transport strategy | ||
TopicConfiguration withDeadline(Duration deadline); | ||
} | ||
|
||
/// Configuration options for Momento TopicClient. | ||
/// The easiest way to get a `TopicClientConfiguration` object is | ||
/// to use one of the prebuilt TopicClientConfigurations classes. | ||
class TopicClientConfiguration implements TopicConfiguration { | ||
@override | ||
late TransportStrategy transportStrategy; | ||
|
||
TopicClientConfiguration(this.transportStrategy); | ||
|
||
@override | ||
TopicConfiguration withTransportStrategy(TransportStrategy transportStrategy) { | ||
return TopicClientConfiguration(transportStrategy); | ||
} | ||
|
||
@override | ||
TopicConfiguration withDeadline(Duration deadline) { | ||
return TopicClientConfiguration(StaticTransportStrategy(StaticGrpcConfiguration(deadline))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'topic_configuration.dart'; | ||
import 'transport/grpc_configuration.dart'; | ||
import 'transport/transport_strategy.dart'; | ||
|
||
/// Prebuilt configurations for Momento Topics clients | ||
abstract interface class TopicClientConfigurations {} | ||
|
||
/// Provides prebuilt configurations for the `TopicClient` on mobile platforms | ||
class Mobile extends TopicClientConfigurations { | ||
static TopicClientConfiguration defaultConfig() { | ||
return latest(); | ||
} | ||
|
||
static TopicClientConfiguration latest() { | ||
return TopicClientConfiguration(StaticTransportStrategy(StaticGrpcConfiguration(Duration(seconds: 15)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
abstract interface class GrpcConfiguration { | ||
/// Duration of time the client is willing to wait for an RPC to | ||
/// complete before it is terminated with a DeadlineExceeded error | ||
late Duration deadline; | ||
|
||
/// Copy constructor for overriding the client-side deadline | ||
GrpcConfiguration withDeadline(Duration deadline); | ||
} | ||
|
||
/// Encapsulates gRPC configuration tunables | ||
class StaticGrpcConfiguration implements GrpcConfiguration { | ||
@override | ||
late Duration deadline; | ||
|
||
StaticGrpcConfiguration(this.deadline); | ||
|
||
@override | ||
GrpcConfiguration withDeadline(Duration deadline) { | ||
return StaticGrpcConfiguration(deadline); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'grpc_configuration.dart'; | ||
|
||
abstract interface class TransportStrategy { | ||
/// Low-level gRPC settings for communication with the Momento server | ||
late GrpcConfiguration grpcConfig; | ||
|
||
/// Copy constructor to update the client-side timeout | ||
TransportStrategy withGrpcConfig(GrpcConfiguration grpcConfig); | ||
|
||
/// Copy constructor to update the client-side timeout | ||
TransportStrategy withClientTimeout(Duration timeout); | ||
} | ||
|
||
class StaticTransportStrategy implements TransportStrategy { | ||
@override | ||
late GrpcConfiguration grpcConfig; | ||
|
||
StaticTransportStrategy(this.grpcConfig); | ||
|
||
@override | ||
TransportStrategy withClientTimeout(Duration timeout) { | ||
return StaticTransportStrategy(StaticGrpcConfiguration(timeout)); | ||
} | ||
|
||
@override | ||
TransportStrategy withGrpcConfig(GrpcConfiguration grpcConfig) { | ||
return StaticTransportStrategy(grpcConfig); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,22 @@ | ||
// 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 'package:logging/logging.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; | ||
final Logger _logger = Logger('MomentoTopicClient'); | ||
|
||
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.