Sample
mitt 3.0.1: mitt
Verified sample for npm mitt 3.0.1: mitt. The contract ran on node 22 · linux alpine/x64 · docker and passed: mitt() initializes an event emitter instance…
sha256:3b5f98f9232ac04551e5ab1a17fe7485964eee5edc4eb82ff3f5d4b05a7a5976
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
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
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 mitt in pkg:npm/mitt@3.0.1
- Packages
- Symbols
-
- mitt
- Environment
- node 22.23.2
- Created
- 2026-08-26T01:03:33Z
Contract
- mitt() initializes an event emitter instance with an all Map
- emitter.on registers event handlers and emitter.emit delivers event payloads to matching listeners
- emitter.off removes a specific event handler from the registered handlers
- emitter.off without handler removes all registered handlers for the given event type
- emitter.on('*', handler) receives event type name and payload for all emitted events
- emitter initialized with existing Map shares and preserves pre-populated handlers
- emitter.all.clear resets and removes all registered listeners across all event types
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Source
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 mitt in pkg:npm/mitt@3.0.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/mitt@3.0.1
Demonstrate these symbols/APIs:
- mitt
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.
{"case":{"caseId":"case:sha256:69c7ce4ba7500ee255b7a37c004a1fcd0b92175086fdc2dd0b11147097201325","constraints":{"executionContext":"node"},"contract":["mitt() initializes an event emitter instance with an all Map","emitter.on registers event handlers and emitter.emit delivers event payloads to matching listeners","emitter.off removes a specific event handler from the registered handlers","emitter.off without handler removes all registered handlers for the given event type","emitter.on('*', handler) receives event type name and payload for all emitted events","emitter initialized with existing Map shares and preserves pre-populated handlers","emitter.all.clear resets and removes all registered listeners across all event types"],"goal":"verify mitt in pkg:npm/mitt@3.0.1","kind":"HOW","packages":["pkg:npm/mitt@3.0.1"],"schemaVersion":1,"symbols":["mitt"]},"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/mitt@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/mitt@3.0.1","symbols":["mitt"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-mitt",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-mitt",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"mitt": "3.0.1"
}
},
"node_modules/mitt": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz",
"integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==",
"license": "MIT"
}
}
}
{
"name": "sample-mitt",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"mitt": "3.0.1"
}
}
{
"schemaVersion": 1,
"goal": "verify mitt in pkg:npm/mitt@3.0.1",
"kind": "HOW",
"packages": [
"pkg:npm/mitt@3.0.1"
],
"symbols": [
"mitt"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import mitt from 'mitt';
/**
* Creates and returns a new mitt event emitter instance.
* @param {Map} [all] Optional Map of event handlers to initialize with.
* @returns {import('mitt').Emitter} An initialized event emitter.
*/
export function createEmitter(all) {
return mitt(all);
}
/**
* Subscribes to an event with a one-time listener that auto-unregisters upon first execution.
* @param {import('mitt').Emitter} emitter The mitt emitter instance.
* @param {string|symbol} type Event name to listen for.
* @param {Function} handler Event handler callback.
* @returns {Function} Function to remove the once listener manually if needed.
*/
export function once(emitter, type, handler) {
const wrapped = (event) => {
emitter.off(type, wrapped);
handler(event);
};
emitter.on(type, wrapped);
return () => emitter.off(type, wrapped);
}
/**
* Collects emitted events for a specific event type into an array.
* @param {import('mitt').Emitter} emitter The mitt emitter instance.
* @param {string|symbol} type Event name to collect.
* @returns {{ events: Array<any>, unsubscribe: Function }} Collected events array and unsubscribe function.
*/
export function collectEvents(emitter, type) {
const events = [];
const handler = (evt) => {
events.push(evt);
};
emitter.on(type, handler);
return {
events,
unsubscribe: () => emitter.off(type, handler),
};
}
export { mitt };
export default mitt;
import assert from 'node:assert/strict';
import mitt from 'mitt';
import { createEmitter, once, collectEvents } from '../src/index.mjs';
// 1. mitt() initializes an event emitter instance with an all Map
{
const emitter = mitt();
assert.equal(typeof emitter.on, 'function');
assert.equal(typeof emitter.off, 'function');
assert.equal(typeof emitter.emit, 'function');
assert(emitter.all instanceof Map);
assert.equal(emitter.all.size, 0);
const helperEmitter = createEmitter();
assert(helperEmitter.all instanceof Map);
assert.equal(helperEmitter.all.size, 0);
}
// 2. emitter.on registers event handlers and emitter.emit delivers event payloads to matching listeners
{
const emitter = mitt();
const received = [];
emitter.on('msg', (data) => {
received.push(data);
});
emitter.emit('msg', { text: 'hello' });
emitter.emit('msg', { text: 'world' });
assert.deepEqual(received, [{ text: 'hello' }, { text: 'world' }]);
}
// 3. emitter.off removes a specific event handler from the registered handlers
{
const emitter = mitt();
const receivedA = [];
const receivedB = [];
const handlerA = (val) => receivedA.push(val);
const handlerB = (val) => receivedB.push(val);
emitter.on('data', handlerA);
emitter.on('data', handlerB);
emitter.emit('data', 1);
assert.deepEqual(receivedA, [1]);
assert.deepEqual(receivedB, [1]);
emitter.off('data', handlerA);
emitter.emit('data', 2);
assert.deepEqual(receivedA, [1]);
assert.deepEqual(receivedB, [1, 2]);
}
// 4. emitter.off without handler removes all registered handlers for the given event type
{
const emitter = mitt();
let calls = 0;
emitter.on('ping', () => calls++);
emitter.on('ping', () => calls++);
emitter.emit('ping');
assert.equal(calls, 2);
emitter.off('ping');
emitter.emit('ping');
assert.equal(calls, 2);
}
// 5. emitter.on('*', handler) receives event type name and payload for all emitted events
{
const emitter = mitt();
const wildcardLog = [];
emitter.on('*', (type, payload) => {
wildcardLog.push({ type, payload });
});
emitter.emit('user:login', { id: 42 });
emitter.emit('user:logout', { id: 42 });
assert.deepEqual(wildcardLog, [
{ type: 'user:login', payload: { id: 42 } },
{ type: 'user:logout', payload: { id: 42 } },
]);
}
// 6. emitter initialized with existing Map shares and preserves pre-populated handlers
{
const customMap = new Map();
const initialLog = [];
customMap.set('custom', [(data) => initialLog.push(data)]);
const emitter = mitt(customMap);
assert.equal(emitter.all, customMap);
emitter.emit('custom', 'from-custom');
assert.deepEqual(initialLog, ['from-custom']);
}
// 7. emitter.all.clear resets and removes all registered listeners across all event types
{
const emitter = mitt();
let count = 0;
emitter.on('a', () => count++);
emitter.on('b', () => count++);
emitter.on('*', () => count++);
emitter.emit('a');
assert.equal(count, 2); // 'a' handler + wildcard handler
emitter.all.clear();
emitter.emit('a');
emitter.emit('b');
assert.equal(count, 2);
}
// 8. Helper utilities once and collectEvents integrate correctly with mitt lifecycle
{
const emitter = mitt();
const onceReceived = [];
once(emitter, 'single', (data) => onceReceived.push(data));
emitter.emit('single', 'first');
emitter.emit('single', 'second');
assert.deepEqual(onceReceived, ['first']);
const collector = collectEvents(emitter, 'stream');
emitter.emit('stream', 100);
emitter.emit('stream', 200);
assert.deepEqual(collector.events, [100, 200]);
collector.unsubscribe();
emitter.emit('stream', 300);
assert.deepEqual(collector.events, [100, 200]);
}
console.log('Contract tests passed successfully.');
Origin Seeder
anonymous