CodeSampleX

サンプル

bare-events 2.9.1: on

検証済みサンプル — npm bare-events 2.9.1: on. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: emitter.on registers an event listener and returns the…

sha256:8d7ab6ede3695b1749852c9ed05fa780132c59a451ebaad82e90023e584de458

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-26
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 bare-events.on in pkg:npm/bare-events@2.9.1
パッケージ
シンボル
  • bare-events.on
作成日
2026-08-26T11:29:16Z

コントラクト

  1. emitter.on registers an event listener and returns the emitter instance for chaining
  2. emitter.on triggers the listener synchronously with all passed arguments when the event is emitted
  3. emitter.on preserves the EventEmitter instance as this context within listener functions
  4. emitter.on emits a newListener event before adding the listener to the emitter
  5. emitter.on appends listeners in registration order and supports multiple listeners for the same event
  6. EventEmitter.on static helper returns an async iterable yielding argument arrays for emitted events
  7. EventEmitter.on queues emitted events until consumed by next
  8. EventEmitter.on respects AbortSignal and rejects with OPERATION_ABORTED when aborted
  9. EventEmitter.on cleans up its internal listeners when return is called on the iterator
  10. EventEmitter.on rejects iterator promises when the emitter emits an error event

ファイル

  • 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 bare-events.on in pkg:npm/bare-events@2.9.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-events@2.9.1
Demonstrate these symbols/APIs:
  - bare-events.on

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:7f67a1b0835aad8e24131b9a8762f38910ec4bc8e4c73969ce0afd0695c9ff75","contract":["emitter.on registers an event listener and returns the emitter instance for chaining","emitter.on triggers the listener synchronously with all passed arguments when the event is emitted","emitter.on preserves the EventEmitter instance as this context within listener functions","emitter.on emits a newListener event before adding the listener to the emitter","emitter.on appends listeners in registration order and supports multiple listeners for the same event","EventEmitter.on static helper returns an async iterable yielding argument arrays for emitted events","EventEmitter.on queues emitted events until consumed by next","EventEmitter.on respects AbortSignal and rejects with OPERATION_ABORTED when aborted","EventEmitter.on cleans up its internal listeners when return is called on the iterator","EventEmitter.on rejects iterator promises when the emitter emits an error event"],"goal":"verify bare-events.on in pkg:npm/bare-events@2.9.1","kind":"HOW","packages":["pkg:npm/bare-events@2.9.1"],"schemaVersion":1,"symbols":["bare-events.on"]},"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","symbols":["bare-events.on"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-events-on",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-events-on",
      "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-on",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-events": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-events.on in pkg:npm/bare-events@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-events@2.9.1"
  ],
  "symbols": [
    "bare-events.on"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import EventEmitter from 'bare-events';

// 1. emitter.on registers an event listener and returns the emitter instance for chaining
{
  const ee = new EventEmitter();
  const res = ee.on('test', () => {});
  assert.equal(res, ee);
  assert.equal(ee.listenerCount('test'), 1);
}

// 2. emitter.on triggers the listener synchronously with all passed arguments when the event is emitted
{
  const ee = new EventEmitter();
  const calls = [];
  ee.on('greet', (greeting, target, extra) => {
    calls.push({ greeting, target, extra });
  });

  const emitted = ee.emit('greet', 'hello', 'world', 42);
  assert.equal(emitted, true);
  assert.deepEqual(calls, [{ greeting: 'hello', target: 'world', extra: 42 }]);
}

// 3. emitter.on preserves the EventEmitter instance as this context within listener functions
{
  const ee = new EventEmitter();
  let capturedThis = null;
  ee.on('context', function () {
    capturedThis = this;
  });

  ee.emit('context');
  assert.equal(capturedThis, ee);
}

// 4. emitter.on emits a newListener event before adding the listener to the emitter
{
  const ee = new EventEmitter();
  const events = [];
  ee.on('newListener', (eventName, listenerFn) => {
    events.push({
      eventName,
      fn: listenerFn,
      countBeforeAdd: ee.listenerCount(eventName)
    });
  });

  const customHandler = () => {};
  ee.on('custom', customHandler);

  assert.equal(events.length, 1);
  assert.equal(events[0].eventName, 'custom');
  assert.equal(events[0].fn, customHandler);
  assert.equal(events[0].countBeforeAdd, 0);
  assert.equal(ee.listenerCount('custom'), 1);
}

// 5. emitter.on appends listeners in registration order and supports multiple listeners for the same event
{
  const ee = new EventEmitter();
  const order = [];
  ee.on('order', () => order.push('first'));
  ee.on('order', () => order.push('second'));
  ee.on('order', () => order.push('third'));

  ee.emit('order');
  assert.deepEqual(order, ['first', 'second', 'third']);
}

// 6. EventEmitter.on static helper returns an async iterable yielding argument arrays for emitted events
{
  const ee = new EventEmitter();
  const iterator = EventEmitter.on(ee, 'stream');
  assert.equal(typeof iterator[Symbol.asyncIterator], 'function');

  const pendingNext = iterator.next();
  ee.emit('stream', 'alpha', 100);

  const res = await pendingNext;
  assert.deepEqual(res, { value: ['alpha', 100], done: false });
}

// 7. EventEmitter.on queues emitted events until consumed by next
{
  const ee = new EventEmitter();
  const iterator = EventEmitter.on(ee, 'batch');

  ee.emit('batch', 1);
  ee.emit('batch', 2);

  const res1 = await iterator.next();
  const res2 = await iterator.next();
  assert.deepEqual(res1.value, [1]);
  assert.deepEqual(res2.value, [2]);
}

// 8. EventEmitter.on respects AbortSignal and rejects with OPERATION_ABORTED when aborted
{
  const ee = new EventEmitter();
  const ac = new AbortController();
  const iterator = EventEmitter.on(ee, 'aborted-stream', { signal: ac.signal });

  ac.abort('stop');

  await assert.rejects(
    async () => {
      await iterator.next();
    },
    (err) => {
      assert.equal(err.code, 'OPERATION_ABORTED');
      return true;
    }
  );
}

// 9. EventEmitter.on cleans up its internal listeners when return is called on the iterator
{
  const ee = new EventEmitter();
  const iterator = EventEmitter.on(ee, 'cleanup');
  assert.equal(ee.listenerCount('cleanup'), 1);

  const closeRes = await iterator.return();
  assert.deepEqual(closeRes, { done: true });
  assert.equal(ee.listenerCount('cleanup'), 0);
}

// 10. EventEmitter.on rejects iterator promises when the emitter emits an error event
{
  const ee = new EventEmitter();
  const iterator = EventEmitter.on(ee, 'faulty');

  const pendingNext = iterator.next();
  const sampleErr = new Error('simulated failure');
  ee.emit('error', sampleErr);

  await assert.rejects(
    async () => {
      await pendingNext;
    },
    (err) => {
      assert.equal(err, sampleErr);
      return true;
    }
  );
}

オリジンシーダー

匿名