{"id":16398680,"url":"https://github.com/ken107/push-model","last_synced_at":"2025-03-23T05:30:59.584Z","repository":{"id":1091173,"uuid":"39984699","full_name":"ken107/push-model","owner":"ken107","description":"A JSON-RPC server with object synchronization based on JSON-Patch","archived":false,"fork":false,"pushed_at":"2023-01-07T03:58:06.000Z","size":1009,"stargazers_count":8,"open_issues_count":6,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T22:16:08.590Z","etag":null,"topics":["firebase","json-patch","json-rpc","json-rpc-server","mvc","mvvm","pubsub"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ken107.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T03:27:39.000Z","updated_at":"2023-07-27T05:47:47.000Z","dependencies_parsed_at":"2023-01-11T15:49:36.055Z","dependency_job_id":null,"html_url":"https://github.com/ken107/push-model","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken107%2Fpush-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken107%2Fpush-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken107%2Fpush-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken107%2Fpush-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ken107","download_url":"https://codeload.github.com/ken107/push-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245061382,"owners_count":20554563,"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","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":["firebase","json-patch","json-rpc","json-rpc-server","mvc","mvvm","pubsub"],"created_at":"2024-10-11T05:13:29.790Z","updated_at":"2025-03-23T05:30:59.348Z","avatar_url":"https://github.com/ken107.png","language":"TypeScript","readme":"[![Build Status](https://travis-ci.org/ken107/push-model.svg?branch=master)](https://travis-ci.org/ken107/push-model)\n\n## What's This?\nThis Node module implements a WebSocket JSON-RPC server with object synchronization capabilities based on the JSON-Pointer and JSON-Patch standards.\n\nIt is called a Push Model because it is intended to be used as part of a server-side MVC Model layer or MVVM ViewModel layer that requires the ability to push changes to clients.\n\nThe Model/ViewModel layer can handle JSON-RPC requests and return data directly to the requester, or it may choose to place data in a _model object_ that is published to interested clients.  [Harmony Proxy](https://github.com/ken107/jsonpatch-observe) is used to detect subsequent changes to the data, which are published incrementally as JSON Patches.\n\n\n## How To Use\n```javascript\nconst pm = require(\"push-model\");\nconst server = require(\"http\").createServer();\nconst model = {\n\t\t//properties that client can subscribe to\n\t\tprop1: ...,\n\t\tprop2: ...,\n\n\t\t//RPC methods\n\t\tmethod1: function(...args) {\n\t\t\t...\n\t\t\treturn result;\t//or promise\n\t\t},\n\t\tmethod2: ...\n\t};\n\npm.mount(server, \"/path\", model, acceptOrigins);\n```\nThis creates an HTTP server and mounts `model` on the specified route.  Clients can send RPC requests to this route over either HTTP or WebSocket, which invoke the corresponding methods on the model.  Return values are automatically sent back as JSON-RPC responses.\n\n\n### Special Methods\nThe PUB/SUB mechanism is only available to WebSocket clients.\n\n##### SUB/UNSUB\nClients call SUB/UNSUB to start/stop observing changes to the model object.  The `pointer` parameter, a JSON Pointer, indicates which part of the model to observe.\n```\nSUB(pointer)\nUNSUB(pointer)\n```\n\n##### PUB\nServer calls PUB to notify clients of changes to the model.  The `patches` parameter holds an array of JSON Patches describing a series of changes that were made to the model.\n```\nSUB(patches)\n```\n\n\n### Special Return Values\n\n##### ErrorResponse\nA return value of type ErrorResponse will be translated into a JSON-RPC error message.\n```\nreturn new pm.ErrorResponse(code, message, data);\n```\n\n\n### A Example Model\nAn MVC chat server that uses object synchronization to push chat messages to clients.\n```javascript\npm.mount(server, \"/chat\", {\n\t//data\n\tchatLog: [],\n\n\t//actions\n\tsendChat: function(name, message) {\n\t\tthis.chatLog.push(name + \": \" + message);\n\t}\n});\n```\n\n\n## Examples\n\n##### Running the Chat Example\nOpen a command prompt in the push-model directory and run:\n```\nnpm install\nnode examples/chat/model.js\n```\nThat will start the chat model on localhost:8080.  Then open the file examples/chat/chat.html in two browser windows and start chatting!\n\n##### Running the Shared TodoList Example\nOpen a command prompt in the push-model directory and run:\n```\nnpm install\nnode examples/sharedtodolist/model.js\n```\nThen open the file examples/sharedtodolist/todo.html in two or more browser windows.  If you use Chrome, you must run a local web server because Chrome does not allow AJAX over file:// URL.\n\n##### Running the Messenger Example\n```\nnpm install\nnode examples/messenger/model.js\n```\nThen open the file examples/messenger/messenger.html in two or more browser windows.  Enter a user ID and name to login to the messenger app.\n\n\n## Other Features\nView the [wiki](http://github.com/ken107/push-model/wiki) for other features supported by the Push Model.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fken107%2Fpush-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fken107%2Fpush-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fken107%2Fpush-model/lists"}