react-nitro-networking 0.0.0-stage → 0.0.1-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/Package.swift +102 -0
- package/README.md +58 -2
- package/Sources/ReactNitroNetworking/HybridNetworking.swift +17 -0
- package/Sources/ReactNitroNetworking/HybridResponse.swift +87 -0
- package/Sources/ReactNitroNetworking/HybridWebSocket.swift +188 -0
- package/Sources/ReactNitroNetworking/NetworkingTaskDelegate.swift +16 -0
- package/Sources/ReactNitroNetworking/WebSocketListeners.swift +49 -0
- package/Sources/ReactNitroNetworking/WebSocketTaskDelegate.swift +26 -0
- package/Sources/ReactNitroNetworking/WebSocketURL.swift +18 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/apple/ReactNitroNetworking-Swift-Cxx-Bridge.cpp +171 -0
- package/nitrogen/generated/apple/ReactNitroNetworkingAppleCxx/ReactNitroNetworkingAppleCxx.cpp +9 -0
- package/nitrogen/generated/apple/ReactNitroNetworkingAppleCxx/include/ReactNitroNetworkingAppleCxx/ReactNitroNetworkingAppleCxx.h +97 -0
- package/nitrogen/generated/apple/ReactNitroNetworkingAutolinking.cpp +24 -0
- package/nitrogen/generated/apple/ReactNitroNetworkingAutolinking.mm +24 -0
- package/nitrogen/generated/apple/c++/HybridNetworkingSpecSwift.cpp +42 -0
- package/nitrogen/generated/apple/c++/HybridNetworkingSpec_cxx-Swift.cpp +28 -0
- package/nitrogen/generated/apple/c++/HybridResponseSpecSwift.cpp +102 -0
- package/nitrogen/generated/apple/c++/HybridResponseSpec_cxx-Swift.cpp +28 -0
- package/nitrogen/generated/apple/c++/HybridWebSocketSpecSwift.cpp +111 -0
- package/nitrogen/generated/apple/c++/HybridWebSocketSpec_cxx-Swift.cpp +28 -0
- package/nitrogen/generated/apple/c++/ListenerSubscription-Swift.cpp +37 -0
- package/nitrogen/generated/apple/c++/Record_swift__String_swift__String-Swift.cpp +26 -0
- package/nitrogen/generated/apple/c++/ResponseType-Swift.cpp +58 -0
- package/nitrogen/generated/apple/c++/Variant_ArrayBuffer_String-Swift.cpp +41 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/ReactNitroNetworkingAutolinking.hpp +13 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/HybridNetworkingSpecSwift.hpp +72 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/HybridNetworkingSpec_cxx-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/HybridResponseSpecSwift.hpp +81 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/HybridResponseSpec_cxx-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/HybridWebSocketSpecSwift.hpp +78 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/HybridWebSocketSpec_cxx-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/ListenerSubscription-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/ReactNitroNetworking-Swift-Cxx-Umbrella.hpp +44 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/Record_swift__String_swift__String-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/ResponseType-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNetworking/private/Variant_ArrayBuffer_String-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/module.modulemap +12 -0
- package/nitrogen/generated/apple/swift/Callback_void.swift +60 -0
- package/nitrogen/generated/apple/swift/Callback_void___ReactNitroNetworking__Variant_ArrayBuffer_String_cxx.swift +66 -0
- package/nitrogen/generated/apple/swift/Callback_void_std__exception_ptr.swift +60 -0
- package/nitrogen/generated/apple/swift/HybridNetworkingSpec.swift +65 -0
- package/nitrogen/generated/apple/swift/HybridNetworkingSpec_cxx.swift +143 -0
- package/nitrogen/generated/apple/swift/HybridResponseSpec.swift +74 -0
- package/nitrogen/generated/apple/swift/HybridResponseSpec_cxx.swift +201 -0
- package/nitrogen/generated/apple/swift/HybridWebSocketSpec.swift +70 -0
- package/nitrogen/generated/apple/swift/HybridWebSocketSpec_cxx.swift +201 -0
- package/nitrogen/generated/apple/swift/ListenerSubscription.swift +29 -0
- package/nitrogen/generated/apple/swift/Promise_ArrayBuffer.swift +100 -0
- package/nitrogen/generated/apple/swift/Promise_NitroModules__AnyJSON.swift +102 -0
- package/nitrogen/generated/apple/swift/Promise___ReactNitroNetworking__HybridResponseSpec_cxx.swift +102 -0
- package/nitrogen/generated/apple/swift/Promise_swift__String.swift +102 -0
- package/nitrogen/generated/apple/swift/Promise_void.swift +100 -0
- package/nitrogen/generated/apple/swift/Record_swift__String_swift__String.swift +48 -0
- package/nitrogen/generated/apple/swift/ResponseType.swift +74 -0
- package/nitrogen/generated/apple/swift/Variant_ArrayBuffer_String.swift +69 -0
- package/nitrogen/generated/hybrid-classes.json +29 -0
- package/nitrogen/generated/shared/c++/ReactNitroNetworkingCxxModule.cpp +2 -0
- package/nitrogen/generated/shared/c++/include/ReactNitroNetworking/ReactNitroNetworkingCxxModule.hpp +2 -0
- package/nitrogen/generated/shared/javascript/Networking.cjs +19 -0
- package/nitrogen/generated/shared/javascript/Networking.d.cts +9 -0
- package/nitrogen/generated/shared/javascript/Response.cjs +19 -0
- package/nitrogen/generated/shared/javascript/Response.d.cts +9 -0
- package/nitrogen/generated/shared/javascript/WebSocket.cjs +19 -0
- package/nitrogen/generated/shared/javascript/WebSocket.d.cts +9 -0
- package/package.json +34 -4
- package/src/ListenerSubscription.ts +7 -0
- package/src/ResponseType.ts +8 -0
- package/src/index.ts +5 -0
- package/src/specs/Networking.nitro.ts +18 -0
- package/src/specs/Response.nitro.ts +37 -0
- package/src/specs/WebSocket.nitro.ts +62 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Promise_swift__String.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
public import NitroModules
|
|
9
|
+
internal import CxxStdlib
|
|
10
|
+
public import Dispatch
|
|
11
|
+
internal import ReactNitroNetworkingAppleCxx
|
|
12
|
+
|
|
13
|
+
public typealias Promise_swift__String = margelo.nitro.networking.swift_bridge.Promise_swift__String
|
|
14
|
+
|
|
15
|
+
extension Promise_swift__String {
|
|
16
|
+
public typealias T = String
|
|
17
|
+
private typealias bridge = margelo.nitro.networking.swift_bridge
|
|
18
|
+
|
|
19
|
+
public func __nitroResolve(result: String) {
|
|
20
|
+
withUnsafePointer(to: result) { (pointer: UnsafePointer<String>) -> Void in
|
|
21
|
+
bridge.resolve_Promise_swift__String(self, pointer)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
public func __nitroReject(error: any Error) {
|
|
25
|
+
bridge.reject_Promise_swift__String(self, error.toCpp())
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public func __nitroAddOnResolvedListener(_ listener: @escaping @Sendable (String) -> Void) {
|
|
29
|
+
bridge.listen_Promise_swift__String(self, .init { (value: UnsafeRawPointer!) -> Void in
|
|
30
|
+
listener(value.load(as: String.self))
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
public func __nitroAddOnRejectedListener(_ listener: @escaping @Sendable (any Error) -> Void) {
|
|
34
|
+
bridge.listenRejected_Promise_swift__String(self, .init { (exceptionPtr: std.exception_ptr) -> Void in
|
|
35
|
+
listener(RuntimeError.from(cppError: exceptionPtr))
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
extension Promise<String> where Self == Promise_swift__String {
|
|
41
|
+
public static func pending() -> Self {
|
|
42
|
+
return margelo.nitro.networking.swift_bridge.create_Promise_swift__String()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static func resolved(with result: String) -> Self {
|
|
46
|
+
let promise = Promise_swift__String.pending()
|
|
47
|
+
promise.resolve(result: result)
|
|
48
|
+
return promise
|
|
49
|
+
}
|
|
50
|
+
public static func rejected(with error: any Error) -> Self {
|
|
51
|
+
let promise = Promise_swift__String.pending()
|
|
52
|
+
promise.reject(error: error)
|
|
53
|
+
return promise
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static func `async`(
|
|
57
|
+
_ priority: TaskPriority? = nil,
|
|
58
|
+
_ run: sending @escaping @isolated(any) () async throws -> sending String
|
|
59
|
+
) -> Self {
|
|
60
|
+
let promise = Promise_swift__String.pending()
|
|
61
|
+
Task(priority: priority) { () async -> Void in
|
|
62
|
+
do {
|
|
63
|
+
promise.resolve(result: try await run())
|
|
64
|
+
} catch {
|
|
65
|
+
promise.reject(error: error)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return promise
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static func parallel(
|
|
72
|
+
_ queue: DispatchQueue = .global(),
|
|
73
|
+
_ run: @escaping @Sendable () throws -> String
|
|
74
|
+
) -> Self {
|
|
75
|
+
let promise = Promise_swift__String.pending()
|
|
76
|
+
queue.async { () -> Void in
|
|
77
|
+
do {
|
|
78
|
+
promise.resolve(result: try run())
|
|
79
|
+
} catch {
|
|
80
|
+
promise.reject(error: error)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return promise
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
extension Promise<String> {
|
|
88
|
+
func toCpp() -> Promise_swift__String {
|
|
89
|
+
if let self = self as? Promise_swift__String {
|
|
90
|
+
return self
|
|
91
|
+
} else {
|
|
92
|
+
let promise = Promise_swift__String.pending()
|
|
93
|
+
self.addOnResolvedListener { (result: String) -> Void in
|
|
94
|
+
promise.resolve(result: result)
|
|
95
|
+
}
|
|
96
|
+
self.addOnRejectedListener { (error: any Error) -> Void in
|
|
97
|
+
promise.reject(error: error)
|
|
98
|
+
}
|
|
99
|
+
return promise
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Promise_void.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
public import NitroModules
|
|
9
|
+
internal import CxxStdlib
|
|
10
|
+
public import Dispatch
|
|
11
|
+
internal import ReactNitroNetworkingAppleCxx
|
|
12
|
+
|
|
13
|
+
public typealias Promise_void = margelo.nitro.networking.swift_bridge.Promise_void
|
|
14
|
+
|
|
15
|
+
extension Promise_void {
|
|
16
|
+
public typealias T = Void
|
|
17
|
+
private typealias bridge = margelo.nitro.networking.swift_bridge
|
|
18
|
+
|
|
19
|
+
public func __nitroResolve(result: ()) {
|
|
20
|
+
resolve()
|
|
21
|
+
}
|
|
22
|
+
public func __nitroReject(error: any Error) {
|
|
23
|
+
reject(consuming: error.toCpp())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public func __nitroAddOnResolvedListener(_ listener: @escaping @Sendable (()) -> Void) {
|
|
27
|
+
addOnResolvedListener(.init { () -> Void in
|
|
28
|
+
listener(())
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
public func __nitroAddOnRejectedListener(_ listener: @escaping @Sendable (any Error) -> Void) {
|
|
32
|
+
addOnRejectedListener(.init { (exceptionPtr: std.exception_ptr) -> Void in
|
|
33
|
+
listener(RuntimeError.from(cppError: exceptionPtr))
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
extension Promise<Void> where Self == Promise_void {
|
|
39
|
+
public static func pending() -> Self {
|
|
40
|
+
return Promise_void.__pending()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static func resolved() -> Self {
|
|
44
|
+
let promise = Promise_void.pending()
|
|
45
|
+
promise.resolve(result: ())
|
|
46
|
+
return promise
|
|
47
|
+
}
|
|
48
|
+
public static func rejected(with error: any Error) -> Self {
|
|
49
|
+
let promise = Promise_void.pending()
|
|
50
|
+
promise.reject(error: error)
|
|
51
|
+
return promise
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static func `async`(
|
|
55
|
+
_ priority: TaskPriority? = nil,
|
|
56
|
+
_ run: sending @escaping @isolated(any) () async throws -> sending Void
|
|
57
|
+
) -> Self {
|
|
58
|
+
let promise = Promise_void.pending()
|
|
59
|
+
Task(priority: priority) { () async -> Void in
|
|
60
|
+
do {
|
|
61
|
+
promise.resolve(result: try await run())
|
|
62
|
+
} catch {
|
|
63
|
+
promise.reject(error: error)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return promise
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public static func parallel(
|
|
70
|
+
_ queue: DispatchQueue = .global(),
|
|
71
|
+
_ run: @escaping @Sendable () throws -> Void
|
|
72
|
+
) -> Self {
|
|
73
|
+
let promise = Promise_void.pending()
|
|
74
|
+
queue.async { () -> Void in
|
|
75
|
+
do {
|
|
76
|
+
promise.resolve(result: try run())
|
|
77
|
+
} catch {
|
|
78
|
+
promise.reject(error: error)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return promise
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
extension Promise<Void> {
|
|
86
|
+
func toCpp() -> Promise_void {
|
|
87
|
+
if let self = self as? Promise_void {
|
|
88
|
+
return self
|
|
89
|
+
} else {
|
|
90
|
+
let promise = Promise_void.pending()
|
|
91
|
+
self.addOnResolvedListener { (result: Void) -> Void in
|
|
92
|
+
promise.resolve(result: result)
|
|
93
|
+
}
|
|
94
|
+
self.addOnRejectedListener { (error: any Error) -> Void in
|
|
95
|
+
promise.reject(error: error)
|
|
96
|
+
}
|
|
97
|
+
return promise
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Record_swift__String_swift__String.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
internal import NitroModules
|
|
9
|
+
internal import CxxStdlib
|
|
10
|
+
|
|
11
|
+
@_expose(Cxx)
|
|
12
|
+
public struct Record_swift__String_swift__String: Equatable, Hashable, Sendable {
|
|
13
|
+
private var storage: Dictionary<String, String>
|
|
14
|
+
public var dictionary: Dictionary<String, String> { storage }
|
|
15
|
+
|
|
16
|
+
public init(_ dictionary: Dictionary<String, String>) {
|
|
17
|
+
self.storage = dictionary
|
|
18
|
+
}
|
|
19
|
+
public init(minimumCapacity: Int) {
|
|
20
|
+
self.storage = .init(minimumCapacity: minimumCapacity)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public mutating func set(key: String, value: String) {
|
|
24
|
+
storage.updateValue(value, forKey: key)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public borrowing func makeCursor() -> Cursor {
|
|
28
|
+
return Cursor(storage)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public struct Cursor {
|
|
32
|
+
private var iterator: Dictionary<String, String>.Iterator
|
|
33
|
+
|
|
34
|
+
fileprivate init(_ dictionary: Dictionary<String, String>) {
|
|
35
|
+
self.iterator = dictionary.makeIterator()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Optional output slots also support values without a default initializer.
|
|
39
|
+
public mutating func next(key: inout String?, value: inout String?) -> Bool {
|
|
40
|
+
guard let entry = iterator.next() else {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
key = entry.key
|
|
44
|
+
value = .some(entry.value)
|
|
45
|
+
return true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ResponseType.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents the JS union `ResponseType`.
|
|
12
|
+
*/
|
|
13
|
+
@_expose(Cxx)
|
|
14
|
+
public enum ResponseType: Int32, CaseIterable, Sendable, CustomStringConvertible {
|
|
15
|
+
case `basic` = 0
|
|
16
|
+
case `cors` = 1
|
|
17
|
+
case `default` = 2
|
|
18
|
+
case `error` = 3
|
|
19
|
+
case `opaque` = 4
|
|
20
|
+
case `opaqueredirect` = 5
|
|
21
|
+
|
|
22
|
+
public static func fromRawValue(_ value: Int32) -> Self {
|
|
23
|
+
return Self(rawValue: value)!
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public extension ResponseType {
|
|
28
|
+
/**
|
|
29
|
+
* Get a ResponseType for the given String value, or
|
|
30
|
+
* return `nil` if the given value was invalid/unknown.
|
|
31
|
+
*/
|
|
32
|
+
init?(fromString string: String) {
|
|
33
|
+
switch string {
|
|
34
|
+
case "basic":
|
|
35
|
+
self = .basic
|
|
36
|
+
case "cors":
|
|
37
|
+
self = .cors
|
|
38
|
+
case "default":
|
|
39
|
+
self = .default
|
|
40
|
+
case "error":
|
|
41
|
+
self = .error
|
|
42
|
+
case "opaque":
|
|
43
|
+
self = .opaque
|
|
44
|
+
case "opaqueredirect":
|
|
45
|
+
self = .opaqueredirect
|
|
46
|
+
default:
|
|
47
|
+
return nil
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get the String value this ResponseType represents.
|
|
53
|
+
*/
|
|
54
|
+
var stringValue: String {
|
|
55
|
+
switch self {
|
|
56
|
+
case .basic:
|
|
57
|
+
return "basic"
|
|
58
|
+
case .cors:
|
|
59
|
+
return "cors"
|
|
60
|
+
case .default:
|
|
61
|
+
return "default"
|
|
62
|
+
case .error:
|
|
63
|
+
return "error"
|
|
64
|
+
case .opaque:
|
|
65
|
+
return "opaque"
|
|
66
|
+
case .opaqueredirect:
|
|
67
|
+
return "opaqueredirect"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var description: String {
|
|
72
|
+
return stringValue
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Variant_ArrayBuffer_String.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
public import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A Swift enum with associated values representing a Variant/Union type.
|
|
12
|
+
* JS type: `array-buffer | string`
|
|
13
|
+
*/
|
|
14
|
+
@frozen
|
|
15
|
+
public enum Variant_ArrayBuffer_String: Equatable {
|
|
16
|
+
case first(ArrayBuffer)
|
|
17
|
+
case second(String)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public extension Variant_ArrayBuffer_String {
|
|
21
|
+
func asType<T>(_ type: T.Type = T.self) -> T? {
|
|
22
|
+
switch self {
|
|
23
|
+
case .first(let value): return value as? T
|
|
24
|
+
case .second(let value): return value as? T
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
func isType<T>(_ type: T.Type = T.self) -> Bool {
|
|
28
|
+
return self.asType(type) != nil
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Raw Swift storage keeps associated values containing imported C++ types exportable.
|
|
33
|
+
@_expose(Cxx)
|
|
34
|
+
public struct Variant_ArrayBuffer_String_cxx: Equatable {
|
|
35
|
+
let value: Variant_ArrayBuffer_String
|
|
36
|
+
|
|
37
|
+
init(_ value: Variant_ArrayBuffer_String) {
|
|
38
|
+
self.value = value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public var index: Int {
|
|
42
|
+
switch value {
|
|
43
|
+
case .first: return 0
|
|
44
|
+
case .second: return 1
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@_spi(NitroCxx)
|
|
49
|
+
public static func initializeFirst(_ payload: ArrayBuffer, result: UnsafeMutableRawPointer) {
|
|
50
|
+
result.assumingMemoryBound(to: Variant_ArrayBuffer_String_cxx.self).initialize(to: Self(.first(payload)))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@_spi(NitroCxx)
|
|
54
|
+
public borrowing func getFirst() -> ArrayBuffer {
|
|
55
|
+
guard case .first(let payload) = value else { preconditionFailure("Invalid variant case") }
|
|
56
|
+
return payload
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@_spi(NitroCxx)
|
|
60
|
+
public static func initializeSecond(_ payload: String, result: UnsafeMutableRawPointer) {
|
|
61
|
+
result.assumingMemoryBound(to: Variant_ArrayBuffer_String_cxx.self).initialize(to: Self(.second(payload)))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@_spi(NitroCxx)
|
|
65
|
+
public borrowing func getSecond() -> String {
|
|
66
|
+
guard case .second(let payload) = value else { preconditionFailure("Invalid variant case") }
|
|
67
|
+
return payload
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"classes": {
|
|
4
|
+
"Networking": {
|
|
5
|
+
"apple": {
|
|
6
|
+
"implementation": {
|
|
7
|
+
"className": "HybridNetworking"
|
|
8
|
+
},
|
|
9
|
+
"language": "swift"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"Response": {
|
|
13
|
+
"apple": {
|
|
14
|
+
"implementation": {
|
|
15
|
+
"className": "HybridResponse"
|
|
16
|
+
},
|
|
17
|
+
"language": "swift"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"WebSocket": {
|
|
21
|
+
"apple": {
|
|
22
|
+
"implementation": {
|
|
23
|
+
"className": "HybridWebSocket"
|
|
24
|
+
},
|
|
25
|
+
"language": "swift"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Networking.cjs
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
const { NitroModules } = require('nitro-core')
|
|
9
|
+
|
|
10
|
+
let hybridClass
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
get Networking() {
|
|
14
|
+
if (hybridClass === undefined) {
|
|
15
|
+
hybridClass = NitroModules.getHybridClass('networking.Networking')
|
|
16
|
+
}
|
|
17
|
+
return hybridClass
|
|
18
|
+
},
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Networking.d.cts
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
// The spec's `export declare class Networking` types this runtime export.
|
|
9
|
+
export {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Response.cjs
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
const { NitroModules } = require('nitro-core')
|
|
9
|
+
|
|
10
|
+
let hybridClass
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
get Response() {
|
|
14
|
+
if (hybridClass === undefined) {
|
|
15
|
+
hybridClass = NitroModules.getHybridClass('networking.Response')
|
|
16
|
+
}
|
|
17
|
+
return hybridClass
|
|
18
|
+
},
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Response.d.cts
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
// The spec's `export declare class Response` types this runtime export.
|
|
9
|
+
export {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// WebSocket.cjs
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
const { NitroModules } = require('nitro-core')
|
|
9
|
+
|
|
10
|
+
let hybridClass
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
get WebSocket() {
|
|
14
|
+
if (hybridClass === undefined) {
|
|
15
|
+
hybridClass = NitroModules.getHybridClass('networking.WebSocket')
|
|
16
|
+
}
|
|
17
|
+
return hybridClass
|
|
18
|
+
},
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// WebSocket.d.cts
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
// The spec's `export declare class WebSocket` types this runtime export.
|
|
9
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-nitro-networking",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
"version": "0.0.1-alpha.7",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"nitro-core": "1.0.0-alpha.nightly.105.g69d365fc9b18"
|
|
6
|
+
},
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"tag": "latest",
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"module": "./src/index.ts",
|
|
12
|
+
"types": "./src/index.ts",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"imports": {
|
|
15
|
+
"#nitro/*": "./nitrogen/generated/shared/javascript/*.cjs"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/margelo/react-nitro.git",
|
|
21
|
+
"directory": "packages/react-nitro-networking"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./src/index.ts",
|
|
26
|
+
"default": "./src/index.ts"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"src",
|
|
32
|
+
"Package.swift",
|
|
33
|
+
"Sources",
|
|
34
|
+
"nitrogen/generated"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WebSocket } from './specs/WebSocket.nitro'
|
|
2
|
+
|
|
3
|
+
/** Owns a listener registered on a {@linkcode WebSocket}. */
|
|
4
|
+
export interface ListenerSubscription {
|
|
5
|
+
/** Removes this listener. Safe to call more than once; an in-flight event may still arrive. */
|
|
6
|
+
remove: () => void
|
|
7
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Networking } from './specs/Networking.nitro'
|
|
2
|
+
export { Response } from './specs/Response.nitro'
|
|
3
|
+
export { WebSocket } from './specs/WebSocket.nitro'
|
|
4
|
+
export type { ResponseType } from './ResponseType'
|
|
5
|
+
export type { ListenerSubscription } from './ListenerSubscription'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { iOS, type HybridObject } from 'nitro-core'
|
|
2
|
+
import type { Response } from './Response.nitro'
|
|
3
|
+
|
|
4
|
+
export * from '#nitro/Networking'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Provides native networking operations.
|
|
8
|
+
* @see {@link Networking.fetch}
|
|
9
|
+
*/
|
|
10
|
+
@iOS({
|
|
11
|
+
language: 'swift',
|
|
12
|
+
implementation: {
|
|
13
|
+
className: 'HybridNetworking',
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
export declare class Networking extends HybridObject {
|
|
17
|
+
static fetch(url: string): Promise<Response>
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { iOS, type AnyJSON, type HybridObject } from 'nitro-core'
|
|
2
|
+
import type { ResponseType } from '../ResponseType'
|
|
3
|
+
|
|
4
|
+
export * from '#nitro/Response'
|
|
5
|
+
|
|
6
|
+
@iOS({
|
|
7
|
+
language: 'swift',
|
|
8
|
+
implementation: {
|
|
9
|
+
className: 'HybridResponse',
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
export declare class Response extends HybridObject {
|
|
13
|
+
/** Response headers keyed by lowercase name; currently a record, not web Headers. */
|
|
14
|
+
readonly headers: Record<string, string>
|
|
15
|
+
/** HTTP status code, or 0 for a non-HTTP response. */
|
|
16
|
+
readonly status: number
|
|
17
|
+
/** Whether the HTTP status is in the 200–299 range. */
|
|
18
|
+
readonly ok: boolean
|
|
19
|
+
/** Empty because URLSession does not expose the HTTP reason phrase. */
|
|
20
|
+
readonly statusText: string
|
|
21
|
+
/** The final response URL. */
|
|
22
|
+
readonly url: string
|
|
23
|
+
/** Whether URLSession followed an HTTP redirect. */
|
|
24
|
+
readonly redirected: boolean
|
|
25
|
+
/** Native requests currently produce basic responses without browser CORS filtering. */
|
|
26
|
+
readonly type: ResponseType
|
|
27
|
+
/** Whether a body-consumption method has been called. */
|
|
28
|
+
readonly bodyUsed: boolean
|
|
29
|
+
|
|
30
|
+
arrayBuffer(): Promise<ArrayBuffer>
|
|
31
|
+
/**
|
|
32
|
+
* Parses the body as UTF-8 JSON, skipping a leading UTF-8 BOM.
|
|
33
|
+
* Rejects with the JSON parse error if the body is not valid JSON.
|
|
34
|
+
*/
|
|
35
|
+
json(): Promise<AnyJSON>
|
|
36
|
+
text(): Promise<string>
|
|
37
|
+
}
|