{"id":20181772,"url":"https://github.com/nichoth/wslog","last_synced_at":"2025-06-18T23:34:14.847Z","repository":{"id":57130926,"uuid":"106506420","full_name":"nichoth/wslog","owner":"nichoth","description":"Log application events via websockets","archived":false,"fork":false,"pushed_at":"2024-11-02T18:44:40.000Z","size":364,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-12T09:24:47.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/nichoth.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-11T04:40:26.000Z","updated_at":"2024-11-02T18:44:37.000Z","dependencies_parsed_at":"2024-11-14T07:03:41.465Z","dependency_job_id":null,"html_url":"https://github.com/nichoth/wslog","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/nichoth/wslog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fwslog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fwslog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fwslog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fwslog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nichoth","download_url":"https://codeload.github.com/nichoth/wslog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fwslog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260653790,"owners_count":23042642,"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":[],"created_at":"2024-11-14T02:36:41.993Z","updated_at":"2025-06-18T23:34:09.835Z","avatar_url":"https://github.com/nichoth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wslog\n\nLog application events via websockets\n\n## install\n\n```\n$ npm install @nichoth/wslog\n```\n\n## example\n\nIn a terminal do this:\n\n```\n$ wslog\n```\n\nAnd in a browser do this (the terminal process will exit when the client disconnects):\n\n```js\nvar Client = require('../client')\n\nvar send = Client()\n\nsend('foo', { hello: 'world' })\nsend.event({ hello: 'again' })\nsend.state({ someData: '' })\n\n// dom events are serialized\nvar form = document.querySelector('form')\nform.addEventListener('submit', function (ev) {\n    ev.preventDefault()\n    console.log('submit', ev)\n    send.event(ev)\n})\n\nvar btn = document.querySelector('button')\nbtn.addEventListener('click', function (ev) {\n    console.log('click', ev)\n    send.event(ev)\n})\n\n// server side:\n// [\"foo\",{\"hello\":\"world\"}]\n// [\"event\",{\"hello\":\"again\"}]\n// [\"state\",{\"someData\":\"\"}]\n// [\"event\",{\"_dom\":true,\"type\":\"click\",\"target\":{\"value\":\"\"}}]\n// [\"event\",{\"_dom\":true,\"type\":\"submit\",\"target\":{\n//   \"elements\":{\n//     \"0\":{\"value\":\"test value\"},\n//     \"1\":{\"value\":\"\"},\n//     \"hello\":{\"value\":\"test value\"},\n//     \"testInput\":{\"value\":\"test value\"}}}}]\n```\n\n### serialize dom events\n\nPass the serialized event to `deserialize` on the server side.\n\n```js\nvar serialize = require('@nichoth/wslog/client').serialize\nvar ev = serialize(domEvent)\n\n// =\u003e {\n//     _dom: true,\n//     type: 'click',\n//     target: {\n//         value: ev.target.value,\n//         elements: ev.target.elements ?\n//             Object.keys(ev.target.elements).reduce(function (acc, k) {\n//                 acc[k] = {\n//                     value: ev.target.elements[k].value\n//                 }\n//                 return acc\n//             }, {}) :\n//             undefined\n// }\n```\n\n### filter events by namespace:\n\n```\n$ cat example/output.json | wslog foo\n{ hello: 'world' }\n\n$ cat example/output.json | wslog event\n{ hello: 'again' }\n\n$ cat example/output.json | wslog state\n{ someData: '' }\n```\n\n\n\n### parse event logs\n\n```js\nvar parse = require('@nichoth/wslog/parse')\nvar assert = require('assert')\n\n// return an object from event namespaces to event data\nparse(__dirname + '/dom-events.json', function (err, logs) {\n    console.log('parsed', err, logs)\n\n    {\n        foo: [{ hello: 'world' }],\n        state: [{ someData: '' }],\n        event: [\n            { hello:'again' },\n            // dom events are deseriazed with the target's value\n            // and `.preventDefault` is a function that does nothing\n            {'type':'click','target':{'value':''}},  \n            {'type':'submit', 'target':{'elements': { \n                '0':{'value':'test value'},\n                '1':{'value':''},\n                'hello':{'value':'test value'},\n                'testInput':{'value':'test value'}}}\n            }\n        ]\n    }\n})\n\n```\n\n\n### deserialize dom events\n\nThis will add mock functions on `preventDefault()`\n\n```js\nvar parse = require('@nichoth/wslog/parse')\n\nlogs.event.map(function (ev) {\n    return parse.deserialize(ev)\n})\n\n// [\n//     { hello:'again' },\n//     // dom events are deseriazed with the target's value\n//     // and `.preventDefault` is a function that does nothing\n//     {'type':'click','target':{'value':''}},  \n//     {'type':'submit', 'target':{'elements': { \n//         '0':{'value':'test value'},\n//         '1':{'value':''},\n//         'hello':{'value':'test value'},\n//         'testInput':{'value':'test value'}}}\n//     }\n// ]\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fwslog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnichoth%2Fwslog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fwslog/lists"}