\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-nodejs20/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.
const { hasOwnProperty } = Object.prototype
const debug = require('./debug.js')

const keys = ['name', 'license', 'funding', 'realpath', 'packageName']
class Inventory extends Map {
  #index

  constructor () {
    super()
    this.#index = new Map()
    for (const key of keys) {
      this.#index.set(key, new Map())
    }
  }

  // XXX where is this used?
  get primaryKey () {
    return 'location'
  }

  // XXX where is this used?
  get indexes () {
    return [...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.location)
    if (current) {
      if (current === node) {
        return
      }
      this.delete(current)
    }
    super.set(node.location, node)
    for (const [key, map] of this.#index.entries()) {
      let val
      if (hasOwnProperty.call(node, key)) {
        // if the node has the value, use it even if it's false
        val = node[key]
      } else if (key === 'license' && node.package) {
        // handling for the outdated "licenses" array, just pick the first one
        // also support the alternative spelling "licence"
        if (node.package.license) {
          val = node.package.license
        } else if (node.package.licence) {
          val = node.package.licence
        } else if (Array.isArray(node.package.licenses)) {
          val = node.package.licenses[0]
        } else if (Array.isArray(node.package.licences)) {
          val = node.package.licences[0]
        }
      } else if (node[key]) {
        val = node[key]
      } else {
        val = node.package?.[key]
      }
      if (val && typeof val === 'object') {
        // We currently only use license and funding
        /* istanbul ignore next - not used */
        if (key === 'license') {
          val = val.type
        } else if (key === 'funding') {
          val = val.url
        }
      }
      if (!map.has(val)) {
        map.set(val, new Set())
      }
      map.get(val).add(node)
    }
  }

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

    super.delete(node.location)
    for (const [key, map] of this.#index.entries()) {
      let val
      if (node[key] !== undefined) {
        val = node[key]
      } else {
        val = 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)
    if (arguments.length === 2) {
      if (map.has(val)) {
        return map.get(val)
      }
      return new Set()
    }
    return map.keys()
  }

  has (node) {
    return super.get(node.location) === node
  }

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

module.exports = Inventory