CodeSampleX

サンプル

bare-events 2.9.1: forward

検証済みサンプル — npm bare-events 2.9.1: forward. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: EventEmitter.forward lazily attaches a listener to the…

sha256:a6921eef221f69725a418b05291831ddda3601210e544fc676498aec363b8851

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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.forward in pkg:npm/bare-events@2.9.1
パッケージ
シンボル
  • bare-events.forward
環境
node 22.23.2
作成日
2026-08-26T11:34:11Z

コントラクト

  1. EventEmitter.forward lazily attaches a listener to the source emitter only when a listener is registered on the destination emitter
  2. forwarded events emitted on the source emitter are received by listeners on the destination emitter with original arguments
  3. multiple listeners on the destination emitter share a single forwarding listener on the source emitter
  4. removing all listeners for an event on the destination emitter detaches the forwarding listener from the source emitter
  5. forward supports an array of multiple event names managed independently
  6. forward accepts an optional custom emit function in options to intercept forwarded events

ファイル

  • 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.forward 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.forward
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.
csx.json
{"case":{"caseId":"case:sha256:f12170e3edc0da2c6b5618d4a0150806ec0933f5604727d16bcf976c3e4d923f","constraints":{"executionContext":"node"},"contract":["EventEmitter.forward lazily attaches a listener to the source emitter only when a listener is registered on the destination emitter","forwarded events emitted on the source emitter are received by listeners on the destination emitter with original arguments","multiple listeners on the destination emitter share a single forwarding listener on the source emitter","removing all listeners for an event on the destination emitter detaches the forwarding listener from the source emitter","forward supports an array of multiple event names managed independently","forward accepts an optional custom emit function in options to intercept forwarded events"],"goal":"verify bare-events.forward in pkg:npm/bare-events@2.9.1","kind":"HOW","packages":["pkg:npm/bare-events@2.9.1"],"schemaVersion":1,"symbols":["bare-events.forward"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","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.forward"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-events-forward",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-events-forward",
      "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-forward",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-events": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-events.forward in pkg:npm/bare-events@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-events@2.9.1"
  ],
  "symbols": [
    "bare-events.forward"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import EventEmitter from 'bare-events';

// 1. EventEmitter.forward lazily attaches a listener to the source emitter only when a listener is registered on the destination emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'eventA');

  assert.equal(src.listenerCount('eventA'), 0);
  assert.equal(dest.listenerCount('eventA'), 0);

  const handler = () => {};
  dest.on('eventA', handler);
  assert.equal(src.listenerCount('eventA'), 1);
  assert.equal(dest.listenerCount('eventA'), 1);
}

// 2. forwarded events emitted on the source emitter are received by listeners on the destination emitter with original arguments
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'message');

  const received = [];
  dest.on('message', (arg1, arg2) => {
    received.push({ arg1, arg2 });
  });

  const emitted = src.emit('message', 'hello', 42);
  assert.equal(emitted, true);
  assert.deepEqual(received, [{ arg1: 'hello', arg2: 42 }]);
}

// 3. multiple listeners on the destination emitter share a single forwarding listener on the source emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'shared');

  const list1 = [];
  const list2 = [];
  dest.on('shared', (val) => list1.push(val));
  dest.on('shared', (val) => list2.push(val));

  assert.equal(dest.listenerCount('shared'), 2);
  assert.equal(src.listenerCount('shared'), 1);

  src.emit('shared', 'broadcast');
  assert.deepEqual(list1, ['broadcast']);
  assert.deepEqual(list2, ['broadcast']);
}

// 4. removing all listeners for an event on the destination emitter detaches the forwarding listener from the source emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'cleanup');

  const h1 = () => {};
  const h2 = () => {};
  dest.on('cleanup', h1);
  dest.on('cleanup', h2);
  assert.equal(src.listenerCount('cleanup'), 1);

  dest.off('cleanup', h1);
  assert.equal(src.listenerCount('cleanup'), 1);

  dest.off('cleanup', h2);
  assert.equal(src.listenerCount('cleanup'), 0);
}

// 5. forward supports an array of multiple event names managed independently
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, ['first', 'second']);

  assert.equal(src.listenerCount('first'), 0);
  assert.equal(src.listenerCount('second'), 0);

  const firstCalls = [];
  const secondCalls = [];
  dest.on('first', (x) => firstCalls.push(x));
  assert.equal(src.listenerCount('first'), 1);
  assert.equal(src.listenerCount('second'), 0);

  dest.on('second', (y) => secondCalls.push(y));
  assert.equal(src.listenerCount('second'), 1);

  src.emit('first', 'data-1');
  src.emit('second', 'data-2');
  assert.deepEqual(firstCalls, ['data-1']);
  assert.deepEqual(secondCalls, ['data-2']);

  dest.removeAllListeners('first');
  assert.equal(src.listenerCount('first'), 0);
  assert.equal(src.listenerCount('second'), 1);
}

// 6. forward accepts an optional custom emit function in options to intercept forwarded events
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  const intercepted = [];

  EventEmitter.forward(src, dest, 'custom', {
    emit(name, ...args) {
      intercepted.push({ name, args });
      dest.emit(name, ...args.map((s) => s.toUpperCase()));
    }
  });

  const received = [];
  dest.on('custom', (val) => received.push(val));

  src.emit('custom', 'lowercase');
  assert.deepEqual(intercepted, [{ name: 'custom', args: ['lowercase'] }]);
  assert.deepEqual(received, ['LOWERCASE']);
}

オリジンシーダー

匿名