-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathNativePluginBindings.swift
More file actions
836 lines (771 loc) · 32 KB
/
NativePluginBindings.swift
File metadata and controls
836 lines (771 loc) · 32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
//
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Autogenerated from Pigeon (v26.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
import Foundation
#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#else
#error("Unsupported platform.")
#endif
/// Error class for passing custom error details to Dart side.
final class PigeonError: Error {
let code: String
let message: String?
let details: Sendable?
init(code: String, message: String?, details: Sendable?) {
self.code = code
self.message = message
self.details = details
}
var localizedDescription: String {
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
}
}
private func wrapResult(_ result: Any?) -> [Any?] {
return [result]
}
private func wrapError(_ error: Any) -> [Any?] {
if let pigeonError = error as? PigeonError {
return [
pigeonError.code,
pigeonError.message,
pigeonError.details,
]
}
if let flutterError = error as? FlutterError {
return [
flutterError.code,
flutterError.message,
flutterError.details,
]
}
return [
"\(error)",
"\(type(of: error))",
"Stacktrace: \(Thread.callStackSymbols)",
]
}
private func createConnectionError(withChannelName channelName: String) -> PigeonError {
return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "")
}
private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
}
private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return value as! T?
}
func deepEqualsNativePluginBindings(_ lhs: Any?, _ rhs: Any?) -> Bool {
let cleanLhs = nilOrValue(lhs) as Any?
let cleanRhs = nilOrValue(rhs) as Any?
switch (cleanLhs, cleanRhs) {
case (nil, nil):
return true
case (nil, _), (_, nil):
return false
case is (Void, Void):
return true
case let (cleanLhsHashable, cleanRhsHashable) as (AnyHashable, AnyHashable):
return cleanLhsHashable == cleanRhsHashable
case let (cleanLhsArray, cleanRhsArray) as ([Any?], [Any?]):
guard cleanLhsArray.count == cleanRhsArray.count else { return false }
for (index, element) in cleanLhsArray.enumerated() {
if !deepEqualsNativePluginBindings(element, cleanRhsArray[index]) {
return false
}
}
return true
case let (cleanLhsDictionary, cleanRhsDictionary) as ([AnyHashable: Any?], [AnyHashable: Any?]):
guard cleanLhsDictionary.count == cleanRhsDictionary.count else { return false }
for (key, cleanLhsValue) in cleanLhsDictionary {
guard cleanRhsDictionary.index(forKey: key) != nil else { return false }
if !deepEqualsNativePluginBindings(cleanLhsValue, cleanRhsDictionary[key]!) {
return false
}
}
return true
default:
// Any other type shouldn't be able to be used with pigeon. File an issue if you find this to be untrue.
return false
}
}
func deepHashNativePluginBindings(value: Any?, hasher: inout Hasher) {
if let valueList = value as? [AnyHashable] {
for item in valueList { deepHashNativePluginBindings(value: item, hasher: &hasher) }
return
}
if let valueDict = value as? [AnyHashable: AnyHashable] {
for key in valueDict.keys {
hasher.combine(key)
deepHashNativePluginBindings(value: valueDict[key]!, hasher: &hasher)
}
return
}
if let hashableValue = value as? AnyHashable {
hasher.combine(hashableValue.hashValue)
}
return hasher.combine(String(describing: value))
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeAuthSession: Hashable {
var isSignedIn: Bool
var userSub: String? = nil
var userPoolTokens: NativeUserPoolTokens? = nil
var identityId: String? = nil
var awsCredentials: NativeAWSCredentials? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeAuthSession? {
let isSignedIn = pigeonVar_list[0] as! Bool
let userSub: String? = nilOrValue(pigeonVar_list[1])
let userPoolTokens: NativeUserPoolTokens? = nilOrValue(pigeonVar_list[2])
let identityId: String? = nilOrValue(pigeonVar_list[3])
let awsCredentials: NativeAWSCredentials? = nilOrValue(pigeonVar_list[4])
return NativeAuthSession(
isSignedIn: isSignedIn,
userSub: userSub,
userPoolTokens: userPoolTokens,
identityId: identityId,
awsCredentials: awsCredentials
)
}
func toList() -> [Any?] {
return [
isSignedIn,
userSub,
userPoolTokens,
identityId,
awsCredentials,
]
}
static func == (lhs: NativeAuthSession, rhs: NativeAuthSession) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeAuthUser: Hashable {
var userId: String
var username: String
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeAuthUser? {
let userId = pigeonVar_list[0] as! String
let username = pigeonVar_list[1] as! String
return NativeAuthUser(
userId: userId,
username: username
)
}
func toList() -> [Any?] {
return [
userId,
username,
]
}
static func == (lhs: NativeAuthUser, rhs: NativeAuthUser) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeUserPoolTokens: Hashable {
var accessToken: String
var refreshToken: String
var idToken: String
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeUserPoolTokens? {
let accessToken = pigeonVar_list[0] as! String
let refreshToken = pigeonVar_list[1] as! String
let idToken = pigeonVar_list[2] as! String
return NativeUserPoolTokens(
accessToken: accessToken,
refreshToken: refreshToken,
idToken: idToken
)
}
func toList() -> [Any?] {
return [
accessToken,
refreshToken,
idToken,
]
}
static func == (lhs: NativeUserPoolTokens, rhs: NativeUserPoolTokens) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeAWSCredentials: Hashable {
var accessKeyId: String
var secretAccessKey: String
var sessionToken: String? = nil
var expirationIso8601Utc: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeAWSCredentials? {
let accessKeyId = pigeonVar_list[0] as! String
let secretAccessKey = pigeonVar_list[1] as! String
let sessionToken: String? = nilOrValue(pigeonVar_list[2])
let expirationIso8601Utc: String? = nilOrValue(pigeonVar_list[3])
return NativeAWSCredentials(
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
sessionToken: sessionToken,
expirationIso8601Utc: expirationIso8601Utc
)
}
func toList() -> [Any?] {
return [
accessKeyId,
secretAccessKey,
sessionToken,
expirationIso8601Utc,
]
}
static func == (lhs: NativeAWSCredentials, rhs: NativeAWSCredentials) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct LegacyCredentialStoreData: Hashable {
var identityId: String? = nil
var accessKeyId: String? = nil
var secretAccessKey: String? = nil
var sessionToken: String? = nil
var expirationMsSinceEpoch: Int64? = nil
var accessToken: String? = nil
var refreshToken: String? = nil
var idToken: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> LegacyCredentialStoreData? {
let identityId: String? = nilOrValue(pigeonVar_list[0])
let accessKeyId: String? = nilOrValue(pigeonVar_list[1])
let secretAccessKey: String? = nilOrValue(pigeonVar_list[2])
let sessionToken: String? = nilOrValue(pigeonVar_list[3])
let expirationMsSinceEpoch: Int64? = nilOrValue(pigeonVar_list[4])
let accessToken: String? = nilOrValue(pigeonVar_list[5])
let refreshToken: String? = nilOrValue(pigeonVar_list[6])
let idToken: String? = nilOrValue(pigeonVar_list[7])
return LegacyCredentialStoreData(
identityId: identityId,
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
sessionToken: sessionToken,
expirationMsSinceEpoch: expirationMsSinceEpoch,
accessToken: accessToken,
refreshToken: refreshToken,
idToken: idToken
)
}
func toList() -> [Any?] {
return [
identityId,
accessKeyId,
secretAccessKey,
sessionToken,
expirationMsSinceEpoch,
accessToken,
refreshToken,
idToken,
]
}
static func == (lhs: LegacyCredentialStoreData, rhs: LegacyCredentialStoreData) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeGraphQLResponse: Hashable {
var payloadJson: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeGraphQLResponse? {
let payloadJson: String? = nilOrValue(pigeonVar_list[0])
return NativeGraphQLResponse(
payloadJson: payloadJson
)
}
func toList() -> [Any?] {
return [
payloadJson
]
}
static func == (lhs: NativeGraphQLResponse, rhs: NativeGraphQLResponse) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeGraphQLSubscriptionResponse: Hashable {
var type: String
var subscriptionId: String
var payloadJson: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeGraphQLSubscriptionResponse? {
let type = pigeonVar_list[0] as! String
let subscriptionId = pigeonVar_list[1] as! String
let payloadJson: String? = nilOrValue(pigeonVar_list[2])
return NativeGraphQLSubscriptionResponse(
type: type,
subscriptionId: subscriptionId,
payloadJson: payloadJson
)
}
func toList() -> [Any?] {
return [
type,
subscriptionId,
payloadJson,
]
}
static func == (lhs: NativeGraphQLSubscriptionResponse, rhs: NativeGraphQLSubscriptionResponse) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct NativeGraphQLRequest: Hashable {
var document: String
var apiName: String? = nil
var variablesJson: String? = nil
var responseType: String? = nil
var decodePath: String? = nil
var options: String? = nil
var authMode: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> NativeGraphQLRequest? {
let document = pigeonVar_list[0] as! String
let apiName: String? = nilOrValue(pigeonVar_list[1])
let variablesJson: String? = nilOrValue(pigeonVar_list[2])
let responseType: String? = nilOrValue(pigeonVar_list[3])
let decodePath: String? = nilOrValue(pigeonVar_list[4])
let options: String? = nilOrValue(pigeonVar_list[5])
let authMode: String? = nilOrValue(pigeonVar_list[6])
return NativeGraphQLRequest(
document: document,
apiName: apiName,
variablesJson: variablesJson,
responseType: responseType,
decodePath: decodePath,
options: options,
authMode: authMode
)
}
func toList() -> [Any?] {
return [
document,
apiName,
variablesJson,
responseType,
decodePath,
options,
authMode,
]
}
static func == (lhs: NativeGraphQLRequest, rhs: NativeGraphQLRequest) -> Bool {
return deepEqualsNativePluginBindings(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashNativePluginBindings(value: toList(), hasher: &hasher)
}
}
private class NativePluginBindingsPigeonCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 129:
return NativeAuthSession.fromList(self.readValue() as! [Any?])
case 130:
return NativeAuthUser.fromList(self.readValue() as! [Any?])
case 131:
return NativeUserPoolTokens.fromList(self.readValue() as! [Any?])
case 132:
return NativeAWSCredentials.fromList(self.readValue() as! [Any?])
case 133:
return LegacyCredentialStoreData.fromList(self.readValue() as! [Any?])
case 134:
return NativeGraphQLResponse.fromList(self.readValue() as! [Any?])
case 135:
return NativeGraphQLSubscriptionResponse.fromList(self.readValue() as! [Any?])
case 136:
return NativeGraphQLRequest.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
}
}
private class NativePluginBindingsPigeonCodecWriter: FlutterStandardWriter {
override func writeValue(_ value: Any) {
if let value = value as? NativeAuthSession {
super.writeByte(129)
super.writeValue(value.toList())
} else if let value = value as? NativeAuthUser {
super.writeByte(130)
super.writeValue(value.toList())
} else if let value = value as? NativeUserPoolTokens {
super.writeByte(131)
super.writeValue(value.toList())
} else if let value = value as? NativeAWSCredentials {
super.writeByte(132)
super.writeValue(value.toList())
} else if let value = value as? LegacyCredentialStoreData {
super.writeByte(133)
super.writeValue(value.toList())
} else if let value = value as? NativeGraphQLResponse {
super.writeByte(134)
super.writeValue(value.toList())
} else if let value = value as? NativeGraphQLSubscriptionResponse {
super.writeByte(135)
super.writeValue(value.toList())
} else if let value = value as? NativeGraphQLRequest {
super.writeByte(136)
super.writeValue(value.toList())
} else {
super.writeValue(value)
}
}
}
private class NativePluginBindingsPigeonCodecReaderWriter: FlutterStandardReaderWriter {
override func reader(with data: Data) -> FlutterStandardReader {
return NativePluginBindingsPigeonCodecReader(data: data)
}
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
return NativePluginBindingsPigeonCodecWriter(data: data)
}
}
class NativePluginBindingsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = NativePluginBindingsPigeonCodec(readerWriter: NativePluginBindingsPigeonCodecReaderWriter())
}
/// Bridge for calling Auth from Native into Flutter
///
/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
protocol NativeAuthPluginProtocol {
func fetchAuthSession(completion: @escaping (Result<NativeAuthSession, PigeonError>) -> Void)
}
class NativeAuthPlugin: NativeAuthPluginProtocol {
private let binaryMessenger: FlutterBinaryMessenger
private let messageChannelSuffix: String
init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") {
self.binaryMessenger = binaryMessenger
self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
}
var codec: NativePluginBindingsPigeonCodec {
return NativePluginBindingsPigeonCodec.shared
}
func fetchAuthSession(completion: @escaping (Result<NativeAuthSession, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage(nil) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! NativeAuthSession
completion(.success(result))
}
}
}
}
/// Bridge for calling API plugin from Native into Flutter
///
/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
protocol NativeApiPluginProtocol {
func getLatestAuthToken(providerName providerNameArg: String, completion: @escaping (Result<String?, PigeonError>) -> Void)
func mutate(request requestArg: NativeGraphQLRequest, completion: @escaping (Result<NativeGraphQLResponse, PigeonError>) -> Void)
func query(request requestArg: NativeGraphQLRequest, completion: @escaping (Result<NativeGraphQLResponse, PigeonError>) -> Void)
func subscribe(request requestArg: NativeGraphQLRequest, completion: @escaping (Result<NativeGraphQLSubscriptionResponse, PigeonError>) -> Void)
func unsubscribe(subscriptionId subscriptionIdArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void)
func deviceOffline(completion: @escaping (Result<Void, PigeonError>) -> Void)
func onStop(completion: @escaping (Result<Void, PigeonError>) -> Void)
}
class NativeApiPlugin: NativeApiPluginProtocol {
private let binaryMessenger: FlutterBinaryMessenger
private let messageChannelSuffix: String
init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") {
self.binaryMessenger = binaryMessenger
self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
}
var codec: NativePluginBindingsPigeonCodec {
return NativePluginBindingsPigeonCodec.shared
}
func getLatestAuthToken(providerName providerNameArg: String, completion: @escaping (Result<String?, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([providerNameArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else {
let result: String? = nilOrValue(listResponse[0])
completion(.success(result))
}
}
}
func mutate(request requestArg: NativeGraphQLRequest, completion: @escaping (Result<NativeGraphQLResponse, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([requestArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! NativeGraphQLResponse
completion(.success(result))
}
}
}
func query(request requestArg: NativeGraphQLRequest, completion: @escaping (Result<NativeGraphQLResponse, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([requestArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! NativeGraphQLResponse
completion(.success(result))
}
}
}
func subscribe(request requestArg: NativeGraphQLRequest, completion: @escaping (Result<NativeGraphQLSubscriptionResponse, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([requestArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! NativeGraphQLSubscriptionResponse
completion(.success(result))
}
}
}
func unsubscribe(subscriptionId subscriptionIdArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([subscriptionIdArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else {
completion(.success(()))
}
}
}
func deviceOffline(completion: @escaping (Result<Void, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage(nil) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else {
completion(.success(()))
}
}
}
func onStop(completion: @escaping (Result<Void, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage(nil) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else {
completion(.success(()))
}
}
}
}
/// Bridge for calling Amplify from Flutter into Native
///
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol NativeAmplifyBridge {
func configure(version: String, config: String, completion: @escaping (Result<Void, Error>) -> Void)
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class NativeAmplifyBridgeSetup {
static var codec: FlutterStandardMessageCodec { NativePluginBindingsPigeonCodec.shared }
/// Sets up an instance of `NativeAmplifyBridge` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAmplifyBridge?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let configureChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
configureChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let versionArg = args[0] as! String
let configArg = args[1] as! String
api.configure(version: versionArg, config: configArg) { result in
switch result {
case .success:
reply(wrapResult(nil))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
configureChannel.setMessageHandler(nil)
}
}
}
/// Bridge for calling Auth plugin from Flutter into Native
///
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol NativeAuthBridge {
func addAuthPlugin(completion: @escaping (Result<Void, Error>) -> Void)
func updateCurrentUser(user: NativeAuthUser?) throws
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class NativeAuthBridgeSetup {
static var codec: FlutterStandardMessageCodec { NativePluginBindingsPigeonCodec.shared }
/// Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAuthBridge?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let addAuthPluginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
addAuthPluginChannel.setMessageHandler { _, reply in
api.addAuthPlugin { result in
switch result {
case .success:
reply(wrapResult(nil))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
addAuthPluginChannel.setMessageHandler(nil)
}
let updateCurrentUserChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
updateCurrentUserChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let userArg: NativeAuthUser? = nilOrValue(args[0])
do {
try api.updateCurrentUser(user: userArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
updateCurrentUserChannel.setMessageHandler(nil)
}
}
}
/// Bridge for calling API methods from Flutter into Native
///
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol NativeApiBridge {
func addApiPlugin(authProvidersList: [String], endpoints: [String: String], completion: @escaping (Result<Void, Error>) -> Void)
func sendSubscriptionEvent(event: NativeGraphQLSubscriptionResponse, completion: @escaping (Result<Void, Error>) -> Void)
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class NativeApiBridgeSetup {
static var codec: FlutterStandardMessageCodec { NativePluginBindingsPigeonCodec.shared }
/// Sets up an instance of `NativeApiBridge` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeApiBridge?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let addApiPluginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
addApiPluginChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let authProvidersListArg = args[0] as! [String]
let endpointsArg = args[1] as! [String: String]
api.addApiPlugin(authProvidersList: authProvidersListArg, endpoints: endpointsArg) { result in
switch result {
case .success:
reply(wrapResult(nil))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
addApiPluginChannel.setMessageHandler(nil)
}
let sendSubscriptionEventChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
sendSubscriptionEventChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let eventArg = args[0] as! NativeGraphQLSubscriptionResponse
api.sendSubscriptionEvent(event: eventArg) { result in
switch result {
case .success:
reply(wrapResult(nil))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
sendSubscriptionEventChannel.setMessageHandler(nil)
}
}
}