1+ /// @docImport 'dart:io';
2+ library ;
3+
14import 'package:celest_cloud/src/cloud/authentication/authentication.dart' ;
25import 'package:celest_cloud/src/cloud/cloud_protocol.dart' ;
36import 'package:celest_cloud/src/cloud/cloud_protocol.grpc.dart' ;
@@ -15,32 +18,90 @@ import 'package:os_detect/os_detect.dart' as os;
1518import 'package:protobuf/protobuf.dart' ;
1619
1720class CelestCloud {
18- CelestCloud ({
21+ factory CelestCloud ({
1922 required Uri uri,
2023 Authenticator authenticator = const Authenticator .static (),
2124 ClientType ? clientType,
2225 Logger ? logger,
2326 String ? userAgent,
2427 http.Client ? httpClient,
25- }) : _protocol = kIsWeb
26- ? CloudProtocolHttp (
27- uri: uri,
28- httpClient: httpClient,
29- authenticator: authenticator,
30- logger: logger,
31- )
32- : CloudProtocolGrpc (
33- uri: uri,
34- userAgent: userAgent,
35- authenticator: authenticator,
36- logger: logger,
37- ),
28+ }) {
29+ return kIsWeb
30+ ? CelestCloud .http (
31+ uri,
32+ authenticator: authenticator,
33+ clientType: clientType,
34+ logger: logger,
35+ httpClient: httpClient,
36+ )
37+ : CelestCloud .grpc (
38+ uri,
39+ authenticator: authenticator,
40+ clientType: clientType,
41+ logger: logger,
42+ userAgent: userAgent,
43+ httpClient: httpClient,
44+ );
45+ }
46+
47+ CelestCloud ._({
48+ required CloudProtocol protocol,
49+ Uri ? uri,
50+ Authenticator authenticator = const Authenticator .static (),
51+ ClientType ? clientType,
52+ Logger ? logger,
53+ http.Client ? httpClient,
54+ }) : _protocol = protocol,
3855 _baseUri = uri,
3956 _httpClient = httpClient,
4057 _authenticator = authenticator,
4158 _clientType = clientType ?? _defaultClientType,
4259 _logger = logger ?? Logger ('Celest.Cloud' );
4360
61+ CelestCloud .http (
62+ Uri uri, {
63+ Authenticator authenticator = const Authenticator .static (),
64+ ClientType ? clientType,
65+ Logger ? logger,
66+ http.Client ? httpClient,
67+ }) : this ._(
68+ uri: uri,
69+ authenticator: authenticator,
70+ protocol: CloudProtocolHttp (
71+ uri: uri,
72+ httpClient: httpClient,
73+ authenticator: authenticator,
74+ logger: logger,
75+ ),
76+ clientType: clientType,
77+ logger: logger,
78+ httpClient: httpClient,
79+ );
80+
81+ /// Creates a gRPC interface for Celest Cloud.
82+ ///
83+ /// [address] must be either a [Uri] or [InternetAddress] .
84+ CelestCloud .grpc (
85+ Object address, {
86+ Authenticator authenticator = const Authenticator .static (),
87+ ClientType ? clientType,
88+ String ? userAgent,
89+ Logger ? logger,
90+ http.Client ? httpClient,
91+ }) : this ._(
92+ uri: address is Uri ? address : null ,
93+ authenticator: authenticator,
94+ protocol: CloudProtocolGrpc (
95+ host: address,
96+ userAgent: userAgent,
97+ authenticator: authenticator,
98+ logger: logger,
99+ ),
100+ clientType: clientType,
101+ logger: logger,
102+ httpClient: httpClient,
103+ );
104+
44105 static final _defaultClientType = kIsWeb
45106 ? ClientType .WEB
46107 : os.isAndroid
@@ -63,7 +124,7 @@ class CelestCloud {
63124 ProjectEnvironment (),
64125 ]);
65126
66- final Uri _baseUri;
127+ final Uri ? _baseUri;
67128 final http.Client ? _httpClient;
68129 final Authenticator _authenticator;
69130
@@ -72,7 +133,7 @@ class CelestCloud {
72133 final Logger _logger;
73134
74135 late final CloudProtocolHttp _httpProtocol = CloudProtocolHttp (
75- uri: _baseUri,
136+ uri: _baseUri! ,
76137 authenticator: _authenticator,
77138 httpClient: _httpClient,
78139 logger: _logger,
0 commit comments