サンプル
eventsource-parser 3.1.1
検証済みサンプル — npm eventsource-parser 3.1.1. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: assert createParser parses single-line and multiline…
sha256:9041007dffbc5e94ed01f18ab87cbef5065683b0e2c4792f6aa517f51307dafb
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 x64 npm
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- verify pkg:npm/eventsource-parser@3.1.1
- パッケージ
- 作成日
- 2026-08-27T22:16:35Z
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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.');
オリジンシーダー
匿名