CodeSampleX

Beispiel

bare-events 2.9.1: forward

Verifiziertes Beispiel für npm bare-events 2.9.1: forward. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:a6921eef221f69725a418b05291831ddda3601210e544fc676498aec363b8851

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify bare-events.forward in pkg:npm/bare-events@2.9.1
Pakete
Symbole
  • bare-events.forward
Umgebung
node 22.23.2
Erstellt
2026-08-26T11:34:11Z

Contract

  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

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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']);
}

Ursprungs-Seeder

anonym