@verdaccio/store 7.0.0-next-7.11 → 7.0.0-next-7.13
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/CHANGELOG.md +34 -0
- package/README.md +24 -57
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -12
- package/build/index.js.map +1 -1
- package/build/lib/storage-utils.d.ts +2 -0
- package/build/lib/storage-utils.js +29 -0
- package/build/lib/storage-utils.js.map +1 -1
- package/build/lib/versions-utils.d.ts +14 -0
- package/build/lib/versions-utils.js +51 -0
- package/build/lib/versions-utils.js.map +1 -1
- package/build/storage.d.ts +6 -10
- package/build/storage.js +37 -107
- package/build/storage.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +12 -11
- package/src/index.ts +0 -1
- package/src/lib/storage-utils.ts +35 -1
- package/src/lib/versions-utils.ts +50 -1
- package/src/storage.ts +51 -102
- package/test/search.spec.ts +26 -5
- package/test/storage.spec.ts +22 -22
- package/test/versions.spec.ts +53 -1
- package/build/lib/TransFormResults.d.ts +0 -15
- package/build/lib/TransFormResults.js +0 -51
- package/build/lib/TransFormResults.js.map +0 -1
- package/build/lib/search-utils.d.ts +0 -4
- package/build/lib/search-utils.js +0 -50
- package/build/lib/search-utils.js.map +0 -1
- package/build/lib/uplink-util.d.ts +0 -10
- package/build/lib/uplink-util.js +0 -43
- package/build/lib/uplink-util.js.map +0 -1
- package/src/lib/TransFormResults.ts +0 -42
- package/src/lib/search-utils.ts +0 -50
- package/src/lib/uplink-util.ts +0 -42
- /package/test/fixtures/config/{getTarballNext-getupstream.yaml → getTarball-getupstream.yaml} +0 -0
package/build/storage.js
CHANGED
|
@@ -16,14 +16,12 @@ var _core = require("@verdaccio/core");
|
|
|
16
16
|
var _loaders = require("@verdaccio/loaders");
|
|
17
17
|
var _logger = require("@verdaccio/logger");
|
|
18
18
|
var _proxy = require("@verdaccio/proxy");
|
|
19
|
+
var _search = _interopRequireDefault(require("@verdaccio/search"));
|
|
19
20
|
var _tarball = require("@verdaccio/tarball");
|
|
20
21
|
var _utils = require("@verdaccio/utils");
|
|
21
22
|
var _2 = require(".");
|
|
22
|
-
var _TransFormResults = require("./lib/TransFormResults");
|
|
23
|
-
var _searchUtils = require("./lib/search-utils");
|
|
24
23
|
var _starUtils = require("./lib/star-utils");
|
|
25
24
|
var _storageUtils = require("./lib/storage-utils");
|
|
26
|
-
var _uplinkUtil = require("./lib/uplink-util");
|
|
27
25
|
var _versionsUtils = require("./lib/versions-utils");
|
|
28
26
|
var _localStorage = require("./local-storage");
|
|
29
27
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -36,10 +34,11 @@ const PROTO_NAME = exports.PROTO_NAME = '__proto__';
|
|
|
36
34
|
class Storage {
|
|
37
35
|
constructor(config) {
|
|
38
36
|
this.config = config;
|
|
39
|
-
this.uplinks = (0, _uplinkUtil.setupUpLinks)(config);
|
|
40
37
|
this.logger = _logger.logger.child({
|
|
41
38
|
module: 'storage'
|
|
42
39
|
});
|
|
40
|
+
this.uplinks = (0, _proxy.setupUpLinks)(config, this.logger);
|
|
41
|
+
this.searchService = new _search.default(config, this.logger);
|
|
43
42
|
this.filters = null;
|
|
44
43
|
// @ts-ignore
|
|
45
44
|
this.localStorage = null;
|
|
@@ -164,74 +163,19 @@ class Storage {
|
|
|
164
163
|
/**
|
|
165
164
|
* Handle search on packages and proxies.
|
|
166
165
|
* Iterate all proxies configured and search in all endpoints in v2 and pipe all responses
|
|
167
|
-
*
|
|
166
|
+
* once the proxies request has finished search in local storage for all packages
|
|
168
167
|
* (privated and cached).
|
|
169
168
|
*/
|
|
170
169
|
async search(options) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
debug('
|
|
179
|
-
|
|
180
|
-
const uplink = this.uplinks[uplinkId];
|
|
181
|
-
if (!uplink) {
|
|
182
|
-
// this line should never happens
|
|
183
|
-
this.logger.error({
|
|
184
|
-
uplinkId
|
|
185
|
-
}, 'uplink @upLinkId not found');
|
|
186
|
-
}
|
|
187
|
-
return this.consumeSearchStream(uplinkId, uplink, options, streamPassThrough);
|
|
188
|
-
});
|
|
189
|
-
try {
|
|
190
|
-
debug('searching on %s uplinks...', searchUplinksStreams === null || searchUplinksStreams === void 0 ? void 0 : searchUplinksStreams.length);
|
|
191
|
-
// only process those streams end successfully, if all request fails
|
|
192
|
-
// just include local storage results (if local fails then return 500)
|
|
193
|
-
await Promise.allSettled([...searchUplinksStreams]);
|
|
194
|
-
debug('searching all uplinks done');
|
|
195
|
-
} catch (err) {
|
|
196
|
-
this.logger.error({
|
|
197
|
-
err: err === null || err === void 0 ? void 0 : err.message
|
|
198
|
-
}, ' error on uplinks search @{err}');
|
|
199
|
-
streamPassThrough.emit('error', err);
|
|
200
|
-
}
|
|
201
|
-
debug('search local');
|
|
202
|
-
try {
|
|
203
|
-
await this.searchCachedPackages(streamPassThrough, options.query);
|
|
204
|
-
} catch (err) {
|
|
205
|
-
this.logger.error({
|
|
206
|
-
err: err === null || err === void 0 ? void 0 : err.message
|
|
207
|
-
}, ' error on local search @{err}');
|
|
208
|
-
streamPassThrough.emit('error', err);
|
|
209
|
-
}
|
|
210
|
-
const data = [];
|
|
211
|
-
const outPutStream = new _stream.PassThrough({
|
|
212
|
-
objectMode: true
|
|
213
|
-
});
|
|
214
|
-
(0, _stream.pipeline)(streamPassThrough, transformResults, outPutStream, err => {
|
|
215
|
-
if (err) {
|
|
216
|
-
this.logger.error({
|
|
217
|
-
err: err === null || err === void 0 ? void 0 : err.message
|
|
218
|
-
}, ' error on search @{err}');
|
|
219
|
-
throw _core.errorUtils.getInternalError(err ? err.message : 'unknown search error');
|
|
220
|
-
} else {
|
|
221
|
-
debug('pipeline succeeded');
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
outPutStream.on('data', chunk => {
|
|
225
|
-
data.push(chunk);
|
|
226
|
-
});
|
|
227
|
-
return new Promise(resolve => {
|
|
228
|
-
outPutStream.on('finish', async () => {
|
|
229
|
-
const searchFinalResults = (0, _searchUtils.removeDuplicates)(data);
|
|
230
|
-
debug('search stream total results: %o', searchFinalResults.length);
|
|
231
|
-
return resolve(searchFinalResults);
|
|
232
|
-
});
|
|
233
|
-
debug('search done');
|
|
234
|
-
});
|
|
170
|
+
debug('search on cache packages');
|
|
171
|
+
const cachePackages = await this.getCachedPackages(options.query);
|
|
172
|
+
debug('search found on cache packages %o', cachePackages.length);
|
|
173
|
+
const remotePackages = await this.searchService.search(options);
|
|
174
|
+
debug('search found on remote packages %o', remotePackages.length);
|
|
175
|
+
const totalResults = [...cachePackages, ...remotePackages];
|
|
176
|
+
const uniqueResults = (0, _versionsUtils.removeLowerVersions)(totalResults);
|
|
177
|
+
debug('unique results %o', uniqueResults.length);
|
|
178
|
+
return uniqueResults;
|
|
235
179
|
}
|
|
236
180
|
async getTarballFromUpstream(name, filename, {
|
|
237
181
|
signal
|
|
@@ -313,7 +257,7 @@ class Storage {
|
|
|
313
257
|
// should not be the case
|
|
314
258
|
const passThroughRemoteStream = new _stream.PassThrough();
|
|
315
259
|
// ensure get the latest data
|
|
316
|
-
const [updatedManifest] = await this.
|
|
260
|
+
const [updatedManifest] = await this.syncUplinksMetadata(name, cachedManifest, {
|
|
317
261
|
uplinksLook: true
|
|
318
262
|
});
|
|
319
263
|
const distFile = updatedManifest._distfiles[filename];
|
|
@@ -356,7 +300,7 @@ class Storage {
|
|
|
356
300
|
* @param param2
|
|
357
301
|
* @returns
|
|
358
302
|
*/
|
|
359
|
-
async
|
|
303
|
+
async getTarball(name, filename, {
|
|
360
304
|
signal
|
|
361
305
|
}) {
|
|
362
306
|
debug('get tarball for package %o filename %o', name, filename);
|
|
@@ -568,32 +512,11 @@ class Storage {
|
|
|
568
512
|
}, plugin => {
|
|
569
513
|
return typeof plugin.filter_metadata !== 'undefined';
|
|
570
514
|
}, (_this$config = this.config) === null || _this$config === void 0 ? void 0 : (_this$config$serverSe = _this$config.serverSettings) === null || _this$config$serverSe === void 0 ? void 0 : _this$config$serverSe.pluginPrefix);
|
|
571
|
-
debug('filters available %o', this.filters);
|
|
515
|
+
debug('filters available %o', this.filters.length);
|
|
572
516
|
}
|
|
573
517
|
return;
|
|
574
518
|
}
|
|
575
519
|
|
|
576
|
-
/**
|
|
577
|
-
* Consume the upstream and pipe it to a transformable stream.
|
|
578
|
-
*/
|
|
579
|
-
consumeSearchStream(uplinkId, uplink, options, searchPassThrough) {
|
|
580
|
-
return uplink.search({
|
|
581
|
-
...options
|
|
582
|
-
}).then(bodyStream => {
|
|
583
|
-
bodyStream.pipe(searchPassThrough, {
|
|
584
|
-
end: false
|
|
585
|
-
});
|
|
586
|
-
bodyStream.on('error', err => {
|
|
587
|
-
_logger.logger.error({
|
|
588
|
-
uplinkId,
|
|
589
|
-
err: err
|
|
590
|
-
}, 'search error for uplink @{uplinkId}: @{err?.message}');
|
|
591
|
-
searchPassThrough.end();
|
|
592
|
-
});
|
|
593
|
-
return new Promise(resolve => bodyStream.on('end', resolve));
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
|
|
597
520
|
/**
|
|
598
521
|
* Retrieve a wrapper that provide access to the package location.
|
|
599
522
|
* @param {Object} pkgName package name.
|
|
@@ -623,9 +546,14 @@ class Storage {
|
|
|
623
546
|
signal
|
|
624
547
|
});
|
|
625
548
|
}
|
|
626
|
-
async
|
|
627
|
-
debug('search on each package');
|
|
628
|
-
|
|
549
|
+
async getCachedPackages(query) {
|
|
550
|
+
debug('search on each package', query);
|
|
551
|
+
const results = [];
|
|
552
|
+
if (typeof query === 'undefined' || typeof (query === null || query === void 0 ? void 0 : query.text) === 'undefined') {
|
|
553
|
+
debug('search query for cached not found');
|
|
554
|
+
return results;
|
|
555
|
+
}
|
|
556
|
+
_logger.logger.info({
|
|
629
557
|
t: query.text,
|
|
630
558
|
q: query.quality,
|
|
631
559
|
p: query.popularity,
|
|
@@ -633,16 +561,16 @@ class Storage {
|
|
|
633
561
|
s: query.size
|
|
634
562
|
}, 'search by text @{t}| maintenance @{m}| quality @{q}| popularity @{p}');
|
|
635
563
|
if (typeof this.localStorage.getStoragePlugin().search === 'undefined') {
|
|
636
|
-
|
|
637
|
-
searchStream.end();
|
|
564
|
+
_logger.logger.info('plugin search not implemented yet');
|
|
638
565
|
} else {
|
|
639
|
-
debug('search on each package by plugin');
|
|
566
|
+
debug('search on each package by plugin query');
|
|
640
567
|
const items = await this.localStorage.getStoragePlugin().search(query);
|
|
641
568
|
try {
|
|
642
569
|
for (const searchItem of items) {
|
|
643
570
|
const manifest = await this.getPackageLocalMetadata(searchItem.package.name);
|
|
644
571
|
if (_lodash.default.isEmpty(manifest === null || manifest === void 0 ? void 0 : manifest.versions) === false) {
|
|
645
|
-
const searchPackage = (0,
|
|
572
|
+
const searchPackage = (0, _storageUtils.mapManifestToSearchPackageBody)(manifest, searchItem);
|
|
573
|
+
debug('search local stream found %o', searchPackage.name);
|
|
646
574
|
const searchPackageItem = {
|
|
647
575
|
package: searchPackage,
|
|
648
576
|
score: searchItem.score,
|
|
@@ -652,19 +580,21 @@ class Storage {
|
|
|
652
580
|
// FUTURE: find a better way to calculate the score
|
|
653
581
|
searchScore: 1
|
|
654
582
|
};
|
|
655
|
-
|
|
583
|
+
results.push(searchPackageItem);
|
|
584
|
+
} else {
|
|
585
|
+
debug('local item without versions detected %s', searchItem.package.name);
|
|
656
586
|
}
|
|
657
587
|
}
|
|
658
588
|
debug('search local stream end');
|
|
659
|
-
searchStream.end();
|
|
660
589
|
} catch (err) {
|
|
661
590
|
this.logger.error({
|
|
662
591
|
err,
|
|
663
592
|
query
|
|
664
593
|
}, 'error on search by plugin @{err.message}');
|
|
665
|
-
|
|
594
|
+
throw err;
|
|
666
595
|
}
|
|
667
596
|
}
|
|
597
|
+
return results;
|
|
668
598
|
}
|
|
669
599
|
async removePackageByRevision(pkgName, revision) {
|
|
670
600
|
const storage = this.getPrivatePackageStorage(pkgName);
|
|
@@ -1314,7 +1244,7 @@ class Storage {
|
|
|
1314
1244
|
async checkPackageRemote(name, uplinksLook) {
|
|
1315
1245
|
try {
|
|
1316
1246
|
// we provide a null manifest, thus the manifest returned will be the remote one
|
|
1317
|
-
const [remoteManifest, upLinksErrors] = await this.
|
|
1247
|
+
const [remoteManifest, upLinksErrors] = await this.syncUplinksMetadata(name, null, {
|
|
1318
1248
|
uplinksLook
|
|
1319
1249
|
});
|
|
1320
1250
|
|
|
@@ -1419,7 +1349,7 @@ class Storage {
|
|
|
1419
1349
|
// if we can't get the local metadata, we try to get the remote metadata
|
|
1420
1350
|
// if we do to have local metadata, we try to update it with the upstream registry
|
|
1421
1351
|
debug('sync uplinks for %o', name);
|
|
1422
|
-
const [remoteManifest, upLinksErrors] = await this.
|
|
1352
|
+
const [remoteManifest, upLinksErrors] = await this.syncUplinksMetadata(name, data, {
|
|
1423
1353
|
uplinksLook: options.uplinksLook,
|
|
1424
1354
|
retry: options.retry,
|
|
1425
1355
|
remoteAddress: options.requestOptions.remoteAddress
|
|
@@ -1465,7 +1395,7 @@ class Storage {
|
|
|
1465
1395
|
in that case the request returns empty body and we want ask next on the list if has fresh
|
|
1466
1396
|
updates.
|
|
1467
1397
|
*/
|
|
1468
|
-
async
|
|
1398
|
+
async syncUplinksMetadata(name, localManifest, options = {}) {
|
|
1469
1399
|
let found = localManifest !== null;
|
|
1470
1400
|
let syncManifest = null;
|
|
1471
1401
|
const upLinks = [];
|
|
@@ -1581,7 +1511,7 @@ class Storage {
|
|
|
1581
1511
|
// merge time field cache and remote
|
|
1582
1512
|
_cacheManifest = (0, _storageUtils.mergeUplinkTimeIntoLocalNext)(_cacheManifest, remoteManifest);
|
|
1583
1513
|
// update the _uplinks field in the cache
|
|
1584
|
-
_cacheManifest = (0,
|
|
1514
|
+
_cacheManifest = (0, _proxy.updateVersionsHiddenUpLinkNext)(_cacheManifest, uplink);
|
|
1585
1515
|
try {
|
|
1586
1516
|
// merge versions from remote into the cache
|
|
1587
1517
|
_cacheManifest = (0, _storageUtils.mergeVersions)(_cacheManifest, remoteManifest);
|