@verdaccio/store 6.0.0-6-next.18 → 6.0.0-6-next.21

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 CHANGED
@@ -1,5 +1,46 @@
1
1
  # @verdaccio/store
2
2
 
3
+ ## 6.0.0-6-next.21
4
+
5
+ ### Minor Changes
6
+
7
+ - 5167bb52: feat: ui search support for remote, local and private packages
8
+
9
+ The command `npm search` search globally and return all matches, with this improvement the user interface
10
+ is powered with the same capabilities.
11
+
12
+ The UI also tag where is the origin the package with a tag, also provide the latest version and description of the package.
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [82cb0f2b]
17
+ - Updated dependencies [5167bb52]
18
+ - @verdaccio/config@6.0.0-6-next.13
19
+ - @verdaccio/core@6.0.0-6-next.5
20
+ - @verdaccio/logger@6.0.0-6-next.11
21
+ - @verdaccio/local-storage@11.0.0-6-next.12
22
+ - @verdaccio/proxy@6.0.0-6-next.19
23
+ - @verdaccio/loaders@6.0.0-6-next.12
24
+ - @verdaccio/tarball@11.0.0-6-next.12
25
+ - @verdaccio/utils@6.0.0-6-next.11
26
+ - @verdaccio/streams@11.0.0-6-next.5
27
+
28
+ ## 6.0.0-6-next.20
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [31d661c7]
33
+ - @verdaccio/loaders@6.0.0-6-next.11
34
+
35
+ ## 6.0.0-6-next.19
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies [b78f3525]
40
+ - @verdaccio/logger@6.0.0-6-next.10
41
+ - @verdaccio/loaders@6.0.0-6-next.10
42
+ - @verdaccio/proxy@6.0.0-6-next.18
43
+
3
44
  ## 6.0.0-6-next.18
4
45
 
5
46
  ### Patch Changes
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './storage';
2
2
  export * from './storage-utils';
3
+ export * from './star-utils';
3
4
  export * from './search';
4
5
  export * from './type';
package/build/index.js CHANGED
@@ -30,6 +30,19 @@ Object.keys(_storageUtils).forEach(function (key) {
30
30
  });
31
31
  });
32
32
 
33
+ var _starUtils = require("./star-utils");
34
+
35
+ Object.keys(_starUtils).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _starUtils[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _starUtils[key];
42
+ }
43
+ });
44
+ });
45
+
33
46
  var _search = require("./search");
34
47
 
35
48
  Object.keys(_search).forEach(function (key) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './storage';\nexport * from './storage-utils';\nexport * from './search';\nexport * from './type';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './storage';\nexport * from './storage-utils';\nexport * from './star-utils';\nexport * from './search';\nexport * from './type';\n"],"file":"index.js"}
@@ -2,6 +2,8 @@
2
2
  import { PassThrough } from 'stream';
3
3
  import { pluginUtils, searchUtils } from '@verdaccio/core';
4
4
  import { Callback, CallbackAction, Config, IReadTarball, IUploadTarball, Logger, MergeTags, Package, StringValue, Token, TokenFilter, Version } from '@verdaccio/types';
5
+ export declare const noSuchFile = "ENOENT";
6
+ export declare const resourceNotAvailable = "EAGAIN";
5
7
  export declare type IPluginStorage = pluginUtils.IPluginStorage<Config>;
6
8
  export declare function normalizeSearchPackage(pkg: Package, searchItem: searchUtils.SearchItem): searchUtils.SearchPackageBody;
7
9
  export declare const PROTO_NAME = "__proto__";
@@ -35,6 +37,7 @@ declare class LocalStorage {
35
37
  * @param {*} callback
36
38
  */
37
39
  addVersion(name: string, version: string, metadata: Version, tag: StringValue, callback: Callback): void;
40
+ addVersionNext(name: string, version: string, metadata: Version, tag: StringValue): Promise<void>;
38
41
  /**
39
42
  * Merge a new list of tags for a local packages with the existing one.
40
43
  * @param {*} pkgName
@@ -51,7 +54,17 @@ declare class LocalStorage {
51
54
  * @param {*} callback
52
55
  * @return {Function}
53
56
  */
54
- changePackage(name: string, incomingPkg: Package, revision: string | void, callback: Callback): void;
57
+ changePackage(name: string, incomingPkg: Package, revision: string | undefined, callback: Callback): void;
58
+ /**
59
+ * Update the package metadata, tags and attachments (tarballs).
60
+ * Note: Currently supports unpublishing and deprecation.
61
+ * @param {*} name
62
+ * @param {*} incomingPkg
63
+ * @param {*} revision
64
+ * @param {*} callback
65
+ * @return {Function}
66
+ */
67
+ changePackageNext(name: string, incomingPkg: Package, revision: string | undefined): Promise<void>;
55
68
  /**
56
69
  * Remove a tarball.
57
70
  * @param {*} name
@@ -135,6 +148,13 @@ declare class LocalStorage {
135
148
  * @return {Function}
136
149
  */
137
150
  private _updatePackage;
151
+ /**
152
+ * @param {*} name package name
153
+ * @param {*} updateHandler function(package, cb) - update function
154
+ * @param {*} callback callback that gets invoked after it's all updated
155
+ * @return {Function}
156
+ */
157
+ private updatePackageNext;
138
158
  /**
139
159
  * Update the revision (_rev) string for a package.
140
160
  * @param {*} name
@@ -143,6 +163,7 @@ declare class LocalStorage {
143
163
  * @return {Function}
144
164
  */
145
165
  private _writePackage;
166
+ private writePackageNext;
146
167
  private _setDefaultRevision;
147
168
  /**
148
169
  * Ensure the dist file remains as the same protocol
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.PROTO_NAME = exports.LocalStorage = void 0;
6
+ exports.noSuchFile = exports.PROTO_NAME = exports.LocalStorage = void 0;
7
7
  exports.normalizeSearchPackage = normalizeSearchPackage;
8
+ exports.resourceNotAvailable = void 0;
8
9
 
9
10
  var _assert = _interopRequireDefault(require("assert"));
10
11
 
@@ -29,6 +30,10 @@ var _storageUtils = require("./storage-utils");
29
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
31
 
31
32
  const debug = (0, _debug.default)('verdaccio:storage:local');
33
+ const noSuchFile = 'ENOENT';
34
+ exports.noSuchFile = noSuchFile;
35
+ const resourceNotAvailable = 'EAGAIN';
36
+ exports.resourceNotAvailable = resourceNotAvailable;
32
37
 
33
38
  function normalizeSearchPackage(pkg, searchItem) {
34
39
  const latest = _core.pkgUtils.getLatest(pkg);
@@ -342,6 +347,124 @@ class LocalStorage {
342
347
  }
343
348
  }, callback);
344
349
  }
350
+
351
+ async addVersionNext(name, version, metadata, tag) {
352
+ debug(`add version %s package for %s`, version, name);
353
+ await this.updatePackageNext(name, async data => {
354
+ debug('%s package is being updated', name); // keep only one readme per package
355
+
356
+ data.readme = metadata.readme;
357
+ debug('%s` readme mutated', name); // TODO: lodash remove
358
+
359
+ metadata = (0, _storageUtils.cleanUpReadme)(metadata);
360
+ metadata.contributors = (0, _utils.normalizeContributors)(metadata.contributors);
361
+ debug('%s` contributors normalized', name);
362
+ const hasVersion = data.versions[version] != null;
363
+
364
+ if (hasVersion) {
365
+ debug('%s version %s already exists', name, version);
366
+ throw _core.errorUtils.getConflict();
367
+ } // if uploaded tarball has a different shasum, it's very likely that we
368
+ // have some kind of error
369
+
370
+
371
+ if (_core.validatioUtils.isObject(metadata.dist) && _lodash.default.isString(metadata.dist.tarball)) {
372
+ const tarball = metadata.dist.tarball.replace(/.*\//, '');
373
+
374
+ if (_core.validatioUtils.isObject(data._attachments[tarball])) {
375
+ if (_lodash.default.isNil(data._attachments[tarball].shasum) === false && _lodash.default.isNil(metadata.dist.shasum) === false) {
376
+ if (data._attachments[tarball].shasum != metadata.dist.shasum) {
377
+ const errorMessage = `shasum error, ` + `${data._attachments[tarball].shasum} != ${metadata.dist.shasum}`;
378
+ throw _core.errorUtils.getBadRequest(errorMessage);
379
+ }
380
+ }
381
+
382
+ const currentDate = new Date().toISOString(); // some old storage do not have this field #740
383
+
384
+ if (_lodash.default.isNil(data.time)) {
385
+ data.time = {};
386
+ }
387
+
388
+ data.time['modified'] = currentDate;
389
+
390
+ if ('created' in data.time === false) {
391
+ data.time.created = currentDate;
392
+ }
393
+
394
+ data.time[version] = currentDate;
395
+ data._attachments[tarball].version = version;
396
+ }
397
+ }
398
+
399
+ data.versions[version] = metadata;
400
+ (0, _storageUtils.tagVersion)(data, version, tag);
401
+
402
+ try {
403
+ debug('%s` add on database', name);
404
+ await this.storagePlugin.add(name);
405
+ } catch (err) {
406
+ throw _core.errorUtils.getBadData(err.message);
407
+ }
408
+
409
+ return data;
410
+ }); // this._updatePackage(
411
+ // name,
412
+ // async (data, cb: Callback): Promise<void> => {
413
+ // debug('%s package is being updated', name);
414
+ // // keep only one readme per package
415
+ // data.readme = metadata.readme;
416
+ // debug('%s` readme mutated', name);
417
+ // // TODO: lodash remove
418
+ // metadata = cleanUpReadme(metadata);
419
+ // metadata.contributors = normalizeContributors(metadata.contributors as Author[]);
420
+ // debug('%s` contributors normalized', name);
421
+ // const hasVersion = data.versions[version] != null;
422
+ // if (hasVersion) {
423
+ // debug('%s version %s already exists', name, version);
424
+ // return cb(errorUtils.getConflict());
425
+ // }
426
+ // // if uploaded tarball has a different shasum, it's very likely that we
427
+ // // have some kind of error
428
+ // if (validatioUtils.isObject(metadata.dist) && _.isString(metadata.dist.tarball)) {
429
+ // const tarball = metadata.dist.tarball.replace(/.*\//, '');
430
+ // if (validatioUtils.isObject(data._attachments[tarball])) {
431
+ // if (
432
+ // _.isNil(data._attachments[tarball].shasum) === false &&
433
+ // _.isNil(metadata.dist.shasum) === false
434
+ // ) {
435
+ // if (data._attachments[tarball].shasum != metadata.dist.shasum) {
436
+ // const errorMessage =
437
+ // `shasum error, ` +
438
+ // `${data._attachments[tarball].shasum} != ${metadata.dist.shasum}`;
439
+ // return cb(errorUtils.getBadRequest(errorMessage));
440
+ // }
441
+ // }
442
+ // const currentDate = new Date().toISOString();
443
+ // // some old storage do not have this field #740
444
+ // if (_.isNil(data.time)) {
445
+ // data.time = {};
446
+ // }
447
+ // data.time['modified'] = currentDate;
448
+ // if ('created' in data.time === false) {
449
+ // data.time.created = currentDate;
450
+ // }
451
+ // data.time[version] = currentDate;
452
+ // data._attachments[tarball].version = version;
453
+ // }
454
+ // }
455
+ // data.versions[version] = metadata;
456
+ // tagVersion(data, version, tag);
457
+ // try {
458
+ // debug('%s` add on database', name);
459
+ // await this.storagePlugin.add(name);
460
+ // cb();
461
+ // } catch (err: any) {
462
+ // cb(errorUtils.getBadData(err.message));
463
+ // }
464
+ // },
465
+ // callback
466
+ // );
467
+ }
345
468
  /**
346
469
  * Merge a new list of tags for a local packages with the existing one.
347
470
  * @param {*} pkgName
@@ -446,6 +569,72 @@ class LocalStorage {
446
569
  callback();
447
570
  });
448
571
  }
572
+ /**
573
+ * Update the package metadata, tags and attachments (tarballs).
574
+ * Note: Currently supports unpublishing and deprecation.
575
+ * @param {*} name
576
+ * @param {*} incomingPkg
577
+ * @param {*} revision
578
+ * @param {*} callback
579
+ * @return {Function}
580
+ */
581
+
582
+
583
+ async changePackageNext(name, incomingPkg, revision) {
584
+ debug(`change package tags for %o revision %s`, name, revision);
585
+
586
+ if (!_core.validatioUtils.isObject(incomingPkg.versions) || !_core.validatioUtils.isObject(incomingPkg[_core.DIST_TAGS])) {
587
+ debug(`change package bad data for %o`, name);
588
+ throw _core.errorUtils.getBadData();
589
+ }
590
+
591
+ debug(`change package udapting package for %o`, name);
592
+ await this.updatePackageNext(name, async localData => {
593
+ for (const version in localData.versions) {
594
+ const incomingVersion = incomingPkg.versions[version];
595
+
596
+ if (_lodash.default.isNil(incomingVersion)) {
597
+ this.logger.info({
598
+ name: name,
599
+ version: version
600
+ }, 'unpublishing @{name}@@{version}'); // FIXME: I prefer return a new object rather mutate the metadata
601
+
602
+ delete localData.versions[version];
603
+ delete localData.time[version];
604
+
605
+ for (const file in localData._attachments) {
606
+ if (localData._attachments[file].version === version) {
607
+ delete localData._attachments[file].version;
608
+ }
609
+ }
610
+ } else if (Object.prototype.hasOwnProperty.call(incomingVersion, 'deprecated')) {
611
+ const incomingDeprecated = incomingVersion.deprecated;
612
+
613
+ if (incomingDeprecated != localData.versions[version].deprecated) {
614
+ if (!incomingDeprecated) {
615
+ this.logger.info({
616
+ name: name,
617
+ version: version
618
+ }, 'undeprecating @{name}@@{version}');
619
+ delete localData.versions[version].deprecated;
620
+ } else {
621
+ this.logger.info({
622
+ name: name,
623
+ version: version
624
+ }, 'deprecating @{name}@@{version}');
625
+ localData.versions[version].deprecated = incomingDeprecated;
626
+ }
627
+
628
+ localData.time.modified = new Date().toISOString();
629
+ }
630
+ }
631
+ }
632
+
633
+ localData[_core.USERS] = incomingPkg[_core.USERS];
634
+ localData[_core.DIST_TAGS] = incomingPkg[_core.DIST_TAGS];
635
+ return localData;
636
+ });
637
+ }
449
638
  /**
450
639
  * Remove a tarball.
451
640
  * @param {*} name
@@ -730,10 +919,16 @@ class LocalStorage {
730
919
  reject(err);
731
920
  }
732
921
 
922
+ if (_lodash.default.isEmpty(pkg === null || pkg === void 0 ? void 0 : pkg.versions)) {
923
+ return resolve({});
924
+ }
925
+
733
926
  const searchPackage = normalizeSearchPackage(pkg, searchItem);
734
927
  const searchPackageItem = {
735
928
  package: searchPackage,
736
929
  score: searchItem.score,
930
+ verdaccioPkgCached: searchItem.verdaccioPkgCached,
931
+ verdaccioPrivate: searchItem.verdaccioPrivate,
737
932
  flags: searchItem === null || searchItem === void 0 ? void 0 : searchItem.flags,
738
933
  // FUTURE: find a better way to calculate the score
739
934
  searchScore: 1
@@ -877,14 +1072,44 @@ class LocalStorage {
877
1072
  */
878
1073
 
879
1074
 
880
- _updatePackage(name, updateHandler, callback) {
1075
+ _updatePackage(name, updateHandler, onEnd) {
881
1076
  const storage = this._getLocalStorage(name);
882
1077
 
883
1078
  if (!storage) {
884
- return callback(_core.errorUtils.getNotFound());
1079
+ return onEnd(_core.errorUtils.getNotFound());
885
1080
  }
886
1081
 
887
- storage.updatePackage(name, updateHandler, this._writePackage.bind(this), _storageUtils.normalizePackage, callback);
1082
+ storage.updatePackage(name, updateHandler, this._writePackage.bind(this), _storageUtils.normalizePackage, onEnd);
1083
+ }
1084
+ /**
1085
+ * @param {*} name package name
1086
+ * @param {*} updateHandler function(package, cb) - update function
1087
+ * @param {*} callback callback that gets invoked after it's all updated
1088
+ * @return {Function}
1089
+ */
1090
+
1091
+
1092
+ async updatePackageNext(name, updateHandler) {
1093
+ const storage = this._getLocalStorage(name);
1094
+
1095
+ if (!storage) {
1096
+ throw _core.errorUtils.getNotFound();
1097
+ } // we update the package on the local storage
1098
+
1099
+
1100
+ const updatedManifest = await storage.updatePackageNext(name, updateHandler); // after correctly updated write to the storage
1101
+
1102
+ try {
1103
+ await this.writePackageNext(name, (0, _storageUtils.normalizePackage)(updatedManifest));
1104
+ } catch (err) {
1105
+ if (err.code === resourceNotAvailable) {
1106
+ throw _core.errorUtils.getInternalError('resource temporarily unavailable');
1107
+ } else if (err.code === noSuchFile) {
1108
+ throw _core.errorUtils.getNotFound();
1109
+ } else {
1110
+ throw err;
1111
+ }
1112
+ }
888
1113
  }
889
1114
  /**
890
1115
  * Update the revision (_rev) string for a package.
@@ -905,6 +1130,17 @@ class LocalStorage {
905
1130
  storage.savePackage(name, this._setDefaultRevision(json), callback);
906
1131
  }
907
1132
 
1133
+ async writePackageNext(name, json) {
1134
+ const storage = this._getLocalStorage(name);
1135
+
1136
+ if (_lodash.default.isNil(storage)) {
1137
+ // TODO: replace here 500 error
1138
+ throw _core.errorUtils.getBadData();
1139
+ }
1140
+
1141
+ await storage.savePackageNext(name, this._setDefaultRevision(json));
1142
+ }
1143
+
908
1144
  _setDefaultRevision(json) {
909
1145
  // calculate revision from couch db
910
1146
  if (_lodash.default.isString(json._rev) === false) {