{"_id":"@amphibian/party","_rev":"5-a40da47f1ab79512930c1d06e12b103e","name":"@amphibian/party","description":"crash parties to avoid executing a function that expects the same result more than once","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@amphibian/party","version":"1.0.0","description":"crash parties to avoid executing a function that expects the same result more than once","main":"index.js","scripts":{"test":"jest --coverage"},"repository":{"type":"git","url":"git+ssh://git@gitlab.com/thomaslindstr_m/party.git"},"author":{"name":"Thomas Lindstrøm","email":"t@hom.as"},"license":"ISC","bugs":{"url":"https://gitlab.com/thomaslindstr_m/party/issues"},"dependencies":{"@amphibian/errors":"^2.0.0","@amphibian/object-has-property":"^1.0.1","@amphibian/validate":"^1.4.0"},"gitHead":"efd2a443b73675098d79a20363b8c0c6f5bc46d7","homepage":"https://gitlab.com/thomaslindstr_m/party#README","_id":"@amphibian/party@1.0.0","_npmVersion":"5.4.2","_nodeVersion":"8.5.0","_npmUser":{"name":"thomaslindstr_m","email":"t@hom.as"},"dist":{"integrity":"sha512-d8AiMDcXvpgnwlSH9dfZeYgqakiwk2GVhe0hSvXHPpLrlk2CvvzX6mrk3PY8N7L/UC4x5PEBEkAdljT9hNpmdQ==","shasum":"159d1ca91b5a5490afaf104d3706916c15eeb86b","tarball":"https://registry.npmjs.org/@amphibian/party/-/party-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDgHzXCsJDuhsFjCe3QiKLRrk7Gj0vS7x13M/AKE+j7KAiEAgSpE9yMLsKizS2mrxoNaaSu9iyYB4MpKkfxnk0TQs2Q="}]},"maintainers":[{"name":"thomaslindstr_m","email":"t@hom.as"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/party-1.0.0.tgz_1508197991639_0.06624636240303516"},"directories":{}},"1.0.1":{"name":"@amphibian/party","version":"1.0.1","description":"crash parties to avoid executing a function that expects the same result more than once","main":"index.js","browser":"browser.js","license":"ISC","scripts":{"test":"npm run lint -s && jest --coverage --bail --forceExit --detectOpenHandles","lint":"amphibian-linter .","prepublishOnly":"babel index.js --out-file browser.js"},"jest":{"testEnvironment":"node"},"repository":{"type":"git","url":"git+ssh://git@gitlab.com/thomaslindstr_m/party.git"},"author":{"name":"Thomas Lindstrøm","email":"t@hom.as"},"bugs":{"url":"https://gitlab.com/thomaslindstr_m/party/issues"},"dependencies":{"@amphibian/errors":"^2.0.0","@amphibian/object-has-property":"^1.0.1","@amphibian/validate":"^1.6.1"},"devDependencies":{"@amphibian/linter":"^1.1.2","babel-cli":"^6.26.0","babel-core":"^6.26.3","babel-preset-env":"^1.7.0","jest":"^23.4.2"},"gitHead":"b136f805c7fccea38785b87468edcab990c4b2c1","homepage":"https://gitlab.com/thomaslindstr_m/party#README","_id":"@amphibian/party@1.0.1","_npmVersion":"6.1.0","_nodeVersion":"8.11.2","_npmUser":{"name":"thomaslindstr_m","email":"t@hom.as"},"dist":{"integrity":"sha512-xZp8N9kg6OqakAFjLhxkBf3jHjXGsopw10+9vHB0yJJU7bJKYxMgneduUw1uo/THhmNV0TopOajiu1eLUggKww==","shasum":"8a9be2de608bd8479da3805d4815b5818f5a559a","tarball":"https://registry.npmjs.org/@amphibian/party/-/party-1.0.1.tgz","fileCount":7,"unpackedSize":212647,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbY5EyCRA9TVsSAnZWagAAGIUP/1ul+6FOhFPujZxjD1Kt\nCTa9HWZAYuL40mEWrSTj0uZuPDvSkoaXamh9nqxvGPErCRzgyn2l92K+bXKj\n8U3OfTm9cBEU91EF7ErbG9Ehs+dCamFaOEBPF4vh1AARuuyV9DxkWRNeaWQz\nMMuo2xITlPaERwiqgjs32DNr6Cw+eegJxQGwLPKLiz1lxTK/PBr6kBInNLaI\nTl0BdCyIrH32oomO1+CFQl32z/3MD/tMP0LA8G9NEkfYhmRHf1fReua5MlFV\niPisABBWyiWvJDPJUblVZD4x0JfT85/nZOP/M79ks2ZRYIl1IxOPprSsbM7E\nXzH6zBXFc0e9sSXUsnO/3uLagkUzXh+9rjEijyGqUrcT4/+jJohTr/c8VniH\nWbWvR/xrXZp1M/R7lGIFjMsGOkxJYcyDsnyZVJ1eIExrfW86afdTR1yZuecI\npGGo9c5XuEWVzpSh02n27mqOf5L7L/0SrNuNzGgvutEi5kxTfdw/dmJymzN3\nhe6LG1wmlRWXCvfc3zH4W2YuZNs1po3JmXTuAjSVEVEaS+RgD/xknyrYQuQ0\na0kOIYTswa01i1+zN32/jNfwnY7B6RUmfM6ByVdxv6OS9J0gk0QDIUEElpBN\nk8vKZIIOYUyZzoiX/x5xTFtUFzRoXOV9JAMsE/G7BZT4ndYy69oo5m7ekhci\nNKJ7\r\n=xsbs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDEA0GRPgb+PcQiMVUTmgsz0zONCgVWvU/VKMN7jAkDMQIgI1qm7qjYr9r9/M2TUu7CwIXUbK1eCMO4RZmaAhsDBtc="}]},"maintainers":[],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/party_1.0.1_1533251890383_0.4350233686167073"},"_hasShrinkwrap":false},"1.0.2":{"name":"@amphibian/party","version":"1.0.2","description":"crash parties to avoid executing a function that expects the same result more than once","main":"index.js","browser":"browser.js","license":"ISC","scripts":{"test":"npm run lint -s && jest --coverage --bail --forceExit --detectOpenHandles","lint":"amphibian-linter .","prepublishOnly":"babel index.js --out-file browser.js"},"jest":{"testEnvironment":"node"},"repository":{"type":"git","url":"git+ssh://git@gitlab.com/thomaslindstr_m/party.git"},"author":{"name":"Thomas Lindstrøm","email":"t@hom.as"},"bugs":{"url":"https://gitlab.com/thomaslindstr_m/party/issues"},"dependencies":{"@amphibian/errors":"^2.0.0","@amphibian/object-has-property":"^1.0.1"},"devDependencies":{"@amphibian/linter":"^1.1.2","babel-cli":"^6.26.0","babel-core":"^6.26.3","babel-preset-env":"^1.7.0","jest":"^23.4.2"},"gitHead":"4c647e3ca1978f432dad5d54d1f2d5d99a432647","homepage":"https://gitlab.com/thomaslindstr_m/party#readme","_id":"@amphibian/party@1.0.2","_npmVersion":"6.4.1","_nodeVersion":"8.11.2","_npmUser":{"name":"thomaslindstr_m","email":"t@hom.as"},"dist":{"integrity":"sha512-FmFN82VdAUWDv4ToGXwuNEZviHy3KbceLw+CvGHJZIYQtXNxGRVb0L5whtCF7RuQGx5HJLt2BNZpkGQS9B8g0Q==","shasum":"ddc2d9078b8dc517dc80f6d5a536a0424914821b","tarball":"https://registry.npmjs.org/@amphibian/party/-/party-1.0.2.tgz","fileCount":7,"unpackedSize":207461,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbpBdPCRA9TVsSAnZWagAA+0oP/1yKvtqbDtngUCoZWee3\n2b9FD9pqMgRrM8Kiuo13fD/Cm5OdXmhpsfyC2cwhYWyFfrrprGdvxu5qZDwr\nCEGrCnp3yPd9C3AZsPs4UmJ22+PEAkprYhLrgPf/0EpRtvXva2oF0m1qAQsy\nhpdgkULYqkb1SMMbMwpWtn+UdbvoCByxlaCPLvrZOMWYIdY3rVZULZ6z1MaP\nNVoajGXJ/Ag6BbNeF8uHl/cXXVYJTsosU7otyhtfK6OuhmnH6JOceegZtddh\nbSAinL4eTUZ6+BoDZCeS8wYaYETY8v/7ijwbuU27QYzWdqqw1MG1RLa1lvl2\noKo/9kNMMOEtzIi/SGAb9cRhAyuYbAckaJ1p99O9jaHOD+UfqXqF5E0rCW5A\n3Ls24mPtGSlsqCRkybBUKtiwYaEhYsS337zF4h4rxjLhT9EitrIBqz0w0LGi\ncS9Rm4P9yQ/6oMdiXVIXlAnNUwpCNYEOG2AsXU2WnIW2vg/dEgOne+Ua5QsU\nKbAnPd9JibBXT66uCA/Ww+TOlGROyoRsvT8Z7Bq9wstkTZdaB1xcW11GpTFT\n1GGZzuldE2rzoasU9r1AcJ07b7Y5LP2giUCB/tq/W1ZxYVeVESU6ZWDYog4C\ncqd43qkgf56N3X9UJWxU/WRwfLBxF142C4dRghXW0MpWckkR/TI8PhTS3oK1\ne6b/\r\n=w9sj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEeznL2u5zbJfzH+ggQ1eyU+9ySpYJXqoYL0N3L7168UAiBbbmkg2XQ5jNx0O4O1wNza9akZ9gy1lO4P1dU4zP9hIw=="}]},"maintainers":[],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/party_1.0.2_1537480526640_0.39671820883021236"},"_hasShrinkwrap":false}},"readme":"# party\n\n[![build status](https://gitlab.com/thomaslindstr_m/party/badges/master/build.svg)](https://gitlab.com/thomaslindstr_m/party/commits/master)\n\ncrash parties to avoid executing a function that expects the same result more than once. *pretty much an utility to batch equal requests together into one, to avoid doing the same operation twice*.\n\n```\nnpm install @amphibian/party\n```\n\n```javascript\nconst parties = require('@amphibian/party');\n\n// Assume a hypothetical asynchronous pure function\n// NOTE Pure functions always return the same result given identical arguments.\nfunction fetchPartyList(url) {\n    const requestId = `fetchPartyList:${url}`;\n    const party = parties(requestId);\n\n    if (party.exists()) {\n        return party.crash();\n    }\n\n    return party.host(\n        fetch(`${PARTY_API_URL}/parties/list`)\n            .then((response) => response.json())\n            .then((response) => response.partyList)\n    );\n}\n\n// Instead of calling “fetch” three times, triggering three separate network requests, this will, when utilizing @amphibian/party, only trigger one\nfetchPartyList();\nfetchPartyList();\nfetchPartyList();\n```\n\n## `parties`\n\nReturns a `party` `Object` provided the required `id` argument.\n\n```javascript\nconst party = parties('my-unique-party-id');\n```\n\n### `party.exists`\n\nReturns a `Boolean` describing the existence of the party. A `party` exists when it's currently being hosted.\n\n```javascript\nparty.exists(); // false\n```\n\n### `party.host`\n\nTakes `Promise` as an argument that should resolve or reject when the task is complete. When a `party` is being hosted, it may be `crash`ed.\n\n```javascript\nparty.host(new Promise((resolve, reject) => {\n    setTimeout(() => {\n        resolve('thanks for waiting');\n    }, 1000);\n}));\n```\n\n### `party.crash`\n\nCrashes the current party. In effect, `party.crash()` just returns the `host`ed `Promise`.\n\n```javascript\nparty.crash().then((message) => {\n    console.log(message); // > 'thanks for waiting'\n});\n```\n\n## Usage with @amphibian/cache\n\nTo [hypercharge](https://media.giphy.com/media/E5TVttEnaz4ME/giphy.gif) your functions, consider utilizing [@amphibian/cache](https://www.npmjs.com/package/@amphibian/cache) in companionship with `@amphibian/party`.\n\n```javascript\nconst parties = require('@amphibian/party');\nconst cache = require('@amphibian/cache').createCache();\n\nfunction fetchPartyList(url) {\n    const requestId = `fetchPartyList:${url}`;\n    const cache = cache.open(requestId);\n\n    if (cache.fresh()) {\n        return Promise.resolve(cache.get());\n    }\n\n    const party = parties(requestId);\n\n    if (party.exists()) {\n        return party.crash();\n    }\n\n    return party.host(\n        fetch(`${PARTY_API_URL}/parties/list`)\n            .then((response) => response.json())\n            .then(({partyList}) => {\n                cache.set(partyList, {lifetime: 1000 * 30});\n                return partyList;\n            })\n    );\n}\n```\n","maintainers":[{"email":"t@hom.as","name":"thomaslindstr_m"}],"time":{"modified":"2022-04-04T13:51:42.140Z","created":"2017-10-16T23:53:12.613Z","1.0.0":"2017-10-16T23:53:12.613Z","1.0.1":"2018-08-02T23:18:10.550Z","1.0.2":"2018-09-20T21:55:26.844Z"},"homepage":"https://gitlab.com/thomaslindstr_m/party#readme","repository":{"type":"git","url":"git+ssh://git@gitlab.com/thomaslindstr_m/party.git"},"author":{"name":"Thomas Lindstrøm","email":"t@hom.as"},"bugs":{"url":"https://gitlab.com/thomaslindstr_m/party/issues"},"license":"ISC","readmeFilename":"readme.md"}