{"_id":"@almgong/jarvus","name":"@almgong/jarvus","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@almgong/jarvus","version":"1.0.0","description":"General purpose action executor package.","main":"dist/index.js","types":"dist/index.d.ts","type":"module","scripts":{"prebuild":"eslint --fix *.ts","build":"tsup","test":"mocha --require tsx test/*.spec.ts test/*/*.spec.ts"},"author":{"name":"@almgong"},"license":"MIT","devDependencies":{"@eslint/js":"^9.2.0","@types/eslint__js":"^8.42.3","@types/mocha":"^10.0.6","@types/pubsub-js":"^1.8.6","@types/sinon":"^17.0.3","eslint":"^8.57.0","globals":"^15.1.0","mocha":"^10.4.0","sinon":"^17.0.2","tsup":"^8.0.2","tsx":"^4.9.3","typescript":"^5.4.5","typescript-eslint":"^7.8.0"},"dependencies":{"pubsub-js":"^1.9.4"},"_id":"@almgong/jarvus@1.0.0","gitHead":"59653029d003aa94276eabe4b1c53c0146acb732","_nodeVersion":"22.1.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-bKakujkLhW6XcIgyKdSGY9zsj2z/TKxypLZGR8Gt/2pUGaxXmD7UaEFijVPHRXp1bfDX3WSLrYcw9n0fQdk8Zw==","shasum":"3d1080db1ac54da93c4f9244a13a59b96808035a","tarball":"https://registry.npmjs.org/@almgong/jarvus/-/jarvus-1.0.0.tgz","fileCount":6,"unpackedSize":12551,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD7eySXTY34IFcDvowL7UgybkENfIPwktyp0T/Xavn1vAIhALEbo5Oc5WNUaAOqs/g57paVaIFPDoHhf+irKOLltRgz"}]},"_npmUser":{"name":"almgong","email":"alm.gong@gmail.com"},"directories":{},"maintainers":[{"name":"almgong","email":"alm.gong@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jarvus_1.0.0_1715719566922_0.48838684949263045"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-14T20:46:06.789Z","1.0.0":"2024-05-14T20:46:07.128Z","modified":"2024-05-14T20:46:07.471Z"},"maintainers":[{"name":"almgong","email":"alm.gong@gmail.com"}],"description":"General purpose action executor package.","author":{"name":"@almgong"},"license":"MIT","readme":"# Jarvus\n\nSmall (just over 1kb) package for executing arbitrary actions (operations, work) based on specified data. Work is done asynchronously and in a decentralized fashion.\n\n## Installation\n\n```\nnpm install @almgong/jarvus\n```\n\n## Usage\n\nAll work-to-do is represented by Action classes in Jarvus. After defining such a class, one simply needs to `#add` an instance of the action to Jarvus' registry.\n\nLet's go through a real(ish) world example.\n\nWe have an ML model that returns text content based on some input. When the model returns 'car', we want to log a car result; when the model returns 'bicycle', we want to log a bicycle result instead.\n\nOur car-`Action` class\n\n```\nimport { Action } from '@almgong/jarvus';\n\nclass CarFoundAction extends Action {\n  shouldRun(payload) {\n    payload.text === 'car';\n  }\n\n  execute(payload) {\n    MyLoggerService.notify(\n      { type: 'vehicle/car', originalImg: payload.imgUrl }\n    );\n  }\n}\n```\n\nand for more flavor, our bicycle-`Action` class\n\n```\nimport { Action } from '@almgong/jarvus';\n\nclass BicycleFoundAction extends Action {\n  shouldRun(payload) {\n    // our model is not quite as accurate when it comes to\n    // detecting bikes\n    payload.text === 'bicycle' && payload.confidence > 0.98;\n  }\n\n  execute(payload) {\n    MyLoggerService.notify(\n      {\n        type: 'vehicle/bicycle',\n        originalImg: payload.imgUrl,\n        confidence: payload.confidence\n      }\n    );\n  }\n}\n```\n\nAnd to wire it all up\n\n```\nimport Jarvus from '@almgong/jarvus';\n\nconst jarvus = new Jarvus();\njarvus.add(new CarFoundAction('cars'));\njarvus.add(new BicycleFoundAction('bicycles));\n\n...\n\njarvus.send({ text: 'car', confidence: .82, imgUrl: '...' }); // executes our car action\n\njarvus.send({ text: 'bicycle', confidence: .82, imgUrl: '...' }); // does not execute any action\njarvus.send({ text: 'bicycle', confidence: .91, imgUrl: '...' }); // executes our bicycle action\n```\n\n## Actions\n\n`Action` subclasses must define two methods:\n\n`shouldRun(payload: object) : boolean` - whether the action should run\n\n`execute(payload: object) : void` - what the action should do if it should run\n\nThe `payload` object in both methods will be the same for any given `Action`, and but can be customized across `Action`s.\n\nAll `Action` instances must have a unique identifier, specified on instantiation. This helps guard against duplicate registrations and provides a path for debugging and metric gathering.\n\n## Jarvus API\n\nThe `Jarvus` class exposes three public methods:\n\n`add(action: Action) : void` - add the action to the registry\n\n`remove(action: Action) : void` - remove the action from the registry\n\n`send(payload: object) : void` - dispatch an arbitrary payload and let actions determine if they need to run\n\n## License\n\nMIT\n","readmeFilename":"README.md"}