@modern-js/runtime-utils 2.65.4 → 2.66.0
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/dist/cjs/universal/cache.js +9 -4
- package/dist/esm/universal/cache.js +10 -5
- package/dist/esm-node/universal/cache.js +9 -4
- package/dist/types/browser/nestedRoutes.d.ts +0 -1
- package/dist/types/node/fileReader.d.ts +1 -4
- package/dist/types/node/stream.d.ts +0 -1
- package/dist/types/universal/async_storage.server.d.ts +8 -9
- package/package.json +6 -7
|
@@ -142,17 +142,22 @@ function cache(fn, options) {
|
|
|
142
142
|
requestCache = /* @__PURE__ */ new Map();
|
|
143
143
|
requestCacheMap.set(request, requestCache);
|
|
144
144
|
}
|
|
145
|
+
let fnCache = requestCache.get(fn);
|
|
146
|
+
if (!fnCache) {
|
|
147
|
+
fnCache = /* @__PURE__ */ new Map();
|
|
148
|
+
requestCache.set(fn, fnCache);
|
|
149
|
+
}
|
|
145
150
|
const key = generateKey(args);
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
151
|
+
if (fnCache.has(key)) {
|
|
152
|
+
return fnCache.get(key);
|
|
148
153
|
}
|
|
149
154
|
const promise = fn(...args);
|
|
150
|
-
|
|
155
|
+
fnCache.set(key, promise);
|
|
151
156
|
try {
|
|
152
157
|
const data = await promise;
|
|
153
158
|
return data;
|
|
154
159
|
} catch (error) {
|
|
155
|
-
|
|
160
|
+
fnCache.delete(key);
|
|
156
161
|
throw error;
|
|
157
162
|
}
|
|
158
163
|
}
|
|
@@ -130,7 +130,7 @@ function cache(fn, options) {
|
|
|
130
130
|
return addTagFnRelation(t, fn);
|
|
131
131
|
});
|
|
132
132
|
return /* @__PURE__ */ _async_to_generator(function() {
|
|
133
|
-
var _len, args, _key, _storage_useContext, storage, request, requestCache, key, promise, data, error, tagCache, key1, cached, now, age, data1;
|
|
133
|
+
var _len, args, _key, _storage_useContext, storage, request, requestCache, fnCache, key, promise, data, error, tagCache, key1, cached, now, age, data1;
|
|
134
134
|
var _arguments = arguments;
|
|
135
135
|
return _ts_generator(this, function(_state) {
|
|
136
136
|
switch (_state.label) {
|
|
@@ -155,15 +155,20 @@ function cache(fn, options) {
|
|
|
155
155
|
requestCache = /* @__PURE__ */ new Map();
|
|
156
156
|
requestCacheMap.set(request, requestCache);
|
|
157
157
|
}
|
|
158
|
+
fnCache = requestCache.get(fn);
|
|
159
|
+
if (!fnCache) {
|
|
160
|
+
fnCache = /* @__PURE__ */ new Map();
|
|
161
|
+
requestCache.set(fn, fnCache);
|
|
162
|
+
}
|
|
158
163
|
key = generateKey(args);
|
|
159
|
-
if (
|
|
164
|
+
if (fnCache.has(key)) {
|
|
160
165
|
return [
|
|
161
166
|
2,
|
|
162
|
-
|
|
167
|
+
fnCache.get(key)
|
|
163
168
|
];
|
|
164
169
|
}
|
|
165
170
|
promise = fn.apply(void 0, _to_consumable_array(args));
|
|
166
|
-
|
|
171
|
+
fnCache.set(key, promise);
|
|
167
172
|
_state.label = 1;
|
|
168
173
|
case 1:
|
|
169
174
|
_state.trys.push([
|
|
@@ -184,7 +189,7 @@ function cache(fn, options) {
|
|
|
184
189
|
];
|
|
185
190
|
case 3:
|
|
186
191
|
error = _state.sent();
|
|
187
|
-
|
|
192
|
+
fnCache.delete(key);
|
|
188
193
|
throw error;
|
|
189
194
|
case 4:
|
|
190
195
|
return [
|
|
@@ -112,17 +112,22 @@ function cache(fn, options) {
|
|
|
112
112
|
requestCache = /* @__PURE__ */ new Map();
|
|
113
113
|
requestCacheMap.set(request, requestCache);
|
|
114
114
|
}
|
|
115
|
+
let fnCache = requestCache.get(fn);
|
|
116
|
+
if (!fnCache) {
|
|
117
|
+
fnCache = /* @__PURE__ */ new Map();
|
|
118
|
+
requestCache.set(fn, fnCache);
|
|
119
|
+
}
|
|
115
120
|
const key = generateKey(args);
|
|
116
|
-
if (
|
|
117
|
-
return
|
|
121
|
+
if (fnCache.has(key)) {
|
|
122
|
+
return fnCache.get(key);
|
|
118
123
|
}
|
|
119
124
|
const promise = fn(...args);
|
|
120
|
-
|
|
125
|
+
fnCache.set(key, promise);
|
|
121
126
|
try {
|
|
122
127
|
const data = await promise;
|
|
123
128
|
return data;
|
|
124
129
|
} catch (error) {
|
|
125
|
-
|
|
130
|
+
fnCache.delete(key);
|
|
126
131
|
throw error;
|
|
127
132
|
}
|
|
128
133
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import type { Buffer } from 'buffer';
|
|
4
1
|
import Fs from '@modern-js/utils/fs-extra';
|
|
5
2
|
import type { Storage } from './storer/storage';
|
|
6
3
|
export declare class FileReader {
|
|
@@ -11,7 +8,7 @@ export declare class FileReader {
|
|
|
11
8
|
readFile(path: string, encoding?: 'buffer'): Promise<Buffer | null>;
|
|
12
9
|
readFileFromSystem(path: string, encoding?: 'utf-8'): Promise<string | null>;
|
|
13
10
|
readFileFromSystem(path: string, encoding?: 'buffer'): Promise<Buffer | null>;
|
|
14
|
-
_readFileFactory(fs: typeof Fs): (path: string, encoding?:
|
|
11
|
+
_readFileFactory(fs: typeof Fs): (path: string, encoding?: "utf-8" | "buffer") => Promise<string | Buffer | null>;
|
|
15
12
|
/**
|
|
16
13
|
* Clear the fileCache entriely.
|
|
17
14
|
*/
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { IncomingHttpHeaders } from 'http';
|
|
3
2
|
import type { Monitors } from '@modern-js/types';
|
|
4
3
|
declare const storage: {
|
|
5
4
|
run: <O>(context: {
|
|
6
|
-
monitors?: Monitors
|
|
7
|
-
headers?: IncomingHttpHeaders
|
|
8
|
-
request?: Request
|
|
5
|
+
monitors?: Monitors;
|
|
6
|
+
headers?: IncomingHttpHeaders;
|
|
7
|
+
request?: Request;
|
|
9
8
|
responseProxy?: {
|
|
10
9
|
headers: Record<string, string>;
|
|
11
10
|
status: number;
|
|
12
|
-
}
|
|
11
|
+
};
|
|
13
12
|
}, cb: () => O | Promise<O>) => Promise<O>;
|
|
14
13
|
useContext: () => {
|
|
15
|
-
monitors?: Monitors
|
|
16
|
-
headers?: IncomingHttpHeaders
|
|
17
|
-
request?: Request
|
|
14
|
+
monitors?: Monitors;
|
|
15
|
+
headers?: IncomingHttpHeaders;
|
|
16
|
+
request?: Request;
|
|
18
17
|
responseProxy?: {
|
|
19
18
|
headers: Record<string, string>;
|
|
20
19
|
status: number;
|
|
21
|
-
}
|
|
20
|
+
};
|
|
22
21
|
};
|
|
23
22
|
};
|
|
24
23
|
type Storage = typeof storage;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.66.0",
|
|
19
19
|
"_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
|
|
20
20
|
"exports": {
|
|
21
21
|
"./router": {
|
|
@@ -91,8 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"registry": "https://registry.npmjs.org/",
|
|
94
|
-
"access": "public"
|
|
95
|
-
"provenance": true
|
|
94
|
+
"access": "public"
|
|
96
95
|
},
|
|
97
96
|
"typesVersions": {
|
|
98
97
|
"*": {
|
|
@@ -146,8 +145,8 @@
|
|
|
146
145
|
"lru-cache": "^10.4.3",
|
|
147
146
|
"react-router-dom": "6.27.0",
|
|
148
147
|
"serialize-javascript": "^6.0.0",
|
|
149
|
-
"@modern-js/
|
|
150
|
-
"@modern-js/
|
|
148
|
+
"@modern-js/utils": "2.66.0",
|
|
149
|
+
"@modern-js/types": "2.66.0"
|
|
151
150
|
},
|
|
152
151
|
"peerDependencies": {
|
|
153
152
|
"react": ">=17.0.0",
|
|
@@ -169,8 +168,8 @@
|
|
|
169
168
|
"react": "^18.3.1",
|
|
170
169
|
"react-dom": "^18.3.1",
|
|
171
170
|
"typescript": "^5",
|
|
172
|
-
"@scripts/build": "2.
|
|
173
|
-
"@scripts/jest-config": "2.
|
|
171
|
+
"@scripts/build": "2.66.0",
|
|
172
|
+
"@scripts/jest-config": "2.66.0"
|
|
174
173
|
},
|
|
175
174
|
"sideEffects": false,
|
|
176
175
|
"scripts": {
|