@nxtedition/lib 28.0.16 → 28.0.18
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/cache.js +10 -8
- package/package.json +2 -2
- package/shared.js +1 -4
- package/slice.js +4 -56
package/cache.js
CHANGED
|
@@ -284,18 +284,20 @@ export class AsyncCache {
|
|
|
284
284
|
throw new TypeError('key must be a non-empty string')
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (!Number.isFinite(ttl)) {
|
|
291
|
-
throw new TypeError('ttl must be a finite number')
|
|
287
|
+
const ttlValue = Math.min(365000000e3, this.#ttl(value, key) ?? 0)
|
|
288
|
+
if (!Number.isFinite(ttlValue) || ttlValue < 0) {
|
|
289
|
+
throw new TypeError('ttl must be nully or a positive integer')
|
|
292
290
|
}
|
|
293
291
|
|
|
294
|
-
const
|
|
295
|
-
if (!Number.isFinite(
|
|
296
|
-
throw new TypeError('stale must be a
|
|
292
|
+
const staleValue = Math.min(365000000e3, this.#stale(value, key) ?? 0)
|
|
293
|
+
if (!Number.isFinite(staleValue) || staleValue < 0) {
|
|
294
|
+
throw new TypeError('stale must be nully or a positive integer')
|
|
297
295
|
}
|
|
298
296
|
|
|
297
|
+
const now = fastNow()
|
|
298
|
+
const ttl = now + ttlValue
|
|
299
|
+
const stale = ttl + staleValue
|
|
300
|
+
|
|
299
301
|
if (stale <= now) {
|
|
300
302
|
return
|
|
301
303
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "28.0.
|
|
3
|
+
"version": "28.0.18",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"pino": ">=7.0.0",
|
|
93
93
|
"rxjs": "^7.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "0e9eba55a86700d53a902b3478366d6cb9791634"
|
|
96
96
|
}
|
package/shared.js
CHANGED
|
@@ -94,9 +94,6 @@ export function reader({ sharedState, sharedBuffer }) {
|
|
|
94
94
|
// wrapped around to the beginning of the buffer.
|
|
95
95
|
if (dataLen === -1) {
|
|
96
96
|
readPos = 0
|
|
97
|
-
// After wrapping, we must re-check against the writer's position.
|
|
98
|
-
// It's possible the writer is now at a position > 0.
|
|
99
|
-
writePos = Atomics.load(state, WRITE_INDEX) | 0
|
|
100
97
|
} else {
|
|
101
98
|
if (dataLen < 0) {
|
|
102
99
|
throw new Error('Invalid data length')
|
|
@@ -122,7 +119,7 @@ export function reader({ sharedState, sharedBuffer }) {
|
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
// IMPORTANT: The reader only updates its shared `readPos` after a batch
|
|
125
|
-
// is processed. This significantly reduces atomic
|
|
122
|
+
// is processed. This significantly reduces atomic operation overhead.
|
|
126
123
|
if (bytes > 0) {
|
|
127
124
|
Atomics.store(state, READ_INDEX, readPos)
|
|
128
125
|
}
|
package/slice.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import util from 'node:util'
|
|
2
2
|
|
|
3
3
|
const EMPTY_BUF = Buffer.alloc(0)
|
|
4
|
-
const POOL = []
|
|
5
4
|
|
|
6
5
|
export class Slice {
|
|
7
6
|
buffer
|
|
@@ -24,6 +23,10 @@ export class Slice {
|
|
|
24
23
|
byteLength = buffer.byteLength,
|
|
25
24
|
maxByteLength = byteLength,
|
|
26
25
|
) {
|
|
26
|
+
if (!(buffer instanceof Buffer)) {
|
|
27
|
+
throw new TypeError('buffer must be a Buffer')
|
|
28
|
+
}
|
|
29
|
+
|
|
27
30
|
if (byteOffset < 0 || !Number.isInteger(byteOffset)) {
|
|
28
31
|
throw new RangeError(`Invalid byteOffset: ${byteOffset}`)
|
|
29
32
|
}
|
|
@@ -46,61 +49,6 @@ export class Slice {
|
|
|
46
49
|
this.maxByteLength = maxByteLength
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
static create(buffer, byteOffset, byteLength, maxByteLength) {
|
|
50
|
-
if (buffer === undefined) {
|
|
51
|
-
buffer = Slice.EMPTY_BUF
|
|
52
|
-
}
|
|
53
|
-
if (byteOffset === undefined) {
|
|
54
|
-
byteOffset = 0
|
|
55
|
-
}
|
|
56
|
-
if (byteLength === undefined) {
|
|
57
|
-
byteLength = buffer.byteLength
|
|
58
|
-
}
|
|
59
|
-
if (maxByteLength === undefined) {
|
|
60
|
-
maxByteLength = byteLength
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (byteOffset < 0) {
|
|
64
|
-
throw new RangeError('byteOffset must be non-negative')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (byteLength < 0) {
|
|
68
|
-
throw new RangeError('byteLength must be non-negative')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (byteLength > maxByteLength) {
|
|
72
|
-
throw new RangeError('byteLength cannot be greater than maxByteLength')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (byteOffset + maxByteLength > buffer.byteLength) {
|
|
76
|
-
throw new RangeError('Slice exceeds buffer length')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const slice = POOL.pop()
|
|
80
|
-
|
|
81
|
-
if (slice) {
|
|
82
|
-
slice.buffer = buffer
|
|
83
|
-
slice.byteOffset = byteOffset
|
|
84
|
-
slice.byteLength = byteLength
|
|
85
|
-
slice.maxByteLength = maxByteLength
|
|
86
|
-
return slice
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return new Slice(buffer, byteOffset, byteLength, maxByteLength)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static free(slice) {
|
|
93
|
-
if (slice == null) {
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
slice.reset()
|
|
98
|
-
|
|
99
|
-
if (POOL.length < 16 * 1024) {
|
|
100
|
-
POOL.push(slice)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
52
|
reset() {
|
|
105
53
|
this.buffer = Slice.EMPTY_BUF
|
|
106
54
|
this.byteOffset = 0
|