CodeSampleX

샘플

bare-events 2.9.1

검증된 샘플 — npm bare-events 2.9.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: EventEmitter can be instantiated and exposes event listener and…

sha256:b34b91b43684e00999b5bf4804c65359cbfbc48fe958ac50586442e5c871de2f

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
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-23
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-07

케이스

HOW
목표
verify pkg:npm/bare-events@2.9.1
패키지
생성일
2026-08-23T15:56:46Z

컨트랙트

  1. EventEmitter can be instantiated and exposes event listener and emission methods
  2. on and emit register listener functions and synchronously invoke them with passed arguments
  3. once registers a one-time listener that executes exactly once and is automatically removed
  4. off removes a previously registered listener function for a specific event
  5. removeAllListeners removes all listeners for a given event or all registered events
  6. prependListener and prependOnceListener add listeners to the beginning of the invocation chain
  7. EventEmitter.once static helper returns a promise resolving with event arguments when emitted
  8. EventEmitter.on static helper returns an async iterable yielding event arguments until aborted
  9. EventEmitter.forward lazily forwards events from a source emitter to a destination emitter
  10. listenerCount and eventNames accurately reflect registered listeners on the emitter

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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/bare-events@2.9.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-events@2.9.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.
csx.json
{"case":{"caseId":"case:sha256:b44aa762836e85b1739d6d94532ca105f4feaefce7e9bb3dbf1d1a3a4211f1eb","contract":["EventEmitter can be instantiated and exposes event listener and emission methods","on and emit register listener functions and synchronously invoke them with passed arguments","once registers a one-time listener that executes exactly once and is automatically removed","off removes a previously registered listener function for a specific event","removeAllListeners removes all listeners for a given event or all registered events","prependListener and prependOnceListener add listeners to the beginning of the invocation chain","EventEmitter.once static helper returns a promise resolving with event arguments when emitted","EventEmitter.on static helper returns an async iterable yielding event arguments until aborted","EventEmitter.forward lazily forwards events from a source emitter to a destination emitter","listenerCount and eventNames accurately reflect registered listeners on the emitter"],"goal":"verify pkg:npm/bare-events@2.9.1","kind":"HOW","packages":["pkg:npm/bare-events@2.9.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/bare-events@2.9.1"],"schemaVersion":1,"subject":"pkg:npm/bare-events@2.9.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-events",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-events",
      "version": "1.0.0",
      "dependencies": {
        "bare-events": "2.9.1"
      }
    },
    "node_modules/bare-events": {
      "version": "2.9.1",
      "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.1.tgz",
      "integrity": "sha512-Z0oHEHAFDZkffN8Qc39zNZjQlMDkPJRyyyZieU1VH7u8c5S+qHZ2S8ixdKIAxEjfHO7FJxXmJWgteOghVanIsg==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "bare-abort-controller": "*"
      },
      "peerDependenciesMeta": {
        "bare-abort-controller": {
          "optional": true
        }
      }
    }
  }
}
package.json
{
  "name": "sample-bare-events",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-events": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-events@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-events@2.9.1"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import EventEmitter from 'bare-events';

// 1. EventEmitter can be instantiated and exposes event listener and emission methods
{
  const ee = new EventEmitter();
  assert.ok(ee instanceof EventEmitter);
  assert.equal(typeof ee.on, 'function');
  assert.equal(typeof ee.emit, 'function');
  assert.equal(typeof ee.once, 'function');
  assert.equal(typeof ee.off, 'function');
  assert.equal(typeof ee.addListener, 'function');
  assert.equal(typeof ee.removeListener, 'function');
  assert.equal(typeof ee.removeAllListeners, 'function');
}

// 2. on and emit register listener functions and synchronously invoke them with passed arguments
{
  const ee = new EventEmitter();
  const received = [];
  ee.on('data', (a, b) => {
    received.push({ a, b });
  });

  const emitted1 = ee.emit('data', 'first', 1);
  const emitted2 = ee.emit('data', 'second', 2);
  const emitted3 = ee.emit('unhandled', 'third');

  assert.equal(emitted1, true);
  assert.equal(emitted2, true);
  assert.equal(emitted3, false);
  assert.deepEqual(received, [
    { a: 'first', b: 1 },
    { a: 'second', b: 2 }
  ]);
}

// 3. once registers a one-time listener that executes exactly once and is automatically removed
{
  const ee = new EventEmitter();
  let count = 0;
  ee.once('tick', () => {
    count++;
  });

  ee.emit('tick');
  ee.emit('tick');
  assert.equal(count, 1);
  assert.equal(ee.listenerCount('tick'), 0);
}

// 4. off removes a previously registered listener function for a specific event
{
  const ee = new EventEmitter();
  let calls = 0;
  const handler = () => {
    calls++;
  };

  ee.on('custom', handler);
  ee.emit('custom');
  assert.equal(calls, 1);

  ee.off('custom', handler);
  ee.emit('custom');
  assert.equal(calls, 1);
}

// 5. removeAllListeners removes all listeners for a given event or all registered events
{
  const ee = new EventEmitter();
  ee.on('eventA', () => {});
  ee.on('eventA', () => {});
  ee.on('eventB', () => {});

  assert.equal(ee.listenerCount('eventA'), 2);
  ee.removeAllListeners('eventA');
  assert.equal(ee.listenerCount('eventA'), 0);
  assert.equal(ee.listenerCount('eventB'), 1);

  ee.removeAllListeners();
  assert.equal(ee.listenerCount('eventB'), 0);
  assert.deepEqual(ee.eventNames(), []);
}

// 6. prependListener and prependOnceListener add listeners to the beginning of the invocation chain
{
  const ee = new EventEmitter();
  const order = [];

  ee.on('order', () => order.push('normal'));
  ee.prependListener('order', () => order.push('prepended'));
  ee.prependOnceListener('order', () => order.push('prependedOnce'));

  ee.emit('order');
  assert.deepEqual(order, ['prependedOnce', 'prepended', 'normal']);

  ee.emit('order');
  assert.deepEqual(order, ['prependedOnce', 'prepended', 'normal', 'prepended', 'normal']);
}

// 7. EventEmitter.once static helper returns a promise resolving with event arguments when emitted
{
  const ee = new EventEmitter();
  const promise = EventEmitter.once(ee, 'success');
  ee.emit('success', 'value1', 'value2');
  const result = await promise;
  assert.deepEqual(result, ['value1', 'value2']);
}

// 8. EventEmitter.on static helper returns an async iterable yielding event arguments until aborted
{
  const ee = new EventEmitter();
  const ac = new AbortController();
  const iterator = EventEmitter.on(ee, 'stream', { signal: ac.signal });

  ee.emit('stream', 'first-item');
  ee.emit('stream', 'second-item');

  const item1 = await iterator.next();
  assert.deepEqual(item1.value, ['first-item']);
  assert.equal(item1.done, false);

  const item2 = await iterator.next();
  assert.deepEqual(item2.value, ['second-item']);
  assert.equal(item2.done, false);

  ac.abort();
}

// 9. EventEmitter.forward lazily forwards events from a source emitter to a destination emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'forwardedEvent');

  const received = [];
  dest.on('forwardedEvent', (msg) => {
    received.push(msg);
  });

  src.emit('forwardedEvent', 'payload');
  assert.deepEqual(received, ['payload']);
}

// 10. listenerCount and eventNames accurately reflect registered listeners on the emitter
{
  const ee = new EventEmitter();
  const fn1 = () => {};
  const fn2 = () => {};

  ee.on('alpha', fn1);
  ee.on('alpha', fn2);
  ee.on('beta', fn1);

  assert.equal(ee.listenerCount('alpha'), 2);
  assert.equal(ee.listenerCount('beta'), 1);
  assert.equal(ee.listenerCount('gamma'), 0);

  const names = ee.eventNames();
  assert.deepEqual(names.sort(), ['alpha', 'beta']);
}

오리진 시더

익명