govuk_publishing_components 17.20.0 → 17.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +8 -0
- data/app/views/govuk_publishing_components/components/_subscription-links.html.erb +15 -5
- data/app/views/govuk_publishing_components/components/docs/subscription-links.yml +13 -2
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/accessible-autocomplete/package.json +1 -1
- data/node_modules/graceful-fs/package.json +13 -13
- data/node_modules/graceful-fs/polyfills.js +17 -11
- data/node_modules/hosted-git-info/CHANGELOG.md +40 -0
- data/node_modules/hosted-git-info/git-host-info.js +5 -3
- data/node_modules/hosted-git-info/git-host.js +35 -10
- data/node_modules/hosted-git-info/index.js +17 -15
- data/node_modules/hosted-git-info/package.json +40 -30
- data/node_modules/lru-cache/LICENSE +15 -0
- data/node_modules/lru-cache/README.md +166 -0
- data/node_modules/lru-cache/index.js +334 -0
- data/node_modules/lru-cache/package.json +108 -0
- data/node_modules/pkg-conf/package.json +1 -1
- data/node_modules/preact/debug.js +630 -2
- data/node_modules/preact/debug.js.map +1 -1
- data/node_modules/preact/debug/dist/debug.js +2 -0
- data/node_modules/preact/debug/dist/debug.js.map +1 -0
- data/node_modules/preact/debug/dist/debug.mjs +681 -0
- data/node_modules/preact/debug/dist/debug.mjs.map +1 -0
- data/node_modules/preact/debug/dist/debug.module.js +2 -0
- data/node_modules/preact/debug/dist/debug.module.js.map +1 -0
- data/node_modules/preact/debug/dist/debug.umd.js +2 -0
- data/node_modules/preact/debug/dist/debug.umd.js.map +1 -0
- data/node_modules/preact/debug/index.js +2 -1
- data/node_modules/preact/dist/preact.d.ts +808 -3
- data/node_modules/preact/dist/preact.dev.js +727 -727
- data/node_modules/preact/dist/preact.dev.js.map +1 -1
- data/node_modules/preact/dist/preact.js +1 -1
- data/node_modules/preact/dist/preact.js.flow +3 -3
- data/node_modules/preact/dist/preact.js.map +1 -1
- data/node_modules/preact/dist/preact.min.js +1 -1
- data/node_modules/preact/dist/preact.min.js.map +1 -1
- data/node_modules/preact/dist/preact.mjs +724 -724
- data/node_modules/preact/dist/preact.mjs.map +1 -1
- data/node_modules/preact/dist/preact.umd.js +751 -0
- data/node_modules/preact/dist/preact.umd.js.map +1 -0
- data/node_modules/preact/package.json +43 -26
- data/node_modules/preact/src/preact.d.ts +808 -3
- data/node_modules/preact/src/preact.js.flow +3 -3
- data/node_modules/preact/src/util.js +1 -1
- data/node_modules/yallist/LICENSE +15 -0
- data/node_modules/yallist/README.md +204 -0
- data/node_modules/yallist/iterator.js +8 -0
- data/node_modules/yallist/package.json +97 -0
- data/node_modules/yallist/yallist.js +376 -0
- metadata +21 -2
@@ -14,19 +14,20 @@
|
|
14
14
|
]
|
15
15
|
],
|
16
16
|
"_from": "hosted-git-info@>=2.1.4 <3.0.0",
|
17
|
-
"
|
17
|
+
"_hasShrinkwrap": false,
|
18
|
+
"_id": "hosted-git-info@2.8.2",
|
18
19
|
"_inCache": true,
|
19
20
|
"_location": "/hosted-git-info",
|
20
|
-
"_nodeVersion": "
|
21
|
+
"_nodeVersion": "12.6.0",
|
21
22
|
"_npmOperationalInternal": {
|
22
23
|
"host": "s3://npm-registry-packages",
|
23
|
-
"tmp": "tmp/hosted-git-info_2.
|
24
|
+
"tmp": "tmp/hosted-git-info_2.8.2_1564987919499_0.01793192251303788"
|
24
25
|
},
|
25
26
|
"_npmUser": {
|
26
|
-
"name": "
|
27
|
-
"email": "
|
27
|
+
"name": "isaacs",
|
28
|
+
"email": "i@izs.me"
|
28
29
|
},
|
29
|
-
"_npmVersion": "6.
|
30
|
+
"_npmVersion": "6.10.2",
|
30
31
|
"_phantomChildren": {},
|
31
32
|
"_requested": {
|
32
33
|
"raw": "hosted-git-info@^2.1.4",
|
@@ -40,8 +41,8 @@
|
|
40
41
|
"_requiredBy": [
|
41
42
|
"/normalize-package-data"
|
42
43
|
],
|
43
|
-
"_resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.
|
44
|
-
"_shasum": "
|
44
|
+
"_resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.2.tgz",
|
45
|
+
"_shasum": "a35c3f355ac1249f1093c0c2a542ace8818c171a",
|
45
46
|
"_shrinkwrap": null,
|
46
47
|
"_spec": "hosted-git-info@^2.1.4",
|
47
48
|
"_where": "/var/lib/jenkins/workspace/ublishing_components_master-N4FWJIUY4CIFHKGZOAAEVVXODRY3YBORQOPIBBXWX72VUPSGJRRQ/node_modules/normalize-package-data",
|
@@ -53,28 +54,25 @@
|
|
53
54
|
"bugs": {
|
54
55
|
"url": "https://github.com/npm/hosted-git-info/issues"
|
55
56
|
},
|
56
|
-
"dependencies": {
|
57
|
+
"dependencies": {
|
58
|
+
"lru-cache": "^5.1.1"
|
59
|
+
},
|
57
60
|
"description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab",
|
58
61
|
"devDependencies": {
|
59
62
|
"standard": "^11.0.1",
|
60
|
-
"standard-version": "^4.
|
61
|
-
"tap": "^12.0
|
63
|
+
"standard-version": "^4.4.0",
|
64
|
+
"tap": "^12.7.0"
|
62
65
|
},
|
63
66
|
"directories": {},
|
64
67
|
"dist": {
|
65
|
-
"integrity": "sha512-
|
66
|
-
"shasum": "
|
67
|
-
"tarball": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.
|
68
|
+
"integrity": "sha512-CyjlXII6LMsPMyUzxpTt8fzh5QwzGqPmQXgY/Jyf4Zfp27t/FvfhwoE/8laaMUcMy816CkWF20I7NeQhwwY88w==",
|
69
|
+
"shasum": "a35c3f355ac1249f1093c0c2a542ace8818c171a",
|
70
|
+
"tarball": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.2.tgz",
|
68
71
|
"fileCount": 7,
|
69
|
-
"unpackedSize":
|
70
|
-
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\
|
72
|
+
"unpackedSize": 22546,
|
73
|
+
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdR9IQCRA9TVsSAnZWagAArRgP/R8XIVPByuZw2w2M3HBm\nhU6KWHOnaK6pNmCsImzINiXY3F6zXgnUq6N4iV/O45A17Fz1NJnWcWw3mH5m\nNuULyQ/QSZmyq1/kFkPT4mhklMJkxnPOZnuAWN8o+BCKE83c8QqaJ95wjnaa\nBmradUNVEAzkNAXCxNAKSOoToj7m7vg+GdD2FLAORqfq9FqGRwxjQtZhkNyc\nlUG/zwJpgNjJbXRS54uWk9f5mXGaTPDiWzKH6pVw8+PSXDl0C/tSa30I5GUy\nZMaSWzL4GD8Y4JOloAe36P7G5Tdz5xyl7RNu9IFOAG2R7bgpxQeMiE0UOxKQ\ncowo7T1K9xPOKz5HwXygnqG2pLfYv9WTwvRRbz8OI1OWTGhEzirfm6uYGgNk\nBxi3/l+C0QQNPmFQNVWJcS3zMTVYFYKAXJGL8b/1Il2v5qnQ0VG7NusxHl9w\nVe+hg3ss0jUuwo2KQ7ImA8LkE4Y0IuOZy9uXnzIPMb8XOsKRNHWY4h0He1Gq\n95lozXzI37hntf7DKdvvM3/DPtIoEYYEeAvQz9g9G4LODieEJeQti4Yqq/rl\nthb/wpLJiLbj089gv2Wh1ax8rhup8zOyddb1twM7WArkEjx+GbCGeajHYav2\n+Zc5Ba92wrF/pk+IntGk5Sd+ER1P8qEixXZhyg4g1ZQWZBqdt6gb8J59fG94\nOlGC\r\n=CzEU\r\n-----END PGP SIGNATURE-----\r\n"
|
71
74
|
},
|
72
|
-
"
|
73
|
-
"index.js",
|
74
|
-
"git-host.js",
|
75
|
-
"git-host-info.js"
|
76
|
-
],
|
77
|
-
"gitHead": "ab35a9024cedf355a6de975e440414061fbb3a27",
|
75
|
+
"gitHead": "96a49ea17d4a21f0d5a507feea09c33dc7080c9b",
|
78
76
|
"homepage": "https://github.com/npm/hosted-git-info",
|
79
77
|
"keywords": [
|
80
78
|
"git",
|
@@ -86,16 +84,28 @@
|
|
86
84
|
"main": "index.js",
|
87
85
|
"maintainers": [
|
88
86
|
{
|
89
|
-
"name": "
|
90
|
-
"email": "
|
87
|
+
"name": "adam_baldwin",
|
88
|
+
"email": "evilpacket@gmail.com"
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"name": "ahmadnassri",
|
92
|
+
"email": "ahmad@ahmadnassri.com"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"name": "annekimsey",
|
96
|
+
"email": "anne@npmjs.com"
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "claudiahdz",
|
100
|
+
"email": "cghr1990@gmail.com"
|
91
101
|
},
|
92
102
|
{
|
93
|
-
"name": "
|
94
|
-
"email": "
|
103
|
+
"name": "darcyclarke",
|
104
|
+
"email": "darcy@darcyclarke.me"
|
95
105
|
},
|
96
106
|
{
|
97
|
-
"name": "
|
98
|
-
"email": "
|
107
|
+
"name": "isaacs",
|
108
|
+
"email": "i@izs.me"
|
99
109
|
}
|
100
110
|
],
|
101
111
|
"name": "hosted-git-info",
|
@@ -110,7 +120,7 @@
|
|
110
120
|
"prerelease": "npm t",
|
111
121
|
"pretest": "standard",
|
112
122
|
"release": "standard-version -s",
|
113
|
-
"test": "tap -J --
|
123
|
+
"test": "tap -J --100 --no-esm test/*.js"
|
114
124
|
},
|
115
|
-
"version": "2.
|
125
|
+
"version": "2.8.2"
|
116
126
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
The ISC License
|
2
|
+
|
3
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
15
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# lru cache
|
2
|
+
|
3
|
+
A cache object that deletes the least-recently-used items.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/isaacs/node-lru-cache.svg?branch=master)](https://travis-ci.org/isaacs/node-lru-cache) [![Coverage Status](https://coveralls.io/repos/isaacs/node-lru-cache/badge.svg?service=github)](https://coveralls.io/github/isaacs/node-lru-cache)
|
6
|
+
|
7
|
+
## Installation:
|
8
|
+
|
9
|
+
```javascript
|
10
|
+
npm install lru-cache --save
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage:
|
14
|
+
|
15
|
+
```javascript
|
16
|
+
var LRU = require("lru-cache")
|
17
|
+
, options = { max: 500
|
18
|
+
, length: function (n, key) { return n * 2 + key.length }
|
19
|
+
, dispose: function (key, n) { n.close() }
|
20
|
+
, maxAge: 1000 * 60 * 60 }
|
21
|
+
, cache = new LRU(options)
|
22
|
+
, otherCache = new LRU(50) // sets just the max size
|
23
|
+
|
24
|
+
cache.set("key", "value")
|
25
|
+
cache.get("key") // "value"
|
26
|
+
|
27
|
+
// non-string keys ARE fully supported
|
28
|
+
// but note that it must be THE SAME object, not
|
29
|
+
// just a JSON-equivalent object.
|
30
|
+
var someObject = { a: 1 }
|
31
|
+
cache.set(someObject, 'a value')
|
32
|
+
// Object keys are not toString()-ed
|
33
|
+
cache.set('[object Object]', 'a different value')
|
34
|
+
assert.equal(cache.get(someObject), 'a value')
|
35
|
+
// A similar object with same keys/values won't work,
|
36
|
+
// because it's a different object identity
|
37
|
+
assert.equal(cache.get({ a: 1 }), undefined)
|
38
|
+
|
39
|
+
cache.reset() // empty the cache
|
40
|
+
```
|
41
|
+
|
42
|
+
If you put more stuff in it, then items will fall out.
|
43
|
+
|
44
|
+
If you try to put an oversized thing in it, then it'll fall out right
|
45
|
+
away.
|
46
|
+
|
47
|
+
## Options
|
48
|
+
|
49
|
+
* `max` The maximum size of the cache, checked by applying the length
|
50
|
+
function to all values in the cache. Not setting this is kind of
|
51
|
+
silly, since that's the whole purpose of this lib, but it defaults
|
52
|
+
to `Infinity`. Setting it to a non-number or negative number will
|
53
|
+
throw a `TypeError`. Setting it to 0 makes it be `Infinity`.
|
54
|
+
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
|
55
|
+
as they age, but if you try to get an item that is too old, it'll
|
56
|
+
drop it and return undefined instead of giving it to you.
|
57
|
+
Setting this to a negative value will make everything seem old!
|
58
|
+
Setting it to a non-number will throw a `TypeError`.
|
59
|
+
* `length` Function that is used to calculate the length of stored
|
60
|
+
items. If you're storing strings or buffers, then you probably want
|
61
|
+
to do something like `function(n, key){return n.length}`. The default is
|
62
|
+
`function(){return 1}`, which is fine if you want to store `max`
|
63
|
+
like-sized things. The item is passed as the first argument, and
|
64
|
+
the key is passed as the second argumnet.
|
65
|
+
* `dispose` Function that is called on items when they are dropped
|
66
|
+
from the cache. This can be handy if you want to close file
|
67
|
+
descriptors or do other cleanup tasks when items are no longer
|
68
|
+
accessible. Called with `key, value`. It's called *before*
|
69
|
+
actually removing the item from the internal cache, so if you want
|
70
|
+
to immediately put it back in, you'll have to do that in a
|
71
|
+
`nextTick` or `setTimeout` callback or it won't do anything.
|
72
|
+
* `stale` By default, if you set a `maxAge`, it'll only actually pull
|
73
|
+
stale items out of the cache when you `get(key)`. (That is, it's
|
74
|
+
not pre-emptively doing a `setTimeout` or anything.) If you set
|
75
|
+
`stale:true`, it'll return the stale value before deleting it. If
|
76
|
+
you don't set this, then it'll return `undefined` when you try to
|
77
|
+
get a stale entry, as if it had already been deleted.
|
78
|
+
* `noDisposeOnSet` By default, if you set a `dispose()` method, then
|
79
|
+
it'll be called whenever a `set()` operation overwrites an existing
|
80
|
+
key. If you set this option, `dispose()` will only be called when a
|
81
|
+
key falls out of the cache, not when it is overwritten.
|
82
|
+
* `updateAgeOnGet` When using time-expiring entries with `maxAge`,
|
83
|
+
setting this to `true` will make each item's effective time update
|
84
|
+
to the current time whenever it is retrieved from cache, causing it
|
85
|
+
to not expire. (It can still fall out of cache based on recency of
|
86
|
+
use, of course.)
|
87
|
+
|
88
|
+
## API
|
89
|
+
|
90
|
+
* `set(key, value, maxAge)`
|
91
|
+
* `get(key) => value`
|
92
|
+
|
93
|
+
Both of these will update the "recently used"-ness of the key.
|
94
|
+
They do what you think. `maxAge` is optional and overrides the
|
95
|
+
cache `maxAge` option if provided.
|
96
|
+
|
97
|
+
If the key is not found, `get()` will return `undefined`.
|
98
|
+
|
99
|
+
The key and val can be any value.
|
100
|
+
|
101
|
+
* `peek(key)`
|
102
|
+
|
103
|
+
Returns the key value (or `undefined` if not found) without
|
104
|
+
updating the "recently used"-ness of the key.
|
105
|
+
|
106
|
+
(If you find yourself using this a lot, you *might* be using the
|
107
|
+
wrong sort of data structure, but there are some use cases where
|
108
|
+
it's handy.)
|
109
|
+
|
110
|
+
* `del(key)`
|
111
|
+
|
112
|
+
Deletes a key out of the cache.
|
113
|
+
|
114
|
+
* `reset()`
|
115
|
+
|
116
|
+
Clear the cache entirely, throwing away all values.
|
117
|
+
|
118
|
+
* `has(key)`
|
119
|
+
|
120
|
+
Check if a key is in the cache, without updating the recent-ness
|
121
|
+
or deleting it for being stale.
|
122
|
+
|
123
|
+
* `forEach(function(value,key,cache), [thisp])`
|
124
|
+
|
125
|
+
Just like `Array.prototype.forEach`. Iterates over all the keys
|
126
|
+
in the cache, in order of recent-ness. (Ie, more recently used
|
127
|
+
items are iterated over first.)
|
128
|
+
|
129
|
+
* `rforEach(function(value,key,cache), [thisp])`
|
130
|
+
|
131
|
+
The same as `cache.forEach(...)` but items are iterated over in
|
132
|
+
reverse order. (ie, less recently used items are iterated over
|
133
|
+
first.)
|
134
|
+
|
135
|
+
* `keys()`
|
136
|
+
|
137
|
+
Return an array of the keys in the cache.
|
138
|
+
|
139
|
+
* `values()`
|
140
|
+
|
141
|
+
Return an array of the values in the cache.
|
142
|
+
|
143
|
+
* `length`
|
144
|
+
|
145
|
+
Return total length of objects in cache taking into account
|
146
|
+
`length` options function.
|
147
|
+
|
148
|
+
* `itemCount`
|
149
|
+
|
150
|
+
Return total quantity of objects currently in cache. Note, that
|
151
|
+
`stale` (see options) items are returned as part of this item
|
152
|
+
count.
|
153
|
+
|
154
|
+
* `dump()`
|
155
|
+
|
156
|
+
Return an array of the cache entries ready for serialization and usage
|
157
|
+
with 'destinationCache.load(arr)`.
|
158
|
+
|
159
|
+
* `load(cacheEntriesArray)`
|
160
|
+
|
161
|
+
Loads another cache entries array, obtained with `sourceCache.dump()`,
|
162
|
+
into the cache. The destination cache is reset before loading new entries
|
163
|
+
|
164
|
+
* `prune()`
|
165
|
+
|
166
|
+
Manually iterates over the entire cache proactively pruning old entries
|
@@ -0,0 +1,334 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// A linked list to keep track of recently-used-ness
|
4
|
+
const Yallist = require('yallist')
|
5
|
+
|
6
|
+
const MAX = Symbol('max')
|
7
|
+
const LENGTH = Symbol('length')
|
8
|
+
const LENGTH_CALCULATOR = Symbol('lengthCalculator')
|
9
|
+
const ALLOW_STALE = Symbol('allowStale')
|
10
|
+
const MAX_AGE = Symbol('maxAge')
|
11
|
+
const DISPOSE = Symbol('dispose')
|
12
|
+
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet')
|
13
|
+
const LRU_LIST = Symbol('lruList')
|
14
|
+
const CACHE = Symbol('cache')
|
15
|
+
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet')
|
16
|
+
|
17
|
+
const naiveLength = () => 1
|
18
|
+
|
19
|
+
// lruList is a yallist where the head is the youngest
|
20
|
+
// item, and the tail is the oldest. the list contains the Hit
|
21
|
+
// objects as the entries.
|
22
|
+
// Each Hit object has a reference to its Yallist.Node. This
|
23
|
+
// never changes.
|
24
|
+
//
|
25
|
+
// cache is a Map (or PseudoMap) that matches the keys to
|
26
|
+
// the Yallist.Node object.
|
27
|
+
class LRUCache {
|
28
|
+
constructor (options) {
|
29
|
+
if (typeof options === 'number')
|
30
|
+
options = { max: options }
|
31
|
+
|
32
|
+
if (!options)
|
33
|
+
options = {}
|
34
|
+
|
35
|
+
if (options.max && (typeof options.max !== 'number' || options.max < 0))
|
36
|
+
throw new TypeError('max must be a non-negative number')
|
37
|
+
// Kind of weird to have a default max of Infinity, but oh well.
|
38
|
+
const max = this[MAX] = options.max || Infinity
|
39
|
+
|
40
|
+
const lc = options.length || naiveLength
|
41
|
+
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc
|
42
|
+
this[ALLOW_STALE] = options.stale || false
|
43
|
+
if (options.maxAge && typeof options.maxAge !== 'number')
|
44
|
+
throw new TypeError('maxAge must be a number')
|
45
|
+
this[MAX_AGE] = options.maxAge || 0
|
46
|
+
this[DISPOSE] = options.dispose
|
47
|
+
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false
|
48
|
+
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false
|
49
|
+
this.reset()
|
50
|
+
}
|
51
|
+
|
52
|
+
// resize the cache when the max changes.
|
53
|
+
set max (mL) {
|
54
|
+
if (typeof mL !== 'number' || mL < 0)
|
55
|
+
throw new TypeError('max must be a non-negative number')
|
56
|
+
|
57
|
+
this[MAX] = mL || Infinity
|
58
|
+
trim(this)
|
59
|
+
}
|
60
|
+
get max () {
|
61
|
+
return this[MAX]
|
62
|
+
}
|
63
|
+
|
64
|
+
set allowStale (allowStale) {
|
65
|
+
this[ALLOW_STALE] = !!allowStale
|
66
|
+
}
|
67
|
+
get allowStale () {
|
68
|
+
return this[ALLOW_STALE]
|
69
|
+
}
|
70
|
+
|
71
|
+
set maxAge (mA) {
|
72
|
+
if (typeof mA !== 'number')
|
73
|
+
throw new TypeError('maxAge must be a non-negative number')
|
74
|
+
|
75
|
+
this[MAX_AGE] = mA
|
76
|
+
trim(this)
|
77
|
+
}
|
78
|
+
get maxAge () {
|
79
|
+
return this[MAX_AGE]
|
80
|
+
}
|
81
|
+
|
82
|
+
// resize the cache when the lengthCalculator changes.
|
83
|
+
set lengthCalculator (lC) {
|
84
|
+
if (typeof lC !== 'function')
|
85
|
+
lC = naiveLength
|
86
|
+
|
87
|
+
if (lC !== this[LENGTH_CALCULATOR]) {
|
88
|
+
this[LENGTH_CALCULATOR] = lC
|
89
|
+
this[LENGTH] = 0
|
90
|
+
this[LRU_LIST].forEach(hit => {
|
91
|
+
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key)
|
92
|
+
this[LENGTH] += hit.length
|
93
|
+
})
|
94
|
+
}
|
95
|
+
trim(this)
|
96
|
+
}
|
97
|
+
get lengthCalculator () { return this[LENGTH_CALCULATOR] }
|
98
|
+
|
99
|
+
get length () { return this[LENGTH] }
|
100
|
+
get itemCount () { return this[LRU_LIST].length }
|
101
|
+
|
102
|
+
rforEach (fn, thisp) {
|
103
|
+
thisp = thisp || this
|
104
|
+
for (let walker = this[LRU_LIST].tail; walker !== null;) {
|
105
|
+
const prev = walker.prev
|
106
|
+
forEachStep(this, fn, walker, thisp)
|
107
|
+
walker = prev
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
forEach (fn, thisp) {
|
112
|
+
thisp = thisp || this
|
113
|
+
for (let walker = this[LRU_LIST].head; walker !== null;) {
|
114
|
+
const next = walker.next
|
115
|
+
forEachStep(this, fn, walker, thisp)
|
116
|
+
walker = next
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
keys () {
|
121
|
+
return this[LRU_LIST].toArray().map(k => k.key)
|
122
|
+
}
|
123
|
+
|
124
|
+
values () {
|
125
|
+
return this[LRU_LIST].toArray().map(k => k.value)
|
126
|
+
}
|
127
|
+
|
128
|
+
reset () {
|
129
|
+
if (this[DISPOSE] &&
|
130
|
+
this[LRU_LIST] &&
|
131
|
+
this[LRU_LIST].length) {
|
132
|
+
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value))
|
133
|
+
}
|
134
|
+
|
135
|
+
this[CACHE] = new Map() // hash of items by key
|
136
|
+
this[LRU_LIST] = new Yallist() // list of items in order of use recency
|
137
|
+
this[LENGTH] = 0 // length of items in the list
|
138
|
+
}
|
139
|
+
|
140
|
+
dump () {
|
141
|
+
return this[LRU_LIST].map(hit =>
|
142
|
+
isStale(this, hit) ? false : {
|
143
|
+
k: hit.key,
|
144
|
+
v: hit.value,
|
145
|
+
e: hit.now + (hit.maxAge || 0)
|
146
|
+
}).toArray().filter(h => h)
|
147
|
+
}
|
148
|
+
|
149
|
+
dumpLru () {
|
150
|
+
return this[LRU_LIST]
|
151
|
+
}
|
152
|
+
|
153
|
+
set (key, value, maxAge) {
|
154
|
+
maxAge = maxAge || this[MAX_AGE]
|
155
|
+
|
156
|
+
if (maxAge && typeof maxAge !== 'number')
|
157
|
+
throw new TypeError('maxAge must be a number')
|
158
|
+
|
159
|
+
const now = maxAge ? Date.now() : 0
|
160
|
+
const len = this[LENGTH_CALCULATOR](value, key)
|
161
|
+
|
162
|
+
if (this[CACHE].has(key)) {
|
163
|
+
if (len > this[MAX]) {
|
164
|
+
del(this, this[CACHE].get(key))
|
165
|
+
return false
|
166
|
+
}
|
167
|
+
|
168
|
+
const node = this[CACHE].get(key)
|
169
|
+
const item = node.value
|
170
|
+
|
171
|
+
// dispose of the old one before overwriting
|
172
|
+
// split out into 2 ifs for better coverage tracking
|
173
|
+
if (this[DISPOSE]) {
|
174
|
+
if (!this[NO_DISPOSE_ON_SET])
|
175
|
+
this[DISPOSE](key, item.value)
|
176
|
+
}
|
177
|
+
|
178
|
+
item.now = now
|
179
|
+
item.maxAge = maxAge
|
180
|
+
item.value = value
|
181
|
+
this[LENGTH] += len - item.length
|
182
|
+
item.length = len
|
183
|
+
this.get(key)
|
184
|
+
trim(this)
|
185
|
+
return true
|
186
|
+
}
|
187
|
+
|
188
|
+
const hit = new Entry(key, value, len, now, maxAge)
|
189
|
+
|
190
|
+
// oversized objects fall out of cache automatically.
|
191
|
+
if (hit.length > this[MAX]) {
|
192
|
+
if (this[DISPOSE])
|
193
|
+
this[DISPOSE](key, value)
|
194
|
+
|
195
|
+
return false
|
196
|
+
}
|
197
|
+
|
198
|
+
this[LENGTH] += hit.length
|
199
|
+
this[LRU_LIST].unshift(hit)
|
200
|
+
this[CACHE].set(key, this[LRU_LIST].head)
|
201
|
+
trim(this)
|
202
|
+
return true
|
203
|
+
}
|
204
|
+
|
205
|
+
has (key) {
|
206
|
+
if (!this[CACHE].has(key)) return false
|
207
|
+
const hit = this[CACHE].get(key).value
|
208
|
+
return !isStale(this, hit)
|
209
|
+
}
|
210
|
+
|
211
|
+
get (key) {
|
212
|
+
return get(this, key, true)
|
213
|
+
}
|
214
|
+
|
215
|
+
peek (key) {
|
216
|
+
return get(this, key, false)
|
217
|
+
}
|
218
|
+
|
219
|
+
pop () {
|
220
|
+
const node = this[LRU_LIST].tail
|
221
|
+
if (!node)
|
222
|
+
return null
|
223
|
+
|
224
|
+
del(this, node)
|
225
|
+
return node.value
|
226
|
+
}
|
227
|
+
|
228
|
+
del (key) {
|
229
|
+
del(this, this[CACHE].get(key))
|
230
|
+
}
|
231
|
+
|
232
|
+
load (arr) {
|
233
|
+
// reset the cache
|
234
|
+
this.reset()
|
235
|
+
|
236
|
+
const now = Date.now()
|
237
|
+
// A previous serialized cache has the most recent items first
|
238
|
+
for (let l = arr.length - 1; l >= 0; l--) {
|
239
|
+
const hit = arr[l]
|
240
|
+
const expiresAt = hit.e || 0
|
241
|
+
if (expiresAt === 0)
|
242
|
+
// the item was created without expiration in a non aged cache
|
243
|
+
this.set(hit.k, hit.v)
|
244
|
+
else {
|
245
|
+
const maxAge = expiresAt - now
|
246
|
+
// dont add already expired items
|
247
|
+
if (maxAge > 0) {
|
248
|
+
this.set(hit.k, hit.v, maxAge)
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
prune () {
|
255
|
+
this[CACHE].forEach((value, key) => get(this, key, false))
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
const get = (self, key, doUse) => {
|
260
|
+
const node = self[CACHE].get(key)
|
261
|
+
if (node) {
|
262
|
+
const hit = node.value
|
263
|
+
if (isStale(self, hit)) {
|
264
|
+
del(self, node)
|
265
|
+
if (!self[ALLOW_STALE])
|
266
|
+
return undefined
|
267
|
+
} else {
|
268
|
+
if (doUse) {
|
269
|
+
if (self[UPDATE_AGE_ON_GET])
|
270
|
+
node.value.now = Date.now()
|
271
|
+
self[LRU_LIST].unshiftNode(node)
|
272
|
+
}
|
273
|
+
}
|
274
|
+
return hit.value
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
const isStale = (self, hit) => {
|
279
|
+
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
280
|
+
return false
|
281
|
+
|
282
|
+
const diff = Date.now() - hit.now
|
283
|
+
return hit.maxAge ? diff > hit.maxAge
|
284
|
+
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
285
|
+
}
|
286
|
+
|
287
|
+
const trim = self => {
|
288
|
+
if (self[LENGTH] > self[MAX]) {
|
289
|
+
for (let walker = self[LRU_LIST].tail;
|
290
|
+
self[LENGTH] > self[MAX] && walker !== null;) {
|
291
|
+
// We know that we're about to delete this one, and also
|
292
|
+
// what the next least recently used key will be, so just
|
293
|
+
// go ahead and set it now.
|
294
|
+
const prev = walker.prev
|
295
|
+
del(self, walker)
|
296
|
+
walker = prev
|
297
|
+
}
|
298
|
+
}
|
299
|
+
}
|
300
|
+
|
301
|
+
const del = (self, node) => {
|
302
|
+
if (node) {
|
303
|
+
const hit = node.value
|
304
|
+
if (self[DISPOSE])
|
305
|
+
self[DISPOSE](hit.key, hit.value)
|
306
|
+
|
307
|
+
self[LENGTH] -= hit.length
|
308
|
+
self[CACHE].delete(hit.key)
|
309
|
+
self[LRU_LIST].removeNode(node)
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
class Entry {
|
314
|
+
constructor (key, value, length, now, maxAge) {
|
315
|
+
this.key = key
|
316
|
+
this.value = value
|
317
|
+
this.length = length
|
318
|
+
this.now = now
|
319
|
+
this.maxAge = maxAge || 0
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
const forEachStep = (self, fn, node, thisp) => {
|
324
|
+
let hit = node.value
|
325
|
+
if (isStale(self, hit)) {
|
326
|
+
del(self, node)
|
327
|
+
if (!self[ALLOW_STALE])
|
328
|
+
hit = undefined
|
329
|
+
}
|
330
|
+
if (hit)
|
331
|
+
fn.call(thisp, hit.value, hit.key, self)
|
332
|
+
}
|
333
|
+
|
334
|
+
module.exports = LRUCache
|