react-native-nitro-fetch 0.1.3 → 0.1.5

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 (50) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +7 -28
  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 +53 -29
  6. package/ios/NativeStorage.swift +61 -0
  7. package/ios/NitroAutoPrefetcher.swift +5 -41
  8. package/ios/NitroFetchClient.swift +25 -0
  9. package/lib/module/NitroFetch.nitro.js +0 -3
  10. package/lib/module/NitroFetch.nitro.js.map +1 -1
  11. package/lib/module/NitroInstances.js +2 -0
  12. package/lib/module/NitroInstances.js.map +1 -1
  13. package/lib/module/fetch.js +79 -125
  14. package/lib/module/fetch.js.map +1 -1
  15. package/lib/typescript/src/NitroFetch.nitro.d.ts +9 -0
  16. package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -1
  17. package/lib/typescript/src/NitroInstances.d.ts +3 -1
  18. package/lib/typescript/src/NitroInstances.d.ts.map +1 -1
  19. package/lib/typescript/src/fetch.d.ts.map +1 -1
  20. package/nitro.json +4 -0
  21. package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.cpp +54 -0
  22. package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.hpp +66 -0
  23. package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp +5 -0
  24. package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.hpp +1 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNativeStorageSpec.kt +60 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt +4 -0
  27. package/nitrogen/generated/android/nitrofetch+autolinking.cmake +9 -4
  28. package/nitrogen/generated/android/nitrofetchOnLoad.cpp +10 -0
  29. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.cpp +17 -0
  30. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +44 -0
  31. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Umbrella.hpp +5 -0
  32. package/nitrogen/generated/ios/NitroFetchAutolinking.mm +8 -0
  33. package/nitrogen/generated/ios/NitroFetchAutolinking.swift +15 -0
  34. package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.cpp +11 -0
  35. package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.hpp +85 -0
  36. package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.hpp +8 -0
  37. package/nitrogen/generated/ios/swift/HybridNativeStorageSpec.swift +51 -0
  38. package/nitrogen/generated/ios/swift/HybridNativeStorageSpec_cxx.swift +145 -0
  39. package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec.swift +1 -0
  40. package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec_cxx.swift +12 -0
  41. package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.cpp +23 -0
  42. package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.hpp +64 -0
  43. package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.cpp +1 -0
  44. package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.hpp +1 -0
  45. package/package.json +8 -24
  46. package/src/NitroFetch.nitro.ts +15 -5
  47. package/src/NitroInstances.ts +7 -1
  48. package/src/fetch.ts +158 -122
  49. package/LICENSE +0 -20
  50. package/README.md +0 -151
@@ -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
@@ -16,6 +16,7 @@ namespace margelo::nitro::nitrofetch {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridMethod("request", &HybridNitroFetchClientSpec::request);
18
18
  prototype.registerHybridMethod("prefetch", &HybridNitroFetchClientSpec::prefetch);
19
+ prototype.registerHybridMethod("requestSync", &HybridNitroFetchClientSpec::requestSync);
19
20
  });
20
21
  }
21
22
 
@@ -55,6 +55,7 @@ namespace margelo::nitro::nitrofetch {
55
55
  // Methods
56
56
  virtual std::shared_ptr<Promise<NitroResponse>> request(const NitroRequest& req) = 0;
57
57
  virtual std::shared_ptr<Promise<void>> prefetch(const NitroRequest& req) = 0;
58
+ virtual NitroResponse requestSync(const NitroRequest& req) = 0;
58
59
 
59
60
  protected:
60
61
  // Hybrid Setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-fetch",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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,18 +40,28 @@ 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`.
47
47
  prefetch(req: NitroRequest): Promise<void>;
48
+
49
+ // Synchronous version of request for worklets
50
+ requestSync(req: NitroRequest): NitroResponse;
48
51
  }
49
52
 
50
53
  export interface NitroFetch
51
- extends HybridObject<{ ios: 'swift'; android: 'kotlin'; }> {
54
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
52
55
  // Create a client bound to a given environment (e.g., cache dir).
53
56
  createClient(): NitroFetchClient;
54
57
 
55
58
  // Optional future: global abort/teardown
56
59
  // shutdown(): void;
57
60
  }
61
+
62
+ export interface NativeStorage
63
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
64
+ getString(key: string): string;
65
+ setString(key: string, value: string): void;
66
+ removeString(key: string): void;
67
+ }
@@ -1,8 +1,14 @@
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
 
11
+ export const NativeStorage: NativeStorageType =
12
+ NitroModules.createHybridObject<NativeStorageType>('NativeStorage');
8
13
 
14
+ export const boxedNitroFetch = NitroModules.box(NitroFetch);