{"_id":"@codeforbreakfast/eventsourcing-protocol-default","_rev":"4-5a357ca2a55548b70e2d0ead2ef3e6dd","name":"@codeforbreakfast/eventsourcing-protocol-default","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"@codeforbreakfast/eventsourcing-protocol-default","version":"0.1.0","keywords":["event-sourcing","protocol","implementation","default","standard","transport-agnostic","websocket","http","sse","message-serialization","command-correlation","subscription-management","cqrs","aggregate","command","stream","effect","effect-ts","functional-programming","fp","typescript","type-safe"],"author":"Code for Breakfast","license":"MIT","_id":"@codeforbreakfast/eventsourcing-protocol-default@0.1.0","maintainers":[{"name":"graemef","email":"graemef@gmail.com"}],"homepage":"https://github.com/codeforbreakfast/eventsourcing#readme","bugs":{"url":"https://github.com/codeforbreakfast/eventsourcing/issues"},"dist":{"shasum":"5a562a7eb1543fbbad3ee3289fe5466be71e59e7","tarball":"https://registry.npmjs.org/@codeforbreakfast/eventsourcing-protocol-default/-/eventsourcing-protocol-default-0.1.0.tgz","fileCount":8,"integrity":"sha512-4yptRIp8PsVsPmSvTSPA+pHLq1YP+IfNeprqs5BqhDx2fMvZCiT3PXAYdmNy2161lnEzXiYq6gE/d8zPNgrDRA==","signatures":[{"sig":"MEUCIQCPMF9RJ2JmQzElezjRfuzJ4AT4yDvgIu4pRyzNhmiEswIgY2UWnTXsZ1D4EoecFrxwwN84EivlNu5vL+TM4WtaJ5M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":133131},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"5a562a7eb1543fbbad3ee3289fe5466be71e59e7","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint . --ext .ts,.tsx","test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --target bun --format esm --external effect --external @effect/* --external @codeforbreakfast/* && bun x tsc --build","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"bun test --watch","prepublishOnly":"bun run clean && bun run build","publish:package":"bun publish --access public"},"_npmUser":{"name":"graemef","email":"graemef@gmail.com"},"_integrity":"sha512-4yptRIp8PsVsPmSvTSPA+pHLq1YP+IfNeprqs5BqhDx2fMvZCiT3PXAYdmNy2161lnEzXiYq6gE/d8zPNgrDRA==","repository":{"url":"https://github.com/codeforbreakfast/eventsourcing.git","type":"git","directory":"packages/eventsourcing-protocol-default"},"_npmVersion":"10.8.3","description":"Default implementation of the event sourcing protocol over any transport - Standard protocol implementation with message serialization, command correlation, and subscription management","directories":{},"sideEffects":false,"_nodeVersion":"24.3.0","dependencies":{"@codeforbreakfast/eventsourcing-store":"0.6.5","@codeforbreakfast/eventsourcing-transport-contracts":"0.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"effect":"3.17.14","eslint":"9.36.0","vitest":"3.2.4","typescript":"5.9.2","@types/node":"24.5.2","@codeforbreakfast/eventsourcing-transport-inmemory":"0.1.0"},"peerDependencies":{"effect":"^3.17.0"},"_npmOperationalInternal":{"tmp":"tmp/eventsourcing-protocol-default_0.1.0_1758660234822_0.661084534382453","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@codeforbreakfast/eventsourcing-protocol-default","version":"0.2.0","keywords":["event-sourcing","protocol","implementation","default","standard","transport-agnostic","websocket","http","sse","message-serialization","command-correlation","subscription-management","cqrs","aggregate","command","stream","effect","effect-ts","functional-programming","fp","typescript","type-safe"],"author":"Code for Breakfast","license":"MIT","_id":"@codeforbreakfast/eventsourcing-protocol-default@0.2.0","maintainers":[{"name":"graemef","email":"graemef@gmail.com"}],"homepage":"https://github.com/codeforbreakfast/eventsourcing#readme","bugs":{"url":"https://github.com/codeforbreakfast/eventsourcing/issues"},"dist":{"shasum":"70fd9b661bdb0928235a8ce3b3d2d5a98875b224","tarball":"https://registry.npmjs.org/@codeforbreakfast/eventsourcing-protocol-default/-/eventsourcing-protocol-default-0.2.0.tgz","fileCount":8,"integrity":"sha512-1PuPpWruQEXp7O9PwLQHUSX708xJePyT2n0VVDL5kY9relATZRXU9Y/LC6nRsa/BhBhMWpktMt0t4xk4VoE4ng==","signatures":[{"sig":"MEUCIA6u2uugsgqCCTny+DVQHn2oE2E7nW+/egFSww29Z/zNAiEA3dQpUuEylqklj/DhkVcNlw4l4XVYh+j5c97xWVLsCn0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":133131},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"70fd9b661bdb0928235a8ce3b3d2d5a98875b224","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint . --ext .ts,.tsx","test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --target bun --format esm --external effect --external @effect/* --external @codeforbreakfast/* && bun x tsc --build","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"bun test --watch","prepublishOnly":"bun run clean && bun run build","publish:package":"bun publish --access public"},"_npmUser":{"name":"graemef","email":"graemef@gmail.com"},"_integrity":"sha512-1PuPpWruQEXp7O9PwLQHUSX708xJePyT2n0VVDL5kY9relATZRXU9Y/LC6nRsa/BhBhMWpktMt0t4xk4VoE4ng==","repository":{"url":"https://github.com/codeforbreakfast/eventsourcing.git","type":"git","directory":"packages/eventsourcing-protocol-default"},"_npmVersion":"10.8.3","description":"Default implementation of the event sourcing protocol over any transport - Standard protocol implementation with message serialization, command correlation, and subscription management","directories":{},"sideEffects":false,"_nodeVersion":"24.3.0","dependencies":{"@codeforbreakfast/eventsourcing-store":"0.6.5","@codeforbreakfast/eventsourcing-transport-contracts":"0.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"effect":"3.17.14","eslint":"9.36.0","vitest":"3.2.4","typescript":"5.9.2","@types/node":"24.5.2","@codeforbreakfast/eventsourcing-transport-inmemory":"0.2.0"},"peerDependencies":{"effect":"^3.17.0"},"_npmOperationalInternal":{"tmp":"tmp/eventsourcing-protocol-default_0.2.0_1758660742383_0.318754360664806","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@codeforbreakfast/eventsourcing-protocol-default","version":"0.2.1","keywords":["event-sourcing","protocol","implementation","default","standard","transport-agnostic","websocket","http","sse","message-serialization","command-correlation","subscription-management","cqrs","aggregate","command","stream","effect","effect-ts","functional-programming","fp","typescript","type-safe"],"author":"Code for Breakfast","license":"MIT","_id":"@codeforbreakfast/eventsourcing-protocol-default@0.2.1","maintainers":[{"name":"graemef","email":"graemef@gmail.com"}],"homepage":"https://github.com/codeforbreakfast/eventsourcing#readme","bugs":{"url":"https://github.com/codeforbreakfast/eventsourcing/issues"},"dist":{"shasum":"640a29432c78342f475d304dc3eae44b315b77a9","tarball":"https://registry.npmjs.org/@codeforbreakfast/eventsourcing-protocol-default/-/eventsourcing-protocol-default-0.2.1.tgz","fileCount":8,"integrity":"sha512-ixuoGvE9Q0egiEhHOhRoBedudFniPA6Etzhvf+RMrb/xPM4dmiJW3/ibJVmJ+IkwOKsYTopOJVkbiNKICBZGoA==","signatures":[{"sig":"MEYCIQCK0hRhgx3IJl0fgUMlPDLgSUdrpftTauBS15cumW3GtgIhALBfxtYbqtCeNI5i6tHep5+/VorwfYIsrCBWIXNglhl5","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":133131},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"640a29432c78342f475d304dc3eae44b315b77a9","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint . --ext .ts,.tsx","test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --target bun --format esm --external effect --external @effect/* --external @codeforbreakfast/* && bun x tsc --build","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"bun test --watch","prepublishOnly":"bun run clean && bun run build","publish:package":"bun publish --access public"},"_npmUser":{"name":"graemef","email":"graemef@gmail.com"},"_integrity":"sha512-ixuoGvE9Q0egiEhHOhRoBedudFniPA6Etzhvf+RMrb/xPM4dmiJW3/ibJVmJ+IkwOKsYTopOJVkbiNKICBZGoA==","repository":{"url":"https://github.com/codeforbreakfast/eventsourcing.git","type":"git","directory":"packages/eventsourcing-protocol-default"},"_npmVersion":"10.8.3","description":"Default implementation of the event sourcing protocol over any transport - Standard protocol implementation with message serialization, command correlation, and subscription management","directories":{},"sideEffects":false,"_nodeVersion":"24.3.0","dependencies":{"@codeforbreakfast/eventsourcing-store":"0.6.6","@codeforbreakfast/eventsourcing-transport-contracts":"0.2.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"effect":"3.17.14","eslint":"9.36.0","vitest":"3.2.4","typescript":"5.9.2","@types/node":"24.5.2","@codeforbreakfast/eventsourcing-transport-inmemory":"0.2.1"},"peerDependencies":{"effect":"^3.17.0"},"_npmOperationalInternal":{"tmp":"tmp/eventsourcing-protocol-default_0.2.1_1758697835588_0.5410886215060715","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"name":"@codeforbreakfast/eventsourcing-protocol-default","version":"0.2.2","description":"Default implementation of the event sourcing protocol over any transport - Standard protocol implementation with message serialization, command correlation, and subscription management","type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"build":"bun build ./src/index.ts --outdir ./dist --target bun --format esm --external effect --external @effect/* --external @codeforbreakfast/* && bun x tsc --build","test":"bun test","test:watch":"bun test --watch","lint":"eslint . --ext .ts,.tsx","typecheck":"tsc --noEmit","clean":"rm -rf dist","publish:package":"npm publish --access public"},"keywords":["event-sourcing","protocol","implementation","default","standard","transport-agnostic","websocket","http","sse","message-serialization","command-correlation","subscription-management","cqrs","aggregate","command","stream","effect","effect-ts","functional-programming","fp","typescript","type-safe"],"author":{"name":"Code for Breakfast"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/codeforbreakfast/eventsourcing.git","directory":"packages/eventsourcing-protocol-default"},"bugs":{"url":"https://github.com/codeforbreakfast/eventsourcing/issues"},"homepage":"https://github.com/codeforbreakfast/eventsourcing#readme","peerDependencies":{"effect":"^3.17.0"},"dependencies":{"@codeforbreakfast/eventsourcing-transport-contracts":"workspace:*","@codeforbreakfast/eventsourcing-store":"workspace:*"},"devDependencies":{"@codeforbreakfast/eventsourcing-transport-inmemory":"workspace:*","@types/node":"24.5.2","effect":"3.17.14","typescript":"5.9.2","vitest":"3.2.4","eslint":"9.36.0"},"publishConfig":{"access":"public"},"sideEffects":false,"engines":{"node":">=18.0.0"},"_id":"@codeforbreakfast/eventsourcing-protocol-default@0.2.2","gitHead":"9510ad686c016cbbf486f3572a78ce3b8e031131","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Zg+A9FO2XXYl+PE372kxZ8ZmPBb0HukMJ2pR9b4m5mBAJr/xsVqKthv0bjqnaaIbouVrk5BseP3HgqV9j5lCyw==","shasum":"281361e945d76603df32c905120f79d5413bcf32","tarball":"https://registry.npmjs.org/@codeforbreakfast/eventsourcing-protocol-default/-/eventsourcing-protocol-default-0.2.2.tgz","fileCount":19,"unpackedSize":162423,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCimefGLXovbT/Z8tNJxHNM/MbOp5CWTCSFsG1ghFdrqgIgbtiFabA9Z2mtqLsl2K50BJWVyc8ixRksvhlalt1dW+U="}]},"_npmUser":{"name":"graemef","email":"graemef@gmail.com"},"directories":{},"maintainers":[{"name":"graemef","email":"graemef@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/eventsourcing-protocol-default_0.2.2_1758706997314_0.08243285353522278"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-23T20:43:54.753Z","modified":"2025-09-24T09:43:17.715Z","0.1.0":"2025-09-23T20:43:55.059Z","0.2.0":"2025-09-23T20:52:22.564Z","0.2.1":"2025-09-24T07:10:35.780Z","0.2.2":"2025-09-24T09:43:17.503Z"},"bugs":{"url":"https://github.com/codeforbreakfast/eventsourcing/issues"},"author":{"name":"Code for Breakfast"},"license":"MIT","homepage":"https://github.com/codeforbreakfast/eventsourcing#readme","keywords":["event-sourcing","protocol","implementation","default","standard","transport-agnostic","websocket","http","sse","message-serialization","command-correlation","subscription-management","cqrs","aggregate","command","stream","effect","effect-ts","functional-programming","fp","typescript","type-safe"],"repository":{"type":"git","url":"git+https://github.com/codeforbreakfast/eventsourcing.git","directory":"packages/eventsourcing-protocol-default"},"description":"Default implementation of the event sourcing protocol over any transport - Standard protocol implementation with message serialization, command correlation, and subscription management","maintainers":[{"name":"graemef","email":"graemef@gmail.com"}],"readme":"# Event Sourcing Protocol\n\nProtocol implementation for event sourcing over transport abstractions.\n\n## Protocol Layer Responsibilities\n\nThe protocol layer acts as a **generic RPC mechanism for event sourcing** - it's a dumb pipe that shuffles messages between client and server without knowing anything about your domain.\n\n### What the protocol SHOULD know:\n\n1. **Message structure** - How to wrap messages in envelopes (IDs, timestamps, correlation)\n2. **Message types** - Basic routing types: \"command\", \"event\", \"subscription\"\n3. **Wire format** - How to serialize/deserialize for transport\n4. **Message correlation** - Matching responses to requests via IDs\n5. **Connection state** - Managing subscriptions and pending commands\n\n### What it SHOULDN'T know:\n\n1. **Domain logic** - What an \"UpdateProfile\" command actually does\n2. **Event schemas** - The actual shape of your business events\n3. **Aggregate rules** - Validation, business invariants, etc.\n4. **Command handlers** - How commands get processed\n\nThink of it like HTTP - HTTP doesn't care what your JSON payload contains, it just delivers it. The protocol's `Command` and `Event` interfaces are just **transport containers** with metadata fields (id, aggregate, position) while the actual `payload` and `data` fields remain `unknown`.\n\nThe protocol's core responsibilities:\n\n- **Message correlation** - Track which responses belong to which requests\n- **Subscription management** - Route events to the right subscribers\n- **Timeout handling** - Fail commands that take too long\n- **Error propagation** - Pass errors back from server to client\n- **Transport abstraction** - Hide WebSocket/HTTP/whatever details\n\n## Installation\n\n```bash\nbun add @codeforbreakfast/eventsourcing-protocol-default\n```\n\n## Usage\n\n```typescript\nimport { createProtocol } from '@codeforbreakfast/eventsourcing-protocol-default';\nimport { createTransport } from '@codeforbreakfast/eventsourcing-transport-websocket';\n\n// Create protocol with a transport\nconst protocol = await Effect.runPromise(createTransport(url).pipe(Effect.flatMap(createProtocol)));\n\n// Send commands\nconst result = await Effect.runPromise(\n  protocol.sendCommand({\n    id: crypto.randomUUID(),\n    aggregate: 'user-123',\n    name: 'UpdateProfile',\n    payload: { name: 'John Doe' },\n  })\n);\n\n// Subscribe to events\nconst eventStream = await Effect.runPromise(protocol.subscribe('user-123'));\n\nawait Effect.runPromise(\n  Stream.runForEach(eventStream, (event) =>\n    Effect.log(`Event: ${event.type} at position ${event.position.eventNumber}`)\n  )\n);\n```\n\n## API\n\n### `createProtocol(transport)`\n\nCreates a protocol instance from a transport connection.\n\n**Parameters:**\n\n- `transport: Client.Transport` - Connected transport instance\n\n**Returns:** `Effect<Protocol, TransportError, never>`\n\n### `Protocol.sendCommand(command)`\n\nSends a command and waits for the result.\n\n**Parameters:**\n\n- `command: Command` - Command to send\n  - `id: string` - Unique command identifier\n  - `aggregate: string` - Aggregate identifier\n  - `name: string` - Command name\n  - `payload: unknown` - Command data\n\n**Returns:** `Effect<CommandResult, TransportError, never>`\n\nResult contains:\n\n- `success: boolean` - Whether command succeeded\n- `position?: EventStreamPosition` - New stream position after command\n- `error?: string` - Error message if command failed\n\nCommands automatically timeout after 10 seconds.\n\n### `Protocol.subscribe(streamId)`\n\nSubscribes to events from a specific stream.\n\n**Parameters:**\n\n- `streamId: string` - Stream identifier to subscribe to\n\n**Returns:** `Effect<Stream<Event>, TransportError, never>`\n\nEach event contains:\n\n- `position: EventStreamPosition` - Event position in stream\n- `type: string` - Event type name\n- `data: unknown` - Event payload\n- `timestamp: Date` - When event occurred\n\n## Message Format\n\nThe protocol exchanges JSON messages over the transport.\n\n### Command Message\n\n```json\n{\n  \"type\": \"command\",\n  \"id\": \"cmd-123\",\n  \"aggregate\": \"user-456\",\n  \"name\": \"UpdateProfile\",\n  \"payload\": { \"name\": \"John\" }\n}\n```\n\n### Command Result Message\n\n```json\n{\n  \"type\": \"command_result\",\n  \"commandId\": \"cmd-123\",\n  \"success\": true,\n  \"position\": { \"streamId\": \"user-456\", \"eventNumber\": 42 }\n}\n```\n\n### Subscribe Message\n\n```json\n{\n  \"type\": \"subscribe\",\n  \"streamId\": \"user-456\"\n}\n```\n\n### Event Message\n\n```json\n{\n  \"type\": \"event\",\n  \"streamId\": \"user-456\",\n  \"position\": { \"streamId\": \"user-456\", \"eventNumber\": 42 },\n  \"eventType\": \"ProfileUpdated\",\n  \"data\": { \"name\": \"John\" },\n  \"timestamp\": \"2024-01-01T00:00:00Z\"\n}\n```\n\n## Error Handling\n\nAll operations return Effects that handle:\n\n- Transport errors (connection failures, network issues)\n- Timeout errors (commands timing out after 10 seconds)\n- Parsing errors (gracefully caught and logged)\n\n## Types\n\n```typescript\ninterface Command {\n  readonly id: string;\n  readonly aggregate: string;\n  readonly name: string;\n  readonly payload: unknown;\n}\n\ninterface Event {\n  readonly position: EventStreamPosition;\n  readonly type: string;\n  readonly data: unknown;\n  readonly timestamp: Date;\n}\n\ninterface CommandResult {\n  readonly success: boolean;\n  readonly position?: EventStreamPosition;\n  readonly error?: string;\n}\n\ninterface Protocol {\n  readonly sendCommand: (command: Command) => Effect<CommandResult, TransportError, never>;\n  readonly subscribe: (streamId: string) => Effect<Stream<Event>, TransportError, never>;\n}\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}