react-native-nitro-fetch 0.3.0 → 1.0.1
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/app.plugin.js +1 -0
- package/expo/plugins/dist/index.d.ts +2 -0
- package/expo/plugins/dist/index.js +11 -0
- package/expo/plugins/dist/withAndroid.d.ts +2 -0
- package/expo/plugins/dist/withAndroid.js +21 -0
- package/ios/FetchCache.swift +14 -7
- package/lib/typescript/expo/plugins/src/index.d.ts +3 -0
- package/lib/typescript/expo/plugins/src/index.d.ts.map +1 -0
- package/lib/typescript/expo/plugins/src/withAndroid.d.ts +3 -0
- package/lib/typescript/expo/plugins/src/withAndroid.d.ts.map +1 -0
- package/package.json +11 -5
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./expo/plugins/dist/index.js').default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const withAndroid_1 = __importDefault(require("./withAndroid"));
|
|
7
|
+
const withNitroFetch = (config) => {
|
|
8
|
+
config = (0, withAndroid_1.default)(config);
|
|
9
|
+
return config;
|
|
10
|
+
};
|
|
11
|
+
exports.default = withNitroFetch;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
|
+
const withAndroidAutoPrefetch = (config) => {
|
|
5
|
+
return (0, config_plugins_1.withMainApplication)(config, (config) => {
|
|
6
|
+
let content = config.modResults.contents;
|
|
7
|
+
// Add import for AutoPrefetcher
|
|
8
|
+
if (!content.includes('import com.margelo.nitro.nitrofetch.AutoPrefetcher')) {
|
|
9
|
+
content = content.replace(/import android.app.Application/g, `import android.app.Application
|
|
10
|
+
import com.margelo.nitro.nitrofetch.AutoPrefetcher`);
|
|
11
|
+
}
|
|
12
|
+
// Add prefetchOnStart call in onCreate before loadReactNative
|
|
13
|
+
if (!content.includes('AutoPrefetcher.prefetchOnStart')) {
|
|
14
|
+
content = content.replace(/super\.onCreate\(\)/, `super.onCreate()
|
|
15
|
+
try { AutoPrefetcher.prefetchOnStart(this) } catch (_: Throwable) {}`);
|
|
16
|
+
}
|
|
17
|
+
config.modResults.contents = content;
|
|
18
|
+
return config;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.default = withAndroidAutoPrefetch;
|
package/ios/FetchCache.swift
CHANGED
|
@@ -25,28 +25,35 @@ final class FetchCache {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
static func complete(_ key: String, with result: Result<NitroResponse, Error>) {
|
|
28
|
-
var callbacks: [(Result<NitroResponse, Error>) -> Void] = []
|
|
29
|
-
queue.sync {
|
|
30
|
-
callbacks = pending[key] ?? []
|
|
31
|
-
}
|
|
32
28
|
queue.async(flags: .barrier) {
|
|
33
|
-
pending.removeValue(forKey: key)
|
|
29
|
+
let callbacks = pending.removeValue(forKey: key) ?? []
|
|
34
30
|
if case let .success(resp) = result {
|
|
35
31
|
results[key] = CachedEntry(response: resp, timestampMs: Int64(Date().timeIntervalSince1970 * 1000))
|
|
36
32
|
}
|
|
33
|
+
callbacks.forEach { $0(result) }
|
|
37
34
|
}
|
|
38
|
-
callbacks.forEach { $0(result) }
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
static func getResultIfFresh(_ key: String, maxAgeMs: Int64) -> NitroResponse? {
|
|
42
38
|
var out: NitroResponse?
|
|
39
|
+
var shouldEvict = false
|
|
43
40
|
queue.sync {
|
|
44
41
|
if let entry = results[key] {
|
|
45
42
|
let age = Int64(Date().timeIntervalSince1970 * 1000) - entry.timestampMs
|
|
46
43
|
if age <= maxAgeMs {
|
|
47
44
|
out = entry.response
|
|
48
45
|
} else {
|
|
49
|
-
|
|
46
|
+
shouldEvict = true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if shouldEvict {
|
|
51
|
+
queue.async(flags: .barrier) {
|
|
52
|
+
if let entry = results[key] {
|
|
53
|
+
let age = Int64(Date().timeIntervalSince1970 * 1000) - entry.timestampMs
|
|
54
|
+
if age > maxAgeMs {
|
|
55
|
+
results.removeValue(forKey: key)
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../expo/plugins/src/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,cAAc,EAAE,GAGrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAndroid.d.ts","sourceRoot":"","sources":["../../../../../expo/plugins/src/withAndroid.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,uBAAuB,GAAI,QAAQ,GAAG,4CA2B3C,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Awesome Fetch :)",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"types": "./lib/typescript/src/index.d.ts",
|
|
14
14
|
"default": "./lib/module/index.js"
|
|
15
15
|
},
|
|
16
|
-
"./package.json": "./package.json"
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
"./app.plugin.js": "./app.plugin.js"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"src",
|
|
@@ -34,16 +35,19 @@
|
|
|
34
35
|
"!**/__tests__",
|
|
35
36
|
"!**/__fixtures__",
|
|
36
37
|
"!**/__mocks__",
|
|
37
|
-
"!**/.*"
|
|
38
|
+
"!**/.*",
|
|
39
|
+
"expo/plugins/dist",
|
|
40
|
+
"app.plugin.js"
|
|
38
41
|
],
|
|
39
42
|
"scripts": {
|
|
40
43
|
"test": "jest",
|
|
41
44
|
"typecheck": "tsc",
|
|
42
45
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
43
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
46
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib expo/plugins/dist",
|
|
44
47
|
"prepare": "bob build",
|
|
48
|
+
"build:plugin": "cd expo/plugins && npx tsc",
|
|
45
49
|
"nitrogen": "nitrogen",
|
|
46
|
-
"release": "release-it --only-version"
|
|
50
|
+
"release": "npm run build:plugin && release-it --only-version"
|
|
47
51
|
},
|
|
48
52
|
"keywords": [
|
|
49
53
|
"react-native",
|
|
@@ -75,7 +79,9 @@
|
|
|
75
79
|
"@types/jest": "^29.5.5",
|
|
76
80
|
"@types/react": "^19.2.0",
|
|
77
81
|
"commitlint": "^19.6.1",
|
|
82
|
+
"@expo/config-plugins": "^9.0.0",
|
|
78
83
|
"del-cli": "^5.1.0",
|
|
84
|
+
"expo-module-scripts": "^5.0.8",
|
|
79
85
|
"eslint": "^9.22.0",
|
|
80
86
|
"eslint-config-prettier": "^10.1.1",
|
|
81
87
|
"eslint-plugin-prettier": "^5.2.3",
|