{"id":28426399,"url":"https://github.com/loganbfisher/topic-validator","last_synced_at":"2025-08-15T23:18:05.859Z","repository":{"id":57378081,"uuid":"114282002","full_name":"loganbfisher/topic-validator","owner":"loganbfisher","description":"Used to filter topic messages in the past to build a state object to use when validating incoming messages.","archived":false,"fork":false,"pushed_at":"2017-12-19T20:12:08.000Z","size":276,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-13T20:48:43.506Z","etag":null,"topics":["cqrs","kafka","node-module","nodejs","replay","topic","topic-modeling"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loganbfisher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-14T18:13:41.000Z","updated_at":"2017-12-14T18:25:44.000Z","dependencies_parsed_at":"2022-09-19T19:20:30.370Z","dependency_job_id":null,"html_url":"https://github.com/loganbfisher/topic-validator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/loganbfisher/topic-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loganbfisher%2Ftopic-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loganbfisher%2Ftopic-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loganbfisher%2Ftopic-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loganbfisher%2Ftopic-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loganbfisher","download_url":"https://codeload.github.com/loganbfisher/topic-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loganbfisher%2Ftopic-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270644762,"owners_count":24621332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cqrs","kafka","node-module","nodejs","replay","topic","topic-modeling"],"created_at":"2025-06-05T11:10:19.341Z","updated_at":"2025-08-15T23:18:05.838Z","avatar_url":"https://github.com/loganbfisher.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Background\n\nThis package was created the help keep track of messages in an existing topic in kafka for use with validation when creating, updating, or deleting new messages. Instead of having a completely different service to store and check records I created this package to maintain a local version of the state so far. In some instances you might still need to create a separate service for tracking state in your topics get to be too big. In my app I create a consumer and consume all messages from the beginning of a topic. We use domain topics for better replay-ability.\n\nI would love to hear input from others around the current problem this package is trying to solve and how I can make it better for your use case. Hope you like!\n\n# Getting Started\n\n### Install\n\n`npm install topic-validator --save`\n\n# API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### Table of Contents\n\n-   [buildTopicState](#buildtopicstate)\n-   [create](#create)\n-   [update](#update)\n-   [remove](#remove)\n-   [isCreatable](#iscreatable)\n-   [isUpdatable](#isupdatable)\n-   [isRemovable](#isremovable)\n\n## buildTopicState\n\nBuilds the most current state of a topic from looping over messages and replaying state.\n\n**Parameters**\n\n-   `topicMessages` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `primaryKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The primary key used to identify each message.\n-   `topicActionKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The key for your command action in the topic message. IMPORTANT your actions must use the keywords: created, updated, or deleted. (example: topicAction: 'created')\n\n**Examples**\n\n```javascript\nconst topicMessages = [\n  {\n    deviceId: 'testDeviceId',\n    externalHardwareId: 'testExternalHardwareId',\n    type: 'testType',\n    vendorId: 'testVendorId',\n    topicAction: 'created',\n    created: 1511215962473,\n    updated: 1511215962473\n  }\n];\n\nbuildTopicState(\n  topicMessages,\n  'deviceId',\n'topicAction'\n);\n```\n\nReturns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Returns a new state array of topic messages from replay.\n\n## create\n\nAdds the new message to the current state.\n\n**Parameters**\n\n-   `state` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `record` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The new message being created.\n\n**Examples**\n\n```javascript\nconst topicMessages = [{\n  thing: 'thing'\n}]\n\ncreate(topicMessages, { test: 'test' });\n```\n\nReturns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Returns the new state with the passed in item.\n\n## update\n\nUpdates found message to the current state.\n\n**Parameters**\n\n-   `state` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `record` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The new message being created.\n-   `primaryKeyIdentifier` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The primary key used to keep records unique.\n\n**Examples**\n\n```javascript\nconst existingObject = {\n  id: 'testId',\n  test: 'test'\n};\n\nconst newRecord = {\n  id: 'testId',\n  test: 'updatedContent'\n};\n\nconst existingState = [existingObject];\n\nupdate(existingState, newRecord, 'id');\n```\n\nReturns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Updates record in the state and returns the new state array.\n\n## remove\n\nRemoves found message from the current state.\n\n**Parameters**\n\n-   `state` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `record` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The new message being created.\n-   `primaryKeyIdentifier` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The primary key used to keep records unique.\n\n**Examples**\n\n```javascript\nconst existingObject = {\n  id: 'testId',\n  test: 'test'\n};\n\nconst newRecord = {\n  id: 'testId',\n  test: 'deletedContent'\n};\n\nconst existingState = [existingObject];\n\nremove(existingState, newRecord, 'id');\n```\n\nReturns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Removes the record from state and returns the new state array.\n\n## isCreatable\n\nSearches the current state to see if the message has already been created.\n\n**Parameters**\n\n-   `record` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**  The new message being created.\n-   `state` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `primaryKeyIdentifier` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The primary key used to keep records unique.\n\n**Examples**\n\n```javascript\nconst existingObject = {\n  id: 'testId',\n  test: 'test'\n};\n\nconst record = {\n  id: 'otherId',\n  test: 'deletedContent'\n};\n\nconst topicMessages = [existingObject];\n\n// Returns true\nisCreatable(record, topicMessages, 'id');\n```\n\nReturns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns a boolean value.\n\n## isUpdatable\n\nSearches the current state to see if the message can be updated.\n\n**Parameters**\n\n-   `record` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**  The new message being created.\n-   `state` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `primaryKeyIdentifier` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The primary key used to keep records unique.\n\n**Examples**\n\n```javascript\nconst existingObject = {\n  id: 'testId',\n  test: 'test'\n};\n\nconst record = {\n  id: 'testId',\n  test: 'deletedContent'\n};\n\nconst topicMessages = [existingObject];\n\n// Returns true\nisUpdatable(record, topicMessages, 'id');\n```\n\nReturns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns a boolean value.\n\n## isRemovable\n\nSearches the current state to see if the message can be deleted.\n\n**Parameters**\n\n-   `record` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**  The new message being created.\n-   `state` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of the current topic messages.\n-   `primaryKeyIdentifier` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The primary key used to keep records unique.\n\n**Examples**\n\n```javascript\nconst existingObject = {\n  id: 'testId',\n  test: 'test'\n};\n\nconst record = {\n  id: 'testId',\n  test: 'deletedContent'\n};\n\nconst topicMessages = [existingObject];\n\n// Returns true\nisRemovable(record, topicMessages, 'id');\n```\n\nReturns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns a boolean value.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floganbfisher%2Ftopic-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floganbfisher%2Ftopic-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floganbfisher%2Ftopic-validator/lists"}