{"name":"@snyk/dep-graph","version":"2.6.0","author":{"name":"snyk.io"},"license":"Apache-2.0","_id":"@snyk/dep-graph@2.6.0","maintainers":[{"name":"snyk-admin","email":"npmjs+snyk-admin@snyk.io"}],"homepage":"https://github.com/snyk/dep-graph#readme","bugs":{"url":"https://github.com/snyk/dep-graph/issues"},"dist":{"shasum":"fde01bb7837798fb2a4f8168424a1ecf5de09177","tarball":"http://registry-npm.ywwl.com/@snyk/dep-graph/download/@snyk/dep-graph-2.6.0.tgz","fileCount":63,"integrity":"sha512-9NPk7cTvDNA90NyNQvh87LYKgkCoD67i+FGdRpwA0/CL59RRY7cG37RTFe++Y3ZALxpYK1sLNzU+yeB7vzVhqQ==","signatures":[{"sig":"MEUCIErYnmYNr1DblHAUdadb/xGjF669X74wkVFXcB4vTYq7AiEA2zR34tzhthlma1cbD5ZXSoXg7LRsU5/gA8cPxuR9eSI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":127718,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJBc2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq+nQ//RXxHe3OtPEiWV7aryIYBxLaF5TajRD2ofQeqeUQesbii2QTm\r\ndeX1oJa4HnriK3NIIqT3CaYTzrdebwINmZYpQtGSKNZmmQbq1WZwIbVEQCFG\r\ndf9mIchOQQqekMtkbezKV0jiK6yuQx+g2Q/LXT/T2D4mllSfY7MEpCl3qGrc\r\nI16d0o6VHKLisHfOl/GeuZKqqH2DQrLxrxg/PBb/BkSyHJCsP30ndYVBrqa7\r\ngRACqzNPo1G/ov2Tnbxz4+5wZrzrLHGzJqjC96Lkzb+h+jlMzzK1Y45VBOh0\r\n5XGZUTF85LnDv5tSgv7scaYtq5bOphbiuknlfcrlGBxx8kAXzjfbCHz3ykhV\r\nfbec8EQ8HMSLm0lJ6nZ4/DwXWKzZvhR7zUyavqo3S7e1e+0BLAGLITo0bnz3\r\nq0e0hiSQ2dfVCWFXgjcMKwm+377T48MkVRXIhMszjoy5IBw5XP5nsVcvi56Y\r\nY8Ms3XaCDjvyGR1q4ZSyxH5pmjWPAfs0lrgDtxo6Hrzh2GP5iWv+nBQADuyP\r\nKJwh53YIo4jgtAmqwW3U8z+YNSzxSwFDCF3si6F+sgAN88mpmIWjCHDLUEup\r\nqasQRMfBb1xyuHzIbcEThYB7d+7mgmVDMQWtwjRMkMmI+jwZ+RM5Ih9JbSM8\r\nPi+DqTwn6S8//YEefYkDQDOiD47QUKD2iBo=\r\n=bzjE\r\n-----END PGP SIGNATURE-----\r\n","size":31375,"noattachment":false,"key":"/@snyk/dep-graph/-/@snyk/dep-graph-2.6.0.tgz"},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=10"},"gitHead":"cf572808eb3490d34734d30997198804a857b575","scripts":{"lint":"npm run lint:eslint && npm run lint:prettier","test":"jest --verbose --runInBand","build":"tsc","format":"prettier --write '{src,test,scripts}/**/*.?s'","prepare":"npm run build","build-dev":"tsc -w","lint:eslint":"eslint 'src/**/*.ts' && (cd test && eslint '**/*.ts')","lint:prettier":"prettier --check '{src,test,scripts}/**/*.ts'","test:coverage":"npm run test -- --coverage"},"_npmUser":{"name":"snyk-admin","email":"npmjs+snyk-admin@snyk.io"},"repository":{"url":"git+https://github.com/snyk/dep-graph.git","type":"git"},"_npmVersion":"6.14.17","description":"Snyk dependency graph library","directories":{},"_nodeVersion":"14.19.3","dependencies":{"tslib":"^2","semver":"^7.0.0","lodash.map":"^4.6.0","lodash.size":"^4.2.0","object-hash":"^3.0.0","lodash.clone":"^4.5.0","lodash.union":"^4.6.0","lodash.filter":"^4.6.0","lodash.reduce":"^4.6.0","lodash.values":"^4.3.0","packageurl-js":"^1.0.0","lodash.foreach":"^4.5.0","lodash.isempty":"^4.4.0","lodash.isequal":"^4.5.0","lodash.constant":"^3.0.0","lodash.transform":"^4.6.0","lodash.isfunction":"^3.0.9","event-loop-spinner":"^2.1.0","lodash.isundefined":"^3.0.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.5","benny":"^3.6.15","eslint":"^7.29.0","ts-jest":"^27.0.3","ts-node":"^10.0.0","prettier":"^2.3.1","typescript":"~4.6.3","@types/jest":"^27","@types/node":"^10","@types/semver":"^7.3.6","@types/graphlib":"^2.1.7","@types/object-hash":"^2.1.0","eslint-config-prettier":"^8.3.0","@typescript-eslint/parser":"^4.28.0","@typescript-eslint/eslint-plugin":"^4.28.0"},"_npmOperationalInternal":{"tmp":"tmp/dep-graph_2.6.0_1680086838483_0.9439399320762007","host":"s3://npm-registry-packages"},"readme":"![Snyk logo](https://snyk.io/style/asset/logo/snyk-print.svg)\n\n***\n\n[![Known Vulnerabilities](https://snyk.io/test/npm/@snyk/dep-graph/badge.svg)](https://snyk.io/test/npm/@snyk/dep-graph)\n\nSnyk helps you find, fix and monitor for known vulnerabilities in your dependencies, both on an ad hoc basis and as part of your CI (Build) system.\n\n# Snyk dep-graph\n\nThis library provides a time and space efficient representation of a resolved package dependency graph, which can be used to construct, query and de/serialize dep-graphs.\n\n## The Graph\n\nA directed graph, where a node represents a package instance and an edge from node `foo` to node `bar` means `bar` is a dependency of `foo`.\n\nA package (`name@version`) can have several different nodes (i.e. instances) in the graph. This flexibility is useful for some ecosystems, for example:\n\n* in `npm` due to conflict-resolutions by duplication. e.g. try to `npm i tap@5.7` and then run `npm ls` and look for `strip-ansi@3.0.1`. You'll see that in some instances it depends on `ansi-regex@2.0.0` while in others on `ansi-regex@2.1.1`.\n* in `maven` due to \"exclusion\" rules. A dependency `foo` can be declared in the `pom.xml` such that some of it's sub-dependencies are excluded via the `<exclusions>` tag. If the same dependency is required elsewhere without (or with different) exclusions then `foo` can appear in the tree with different sub-trees.\n\nThis can also be used to break cycles in the graph, e.g.:\n\ninstead of:\n```\nA -> B -> C -> A\n```\ncan have:\n```\nA -> B -> C -> A'\n```\n\n## API Reference\n\n### `DepGraph`\n\n#### Interface\n\nA dep-graph instance can be queried using the following interface:\n\n```typescript\nexport interface DepGraph {\n  readonly pkgManager: {\n    name: string;\n    version?: string;\n    repositories?: Array<{\n      alias: string;\n    }>;\n  };\n  readonly rootPkg: {\n    name: string;\n    version?: string;\n    purl?: string;\n  };\n  // all unique packages in the graph (including root package)\n  getPkgs(): Array<{\n    name: string;\n    version?: string;\n    purl?: string;\n  }>;\n  // all unique packages in the graph, except the root package\n  getDepPkgs(): Array<{\n    name: string;\n    version?: string;\n    purl?: string;\n  }>;\n  pkgPathsToRoot(pkg: Pkg): Array<Array<{\n    name: string;\n    version?: string;\n    purl?: string;\n  }>>;\n  directDepsLeadingTo(pkg: Pkg): Array<{\n    name: string;\n    version?: string;\n    purl?: string;\n  }>;\n  countPathsToRoot(pkg: Pkg): number;\n  toJSON(): DepGraphData;\n  equals(other: DepGraph, options?: { compareRoot?: boolean }): boolean;\n}\n```\n\n### `DepGraphData`\n\nA dep-graph can be serialised into the following format:\n\n```typescript\nexport interface DepGraphData {\n  schemaVersion: string;\n  pkgManager: {\n    name: string;\n    version?: string;\n    repositories?: Array<{\n      alias: string;\n    }>;\n  };\n  pkgs: Array<{\n    id: string;\n    info: {\n      name: string;\n      version?: string;\n    purl?: string;\n    };\n  }>;\n  graph: {\n    rootNodeId: string;\n    nodes: Array<{\n      nodeId: string;\n      pkgId: string;\n      info?: {\n        versionProvenance?: {\n          type: string;\n          location: string;\n          property?: {\n            name: string;\n          };\n        },\n        labels?: {\n          [key: string]: string | undefined;\n        };\n      };\n      deps: Array<{\n        nodeId: string;\n      }>;\n    }>;\n  };\n}\n```\n\n### `createFromJSON`\n\n`DepGraphData` can be used to construct a `DepGraph` instance using `createFromJSON`\n\n### `DepGraphBuilder`\n`DepGraphBuilder` is used to create new `DepGraph` instances by adding packages and their connections.\n\n```typescript\n  /**\n   * Instantiates build for given package manager\n   *\n   * @param pkgManager - package manager for which dependcy graph is created\n   * @param rootPkg - root package information\n   *\n   */\n  public constructor(pkgManager: types.PkgManager, rootPkg?: types.PkgInfo)\n\n  /**\n   * Adds node to the graph. Every node represents logical instance of the package in the dependency graph.\n   *\n   * @param pkgInfo - name and version of the package\n   * @param nodeId - identifier for node in the graph, e.g. `package@version`.\n   *                 Must uniquely identify this \"instance\" of the package in the graph,\n   *                 so may need to be more than `package@version` for many ecosystems.\n   *                 If in doubt - ask a contributor!\n   * @param nodeInfo - additional node info, e.g. for version provenance\n   *\n   */\n  public addPkgNode(pkgInfo: types.PkgInfo, nodeId: string, nodeInfo?: types.NodeInfo)\n\n  /**\n   * Makes a connection between parent and its dependency.\n   *\n   * @param parentNodeId - id of the parent node\n   * @param depNodeId - id of the dependency node\n   *\n   */\n  public connectDep(parentNodeId: string, depNodeId: string)\n\n  /**\n   * Creates an instance of DepGraph\n   *\n   * @return DepGraph instance built from provided packages and their connections\n   *\n   */\n  public build(): types.DepGraph\n\n```\n### The `legacy` module\n\nA `DepTree` is a legacy structure used by the Snyk CLI to represent dependency trees. Conversion functions in the `legacy` module ease the gradual migration of code that relies on the legacy format.\n\n#### Legacy `DepTree`\n\nA `DepTree` is a recursive structure that is quite similar to the output of `npm list --json`, and (omitting some details) looks like:\n\n```typescript\ninterface DepTree {\n  name: string;\n  version: string;\n  dependencies?: {\n    [depName: string]: DepTree\n  };\n}\n```\n\nThe `legacy` conversion functions aim to maintain extra data that might be attached to the dep-tree and is dependant upon in code that wasn't yet updated to use solely dep-graphs:\n* `targetOS` which exists on tree roots for Docker scans\n* `versionProvenance` which might exist on the nodes of maven trees, storing information about the source manifest that caused the specfic version to be resolved\n","publish_time":1680086838693,"_cnpm_publish_time":1680086838693,"dist-tags":{"latest":"2.16.11"}}