vlt 0.0.0-31 → 0.0.0-32
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/{build-LRDKUHJK.js → build-KMGMW3EZ.js} +8 -8
- package/{cache-I4JGFEM2.js → cache-PDCL2ZUG.js} +7 -7
- package/{chunk-ZF5MHRCT.js → chunk-2IYWVHBN.js} +5 -5
- package/{chunk-OUL7JE73.js → chunk-2UNCDUC4.js} +2 -2
- package/{chunk-EKBSQQ6W.js → chunk-3GMR34FM.js} +5 -5
- package/{chunk-SZ3KI24O.js → chunk-3T6A7YZ5.js} +2 -2
- package/{chunk-IDOEF6OJ.js → chunk-7FANUXII.js} +2 -2
- package/{chunk-5R5NSUCN.js → chunk-B3M3HY3X.js} +36 -36
- package/{chunk-5R5NSUCN.js.map → chunk-B3M3HY3X.js.map} +4 -4
- package/{chunk-JC4WASXA.js → chunk-B4MAUXR2.js} +195 -195
- package/{chunk-JC4WASXA.js.map → chunk-B4MAUXR2.js.map} +4 -4
- package/{chunk-N3Q26AXW.js → chunk-E64JLMRD.js} +2 -2
- package/{chunk-QEYM4UAU.js → chunk-J7HQZAES.js} +11 -6
- package/chunk-J7HQZAES.js.map +7 -0
- package/{chunk-EIOKPCZD.js → chunk-JYTPHQ4K.js} +4 -4
- package/{chunk-34YJRFHS.js → chunk-MHTZEJP3.js} +7 -7
- package/{chunk-BW4JKVB6.js → chunk-OY4QLBLS.js} +4 -4
- package/{chunk-NSZCBCC5.js → chunk-PALUZ2UX.js} +2 -2
- package/{chunk-IJH53F3B.js → chunk-PPT2YQ4P.js} +3 -3
- package/{chunk-DNNZSV6K.js → chunk-QEJDHVVK.js} +2 -2
- package/{chunk-2CGYSOAS.js → chunk-QI752L7R.js} +3 -3
- package/{chunk-SNQ4PO7Y.js → chunk-VNXRDROY.js} +2 -2
- package/{chunk-YVCRGHAO.js → chunk-WFRXX4YI.js} +5 -5
- package/chunk-XAUNNB4J.js +59 -0
- package/{chunk-K64USDHL.js.map → chunk-XAUNNB4J.js.map} +1 -1
- package/{chunk-P2BCNHZP.js → chunk-YQDU3VOE.js} +2 -1
- package/{chunk-P2BCNHZP.js.map → chunk-YQDU3VOE.js.map} +2 -2
- package/{chunk-MJ6IEING.js → chunk-ZVDNERGW.js} +9 -9
- package/{ci-37OJVYX5.js → ci-CWYKVWKH.js} +8 -8
- package/cli-package.json +2 -1
- package/{config-5A2CP5SV.js → config-JKPHMOZ5.js} +10 -10
- package/{config-VLHYTONG.js → config-TSS7Q2O4.js} +8 -8
- package/docs-ZQCCBSMY.js +2052 -0
- package/docs-ZQCCBSMY.js.map +7 -0
- package/{exec-ID3WRKLO.js → exec-ZX3PLEDA.js} +16 -16
- package/{exec-cache-A7HM5XPP.js → exec-cache-QPPQDNGW.js} +12 -12
- package/{exec-local-AXEJZE76.js → exec-local-N5MTZG4A.js} +15 -15
- package/{help-EI23EMPZ.js → help-ITLJK5ML.js} +4 -4
- package/{init-NB4R632S.js → init-HAPSHNV5.js} +7 -7
- package/{install-65NJ4HVW.js → install-NF7BKA7U.js} +9 -9
- package/{list-PYOZQWNI.js → list-ZH6NQGV5.js} +15 -15
- package/{login-UZO6WYY3.js → login-N4CQS2VA.js} +6 -6
- package/{logout-CGBNCC34.js → logout-LIDHTAZW.js} +6 -6
- package/{pack-F3ZVQYBI.js → pack-DD2Q2EFP.js} +14 -14
- package/package.json +1 -1
- package/{pkg-LHXQDKMQ.js → pkg-AQZBDQHR.js} +14 -14
- package/{publish-HTGCIY3S.js → publish-JG3QM654.js} +14 -14
- package/{query-6BHCY4RH.js → query-6ZXCB62J.js} +15 -15
- package/registry-client-package.json +1 -1
- package/{run-XHC3RPFG.js → run-S2GDX5LQ.js} +15 -15
- package/{run-exec-NF2PD6OG.js → run-exec-WKYKQ7YZ.js} +15 -15
- package/{serve-SPLWOC7D.js → serve-VPMETC7Q.js} +17 -17
- package/{src-XZR4K5W5.js → src-XYDPD2HX.js} +10 -10
- package/{token-KCFRIDIZ.js → token-X2QMBMYR.js} +6 -6
- package/{uninstall-4NT4N27K.js → uninstall-6HLK2PKW.js} +9 -9
- package/{update-YYJXOCPL.js → update-CFQEMARY.js} +8 -8
- package/{version-WO5L7MQP.js → version-QGOW3ROC.js} +13 -13
- package/vlr.js +1 -1
- package/vlrx.js +1 -1
- package/vlt.js +1 -1
- package/vlx.js +1 -1
- package/vlxl.js +1 -1
- package/{whoami-Q3S6RLSA.js → whoami-5J2DKCJX.js} +6 -6
- package/chunk-K64USDHL.js +0 -58
- package/chunk-QEYM4UAU.js.map +0 -7
- /package/{build-LRDKUHJK.js.map → build-KMGMW3EZ.js.map} +0 -0
- /package/{cache-I4JGFEM2.js.map → cache-PDCL2ZUG.js.map} +0 -0
- /package/{chunk-ZF5MHRCT.js.map → chunk-2IYWVHBN.js.map} +0 -0
- /package/{chunk-OUL7JE73.js.map → chunk-2UNCDUC4.js.map} +0 -0
- /package/{chunk-EKBSQQ6W.js.map → chunk-3GMR34FM.js.map} +0 -0
- /package/{chunk-SZ3KI24O.js.map → chunk-3T6A7YZ5.js.map} +0 -0
- /package/{chunk-IDOEF6OJ.js.map → chunk-7FANUXII.js.map} +0 -0
- /package/{chunk-N3Q26AXW.js.map → chunk-E64JLMRD.js.map} +0 -0
- /package/{chunk-EIOKPCZD.js.map → chunk-JYTPHQ4K.js.map} +0 -0
- /package/{chunk-34YJRFHS.js.map → chunk-MHTZEJP3.js.map} +0 -0
- /package/{chunk-BW4JKVB6.js.map → chunk-OY4QLBLS.js.map} +0 -0
- /package/{chunk-NSZCBCC5.js.map → chunk-PALUZ2UX.js.map} +0 -0
- /package/{chunk-IJH53F3B.js.map → chunk-PPT2YQ4P.js.map} +0 -0
- /package/{chunk-DNNZSV6K.js.map → chunk-QEJDHVVK.js.map} +0 -0
- /package/{chunk-2CGYSOAS.js.map → chunk-QI752L7R.js.map} +0 -0
- /package/{chunk-SNQ4PO7Y.js.map → chunk-VNXRDROY.js.map} +0 -0
- /package/{chunk-YVCRGHAO.js.map → chunk-WFRXX4YI.js.map} +0 -0
- /package/{chunk-MJ6IEING.js.map → chunk-ZVDNERGW.js.map} +0 -0
- /package/{ci-37OJVYX5.js.map → ci-CWYKVWKH.js.map} +0 -0
- /package/{config-5A2CP5SV.js.map → config-JKPHMOZ5.js.map} +0 -0
- /package/{config-VLHYTONG.js.map → config-TSS7Q2O4.js.map} +0 -0
- /package/{exec-ID3WRKLO.js.map → exec-ZX3PLEDA.js.map} +0 -0
- /package/{exec-cache-A7HM5XPP.js.map → exec-cache-QPPQDNGW.js.map} +0 -0
- /package/{exec-local-AXEJZE76.js.map → exec-local-N5MTZG4A.js.map} +0 -0
- /package/{help-EI23EMPZ.js.map → help-ITLJK5ML.js.map} +0 -0
- /package/{init-NB4R632S.js.map → init-HAPSHNV5.js.map} +0 -0
- /package/{install-65NJ4HVW.js.map → install-NF7BKA7U.js.map} +0 -0
- /package/{list-PYOZQWNI.js.map → list-ZH6NQGV5.js.map} +0 -0
- /package/{login-UZO6WYY3.js.map → login-N4CQS2VA.js.map} +0 -0
- /package/{logout-CGBNCC34.js.map → logout-LIDHTAZW.js.map} +0 -0
- /package/{pack-F3ZVQYBI.js.map → pack-DD2Q2EFP.js.map} +0 -0
- /package/{pkg-LHXQDKMQ.js.map → pkg-AQZBDQHR.js.map} +0 -0
- /package/{publish-HTGCIY3S.js.map → publish-JG3QM654.js.map} +0 -0
- /package/{query-6BHCY4RH.js.map → query-6ZXCB62J.js.map} +0 -0
- /package/{run-XHC3RPFG.js.map → run-S2GDX5LQ.js.map} +0 -0
- /package/{run-exec-NF2PD6OG.js.map → run-exec-WKYKQ7YZ.js.map} +0 -0
- /package/{serve-SPLWOC7D.js.map → serve-VPMETC7Q.js.map} +0 -0
- /package/{src-XZR4K5W5.js.map → src-XYDPD2HX.js.map} +0 -0
- /package/{token-KCFRIDIZ.js.map → token-X2QMBMYR.js.map} +0 -0
- /package/{uninstall-4NT4N27K.js.map → uninstall-6HLK2PKW.js.map} +0 -0
- /package/{update-YYJXOCPL.js.map → update-CFQEMARY.js.map} +0 -0
- /package/{version-WO5L7MQP.js.map → version-QGOW3ROC.js.map} +0 -0
- /package/{whoami-Q3S6RLSA.js.map → whoami-5J2DKCJX.js.map} +0 -0
package/docs-ZQCCBSMY.js
ADDED
|
@@ -0,0 +1,2052 @@
|
|
|
1
|
+
var global = globalThis;
|
|
2
|
+
import {Buffer} from "node:buffer";
|
|
3
|
+
import {setTimeout,clearTimeout,setImmediate,clearImmediate,setInterval,clearInterval} from "node:timers";
|
|
4
|
+
import {createRequire as _vlt_createRequire} from "node:module";
|
|
5
|
+
var require = _vlt_createRequire(import.meta.filename);
|
|
6
|
+
import {
|
|
7
|
+
createHostContextsMap
|
|
8
|
+
} from "./chunk-ZVDNERGW.js";
|
|
9
|
+
import "./chunk-PPT2YQ4P.js";
|
|
10
|
+
import "./chunk-53BUMVGW.js";
|
|
11
|
+
import "./chunk-2IYWVHBN.js";
|
|
12
|
+
import {
|
|
13
|
+
PackageInfoClient
|
|
14
|
+
} from "./chunk-J7HQZAES.js";
|
|
15
|
+
import {
|
|
16
|
+
urlOpen
|
|
17
|
+
} from "./chunk-B3M3HY3X.js";
|
|
18
|
+
import {
|
|
19
|
+
Query,
|
|
20
|
+
SecurityArchive,
|
|
21
|
+
actual
|
|
22
|
+
} from "./chunk-WFRXX4YI.js";
|
|
23
|
+
import "./chunk-3T6A7YZ5.js";
|
|
24
|
+
import {
|
|
25
|
+
commandUsage
|
|
26
|
+
} from "./chunk-VNXRDROY.js";
|
|
27
|
+
import "./chunk-7FANUXII.js";
|
|
28
|
+
import {
|
|
29
|
+
Spec2 as Spec
|
|
30
|
+
} from "./chunk-OV3MJLQS.js";
|
|
31
|
+
import "./chunk-PALUZ2UX.js";
|
|
32
|
+
import "./chunk-B4MAUXR2.js";
|
|
33
|
+
import "./chunk-YQDU3VOE.js";
|
|
34
|
+
import "./chunk-O57KIW5U.js";
|
|
35
|
+
import "./chunk-3K26SXIZ.js";
|
|
36
|
+
import "./chunk-OAYCZMD4.js";
|
|
37
|
+
import "./chunk-QOAKZNUG.js";
|
|
38
|
+
import "./chunk-BA67AKYJ.js";
|
|
39
|
+
import {
|
|
40
|
+
error
|
|
41
|
+
} from "./chunk-KVH5ECIG.js";
|
|
42
|
+
import {
|
|
43
|
+
__commonJS,
|
|
44
|
+
__require,
|
|
45
|
+
__toESM
|
|
46
|
+
} from "./chunk-AECDW3EJ.js";
|
|
47
|
+
|
|
48
|
+
// ../../node_modules/.pnpm/lru-cache@10.4.3/node_modules/lru-cache/dist/commonjs/index.js
|
|
49
|
+
var require_commonjs = __commonJS({
|
|
50
|
+
"../../node_modules/.pnpm/lru-cache@10.4.3/node_modules/lru-cache/dist/commonjs/index.js"(exports) {
|
|
51
|
+
"use strict";
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.LRUCache = void 0;
|
|
54
|
+
var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
55
|
+
var warned = /* @__PURE__ */ new Set();
|
|
56
|
+
var PROCESS = typeof process === "object" && !!process ? process : {};
|
|
57
|
+
var emitWarning = (msg, type, code, fn) => {
|
|
58
|
+
typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
|
|
59
|
+
};
|
|
60
|
+
var AC = globalThis.AbortController;
|
|
61
|
+
var AS = globalThis.AbortSignal;
|
|
62
|
+
if (typeof AC === "undefined") {
|
|
63
|
+
AS = class AbortSignal {
|
|
64
|
+
onabort;
|
|
65
|
+
_onabort = [];
|
|
66
|
+
reason;
|
|
67
|
+
aborted = false;
|
|
68
|
+
addEventListener(_, fn) {
|
|
69
|
+
this._onabort.push(fn);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
AC = class AbortController {
|
|
73
|
+
constructor() {
|
|
74
|
+
warnACPolyfill();
|
|
75
|
+
}
|
|
76
|
+
signal = new AS();
|
|
77
|
+
abort(reason) {
|
|
78
|
+
if (this.signal.aborted)
|
|
79
|
+
return;
|
|
80
|
+
this.signal.reason = reason;
|
|
81
|
+
this.signal.aborted = true;
|
|
82
|
+
for (const fn of this.signal._onabort) {
|
|
83
|
+
fn(reason);
|
|
84
|
+
}
|
|
85
|
+
this.signal.onabort?.(reason);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
|
|
89
|
+
const warnACPolyfill = () => {
|
|
90
|
+
if (!printACPolyfillWarning)
|
|
91
|
+
return;
|
|
92
|
+
printACPolyfillWarning = false;
|
|
93
|
+
emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
var shouldWarn = (code) => !warned.has(code);
|
|
97
|
+
var TYPE = Symbol("type");
|
|
98
|
+
var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
99
|
+
var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
|
|
100
|
+
var ZeroArray = class extends Array {
|
|
101
|
+
constructor(size) {
|
|
102
|
+
super(size);
|
|
103
|
+
this.fill(0);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var Stack = class _Stack {
|
|
107
|
+
heap;
|
|
108
|
+
length;
|
|
109
|
+
// private constructor
|
|
110
|
+
static #constructing = false;
|
|
111
|
+
static create(max) {
|
|
112
|
+
const HeapCls = getUintArray(max);
|
|
113
|
+
if (!HeapCls)
|
|
114
|
+
return [];
|
|
115
|
+
_Stack.#constructing = true;
|
|
116
|
+
const s = new _Stack(max, HeapCls);
|
|
117
|
+
_Stack.#constructing = false;
|
|
118
|
+
return s;
|
|
119
|
+
}
|
|
120
|
+
constructor(max, HeapCls) {
|
|
121
|
+
if (!_Stack.#constructing) {
|
|
122
|
+
throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
123
|
+
}
|
|
124
|
+
this.heap = new HeapCls(max);
|
|
125
|
+
this.length = 0;
|
|
126
|
+
}
|
|
127
|
+
push(n) {
|
|
128
|
+
this.heap[this.length++] = n;
|
|
129
|
+
}
|
|
130
|
+
pop() {
|
|
131
|
+
return this.heap[--this.length];
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var LRUCache = class _LRUCache {
|
|
135
|
+
// options that cannot be changed without disaster
|
|
136
|
+
#max;
|
|
137
|
+
#maxSize;
|
|
138
|
+
#dispose;
|
|
139
|
+
#disposeAfter;
|
|
140
|
+
#fetchMethod;
|
|
141
|
+
#memoMethod;
|
|
142
|
+
/**
|
|
143
|
+
* {@link LRUCache.OptionsBase.ttl}
|
|
144
|
+
*/
|
|
145
|
+
ttl;
|
|
146
|
+
/**
|
|
147
|
+
* {@link LRUCache.OptionsBase.ttlResolution}
|
|
148
|
+
*/
|
|
149
|
+
ttlResolution;
|
|
150
|
+
/**
|
|
151
|
+
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
|
152
|
+
*/
|
|
153
|
+
ttlAutopurge;
|
|
154
|
+
/**
|
|
155
|
+
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
|
156
|
+
*/
|
|
157
|
+
updateAgeOnGet;
|
|
158
|
+
/**
|
|
159
|
+
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
|
160
|
+
*/
|
|
161
|
+
updateAgeOnHas;
|
|
162
|
+
/**
|
|
163
|
+
* {@link LRUCache.OptionsBase.allowStale}
|
|
164
|
+
*/
|
|
165
|
+
allowStale;
|
|
166
|
+
/**
|
|
167
|
+
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
|
168
|
+
*/
|
|
169
|
+
noDisposeOnSet;
|
|
170
|
+
/**
|
|
171
|
+
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
|
172
|
+
*/
|
|
173
|
+
noUpdateTTL;
|
|
174
|
+
/**
|
|
175
|
+
* {@link LRUCache.OptionsBase.maxEntrySize}
|
|
176
|
+
*/
|
|
177
|
+
maxEntrySize;
|
|
178
|
+
/**
|
|
179
|
+
* {@link LRUCache.OptionsBase.sizeCalculation}
|
|
180
|
+
*/
|
|
181
|
+
sizeCalculation;
|
|
182
|
+
/**
|
|
183
|
+
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
|
184
|
+
*/
|
|
185
|
+
noDeleteOnFetchRejection;
|
|
186
|
+
/**
|
|
187
|
+
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
|
188
|
+
*/
|
|
189
|
+
noDeleteOnStaleGet;
|
|
190
|
+
/**
|
|
191
|
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
|
192
|
+
*/
|
|
193
|
+
allowStaleOnFetchAbort;
|
|
194
|
+
/**
|
|
195
|
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
|
196
|
+
*/
|
|
197
|
+
allowStaleOnFetchRejection;
|
|
198
|
+
/**
|
|
199
|
+
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
|
200
|
+
*/
|
|
201
|
+
ignoreFetchAbort;
|
|
202
|
+
// computed properties
|
|
203
|
+
#size;
|
|
204
|
+
#calculatedSize;
|
|
205
|
+
#keyMap;
|
|
206
|
+
#keyList;
|
|
207
|
+
#valList;
|
|
208
|
+
#next;
|
|
209
|
+
#prev;
|
|
210
|
+
#head;
|
|
211
|
+
#tail;
|
|
212
|
+
#free;
|
|
213
|
+
#disposed;
|
|
214
|
+
#sizes;
|
|
215
|
+
#starts;
|
|
216
|
+
#ttls;
|
|
217
|
+
#hasDispose;
|
|
218
|
+
#hasFetchMethod;
|
|
219
|
+
#hasDisposeAfter;
|
|
220
|
+
/**
|
|
221
|
+
* Do not call this method unless you need to inspect the
|
|
222
|
+
* inner workings of the cache. If anything returned by this
|
|
223
|
+
* object is modified in any way, strange breakage may occur.
|
|
224
|
+
*
|
|
225
|
+
* These fields are private for a reason!
|
|
226
|
+
*
|
|
227
|
+
* @internal
|
|
228
|
+
*/
|
|
229
|
+
static unsafeExposeInternals(c) {
|
|
230
|
+
return {
|
|
231
|
+
// properties
|
|
232
|
+
starts: c.#starts,
|
|
233
|
+
ttls: c.#ttls,
|
|
234
|
+
sizes: c.#sizes,
|
|
235
|
+
keyMap: c.#keyMap,
|
|
236
|
+
keyList: c.#keyList,
|
|
237
|
+
valList: c.#valList,
|
|
238
|
+
next: c.#next,
|
|
239
|
+
prev: c.#prev,
|
|
240
|
+
get head() {
|
|
241
|
+
return c.#head;
|
|
242
|
+
},
|
|
243
|
+
get tail() {
|
|
244
|
+
return c.#tail;
|
|
245
|
+
},
|
|
246
|
+
free: c.#free,
|
|
247
|
+
// methods
|
|
248
|
+
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
249
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
250
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
251
|
+
indexes: (options) => c.#indexes(options),
|
|
252
|
+
rindexes: (options) => c.#rindexes(options),
|
|
253
|
+
isStale: (index) => c.#isStale(index)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// Protected read-only members
|
|
257
|
+
/**
|
|
258
|
+
* {@link LRUCache.OptionsBase.max} (read-only)
|
|
259
|
+
*/
|
|
260
|
+
get max() {
|
|
261
|
+
return this.#max;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
|
265
|
+
*/
|
|
266
|
+
get maxSize() {
|
|
267
|
+
return this.#maxSize;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The total computed size of items in the cache (read-only)
|
|
271
|
+
*/
|
|
272
|
+
get calculatedSize() {
|
|
273
|
+
return this.#calculatedSize;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The number of items stored in the cache (read-only)
|
|
277
|
+
*/
|
|
278
|
+
get size() {
|
|
279
|
+
return this.#size;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
|
283
|
+
*/
|
|
284
|
+
get fetchMethod() {
|
|
285
|
+
return this.#fetchMethod;
|
|
286
|
+
}
|
|
287
|
+
get memoMethod() {
|
|
288
|
+
return this.#memoMethod;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
|
292
|
+
*/
|
|
293
|
+
get dispose() {
|
|
294
|
+
return this.#dispose;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
|
298
|
+
*/
|
|
299
|
+
get disposeAfter() {
|
|
300
|
+
return this.#disposeAfter;
|
|
301
|
+
}
|
|
302
|
+
constructor(options) {
|
|
303
|
+
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort } = options;
|
|
304
|
+
if (max !== 0 && !isPosInt(max)) {
|
|
305
|
+
throw new TypeError("max option must be a nonnegative integer");
|
|
306
|
+
}
|
|
307
|
+
const UintArray = max ? getUintArray(max) : Array;
|
|
308
|
+
if (!UintArray) {
|
|
309
|
+
throw new Error("invalid max value: " + max);
|
|
310
|
+
}
|
|
311
|
+
this.#max = max;
|
|
312
|
+
this.#maxSize = maxSize;
|
|
313
|
+
this.maxEntrySize = maxEntrySize || this.#maxSize;
|
|
314
|
+
this.sizeCalculation = sizeCalculation;
|
|
315
|
+
if (this.sizeCalculation) {
|
|
316
|
+
if (!this.#maxSize && !this.maxEntrySize) {
|
|
317
|
+
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
318
|
+
}
|
|
319
|
+
if (typeof this.sizeCalculation !== "function") {
|
|
320
|
+
throw new TypeError("sizeCalculation set to non-function");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (memoMethod !== void 0 && typeof memoMethod !== "function") {
|
|
324
|
+
throw new TypeError("memoMethod must be a function if defined");
|
|
325
|
+
}
|
|
326
|
+
this.#memoMethod = memoMethod;
|
|
327
|
+
if (fetchMethod !== void 0 && typeof fetchMethod !== "function") {
|
|
328
|
+
throw new TypeError("fetchMethod must be a function if specified");
|
|
329
|
+
}
|
|
330
|
+
this.#fetchMethod = fetchMethod;
|
|
331
|
+
this.#hasFetchMethod = !!fetchMethod;
|
|
332
|
+
this.#keyMap = /* @__PURE__ */ new Map();
|
|
333
|
+
this.#keyList = new Array(max).fill(void 0);
|
|
334
|
+
this.#valList = new Array(max).fill(void 0);
|
|
335
|
+
this.#next = new UintArray(max);
|
|
336
|
+
this.#prev = new UintArray(max);
|
|
337
|
+
this.#head = 0;
|
|
338
|
+
this.#tail = 0;
|
|
339
|
+
this.#free = Stack.create(max);
|
|
340
|
+
this.#size = 0;
|
|
341
|
+
this.#calculatedSize = 0;
|
|
342
|
+
if (typeof dispose === "function") {
|
|
343
|
+
this.#dispose = dispose;
|
|
344
|
+
}
|
|
345
|
+
if (typeof disposeAfter === "function") {
|
|
346
|
+
this.#disposeAfter = disposeAfter;
|
|
347
|
+
this.#disposed = [];
|
|
348
|
+
} else {
|
|
349
|
+
this.#disposeAfter = void 0;
|
|
350
|
+
this.#disposed = void 0;
|
|
351
|
+
}
|
|
352
|
+
this.#hasDispose = !!this.#dispose;
|
|
353
|
+
this.#hasDisposeAfter = !!this.#disposeAfter;
|
|
354
|
+
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
355
|
+
this.noUpdateTTL = !!noUpdateTTL;
|
|
356
|
+
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
|
357
|
+
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
|
358
|
+
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
|
359
|
+
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
|
360
|
+
if (this.maxEntrySize !== 0) {
|
|
361
|
+
if (this.#maxSize !== 0) {
|
|
362
|
+
if (!isPosInt(this.#maxSize)) {
|
|
363
|
+
throw new TypeError("maxSize must be a positive integer if specified");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (!isPosInt(this.maxEntrySize)) {
|
|
367
|
+
throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
368
|
+
}
|
|
369
|
+
this.#initializeSizeTracking();
|
|
370
|
+
}
|
|
371
|
+
this.allowStale = !!allowStale;
|
|
372
|
+
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
|
373
|
+
this.updateAgeOnGet = !!updateAgeOnGet;
|
|
374
|
+
this.updateAgeOnHas = !!updateAgeOnHas;
|
|
375
|
+
this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
|
|
376
|
+
this.ttlAutopurge = !!ttlAutopurge;
|
|
377
|
+
this.ttl = ttl || 0;
|
|
378
|
+
if (this.ttl) {
|
|
379
|
+
if (!isPosInt(this.ttl)) {
|
|
380
|
+
throw new TypeError("ttl must be a positive integer if specified");
|
|
381
|
+
}
|
|
382
|
+
this.#initializeTTLTracking();
|
|
383
|
+
}
|
|
384
|
+
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
|
|
385
|
+
throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
386
|
+
}
|
|
387
|
+
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
|
388
|
+
const code = "LRU_CACHE_UNBOUNDED";
|
|
389
|
+
if (shouldWarn(code)) {
|
|
390
|
+
warned.add(code);
|
|
391
|
+
const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
|
|
392
|
+
emitWarning(msg, "UnboundedCacheWarning", code, _LRUCache);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Return the number of ms left in the item's TTL. If item is not in cache,
|
|
398
|
+
* returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
|
|
399
|
+
*/
|
|
400
|
+
getRemainingTTL(key) {
|
|
401
|
+
return this.#keyMap.has(key) ? Infinity : 0;
|
|
402
|
+
}
|
|
403
|
+
#initializeTTLTracking() {
|
|
404
|
+
const ttls = new ZeroArray(this.#max);
|
|
405
|
+
const starts = new ZeroArray(this.#max);
|
|
406
|
+
this.#ttls = ttls;
|
|
407
|
+
this.#starts = starts;
|
|
408
|
+
this.#setItemTTL = (index, ttl, start = perf.now()) => {
|
|
409
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
410
|
+
ttls[index] = ttl;
|
|
411
|
+
if (ttl !== 0 && this.ttlAutopurge) {
|
|
412
|
+
const t = setTimeout(() => {
|
|
413
|
+
if (this.#isStale(index)) {
|
|
414
|
+
this.#delete(this.#keyList[index], "expire");
|
|
415
|
+
}
|
|
416
|
+
}, ttl + 1);
|
|
417
|
+
if (t.unref) {
|
|
418
|
+
t.unref();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
this.#updateItemAge = (index) => {
|
|
423
|
+
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
424
|
+
};
|
|
425
|
+
this.#statusTTL = (status, index) => {
|
|
426
|
+
if (ttls[index]) {
|
|
427
|
+
const ttl = ttls[index];
|
|
428
|
+
const start = starts[index];
|
|
429
|
+
if (!ttl || !start)
|
|
430
|
+
return;
|
|
431
|
+
status.ttl = ttl;
|
|
432
|
+
status.start = start;
|
|
433
|
+
status.now = cachedNow || getNow();
|
|
434
|
+
const age = status.now - start;
|
|
435
|
+
status.remainingTTL = ttl - age;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
let cachedNow = 0;
|
|
439
|
+
const getNow = () => {
|
|
440
|
+
const n = perf.now();
|
|
441
|
+
if (this.ttlResolution > 0) {
|
|
442
|
+
cachedNow = n;
|
|
443
|
+
const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
|
|
444
|
+
if (t.unref) {
|
|
445
|
+
t.unref();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return n;
|
|
449
|
+
};
|
|
450
|
+
this.getRemainingTTL = (key) => {
|
|
451
|
+
const index = this.#keyMap.get(key);
|
|
452
|
+
if (index === void 0) {
|
|
453
|
+
return 0;
|
|
454
|
+
}
|
|
455
|
+
const ttl = ttls[index];
|
|
456
|
+
const start = starts[index];
|
|
457
|
+
if (!ttl || !start) {
|
|
458
|
+
return Infinity;
|
|
459
|
+
}
|
|
460
|
+
const age = (cachedNow || getNow()) - start;
|
|
461
|
+
return ttl - age;
|
|
462
|
+
};
|
|
463
|
+
this.#isStale = (index) => {
|
|
464
|
+
const s = starts[index];
|
|
465
|
+
const t = ttls[index];
|
|
466
|
+
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
// conditionally set private methods related to TTL
|
|
470
|
+
#updateItemAge = () => {
|
|
471
|
+
};
|
|
472
|
+
#statusTTL = () => {
|
|
473
|
+
};
|
|
474
|
+
#setItemTTL = () => {
|
|
475
|
+
};
|
|
476
|
+
/* c8 ignore stop */
|
|
477
|
+
#isStale = () => false;
|
|
478
|
+
#initializeSizeTracking() {
|
|
479
|
+
const sizes = new ZeroArray(this.#max);
|
|
480
|
+
this.#calculatedSize = 0;
|
|
481
|
+
this.#sizes = sizes;
|
|
482
|
+
this.#removeItemSize = (index) => {
|
|
483
|
+
this.#calculatedSize -= sizes[index];
|
|
484
|
+
sizes[index] = 0;
|
|
485
|
+
};
|
|
486
|
+
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
487
|
+
if (this.#isBackgroundFetch(v)) {
|
|
488
|
+
return 0;
|
|
489
|
+
}
|
|
490
|
+
if (!isPosInt(size)) {
|
|
491
|
+
if (sizeCalculation) {
|
|
492
|
+
if (typeof sizeCalculation !== "function") {
|
|
493
|
+
throw new TypeError("sizeCalculation must be a function");
|
|
494
|
+
}
|
|
495
|
+
size = sizeCalculation(v, k);
|
|
496
|
+
if (!isPosInt(size)) {
|
|
497
|
+
throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return size;
|
|
504
|
+
};
|
|
505
|
+
this.#addItemSize = (index, size, status) => {
|
|
506
|
+
sizes[index] = size;
|
|
507
|
+
if (this.#maxSize) {
|
|
508
|
+
const maxSize = this.#maxSize - sizes[index];
|
|
509
|
+
while (this.#calculatedSize > maxSize) {
|
|
510
|
+
this.#evict(true);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
this.#calculatedSize += sizes[index];
|
|
514
|
+
if (status) {
|
|
515
|
+
status.entrySize = size;
|
|
516
|
+
status.totalCalculatedSize = this.#calculatedSize;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
#removeItemSize = (_i) => {
|
|
521
|
+
};
|
|
522
|
+
#addItemSize = (_i, _s, _st) => {
|
|
523
|
+
};
|
|
524
|
+
#requireSize = (_k, _v, size, sizeCalculation) => {
|
|
525
|
+
if (size || sizeCalculation) {
|
|
526
|
+
throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
527
|
+
}
|
|
528
|
+
return 0;
|
|
529
|
+
};
|
|
530
|
+
*#indexes({ allowStale = this.allowStale } = {}) {
|
|
531
|
+
if (this.#size) {
|
|
532
|
+
for (let i = this.#tail; true; ) {
|
|
533
|
+
if (!this.#isValidIndex(i)) {
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
if (allowStale || !this.#isStale(i)) {
|
|
537
|
+
yield i;
|
|
538
|
+
}
|
|
539
|
+
if (i === this.#head) {
|
|
540
|
+
break;
|
|
541
|
+
} else {
|
|
542
|
+
i = this.#prev[i];
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
*#rindexes({ allowStale = this.allowStale } = {}) {
|
|
548
|
+
if (this.#size) {
|
|
549
|
+
for (let i = this.#head; true; ) {
|
|
550
|
+
if (!this.#isValidIndex(i)) {
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
if (allowStale || !this.#isStale(i)) {
|
|
554
|
+
yield i;
|
|
555
|
+
}
|
|
556
|
+
if (i === this.#tail) {
|
|
557
|
+
break;
|
|
558
|
+
} else {
|
|
559
|
+
i = this.#next[i];
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
#isValidIndex(index) {
|
|
565
|
+
return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Return a generator yielding `[key, value]` pairs,
|
|
569
|
+
* in order from most recently used to least recently used.
|
|
570
|
+
*/
|
|
571
|
+
*entries() {
|
|
572
|
+
for (const i of this.#indexes()) {
|
|
573
|
+
if (this.#valList[i] !== void 0 && this.#keyList[i] !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
574
|
+
yield [this.#keyList[i], this.#valList[i]];
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Inverse order version of {@link LRUCache.entries}
|
|
580
|
+
*
|
|
581
|
+
* Return a generator yielding `[key, value]` pairs,
|
|
582
|
+
* in order from least recently used to most recently used.
|
|
583
|
+
*/
|
|
584
|
+
*rentries() {
|
|
585
|
+
for (const i of this.#rindexes()) {
|
|
586
|
+
if (this.#valList[i] !== void 0 && this.#keyList[i] !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
587
|
+
yield [this.#keyList[i], this.#valList[i]];
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Return a generator yielding the keys in the cache,
|
|
593
|
+
* in order from most recently used to least recently used.
|
|
594
|
+
*/
|
|
595
|
+
*keys() {
|
|
596
|
+
for (const i of this.#indexes()) {
|
|
597
|
+
const k = this.#keyList[i];
|
|
598
|
+
if (k !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
599
|
+
yield k;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Inverse order version of {@link LRUCache.keys}
|
|
605
|
+
*
|
|
606
|
+
* Return a generator yielding the keys in the cache,
|
|
607
|
+
* in order from least recently used to most recently used.
|
|
608
|
+
*/
|
|
609
|
+
*rkeys() {
|
|
610
|
+
for (const i of this.#rindexes()) {
|
|
611
|
+
const k = this.#keyList[i];
|
|
612
|
+
if (k !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
613
|
+
yield k;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Return a generator yielding the values in the cache,
|
|
619
|
+
* in order from most recently used to least recently used.
|
|
620
|
+
*/
|
|
621
|
+
*values() {
|
|
622
|
+
for (const i of this.#indexes()) {
|
|
623
|
+
const v = this.#valList[i];
|
|
624
|
+
if (v !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
625
|
+
yield this.#valList[i];
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Inverse order version of {@link LRUCache.values}
|
|
631
|
+
*
|
|
632
|
+
* Return a generator yielding the values in the cache,
|
|
633
|
+
* in order from least recently used to most recently used.
|
|
634
|
+
*/
|
|
635
|
+
*rvalues() {
|
|
636
|
+
for (const i of this.#rindexes()) {
|
|
637
|
+
const v = this.#valList[i];
|
|
638
|
+
if (v !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
639
|
+
yield this.#valList[i];
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Iterating over the cache itself yields the same results as
|
|
645
|
+
* {@link LRUCache.entries}
|
|
646
|
+
*/
|
|
647
|
+
[Symbol.iterator]() {
|
|
648
|
+
return this.entries();
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* A String value that is used in the creation of the default string
|
|
652
|
+
* description of an object. Called by the built-in method
|
|
653
|
+
* `Object.prototype.toString`.
|
|
654
|
+
*/
|
|
655
|
+
[Symbol.toStringTag] = "LRUCache";
|
|
656
|
+
/**
|
|
657
|
+
* Find a value for which the supplied fn method returns a truthy value,
|
|
658
|
+
* similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
|
|
659
|
+
*/
|
|
660
|
+
find(fn, getOptions = {}) {
|
|
661
|
+
for (const i of this.#indexes()) {
|
|
662
|
+
const v = this.#valList[i];
|
|
663
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
664
|
+
if (value === void 0)
|
|
665
|
+
continue;
|
|
666
|
+
if (fn(value, this.#keyList[i], this)) {
|
|
667
|
+
return this.get(this.#keyList[i], getOptions);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Call the supplied function on each item in the cache, in order from most
|
|
673
|
+
* recently used to least recently used.
|
|
674
|
+
*
|
|
675
|
+
* `fn` is called as `fn(value, key, cache)`.
|
|
676
|
+
*
|
|
677
|
+
* If `thisp` is provided, function will be called in the `this`-context of
|
|
678
|
+
* the provided object, or the cache if no `thisp` object is provided.
|
|
679
|
+
*
|
|
680
|
+
* Does not update age or recenty of use, or iterate over stale values.
|
|
681
|
+
*/
|
|
682
|
+
forEach(fn, thisp = this) {
|
|
683
|
+
for (const i of this.#indexes()) {
|
|
684
|
+
const v = this.#valList[i];
|
|
685
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
686
|
+
if (value === void 0)
|
|
687
|
+
continue;
|
|
688
|
+
fn.call(thisp, value, this.#keyList[i], this);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* The same as {@link LRUCache.forEach} but items are iterated over in
|
|
693
|
+
* reverse order. (ie, less recently used items are iterated over first.)
|
|
694
|
+
*/
|
|
695
|
+
rforEach(fn, thisp = this) {
|
|
696
|
+
for (const i of this.#rindexes()) {
|
|
697
|
+
const v = this.#valList[i];
|
|
698
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
699
|
+
if (value === void 0)
|
|
700
|
+
continue;
|
|
701
|
+
fn.call(thisp, value, this.#keyList[i], this);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Delete any stale entries. Returns true if anything was removed,
|
|
706
|
+
* false otherwise.
|
|
707
|
+
*/
|
|
708
|
+
purgeStale() {
|
|
709
|
+
let deleted = false;
|
|
710
|
+
for (const i of this.#rindexes({ allowStale: true })) {
|
|
711
|
+
if (this.#isStale(i)) {
|
|
712
|
+
this.#delete(this.#keyList[i], "expire");
|
|
713
|
+
deleted = true;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return deleted;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Get the extended info about a given entry, to get its value, size, and
|
|
720
|
+
* TTL info simultaneously. Returns `undefined` if the key is not present.
|
|
721
|
+
*
|
|
722
|
+
* Unlike {@link LRUCache#dump}, which is designed to be portable and survive
|
|
723
|
+
* serialization, the `start` value is always the current timestamp, and the
|
|
724
|
+
* `ttl` is a calculated remaining time to live (negative if expired).
|
|
725
|
+
*
|
|
726
|
+
* Always returns stale values, if their info is found in the cache, so be
|
|
727
|
+
* sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
|
|
728
|
+
* if relevant.
|
|
729
|
+
*/
|
|
730
|
+
info(key) {
|
|
731
|
+
const i = this.#keyMap.get(key);
|
|
732
|
+
if (i === void 0)
|
|
733
|
+
return void 0;
|
|
734
|
+
const v = this.#valList[i];
|
|
735
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
736
|
+
if (value === void 0)
|
|
737
|
+
return void 0;
|
|
738
|
+
const entry = { value };
|
|
739
|
+
if (this.#ttls && this.#starts) {
|
|
740
|
+
const ttl = this.#ttls[i];
|
|
741
|
+
const start = this.#starts[i];
|
|
742
|
+
if (ttl && start) {
|
|
743
|
+
const remain = ttl - (perf.now() - start);
|
|
744
|
+
entry.ttl = remain;
|
|
745
|
+
entry.start = Date.now();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (this.#sizes) {
|
|
749
|
+
entry.size = this.#sizes[i];
|
|
750
|
+
}
|
|
751
|
+
return entry;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
|
755
|
+
* passed to {@link LRLUCache#load}.
|
|
756
|
+
*
|
|
757
|
+
* The `start` fields are calculated relative to a portable `Date.now()`
|
|
758
|
+
* timestamp, even if `performance.now()` is available.
|
|
759
|
+
*
|
|
760
|
+
* Stale entries are always included in the `dump`, even if
|
|
761
|
+
* {@link LRUCache.OptionsBase.allowStale} is false.
|
|
762
|
+
*
|
|
763
|
+
* Note: this returns an actual array, not a generator, so it can be more
|
|
764
|
+
* easily passed around.
|
|
765
|
+
*/
|
|
766
|
+
dump() {
|
|
767
|
+
const arr = [];
|
|
768
|
+
for (const i of this.#indexes({ allowStale: true })) {
|
|
769
|
+
const key = this.#keyList[i];
|
|
770
|
+
const v = this.#valList[i];
|
|
771
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
772
|
+
if (value === void 0 || key === void 0)
|
|
773
|
+
continue;
|
|
774
|
+
const entry = { value };
|
|
775
|
+
if (this.#ttls && this.#starts) {
|
|
776
|
+
entry.ttl = this.#ttls[i];
|
|
777
|
+
const age = perf.now() - this.#starts[i];
|
|
778
|
+
entry.start = Math.floor(Date.now() - age);
|
|
779
|
+
}
|
|
780
|
+
if (this.#sizes) {
|
|
781
|
+
entry.size = this.#sizes[i];
|
|
782
|
+
}
|
|
783
|
+
arr.unshift([key, entry]);
|
|
784
|
+
}
|
|
785
|
+
return arr;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Reset the cache and load in the items in entries in the order listed.
|
|
789
|
+
*
|
|
790
|
+
* The shape of the resulting cache may be different if the same options are
|
|
791
|
+
* not used in both caches.
|
|
792
|
+
*
|
|
793
|
+
* The `start` fields are assumed to be calculated relative to a portable
|
|
794
|
+
* `Date.now()` timestamp, even if `performance.now()` is available.
|
|
795
|
+
*/
|
|
796
|
+
load(arr) {
|
|
797
|
+
this.clear();
|
|
798
|
+
for (const [key, entry] of arr) {
|
|
799
|
+
if (entry.start) {
|
|
800
|
+
const age = Date.now() - entry.start;
|
|
801
|
+
entry.start = perf.now() - age;
|
|
802
|
+
}
|
|
803
|
+
this.set(key, entry.value, entry);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Add a value to the cache.
|
|
808
|
+
*
|
|
809
|
+
* Note: if `undefined` is specified as a value, this is an alias for
|
|
810
|
+
* {@link LRUCache#delete}
|
|
811
|
+
*
|
|
812
|
+
* Fields on the {@link LRUCache.SetOptions} options param will override
|
|
813
|
+
* their corresponding values in the constructor options for the scope
|
|
814
|
+
* of this single `set()` operation.
|
|
815
|
+
*
|
|
816
|
+
* If `start` is provided, then that will set the effective start
|
|
817
|
+
* time for the TTL calculation. Note that this must be a previous
|
|
818
|
+
* value of `performance.now()` if supported, or a previous value of
|
|
819
|
+
* `Date.now()` if not.
|
|
820
|
+
*
|
|
821
|
+
* Options object may also include `size`, which will prevent
|
|
822
|
+
* calling the `sizeCalculation` function and just use the specified
|
|
823
|
+
* number if it is a positive integer, and `noDisposeOnSet` which
|
|
824
|
+
* will prevent calling a `dispose` function in the case of
|
|
825
|
+
* overwrites.
|
|
826
|
+
*
|
|
827
|
+
* If the `size` (or return value of `sizeCalculation`) for a given
|
|
828
|
+
* entry is greater than `maxEntrySize`, then the item will not be
|
|
829
|
+
* added to the cache.
|
|
830
|
+
*
|
|
831
|
+
* Will update the recency of the entry.
|
|
832
|
+
*
|
|
833
|
+
* If the value is `undefined`, then this is an alias for
|
|
834
|
+
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
|
835
|
+
*/
|
|
836
|
+
set(k, v, setOptions = {}) {
|
|
837
|
+
if (v === void 0) {
|
|
838
|
+
this.delete(k);
|
|
839
|
+
return this;
|
|
840
|
+
}
|
|
841
|
+
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
|
|
842
|
+
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
|
843
|
+
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
|
|
844
|
+
if (this.maxEntrySize && size > this.maxEntrySize) {
|
|
845
|
+
if (status) {
|
|
846
|
+
status.set = "miss";
|
|
847
|
+
status.maxEntrySizeExceeded = true;
|
|
848
|
+
}
|
|
849
|
+
this.#delete(k, "set");
|
|
850
|
+
return this;
|
|
851
|
+
}
|
|
852
|
+
let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
|
|
853
|
+
if (index === void 0) {
|
|
854
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
855
|
+
this.#keyList[index] = k;
|
|
856
|
+
this.#valList[index] = v;
|
|
857
|
+
this.#keyMap.set(k, index);
|
|
858
|
+
this.#next[this.#tail] = index;
|
|
859
|
+
this.#prev[index] = this.#tail;
|
|
860
|
+
this.#tail = index;
|
|
861
|
+
this.#size++;
|
|
862
|
+
this.#addItemSize(index, size, status);
|
|
863
|
+
if (status)
|
|
864
|
+
status.set = "add";
|
|
865
|
+
noUpdateTTL = false;
|
|
866
|
+
} else {
|
|
867
|
+
this.#moveToTail(index);
|
|
868
|
+
const oldVal = this.#valList[index];
|
|
869
|
+
if (v !== oldVal) {
|
|
870
|
+
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
871
|
+
oldVal.__abortController.abort(new Error("replaced"));
|
|
872
|
+
const { __staleWhileFetching: s } = oldVal;
|
|
873
|
+
if (s !== void 0 && !noDisposeOnSet) {
|
|
874
|
+
if (this.#hasDispose) {
|
|
875
|
+
this.#dispose?.(s, k, "set");
|
|
876
|
+
}
|
|
877
|
+
if (this.#hasDisposeAfter) {
|
|
878
|
+
this.#disposed?.push([s, k, "set"]);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
} else if (!noDisposeOnSet) {
|
|
882
|
+
if (this.#hasDispose) {
|
|
883
|
+
this.#dispose?.(oldVal, k, "set");
|
|
884
|
+
}
|
|
885
|
+
if (this.#hasDisposeAfter) {
|
|
886
|
+
this.#disposed?.push([oldVal, k, "set"]);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
this.#removeItemSize(index);
|
|
890
|
+
this.#addItemSize(index, size, status);
|
|
891
|
+
this.#valList[index] = v;
|
|
892
|
+
if (status) {
|
|
893
|
+
status.set = "replace";
|
|
894
|
+
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
895
|
+
if (oldValue !== void 0)
|
|
896
|
+
status.oldValue = oldValue;
|
|
897
|
+
}
|
|
898
|
+
} else if (status) {
|
|
899
|
+
status.set = "update";
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (ttl !== 0 && !this.#ttls) {
|
|
903
|
+
this.#initializeTTLTracking();
|
|
904
|
+
}
|
|
905
|
+
if (this.#ttls) {
|
|
906
|
+
if (!noUpdateTTL) {
|
|
907
|
+
this.#setItemTTL(index, ttl, start);
|
|
908
|
+
}
|
|
909
|
+
if (status)
|
|
910
|
+
this.#statusTTL(status, index);
|
|
911
|
+
}
|
|
912
|
+
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
913
|
+
const dt = this.#disposed;
|
|
914
|
+
let task;
|
|
915
|
+
while (task = dt?.shift()) {
|
|
916
|
+
this.#disposeAfter?.(...task);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return this;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Evict the least recently used item, returning its value or
|
|
923
|
+
* `undefined` if cache is empty.
|
|
924
|
+
*/
|
|
925
|
+
pop() {
|
|
926
|
+
try {
|
|
927
|
+
while (this.#size) {
|
|
928
|
+
const val = this.#valList[this.#head];
|
|
929
|
+
this.#evict(true);
|
|
930
|
+
if (this.#isBackgroundFetch(val)) {
|
|
931
|
+
if (val.__staleWhileFetching) {
|
|
932
|
+
return val.__staleWhileFetching;
|
|
933
|
+
}
|
|
934
|
+
} else if (val !== void 0) {
|
|
935
|
+
return val;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
} finally {
|
|
939
|
+
if (this.#hasDisposeAfter && this.#disposed) {
|
|
940
|
+
const dt = this.#disposed;
|
|
941
|
+
let task;
|
|
942
|
+
while (task = dt?.shift()) {
|
|
943
|
+
this.#disposeAfter?.(...task);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
#evict(free) {
|
|
949
|
+
const head = this.#head;
|
|
950
|
+
const k = this.#keyList[head];
|
|
951
|
+
const v = this.#valList[head];
|
|
952
|
+
if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
|
|
953
|
+
v.__abortController.abort(new Error("evicted"));
|
|
954
|
+
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
955
|
+
if (this.#hasDispose) {
|
|
956
|
+
this.#dispose?.(v, k, "evict");
|
|
957
|
+
}
|
|
958
|
+
if (this.#hasDisposeAfter) {
|
|
959
|
+
this.#disposed?.push([v, k, "evict"]);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
this.#removeItemSize(head);
|
|
963
|
+
if (free) {
|
|
964
|
+
this.#keyList[head] = void 0;
|
|
965
|
+
this.#valList[head] = void 0;
|
|
966
|
+
this.#free.push(head);
|
|
967
|
+
}
|
|
968
|
+
if (this.#size === 1) {
|
|
969
|
+
this.#head = this.#tail = 0;
|
|
970
|
+
this.#free.length = 0;
|
|
971
|
+
} else {
|
|
972
|
+
this.#head = this.#next[head];
|
|
973
|
+
}
|
|
974
|
+
this.#keyMap.delete(k);
|
|
975
|
+
this.#size--;
|
|
976
|
+
return head;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Check if a key is in the cache, without updating the recency of use.
|
|
980
|
+
* Will return false if the item is stale, even though it is technically
|
|
981
|
+
* in the cache.
|
|
982
|
+
*
|
|
983
|
+
* Check if a key is in the cache, without updating the recency of
|
|
984
|
+
* use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
|
|
985
|
+
* to `true` in either the options or the constructor.
|
|
986
|
+
*
|
|
987
|
+
* Will return `false` if the item is stale, even though it is technically in
|
|
988
|
+
* the cache. The difference can be determined (if it matters) by using a
|
|
989
|
+
* `status` argument, and inspecting the `has` field.
|
|
990
|
+
*
|
|
991
|
+
* Will not update item age unless
|
|
992
|
+
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
|
993
|
+
*/
|
|
994
|
+
has(k, hasOptions = {}) {
|
|
995
|
+
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
996
|
+
const index = this.#keyMap.get(k);
|
|
997
|
+
if (index !== void 0) {
|
|
998
|
+
const v = this.#valList[index];
|
|
999
|
+
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
if (!this.#isStale(index)) {
|
|
1003
|
+
if (updateAgeOnHas) {
|
|
1004
|
+
this.#updateItemAge(index);
|
|
1005
|
+
}
|
|
1006
|
+
if (status) {
|
|
1007
|
+
status.has = "hit";
|
|
1008
|
+
this.#statusTTL(status, index);
|
|
1009
|
+
}
|
|
1010
|
+
return true;
|
|
1011
|
+
} else if (status) {
|
|
1012
|
+
status.has = "stale";
|
|
1013
|
+
this.#statusTTL(status, index);
|
|
1014
|
+
}
|
|
1015
|
+
} else if (status) {
|
|
1016
|
+
status.has = "miss";
|
|
1017
|
+
}
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
|
1022
|
+
* items.
|
|
1023
|
+
*
|
|
1024
|
+
* Returns `undefined` if the item is stale, unless
|
|
1025
|
+
* {@link LRUCache.OptionsBase.allowStale} is set.
|
|
1026
|
+
*/
|
|
1027
|
+
peek(k, peekOptions = {}) {
|
|
1028
|
+
const { allowStale = this.allowStale } = peekOptions;
|
|
1029
|
+
const index = this.#keyMap.get(k);
|
|
1030
|
+
if (index === void 0 || !allowStale && this.#isStale(index)) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
const v = this.#valList[index];
|
|
1034
|
+
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
1035
|
+
}
|
|
1036
|
+
#backgroundFetch(k, index, options, context) {
|
|
1037
|
+
const v = index === void 0 ? void 0 : this.#valList[index];
|
|
1038
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1039
|
+
return v;
|
|
1040
|
+
}
|
|
1041
|
+
const ac = new AC();
|
|
1042
|
+
const { signal } = options;
|
|
1043
|
+
signal?.addEventListener("abort", () => ac.abort(signal.reason), {
|
|
1044
|
+
signal: ac.signal
|
|
1045
|
+
});
|
|
1046
|
+
const fetchOpts = {
|
|
1047
|
+
signal: ac.signal,
|
|
1048
|
+
options,
|
|
1049
|
+
context
|
|
1050
|
+
};
|
|
1051
|
+
const cb = (v2, updateCache = false) => {
|
|
1052
|
+
const { aborted } = ac.signal;
|
|
1053
|
+
const ignoreAbort = options.ignoreFetchAbort && v2 !== void 0;
|
|
1054
|
+
if (options.status) {
|
|
1055
|
+
if (aborted && !updateCache) {
|
|
1056
|
+
options.status.fetchAborted = true;
|
|
1057
|
+
options.status.fetchError = ac.signal.reason;
|
|
1058
|
+
if (ignoreAbort)
|
|
1059
|
+
options.status.fetchAbortIgnored = true;
|
|
1060
|
+
} else {
|
|
1061
|
+
options.status.fetchResolved = true;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (aborted && !ignoreAbort && !updateCache) {
|
|
1065
|
+
return fetchFail(ac.signal.reason);
|
|
1066
|
+
}
|
|
1067
|
+
const bf2 = p;
|
|
1068
|
+
if (this.#valList[index] === p) {
|
|
1069
|
+
if (v2 === void 0) {
|
|
1070
|
+
if (bf2.__staleWhileFetching) {
|
|
1071
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
1072
|
+
} else {
|
|
1073
|
+
this.#delete(k, "fetch");
|
|
1074
|
+
}
|
|
1075
|
+
} else {
|
|
1076
|
+
if (options.status)
|
|
1077
|
+
options.status.fetchUpdated = true;
|
|
1078
|
+
this.set(k, v2, fetchOpts.options);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return v2;
|
|
1082
|
+
};
|
|
1083
|
+
const eb = (er) => {
|
|
1084
|
+
if (options.status) {
|
|
1085
|
+
options.status.fetchRejected = true;
|
|
1086
|
+
options.status.fetchError = er;
|
|
1087
|
+
}
|
|
1088
|
+
return fetchFail(er);
|
|
1089
|
+
};
|
|
1090
|
+
const fetchFail = (er) => {
|
|
1091
|
+
const { aborted } = ac.signal;
|
|
1092
|
+
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
|
1093
|
+
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
1094
|
+
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
1095
|
+
const bf2 = p;
|
|
1096
|
+
if (this.#valList[index] === p) {
|
|
1097
|
+
const del = !noDelete || bf2.__staleWhileFetching === void 0;
|
|
1098
|
+
if (del) {
|
|
1099
|
+
this.#delete(k, "fetch");
|
|
1100
|
+
} else if (!allowStaleAborted) {
|
|
1101
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (allowStale) {
|
|
1105
|
+
if (options.status && bf2.__staleWhileFetching !== void 0) {
|
|
1106
|
+
options.status.returnedStale = true;
|
|
1107
|
+
}
|
|
1108
|
+
return bf2.__staleWhileFetching;
|
|
1109
|
+
} else if (bf2.__returned === bf2) {
|
|
1110
|
+
throw er;
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
const pcall = (res, rej) => {
|
|
1114
|
+
const fmp = this.#fetchMethod?.(k, v, fetchOpts);
|
|
1115
|
+
if (fmp && fmp instanceof Promise) {
|
|
1116
|
+
fmp.then((v2) => res(v2 === void 0 ? void 0 : v2), rej);
|
|
1117
|
+
}
|
|
1118
|
+
ac.signal.addEventListener("abort", () => {
|
|
1119
|
+
if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
|
|
1120
|
+
res(void 0);
|
|
1121
|
+
if (options.allowStaleOnFetchAbort) {
|
|
1122
|
+
res = (v2) => cb(v2, true);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
};
|
|
1127
|
+
if (options.status)
|
|
1128
|
+
options.status.fetchDispatched = true;
|
|
1129
|
+
const p = new Promise(pcall).then(cb, eb);
|
|
1130
|
+
const bf = Object.assign(p, {
|
|
1131
|
+
__abortController: ac,
|
|
1132
|
+
__staleWhileFetching: v,
|
|
1133
|
+
__returned: void 0
|
|
1134
|
+
});
|
|
1135
|
+
if (index === void 0) {
|
|
1136
|
+
this.set(k, bf, { ...fetchOpts.options, status: void 0 });
|
|
1137
|
+
index = this.#keyMap.get(k);
|
|
1138
|
+
} else {
|
|
1139
|
+
this.#valList[index] = bf;
|
|
1140
|
+
}
|
|
1141
|
+
return bf;
|
|
1142
|
+
}
|
|
1143
|
+
#isBackgroundFetch(p) {
|
|
1144
|
+
if (!this.#hasFetchMethod)
|
|
1145
|
+
return false;
|
|
1146
|
+
const b = p;
|
|
1147
|
+
return !!b && b instanceof Promise && b.hasOwnProperty("__staleWhileFetching") && b.__abortController instanceof AC;
|
|
1148
|
+
}
|
|
1149
|
+
async fetch(k, fetchOptions = {}) {
|
|
1150
|
+
const {
|
|
1151
|
+
// get options
|
|
1152
|
+
allowStale = this.allowStale,
|
|
1153
|
+
updateAgeOnGet = this.updateAgeOnGet,
|
|
1154
|
+
noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
1155
|
+
// set options
|
|
1156
|
+
ttl = this.ttl,
|
|
1157
|
+
noDisposeOnSet = this.noDisposeOnSet,
|
|
1158
|
+
size = 0,
|
|
1159
|
+
sizeCalculation = this.sizeCalculation,
|
|
1160
|
+
noUpdateTTL = this.noUpdateTTL,
|
|
1161
|
+
// fetch exclusive options
|
|
1162
|
+
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
|
|
1163
|
+
allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
|
|
1164
|
+
ignoreFetchAbort = this.ignoreFetchAbort,
|
|
1165
|
+
allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
|
|
1166
|
+
context,
|
|
1167
|
+
forceRefresh = false,
|
|
1168
|
+
status,
|
|
1169
|
+
signal
|
|
1170
|
+
} = fetchOptions;
|
|
1171
|
+
if (!this.#hasFetchMethod) {
|
|
1172
|
+
if (status)
|
|
1173
|
+
status.fetch = "get";
|
|
1174
|
+
return this.get(k, {
|
|
1175
|
+
allowStale,
|
|
1176
|
+
updateAgeOnGet,
|
|
1177
|
+
noDeleteOnStaleGet,
|
|
1178
|
+
status
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
const options = {
|
|
1182
|
+
allowStale,
|
|
1183
|
+
updateAgeOnGet,
|
|
1184
|
+
noDeleteOnStaleGet,
|
|
1185
|
+
ttl,
|
|
1186
|
+
noDisposeOnSet,
|
|
1187
|
+
size,
|
|
1188
|
+
sizeCalculation,
|
|
1189
|
+
noUpdateTTL,
|
|
1190
|
+
noDeleteOnFetchRejection,
|
|
1191
|
+
allowStaleOnFetchRejection,
|
|
1192
|
+
allowStaleOnFetchAbort,
|
|
1193
|
+
ignoreFetchAbort,
|
|
1194
|
+
status,
|
|
1195
|
+
signal
|
|
1196
|
+
};
|
|
1197
|
+
let index = this.#keyMap.get(k);
|
|
1198
|
+
if (index === void 0) {
|
|
1199
|
+
if (status)
|
|
1200
|
+
status.fetch = "miss";
|
|
1201
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
1202
|
+
return p.__returned = p;
|
|
1203
|
+
} else {
|
|
1204
|
+
const v = this.#valList[index];
|
|
1205
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1206
|
+
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
1207
|
+
if (status) {
|
|
1208
|
+
status.fetch = "inflight";
|
|
1209
|
+
if (stale)
|
|
1210
|
+
status.returnedStale = true;
|
|
1211
|
+
}
|
|
1212
|
+
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
1213
|
+
}
|
|
1214
|
+
const isStale = this.#isStale(index);
|
|
1215
|
+
if (!forceRefresh && !isStale) {
|
|
1216
|
+
if (status)
|
|
1217
|
+
status.fetch = "hit";
|
|
1218
|
+
this.#moveToTail(index);
|
|
1219
|
+
if (updateAgeOnGet) {
|
|
1220
|
+
this.#updateItemAge(index);
|
|
1221
|
+
}
|
|
1222
|
+
if (status)
|
|
1223
|
+
this.#statusTTL(status, index);
|
|
1224
|
+
return v;
|
|
1225
|
+
}
|
|
1226
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
1227
|
+
const hasStale = p.__staleWhileFetching !== void 0;
|
|
1228
|
+
const staleVal = hasStale && allowStale;
|
|
1229
|
+
if (status) {
|
|
1230
|
+
status.fetch = isStale ? "stale" : "refresh";
|
|
1231
|
+
if (staleVal && isStale)
|
|
1232
|
+
status.returnedStale = true;
|
|
1233
|
+
}
|
|
1234
|
+
return staleVal ? p.__staleWhileFetching : p.__returned = p;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
async forceFetch(k, fetchOptions = {}) {
|
|
1238
|
+
const v = await this.fetch(k, fetchOptions);
|
|
1239
|
+
if (v === void 0)
|
|
1240
|
+
throw new Error("fetch() returned undefined");
|
|
1241
|
+
return v;
|
|
1242
|
+
}
|
|
1243
|
+
memo(k, memoOptions = {}) {
|
|
1244
|
+
const memoMethod = this.#memoMethod;
|
|
1245
|
+
if (!memoMethod) {
|
|
1246
|
+
throw new Error("no memoMethod provided to constructor");
|
|
1247
|
+
}
|
|
1248
|
+
const { context, forceRefresh, ...options } = memoOptions;
|
|
1249
|
+
const v = this.get(k, options);
|
|
1250
|
+
if (!forceRefresh && v !== void 0)
|
|
1251
|
+
return v;
|
|
1252
|
+
const vv = memoMethod(k, v, {
|
|
1253
|
+
options,
|
|
1254
|
+
context
|
|
1255
|
+
});
|
|
1256
|
+
this.set(k, vv, options);
|
|
1257
|
+
return vv;
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Return a value from the cache. Will update the recency of the cache
|
|
1261
|
+
* entry found.
|
|
1262
|
+
*
|
|
1263
|
+
* If the key is not found, get() will return `undefined`.
|
|
1264
|
+
*/
|
|
1265
|
+
get(k, getOptions = {}) {
|
|
1266
|
+
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
1267
|
+
const index = this.#keyMap.get(k);
|
|
1268
|
+
if (index !== void 0) {
|
|
1269
|
+
const value = this.#valList[index];
|
|
1270
|
+
const fetching = this.#isBackgroundFetch(value);
|
|
1271
|
+
if (status)
|
|
1272
|
+
this.#statusTTL(status, index);
|
|
1273
|
+
if (this.#isStale(index)) {
|
|
1274
|
+
if (status)
|
|
1275
|
+
status.get = "stale";
|
|
1276
|
+
if (!fetching) {
|
|
1277
|
+
if (!noDeleteOnStaleGet) {
|
|
1278
|
+
this.#delete(k, "expire");
|
|
1279
|
+
}
|
|
1280
|
+
if (status && allowStale)
|
|
1281
|
+
status.returnedStale = true;
|
|
1282
|
+
return allowStale ? value : void 0;
|
|
1283
|
+
} else {
|
|
1284
|
+
if (status && allowStale && value.__staleWhileFetching !== void 0) {
|
|
1285
|
+
status.returnedStale = true;
|
|
1286
|
+
}
|
|
1287
|
+
return allowStale ? value.__staleWhileFetching : void 0;
|
|
1288
|
+
}
|
|
1289
|
+
} else {
|
|
1290
|
+
if (status)
|
|
1291
|
+
status.get = "hit";
|
|
1292
|
+
if (fetching) {
|
|
1293
|
+
return value.__staleWhileFetching;
|
|
1294
|
+
}
|
|
1295
|
+
this.#moveToTail(index);
|
|
1296
|
+
if (updateAgeOnGet) {
|
|
1297
|
+
this.#updateItemAge(index);
|
|
1298
|
+
}
|
|
1299
|
+
return value;
|
|
1300
|
+
}
|
|
1301
|
+
} else if (status) {
|
|
1302
|
+
status.get = "miss";
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
#connect(p, n) {
|
|
1306
|
+
this.#prev[n] = p;
|
|
1307
|
+
this.#next[p] = n;
|
|
1308
|
+
}
|
|
1309
|
+
#moveToTail(index) {
|
|
1310
|
+
if (index !== this.#tail) {
|
|
1311
|
+
if (index === this.#head) {
|
|
1312
|
+
this.#head = this.#next[index];
|
|
1313
|
+
} else {
|
|
1314
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
1315
|
+
}
|
|
1316
|
+
this.#connect(this.#tail, index);
|
|
1317
|
+
this.#tail = index;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Deletes a key out of the cache.
|
|
1322
|
+
*
|
|
1323
|
+
* Returns true if the key was deleted, false otherwise.
|
|
1324
|
+
*/
|
|
1325
|
+
delete(k) {
|
|
1326
|
+
return this.#delete(k, "delete");
|
|
1327
|
+
}
|
|
1328
|
+
#delete(k, reason) {
|
|
1329
|
+
let deleted = false;
|
|
1330
|
+
if (this.#size !== 0) {
|
|
1331
|
+
const index = this.#keyMap.get(k);
|
|
1332
|
+
if (index !== void 0) {
|
|
1333
|
+
deleted = true;
|
|
1334
|
+
if (this.#size === 1) {
|
|
1335
|
+
this.#clear(reason);
|
|
1336
|
+
} else {
|
|
1337
|
+
this.#removeItemSize(index);
|
|
1338
|
+
const v = this.#valList[index];
|
|
1339
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1340
|
+
v.__abortController.abort(new Error("deleted"));
|
|
1341
|
+
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
1342
|
+
if (this.#hasDispose) {
|
|
1343
|
+
this.#dispose?.(v, k, reason);
|
|
1344
|
+
}
|
|
1345
|
+
if (this.#hasDisposeAfter) {
|
|
1346
|
+
this.#disposed?.push([v, k, reason]);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
this.#keyMap.delete(k);
|
|
1350
|
+
this.#keyList[index] = void 0;
|
|
1351
|
+
this.#valList[index] = void 0;
|
|
1352
|
+
if (index === this.#tail) {
|
|
1353
|
+
this.#tail = this.#prev[index];
|
|
1354
|
+
} else if (index === this.#head) {
|
|
1355
|
+
this.#head = this.#next[index];
|
|
1356
|
+
} else {
|
|
1357
|
+
const pi = this.#prev[index];
|
|
1358
|
+
this.#next[pi] = this.#next[index];
|
|
1359
|
+
const ni = this.#next[index];
|
|
1360
|
+
this.#prev[ni] = this.#prev[index];
|
|
1361
|
+
}
|
|
1362
|
+
this.#size--;
|
|
1363
|
+
this.#free.push(index);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
if (this.#hasDisposeAfter && this.#disposed?.length) {
|
|
1368
|
+
const dt = this.#disposed;
|
|
1369
|
+
let task;
|
|
1370
|
+
while (task = dt?.shift()) {
|
|
1371
|
+
this.#disposeAfter?.(...task);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return deleted;
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Clear the cache entirely, throwing away all values.
|
|
1378
|
+
*/
|
|
1379
|
+
clear() {
|
|
1380
|
+
return this.#clear("delete");
|
|
1381
|
+
}
|
|
1382
|
+
#clear(reason) {
|
|
1383
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
1384
|
+
const v = this.#valList[index];
|
|
1385
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1386
|
+
v.__abortController.abort(new Error("deleted"));
|
|
1387
|
+
} else {
|
|
1388
|
+
const k = this.#keyList[index];
|
|
1389
|
+
if (this.#hasDispose) {
|
|
1390
|
+
this.#dispose?.(v, k, reason);
|
|
1391
|
+
}
|
|
1392
|
+
if (this.#hasDisposeAfter) {
|
|
1393
|
+
this.#disposed?.push([v, k, reason]);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
this.#keyMap.clear();
|
|
1398
|
+
this.#valList.fill(void 0);
|
|
1399
|
+
this.#keyList.fill(void 0);
|
|
1400
|
+
if (this.#ttls && this.#starts) {
|
|
1401
|
+
this.#ttls.fill(0);
|
|
1402
|
+
this.#starts.fill(0);
|
|
1403
|
+
}
|
|
1404
|
+
if (this.#sizes) {
|
|
1405
|
+
this.#sizes.fill(0);
|
|
1406
|
+
}
|
|
1407
|
+
this.#head = 0;
|
|
1408
|
+
this.#tail = 0;
|
|
1409
|
+
this.#free.length = 0;
|
|
1410
|
+
this.#calculatedSize = 0;
|
|
1411
|
+
this.#size = 0;
|
|
1412
|
+
if (this.#hasDisposeAfter && this.#disposed) {
|
|
1413
|
+
const dt = this.#disposed;
|
|
1414
|
+
let task;
|
|
1415
|
+
while (task = dt?.shift()) {
|
|
1416
|
+
this.#disposeAfter?.(...task);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
exports.LRUCache = LRUCache;
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
|
|
1425
|
+
// ../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/hosts.js
|
|
1426
|
+
var require_hosts = __commonJS({
|
|
1427
|
+
"../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/hosts.js"(exports, module) {
|
|
1428
|
+
"use strict";
|
|
1429
|
+
var maybeJoin = (...args) => args.every((arg) => arg) ? args.join("") : "";
|
|
1430
|
+
var maybeEncode = (arg) => arg ? encodeURIComponent(arg) : "";
|
|
1431
|
+
var formatHashFragment = (f) => f.toLowerCase().replace(/^\W+/g, "").replace(/(?<!\W)\W+$/, "").replace(/\//g, "").replace(/\W+/g, "-");
|
|
1432
|
+
var defaults = {
|
|
1433
|
+
sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1434
|
+
sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1435
|
+
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin("/", editpath, "/", maybeEncode(committish || "HEAD"), "/", path)}`,
|
|
1436
|
+
browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish))}`,
|
|
1437
|
+
browsetreetemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || "HEAD")}/${path}${maybeJoin("#", hashformat(fragment || ""))}`,
|
|
1438
|
+
browseblobtemplate: ({ domain, user, project, committish, blobpath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${blobpath}/${maybeEncode(committish || "HEAD")}/${path}${maybeJoin("#", hashformat(fragment || ""))}`,
|
|
1439
|
+
docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish))}#readme`,
|
|
1440
|
+
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1441
|
+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish || "HEAD")}/${path}`,
|
|
1442
|
+
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin("#", committish)}`,
|
|
1443
|
+
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin("#", committish)}`,
|
|
1444
|
+
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
|
|
1445
|
+
hashformat: formatHashFragment
|
|
1446
|
+
};
|
|
1447
|
+
var hosts = {};
|
|
1448
|
+
hosts.github = {
|
|
1449
|
+
// First two are insecure and generally shouldn't be used any more, but
|
|
1450
|
+
// they are still supported.
|
|
1451
|
+
protocols: ["git:", "http:", "git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1452
|
+
domain: "github.com",
|
|
1453
|
+
treepath: "tree",
|
|
1454
|
+
blobpath: "blob",
|
|
1455
|
+
editpath: "edit",
|
|
1456
|
+
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, "@")}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish || "HEAD")}/${path}`,
|
|
1457
|
+
gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1458
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish || "HEAD")}`,
|
|
1459
|
+
extract: (url) => {
|
|
1460
|
+
let [, user, project, type, committish] = url.pathname.split("/", 5);
|
|
1461
|
+
if (type && type !== "tree") {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
if (!type) {
|
|
1465
|
+
committish = url.hash.slice(1);
|
|
1466
|
+
}
|
|
1467
|
+
if (project && project.endsWith(".git")) {
|
|
1468
|
+
project = project.slice(0, -4);
|
|
1469
|
+
}
|
|
1470
|
+
if (!user || !project) {
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
return { user, project, committish };
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
hosts.bitbucket = {
|
|
1477
|
+
protocols: ["git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1478
|
+
domain: "bitbucket.org",
|
|
1479
|
+
treepath: "src",
|
|
1480
|
+
blobpath: "src",
|
|
1481
|
+
editpath: "?mode=edit",
|
|
1482
|
+
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish || "HEAD"), "/", path, editpath)}`,
|
|
1483
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish || "HEAD")}.tar.gz`,
|
|
1484
|
+
extract: (url) => {
|
|
1485
|
+
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
1486
|
+
if (["get"].includes(aux)) {
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
if (project && project.endsWith(".git")) {
|
|
1490
|
+
project = project.slice(0, -4);
|
|
1491
|
+
}
|
|
1492
|
+
if (!user || !project) {
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
hosts.gitlab = {
|
|
1499
|
+
protocols: ["git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1500
|
+
domain: "gitlab.com",
|
|
1501
|
+
treepath: "tree",
|
|
1502
|
+
blobpath: "tree",
|
|
1503
|
+
editpath: "-/edit",
|
|
1504
|
+
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1505
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish || "HEAD")}`,
|
|
1506
|
+
extract: (url) => {
|
|
1507
|
+
const path = url.pathname.slice(1);
|
|
1508
|
+
if (path.includes("/-/") || path.includes("/archive.tar.gz")) {
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
const segments = path.split("/");
|
|
1512
|
+
let project = segments.pop();
|
|
1513
|
+
if (project.endsWith(".git")) {
|
|
1514
|
+
project = project.slice(0, -4);
|
|
1515
|
+
}
|
|
1516
|
+
const user = segments.join("/");
|
|
1517
|
+
if (!user || !project) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
hosts.gist = {
|
|
1524
|
+
protocols: ["git:", "git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1525
|
+
domain: "gist.github.com",
|
|
1526
|
+
editpath: "edit",
|
|
1527
|
+
sshtemplate: ({ domain, project, committish }) => `git@${domain}:${project}.git${maybeJoin("#", committish)}`,
|
|
1528
|
+
sshurltemplate: ({ domain, project, committish }) => `git+ssh://git@${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
1529
|
+
edittemplate: ({ domain, user, project, committish, editpath }) => `https://${domain}/${user}/${project}${maybeJoin("/", maybeEncode(committish))}/${editpath}`,
|
|
1530
|
+
browsetemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}`,
|
|
1531
|
+
browsetreetemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}${maybeJoin("#", hashformat(path))}`,
|
|
1532
|
+
browseblobtemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}${maybeJoin("#", hashformat(path))}`,
|
|
1533
|
+
docstemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}`,
|
|
1534
|
+
httpstemplate: ({ domain, project, committish }) => `git+https://${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
1535
|
+
filetemplate: ({ user, project, committish, path }) => `https://gist.githubusercontent.com/${user}/${project}/raw${maybeJoin("/", maybeEncode(committish))}/${path}`,
|
|
1536
|
+
shortcuttemplate: ({ type, project, committish }) => `${type}:${project}${maybeJoin("#", committish)}`,
|
|
1537
|
+
pathtemplate: ({ project, committish }) => `${project}${maybeJoin("#", committish)}`,
|
|
1538
|
+
bugstemplate: ({ domain, project }) => `https://${domain}/${project}`,
|
|
1539
|
+
gittemplate: ({ domain, project, committish }) => `git://${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
1540
|
+
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish || "HEAD")}`,
|
|
1541
|
+
extract: (url) => {
|
|
1542
|
+
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
1543
|
+
if (aux === "raw") {
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
if (!project) {
|
|
1547
|
+
if (!user) {
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
project = user;
|
|
1551
|
+
user = null;
|
|
1552
|
+
}
|
|
1553
|
+
if (project.endsWith(".git")) {
|
|
1554
|
+
project = project.slice(0, -4);
|
|
1555
|
+
}
|
|
1556
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1557
|
+
},
|
|
1558
|
+
hashformat: function(fragment) {
|
|
1559
|
+
return fragment && "file-" + formatHashFragment(fragment);
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
hosts.sourcehut = {
|
|
1563
|
+
protocols: ["git+ssh:", "https:"],
|
|
1564
|
+
domain: "git.sr.ht",
|
|
1565
|
+
treepath: "tree",
|
|
1566
|
+
blobpath: "tree",
|
|
1567
|
+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/blob/${maybeEncode(committish) || "HEAD"}/${path}`,
|
|
1568
|
+
httpstemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1569
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/archive/${maybeEncode(committish) || "HEAD"}.tar.gz`,
|
|
1570
|
+
bugstemplate: () => null,
|
|
1571
|
+
extract: (url) => {
|
|
1572
|
+
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
1573
|
+
if (["archive"].includes(aux)) {
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
if (project && project.endsWith(".git")) {
|
|
1577
|
+
project = project.slice(0, -4);
|
|
1578
|
+
}
|
|
1579
|
+
if (!user || !project) {
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
for (const [name, host] of Object.entries(hosts)) {
|
|
1586
|
+
hosts[name] = Object.assign({}, defaults, host);
|
|
1587
|
+
}
|
|
1588
|
+
module.exports = hosts;
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
// ../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/parse-url.js
|
|
1593
|
+
var require_parse_url = __commonJS({
|
|
1594
|
+
"../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/parse-url.js"(exports, module) {
|
|
1595
|
+
var url = __require("node:url");
|
|
1596
|
+
var lastIndexOfBefore = (str, char, beforeChar) => {
|
|
1597
|
+
const startPosition = str.indexOf(beforeChar);
|
|
1598
|
+
return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity);
|
|
1599
|
+
};
|
|
1600
|
+
var safeUrl = (u) => {
|
|
1601
|
+
try {
|
|
1602
|
+
return new url.URL(u);
|
|
1603
|
+
} catch {
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
var correctProtocol = (arg, protocols) => {
|
|
1607
|
+
const firstColon = arg.indexOf(":");
|
|
1608
|
+
const proto = arg.slice(0, firstColon + 1);
|
|
1609
|
+
if (Object.prototype.hasOwnProperty.call(protocols, proto)) {
|
|
1610
|
+
return arg;
|
|
1611
|
+
}
|
|
1612
|
+
const firstAt = arg.indexOf("@");
|
|
1613
|
+
if (firstAt > -1) {
|
|
1614
|
+
if (firstAt > firstColon) {
|
|
1615
|
+
return `git+ssh://${arg}`;
|
|
1616
|
+
} else {
|
|
1617
|
+
return arg;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
const doubleSlash = arg.indexOf("//");
|
|
1621
|
+
if (doubleSlash === firstColon + 1) {
|
|
1622
|
+
return arg;
|
|
1623
|
+
}
|
|
1624
|
+
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`;
|
|
1625
|
+
};
|
|
1626
|
+
var correctUrl = (giturl) => {
|
|
1627
|
+
const firstAt = lastIndexOfBefore(giturl, "@", "#");
|
|
1628
|
+
const lastColonBeforeHash = lastIndexOfBefore(giturl, ":", "#");
|
|
1629
|
+
if (lastColonBeforeHash > firstAt) {
|
|
1630
|
+
giturl = giturl.slice(0, lastColonBeforeHash) + "/" + giturl.slice(lastColonBeforeHash + 1);
|
|
1631
|
+
}
|
|
1632
|
+
if (lastIndexOfBefore(giturl, ":", "#") === -1 && giturl.indexOf("//") === -1) {
|
|
1633
|
+
giturl = `git+ssh://${giturl}`;
|
|
1634
|
+
}
|
|
1635
|
+
return giturl;
|
|
1636
|
+
};
|
|
1637
|
+
module.exports = (giturl, protocols) => {
|
|
1638
|
+
const withProtocol = protocols ? correctProtocol(giturl, protocols) : giturl;
|
|
1639
|
+
return safeUrl(withProtocol) || safeUrl(correctUrl(withProtocol));
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// ../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/from-url.js
|
|
1645
|
+
var require_from_url = __commonJS({
|
|
1646
|
+
"../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/from-url.js"(exports, module) {
|
|
1647
|
+
"use strict";
|
|
1648
|
+
var parseUrl = require_parse_url();
|
|
1649
|
+
var isGitHubShorthand = (arg) => {
|
|
1650
|
+
const firstHash = arg.indexOf("#");
|
|
1651
|
+
const firstSlash = arg.indexOf("/");
|
|
1652
|
+
const secondSlash = arg.indexOf("/", firstSlash + 1);
|
|
1653
|
+
const firstColon = arg.indexOf(":");
|
|
1654
|
+
const firstSpace = /\s/.exec(arg);
|
|
1655
|
+
const firstAt = arg.indexOf("@");
|
|
1656
|
+
const spaceOnlyAfterHash = !firstSpace || firstHash > -1 && firstSpace.index > firstHash;
|
|
1657
|
+
const atOnlyAfterHash = firstAt === -1 || firstHash > -1 && firstAt > firstHash;
|
|
1658
|
+
const colonOnlyAfterHash = firstColon === -1 || firstHash > -1 && firstColon > firstHash;
|
|
1659
|
+
const secondSlashOnlyAfterHash = secondSlash === -1 || firstHash > -1 && secondSlash > firstHash;
|
|
1660
|
+
const hasSlash = firstSlash > 0;
|
|
1661
|
+
const doesNotEndWithSlash = firstHash > -1 ? arg[firstHash - 1] !== "/" : !arg.endsWith("/");
|
|
1662
|
+
const doesNotStartWithDot = !arg.startsWith(".");
|
|
1663
|
+
return spaceOnlyAfterHash && hasSlash && doesNotEndWithSlash && doesNotStartWithDot && atOnlyAfterHash && colonOnlyAfterHash && secondSlashOnlyAfterHash;
|
|
1664
|
+
};
|
|
1665
|
+
module.exports = (giturl, opts, { gitHosts, protocols }) => {
|
|
1666
|
+
if (!giturl) {
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
const correctedUrl = isGitHubShorthand(giturl) ? `github:${giturl}` : giturl;
|
|
1670
|
+
const parsed = parseUrl(correctedUrl, protocols);
|
|
1671
|
+
if (!parsed) {
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
const gitHostShortcut = gitHosts.byShortcut[parsed.protocol];
|
|
1675
|
+
const gitHostDomain = gitHosts.byDomain[parsed.hostname.startsWith("www.") ? parsed.hostname.slice(4) : parsed.hostname];
|
|
1676
|
+
const gitHostName = gitHostShortcut || gitHostDomain;
|
|
1677
|
+
if (!gitHostName) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
const gitHostInfo = gitHosts[gitHostShortcut || gitHostDomain];
|
|
1681
|
+
let auth = null;
|
|
1682
|
+
if (protocols[parsed.protocol]?.auth && (parsed.username || parsed.password)) {
|
|
1683
|
+
auth = `${parsed.username}${parsed.password ? ":" + parsed.password : ""}`;
|
|
1684
|
+
}
|
|
1685
|
+
let committish = null;
|
|
1686
|
+
let user = null;
|
|
1687
|
+
let project = null;
|
|
1688
|
+
let defaultRepresentation = null;
|
|
1689
|
+
try {
|
|
1690
|
+
if (gitHostShortcut) {
|
|
1691
|
+
let pathname = parsed.pathname.startsWith("/") ? parsed.pathname.slice(1) : parsed.pathname;
|
|
1692
|
+
const firstAt = pathname.indexOf("@");
|
|
1693
|
+
if (firstAt > -1) {
|
|
1694
|
+
pathname = pathname.slice(firstAt + 1);
|
|
1695
|
+
}
|
|
1696
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
1697
|
+
if (lastSlash > -1) {
|
|
1698
|
+
user = decodeURIComponent(pathname.slice(0, lastSlash));
|
|
1699
|
+
if (!user) {
|
|
1700
|
+
user = null;
|
|
1701
|
+
}
|
|
1702
|
+
project = decodeURIComponent(pathname.slice(lastSlash + 1));
|
|
1703
|
+
} else {
|
|
1704
|
+
project = decodeURIComponent(pathname);
|
|
1705
|
+
}
|
|
1706
|
+
if (project.endsWith(".git")) {
|
|
1707
|
+
project = project.slice(0, -4);
|
|
1708
|
+
}
|
|
1709
|
+
if (parsed.hash) {
|
|
1710
|
+
committish = decodeURIComponent(parsed.hash.slice(1));
|
|
1711
|
+
}
|
|
1712
|
+
defaultRepresentation = "shortcut";
|
|
1713
|
+
} else {
|
|
1714
|
+
if (!gitHostInfo.protocols.includes(parsed.protocol)) {
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
const segments = gitHostInfo.extract(parsed);
|
|
1718
|
+
if (!segments) {
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
user = segments.user && decodeURIComponent(segments.user);
|
|
1722
|
+
project = decodeURIComponent(segments.project);
|
|
1723
|
+
committish = decodeURIComponent(segments.committish);
|
|
1724
|
+
defaultRepresentation = protocols[parsed.protocol]?.name || parsed.protocol.slice(0, -1);
|
|
1725
|
+
}
|
|
1726
|
+
} catch (err) {
|
|
1727
|
+
if (err instanceof URIError) {
|
|
1728
|
+
return;
|
|
1729
|
+
} else {
|
|
1730
|
+
throw err;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
return [gitHostName, user, auth, project, committish, defaultRepresentation, opts];
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
|
|
1738
|
+
// ../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/index.js
|
|
1739
|
+
var require_lib = __commonJS({
|
|
1740
|
+
"../../node_modules/.pnpm/hosted-git-info@8.1.0/node_modules/hosted-git-info/lib/index.js"(exports, module) {
|
|
1741
|
+
"use strict";
|
|
1742
|
+
var { LRUCache } = require_commonjs();
|
|
1743
|
+
var hosts = require_hosts();
|
|
1744
|
+
var fromUrl = require_from_url();
|
|
1745
|
+
var parseUrl = require_parse_url();
|
|
1746
|
+
var cache = new LRUCache({ max: 1e3 });
|
|
1747
|
+
function unknownHostedUrl(url) {
|
|
1748
|
+
try {
|
|
1749
|
+
const {
|
|
1750
|
+
protocol,
|
|
1751
|
+
hostname,
|
|
1752
|
+
pathname
|
|
1753
|
+
} = new URL(url);
|
|
1754
|
+
if (!hostname) {
|
|
1755
|
+
return null;
|
|
1756
|
+
}
|
|
1757
|
+
const proto = /(?:git\+)http:$/.test(protocol) ? "http:" : "https:";
|
|
1758
|
+
const path = pathname.replace(/\.git$/, "");
|
|
1759
|
+
return `${proto}//${hostname}${path}`;
|
|
1760
|
+
} catch {
|
|
1761
|
+
return null;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
var GitHost = class _GitHost {
|
|
1765
|
+
constructor(type, user, auth, project, committish, defaultRepresentation, opts = {}) {
|
|
1766
|
+
Object.assign(this, _GitHost.#gitHosts[type], {
|
|
1767
|
+
type,
|
|
1768
|
+
user,
|
|
1769
|
+
auth,
|
|
1770
|
+
project,
|
|
1771
|
+
committish,
|
|
1772
|
+
default: defaultRepresentation,
|
|
1773
|
+
opts
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1776
|
+
static #gitHosts = { byShortcut: {}, byDomain: {} };
|
|
1777
|
+
static #protocols = {
|
|
1778
|
+
"git+ssh:": { name: "sshurl" },
|
|
1779
|
+
"ssh:": { name: "sshurl" },
|
|
1780
|
+
"git+https:": { name: "https", auth: true },
|
|
1781
|
+
"git:": { auth: true },
|
|
1782
|
+
"http:": { auth: true },
|
|
1783
|
+
"https:": { auth: true },
|
|
1784
|
+
"git+http:": { auth: true }
|
|
1785
|
+
};
|
|
1786
|
+
static addHost(name, host) {
|
|
1787
|
+
_GitHost.#gitHosts[name] = host;
|
|
1788
|
+
_GitHost.#gitHosts.byDomain[host.domain] = name;
|
|
1789
|
+
_GitHost.#gitHosts.byShortcut[`${name}:`] = name;
|
|
1790
|
+
_GitHost.#protocols[`${name}:`] = { name };
|
|
1791
|
+
}
|
|
1792
|
+
static fromUrl(giturl, opts) {
|
|
1793
|
+
if (typeof giturl !== "string") {
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
const key = giturl + JSON.stringify(opts || {});
|
|
1797
|
+
if (!cache.has(key)) {
|
|
1798
|
+
const hostArgs = fromUrl(giturl, opts, {
|
|
1799
|
+
gitHosts: _GitHost.#gitHosts,
|
|
1800
|
+
protocols: _GitHost.#protocols
|
|
1801
|
+
});
|
|
1802
|
+
cache.set(key, hostArgs ? new _GitHost(...hostArgs) : void 0);
|
|
1803
|
+
}
|
|
1804
|
+
return cache.get(key);
|
|
1805
|
+
}
|
|
1806
|
+
static fromManifest(manifest, opts = {}) {
|
|
1807
|
+
if (!manifest || typeof manifest !== "object") {
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
const r = manifest.repository;
|
|
1811
|
+
const rurl = r && (typeof r === "string" ? r : typeof r === "object" && typeof r.url === "string" ? r.url : null);
|
|
1812
|
+
if (!rurl) {
|
|
1813
|
+
throw new Error("no repository");
|
|
1814
|
+
}
|
|
1815
|
+
const info = rurl && _GitHost.fromUrl(rurl.replace(/^git\+/, ""), opts) || null;
|
|
1816
|
+
if (info) {
|
|
1817
|
+
return info;
|
|
1818
|
+
}
|
|
1819
|
+
const unk = unknownHostedUrl(rurl);
|
|
1820
|
+
return _GitHost.fromUrl(unk, opts) || unk;
|
|
1821
|
+
}
|
|
1822
|
+
static parseUrl(url) {
|
|
1823
|
+
return parseUrl(url);
|
|
1824
|
+
}
|
|
1825
|
+
#fill(template, opts) {
|
|
1826
|
+
if (typeof template !== "function") {
|
|
1827
|
+
return null;
|
|
1828
|
+
}
|
|
1829
|
+
const options = { ...this, ...this.opts, ...opts };
|
|
1830
|
+
if (!options.path) {
|
|
1831
|
+
options.path = "";
|
|
1832
|
+
}
|
|
1833
|
+
if (options.path.startsWith("/")) {
|
|
1834
|
+
options.path = options.path.slice(1);
|
|
1835
|
+
}
|
|
1836
|
+
if (options.noCommittish) {
|
|
1837
|
+
options.committish = null;
|
|
1838
|
+
}
|
|
1839
|
+
const result = template(options);
|
|
1840
|
+
return options.noGitPlus && result.startsWith("git+") ? result.slice(4) : result;
|
|
1841
|
+
}
|
|
1842
|
+
hash() {
|
|
1843
|
+
return this.committish ? `#${this.committish}` : "";
|
|
1844
|
+
}
|
|
1845
|
+
ssh(opts) {
|
|
1846
|
+
return this.#fill(this.sshtemplate, opts);
|
|
1847
|
+
}
|
|
1848
|
+
sshurl(opts) {
|
|
1849
|
+
return this.#fill(this.sshurltemplate, opts);
|
|
1850
|
+
}
|
|
1851
|
+
browse(path, ...args) {
|
|
1852
|
+
if (typeof path !== "string") {
|
|
1853
|
+
return this.#fill(this.browsetemplate, path);
|
|
1854
|
+
}
|
|
1855
|
+
if (typeof args[0] !== "string") {
|
|
1856
|
+
return this.#fill(this.browsetreetemplate, { ...args[0], path });
|
|
1857
|
+
}
|
|
1858
|
+
return this.#fill(this.browsetreetemplate, { ...args[1], fragment: args[0], path });
|
|
1859
|
+
}
|
|
1860
|
+
// If the path is known to be a file, then browseFile should be used. For some hosts
|
|
1861
|
+
// the url is the same as browse, but for others like GitHub a file can use both `/tree/`
|
|
1862
|
+
// and `/blob/` in the path. When using a default committish of `HEAD` then the `/tree/`
|
|
1863
|
+
// path will redirect to a specific commit. Using the `/blob/` path avoids this and
|
|
1864
|
+
// does not redirect to a different commit.
|
|
1865
|
+
browseFile(path, ...args) {
|
|
1866
|
+
if (typeof args[0] !== "string") {
|
|
1867
|
+
return this.#fill(this.browseblobtemplate, { ...args[0], path });
|
|
1868
|
+
}
|
|
1869
|
+
return this.#fill(this.browseblobtemplate, { ...args[1], fragment: args[0], path });
|
|
1870
|
+
}
|
|
1871
|
+
docs(opts) {
|
|
1872
|
+
return this.#fill(this.docstemplate, opts);
|
|
1873
|
+
}
|
|
1874
|
+
bugs(opts) {
|
|
1875
|
+
return this.#fill(this.bugstemplate, opts);
|
|
1876
|
+
}
|
|
1877
|
+
https(opts) {
|
|
1878
|
+
return this.#fill(this.httpstemplate, opts);
|
|
1879
|
+
}
|
|
1880
|
+
git(opts) {
|
|
1881
|
+
return this.#fill(this.gittemplate, opts);
|
|
1882
|
+
}
|
|
1883
|
+
shortcut(opts) {
|
|
1884
|
+
return this.#fill(this.shortcuttemplate, opts);
|
|
1885
|
+
}
|
|
1886
|
+
path(opts) {
|
|
1887
|
+
return this.#fill(this.pathtemplate, opts);
|
|
1888
|
+
}
|
|
1889
|
+
tarball(opts) {
|
|
1890
|
+
return this.#fill(this.tarballtemplate, { ...opts, noCommittish: false });
|
|
1891
|
+
}
|
|
1892
|
+
file(path, opts) {
|
|
1893
|
+
return this.#fill(this.filetemplate, { ...opts, path });
|
|
1894
|
+
}
|
|
1895
|
+
edit(path, opts) {
|
|
1896
|
+
return this.#fill(this.edittemplate, { ...opts, path });
|
|
1897
|
+
}
|
|
1898
|
+
getDefaultRepresentation() {
|
|
1899
|
+
return this.default;
|
|
1900
|
+
}
|
|
1901
|
+
toString(opts) {
|
|
1902
|
+
if (this.default && typeof this[this.default] === "function") {
|
|
1903
|
+
return this[this.default](opts);
|
|
1904
|
+
}
|
|
1905
|
+
return this.sshurl(opts);
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
for (const [name, host] of Object.entries(hosts)) {
|
|
1909
|
+
GitHost.addHost(name, host);
|
|
1910
|
+
}
|
|
1911
|
+
module.exports = GitHost;
|
|
1912
|
+
}
|
|
1913
|
+
});
|
|
1914
|
+
|
|
1915
|
+
// ../../src/cli-sdk/src/commands/docs.ts
|
|
1916
|
+
var import_hosted_git_info = __toESM(require_lib(), 1);
|
|
1917
|
+
var { fromUrl: hostedGitInfoFromUrl } = import_hosted_git_info.default;
|
|
1918
|
+
var usage = () => commandUsage({
|
|
1919
|
+
command: "docs",
|
|
1920
|
+
usage: ["[<spec>]", "[--target=<query>]"],
|
|
1921
|
+
description: `Open documentation for a package in a web browser.
|
|
1922
|
+
Reads repository information from package.json or fetches
|
|
1923
|
+
manifest data for the specified package.`,
|
|
1924
|
+
options: {
|
|
1925
|
+
target: {
|
|
1926
|
+
value: "<query>",
|
|
1927
|
+
description: "Query selector to filter packages using DSS syntax."
|
|
1928
|
+
}
|
|
1929
|
+
},
|
|
1930
|
+
examples: {
|
|
1931
|
+
"": {
|
|
1932
|
+
description: "Open docs for the current package (reads local package.json)"
|
|
1933
|
+
},
|
|
1934
|
+
"abbrev@2.0.0": {
|
|
1935
|
+
description: "Open docs for a specific package version"
|
|
1936
|
+
},
|
|
1937
|
+
'--target=":root > *"': {
|
|
1938
|
+
description: "List documentation URLs for all direct dependencies"
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
var views = {
|
|
1943
|
+
human: (r) => {
|
|
1944
|
+
if (Array.isArray(r)) {
|
|
1945
|
+
let msg = "Multiple package docs found:\n";
|
|
1946
|
+
msg += r.map((item) => `\u2022 ${item.name}: ${item.url}`).join("\n");
|
|
1947
|
+
return msg;
|
|
1948
|
+
}
|
|
1949
|
+
return "";
|
|
1950
|
+
},
|
|
1951
|
+
json: (r) => r
|
|
1952
|
+
};
|
|
1953
|
+
var getUrlFromManifest = (manifest) => {
|
|
1954
|
+
const { name, homepage, repository } = manifest;
|
|
1955
|
+
if (!name) {
|
|
1956
|
+
throw error("No package name found");
|
|
1957
|
+
}
|
|
1958
|
+
let url;
|
|
1959
|
+
if (homepage) {
|
|
1960
|
+
url = homepage;
|
|
1961
|
+
} else if (repository) {
|
|
1962
|
+
const repoUrl = typeof repository === "string" ? repository : typeof repository === "object" && "url" in repository ? repository.url : (
|
|
1963
|
+
/* c8 ignore next */
|
|
1964
|
+
void 0
|
|
1965
|
+
);
|
|
1966
|
+
if (repoUrl) {
|
|
1967
|
+
const info = hostedGitInfoFromUrl(repoUrl.replace(/^git\+/, ""));
|
|
1968
|
+
if (info && typeof info.docs === "function") {
|
|
1969
|
+
url = info.docs();
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
if (!url) {
|
|
1974
|
+
url = `https://www.npmjs.com/package/${name}`;
|
|
1975
|
+
}
|
|
1976
|
+
return url;
|
|
1977
|
+
};
|
|
1978
|
+
var command = async (conf) => {
|
|
1979
|
+
const { projectRoot, packageJson } = conf.options;
|
|
1980
|
+
const targetOption = conf.get("target");
|
|
1981
|
+
if (targetOption) {
|
|
1982
|
+
const mainManifest = packageJson.maybeRead(projectRoot);
|
|
1983
|
+
if (!mainManifest) {
|
|
1984
|
+
throw error("No package.json found in project root", {
|
|
1985
|
+
path: projectRoot
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
const graph = actual.load({
|
|
1989
|
+
...conf.options,
|
|
1990
|
+
mainManifest,
|
|
1991
|
+
monorepo: conf.options.monorepo,
|
|
1992
|
+
loadManifests: true
|
|
1993
|
+
});
|
|
1994
|
+
const securityArchive = Query.hasSecuritySelectors(targetOption) ? await SecurityArchive.start({
|
|
1995
|
+
nodes: [...graph.nodes.values()]
|
|
1996
|
+
}) : void 0;
|
|
1997
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
1998
|
+
const query = new Query({
|
|
1999
|
+
nodes: new Set(graph.nodes.values()),
|
|
2000
|
+
edges: graph.edges,
|
|
2001
|
+
importers: graph.importers,
|
|
2002
|
+
securityArchive,
|
|
2003
|
+
hostContexts
|
|
2004
|
+
});
|
|
2005
|
+
const { nodes } = await query.search(targetOption, {
|
|
2006
|
+
signal: new AbortController().signal
|
|
2007
|
+
});
|
|
2008
|
+
const results = [];
|
|
2009
|
+
for (const node of nodes) {
|
|
2010
|
+
if (!node.manifest) continue;
|
|
2011
|
+
const url2 = getUrlFromManifest(node.manifest);
|
|
2012
|
+
results.push({
|
|
2013
|
+
url: url2,
|
|
2014
|
+
name: node.name ?? "(unknown)"
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
if (results.length === 0) {
|
|
2018
|
+
throw error("No packages found matching target query", {
|
|
2019
|
+
found: targetOption
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
if (results.length === 1) {
|
|
2023
|
+
const result = results[0];
|
|
2024
|
+
if (!result) {
|
|
2025
|
+
throw error("Unexpected empty result");
|
|
2026
|
+
}
|
|
2027
|
+
await urlOpen(result.url);
|
|
2028
|
+
return result;
|
|
2029
|
+
}
|
|
2030
|
+
return results;
|
|
2031
|
+
}
|
|
2032
|
+
const specArg = conf.positionals[0];
|
|
2033
|
+
const manifest = conf.positionals.length === 0 ? packageJson.read(projectRoot) : specArg ? await new PackageInfoClient(conf.options).manifest(
|
|
2034
|
+
Spec.parseArgs(specArg, conf.options)
|
|
2035
|
+
) : (
|
|
2036
|
+
/* c8 ignore next */
|
|
2037
|
+
packageJson.read(projectRoot)
|
|
2038
|
+
);
|
|
2039
|
+
const url = getUrlFromManifest(manifest);
|
|
2040
|
+
const { name } = manifest;
|
|
2041
|
+
if (!name) {
|
|
2042
|
+
throw error("No package name found");
|
|
2043
|
+
}
|
|
2044
|
+
await urlOpen(url);
|
|
2045
|
+
return { url, name };
|
|
2046
|
+
};
|
|
2047
|
+
export {
|
|
2048
|
+
command,
|
|
2049
|
+
usage,
|
|
2050
|
+
views
|
|
2051
|
+
};
|
|
2052
|
+
//# sourceMappingURL=docs-ZQCCBSMY.js.map
|