@vltpkg/registry-client 0.0.0-0.1730239248325 → 0.0.0-10
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/README.md +57 -54
- package/dist/esm/add-header.d.ts +1 -1
- package/dist/esm/add-header.d.ts.map +1 -1
- package/dist/esm/add-header.js +4 -1
- package/dist/esm/add-header.js.map +1 -1
- package/dist/esm/auth.d.ts +9 -0
- package/dist/esm/auth.d.ts.map +1 -0
- package/dist/esm/auth.js +39 -0
- package/dist/esm/auth.js.map +1 -0
- package/dist/esm/cache-entry.d.ts +62 -14
- package/dist/esm/cache-entry.d.ts.map +1 -1
- package/dist/esm/cache-entry.js +159 -55
- package/dist/esm/cache-entry.js.map +1 -1
- package/dist/esm/cache-revalidate.d.ts +2 -0
- package/dist/esm/cache-revalidate.d.ts.map +1 -0
- package/dist/esm/cache-revalidate.js +66 -0
- package/dist/esm/cache-revalidate.js.map +1 -0
- package/dist/esm/delete-header.d.ts +2 -0
- package/dist/esm/delete-header.d.ts.map +1 -0
- package/dist/esm/delete-header.js +32 -0
- package/dist/esm/delete-header.js.map +1 -0
- package/dist/esm/env.d.ts +0 -4
- package/dist/esm/env.d.ts.map +1 -1
- package/dist/esm/env.js +0 -3
- package/dist/esm/env.js.map +1 -1
- package/dist/esm/get-header.js +1 -1
- package/dist/esm/get-header.js.map +1 -1
- package/dist/esm/handle-304-response.d.ts +2 -2
- package/dist/esm/handle-304-response.d.ts.map +1 -1
- package/dist/esm/handle-304-response.js.map +1 -1
- package/dist/esm/index.d.ts +98 -9
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +265 -69
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/is-iterable.d.ts +2 -0
- package/dist/esm/is-iterable.d.ts.map +1 -0
- package/dist/esm/is-iterable.js +2 -0
- package/dist/esm/is-iterable.js.map +1 -0
- package/dist/esm/otplease.d.ts +4 -0
- package/dist/esm/otplease.d.ts.map +1 -0
- package/dist/esm/otplease.js +55 -0
- package/dist/esm/otplease.js.map +1 -0
- package/dist/esm/raw-header.d.ts +1 -1
- package/dist/esm/raw-header.d.ts.map +1 -1
- package/dist/esm/redirect.d.ts +2 -2
- package/dist/esm/redirect.d.ts.map +1 -1
- package/dist/esm/redirect.js +1 -0
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/revalidate.d.ts +5 -0
- package/dist/esm/revalidate.d.ts.map +1 -0
- package/dist/esm/revalidate.js +49 -0
- package/dist/esm/revalidate.js.map +1 -0
- package/dist/esm/set-cache-headers.d.ts +2 -2
- package/dist/esm/set-cache-headers.d.ts.map +1 -1
- package/dist/esm/set-cache-headers.js +1 -1
- package/dist/esm/set-cache-headers.js.map +1 -1
- package/dist/esm/token-response.d.ts +5 -0
- package/dist/esm/token-response.d.ts.map +1 -0
- package/dist/esm/token-response.js +5 -0
- package/dist/esm/token-response.js.map +1 -0
- package/dist/esm/web-auth-challenge.d.ts +6 -0
- package/dist/esm/web-auth-challenge.d.ts.map +1 -0
- package/dist/esm/web-auth-challenge.js +7 -0
- package/dist/esm/web-auth-challenge.js.map +1 -0
- package/package.json +30 -21
- package/dist/esm/serdes.d.ts +0 -15
- package/dist/esm/serdes.d.ts.map +0 -1
- package/dist/esm/serdes.js +0 -19
- package/dist/esm/serdes.js.map +0 -1
package/dist/esm/cache-entry.js
CHANGED
|
@@ -20,11 +20,10 @@
|
|
|
20
20
|
// of the file.
|
|
21
21
|
import { error } from '@vltpkg/error-cause';
|
|
22
22
|
import ccp from 'cache-control-parser';
|
|
23
|
-
import { createHash } from 'crypto';
|
|
24
|
-
import { inspect } from 'util';
|
|
25
|
-
import { gunzipSync } from 'zlib';
|
|
26
|
-
import { getRawHeader, setRawHeader } from
|
|
27
|
-
import { deserialize, serialize, serializedHeader } from './serdes.js';
|
|
23
|
+
import { createHash } from 'node:crypto';
|
|
24
|
+
import { inspect } from 'node:util';
|
|
25
|
+
import { gunzipSync } from 'node:zlib';
|
|
26
|
+
import { getRawHeader, setRawHeader } from "./raw-header.js";
|
|
28
27
|
const readSize = (buf, offset) => {
|
|
29
28
|
const a = buf[offset];
|
|
30
29
|
const b = buf[offset + 1];
|
|
@@ -52,10 +51,15 @@ export class CacheEntry {
|
|
|
52
51
|
#integrity;
|
|
53
52
|
#integrityActual;
|
|
54
53
|
#json;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
#trustIntegrity;
|
|
55
|
+
#staleWhileRevalidateFactor;
|
|
56
|
+
constructor(statusCode, headers, { integrity, trustIntegrity = false, 'stale-while-revalidate-factor': staleWhileRevalidateFactor = 60, } = {}) {
|
|
58
57
|
this.#headers = headers;
|
|
58
|
+
this.#statusCode = statusCode;
|
|
59
|
+
this.#trustIntegrity = trustIntegrity;
|
|
60
|
+
this.#staleWhileRevalidateFactor = staleWhileRevalidateFactor;
|
|
61
|
+
if (integrity)
|
|
62
|
+
this.integrity = integrity;
|
|
59
63
|
}
|
|
60
64
|
get #headersAsObject() {
|
|
61
65
|
const ret = [];
|
|
@@ -66,39 +70,110 @@ export class CacheEntry {
|
|
|
66
70
|
}
|
|
67
71
|
return ret;
|
|
68
72
|
}
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
73
|
+
toJSON() {
|
|
74
|
+
const { statusCode, valid, staleWhileRevalidate, cacheControl, date, contentType, integrity, maxAge, isGzip, isJSON, } = this;
|
|
75
|
+
/* c8 ignore start */
|
|
76
|
+
const age = date ?
|
|
77
|
+
Math.floor((Date.now() - date.getTime()) / 1000)
|
|
78
|
+
: undefined;
|
|
79
|
+
const expires = date ? new Date(date.getTime() + this.maxAge * 1000) : undefined;
|
|
80
|
+
/* c8 ignore end */
|
|
81
|
+
return Object.fromEntries(Object.entries({
|
|
82
|
+
statusCode,
|
|
72
83
|
headers: this.#headersAsObject,
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
contentType,
|
|
85
|
+
integrity,
|
|
86
|
+
date,
|
|
87
|
+
expires,
|
|
88
|
+
cacheControl,
|
|
89
|
+
valid,
|
|
90
|
+
staleWhileRevalidate,
|
|
91
|
+
age,
|
|
92
|
+
maxAge,
|
|
93
|
+
isGzip,
|
|
94
|
+
isJSON,
|
|
95
|
+
}).filter(([_, v]) => v !== undefined));
|
|
96
|
+
}
|
|
97
|
+
[kCustomInspect](depth, options) {
|
|
98
|
+
const str = inspect(this.toJSON(), {
|
|
99
|
+
depth,
|
|
100
|
+
...options,
|
|
101
|
+
});
|
|
75
102
|
return `@vltpkg/registry-client.CacheEntry ${str}`;
|
|
76
103
|
}
|
|
104
|
+
#date;
|
|
105
|
+
get date() {
|
|
106
|
+
if (this.#date)
|
|
107
|
+
return this.#date;
|
|
108
|
+
const dh = this.getHeader('date')?.toString();
|
|
109
|
+
if (dh)
|
|
110
|
+
this.#date = new Date(dh);
|
|
111
|
+
return this.#date;
|
|
112
|
+
}
|
|
113
|
+
#maxAge;
|
|
114
|
+
get maxAge() {
|
|
115
|
+
if (this.#maxAge !== undefined)
|
|
116
|
+
return this.#maxAge;
|
|
117
|
+
// see if the max-age has not yet been crossed
|
|
118
|
+
// default to 5m if maxage is not set, as some registries
|
|
119
|
+
// do not set a cache control header at all.
|
|
120
|
+
const cc = this.cacheControl;
|
|
121
|
+
this.#maxAge = cc['max-age'] || cc['s-maxage'] || 300;
|
|
122
|
+
return this.#maxAge;
|
|
123
|
+
}
|
|
124
|
+
#cacheControl;
|
|
125
|
+
get cacheControl() {
|
|
126
|
+
if (this.#cacheControl)
|
|
127
|
+
return this.#cacheControl;
|
|
128
|
+
const cc = this.getHeader('cache-control')?.toString();
|
|
129
|
+
this.#cacheControl = cc ? ccp.parse(cc) : {};
|
|
130
|
+
return this.#cacheControl;
|
|
131
|
+
}
|
|
132
|
+
#staleWhileRevalidate;
|
|
133
|
+
get staleWhileRevalidate() {
|
|
134
|
+
if (this.#staleWhileRevalidate !== undefined)
|
|
135
|
+
return this.#staleWhileRevalidate;
|
|
136
|
+
if (this.valid || !this.date)
|
|
137
|
+
return true;
|
|
138
|
+
const swv = this.cacheControl['stale-while-revalidate'] ??
|
|
139
|
+
this.maxAge * this.#staleWhileRevalidateFactor;
|
|
140
|
+
this.#staleWhileRevalidate =
|
|
141
|
+
this.date.getTime() + swv * 1000 > Date.now();
|
|
142
|
+
return this.#staleWhileRevalidate;
|
|
143
|
+
}
|
|
144
|
+
#contentType;
|
|
145
|
+
get contentType() {
|
|
146
|
+
if (this.#contentType !== undefined)
|
|
147
|
+
return this.#contentType;
|
|
148
|
+
this.#contentType =
|
|
149
|
+
this.getHeader('content-type')?.toString() ?? '';
|
|
150
|
+
return this.#contentType;
|
|
151
|
+
}
|
|
77
152
|
/**
|
|
78
153
|
* `true` if the entry represents a cached response that is still
|
|
79
154
|
* valid to use.
|
|
80
155
|
*/
|
|
156
|
+
#valid;
|
|
81
157
|
get valid() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const ct = this.getHeader('content-type')?.toString() ?? '';
|
|
85
|
-
const dh = this.getHeader('date')?.toString();
|
|
158
|
+
if (this.#valid !== undefined)
|
|
159
|
+
return this.#valid;
|
|
86
160
|
// immutable = never changes
|
|
87
|
-
if (
|
|
88
|
-
return true;
|
|
161
|
+
if (this.cacheControl.immutable)
|
|
162
|
+
return (this.#valid = true);
|
|
89
163
|
// some registries do text/json, some do application/json,
|
|
90
164
|
// some do application/vnd.npm.install-v1+json
|
|
91
165
|
// If it's NOT json, it's an immutable tarball
|
|
92
|
-
|
|
93
|
-
|
|
166
|
+
const ct = this.contentType;
|
|
167
|
+
if (ct && !/\bjson\b/.test(ct))
|
|
168
|
+
return (this.#valid = true);
|
|
94
169
|
// see if the max-age has not yet been crossed
|
|
95
170
|
// default to 5m if maxage is not set, as some registries
|
|
96
171
|
// do not set a cache control header at all.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return
|
|
172
|
+
if (!this.date)
|
|
173
|
+
return (this.#valid = false);
|
|
174
|
+
this.#valid =
|
|
175
|
+
this.date.getTime() + this.maxAge * 1000 > Date.now();
|
|
176
|
+
return this.#valid;
|
|
102
177
|
}
|
|
103
178
|
addBody(b) {
|
|
104
179
|
this.#body.push(b);
|
|
@@ -111,18 +186,31 @@ export class CacheEntry {
|
|
|
111
186
|
return this.#headers;
|
|
112
187
|
}
|
|
113
188
|
/**
|
|
114
|
-
*
|
|
189
|
+
* Check that the sri integrity string that was provided to the ctor
|
|
115
190
|
* matches the body that we actually received. This should only be called
|
|
116
191
|
* AFTER the entire body has been completely downloaded.
|
|
117
192
|
*
|
|
193
|
+
* This method **will throw** if the integrity values do not match.
|
|
194
|
+
*
|
|
118
195
|
* Note that this will *usually* not be true if the value is coming out of
|
|
119
196
|
* the cache, because the cache entries are un-gzipped in place. It should
|
|
120
|
-
*
|
|
197
|
+
* _only_ be called for artifacts that come from an actual http response.
|
|
198
|
+
*
|
|
199
|
+
* Returns true if anything was actually verified.
|
|
121
200
|
*/
|
|
122
|
-
checkIntegrity() {
|
|
201
|
+
checkIntegrity(context = {}) {
|
|
123
202
|
if (!this.#integrity)
|
|
124
203
|
return false;
|
|
125
|
-
|
|
204
|
+
if (this.integrityActual !== this.#integrity) {
|
|
205
|
+
throw error('Integrity check failure', {
|
|
206
|
+
code: 'EINTEGRITY',
|
|
207
|
+
response: this,
|
|
208
|
+
wanted: this.#integrity,
|
|
209
|
+
found: this.integrityActual,
|
|
210
|
+
...context,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
126
214
|
}
|
|
127
215
|
get integrityActual() {
|
|
128
216
|
if (this.#integrityActual)
|
|
@@ -130,8 +218,20 @@ export class CacheEntry {
|
|
|
130
218
|
const hash = createHash('sha512');
|
|
131
219
|
for (const buf of this.#body)
|
|
132
220
|
hash.update(buf);
|
|
133
|
-
|
|
134
|
-
|
|
221
|
+
const i = `sha512-${hash.digest('base64')}`;
|
|
222
|
+
this.integrityActual = i;
|
|
223
|
+
return i;
|
|
224
|
+
}
|
|
225
|
+
set integrityActual(i) {
|
|
226
|
+
this.#integrityActual = i;
|
|
227
|
+
this.setHeader('integrity', i);
|
|
228
|
+
}
|
|
229
|
+
set integrity(i) {
|
|
230
|
+
if (!this.#integrity && i) {
|
|
231
|
+
this.#integrity = i;
|
|
232
|
+
if (this.#trustIntegrity)
|
|
233
|
+
this.integrityActual = i;
|
|
234
|
+
}
|
|
135
235
|
}
|
|
136
236
|
get integrity() {
|
|
137
237
|
return this.#integrity;
|
|
@@ -170,13 +270,10 @@ export class CacheEntry {
|
|
|
170
270
|
get isJSON() {
|
|
171
271
|
if (this.#isJSON !== undefined)
|
|
172
272
|
return this.#isJSON;
|
|
173
|
-
const ser = serializedHeader && this.getHeader(serializedHeader);
|
|
174
|
-
if (ser)
|
|
175
|
-
return (this.#isJSON = true);
|
|
176
273
|
const ct = this.getHeader('content-type')?.toString();
|
|
177
274
|
// if it says it's json, assume json
|
|
178
275
|
if (ct)
|
|
179
|
-
return /\bjson\b/.test(ct);
|
|
276
|
+
return (this.#isJSON = /\bjson\b/.test(ct));
|
|
180
277
|
const text = this.text();
|
|
181
278
|
// don't cache, because we might just not have it yet.
|
|
182
279
|
if (!text)
|
|
@@ -244,18 +341,9 @@ export class CacheEntry {
|
|
|
244
341
|
json() {
|
|
245
342
|
if (this.#json !== undefined)
|
|
246
343
|
return this.#json;
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
return (this.#json = deserialize(ser));
|
|
252
|
-
}
|
|
253
|
-
catch { }
|
|
254
|
-
/* c8 ignore stop */
|
|
255
|
-
}
|
|
256
|
-
const obj = JSON.parse(this.text());
|
|
257
|
-
if (serializedHeader)
|
|
258
|
-
this.setHeader(serializedHeader, serialize(obj));
|
|
344
|
+
const text = this.text();
|
|
345
|
+
const obj = JSON.parse(text || '{}');
|
|
346
|
+
this.#json = obj;
|
|
259
347
|
return obj;
|
|
260
348
|
}
|
|
261
349
|
/**
|
|
@@ -265,44 +353,59 @@ export class CacheEntry {
|
|
|
265
353
|
*/
|
|
266
354
|
static decode(buffer) {
|
|
267
355
|
if (buffer.length < 4) {
|
|
268
|
-
return
|
|
356
|
+
return emptyCacheEntry;
|
|
269
357
|
}
|
|
270
358
|
const headSize = readSize(buffer, 0);
|
|
271
359
|
if (buffer.length < headSize) {
|
|
272
|
-
return
|
|
360
|
+
return emptyCacheEntry;
|
|
273
361
|
}
|
|
274
362
|
const statusCode = Number(buffer.subarray(4, 7).toString());
|
|
275
363
|
const headersBuffer = buffer.subarray(7, headSize);
|
|
276
364
|
// walk through the headers array, building up the rawHeaders Buffer[]
|
|
277
365
|
const headers = [];
|
|
278
366
|
let i = 0;
|
|
367
|
+
let integrity = undefined;
|
|
279
368
|
while (i < headersBuffer.length - 4) {
|
|
280
369
|
const size = readSize(headersBuffer, i);
|
|
281
|
-
|
|
370
|
+
const val = headersBuffer.subarray(i + 4, i + size);
|
|
371
|
+
// if the last one was the key integrity, then this one is the value
|
|
372
|
+
if (headers.length % 2 === 1 &&
|
|
373
|
+
String(headers[headers.length - 1]) === 'integrity') {
|
|
374
|
+
integrity = String(val);
|
|
375
|
+
}
|
|
376
|
+
headers.push(val);
|
|
282
377
|
i += size;
|
|
283
378
|
}
|
|
284
|
-
const c = new CacheEntry(statusCode, headers);
|
|
285
379
|
const body = buffer.subarray(headSize);
|
|
380
|
+
const c = new CacheEntry(statusCode, setRawHeader(headers, 'content-length', String(body.byteLength)), {
|
|
381
|
+
integrity,
|
|
382
|
+
trustIntegrity: true,
|
|
383
|
+
});
|
|
286
384
|
c.#body = [body];
|
|
287
385
|
c.#bodyLength = body.byteLength;
|
|
288
|
-
c.setHeader('content-length', String(c.#bodyLength));
|
|
289
386
|
if (c.isJSON) {
|
|
290
387
|
try {
|
|
291
388
|
c.json();
|
|
292
389
|
}
|
|
293
390
|
catch {
|
|
294
|
-
return
|
|
391
|
+
return emptyCacheEntry;
|
|
295
392
|
}
|
|
296
393
|
}
|
|
297
394
|
return c;
|
|
298
395
|
}
|
|
396
|
+
static isGzipEntry(buffer) {
|
|
397
|
+
if (buffer.length < 4)
|
|
398
|
+
return false;
|
|
399
|
+
const headSize = readSize(buffer, 0);
|
|
400
|
+
const gzipBytes = buffer.subarray(headSize, headSize + 2);
|
|
401
|
+
return gzipBytes[0] === 0x1f && gzipBytes[1] === 0x8b;
|
|
402
|
+
}
|
|
299
403
|
/**
|
|
300
404
|
* Encode the entry as a single Buffer for writing to the cache
|
|
301
405
|
*/
|
|
302
406
|
// TODO: should this maybe not concat, and just return Buffer[]?
|
|
303
407
|
// Then we can writev it to the cache file and save the memory copy
|
|
304
408
|
encode() {
|
|
305
|
-
// store json results as a serialized object.
|
|
306
409
|
if (this.isJSON)
|
|
307
410
|
this.json();
|
|
308
411
|
const sb = Buffer.from(String(this.#statusCode));
|
|
@@ -332,4 +435,5 @@ export class CacheEntry {
|
|
|
332
435
|
return Buffer.concat(chunks, headLength + this.#bodyLength);
|
|
333
436
|
}
|
|
334
437
|
}
|
|
438
|
+
const emptyCacheEntry = new CacheEntry(0, []);
|
|
335
439
|
//# sourceMappingURL=cache-entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-entry.js","sourceRoot":"","sources":["../../src/cache-entry.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,4EAA4E;AAC5E,yDAAyD;AACzD,EAAE;AACF,sBAAsB;AACtB,EAAE;AACF,gBAAgB;AAChB,yBAAyB;AACzB,YAAY;AACZ,SAAS;AACT,EAAE;AACF,0EAA0E;AAC1E,+CAA+C;AAC/C,EAAE;AACF,8EAA8E;AAC9E,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,eAAe;AAEf,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,GAAG,MAAM,sBAAsB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA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AAG,CAAC,CAAA;QAClC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;YACnC,MAAM,EAAE,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,CAAA;YAC3B,UAAU,IAAI,EAAE,CAAA;YAChB,KAAK,CAAC,GAAG,CACP;gBACE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;gBACjB,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;gBACjB,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI;gBAChB,EAAE,GAAG,IAAI;aACV,EACD,CAAC,CACF,CAAA;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACvB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QACnC,KAAK,CAAC,GAAG,CACP;YACE,CAAC,UAAU,IAAI,EAAE,CAAC,GAAG,IAAI;YACzB,CAAC,UAAU,IAAI,EAAE,CAAC,GAAG,IAAI;YACzB,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,IAAI;YACxB,UAAU,GAAG,IAAI;SAClB,EACD,CAAC,CACF,CAAA;QACD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACrB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAC7D,CAAC;CACF","sourcesContent":["// A response object in the cache.\n//\n// The cache stores Buffer objects, and it's convenient to have headers/body\n// together, so we have a simple data structure for this.\n//\n// The shape of it is:\n//\n// [head length]\n// <status code in ascii>\n// [headers]\n// [body]\n//\n// The [UInt32BE head length] is 4 bytes specifying the full length of the\n// status code plus all header keys and values.\n//\n// The [headers] section is key/value/key2/value2/... where each key and value\n// is a 4-byte Uint32BE length, followed by that many bytes.\n//\n// From there, the body can be of any indeterminate length, and is the rest\n// of the file.\n\nimport { error } from '@vltpkg/error-cause'\nimport { Integrity, JSONField } from '@vltpkg/types'\nimport ccp from 'cache-control-parser'\nimport { createHash } from 'crypto'\nimport { inspect } from 'util'\nimport { gunzipSync } from 'zlib'\nimport { getRawHeader, setRawHeader } from './raw-header.js'\nimport { deserialize, serialize, serializedHeader } from './serdes.js'\n\nconst readSize = (buf: Buffer, offset: number) => {\n const a = buf[offset]\n const b = buf[offset + 1]\n const c = buf[offset + 2]\n const d = buf[offset + 3]\n\n // not possible, we check the length\n /* c8 ignore start */\n if (\n a === undefined ||\n b === undefined ||\n c === undefined ||\n d === undefined\n ) {\n throw error('Invalid buffer, not long enough to readSize', {\n found: buf.length,\n })\n }\n /* c8 ignore stop */\n\n return (a << 24) | (b << 16) | (c << 8) | d\n}\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport class CacheEntry {\n #statusCode: number\n #headers: Buffer[]\n #body: Buffer[] = []\n #bodyLength = 0\n #integrity?: Integrity\n #integrityActual?: Integrity\n #json?: Record<string, JSONField>\n\n constructor(\n statusCode: number,\n headers: Buffer[],\n integrity?: Integrity,\n ) {\n this.#integrity = integrity\n this.#statusCode = statusCode\n this.#headers = headers\n }\n\n get #headersAsObject(): [string, string][] {\n const ret: [string, string][] = []\n for (let i = 0; i < this.#headers.length - 1; i += 2) {\n const key = String(this.#headers[i])\n const val = String(this.#headers[i + 1])\n ret.push([key, val])\n }\n return ret\n }\n\n [kCustomInspect](...args: any[]): string {\n const str = inspect(\n {\n statusCode: this.statusCode,\n headers: this.#headersAsObject,\n text: this.text(),\n },\n ...args,\n )\n return `@vltpkg/registry-client.CacheEntry ${str}`\n }\n\n /**\n * `true` if the entry represents a cached response that is still\n * valid to use.\n */\n get valid(): boolean {\n const cc_ = this.getHeader('cache-control')?.toString()\n const cc = cc_ ? ccp.parse(cc_) : {}\n const ct = this.getHeader('content-type')?.toString() ?? ''\n const dh = this.getHeader('date')?.toString()\n\n // immutable = never changes\n if (cc.immutable) return true\n\n // some registries do text/json, some do application/json,\n // some do application/vnd.npm.install-v1+json\n // If it's NOT json, it's an immutable tarball\n if (ct !== '' && !/\\bjson\\b/.test(ct)) return true\n\n // see if the max-age has not yet been crossed\n // default to 5m if maxage is not set, as some registries\n // do not set a cache control header at all.\n const ma = cc['max-age'] || cc['s-maxage'] || 300\n if (ma && dh) {\n return Date.parse(dh) + ma * 1000 > Date.now()\n }\n return false\n }\n\n addBody(b: Buffer) {\n this.#body.push(b)\n this.#bodyLength += b.byteLength\n }\n\n get statusCode() {\n return this.#statusCode\n }\n get headers() {\n return this.#headers\n }\n\n /**\n * check that the sri integrity string that was provided to the ctor\n * matches the body that we actually received. This should only be called\n * AFTER the entire body has been completely downloaded.\n *\n * Note that this will *usually* not be true if the value is coming out of\n * the cache, because the cache entries are un-gzipped in place. It should\n * *only* be called for artifacts that come from an actual http response.\n */\n checkIntegrity(): boolean {\n if (!this.#integrity) return false\n return this.integrityActual === this.#integrity\n }\n get integrityActual(): Integrity {\n if (this.#integrityActual) return this.#integrityActual\n const hash = createHash('sha512')\n for (const buf of this.#body) hash.update(buf)\n this.#integrityActual = `sha512-${hash.digest('base64')}`\n return this.#integrityActual\n }\n get integrity() {\n return this.#integrity\n }\n\n /**\n * Give it a key, and it'll return the buffer of that header value\n */\n getHeader(h: string) {\n return getRawHeader(this.#headers, h)\n }\n\n /**\n * Set a header to a specific value\n */\n setHeader(h: string, value: Buffer | string) {\n this.#headers = setRawHeader(this.#headers, h, value)\n }\n\n /**\n * Return the body of the entry as a Buffer\n */\n buffer(): Buffer {\n const b = this.#body[0]\n if (!b) return Buffer.allocUnsafe(0)\n if (this.#body.length === 1) return b\n const cat = Buffer.concat(this.#body, this.#bodyLength)\n this.#body = [cat]\n return cat\n }\n\n // return the buffer if it's a tarball, or the parsed\n // JSON if it's not.\n get body(): Buffer | Record<string, any> {\n return this.isJSON ? this.json() : this.buffer()\n }\n\n #isJSON?: boolean\n get isJSON(): boolean {\n if (this.#isJSON !== undefined) return this.#isJSON\n const ser = serializedHeader && this.getHeader(serializedHeader)\n if (ser) return (this.#isJSON = true)\n const ct = this.getHeader('content-type')?.toString()\n // if it says it's json, assume json\n if (ct) return /\\bjson\\b/.test(ct)\n const text = this.text()\n // don't cache, because we might just not have it yet.\n if (!text) return false\n // all registry json starts with {, and no tarball ever can.\n this.#isJSON = text.startsWith('{')\n if (this.#isJSON) this.setHeader('content-type', 'text/json')\n return this.#isJSON\n }\n\n #isGzip?: boolean\n get isGzip(): boolean {\n if (this.#isGzip !== undefined) return this.#isGzip\n const ce = this.getHeader('content-encoding')?.toString()\n if (ce && !/\\bgzip\\b/.test(ce)) return (this.#isGzip = false)\n const buf = this.buffer()\n if (buf.length < 2) return false\n this.#isGzip = buf[0] === 0x1f && buf[1] === 0x8b\n if (this.#isGzip) {\n this.setHeader('content-encoding', 'gzip')\n } else {\n this.setHeader('content-encoding', 'identity')\n this.setHeader('content-length', String(this.#bodyLength))\n }\n return this.#isGzip\n }\n\n /**\n * Un-gzip encode the body.\n * Returns true if it was previously gzip (so something was done), otherwise\n * returns false.\n */\n unzip() {\n if (this.isGzip) {\n // we know that if we know it's gzip, that the body has been\n // flattened to a single buffer, so save the extra call.\n /* c8 ignore start */\n if (this.#body[0] == null)\n throw error('Invalid buffer, cant unzip')\n /* c8 ignore stop */\n const b = gunzipSync(this.#body[0])\n this.setHeader('content-encoding', 'identity')\n this.#body = [b]\n this.#bodyLength = b.byteLength\n this.setHeader('content-length', String(this.#bodyLength))\n this.#isGzip = false\n return true\n }\n return false\n }\n\n /**\n * Return the body of the entry as utf8 text\n * Automatically unzips if the content is gzip encoded\n */\n text() {\n this.unzip()\n return this.buffer().toString()\n }\n\n /**\n * Parse the entry body as JSON and return the result\n */\n json(): Record<string, JSONField> {\n if (this.#json !== undefined) return this.#json\n const ser = serializedHeader && this.getHeader(serializedHeader)\n if (ser) {\n /* c8 ignore start - very rare, but theoretically possible to throw */\n try {\n return (this.#json = deserialize(ser))\n } catch {}\n /* c8 ignore stop */\n }\n const obj = JSON.parse(this.text())\n if (serializedHeader)\n this.setHeader(serializedHeader, serialize(obj))\n return obj\n }\n\n /**\n * Pass the contents of a @vltpkg/cache.Cache object as a buffer,\n * and this static method will decode it into a CacheEntry representing\n * the cached response.\n */\n static decode(buffer: Buffer): CacheEntry {\n if (buffer.length < 4) {\n return new CacheEntry(0, [])\n }\n const headSize = readSize(buffer, 0)\n if (buffer.length < headSize) {\n return new CacheEntry(0, [])\n }\n const statusCode = Number(buffer.subarray(4, 7).toString())\n const headersBuffer = buffer.subarray(7, headSize)\n // walk through the headers array, building up the rawHeaders Buffer[]\n const headers: Buffer[] = []\n let i = 0\n while (i < headersBuffer.length - 4) {\n const size = readSize(headersBuffer, i)\n headers.push(headersBuffer.subarray(i + 4, i + size))\n i += size\n }\n const c = new CacheEntry(statusCode, headers)\n const body = buffer.subarray(headSize)\n c.#body = [body]\n c.#bodyLength = body.byteLength\n c.setHeader('content-length', String(c.#bodyLength))\n if (c.isJSON) {\n try {\n c.json()\n } catch {\n return new CacheEntry(0, [])\n }\n }\n return c\n }\n\n /**\n * Encode the entry as a single Buffer for writing to the cache\n */\n // TODO: should this maybe not concat, and just return Buffer[]?\n // Then we can writev it to the cache file and save the memory copy\n encode(): Buffer {\n // store json results as a serialized object.\n if (this.isJSON) this.json()\n const sb = Buffer.from(String(this.#statusCode))\n const chunks: Buffer[] = [sb]\n let headLength = sb.byteLength + 4\n for (const h of this.#headers) {\n const hlBuf = Buffer.allocUnsafe(4)\n const hl = h.byteLength + 4\n headLength += hl\n hlBuf.set(\n [\n (hl >> 24) & 0xff,\n (hl >> 16) & 0xff,\n (hl >> 8) & 0xff,\n hl & 0xff,\n ],\n 0,\n )\n chunks.push(hlBuf, h)\n }\n\n const hlBuf = Buffer.allocUnsafe(4)\n hlBuf.set(\n [\n (headLength >> 24) & 0xff,\n (headLength >> 16) & 0xff,\n (headLength >> 8) & 0xff,\n headLength & 0xff,\n ],\n 0,\n )\n chunks.unshift(hlBuf)\n chunks.push(...this.#body)\n return Buffer.concat(chunks, headLength + this.#bodyLength)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cache-entry.js","sourceRoot":"","sources":["../../src/cache-entry.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,4EAA4E;AAC5E,yDAAyD;AACzD,EAAE;AACF,sBAAsB;AACtB,EAAE;AACF,gBAAgB;AAChB,yBAAyB;AACzB,YAAY;AACZ,SAAS;AACT,EAAE;AACF,0EAA0E;AAC1E,+CAA+C;AAC/C,EAAE;AACF,8EAA8E;AAC9E,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,eAAe;AAGf,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,GAAG,MAAM,sBAAsB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAI5D,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE;IAC/C,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;IACrB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEzB,oCAAoC;IACpC,qBAAqB;IACrB,IACE,CAAC,KAAK,SAAS;QACf,CAAC,KAAK,SAAS;QACf,CAAC,K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ACD,CAAC,CACF,CAAA;QACD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACrB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAC7D,CAAC;CACF;AAED,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA","sourcesContent":["// A response object in the cache.\n//\n// The cache stores Buffer objects, and it's convenient to have headers/body\n// together, so we have a simple data structure for this.\n//\n// The shape of it is:\n//\n// [head length]\n// <status code in ascii>\n// [headers]\n// [body]\n//\n// The [UInt32BE head length] is 4 bytes specifying the full length of the\n// status code plus all header keys and values.\n//\n// The [headers] section is key/value/key2/value2/... where each key and value\n// is a 4-byte Uint32BE length, followed by that many bytes.\n//\n// From there, the body can be of any indeterminate length, and is the rest\n// of the file.\n\nimport type { ErrorCauseOptions } from '@vltpkg/error-cause'\nimport { error } from '@vltpkg/error-cause'\nimport type { Integrity, JSONField } from '@vltpkg/types'\nimport ccp from 'cache-control-parser'\nimport { createHash } from 'node:crypto'\nimport type { InspectOptions } from 'node:util'\nimport { inspect } from 'node:util'\nimport { gunzipSync } from 'node:zlib'\nimport { getRawHeader, setRawHeader } from './raw-header.ts'\n\nexport type JSONObj = Record<string, JSONField>\n\nconst readSize = (buf: Buffer, offset: number) => {\n const a = buf[offset]\n const b = buf[offset + 1]\n const c = buf[offset + 2]\n const d = buf[offset + 3]\n\n // not possible, we check the length\n /* c8 ignore start */\n if (\n a === undefined ||\n b === undefined ||\n c === undefined ||\n d === undefined\n ) {\n throw error('Invalid buffer, not long enough to readSize', {\n found: buf.length,\n })\n }\n /* c8 ignore stop */\n\n return (a << 24) | (b << 16) | (c << 8) | d\n}\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport type CacheEntryOptions = {\n /**\n * The expected integrity value for this response body\n */\n integrity?: Integrity\n /**\n * Whether to trust the integrity, or calculate the actual value.\n *\n * This indicates that we just accept whatever the integrity is as the actual\n * integrity for saving back to the cache, because it's coming directly from\n * the registry that we fetched a packument from, and is an initial gzipped\n * artifact request.\n */\n trustIntegrity?: boolean\n\n /**\n * If the server does not serve a `stale-while-revalidate` value in the\n * `cache-control` header, then this multiplier is applied to the `max-age`\n * or `s-maxage` values.\n *\n * By default, this is `60`, so for example a response that is cacheable for\n * 5 minutes will allow a stale response while revalidating for up to 5\n * hours.\n *\n * If the server *does* provide a `stale-while-revalidate` value, then that\n * is always used.\n *\n * Set to 0 to prevent any `stale-while-revalidate` behavior unless\n * explicitly allowed by the server's `cache-control` header.\n */\n 'stale-while-revalidate-factor'?: number\n}\n\nexport class CacheEntry {\n #statusCode: number\n #headers: Buffer[]\n #body: Buffer[] = []\n #bodyLength = 0\n #integrity?: Integrity\n #integrityActual?: Integrity\n #json?: JSONObj\n #trustIntegrity\n #staleWhileRevalidateFactor\n\n constructor(\n statusCode: number,\n headers: Buffer[],\n {\n integrity,\n trustIntegrity = false,\n 'stale-while-revalidate-factor':\n staleWhileRevalidateFactor = 60,\n }: CacheEntryOptions = {},\n ) {\n this.#headers = headers\n this.#statusCode = statusCode\n this.#trustIntegrity = trustIntegrity\n this.#staleWhileRevalidateFactor = staleWhileRevalidateFactor\n if (integrity) this.integrity = integrity\n }\n\n get #headersAsObject(): [string, string][] {\n const ret: [string, string][] = []\n for (let i = 0; i < this.#headers.length - 1; i += 2) {\n const key = String(this.#headers[i])\n const val = String(this.#headers[i + 1])\n ret.push([key, val])\n }\n return ret\n }\n\n toJSON() {\n const {\n statusCode,\n valid,\n staleWhileRevalidate,\n cacheControl,\n date,\n contentType,\n integrity,\n maxAge,\n isGzip,\n isJSON,\n } = this\n /* c8 ignore start */\n const age =\n date ?\n Math.floor((Date.now() - date.getTime()) / 1000)\n : undefined\n const expires =\n date ? new Date(date.getTime() + this.maxAge * 1000) : undefined\n /* c8 ignore end */\n return Object.fromEntries(\n Object.entries({\n statusCode,\n headers: this.#headersAsObject,\n contentType,\n integrity,\n date,\n expires,\n cacheControl,\n valid,\n staleWhileRevalidate,\n age,\n maxAge,\n isGzip,\n isJSON,\n }).filter(([_, v]) => v !== undefined),\n )\n }\n\n [kCustomInspect](depth: number, options: InspectOptions): string {\n const str = inspect(this.toJSON(), {\n depth,\n ...options,\n })\n return `@vltpkg/registry-client.CacheEntry ${str}`\n }\n\n #date?: Date\n get date(): Date | undefined {\n if (this.#date) return this.#date\n const dh = this.getHeader('date')?.toString()\n if (dh) this.#date = new Date(dh)\n return this.#date\n }\n\n #maxAge?: number\n get maxAge(): number {\n if (this.#maxAge !== undefined) return this.#maxAge\n // see if the max-age has not yet been crossed\n // default to 5m if maxage is not set, as some registries\n // do not set a cache control header at all.\n const cc = this.cacheControl\n this.#maxAge = cc['max-age'] || cc['s-maxage'] || 300\n return this.#maxAge\n }\n\n #cacheControl?: ccp.CacheControl\n get cacheControl(): ccp.CacheControl {\n if (this.#cacheControl) return this.#cacheControl\n const cc = this.getHeader('cache-control')?.toString()\n this.#cacheControl = cc ? ccp.parse(cc) : {}\n return this.#cacheControl\n }\n\n #staleWhileRevalidate?: boolean\n get staleWhileRevalidate(): boolean {\n if (this.#staleWhileRevalidate !== undefined)\n return this.#staleWhileRevalidate\n if (this.valid || !this.date) return true\n const swv =\n this.cacheControl['stale-while-revalidate'] ??\n this.maxAge * this.#staleWhileRevalidateFactor\n\n this.#staleWhileRevalidate =\n this.date.getTime() + swv * 1000 > Date.now()\n return this.#staleWhileRevalidate\n }\n\n #contentType?: string\n get contentType() {\n if (this.#contentType !== undefined) return this.#contentType\n this.#contentType =\n this.getHeader('content-type')?.toString() ?? ''\n return this.#contentType\n }\n\n /**\n * `true` if the entry represents a cached response that is still\n * valid to use.\n */\n #valid?: boolean\n get valid(): boolean {\n if (this.#valid !== undefined) return this.#valid\n\n // immutable = never changes\n if (this.cacheControl.immutable) return (this.#valid = true)\n\n // some registries do text/json, some do application/json,\n // some do application/vnd.npm.install-v1+json\n // If it's NOT json, it's an immutable tarball\n const ct = this.contentType\n if (ct && !/\\bjson\\b/.test(ct)) return (this.#valid = true)\n\n // see if the max-age has not yet been crossed\n // default to 5m if maxage is not set, as some registries\n // do not set a cache control header at all.\n if (!this.date) return (this.#valid = false)\n this.#valid =\n this.date.getTime() + this.maxAge * 1000 > Date.now()\n return this.#valid\n }\n\n addBody(b: Buffer) {\n this.#body.push(b)\n this.#bodyLength += b.byteLength\n }\n\n get statusCode() {\n return this.#statusCode\n }\n get headers() {\n return this.#headers\n }\n\n /**\n * Check that the sri integrity string that was provided to the ctor\n * matches the body that we actually received. This should only be called\n * AFTER the entire body has been completely downloaded.\n *\n * This method **will throw** if the integrity values do not match.\n *\n * Note that this will *usually* not be true if the value is coming out of\n * the cache, because the cache entries are un-gzipped in place. It should\n * _only_ be called for artifacts that come from an actual http response.\n *\n * Returns true if anything was actually verified.\n */\n checkIntegrity(\n context: ErrorCauseOptions = {},\n ): this is CacheEntry & { integrity: Integrity } {\n if (!this.#integrity) return false\n if (this.integrityActual !== this.#integrity) {\n throw error('Integrity check failure', {\n code: 'EINTEGRITY',\n response: this,\n wanted: this.#integrity,\n found: this.integrityActual,\n ...context,\n })\n }\n return true\n }\n\n get integrityActual(): Integrity {\n if (this.#integrityActual) return this.#integrityActual\n const hash = createHash('sha512')\n for (const buf of this.#body) hash.update(buf)\n const i: Integrity = `sha512-${hash.digest('base64')}`\n this.integrityActual = i\n return i\n }\n\n set integrityActual(i: Integrity) {\n this.#integrityActual = i\n this.setHeader('integrity', i)\n }\n\n set integrity(i: Integrity | undefined) {\n if (!this.#integrity && i) {\n this.#integrity = i\n if (this.#trustIntegrity) this.integrityActual = i\n }\n }\n get integrity() {\n return this.#integrity\n }\n\n /**\n * Give it a key, and it'll return the buffer of that header value\n */\n getHeader(h: string) {\n return getRawHeader(this.#headers, h)\n }\n\n /**\n * Set a header to a specific value\n */\n setHeader(h: string, value: Buffer | string) {\n this.#headers = setRawHeader(this.#headers, h, value)\n }\n\n /**\n * Return the body of the entry as a Buffer\n */\n buffer(): Buffer {\n const b = this.#body[0]\n if (!b) return Buffer.allocUnsafe(0)\n if (this.#body.length === 1) return b\n const cat = Buffer.concat(this.#body, this.#bodyLength)\n this.#body = [cat]\n return cat\n }\n\n // return the buffer if it's a tarball, or the parsed\n // JSON if it's not.\n get body(): Buffer | Record<string, any> {\n return this.isJSON ? this.json() : this.buffer()\n }\n\n #isJSON?: boolean\n get isJSON(): boolean {\n if (this.#isJSON !== undefined) return this.#isJSON\n const ct = this.getHeader('content-type')?.toString()\n // if it says it's json, assume json\n if (ct) return (this.#isJSON = /\\bjson\\b/.test(ct))\n const text = this.text()\n // don't cache, because we might just not have it yet.\n if (!text) return false\n // all registry json starts with {, and no tarball ever can.\n this.#isJSON = text.startsWith('{')\n if (this.#isJSON) this.setHeader('content-type', 'text/json')\n return this.#isJSON\n }\n\n #isGzip?: boolean\n get isGzip(): boolean {\n if (this.#isGzip !== undefined) return this.#isGzip\n const ce = this.getHeader('content-encoding')?.toString()\n if (ce && !/\\bgzip\\b/.test(ce)) return (this.#isGzip = false)\n const buf = this.buffer()\n if (buf.length < 2) return false\n this.#isGzip = buf[0] === 0x1f && buf[1] === 0x8b\n if (this.#isGzip) {\n this.setHeader('content-encoding', 'gzip')\n } else {\n this.setHeader('content-encoding', 'identity')\n this.setHeader('content-length', String(this.#bodyLength))\n }\n return this.#isGzip\n }\n\n /**\n * Un-gzip encode the body.\n * Returns true if it was previously gzip (so something was done), otherwise\n * returns false.\n */\n unzip() {\n if (this.isGzip) {\n // we know that if we know it's gzip, that the body has been\n // flattened to a single buffer, so save the extra call.\n /* c8 ignore start */\n if (this.#body[0] == null)\n throw error('Invalid buffer, cant unzip')\n /* c8 ignore stop */\n const b = gunzipSync(this.#body[0])\n this.setHeader('content-encoding', 'identity')\n this.#body = [b]\n this.#bodyLength = b.byteLength\n this.setHeader('content-length', String(this.#bodyLength))\n this.#isGzip = false\n return true\n }\n return false\n }\n\n /**\n * Return the body of the entry as utf8 text\n * Automatically unzips if the content is gzip encoded\n */\n text() {\n this.unzip()\n return this.buffer().toString()\n }\n\n /**\n * Parse the entry body as JSON and return the result\n */\n json(): JSONObj {\n if (this.#json !== undefined) return this.#json\n const text = this.text()\n const obj = JSON.parse(text || '{}') as JSONObj\n this.#json = obj\n return obj\n }\n\n /**\n * Pass the contents of a @vltpkg/cache.Cache object as a buffer,\n * and this static method will decode it into a CacheEntry representing\n * the cached response.\n */\n static decode(buffer: Buffer): CacheEntry {\n if (buffer.length < 4) {\n return emptyCacheEntry\n }\n const headSize = readSize(buffer, 0)\n if (buffer.length < headSize) {\n return emptyCacheEntry\n }\n const statusCode = Number(buffer.subarray(4, 7).toString())\n const headersBuffer = buffer.subarray(7, headSize)\n // walk through the headers array, building up the rawHeaders Buffer[]\n const headers: Buffer[] = []\n let i = 0\n let integrity: Integrity | undefined = undefined\n while (i < headersBuffer.length - 4) {\n const size = readSize(headersBuffer, i)\n const val = headersBuffer.subarray(i + 4, i + size)\n // if the last one was the key integrity, then this one is the value\n if (\n headers.length % 2 === 1 &&\n String(headers[headers.length - 1]) === 'integrity'\n ) {\n integrity = String(val) as Integrity\n }\n headers.push(val)\n i += size\n }\n const body = buffer.subarray(headSize)\n\n const c = new CacheEntry(\n statusCode,\n setRawHeader(\n headers,\n 'content-length',\n String(body.byteLength),\n ),\n {\n integrity,\n trustIntegrity: true,\n },\n )\n\n c.#body = [body]\n c.#bodyLength = body.byteLength\n if (c.isJSON) {\n try {\n c.json()\n } catch {\n return emptyCacheEntry\n }\n }\n return c\n }\n\n static isGzipEntry(buffer: Buffer): boolean {\n if (buffer.length < 4) return false\n const headSize = readSize(buffer, 0)\n const gzipBytes = buffer.subarray(headSize, headSize + 2)\n return gzipBytes[0] === 0x1f && gzipBytes[1] === 0x8b\n }\n\n /**\n * Encode the entry as a single Buffer for writing to the cache\n */\n // TODO: should this maybe not concat, and just return Buffer[]?\n // Then we can writev it to the cache file and save the memory copy\n encode(): Buffer {\n if (this.isJSON) this.json()\n const sb = Buffer.from(String(this.#statusCode))\n const chunks: Buffer[] = [sb]\n let headLength = sb.byteLength + 4\n for (const h of this.#headers) {\n const hlBuf = Buffer.allocUnsafe(4)\n const hl = h.byteLength + 4\n headLength += hl\n hlBuf.set(\n [\n (hl >> 24) & 0xff,\n (hl >> 16) & 0xff,\n (hl >> 8) & 0xff,\n hl & 0xff,\n ],\n 0,\n )\n chunks.push(hlBuf, h)\n }\n\n const hlBuf = Buffer.allocUnsafe(4)\n hlBuf.set(\n [\n (headLength >> 24) & 0xff,\n (headLength >> 16) & 0xff,\n (headLength >> 8) & 0xff,\n headLength & 0xff,\n ],\n 0,\n )\n chunks.unshift(hlBuf)\n chunks.push(...this.#body)\n return Buffer.concat(chunks, headLength + this.#bodyLength)\n }\n}\n\nconst emptyCacheEntry = new CacheEntry(0, [])\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-revalidate.d.ts","sourceRoot":"","sources":["../../src/cache-revalidate.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ,SACb,MAAM,UACJ,MAAM,GAAG,KAAK,OACjB,MAAM,GAAG,GAAG,KAChB,IASF,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { __CODE_SPLIT_SCRIPT_NAME } from "./revalidate.js";
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
const isDeno = globalThis.Deno != undefined;
|
|
5
|
+
let didProcessBeforeExitHook = false;
|
|
6
|
+
const registered = new Map();
|
|
7
|
+
export const register = (path, method, url) => {
|
|
8
|
+
const r = registered.get(path) ?? new Set();
|
|
9
|
+
const key = `${method} ${url}`;
|
|
10
|
+
r.add(key);
|
|
11
|
+
registered.set(path, r);
|
|
12
|
+
if (!didProcessBeforeExitHook) {
|
|
13
|
+
didProcessBeforeExitHook = true;
|
|
14
|
+
process.on('beforeExit', handleBeforeExit);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const handleBeforeExit = () => {
|
|
18
|
+
for (const [path, r] of registered) {
|
|
19
|
+
/* c8 ignore next */
|
|
20
|
+
if (!r.size)
|
|
21
|
+
return;
|
|
22
|
+
const env = { ...process.env };
|
|
23
|
+
const args = [];
|
|
24
|
+
/* c8 ignore start */
|
|
25
|
+
// When compiled the script to be run is passed as an
|
|
26
|
+
// environment variable and then routed by the main entry point
|
|
27
|
+
if (process.env.__VLT_INTERNAL_COMPILED) {
|
|
28
|
+
env.__VLT_INTERNAL_MAIN = pathToFileURL(__CODE_SPLIT_SCRIPT_NAME).toString();
|
|
29
|
+
args.push(path);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// If we are running deno from source we need to add the
|
|
33
|
+
// unstable flags we need. The '-A' flag does not need
|
|
34
|
+
// to be passed in as Deno supplies that automatically.
|
|
35
|
+
if (isDeno) {
|
|
36
|
+
args.push('--unstable-node-globals', '--unstable-bare-node-builtins');
|
|
37
|
+
}
|
|
38
|
+
/* c8 ignore stop */
|
|
39
|
+
args.push(__CODE_SPLIT_SCRIPT_NAME, path);
|
|
40
|
+
}
|
|
41
|
+
registered.delete(path);
|
|
42
|
+
// Deno on Windows does not support detached processes
|
|
43
|
+
// https://github.com/denoland/deno/issues/25867
|
|
44
|
+
// TODO: figure out something better to do here?
|
|
45
|
+
/* c8 ignore next */
|
|
46
|
+
const detached = !(isDeno && process.platform === 'win32');
|
|
47
|
+
const proc = spawn(process.execPath, args, {
|
|
48
|
+
detached,
|
|
49
|
+
stdio: ['pipe', 'ignore', 'ignore'],
|
|
50
|
+
env,
|
|
51
|
+
});
|
|
52
|
+
for (const key of r) {
|
|
53
|
+
proc.stdin.write(`${key}\0`);
|
|
54
|
+
}
|
|
55
|
+
proc.stdin.end();
|
|
56
|
+
// Another Deno oddity. Calling unref on a spawned process will kill the
|
|
57
|
+
// process unless it is detached. https://github.com/denoland/deno/issues/21446
|
|
58
|
+
// So in this case Deno on Windows will be slower to exit the main process
|
|
59
|
+
// since it will wait for the child process to exit.
|
|
60
|
+
// TODO: figure out something better to do here?
|
|
61
|
+
if (detached) {
|
|
62
|
+
proc.unref();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=cache-revalidate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-revalidate.js","sourceRoot":"","sources":["../../src/cache-revalidate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,MAAM,GACT,UAAiD,CAAC,IAAI,IAAI,SAAS,CAAA;AAEtE,IAAI,wBAAwB,GAAG,KAAK,CAAA;AACpC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAA;AAEjD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAY,EACZ,MAAsB,EACtB,GAAiB,EACX,EAAE;IACR,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAU,CAAA;IACnD,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,GAAG,EAAE,CAAA;IAC9B,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACV,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACvB,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,wBAAwB,GAAG,IAAI,CAAA;QAC/B,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAA;IAC5C,CAAC;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,GAAG,EAAE;IAC5B,KAAK,MAAM,CAAC,IA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AK,CAAC,GAAG,EAAE,CAAA;QAChB,wEAAwE;QACxE,+EAA+E;QAC/E,0EAA0E;QAC1E,oDAAoD;QACpD,gDAAgD;QAChD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,EAAE,CAAA;QACd,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { spawn } from 'node:child_process'\nimport { __CODE_SPLIT_SCRIPT_NAME } from './revalidate.ts'\nimport { pathToFileURL } from 'node:url'\n\nconst isDeno =\n (globalThis as typeof globalThis & { Deno?: any }).Deno != undefined\n\nlet didProcessBeforeExitHook = false\nconst registered = new Map<string, Set<string>>()\n\nexport const register = (\n path: string,\n method: 'HEAD' | 'GET',\n url: string | URL,\n): void => {\n const r = registered.get(path) ?? new Set<string>()\n const key = `${method} ${url}`\n r.add(key)\n registered.set(path, r)\n if (!didProcessBeforeExitHook) {\n didProcessBeforeExitHook = true\n process.on('beforeExit', handleBeforeExit)\n }\n}\n\nconst handleBeforeExit = () => {\n for (const [path, r] of registered) {\n /* c8 ignore next */\n if (!r.size) return\n const env = { ...process.env }\n const args = []\n /* c8 ignore start */\n // When compiled the script to be run is passed as an\n // environment variable and then routed by the main entry point\n if (process.env.__VLT_INTERNAL_COMPILED) {\n env.__VLT_INTERNAL_MAIN = pathToFileURL(\n __CODE_SPLIT_SCRIPT_NAME,\n ).toString()\n args.push(path)\n } else {\n // If we are running deno from source we need to add the\n // unstable flags we need. The '-A' flag does not need\n // to be passed in as Deno supplies that automatically.\n if (isDeno) {\n args.push(\n '--unstable-node-globals',\n '--unstable-bare-node-builtins',\n )\n }\n /* c8 ignore stop */\n args.push(__CODE_SPLIT_SCRIPT_NAME, path)\n }\n registered.delete(path)\n // Deno on Windows does not support detached processes\n // https://github.com/denoland/deno/issues/25867\n // TODO: figure out something better to do here?\n /* c8 ignore next */\n const detached = !(isDeno && process.platform === 'win32')\n const proc = spawn(process.execPath, args, {\n detached,\n stdio: ['pipe', 'ignore', 'ignore'],\n env,\n })\n for (const key of r) {\n proc.stdin.write(`${key}\\0`)\n }\n proc.stdin.end()\n // Another Deno oddity. Calling unref on a spawned process will kill the\n // process unless it is detached. https://github.com/denoland/deno/issues/21446\n // So in this case Deno on Windows will be slower to exit the main process\n // since it will wait for the child process to exit.\n // TODO: figure out something better to do here?\n if (detached) {\n proc.unref()\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const deleteHeader: <H extends [string, string[] | string][] | Iterable<[string, string[] | string | undefined]> | Record<string, string[] | string | undefined> | string[]>(headers: H | null | undefined, key: string) => H;
|
|
2
|
+
//# sourceMappingURL=delete-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-header.d.ts","sourceRoot":"","sources":["../../src/delete-header.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,GACvB,CAAC,SACG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,GAC7B,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,GACjD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,GAC7C,MAAM,EAAE,WAEH,CAAC,GAAG,IAAI,GAAG,SAAS,OACxB,MAAM,KACV,CA2BF,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isIterable } from "./is-iterable.js";
|
|
2
|
+
export const deleteHeader = (headers, key) => {
|
|
3
|
+
if (!headers)
|
|
4
|
+
return {};
|
|
5
|
+
if (Array.isArray(headers)) {
|
|
6
|
+
if (!headers.length)
|
|
7
|
+
return headers;
|
|
8
|
+
if (Array.isArray(headers[0])) {
|
|
9
|
+
const index = headers.findIndex(([k]) => k.toLowerCase() === key.toLowerCase());
|
|
10
|
+
if (index !== -1)
|
|
11
|
+
headers.splice(index, 1);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const h = headers;
|
|
15
|
+
for (let i = 0; i < h.length; i += 2) {
|
|
16
|
+
if (h[i]?.toLowerCase() === key.toLowerCase()) {
|
|
17
|
+
headers.splice(i, 2);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return headers;
|
|
23
|
+
}
|
|
24
|
+
else if (isIterable(headers)) {
|
|
25
|
+
return deleteHeader([...headers], key);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
delete headers[key];
|
|
29
|
+
return headers;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=delete-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-header.js","sourceRoot":"","sources":["../../src/delete-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,MAAM,YAAY,GAAG,CAO1B,OAA6B,EAC7B,GAAW,EACR,EAAE;IACL,IAAI,CAAC,OAAO;QAAE,OAAO,EAAO,CAAA;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,OAAO,CAAA;QACnC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAI,OAA8B,CAAC,SAAS,CACrD,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,CAC/C,CAAA;YACD,IAAI,KAAK,KAAK,CAAC,CAAC;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,OAAmB,CAAA;YAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC;oBAC9C,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;oBACpB,MAAK;gBACP,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,IACL,UAAU,CAA0C,OAAO,CAAC,EAC5D,CAAC;QACD,OAAO,YAAY,CAAC,CAAC,GAAG,OAAO,CAAiB,EAAE,GAAG,CAAC,CAAA;IACxD,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { isIterable } from './is-iterable.ts'\n\nexport const deleteHeader = <\n H extends\n | [string, string[] | string][]\n | Iterable<[string, string[] | string | undefined]>\n | Record<string, string[] | string | undefined>\n | string[],\n>(\n headers: H | null | undefined,\n key: string,\n): H => {\n if (!headers) return {} as H\n if (Array.isArray(headers)) {\n if (!headers.length) return headers\n if (Array.isArray(headers[0])) {\n const index = (headers as [string, string][]).findIndex(\n ([k]) => k.toLowerCase() === key.toLowerCase(),\n )\n if (index !== -1) headers.splice(index, 1)\n } else {\n const h = headers as string[]\n for (let i = 0; i < h.length; i += 2) {\n if (h[i]?.toLowerCase() === key.toLowerCase()) {\n headers.splice(i, 2)\n break\n }\n }\n }\n return headers\n } else if (\n isIterable<[string, string[] | string | undefined]>(headers)\n ) {\n return deleteHeader([...headers] as unknown as H, key)\n } else {\n delete headers[key]\n return headers\n }\n}\n"]}
|
package/dist/esm/env.d.ts
CHANGED
|
@@ -4,8 +4,4 @@ export declare const isNode: boolean;
|
|
|
4
4
|
export declare const bun: string | undefined;
|
|
5
5
|
export declare const deno: string | undefined;
|
|
6
6
|
export declare const node: string | undefined;
|
|
7
|
-
export declare const engine: {
|
|
8
|
-
name: string;
|
|
9
|
-
version: string;
|
|
10
|
-
} | undefined;
|
|
11
7
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/esm/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,SAAc,CAAA;AACjC,eAAO,MAAM,KAAK,SAAwB,CAAA;AAG1C,eAAO,MAAM,MAAM,SAA+C,CAAA;AAGlE,eAAO,MAAM,GAAG,oBAAwC,CAAA;AACxD,eAAO,MAAM,IAAI,oBAA0C,CAAA;AAC3D,eAAO,MAAM,IAAI,oBAA0C,CAAA
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,SAAc,CAAA;AACjC,eAAO,MAAM,KAAK,SAAwB,CAAA;AAG1C,eAAO,MAAM,MAAM,SAA+C,CAAA;AAGlE,eAAO,MAAM,GAAG,oBAAwC,CAAA;AACxD,eAAO,MAAM,IAAI,oBAA0C,CAAA;AAC3D,eAAO,MAAM,IAAI,oBAA0C,CAAA"}
|
package/dist/esm/env.js
CHANGED
|
@@ -10,7 +10,4 @@ export const isNode = !isDeno && !isBun && 'node' in proc.versions;
|
|
|
10
10
|
export const bun = isBun ? proc.versions.bun : undefined;
|
|
11
11
|
export const deno = isDeno ? proc.versions.deno : undefined;
|
|
12
12
|
export const node = isNode ? proc.versions.node : undefined;
|
|
13
|
-
export const engine = isNode || isDeno ? { name: 'v8', version: proc.versions.v8 }
|
|
14
|
-
: isBun && bun ? { name: 'bun', version: bun }
|
|
15
|
-
: undefined;
|
|
16
13
|
//# sourceMappingURL=env.js.map
|
package/dist/esm/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","source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AAK,CAAC,IAAI,CAAC,CAAA;AACjC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AAC1C,kEAAkE;AAClE,gCAAgC;AAChC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAA;AAElE,4DAA4D;AAC5D,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAA;AACxD,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AAC3D,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA","sourcesContent":["import proc from 'node:process'\n\nconst { Deno, Bun } = globalThis as typeof globalThis & {\n Deno: undefined | object\n Bun: undefined | object\n}\n\nconst isObj = (v: unknown) => typeof v === 'object' && !!v\n\nexport const isDeno = isObj(Deno)\nexport const isBun = !isDeno && isObj(Bun)\n// bun and deno also report 'node' in process.versions so its only\n// node if it is not bun or deno\nexport const isNode = !isDeno && !isBun && 'node' in proc.versions\n\n// All the runtimes put their versions into process.versions\nexport const bun = isBun ? proc.versions.bun : undefined\nexport const deno = isDeno ? proc.versions.deno : undefined\nexport const node = isNode ? proc.versions.node : undefined\n"]}
|
package/dist/esm/get-header.js
CHANGED