{"_id":"@bveenema/node-red-context-pubsub","name":"@bveenema/node-red-context-pubsub","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@bveenema/node-red-context-pubsub","version":"0.0.1","description":"Nodes for managing global context using pub/sub","keywords":["node-red","node-red-contrib","context","publish","subscribe"],"repository":{"type":"git","url":"git+https://github.com/bveenema/node-red-context-pubsub.git"},"bugs":{"url":"https://github.com/bveenema/node-red-context-pubsub/issues"},"homepage":"https://github.com/bveenema/node-red-context-pubsub#readme","node-red":{"nodes":{"publish-context":"nodes/publish-context/publish-context.js","subscribe-context":"nodes/subscribe-context/subscribe-context.js"}},"scripts":{"test":"jest \".*.test.js\""},"author":{"name":"Ben Veenema"},"contributors":[{"name":"Siiri Mangus"},{"name":"Mikk Mangus"}],"license":"MIT","dependencies":{"jsonata":"^2.0.6","lodash":"^4.17.21","pubsub-js":"^1.9.5"},"devDependencies":{"jest":"^29.5.0","node-red":"^3.0.2","node-red-node-test-helper":"^0.3.0"},"_id":"@bveenema/node-red-context-pubsub@0.0.1","gitHead":"aa93073cf24423caef129825159aae52f144ad66","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-L65dwayo+Aj7ItiUYSAx8JE0nRXxdYVf/OaKeIAlCISAXm0aQa6MmyO3u46kCp1joGMlxDHs2zSoLFCeDKb5CA==","shasum":"6b1038c17f083e6013a67ee2d99778e9243f47bc","tarball":"https://registry.npmjs.org/@bveenema/node-red-context-pubsub/-/node-red-context-pubsub-0.0.1.tgz","fileCount":14,"unpackedSize":135199,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCL499nxat0uuJUJP1Wzf7VKuGt+d/1eW9eKe8g/E45MQIgalRKnoP47uos6uMBfbCUVy+G/kgnnXWIfDquHRw1Yt0="}]},"_npmUser":{"name":"bveenema","email":"bveenema@gmail.com"},"directories":{},"maintainers":[{"name":"bveenema","email":"bveenema@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/node-red-context-pubsub_0.0.1_1745528740911_0.05975963233180215"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-24T21:05:40.791Z","0.0.1":"2025-04-24T21:05:41.134Z","modified":"2025-04-24T21:05:41.460Z"},"maintainers":[{"name":"bveenema","email":"bveenema@gmail.com"}],"description":"Nodes for managing global context using pub/sub","homepage":"https://github.com/bveenema/node-red-context-pubsub#readme","keywords":["node-red","node-red-contrib","context","publish","subscribe"],"repository":{"type":"git","url":"git+https://github.com/bveenema/node-red-context-pubsub.git"},"contributors":[{"name":"Siiri Mangus"},{"name":"Mikk Mangus"}],"author":{"name":"Ben Veenema"},"bugs":{"url":"https://github.com/bveenema/node-red-context-pubsub/issues"},"license":"MIT","readme":"# node-red-context-pubsub\r\n\r\nThis project features publish and subscribe nodes for global context. It is especially useful for state management through global context, providing a [tag browser style](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/tag-browser) interface for your node-red project and aggregating your applications data and events into a local [unified namespace](https://www.iiot.university/blog/what-is-uns%3F).\r\n\r\nThis project was orignally inspired by [node-red-contrib-context-pubsub](https://flows.nodered.org/node/@siirimangus/node-red-contrib-context-pubsub) but is a near complete re-write, with a different underlying pub/sub engine and providing many more features.\r\n\r\n**Note: This package should be considered in beta stage. It has been tested in nominal cases but not in production. Use with care. Expect issues**\r\n\r\n## Installation\r\n\r\nEither use the Manage Palette option in the Node-RED menu, run the following command in your Node-RED user directory, or add it to your Dockerfile\r\n\r\n```\r\nnpm install --production --save @bveenema/node-red-context-pubsub\r\n```\r\n\r\nOmit the `--production` flag, in order to install the development dependencies for testing and coverage. Omit `--save` if you don't want to add it to your package.json.\r\n\r\n## Usage\r\n`Context Pub/Sub` provides two simple nodes, publish-context and subscribe-context. They can be used very basically and expanded on as your application develops.\r\n\r\n### publish-context\r\nThis node stores data in Node-Reds global context. After the value is set, it triggers any `subscribe-context` nodes that are listening, causing them to trigger their flow.\r\n\r\nPublish Context has the following inputs:\r\n- Name - Name of the node\r\n- Property - Name of the property to store the value in global context. Can use dot notation to update at sepecific point in global context (ex: \"model.view.valveTable)\r\n- Action - Replace or Append\r\n- Value - a function to process the incoming msg object and return whatever should be published to property\r\n\r\n**IMPORTANT!** In order for the subscribe-context node to work, global context must be updated using this Node! Any context updated outside this node will NOT trigger subscribing nodes, but will update global context\r\n\r\n### subscribe-context\r\nThis node listens for changes in the global context that are updated by the `publish-context` node. When the subscribed global context changes, the triggers a message with the following format\r\n```json\r\n{\r\n    \"payload\": {type: any}, // the new value - the type will be that of the subscribed value stored in global context\r\n    \"previousValue\": {type: any}, // the previous value - the type will be that of the subscribed value stored in global context\r\n    \"changedPaths\": {type: array}, // the full path to all the properties in the payload that changed\r\n    \"changedProperties\": {type: array}, // the properties in the payload that changed\r\n    \"subscribedPattern\": {type: string}, // the matched pattern of the subscriber\r\n}\r\n```\r\n\r\nSubscribe supports\r\n- subscriptions of any depth (ie, publishes to `model.view.valveTable` will trigger subscriptions to `model` and `model.view`)\r\n- multiple subscriptions per node, with each subscription resulting in a separate message triggering a flow\r\n- dynamic subscriptions using:\r\n  - Wildcards (`model.view.*Table` or `model.*Valve.currentValue.value`)\r\n  - Regex (`model\\.[^.]*Valve\\.(current|target)State\\.value$` *the value of either the currentState or targetState of any key ending in \"Valve\" in model*)\r\n  - JSONata (`model.**[type=\"Valve\"]` *any key in model that has a subkey \"type\" of value \"Valve\", ie - all \"Valve\" type objects in model*)\r\n\r\n**Note: Dynamic Subscriptions use considerably more processing power than standard subscriptions. Care should be taken in their deployment**\r\n\r\n\r\n## Example Flows\r\nSeveral example flows are included to demonstrate different features:\r\n- `examples/basic.json` - Basic usage of set and subscribe\r\n- `examples/deep-subscribe.json` - Deep property subscriptions\r\n- `examples/multi-subscribe.json` - Multi value subscriptions\r\n- `examples/dynamic-subscribe.json` - Working with dynamic property updates\r\n- `examples/append-publish.json` - Appending to the global context instead of Replacing\r\n- `examples/stress-test.json` - A simple stress test that triggers multiple dynamic subscriptions frequently\r\n\r\n## Contribution\r\n\r\nTo setup your local development environment first clone this repository, then use a container runtime to get your node-red environment up and running.\r\n\r\nUsing Podman:\r\n```bash\r\npodman run -p 1880:1880 -v $(pwd):/data/node_modules/@bveenema/node-red-context-pubsub -d --name node-red-context-pubsub nodered/node-red\r\n```\r\n\r\nOr using Docker:\r\n```bash\r\n# For Linux/Mac:\r\ndocker run -p 1880:1880 -v \"$(pwd)\":/data/node_modules/@bveenema/node-red-context-pubsub -d --name node-red-context-pubsub nodered/node-red\r\n\r\n# For Windows PowerShell:\r\ndocker run -p 1880:1880 -v ${PWD}:/data/node_modules/@bveenema/node-red-context-pubsub -d --name node-red-context-pubsub nodered/node-red\r\n```\r\n\r\nAfter you saved your changes to the code update the installation within the container with this command:\r\n\r\nFor Podman:\r\n```bash\r\npodman exec -it node-red-context-pubsub npm install /data/node_modules/@bveenema/node-red-context-pubsub/ && podman restart node-red-context-pubsub\r\n```\r\n\r\nFor Docker:\r\n```bash\r\n# For Linux/Mac:\r\ndocker exec -it node-red-context-pubsub npm install /data/node_modules/@bveenema/node-red-context-pubsub/ && docker restart node-red-context-pubsub\r\n\r\n# For Windows PowerShell:\r\ndocker exec -it node-red-context-pubsub npm install /data/node_modules/@bveenema/node-red-context-pubsub/; docker restart node-red-context-pubsub \r\n```\r\n\r\n## Roadmap\r\n- Build JSONata and Regex testing environments","readmeFilename":"README.md","_rev":"1-dfd6d8b57ccde41c9166145af13b33a6"}