@modern-js/runtime-utils 3.10.1 → 3.10.2
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/node/storer/container.js +11 -3
- package/dist/cjs/server/nestedRoutes.js +3 -12
- package/dist/esm/node/storer/container.mjs +7 -2
- package/dist/esm/server/nestedRoutes.mjs +3 -12
- package/dist/esm-node/node/storer/container.mjs +7 -2
- package/dist/esm-node/server/nestedRoutes.mjs +3 -12
- package/dist/types/node/storer/container.d.ts +10 -1
- package/package.json +5 -5
|
@@ -28,9 +28,15 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
MemoryContainer: ()=>MemoryContainer
|
|
31
|
+
MemoryContainer: ()=>MemoryContainer,
|
|
32
|
+
calculateSize: ()=>calculateSize
|
|
32
33
|
});
|
|
33
34
|
const external_lru_cache_namespaceObject = require("lru-cache");
|
|
35
|
+
function calculateSize(value) {
|
|
36
|
+
let size;
|
|
37
|
+
size = 'string' == typeof value ? value.length : ArrayBuffer.isView(value) || value instanceof ArrayBuffer ? value.byteLength : JSON.stringify(value)?.length;
|
|
38
|
+
return Math.max(size || 0, 1);
|
|
39
|
+
}
|
|
34
40
|
class MemoryContainer {
|
|
35
41
|
async get(key) {
|
|
36
42
|
return this.cache.get(key);
|
|
@@ -56,7 +62,7 @@ class MemoryContainer {
|
|
|
56
62
|
this.cache = new external_lru_cache_namespaceObject.LRUCache({
|
|
57
63
|
maxSize: (max || 256) * MemoryContainer.MB,
|
|
58
64
|
ttl: maxAge || MemoryContainer.hour,
|
|
59
|
-
sizeCalculation:
|
|
65
|
+
sizeCalculation: calculateSize
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
}
|
|
@@ -68,8 +74,10 @@ MemoryContainer.second = 1000 * MemoryContainer.ms;
|
|
|
68
74
|
MemoryContainer.minute = 60 * MemoryContainer.second;
|
|
69
75
|
MemoryContainer.hour = 60 * MemoryContainer.minute;
|
|
70
76
|
exports.MemoryContainer = __webpack_exports__.MemoryContainer;
|
|
77
|
+
exports.calculateSize = __webpack_exports__.calculateSize;
|
|
71
78
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
72
|
-
"MemoryContainer"
|
|
79
|
+
"MemoryContainer",
|
|
80
|
+
"calculateSize"
|
|
73
81
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
74
82
|
Object.defineProperty(exports, '__esModule', {
|
|
75
83
|
value: true
|
|
@@ -27,19 +27,10 @@ var __webpack_require__ = {};
|
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
function sortByUrlPath(entries) {
|
|
31
|
-
entries.sort(function(a, b) {
|
|
32
|
-
const length1 = a.urlPath.length;
|
|
33
|
-
const length2 = b.urlPath.length;
|
|
34
|
-
if (length1 < length2) return 1;
|
|
35
|
-
if (length1 > length2) return -1;
|
|
36
|
-
return 0;
|
|
37
|
-
});
|
|
38
|
-
return entries;
|
|
39
|
-
}
|
|
40
30
|
const matchEntry = (pathname, entries)=>{
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
let matched;
|
|
32
|
+
for (const entry of entries)if (pathname.startsWith(entry.urlPath) && (!matched || entry.urlPath.length > matched.urlPath.length)) matched = entry;
|
|
33
|
+
return matched;
|
|
43
34
|
};
|
|
44
35
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
45
36
|
matchEntry: matchEntry
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { LRUCache } from "lru-cache";
|
|
2
|
+
function calculateSize(value) {
|
|
3
|
+
let size;
|
|
4
|
+
size = 'string' == typeof value ? value.length : ArrayBuffer.isView(value) || value instanceof ArrayBuffer ? value.byteLength : JSON.stringify(value)?.length;
|
|
5
|
+
return Math.max(size || 0, 1);
|
|
6
|
+
}
|
|
2
7
|
class MemoryContainer {
|
|
3
8
|
async get(key) {
|
|
4
9
|
return this.cache.get(key);
|
|
@@ -24,7 +29,7 @@ class MemoryContainer {
|
|
|
24
29
|
this.cache = new LRUCache({
|
|
25
30
|
maxSize: (max || 256) * MemoryContainer.MB,
|
|
26
31
|
ttl: maxAge || MemoryContainer.hour,
|
|
27
|
-
sizeCalculation:
|
|
32
|
+
sizeCalculation: calculateSize
|
|
28
33
|
});
|
|
29
34
|
}
|
|
30
35
|
}
|
|
@@ -35,4 +40,4 @@ MemoryContainer.ms = 1;
|
|
|
35
40
|
MemoryContainer.second = 1000 * MemoryContainer.ms;
|
|
36
41
|
MemoryContainer.minute = 60 * MemoryContainer.second;
|
|
37
42
|
MemoryContainer.hour = 60 * MemoryContainer.minute;
|
|
38
|
-
export { MemoryContainer };
|
|
43
|
+
export { MemoryContainer, calculateSize };
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
function sortByUrlPath(entries) {
|
|
2
|
-
entries.sort(function(a, b) {
|
|
3
|
-
const length1 = a.urlPath.length;
|
|
4
|
-
const length2 = b.urlPath.length;
|
|
5
|
-
if (length1 < length2) return 1;
|
|
6
|
-
if (length1 > length2) return -1;
|
|
7
|
-
return 0;
|
|
8
|
-
});
|
|
9
|
-
return entries;
|
|
10
|
-
}
|
|
11
1
|
const matchEntry = (pathname, entries)=>{
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
let matched;
|
|
3
|
+
for (const entry of entries)if (pathname.startsWith(entry.urlPath) && (!matched || entry.urlPath.length > matched.urlPath.length)) matched = entry;
|
|
4
|
+
return matched;
|
|
14
5
|
};
|
|
15
6
|
export { matchEntry };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { LRUCache } from "lru-cache";
|
|
3
|
+
function calculateSize(value) {
|
|
4
|
+
let size;
|
|
5
|
+
size = 'string' == typeof value ? value.length : ArrayBuffer.isView(value) || value instanceof ArrayBuffer ? value.byteLength : JSON.stringify(value)?.length;
|
|
6
|
+
return Math.max(size || 0, 1);
|
|
7
|
+
}
|
|
3
8
|
class MemoryContainer {
|
|
4
9
|
async get(key) {
|
|
5
10
|
return this.cache.get(key);
|
|
@@ -25,7 +30,7 @@ class MemoryContainer {
|
|
|
25
30
|
this.cache = new LRUCache({
|
|
26
31
|
maxSize: (max || 256) * MemoryContainer.MB,
|
|
27
32
|
ttl: maxAge || MemoryContainer.hour,
|
|
28
|
-
sizeCalculation:
|
|
33
|
+
sizeCalculation: calculateSize
|
|
29
34
|
});
|
|
30
35
|
}
|
|
31
36
|
}
|
|
@@ -36,4 +41,4 @@ MemoryContainer.ms = 1;
|
|
|
36
41
|
MemoryContainer.second = 1000 * MemoryContainer.ms;
|
|
37
42
|
MemoryContainer.minute = 60 * MemoryContainer.second;
|
|
38
43
|
MemoryContainer.hour = 60 * MemoryContainer.minute;
|
|
39
|
-
export { MemoryContainer };
|
|
44
|
+
export { MemoryContainer, calculateSize };
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
function sortByUrlPath(entries) {
|
|
3
|
-
entries.sort(function(a, b) {
|
|
4
|
-
const length1 = a.urlPath.length;
|
|
5
|
-
const length2 = b.urlPath.length;
|
|
6
|
-
if (length1 < length2) return 1;
|
|
7
|
-
if (length1 > length2) return -1;
|
|
8
|
-
return 0;
|
|
9
|
-
});
|
|
10
|
-
return entries;
|
|
11
|
-
}
|
|
12
2
|
const matchEntry = (pathname, entries)=>{
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
let matched;
|
|
4
|
+
for (const entry of entries)if (pathname.startsWith(entry.urlPath) && (!matched || entry.urlPath.length > matched.urlPath.length)) matched = entry;
|
|
5
|
+
return matched;
|
|
15
6
|
};
|
|
16
7
|
export { matchEntry };
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import type { Container } from '@modern-js/types';
|
|
2
2
|
interface MemoryContainerOptions {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The maximum size of the cache, unit(MB). The default of value is 256.
|
|
5
|
+
* Binary values are counted in bytes, strings in UTF-16 code units and other
|
|
6
|
+
* values by the length of their JSON.
|
|
7
|
+
*/
|
|
4
8
|
max?: number;
|
|
5
9
|
maxAge?: number;
|
|
6
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Estimate the size of a cached value without serializing binary data or strings.
|
|
13
|
+
* lru-cache requires a positive integer, so the minimum size is 1.
|
|
14
|
+
*/
|
|
15
|
+
export declare function calculateSize(value: unknown): number;
|
|
7
16
|
/**
|
|
8
17
|
* MemoryContainer, it use lur-cache as cahe layer.
|
|
9
18
|
* It has a Time to Live, by default as 1 hour.
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.10.
|
|
18
|
+
"version": "3.10.2",
|
|
19
19
|
"_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
|
|
20
20
|
"exports": {
|
|
21
21
|
"./router": {
|
|
@@ -159,8 +159,8 @@
|
|
|
159
159
|
"lru-cache": "^10.4.3",
|
|
160
160
|
"react-router": "7.18.4",
|
|
161
161
|
"serialize-javascript": "^7.1.2",
|
|
162
|
-
"@modern-js/types": "3.10.
|
|
163
|
-
"@modern-js/utils": "3.10.
|
|
162
|
+
"@modern-js/types": "3.10.2",
|
|
163
|
+
"@modern-js/utils": "3.10.2"
|
|
164
164
|
},
|
|
165
165
|
"peerDependencies": {
|
|
166
166
|
"react": ">=18.3.1",
|
|
@@ -182,8 +182,8 @@
|
|
|
182
182
|
"react": "^19.3.1",
|
|
183
183
|
"react-dom": "^19.3.1",
|
|
184
184
|
"typescript": "^5",
|
|
185
|
-
"@modern-js/rslib": "
|
|
186
|
-
"@scripts/rstest-config": "2.66.
|
|
185
|
+
"@modern-js/rslib": "3.10.2",
|
|
186
|
+
"@scripts/rstest-config": "2.66.1"
|
|
187
187
|
},
|
|
188
188
|
"sideEffects": false,
|
|
189
189
|
"scripts": {
|