Sample
eventsource-parser 3.1.1
Verified sample for npm eventsource-parser 3.1.1. The contract ran on node 22 · linux alpine/x64 · docker and passed: assert createParser parses single-line…
sha256:9041007dffbc5e94ed01f18ab87cbef5065683b0e2c4792f6aa517f51307dafb
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 npm
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-27 |
Case
HOW- Goal
- verify pkg:npm/eventsource-parser@3.1.1
- Packages
- Created
- 2026-08-27T22:16:35Z
Contract
- assert createParser parses single-line and multiline data fields into EventSourceMessage objects when fed chunks
- assert createParser extracts optional id and event type fields along with message data
- assert createParser invokes onRetry callback when parsing retry interval directives and onComment for comment lines
- assert createParser emits ParseError with invalid-retry or unknown-field types when encountering malformed SSE fields
- assert createParser enforces maxBufferSize limit by emitting ParseError with max-buffer-size-exceeded and terminating feed
- assert EventSourceParserStream transforms a stream of chunked strings into a stream of EventSourceMessage events
Files
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/eventsource-parser@3.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/eventsource-parser@3.1.1
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:514ff6fa387a790563675e2c5cd7659b5477a038f6ce273838523d2e0c937633","contract":["assert createParser parses single-line and multiline data fields into EventSourceMessage objects when fed chunks","assert createParser extracts optional id and event type fields along with message data","assert createParser invokes onRetry callback when parsing retry interval directives and onComment for comment lines","assert createParser emits ParseError with invalid-retry or unknown-field types when encountering malformed SSE fields","assert createParser enforces maxBufferSize limit by emitting ParseError with max-buffer-size-exceeded and terminating feed","assert EventSourceParserStream transforms a stream of chunked strings into a stream of EventSourceMessage events"],"goal":"verify pkg:npm/eventsource-parser@3.1.1","kind":"HOW","packages":["pkg:npm/eventsource-parser@3.1.1"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/eventsource-parser@3.1.1"],"schemaVersion":1,"subject":"pkg:npm/eventsource-parser@3.1.1","verifierAdapter":"node-typescript@1"}
import { createParser, ParseError } from 'eventsource-parser';
import { EventSourceParserStream } from 'eventsource-parser/stream';
/**
* Parse an SSE string directly into an array of parsed messages.
* @param {string} input - Raw SSE stream text
* @param {import('eventsource-parser').ParserConfig} [config]
* @returns {import('eventsource-parser').EventSourceMessage[]}
*/
export function parseSSE(input, config = {}) {
const events = [];
const parser = createParser({
...config,
onEvent: (event) => {
events.push(event);
config.onEvent?.(event);
},
});
parser.feed(input);
return events;
}
export { createParser, ParseError, EventSourceParserStream };
export default createParser;
{
"name": "sample-eventsource-parser-verify",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-eventsource-parser-verify",
"version": "1.0.0",
"dependencies": {
"eventsource-parser": "3.1.1"
}
},
"node_modules/eventsource-parser": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz",
"integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
}
}
}
}
{
"name": "sample-eventsource-parser-verify",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"eventsource-parser": "3.1.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/eventsource-parser@3.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/eventsource-parser@3.1.1"
]
}
import assert from 'node:assert/strict';
import { createParser, ParseError, EventSourceParserStream, parseSSE } from '../index.mjs';
// 1. assert createParser parses single-line and multiline data fields into EventSourceMessage objects when fed chunks
{
const events = [];
const parser = createParser({
onEvent: (event) => events.push(event),
});
parser.feed('data: hel');
parser.feed('lo world\n\n');
parser.feed('data: line 1\n');
parser.feed('data: line 2\n\n');
assert.strictEqual(events.length, 2);
assert.deepStrictEqual(events[0], {
id: undefined,
event: undefined,
data: 'hello world',
});
assert.deepStrictEqual(events[1], {
id: undefined,
event: undefined,
data: 'line 1\nline 2',
});
const batchEvents = parseSSE('data: batch test\n\n');
assert.strictEqual(batchEvents.length, 1);
assert.strictEqual(batchEvents[0].data, 'batch test');
}
// 2. assert createParser extracts optional id and event type fields along with message data
{
const events = [];
const parser = createParser({
onEvent: (event) => events.push(event),
});
parser.feed('id: msg-001\nevent: custom-event\ndata: payload body\n\n');
assert.strictEqual(events.length, 1);
assert.strictEqual(events[0].id, 'msg-001');
assert.strictEqual(events[0].event, 'custom-event');
assert.strictEqual(events[0].data, 'payload body');
}
// 3. assert createParser invokes onRetry callback when parsing retry interval directives and onComment for comment lines
{
const retries = [];
const comments = [];
const parser = createParser({
onRetry: (interval) => retries.push(interval),
onComment: (comment) => comments.push(comment),
});
parser.feed('retry: 5000\n\n');
parser.feed(': keep-alive comment\n\n');
assert.strictEqual(retries.length, 1);
assert.strictEqual(retries[0], 5000);
assert.strictEqual(comments.length, 1);
assert.strictEqual(comments[0], 'keep-alive comment');
}
// 4. assert createParser emits ParseError with invalid-retry or unknown-field types when encountering malformed SSE fields
{
const errors = [];
const parser = createParser({
onError: (err) => errors.push(err),
});
parser.feed('unknown_directive: value\n\n');
parser.feed('retry: not_a_number\n\n');
assert.strictEqual(errors.length, 2);
assert.ok(errors[0] instanceof ParseError);
assert.strictEqual(errors[0].type, 'unknown-field');
assert.strictEqual(errors[0].field, 'unknown_directive');
assert.strictEqual(errors[0].value, 'value');
assert.ok(errors[1] instanceof ParseError);
assert.strictEqual(errors[1].type, 'invalid-retry');
assert.strictEqual(errors[1].value, 'not_a_number');
}
// 5. assert createParser enforces maxBufferSize limit by emitting ParseError with max-buffer-size-exceeded and terminating feed
{
const errors = [];
const parser = createParser({
maxBufferSize: 20,
onError: (err) => errors.push(err),
});
parser.feed('data: this is an overly long stream message that exceeds buffer limit');
assert.strictEqual(errors.length, 1);
assert.strictEqual(errors[0].type, 'max-buffer-size-exceeded');
assert.throws(
() => parser.feed('data: next chunk'),
/terminated after exceeding the configured max buffer size/
);
parser.reset();
const resetEvents = [];
const resetParser = createParser({
maxBufferSize: 50,
onEvent: (e) => resetEvents.push(e),
});
resetParser.feed('data: valid\n\n');
assert.strictEqual(resetEvents.length, 1);
assert.strictEqual(resetEvents[0].data, 'valid');
}
// 6. assert EventSourceParserStream transforms a stream of chunked strings into a stream of EventSourceMessage events
{
const stream = new ReadableStream({
start(controller) {
controller.enqueue('event: notice\n');
controller.enqueue('data: chunk1\n\n');
controller.enqueue('id: 99\ndata: chunk2\n\n');
controller.close();
},
});
const parsedStream = stream.pipeThrough(new EventSourceParserStream());
const reader = parsedStream.getReader();
const msg1 = await reader.read();
assert.strictEqual(msg1.done, false);
assert.deepStrictEqual(msg1.value, {
id: undefined,
event: 'notice',
data: 'chunk1',
});
const msg2 = await reader.read();
assert.strictEqual(msg2.done, false);
assert.deepStrictEqual(msg2.value, {
id: '99',
event: undefined,
data: 'chunk2',
});
const done = await reader.read();
assert.strictEqual(done.done, true);
}
console.log('All contracts passed successfully.');
Origin Seeder
anonymous