{"id":17321802,"url":"https://github.com/avoidwork/tiny-eventsource","last_synced_at":"2025-07-31T23:30:45.948Z","repository":{"id":55860662,"uuid":"158322869","full_name":"avoidwork/tiny-eventsource","owner":"avoidwork","description":"Tiny EventSource for API servers","archived":false,"fork":false,"pushed_at":"2025-07-29T16:31:52.000Z","size":821,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-29T19:21:24.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avoidwork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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,"zenodo":null},"funding":{"github":["avoidwork"]}},"created_at":"2018-11-20T03:01:36.000Z","updated_at":"2025-07-29T16:31:49.000Z","dependencies_parsed_at":"2023-10-17T01:17:59.171Z","dependency_job_id":"d1308ebc-ef9c-4148-b0de-71a27ee82978","html_url":"https://github.com/avoidwork/tiny-eventsource","commit_stats":{"total_commits":30,"total_committers":3,"mean_commits":10.0,"dds":0.1333333333333333,"last_synced_commit":"8156add8bb591ff8f0d77f63f4bc864970eccc19"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/avoidwork/tiny-eventsource","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-eventsource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-eventsource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-eventsource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-eventsource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avoidwork","download_url":"https://codeload.github.com/avoidwork/tiny-eventsource/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-eventsource/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267753174,"owners_count":24139156,"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-07-29T02:00:12.549Z","response_time":2574,"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":[],"created_at":"2024-10-15T13:39:40.936Z","updated_at":"2025-07-31T23:30:45.661Z","avatar_url":"https://github.com/avoidwork.png","language":"JavaScript","funding_links":["https://github.com/sponsors/avoidwork"],"categories":[],"sub_categories":[],"readme":"# Tiny EventSource\n\nTiny EventSource simplifies `server-sent` events for API servers.\n\n## Example\n\n### Using the factory\n\n```javascript\nimport {eventsource} from \"tiny-eventsource\";\nimport {STATUS_CODES} from \"node:http\";\n\nconst streams = new Map();\n\nexport function stream (req, res) {\n\tif (req.isAuthenticated()) {\n\t\tconst id = req.user.id;\n\n\t\tif (!streams.has(id)) {\n\t\t\tstreams.set(id, eventsource({ms: 2e4}, \"connected\"));\n\t\t}\n\n\t\tstreams.get(id).init(req, res);\n\t} else {\n\t\tres.statusCode = 401;\n\t\tres.writeHead(res.statusCode, {headers: {\"cache-control\": \"no-cache, must re-validate\"}})\n\t\tres.end(STATUS_CODES[res.statusCode]);\n\t}\n};\n```\n\n### Using the Class\n\n```javascript\nimport {EventSource} from \"tiny-eventsource\";\n```\n\n## Testing\n\nTiny EventSource has 100% code coverage with its tests.\n\n```console\n  Testing functionality\n    ✔ It should do nothing with stock configuration\n    ✔ It should have an accurate listener count\n    ✔ It should have a heartbeat (502ms)\n    ✔ It should send custom events\n\n\n  4 passing (508ms)\n\n----------------------|---------|----------|---------|---------|----------------------\nFile                  | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s    \n----------------------|---------|----------|---------|---------|----------------------\nAll files             |     100 |    72.22 |     100 |     100 |                      \n tiny-eventsource.cjs |     100 |    72.22 |     100 |     100 | 35-36,49,56,66,68-88 \n----------------------|---------|----------|---------|---------|----------------------\n```\n\n## Options\n\n### event\n\nDefault is `message`.\n\n### ms\n\nDefault is `0`. If greater than 0 a heart beat will be created from `init()`.\n\n### msg\n\nDefault is `ping`. Message sent if `ms` is greater than `0`.\n\n## Events\n\n### close\n\nEmitted when an `EventSource` request is closed.\n\n## API\n\n### constructor({options}, [...msgs])\n\nCreates an `EventSource` instance with optional messages to be transmitted on successful connection.\n\n### init(req, res)\n\nInitializes an `Event Source` stream.\n\n### listenerCount()\n\nReturns the number of listeners on the `EventSource` instance.\n\n### send(msg[, event, id]);\n\nSends a message over an `EventSource` instance.\n\n### setMaxListeners(n)\n\nSets the maximum listeners on the `EventSource` instance; default is `0`.\n\n## License\nCopyright (c) 2023 Jason Mulligan\nLicensed under the BSD-3 license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-eventsource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favoidwork%2Ftiny-eventsource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-eventsource/lists"}