CodeSampleX

Sample

bare-events 2.9.1: once

Verified sample for npm bare-events 2.9.1: once. The contract ran on node 22 · linux alpine/x64 · docker and passed: emitter.once registers a listener that…

sha256:6588cc35a188d36b6375a1b9e48f329221d9d9b263eafeda464b3bf6278e743a

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify bare-events.once in pkg:npm/bare-events@2.9.1
Packages
Symbols
  • bare-events.once
Created
2026-08-26T11:31:14Z

Contract

  1. emitter.once registers a listener that is invoked on the first emit and automatically removed for subsequent emissions
  2. emitter.once returns the EventEmitter instance to allow method chaining
  3. emitter.addOnceListener functions identically to once as an alias
  4. emitter.prependOnceListener adds a one-time listener to the beginning of the listener list
  5. emitter.off and removeListener can remove a once listener before it is emitted
  6. EventEmitter.once static helper returns a Promise that resolves with an array of emitted event arguments
  7. EventEmitter.once static helper rejects if the emitter emits an error event while waiting for another event
  8. EventEmitter.once static helper can listen directly to the error event and resolves with the emitted error
  9. EventEmitter.once static helper rejects when an AbortSignal option is aborted

Files

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

Download the source artifact (tar.gz)

Source

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.once 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.once

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:dca6e335ec4370dee58cacbfc2162316bc27ce26fc1d7ffeb10bfca5e45ba286","contract":["emitter.once registers a listener that is invoked on the first emit and automatically removed for subsequent emissions","emitter.once returns the EventEmitter instance to allow method chaining","emitter.addOnceListener functions identically to once as an alias","emitter.prependOnceListener adds a one-time listener to the beginning of the listener list","emitter.off and removeListener can remove a once listener before it is emitted","EventEmitter.once static helper returns a Promise that resolves with an array of emitted event arguments","EventEmitter.once static helper rejects if the emitter emits an error event while waiting for another event","EventEmitter.once static helper can listen directly to the error event and resolves with the emitted error","EventEmitter.once static helper rejects when an AbortSignal option is aborted"],"goal":"verify bare-events.once in pkg:npm/bare-events@2.9.1","kind":"HOW","packages":["pkg:npm/bare-events@2.9.1"],"schemaVersion":1,"symbols":["bare-events.once"]},"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.once"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-events-once",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-events-once",
      "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-once",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-events": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-events.once in pkg:npm/bare-events@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-events@2.9.1"
  ],
  "symbols": [
    "bare-events.once"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import EventEmitter from 'bare-events';

// 1. emitter.once registers a listener that is invoked on the first emit and automatically removed for subsequent emissions
{
  const ee = new EventEmitter();
  let callCount = 0;
  let receivedArgs = null;

  ee.once('greet', (a, b) => {
    callCount++;
    receivedArgs = [a, b];
  });

  assert.equal(ee.listenerCount('greet'), 1);

  const emitted1 = ee.emit('greet', 'hello', 'world');
  assert.equal(emitted1, true);
  assert.equal(callCount, 1);
  assert.deepEqual(receivedArgs, ['hello', 'world']);
  assert.equal(ee.listenerCount('greet'), 0);

  const emitted2 = ee.emit('greet', 'again', 'there');
  assert.equal(emitted2, false);
  assert.equal(callCount, 1);
}

// 2. emitter.once returns the EventEmitter instance to allow method chaining
{
  const ee = new EventEmitter();
  const returned = ee.once('event1', () => {}).once('event2', () => {});
  assert.equal(returned, ee);
  assert.equal(ee.listenerCount('event1'), 1);
  assert.equal(ee.listenerCount('event2'), 1);
}

// 3. emitter.addOnceListener functions identically to once as an alias
{
  const ee = new EventEmitter();
  let called = false;
  ee.addOnceListener('aliasTest', () => {
    called = true;
  });

  assert.equal(ee.listenerCount('aliasTest'), 1);
  ee.emit('aliasTest');
  assert.equal(called, true);
  assert.equal(ee.listenerCount('aliasTest'), 0);
}

// 4. emitter.prependOnceListener adds a one-time listener to the beginning of the listener list
{
  const ee = new EventEmitter();
  const executionOrder = [];

  ee.on('ordered', () => executionOrder.push('normal-1'));
  ee.prependOnceListener('ordered', () => executionOrder.push('prepend-once'));
  ee.on('ordered', () => executionOrder.push('normal-2'));

  ee.emit('ordered');
  assert.deepEqual(executionOrder, ['prepend-once', 'normal-1', 'normal-2']);

  ee.emit('ordered');
  assert.deepEqual(executionOrder, ['prepend-once', 'normal-1', 'normal-2', 'normal-1', 'normal-2']);
}

// 5. emitter.off and removeListener can remove a once listener before it is emitted
{
  const ee = new EventEmitter();
  let called = false;
  const listener = () => {
    called = true;
  };

  ee.once('cancelMe', listener);
  assert.equal(ee.listenerCount('cancelMe'), 1);

  ee.off('cancelMe', listener);
  assert.equal(ee.listenerCount('cancelMe'), 0);

  ee.emit('cancelMe');
  assert.equal(called, false);
}

// 6. EventEmitter.once static helper returns a Promise that resolves with an array of emitted event arguments
{
  const ee = new EventEmitter();
  const promise = EventEmitter.once(ee, 'asyncEvent');

  ee.emit('asyncEvent', 42, { key: 'value' });
  const result = await promise;

  assert.deepEqual(result, [42, { key: 'value' }]);
}

// 7. EventEmitter.once static helper rejects if the emitter emits an error event while waiting for another event
{
  const ee = new EventEmitter();
  const promise = EventEmitter.once(ee, 'expectedEvent');
  const testError = new Error('boom');

  ee.emit('error', testError);

  await assert.rejects(promise, (err) => {
    assert.equal(err, testError);
    return true;
  });
}

// 8. EventEmitter.once static helper can listen directly to the error event and resolves with the emitted error
{
  const ee = new EventEmitter();
  const promise = EventEmitter.once(ee, 'error');
  const testError = new Error('handled error');

  ee.emit('error', testError);
  const result = await promise;

  assert.deepEqual(result, [testError]);
}

// 9. EventEmitter.once static helper rejects when an AbortSignal option is aborted
{
  const ee = new EventEmitter();
  const ac = new AbortController();
  const promise = EventEmitter.once(ee, 'neverEmitted', { signal: ac.signal });

  ac.abort(new Error('aborted-reason'));

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

Origin Seeder

anonymous