@verdaccio/search 9.0.0-next-9.16 → 9.0.0-next-9.18

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.
@@ -1,4 +1,3 @@
1
- require("./_virtual/_rolldown/runtime.js");
2
1
  let lodash_es = require("lodash-es");
3
2
  //#region src/search-utils.ts
4
3
  function removeDuplicates(results) {
@@ -1 +1 @@
1
- {"version":3,"file":"search-utils.js","names":[],"sources":["../src/search-utils.ts"],"sourcesContent":["import { orderBy } from 'lodash-es';\n\nimport type { searchUtils } from '@verdaccio/core';\n\nexport function removeDuplicates(results: searchUtils.SearchPackageItem[]) {\n const pkgNames: any[] = [];\n const orderByResults = orderBy(results, ['verdaccioPrivate', 'asc']);\n return orderByResults.filter((pkg) => {\n if (pkgNames.includes(pkg?.package?.name)) {\n return false;\n }\n pkgNames.push(pkg?.package?.name);\n return true;\n });\n}\n"],"mappings":";;;AAIA,SAAgB,iBAAiB,SAA0C;CACzE,MAAM,WAAkB,EAAE;AAE1B,SAAA,GAAA,UAAA,SAD+B,SAAS,CAAC,oBAAoB,MAAM,CAAC,CAC9C,QAAQ,QAAQ;AACpC,MAAI,SAAS,SAAS,KAAK,SAAS,KAAK,CACvC,QAAO;AAET,WAAS,KAAK,KAAK,SAAS,KAAK;AACjC,SAAO;GACP"}
1
+ {"version":3,"file":"search-utils.js","names":[],"sources":["../src/search-utils.ts"],"sourcesContent":["import { orderBy } from 'lodash-es';\n\nimport type { searchUtils } from '@verdaccio/core';\n\nexport function removeDuplicates(results: searchUtils.SearchPackageItem[]) {\n const pkgNames: any[] = [];\n const orderByResults = orderBy(results, ['verdaccioPrivate', 'asc']);\n return orderByResults.filter((pkg) => {\n if (pkgNames.includes(pkg?.package?.name)) {\n return false;\n }\n pkgNames.push(pkg?.package?.name);\n return true;\n });\n}\n"],"mappings":";;AAIA,SAAgB,iBAAiB,SAA0C;CACzE,MAAM,WAAkB,CAAC;CAEzB,QAAA,GAAA,UAAA,SAD+B,SAAS,CAAC,oBAAoB,KAAK,CAC3D,EAAe,QAAQ,QAAQ;EACpC,IAAI,SAAS,SAAS,KAAK,SAAS,IAAI,GACtC,OAAO;EAET,SAAS,KAAK,KAAK,SAAS,IAAI;EAChC,OAAO;CACT,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"search-utils.mjs","names":[],"sources":["../src/search-utils.ts"],"sourcesContent":["import { orderBy } from 'lodash-es';\n\nimport type { searchUtils } from '@verdaccio/core';\n\nexport function removeDuplicates(results: searchUtils.SearchPackageItem[]) {\n const pkgNames: any[] = [];\n const orderByResults = orderBy(results, ['verdaccioPrivate', 'asc']);\n return orderByResults.filter((pkg) => {\n if (pkgNames.includes(pkg?.package?.name)) {\n return false;\n }\n pkgNames.push(pkg?.package?.name);\n return true;\n });\n}\n"],"mappings":";;AAIA,SAAgB,iBAAiB,SAA0C;CACzE,MAAM,WAAkB,EAAE;AAE1B,QADuB,QAAQ,SAAS,CAAC,oBAAoB,MAAM,CAAC,CAC9C,QAAQ,QAAQ;AACpC,MAAI,SAAS,SAAS,KAAK,SAAS,KAAK,CACvC,QAAO;AAET,WAAS,KAAK,KAAK,SAAS,KAAK;AACjC,SAAO;GACP"}
1
+ {"version":3,"file":"search-utils.mjs","names":[],"sources":["../src/search-utils.ts"],"sourcesContent":["import { orderBy } from 'lodash-es';\n\nimport type { searchUtils } from '@verdaccio/core';\n\nexport function removeDuplicates(results: searchUtils.SearchPackageItem[]) {\n const pkgNames: any[] = [];\n const orderByResults = orderBy(results, ['verdaccioPrivate', 'asc']);\n return orderByResults.filter((pkg) => {\n if (pkgNames.includes(pkg?.package?.name)) {\n return false;\n }\n pkgNames.push(pkg?.package?.name);\n return true;\n });\n}\n"],"mappings":";;AAIA,SAAgB,iBAAiB,SAA0C;CACzE,MAAM,WAAkB,CAAC;CAEzB,OADuB,QAAQ,SAAS,CAAC,oBAAoB,KAAK,CAC3D,EAAe,QAAQ,QAAQ;EACpC,IAAI,SAAS,SAAS,KAAK,SAAS,IAAI,GACtC,OAAO;EAET,SAAS,KAAK,KAAK,SAAS,IAAI;EAChC,OAAO;CACT,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { PassThrough } from 'node:stream';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport type { IProxy, ProxyInstanceList, ProxySearchParams } from '@verdaccio/proxy';\nimport { setupUpLinks } from '@verdaccio/proxy';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport { removeDuplicates } from './search-utils';\n\nconst debug = buildDebug('verdaccio:search');\n\nclass Search {\n public readonly uplinks: ProxyInstanceList;\n public readonly logger: Logger;\n constructor(config: Config, logger: Logger) {\n this.logger = logger.child({ module: 'proxy' });\n this.uplinks = setupUpLinks(config, this.logger);\n }\n\n private getProxyList() {\n const uplinksList = Object.keys(this.uplinks);\n\n return uplinksList;\n }\n\n /**\n * Handle search on packages and proxies.\n * Iterate all proxies configured and search in all endpoints in v2 and pipe all responses\n * to a stream, once the proxies request has finished search in local storage for all packages\n * (privated and cached).\n */\n public async search(options: ProxySearchParams): Promise<searchUtils.SearchPackageItem[]> {\n const results: searchUtils.SearchPackageItem[] = [];\n const upLinkList = this.getProxyList();\n // const transformResults = new TransFormResults({ objectMode: true });\n const streamPassThrough = new PassThrough({ objectMode: true });\n debug('uplinks found %s', upLinkList.length);\n const searchUplinksStreams = upLinkList.map((uplinkName: string) => {\n const uplink = this.uplinks[uplinkName];\n if (!uplink) {\n // this line should never happens\n this.logger.error({ uplinkName }, 'uplink @uplinkName not found');\n }\n return this.consumeSearchStream(uplinkName, uplink, options, streamPassThrough);\n });\n\n try {\n debug('searching on %s uplinks...', searchUplinksStreams?.length);\n // only process those streams end successfully, if all request fails\n // just include local storage results (if local fails then return 500)\n await Promise.allSettled([...searchUplinksStreams]);\n streamPassThrough.end();\n\n for await (const chunk of streamPassThrough) {\n if (Array.isArray(chunk)) {\n (chunk as searchUtils.SearchItem[])\n .filter((pkgItem) => {\n debug(`streaming remote pkg name ${pkgItem?.package?.name}`);\n return true;\n })\n .forEach((pkgItem) => {\n // @ts-ignore\n return results.push({\n ...pkgItem,\n verdaccioPkgCached: false,\n verdaccioPrivate: false,\n });\n });\n }\n }\n debug('searching all uplinks done');\n } catch (err: any) {\n this.logger.error({ err: err?.message }, ' error on uplinks search @{err}');\n throw err;\n }\n\n return removeDuplicates(results);\n }\n\n /**\n * Consume the upstream and pipe it to a transformable stream.\n */\n private consumeSearchStream(\n uplinkName: string,\n uplink: IProxy,\n options: ProxySearchParams,\n searchPassThrough: PassThrough\n ): Promise<any> {\n return uplink.search({ ...options }).then((bodyStream) => {\n bodyStream.pipe(searchPassThrough, { end: false });\n bodyStream.on('error', (err: any): void => {\n this.logger.error(\n { uplinkName, err: err },\n 'search error for uplink @{uplinkName}: @{err?.message}'\n );\n searchPassThrough.end();\n });\n return new Promise((resolve) => bodyStream.on('end', resolve));\n });\n }\n}\n\nexport { Search };\n"],"mappings":";;;;;;;AAUA,IAAM,WAAA,GAAA,MAAA,SAAmB,mBAAmB;AAE5C,IAAM,SAAN,MAAa;CACX;CACA;CACA,YAAY,QAAgB,QAAgB;AAC1C,OAAK,SAAS,OAAO,MAAM,EAAE,QAAQ,SAAS,CAAC;AAC/C,OAAK,WAAA,GAAA,iBAAA,cAAuB,QAAQ,KAAK,OAAO;;CAGlD,eAAuB;AAGrB,SAFoB,OAAO,KAAK,KAAK,QAAQ;;;;;;;;CAW/C,MAAa,OAAO,SAAsE;EACxF,MAAM,UAA2C,EAAE;EACnD,MAAM,aAAa,KAAK,cAAc;EAEtC,MAAM,oBAAoB,IAAI,YAAA,YAAY,EAAE,YAAY,MAAM,CAAC;AAC/D,UAAM,oBAAoB,WAAW,OAAO;EAC5C,MAAM,uBAAuB,WAAW,KAAK,eAAuB;GAClE,MAAM,SAAS,KAAK,QAAQ;AAC5B,OAAI,CAAC,OAEH,MAAK,OAAO,MAAM,EAAE,YAAY,EAAE,+BAA+B;AAEnE,UAAO,KAAK,oBAAoB,YAAY,QAAQ,SAAS,kBAAkB;IAC/E;AAEF,MAAI;AACF,WAAM,8BAA8B,sBAAsB,OAAO;AAGjE,SAAM,QAAQ,WAAW,CAAC,GAAG,qBAAqB,CAAC;AACnD,qBAAkB,KAAK;AAEvB,cAAW,MAAM,SAAS,kBACxB,KAAI,MAAM,QAAQ,MAAM,CACrB,OACE,QAAQ,YAAY;AACnB,YAAM,6BAA6B,SAAS,SAAS,OAAO;AAC5D,WAAO;KACP,CACD,SAAS,YAAY;AAEpB,WAAO,QAAQ,KAAK;KAClB,GAAG;KACH,oBAAoB;KACpB,kBAAkB;KACnB,CAAC;KACF;AAGR,WAAM,6BAA6B;WAC5B,KAAU;AACjB,QAAK,OAAO,MAAM,EAAE,KAAK,KAAK,SAAS,EAAE,kCAAkC;AAC3E,SAAM;;AAGR,SAAO,qBAAA,iBAAiB,QAAQ;;;;;CAMlC,oBACE,YACA,QACA,SACA,mBACc;AACd,SAAO,OAAO,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC,MAAM,eAAe;AACxD,cAAW,KAAK,mBAAmB,EAAE,KAAK,OAAO,CAAC;AAClD,cAAW,GAAG,UAAU,QAAmB;AACzC,SAAK,OAAO,MACV;KAAE;KAAiB;KAAK,EACxB,yDACD;AACD,sBAAkB,KAAK;KACvB;AACF,UAAO,IAAI,SAAS,YAAY,WAAW,GAAG,OAAO,QAAQ,CAAC;IAC9D"}
1
+ {"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { PassThrough } from 'node:stream';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport type { IProxy, ProxyInstanceList, ProxySearchParams } from '@verdaccio/proxy';\nimport { setupUpLinks } from '@verdaccio/proxy';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport { removeDuplicates } from './search-utils';\n\nconst debug = buildDebug('verdaccio:search');\n\nclass Search {\n public readonly uplinks: ProxyInstanceList;\n public readonly logger: Logger;\n constructor(config: Config, logger: Logger) {\n this.logger = logger.child({ module: 'proxy' });\n this.uplinks = setupUpLinks(config, this.logger);\n }\n\n private getProxyList() {\n const uplinksList = Object.keys(this.uplinks);\n\n return uplinksList;\n }\n\n /**\n * Handle search on packages and proxies.\n * Iterate all proxies configured and search in all endpoints in v2 and pipe all responses\n * to a stream, once the proxies request has finished search in local storage for all packages\n * (privated and cached).\n */\n public async search(options: ProxySearchParams): Promise<searchUtils.SearchPackageItem[]> {\n const results: searchUtils.SearchPackageItem[] = [];\n const upLinkList = this.getProxyList();\n // const transformResults = new TransFormResults({ objectMode: true });\n const streamPassThrough = new PassThrough({ objectMode: true });\n debug('uplinks found %s', upLinkList.length);\n const searchUplinksStreams = upLinkList.map((uplinkName: string) => {\n const uplink = this.uplinks[uplinkName];\n if (!uplink) {\n // this line should never happens\n this.logger.error({ uplinkName }, 'uplink @uplinkName not found');\n }\n return this.consumeSearchStream(uplinkName, uplink, options, streamPassThrough);\n });\n\n try {\n debug('searching on %s uplinks...', searchUplinksStreams?.length);\n // only process those streams end successfully, if all request fails\n // just include local storage results (if local fails then return 500)\n await Promise.allSettled([...searchUplinksStreams]);\n streamPassThrough.end();\n\n for await (const chunk of streamPassThrough) {\n if (Array.isArray(chunk)) {\n (chunk as searchUtils.SearchItem[])\n .filter((pkgItem) => {\n debug(`streaming remote pkg name ${pkgItem?.package?.name}`);\n return true;\n })\n .forEach((pkgItem) => {\n // @ts-ignore\n return results.push({\n ...pkgItem,\n verdaccioPkgCached: false,\n verdaccioPrivate: false,\n });\n });\n }\n }\n debug('searching all uplinks done');\n } catch (err: any) {\n this.logger.error({ err: err?.message }, ' error on uplinks search @{err}');\n throw err;\n }\n\n return removeDuplicates(results);\n }\n\n /**\n * Consume the upstream and pipe it to a transformable stream.\n */\n private consumeSearchStream(\n uplinkName: string,\n uplink: IProxy,\n options: ProxySearchParams,\n searchPassThrough: PassThrough\n ): Promise<any> {\n return uplink.search({ ...options }).then((bodyStream) => {\n bodyStream.pipe(searchPassThrough, { end: false });\n bodyStream.on('error', (err: any): void => {\n this.logger.error(\n { uplinkName, err: err },\n 'search error for uplink @{uplinkName}: @{err?.message}'\n );\n searchPassThrough.end();\n });\n return new Promise((resolve) => bodyStream.on('end', resolve));\n });\n }\n}\n\nexport { Search };\n"],"mappings":";;;;;;;AAUA,IAAM,WAAA,GAAA,MAAA,SAAmB,kBAAkB;AAE3C,IAAM,SAAN,MAAa;CACX;CACA;CACA,YAAY,QAAgB,QAAgB;EAC1C,KAAK,SAAS,OAAO,MAAM,EAAE,QAAQ,QAAQ,CAAC;EAC9C,KAAK,WAAA,GAAA,iBAAA,cAAuB,QAAQ,KAAK,MAAM;CACjD;CAEA,eAAuB;EAGrB,OAFoB,OAAO,KAAK,KAAK,OAE9B;CACT;;;;;;;CAQA,MAAa,OAAO,SAAsE;EACxF,MAAM,UAA2C,CAAC;EAClD,MAAM,aAAa,KAAK,aAAa;EAErC,MAAM,oBAAoB,IAAI,YAAA,YAAY,EAAE,YAAY,KAAK,CAAC;EAC9D,QAAM,oBAAoB,WAAW,MAAM;EAC3C,MAAM,uBAAuB,WAAW,KAAK,eAAuB;GAClE,MAAM,SAAS,KAAK,QAAQ;GAC5B,IAAI,CAAC,QAEH,KAAK,OAAO,MAAM,EAAE,WAAW,GAAG,8BAA8B;GAElE,OAAO,KAAK,oBAAoB,YAAY,QAAQ,SAAS,iBAAiB;EAChF,CAAC;EAED,IAAI;GACF,QAAM,8BAA8B,sBAAsB,MAAM;GAGhE,MAAM,QAAQ,WAAW,CAAC,GAAG,oBAAoB,CAAC;GAClD,kBAAkB,IAAI;GAEtB,WAAW,MAAM,SAAS,mBACxB,IAAI,MAAM,QAAQ,KAAK,GACrB,MACG,QAAQ,YAAY;IACnB,QAAM,6BAA6B,SAAS,SAAS,MAAM;IAC3D,OAAO;GACT,CAAC,EACA,SAAS,YAAY;IAEpB,OAAO,QAAQ,KAAK;KAClB,GAAG;KACH,oBAAoB;KACpB,kBAAkB;IACpB,CAAC;GACH,CAAC;GAGP,QAAM,4BAA4B;EACpC,SAAS,KAAU;GACjB,KAAK,OAAO,MAAM,EAAE,KAAK,KAAK,QAAQ,GAAG,iCAAiC;GAC1E,MAAM;EACR;EAEA,OAAO,qBAAA,iBAAiB,OAAO;CACjC;;;;CAKA,oBACE,YACA,QACA,SACA,mBACc;EACd,OAAO,OAAO,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE,MAAM,eAAe;GACxD,WAAW,KAAK,mBAAmB,EAAE,KAAK,MAAM,CAAC;GACjD,WAAW,GAAG,UAAU,QAAmB;IACzC,KAAK,OAAO,MACV;KAAE;KAAiB;IAAI,GACvB,wDACF;IACA,kBAAkB,IAAI;GACxB,CAAC;GACD,OAAO,IAAI,SAAS,YAAY,WAAW,GAAG,OAAO,OAAO,CAAC;EAC/D,CAAC;CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"search.mjs","names":[],"sources":["../src/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { PassThrough } from 'node:stream';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport type { IProxy, ProxyInstanceList, ProxySearchParams } from '@verdaccio/proxy';\nimport { setupUpLinks } from '@verdaccio/proxy';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport { removeDuplicates } from './search-utils';\n\nconst debug = buildDebug('verdaccio:search');\n\nclass Search {\n public readonly uplinks: ProxyInstanceList;\n public readonly logger: Logger;\n constructor(config: Config, logger: Logger) {\n this.logger = logger.child({ module: 'proxy' });\n this.uplinks = setupUpLinks(config, this.logger);\n }\n\n private getProxyList() {\n const uplinksList = Object.keys(this.uplinks);\n\n return uplinksList;\n }\n\n /**\n * Handle search on packages and proxies.\n * Iterate all proxies configured and search in all endpoints in v2 and pipe all responses\n * to a stream, once the proxies request has finished search in local storage for all packages\n * (privated and cached).\n */\n public async search(options: ProxySearchParams): Promise<searchUtils.SearchPackageItem[]> {\n const results: searchUtils.SearchPackageItem[] = [];\n const upLinkList = this.getProxyList();\n // const transformResults = new TransFormResults({ objectMode: true });\n const streamPassThrough = new PassThrough({ objectMode: true });\n debug('uplinks found %s', upLinkList.length);\n const searchUplinksStreams = upLinkList.map((uplinkName: string) => {\n const uplink = this.uplinks[uplinkName];\n if (!uplink) {\n // this line should never happens\n this.logger.error({ uplinkName }, 'uplink @uplinkName not found');\n }\n return this.consumeSearchStream(uplinkName, uplink, options, streamPassThrough);\n });\n\n try {\n debug('searching on %s uplinks...', searchUplinksStreams?.length);\n // only process those streams end successfully, if all request fails\n // just include local storage results (if local fails then return 500)\n await Promise.allSettled([...searchUplinksStreams]);\n streamPassThrough.end();\n\n for await (const chunk of streamPassThrough) {\n if (Array.isArray(chunk)) {\n (chunk as searchUtils.SearchItem[])\n .filter((pkgItem) => {\n debug(`streaming remote pkg name ${pkgItem?.package?.name}`);\n return true;\n })\n .forEach((pkgItem) => {\n // @ts-ignore\n return results.push({\n ...pkgItem,\n verdaccioPkgCached: false,\n verdaccioPrivate: false,\n });\n });\n }\n }\n debug('searching all uplinks done');\n } catch (err: any) {\n this.logger.error({ err: err?.message }, ' error on uplinks search @{err}');\n throw err;\n }\n\n return removeDuplicates(results);\n }\n\n /**\n * Consume the upstream and pipe it to a transformable stream.\n */\n private consumeSearchStream(\n uplinkName: string,\n uplink: IProxy,\n options: ProxySearchParams,\n searchPassThrough: PassThrough\n ): Promise<any> {\n return uplink.search({ ...options }).then((bodyStream) => {\n bodyStream.pipe(searchPassThrough, { end: false });\n bodyStream.on('error', (err: any): void => {\n this.logger.error(\n { uplinkName, err: err },\n 'search error for uplink @{uplinkName}: @{err?.message}'\n );\n searchPassThrough.end();\n });\n return new Promise((resolve) => bodyStream.on('end', resolve));\n });\n }\n}\n\nexport { Search };\n"],"mappings":";;;;;AAUA,IAAM,QAAQ,WAAW,mBAAmB;AAE5C,IAAM,SAAN,MAAa;CACX;CACA;CACA,YAAY,QAAgB,QAAgB;AAC1C,OAAK,SAAS,OAAO,MAAM,EAAE,QAAQ,SAAS,CAAC;AAC/C,OAAK,UAAU,aAAa,QAAQ,KAAK,OAAO;;CAGlD,eAAuB;AAGrB,SAFoB,OAAO,KAAK,KAAK,QAAQ;;;;;;;;CAW/C,MAAa,OAAO,SAAsE;EACxF,MAAM,UAA2C,EAAE;EACnD,MAAM,aAAa,KAAK,cAAc;EAEtC,MAAM,oBAAoB,IAAI,YAAY,EAAE,YAAY,MAAM,CAAC;AAC/D,QAAM,oBAAoB,WAAW,OAAO;EAC5C,MAAM,uBAAuB,WAAW,KAAK,eAAuB;GAClE,MAAM,SAAS,KAAK,QAAQ;AAC5B,OAAI,CAAC,OAEH,MAAK,OAAO,MAAM,EAAE,YAAY,EAAE,+BAA+B;AAEnE,UAAO,KAAK,oBAAoB,YAAY,QAAQ,SAAS,kBAAkB;IAC/E;AAEF,MAAI;AACF,SAAM,8BAA8B,sBAAsB,OAAO;AAGjE,SAAM,QAAQ,WAAW,CAAC,GAAG,qBAAqB,CAAC;AACnD,qBAAkB,KAAK;AAEvB,cAAW,MAAM,SAAS,kBACxB,KAAI,MAAM,QAAQ,MAAM,CACrB,OACE,QAAQ,YAAY;AACnB,UAAM,6BAA6B,SAAS,SAAS,OAAO;AAC5D,WAAO;KACP,CACD,SAAS,YAAY;AAEpB,WAAO,QAAQ,KAAK;KAClB,GAAG;KACH,oBAAoB;KACpB,kBAAkB;KACnB,CAAC;KACF;AAGR,SAAM,6BAA6B;WAC5B,KAAU;AACjB,QAAK,OAAO,MAAM,EAAE,KAAK,KAAK,SAAS,EAAE,kCAAkC;AAC3E,SAAM;;AAGR,SAAO,iBAAiB,QAAQ;;;;;CAMlC,oBACE,YACA,QACA,SACA,mBACc;AACd,SAAO,OAAO,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC,MAAM,eAAe;AACxD,cAAW,KAAK,mBAAmB,EAAE,KAAK,OAAO,CAAC;AAClD,cAAW,GAAG,UAAU,QAAmB;AACzC,SAAK,OAAO,MACV;KAAE;KAAiB;KAAK,EACxB,yDACD;AACD,sBAAkB,KAAK;KACvB;AACF,UAAO,IAAI,SAAS,YAAY,WAAW,GAAG,OAAO,QAAQ,CAAC;IAC9D"}
1
+ {"version":3,"file":"search.mjs","names":[],"sources":["../src/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { PassThrough } from 'node:stream';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport type { IProxy, ProxyInstanceList, ProxySearchParams } from '@verdaccio/proxy';\nimport { setupUpLinks } from '@verdaccio/proxy';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport { removeDuplicates } from './search-utils';\n\nconst debug = buildDebug('verdaccio:search');\n\nclass Search {\n public readonly uplinks: ProxyInstanceList;\n public readonly logger: Logger;\n constructor(config: Config, logger: Logger) {\n this.logger = logger.child({ module: 'proxy' });\n this.uplinks = setupUpLinks(config, this.logger);\n }\n\n private getProxyList() {\n const uplinksList = Object.keys(this.uplinks);\n\n return uplinksList;\n }\n\n /**\n * Handle search on packages and proxies.\n * Iterate all proxies configured and search in all endpoints in v2 and pipe all responses\n * to a stream, once the proxies request has finished search in local storage for all packages\n * (privated and cached).\n */\n public async search(options: ProxySearchParams): Promise<searchUtils.SearchPackageItem[]> {\n const results: searchUtils.SearchPackageItem[] = [];\n const upLinkList = this.getProxyList();\n // const transformResults = new TransFormResults({ objectMode: true });\n const streamPassThrough = new PassThrough({ objectMode: true });\n debug('uplinks found %s', upLinkList.length);\n const searchUplinksStreams = upLinkList.map((uplinkName: string) => {\n const uplink = this.uplinks[uplinkName];\n if (!uplink) {\n // this line should never happens\n this.logger.error({ uplinkName }, 'uplink @uplinkName not found');\n }\n return this.consumeSearchStream(uplinkName, uplink, options, streamPassThrough);\n });\n\n try {\n debug('searching on %s uplinks...', searchUplinksStreams?.length);\n // only process those streams end successfully, if all request fails\n // just include local storage results (if local fails then return 500)\n await Promise.allSettled([...searchUplinksStreams]);\n streamPassThrough.end();\n\n for await (const chunk of streamPassThrough) {\n if (Array.isArray(chunk)) {\n (chunk as searchUtils.SearchItem[])\n .filter((pkgItem) => {\n debug(`streaming remote pkg name ${pkgItem?.package?.name}`);\n return true;\n })\n .forEach((pkgItem) => {\n // @ts-ignore\n return results.push({\n ...pkgItem,\n verdaccioPkgCached: false,\n verdaccioPrivate: false,\n });\n });\n }\n }\n debug('searching all uplinks done');\n } catch (err: any) {\n this.logger.error({ err: err?.message }, ' error on uplinks search @{err}');\n throw err;\n }\n\n return removeDuplicates(results);\n }\n\n /**\n * Consume the upstream and pipe it to a transformable stream.\n */\n private consumeSearchStream(\n uplinkName: string,\n uplink: IProxy,\n options: ProxySearchParams,\n searchPassThrough: PassThrough\n ): Promise<any> {\n return uplink.search({ ...options }).then((bodyStream) => {\n bodyStream.pipe(searchPassThrough, { end: false });\n bodyStream.on('error', (err: any): void => {\n this.logger.error(\n { uplinkName, err: err },\n 'search error for uplink @{uplinkName}: @{err?.message}'\n );\n searchPassThrough.end();\n });\n return new Promise((resolve) => bodyStream.on('end', resolve));\n });\n }\n}\n\nexport { Search };\n"],"mappings":";;;;;AAUA,IAAM,QAAQ,WAAW,kBAAkB;AAE3C,IAAM,SAAN,MAAa;CACX;CACA;CACA,YAAY,QAAgB,QAAgB;EAC1C,KAAK,SAAS,OAAO,MAAM,EAAE,QAAQ,QAAQ,CAAC;EAC9C,KAAK,UAAU,aAAa,QAAQ,KAAK,MAAM;CACjD;CAEA,eAAuB;EAGrB,OAFoB,OAAO,KAAK,KAAK,OAE9B;CACT;;;;;;;CAQA,MAAa,OAAO,SAAsE;EACxF,MAAM,UAA2C,CAAC;EAClD,MAAM,aAAa,KAAK,aAAa;EAErC,MAAM,oBAAoB,IAAI,YAAY,EAAE,YAAY,KAAK,CAAC;EAC9D,MAAM,oBAAoB,WAAW,MAAM;EAC3C,MAAM,uBAAuB,WAAW,KAAK,eAAuB;GAClE,MAAM,SAAS,KAAK,QAAQ;GAC5B,IAAI,CAAC,QAEH,KAAK,OAAO,MAAM,EAAE,WAAW,GAAG,8BAA8B;GAElE,OAAO,KAAK,oBAAoB,YAAY,QAAQ,SAAS,iBAAiB;EAChF,CAAC;EAED,IAAI;GACF,MAAM,8BAA8B,sBAAsB,MAAM;GAGhE,MAAM,QAAQ,WAAW,CAAC,GAAG,oBAAoB,CAAC;GAClD,kBAAkB,IAAI;GAEtB,WAAW,MAAM,SAAS,mBACxB,IAAI,MAAM,QAAQ,KAAK,GACrB,MACG,QAAQ,YAAY;IACnB,MAAM,6BAA6B,SAAS,SAAS,MAAM;IAC3D,OAAO;GACT,CAAC,EACA,SAAS,YAAY;IAEpB,OAAO,QAAQ,KAAK;KAClB,GAAG;KACH,oBAAoB;KACpB,kBAAkB;IACpB,CAAC;GACH,CAAC;GAGP,MAAM,4BAA4B;EACpC,SAAS,KAAU;GACjB,KAAK,OAAO,MAAM,EAAE,KAAK,KAAK,QAAQ,GAAG,iCAAiC;GAC1E,MAAM;EACR;EAEA,OAAO,iBAAiB,OAAO;CACjC;;;;CAKA,oBACE,YACA,QACA,SACA,mBACc;EACd,OAAO,OAAO,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE,MAAM,eAAe;GACxD,WAAW,KAAK,mBAAmB,EAAE,KAAK,MAAM,CAAC;GACjD,WAAW,GAAG,UAAU,QAAmB;IACzC,KAAK,OAAO,MACV;KAAE;KAAiB;IAAI,GACvB,wDACF;IACA,kBAAkB,IAAI;GACxB,CAAC;GACD,OAAO,IAAI,SAAS,YAAY,WAAW,GAAG,OAAO,OAAO,CAAC;EAC/D,CAAC;CACH;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/search",
3
- "version": "9.0.0-next-9.16",
3
+ "version": "9.0.0-next-9.18",
4
4
  "description": "Verdaccio Search Proxy",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -33,18 +33,18 @@
33
33
  "node": ">=24"
34
34
  },
35
35
  "dependencies": {
36
- "@verdaccio/config": "9.0.0-next-9.16",
37
- "@verdaccio/core": "9.0.0-next-9.16",
38
- "@verdaccio/logger": "9.0.0-next-9.16",
39
- "@verdaccio/proxy": "9.0.0-next-9.16",
36
+ "@verdaccio/config": "9.0.0-next-9.18",
37
+ "@verdaccio/core": "9.0.0-next-9.18",
38
+ "@verdaccio/logger": "9.0.0-next-9.18",
39
+ "@verdaccio/proxy": "9.0.0-next-9.18",
40
40
  "debug": "4.4.3",
41
41
  "lodash-es": "4.18.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@verdaccio/types": "14.0.0-next-9.7",
45
44
  "@types/lodash-es": "4.17.12",
45
+ "@verdaccio/types": "14.0.0-next-9.9",
46
46
  "nock": "13.5.6",
47
- "vitest": "4.1.0"
47
+ "vitest": "4.1.7"
48
48
  },
49
49
  "funding": {
50
50
  "type": "opencollective",