{"_id":"@vkontakte/graph-cache","_rev":"27-24987ebf347e934c2c2d4223c8e9633f","name":"@vkontakte/graph-cache","dist-tags":{"latest":"1.1.1"},"versions":{"1.1.1":{"name":"@vkontakte/graph-cache","version":"1.1.1","description":"This library provides easy way to build and maintain persistent dependency graph for any type of files/languages. It provides a high-level set of operations on graph to fulfill common use cases, when working with dependency graphs.","main":"index.js","scripts":{"test":"mocha ./tests/lib/*.js","test-watch":"mocha ./tests/lib/*.js -w","build":"babel --presets es2015 -d build/ lib/"},"author":{"name":"Termina1"},"license":"MIT","devDependencies":{"babel-cli":"^6.10.1","babel-preset-es2015":"^6.9.0","chai":"^3.5.0","chai-as-promised":"^5.3.0","memory-fs":"^0.3.0","mocha":"^2.5.3"},"dependencies":{"graphlib":"^2.1.0","lodash.difference":"^4.3.0","lodash.differenceby":"^4.6.0","lodash.includes":"^4.3.0","lodash.uniq":"^4.3.0","object-assign":"^4.1.0"},"gitHead":"e8cdfb31c4facec5d3521c8ba60398c294bc341e","_id":"@vkontakte/graph-cache@1.1.1","_npmVersion":"6.4.1","_nodeVersion":"10.10.0","_npmUser":{"name":"k.egor.smirnov","email":"k.egor.smirnov@gmail.com"},"dist":{"integrity":"sha512-TAKKBmmHDExEZbtKZAOV0Lv9RdbQRSiiLDjoqITjhtkpT7cvfrK32lFgrdtTJIq4VoDwNMflbXy2ds6rjEfKlw==","shasum":"6d1d82fec7743000e282a8642703b081d8d8462d","tarball":"https://registry.npmjs.org/@vkontakte/graph-cache/-/graph-cache-1.1.1.tgz","fileCount":30,"unpackedSize":55297,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2gkOCRA9TVsSAnZWagAAIYwQAJCrsCHZJrvnw7mF3AMz\nHxsqaByFPLiqekX3pijcWoeHngN0W+5+qXAYOtdbymyWPo/TL4gr+QkjccbW\ntLQ/uXEVSl06ofQJOSL6jM5CUaU9OZwECqYWoujiYPsPwk/GyM0tHov/ES6d\ngGO9YakC/g2S/X241L146a6wv6mQnPwg7eQgt14oiVdzfLtkKVIiL/deY4uO\nuidrezfNSU/1UGDG/ppDD3B+OQ6f4xlyaUytnwmKnNvwzAyg5rL1w5u5TwWs\nA9pw8ieV7ligP/EE++sKbdUTPKDg4EBtES/SBHLSa8fzJ/KKlllQJjvcmGnG\n8z2Y/uoURYNNF1yyGqZRe1p4f2e8jw98mInfbHAXm/zUM6emLcZmKUFJNPZq\n63OvOFpdkfj2c+QGf8cCQf5XxyBXQ2HArzX0yRyH5zbw2WcAwASjiGWmPkN3\nSbhVkb21OA5KwWU0XugoXvome60U8lGgJl7QKuA64ociWs+l2522/lTcJRWb\nE7PSlXiN6xtAuyjZUI/b446031cv6zklZuGjtjsSGhiBP7SXoXfjssadccpp\nRkMU9KzewshTpS8x08hu8D5uMnNt2DmJfWDgLMJdf3S12fjX0eydiyFmdw0v\nR9wLn+xl0fJQFQSHzhNsKPmjUTVbWNXxkpLtMqM1CxZ8Tt2w/IihW1z0nW7k\nW0Pg\r\n=Z+Bt\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC3fJ5wWXLwWCz1G6I78qabcPg/AZ43BLQ4DAQLCpKOHQIgMBfaUh8jIFHbrCwaQJ0CO/6zphEU0Y/YgDGIgqm7hm8="}]},"maintainers":[{"name":"k.egor.smirnov","email":"k.egor.smirnov@gmail.com"},{"name":"kuhel","email":"vorontsov.gleb@gmail.com"},{"name":"tsivarev","email":"tsivarev.a@gmail.com"},{"name":"vkcom","email":"mobileapps.vk@gmail.com"},{"name":"artur_supertramp","email":"bumbledos@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graph-cache_1.1.1_1549375711503_0.6909303345398852"},"_hasShrinkwrap":false}},"time":{"created":"2019-02-05T14:08:31.329Z","1.1.1":"2019-02-05T14:08:31.670Z","modified":"2024-04-15T13:48:26.863Z"},"maintainers":[{"email":"k.egor.smirnov@gmail.com","name":"k.egor.smirnov"}],"description":"This library provides easy way to build and maintain persistent dependency graph for any type of files/languages. It provides a high-level set of operations on graph to fulfill common use cases, when working with dependency graphs.","author":{"name":"Termina1"},"license":"MIT","readme":"# graph-cache\n\nThis library provides easy way to build and maintain persistent dependency graph for any type of files/languages.\nIt provides a high-level set of operations on graph to fulfill common use cases, when working with dependency graphs.\n\n```graph-cache``` is language agnostic, you can provide a parser for any type of files (JS, LESS, SASS, etc).\n\nThis library is built on top of the [graphlib](https://github.com/cpettitt/graphlib) npm package.\n\n## Use cases\n\nThe simplest use case is if you want to build persistent cache for some language that supports importing files from other files.\n\nThe reason I created it was that I needed to build persistent cache for ```LESS``` language.\n\nProject I was working on consisted of hundreds of files, and I wanted to\nrecompile only those that changed while deploying code.\n\n## Installation\n\n```npm install --save graph-cache```\n\n## Usage\n```javascript\nconst createGraphCache = require('graph-cache');\n\nconst gcache = createGraphCache(parser, sign, {\n  persistence: false\n});\n\ngcache.then((cache) => cache.checkFile(file, name));\n```\n\nAPI\n\n### constructor\n```javascript\nconst createGraphCache = require('graph-cache');\nconst gcache = createGraphCache(parser, sign, opts);\n```\n\n- parser — this is a function that takes a ```sign function```, file ```Buffer``` and file name.\n```javascript\nparser(sign, file, filename)\n```\n\n```Parser``` function should return ```Promise``` that resolves into full dependency graph of given file as an instance of ```graphlib``` graph. Example of parser function is [graph-cache-less](https://github.com/VKCOM/graph-cache-less).\n\n- sign — sign function, which takes ```Buffer``` and returns string (hash), that identifies this file, i.e. md5.\n- opts — options object\n```javascript\n{\n  persistence: 'test.txt', // string, file name where graph will be stored\n  g: new Graph({ directed: true }), // initial graph, ignored if persistence is set\n  targetFs: fs, // if you want to store graph in memory for some reasons\n  cacheVersion: false, // this is the version, that should match the version stored in cache file,\n                       //if differs, cache will be discarded\n}\n```\n\nReturns ```Promise```, that will resolve into ```Cache``` object.\n\n### Cache object\n\nIt container cache API.\n\n#### checkFile(file, filename)\n\nThis method allows tou to check whether this file or its deps has changed.\n\n- file — ```Buffer``` with file contents\n- filename — file name\n\nReturns ```Promise``` that will resolve into false if file or its dependencies has changed, otherwise it will be resolved into true.\n\n#### rebuildFromFile(file, filename)\n\nThis method allows you to update your cache with file and its dependency subgraph and merge it to existing graph.\nChanges won't take effect until you call ```swapGraphs```.\n\n- file — ```Buffer``` with file contents\n- filename — file name\n\n#### getChangedLeafs(file, filename)\n\nThis method allows you to obtain all leaf-files, that depend on the given file.\n\n- file — ```Buffer``` with file contents\n- filename — file name\n\nReturns ```Promise``` that will be resolved int list with leaf-file names.\n\n#### saveGraph()\n\nThis method allows you to save graph to disk or target fs.\n\nReturns ```Promise``` when saving is done.\n\n#### swapGraphs()\n\nWhen you call ```rebuildFromFile``` resulting graph is not yet used, until you call this method.\nThis is a way of ```committing``` changes to your dependency graph.\n\nReturns null\n\n#### visualise(dest)\n\nThis method will create HTML-file with your dependency graph visualisation.\n\n- dest — destination for saving file with visualisation\n\nReturns ```Promise```\n\n## Testing\n\nThis library is tested using ```Mocha``` and ```Chai```. You can run test suit with ```npm test```.\nYou can run ```npm run test-watch``` to rerun tests on file updates.\n\n## Contributing\n\nThis library is written using ES6 code.\nBefore pushing run ```npm run build``` to generate ES5 compatible js code.\nIssues and PR's are welcomed here.\n","readmeFilename":"README.md"}