\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/alt/alt-nodejs19/root/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/

Viewing File: inventory.js

// a class to manage an inventory and set of indexes of
// a set of objects based on specific fields.
// primary is the primary index key.
// keys is the set of fields to be able to query.
const _primaryKey = Symbol('_primaryKey')
const _index = Symbol('_index')
const defaultKeys = ['name', 'license', 'funding', 'realpath', 'packageName']
const { hasOwnProperty } = Object.prototype
const debug = require('./debug.js')

// handling for the outdated "licenses" array, just pick the first one
// also support the alternative spelling "licence"
const getLicense = pkg => {
  if (pkg) {
    const lic = pkg.license || pkg.licence
    if (lic) {
      return lic
    }
    const lics = pkg.licenses || pkg.licences
    if (Array.isArray(lics)) {
      return lics[0]
    }
  }
}

class Inventory extends Map {
  constructor (opt = {}) {
    const { primary, keys } = opt
    super()
    this[_primaryKey] = primary || 'location'
    this[_index] = (keys || defaultKeys).reduce((index, i) => {
      index.set(i, new Map())
      return index
    }, new Map())
  }

  get primaryKey () {
    return this[_primaryKey]
  }

  get indexes () {
    return [...this[_index].keys()]
  }

  * filter (fn) {
    for (const node of this.values()) {
      if (fn(node)) {
        yield node
      }
    }
  }

  add (node) {
    const root = super.get('')
    if (root && node.root !== root && node.root !== root.root) {
      debug(() => {
        throw Object.assign(new Error('adding external node to inventory'), {
          root: root.path,
          node: node.path,
          nodeRoot: node.root.path,
        })
      })
      return
    }

    const current = super.get(node[this.primaryKey])
    if (current) {
      if (current === node) {
        return
      }
      this.delete(current)
    }
    super.set(node[this.primaryKey], node)
    for (const [key, map] of this[_index].entries()) {
      // if the node has the value, but it's false, then use that
      const val_ = hasOwnProperty.call(node, key) ? node[key]
        : key === 'license' ? getLicense(node.package)
        : node[key] ? node[key]
        : node.package && node.package[key]
      const val = typeof val_ === 'string' ? val_
        : !val_ || typeof val_ !== 'object' ? val_
        : key === 'license' ? val_.type
        : key === 'funding' ? val_.url
        : /* istanbul ignore next - not used */ val_
      const set = map.get(val) || new Set()
      set.add(node)
      map.set(val, set)
    }
  }

  delete (node) {
    if (!this.has(node)) {
      return
    }

    super.delete(node[this.primaryKey])
    for (const [key, map] of this[_index].entries()) {
      const val = node[key] !== undefined ? node[key]
        : (node[key] || (node.package && node.package[key]))
      const set = map.get(val)
      if (set) {
        set.delete(node)
        if (set.size === 0) {
          map.delete(node[key])
        }
      }
    }
  }

  query (key, val) {
    const map = this[_index].get(key)
    return map && (arguments.length === 2 ? map.get(val) : map.keys()) ||
      new Set()
  }

  has (node) {
    return super.get(node[this.primaryKey]) === node
  }

  set (k, v) {
    throw new Error('direct set() not supported, use inventory.add(node)')
  }
}

module.exports = Inventory