샘플
eventsource-parser 3.1.1: EventSourceParser
검증된 샘플 — npm eventsource-parser 3.1.1: EventSourceParser. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: createParser returns an…
sha256:dd0b26712b53af27316a55bfee4a442656a61a558e3be0713da04774d8b98494
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-02 |
케이스
HOW- 목표
- verify EventSourceParser in pkg:npm/eventsource-parser@3.1.1
- 심벌
-
- EventSourceParser
- 환경
- node 22.23.2
- 생성일
- 2026-09-02T01:41:10Z
컨트랙트
- createParser returns an EventSourceParser instance with feed and reset methods
- EventSourceParser parses basic messages, multiline data, event types, and message IDs
- EventSourceParser streams partial chunks across line and message boundaries
- EventSourceParser emits comment and retry events to their respective callbacks
- EventSourceParser handles reset and reports invalid retry or unknown fields
- EventSourceParser enforces maxBufferSize and throws on subsequent feed until reset
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
소스
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 EventSourceParser in pkg:npm/eventsource-parser@3.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/eventsource-parser@3.1.1
Demonstrate these symbols/APIs:
- EventSourceParser
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:b987c91379c625a6c3d201d51faccb6bc1b6a1c8e4408b074ea64dd72fd4bc8e","constraints":{"executionContext":"node"},"contract":["createParser returns an EventSourceParser instance with feed and reset methods","EventSourceParser parses basic messages, multiline data, event types, and message IDs","EventSourceParser streams partial chunks across line and message boundaries","EventSourceParser emits comment and retry events to their respective callbacks","EventSourceParser handles reset and reports invalid retry or unknown fields","EventSourceParser enforces maxBufferSize and throws on subsequent feed until reset"],"goal":"verify EventSourceParser in pkg:npm/eventsource-parser@3.1.1","kind":"HOW","packages":["pkg:npm/eventsource-parser@3.1.1"],"schemaVersion":1,"symbols":["EventSourceParser"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/eventsource-parser@3.1.1"],"schemaVersion":1,"subject":"pkg:npm/eventsource-parser@3.1.1","symbols":["EventSourceParser"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-eventsource-parser",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-eventsource-parser",
"version": "1.0.0",
"license": "MIT-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",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for EventSourceParser in eventsource-parser",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"eventsource-parser": "3.1.1"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify EventSourceParser in pkg:npm/eventsource-parser@3.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/eventsource-parser@3.1.1"
],
"symbols": [
"EventSourceParser"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const { createParser, ParseError } = require('eventsource-parser');
/**
* Creates an EventSource parser instance with given callbacks and options.
* @param {import('eventsource-parser').ParserConfig} config
* @returns {import('eventsource-parser').EventSourceParser}
*/
function createEventParser(config) {
return createParser(config);
}
/**
* Feeds SSE chunked stream into a new parser and collects parsed events.
* @param {string[]} chunks
* @param {import('eventsource-parser').ParserConfig} [config]
* @returns {Array<import('eventsource-parser').EventSourceMessage>}
*/
function parseChunks(chunks, config = {}) {
const events = [];
const parser = createParser({
...config,
onEvent: (event) => {
events.push(event);
if (config.onEvent) config.onEvent(event);
}
});
for (const chunk of chunks) {
parser.feed(chunk);
}
return events;
}
module.exports = {
createParser,
createEventParser,
parseChunks,
ParseError
};
const assert = require('node:assert/strict');
const { createParser, ParseError } = require('eventsource-parser');
const { createEventParser, parseChunks } = require('../src/index.js');
// 1. createParser returns an EventSourceParser instance with feed and reset methods
{
const parser = createParser({ onEvent: () => {} });
assert.equal(typeof parser.feed, 'function', 'parser.feed should be a function');
assert.equal(typeof parser.reset, 'function', 'parser.reset should be a function');
assert.throws(() => createParser(() => {}), TypeError);
const wrappedParser = createEventParser({ onEvent: () => {} });
assert.equal(typeof wrappedParser.feed, 'function');
assert.equal(typeof wrappedParser.reset, 'function');
}
// 2. EventSourceParser parses basic messages, multiline data, event types, and message IDs
{
const events = [];
const parser = createParser({
onEvent: (event) => events.push(event)
});
parser.feed('data: hello world\n\n');
assert.deepEqual(events[0], {
id: undefined,
event: undefined,
data: 'hello world'
});
parser.feed('id: 42\nevent: custom-event\ndata: line 1\ndata: line 2\n\n');
assert.deepEqual(events[1], {
id: '42',
event: 'custom-event',
data: 'line 1\nline 2'
});
assert.equal(events.length, 2);
}
// 3. EventSourceParser streams partial chunks across line and message boundaries
{
const events = [];
const parser = createParser({
onEvent: (event) => events.push(event)
});
parser.feed('\xEF\xBB\xBFdata: hel');
assert.equal(events.length, 0);
parser.feed('lo\n');
assert.equal(events.length, 0);
parser.feed('\n');
assert.equal(events.length, 1);
assert.deepEqual(events[0], {
id: undefined,
event: undefined,
data: 'hello'
});
const parsedFromHelper = parseChunks(['data: ch', 'unk1\n\n', 'data: chunk2\n\n']);
assert.equal(parsedFromHelper.length, 2);
assert.equal(parsedFromHelper[0].data, 'chunk1');
assert.equal(parsedFromHelper[1].data, 'chunk2');
}
// 4. EventSourceParser emits comment and retry events to their respective callbacks
{
const comments = [];
const retries = [];
const parser = createParser({
onComment: (comment) => comments.push(comment),
onRetry: (retry) => retries.push(retry)
});
parser.feed(': this is a comment\n\n');
assert.deepEqual(comments, ['this is a comment']);
parser.feed('retry: 5000\n\n');
assert.deepEqual(retries, [5000]);
}
// 5. EventSourceParser handles reset and reports invalid retry or unknown fields
{
const errors = [];
const parser = createParser({
onError: (err) => errors.push(err)
});
parser.feed('retry: not-a-number\n\n');
assert.equal(errors.length, 1);
assert.equal(errors[0].type, 'invalid-retry');
assert(errors[0] instanceof ParseError);
parser.feed('unknown-field: some-value\n\n');
assert.equal(errors.length, 2);
assert.equal(errors[1].type, 'unknown-field');
// reset with consume parses trailing incomplete line
parser.feed('trailing-invalid: foo');
parser.reset({ consume: true });
assert.equal(errors.length, 3);
assert.equal(errors[2].type, 'unknown-field');
}
// 6. EventSourceParser enforces maxBufferSize and throws on subsequent feed until reset
{
const errors = [];
const parser = createParser({
maxBufferSize: 10,
onError: (err) => errors.push(err)
});
parser.feed('data: unclosed line exceeding buffer size');
assert.equal(errors.length, 1);
assert.equal(errors[0].type, 'max-buffer-size-exceeded');
assert(errors[0] instanceof ParseError);
// Feeding terminated parser throws
assert.throws(() => parser.feed('data: test\n\n'), /Cannot feed parser/);
// Calling reset allows feeding again
parser.reset();
parser.feed('data: ok\n\n');
}
console.log('Contract tests passed successfully.');
오리진 시더
익명