react-native-nitro-fetch 0.1.2 → 0.1.4

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.
Files changed (45) hide show
  1. package/android/build.gradle +1 -0
  2. package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +8 -27
  3. package/android/src/main/java/com/margelo/nitro/nitrofetch/FetchCache.kt +11 -1
  4. package/android/src/main/java/com/margelo/nitro/nitrofetch/NativeStorage.kt +102 -0
  5. package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchClient.kt +3 -3
  6. package/ios/NativeStorage.swift +61 -0
  7. package/ios/NitroAutoPrefetcher.swift +5 -41
  8. package/lib/module/NitroFetch.nitro.js +0 -3
  9. package/lib/module/NitroFetch.nitro.js.map +1 -1
  10. package/lib/module/NitroInstances.js +1 -0
  11. package/lib/module/NitroInstances.js.map +1 -1
  12. package/lib/module/fetch.js +63 -81
  13. package/lib/module/fetch.js.map +1 -1
  14. package/lib/typescript/src/NitroFetch.nitro.d.ts +8 -0
  15. package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -1
  16. package/lib/typescript/src/NitroInstances.d.ts +2 -1
  17. package/lib/typescript/src/NitroInstances.d.ts.map +1 -1
  18. package/lib/typescript/src/fetch.d.ts.map +1 -1
  19. package/nitro.json +4 -0
  20. package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.cpp +54 -0
  21. package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.hpp +66 -0
  22. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNativeStorageSpec.kt +60 -0
  23. package/nitrogen/generated/android/nitrofetch+autolinking.cmake +9 -4
  24. package/nitrogen/generated/android/nitrofetchOnLoad.cpp +10 -0
  25. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.cpp +17 -0
  26. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +35 -0
  27. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Umbrella.hpp +5 -0
  28. package/nitrogen/generated/ios/NitroFetchAutolinking.mm +8 -0
  29. package/nitrogen/generated/ios/NitroFetchAutolinking.swift +15 -0
  30. package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.cpp +11 -0
  31. package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.hpp +85 -0
  32. package/nitrogen/generated/ios/swift/HybridNativeStorageSpec.swift +51 -0
  33. package/nitrogen/generated/ios/swift/HybridNativeStorageSpec_cxx.swift +145 -0
  34. package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.cpp +23 -0
  35. package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.hpp +64 -0
  36. package/package.json +8 -24
  37. package/src/NitroFetch.nitro.ts +12 -5
  38. package/src/NitroInstances.ts +6 -2
  39. package/src/fetch.ts +151 -89
  40. package/LICENSE +0 -20
  41. package/README.md +0 -144
  42. package/src/NitroFetch.nitro.js +0 -2
  43. package/src/NitroInstances.js +0 -3
  44. package/src/fetch.js +0 -377
  45. package/src/index.js +0 -8
@@ -0,0 +1,51 @@
1
+ ///
2
+ /// HybridNativeStorageSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /// See ``HybridNativeStorageSpec``
12
+ public protocol HybridNativeStorageSpec_protocol: HybridObject {
13
+ // Properties
14
+
15
+
16
+ // Methods
17
+ func getString(key: String) throws -> String
18
+ func setString(key: String, value: String) throws -> Void
19
+ func removeString(key: String) throws -> Void
20
+ }
21
+
22
+ /// See ``HybridNativeStorageSpec``
23
+ open class HybridNativeStorageSpec_base {
24
+ private weak var cxxWrapper: HybridNativeStorageSpec_cxx? = nil
25
+ public init() { }
26
+ public func getCxxWrapper() -> HybridNativeStorageSpec_cxx {
27
+ #if DEBUG
28
+ guard self is HybridNativeStorageSpec else {
29
+ fatalError("`self` is not a `HybridNativeStorageSpec`! Did you accidentally inherit from `HybridNativeStorageSpec_base` instead of `HybridNativeStorageSpec`?")
30
+ }
31
+ #endif
32
+ if let cxxWrapper = self.cxxWrapper {
33
+ return cxxWrapper
34
+ } else {
35
+ let cxxWrapper = HybridNativeStorageSpec_cxx(self as! HybridNativeStorageSpec)
36
+ self.cxxWrapper = cxxWrapper
37
+ return cxxWrapper
38
+ }
39
+ }
40
+ }
41
+
42
+ /**
43
+ * A Swift base-protocol representing the NativeStorage HybridObject.
44
+ * Implement this protocol to create Swift-based instances of NativeStorage.
45
+ * ```swift
46
+ * class HybridNativeStorage : HybridNativeStorageSpec {
47
+ * // ...
48
+ * }
49
+ * ```
50
+ */
51
+ public typealias HybridNativeStorageSpec = HybridNativeStorageSpec_protocol & HybridNativeStorageSpec_base
@@ -0,0 +1,145 @@
1
+ ///
2
+ /// HybridNativeStorageSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridNativeStorageSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridNativeStorageSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::nitrofetch::bridge::swift`)
23
+ * from `NitroFetch-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.nitrofetch.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridNativeStorageSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridNativeStorageSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridNativeStorageSpec_
37
+
38
+ /**
39
+ * Create a new `HybridNativeStorageSpec_cxx` that wraps the given `HybridNativeStorageSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridNativeStorageSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridNativeStorageSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridNativeStorageSpec() -> any HybridNativeStorageSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridNativeStorageSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridNativeStorageSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNativeStorageSpec_cxx {
70
+ return Unmanaged<HybridNativeStorageSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridNativeStorageSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridNativeStorageSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if cachedCxxPart.__convertToBool() {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridNativeStorageSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridNativeStorageSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ // Properties
109
+
110
+
111
+ // Methods
112
+ @inline(__always)
113
+ public final func getString(key: std.string) -> bridge.Result_std__string_ {
114
+ do {
115
+ let __result = try self.__implementation.getString(key: String(key))
116
+ let __resultCpp = std.string(__result)
117
+ return bridge.create_Result_std__string_(__resultCpp)
118
+ } catch (let __error) {
119
+ let __exceptionPtr = __error.toCpp()
120
+ return bridge.create_Result_std__string_(__exceptionPtr)
121
+ }
122
+ }
123
+
124
+ @inline(__always)
125
+ public final func setString(key: std.string, value: std.string) -> bridge.Result_void_ {
126
+ do {
127
+ try self.__implementation.setString(key: String(key), value: String(value))
128
+ return bridge.create_Result_void_()
129
+ } catch (let __error) {
130
+ let __exceptionPtr = __error.toCpp()
131
+ return bridge.create_Result_void_(__exceptionPtr)
132
+ }
133
+ }
134
+
135
+ @inline(__always)
136
+ public final func removeString(key: std.string) -> bridge.Result_void_ {
137
+ do {
138
+ try self.__implementation.removeString(key: String(key))
139
+ return bridge.create_Result_void_()
140
+ } catch (let __error) {
141
+ let __exceptionPtr = __error.toCpp()
142
+ return bridge.create_Result_void_(__exceptionPtr)
143
+ }
144
+ }
145
+ }
@@ -0,0 +1,23 @@
1
+ ///
2
+ /// HybridNativeStorageSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridNativeStorageSpec.hpp"
9
+
10
+ namespace margelo::nitro::nitrofetch {
11
+
12
+ void HybridNativeStorageSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("getString", &HybridNativeStorageSpec::getString);
18
+ prototype.registerHybridMethod("setString", &HybridNativeStorageSpec::setString);
19
+ prototype.registerHybridMethod("removeString", &HybridNativeStorageSpec::removeString);
20
+ });
21
+ }
22
+
23
+ } // namespace margelo::nitro::nitrofetch
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// HybridNativeStorageSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+ #include <string>
19
+
20
+ namespace margelo::nitro::nitrofetch {
21
+
22
+ using namespace margelo::nitro;
23
+
24
+ /**
25
+ * An abstract base class for `NativeStorage`
26
+ * Inherit this class to create instances of `HybridNativeStorageSpec` in C++.
27
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
28
+ * @example
29
+ * ```cpp
30
+ * class HybridNativeStorage: public HybridNativeStorageSpec {
31
+ * public:
32
+ * HybridNativeStorage(...): HybridObject(TAG) { ... }
33
+ * // ...
34
+ * };
35
+ * ```
36
+ */
37
+ class HybridNativeStorageSpec: public virtual HybridObject {
38
+ public:
39
+ // Constructor
40
+ explicit HybridNativeStorageSpec(): HybridObject(TAG) { }
41
+
42
+ // Destructor
43
+ ~HybridNativeStorageSpec() override = default;
44
+
45
+ public:
46
+ // Properties
47
+
48
+
49
+ public:
50
+ // Methods
51
+ virtual std::string getString(const std::string& key) = 0;
52
+ virtual void setString(const std::string& key, const std::string& value) = 0;
53
+ virtual void removeString(const std::string& key) = 0;
54
+
55
+ protected:
56
+ // Hybrid Setup
57
+ void loadHybridMethods() override;
58
+
59
+ protected:
60
+ // Tag for logging
61
+ static constexpr auto TAG = "NativeStorage";
62
+ };
63
+
64
+ } // namespace margelo::nitro::nitrofetch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-fetch",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Awesome Fetch :)",
5
5
  "main": "./lib/module/index.js",
6
6
  "module": "./lib/module/index.js",
@@ -37,13 +37,12 @@
37
37
  "!**/.*"
38
38
  ],
39
39
  "scripts": {
40
- "example": "yarn workspace react-native-nitro-fetch-example",
41
40
  "test": "jest",
42
41
  "typecheck": "tsc",
43
42
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
44
43
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
45
44
  "prepare": "bob build",
46
- "nitrogen": "nitro-codegen",
45
+ "nitrogen": "nitrogen",
47
46
  "release": "release-it --only-version"
48
47
  },
49
48
  "keywords": [
@@ -53,14 +52,14 @@
53
52
  ],
54
53
  "repository": {
55
54
  "type": "git",
56
- "url": "git+http://google.com.git"
55
+ "url": "git+https://github.com/margelo/react-native-nitro-fetch.git"
57
56
  },
58
57
  "author": "Szymon Kapala <szymon20000@gmail.com'> (https://x.com/Turbo_Szymon)",
59
58
  "license": "MIT",
60
59
  "bugs": {
61
- "url": "http://google.com/issues"
60
+ "url": "https://github.com/margelo/react-native-nitro-fetch/issues"
62
61
  },
63
- "homepage": "http://google.com#readme",
62
+ "homepage": "https://github.com/margelo/react-native-nitro-fetch#readme",
64
63
  "publishConfig": {
65
64
  "registry": "https://registry.npmjs.org/"
66
65
  },
@@ -81,7 +80,7 @@
81
80
  "eslint-config-prettier": "^10.1.1",
82
81
  "eslint-plugin-prettier": "^5.2.3",
83
82
  "jest": "^29.7.0",
84
- "nitro-codegen": "^0.29.2",
83
+ "nitrogen": "^0.29.2",
85
84
  "prettier": "^3.0.3",
86
85
  "react": "19.1.0",
87
86
  "react-native": "0.81.0",
@@ -113,28 +112,13 @@
113
112
  "<rootDir>/lib/"
114
113
  ]
115
114
  },
116
- "commitlint": {
117
- "extends": [
118
- "@commitlint/config-conventional"
119
- ]
120
- },
121
115
  "release-it": {
122
- "git": {
123
- "commitMessage": "chore: release ${version}",
124
- "tagName": "v${version}"
125
- },
116
+ "git": false,
126
117
  "npm": {
127
118
  "publish": true
128
119
  },
129
120
  "github": {
130
- "release": true
131
- },
132
- "plugins": {
133
- "@release-it/conventional-changelog": {
134
- "preset": {
135
- "name": "angular"
136
- }
137
- }
121
+ "release": false
138
122
  }
139
123
  },
140
124
  "prettier": {
@@ -10,10 +10,10 @@ export type NitroRequestMethod =
10
10
  | 'DELETE'
11
11
  | 'OPTIONS';
12
12
 
13
- export interface NitroHeader {
13
+ export interface NitroHeader {
14
14
  key: string;
15
15
  value: string;
16
- };
16
+ }
17
17
  export interface NitroRequest {
18
18
  url: string;
19
19
  method?: NitroRequestMethod;
@@ -21,7 +21,7 @@ export interface NitroRequest {
21
21
  headers?: NitroHeader[];
22
22
  // Body as either UTF-8 string or raw bytes.
23
23
  bodyString?: string;
24
- bodyBytes?: string; //will be ArrayBuffer in future
24
+ bodyBytes?: string; //will be ArrayBuffer in future
25
25
  // Controls
26
26
  timeoutMs?: number;
27
27
  followRedirects?: boolean; // default true
@@ -40,7 +40,7 @@ export interface NitroResponse {
40
40
  }
41
41
 
42
42
  export interface NitroFetchClient
43
- extends HybridObject<{ ios: 'swift'; android: 'kotlin'; }> {
43
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
44
44
  // Client-binded request that uses the env configured at creation.
45
45
  request(req: NitroRequest): Promise<NitroResponse>;
46
46
  // Start a prefetch for a given request; expects a header `prefetchKey`.
@@ -48,10 +48,17 @@ export interface NitroFetchClient
48
48
  }
49
49
 
50
50
  export interface NitroFetch
51
- extends HybridObject<{ ios: 'swift'; android: 'kotlin'; }> {
51
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
52
52
  // Create a client bound to a given environment (e.g., cache dir).
53
53
  createClient(): NitroFetchClient;
54
54
 
55
55
  // Optional future: global abort/teardown
56
56
  // shutdown(): void;
57
57
  }
58
+
59
+ export interface NativeStorage
60
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
61
+ getString(key: string): string;
62
+ setString(key: string, value: string): void;
63
+ removeString(key: string): void;
64
+ }
@@ -1,8 +1,12 @@
1
1
  import { NitroModules } from 'react-native-nitro-modules';
2
- import type { NitroFetch as NitroFetchType } from './NitroFetch.nitro';
2
+ import type {
3
+ NitroFetch as NitroFetchType,
4
+ NativeStorage as NativeStorageType,
5
+ } from './NitroFetch.nitro';
3
6
 
4
7
  // Create singletons once per JS runtime
5
8
  export const NitroFetch: NitroFetchType =
6
9
  NitroModules.createHybridObject<NitroFetchType>('NitroFetch');
7
10
 
8
-
11
+ export const NativeStorage: NativeStorageType =
12
+ NitroModules.createHybridObject<NativeStorageType>('NativeStorage');