CodeSampleX

Sample

wrappy 1.0.2: wrappy

Verified sample for npm wrappy 1.0.2: wrappy. The contract ran on node 22 · linux alpine/x64 · docker and passed: wrappy returns a wrapper generator function…

sha256:fe88c89d35d48a347a6dcaeb0bb8ca0058a40c22fd24b3d754a9d7a8cc669ea9

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
1
Signing keys that built it
1
Declared environment windows 11 x64 npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

Case

HOW
Goal
verify pkg:npm/wrappy@1.0.2
Packages
Symbols
  • wrappy
Created
2026-08-18T18:16:16Z

Contract

  1. wrappy returns a wrapper generator function when passed a wrapper function
  2. wrappy immediately wraps a target callback when passed both wrapper and target
  3. wrappy copies own enumerable properties from wrapper function to generated wrapper
  4. wrappy copies own enumerable properties from target callback to the returned wrapped function
  5. wrappy does not copy properties if returned function is identical to target callback
  6. wrappy preserves receiver and arguments forwarding to wrapper function
  7. wrappy throws TypeError with need wrapper function when first argument is not a function
  8. wrapFunction helper provides wrapper generator and immediate wrapping interfaces

Files

  • PROMPT.md
  • csx.json
  • index.mjs
  • 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 pkg:npm/wrappy@1.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/wrappy@1.0.2
Demonstrate these symbols/APIs:
  - wrappy

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:975d92c4a134441a71709898631e648d603e08c40c7f9ab2d934213faf640d01","contract":["wrappy returns a wrapper generator function when passed a wrapper function","wrappy immediately wraps a target callback when passed both wrapper and target","wrappy copies own enumerable properties from wrapper function to generated wrapper","wrappy copies own enumerable properties from target callback to the returned wrapped function","wrappy does not copy properties if returned function is identical to target callback","wrappy preserves receiver and arguments forwarding to wrapper function","wrappy throws TypeError with need wrapper function when first argument is not a function","wrapFunction helper provides wrapper generator and immediate wrapping interfaces"],"goal":"verify pkg:npm/wrappy@1.0.2","kind":"HOW","packages":["pkg:npm/wrappy@1.0.2"],"schemaVersion":1,"symbols":["wrappy"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/wrappy@1.0.2"],"schemaVersion":1,"symbols":["wrappy"],"verifierAdapter":"node-typescript@1"}
index.mjs
import wrappy from 'wrappy';

/**
 * Wraps a transformation function so that it can be applied to a callback
 * while preserving callback identity, properties, prototype, and name.
 *
 * @param {Function} fn - The wrapper function.
 * @param {Function} [cb] - Optional target callback to wrap immediately.
 * @returns {Function} The wrapped function or wrapper generator.
 */
export function wrapFunction(fn, cb) {
  if (cb !== undefined) {
    return wrappy(fn, cb);
  }
  return wrappy(fn);
}

export default wrappy;
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "wrappy": "1.0.2"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "wrappy": "1.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/wrappy@1.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/wrappy@1.0.2"
  ],
  "symbols": [
    "wrappy"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import wrappy from 'wrappy';
import { wrapFunction } from '../index.mjs';

// Case 1: wrappy returns a wrapper generator function when passed a wrapper function
{
  const makeMultiplier = wrappy((cb) => {
    return function (...args) {
      return cb(...args) * 2;
    };
  });
  assert.equal(typeof makeMultiplier, 'function', 'wrappy(fn) should return a wrapper generator function');

  const add = (a, b) => a + b;
  const wrappedAdd = makeMultiplier(add);
  assert.equal(typeof wrappedAdd, 'function', 'wrapper generator should return a function');
  assert.equal(wrappedAdd(2, 3), 10, 'wrapped function should apply transformation: (2 + 3) * 2 = 10');
}

// Case 2: wrappy immediately wraps a target callback when passed both wrapper and target
{
  function prependHello(cb) {
    return function (name) {
      return `Hello, ${cb(name)}`;
    };
  }

  function getTarget(name) {
    return name.toUpperCase();
  }

  const greeted = wrappy(prependHello, getTarget);
  assert.equal(typeof greeted, 'function', 'wrappy(fn, cb) should return wrapped callback');
  assert.equal(greeted('world'), 'Hello, WORLD', 'wrappy(fn, cb) should immediately wrap the callback');
}

// Case 3: wrappy copies own enumerable properties from wrapper function to generated wrapper
{
  function myWrapper(cb) {
    return function (...args) {
      return cb(...args);
    };
  }
  myWrapper.customMetadata = 'wrapper-v1';
  myWrapper.version = 42;

  const generator = wrappy(myWrapper);
  assert.equal(generator.customMetadata, 'wrapper-v1', 'wrapper generator should inherit wrapper custom properties');
  assert.equal(generator.version, 42, 'wrapper generator should inherit wrapper version property');
}

// Case 4: wrappy copies own enumerable properties from target callback to the returned wrapped function
{
  const once = wrappy((cb) => {
    let called = false;
    let result;
    return function (...args) {
      if (called) return result;
      called = true;
      result = cb.apply(this, args);
      return result;
    };
  });

  function originalWorker(x) {
    return x * 3;
  }
  originalWorker.role = 'worker';
  originalWorker.taskCount = 5;

  const wrappedWorker = once(originalWorker);

  assert.equal(wrappedWorker.role, 'worker', 'wrapped function should inherit callback own property role');
  assert.equal(wrappedWorker.taskCount, 5, 'wrapped function should inherit callback own property taskCount');
  assert.equal(wrappedWorker(4), 12, 'first call should compute 4 * 3 = 12');
  assert.equal(wrappedWorker(10), 12, 'subsequent calls should return cached result 12');
}

// Case 5: wrappy does not copy properties if returned function is identical to target callback
{
  const identityWrapper = wrappy((cb) => cb);

  function noop() {}
  noop.flag = true;

  const result = identityWrapper(noop);
  assert.equal(result, noop, 'identity wrapper returns the original callback unchanged');
}

// Case 6: wrappy preserves receiver and arguments forwarding to wrapper function
{
  function withContext(cb) {
    return function (...args) {
      return `${this.prefix}: ${cb.apply(this, args)}`;
    };
  }

  const wrapWithCtx = wrappy(withContext);
  const formatter = wrapWithCtx(function (val) {
    return val + this.suffix;
  });

  const context = { prefix: 'PRE', suffix: 'POST' };
  const res = formatter.call(context, 'DATA');
  assert.equal(res, 'PRE: DATAPOST', 'this context and arguments should be preserved');
}

// Case 7: wrappy throws TypeError with need wrapper function when first argument is not a function
{
  assert.throws(
    () => {
      wrappy(null);
    },
    {
      name: 'TypeError',
      message: 'need wrapper function'
    },
    'wrappy(null) should throw TypeError with message "need wrapper function"'
  );

  assert.throws(
    () => {
      wrappy('not-a-function');
    },
    {
      name: 'TypeError',
      message: 'need wrapper function'
    },
    'wrappy non-function should throw TypeError'
  );
}

// Case 8: wrapFunction helper provides wrapper generator and immediate wrapping interfaces
{
  const helperGen = wrapFunction((cb) => (x) => cb(x) + 1);
  const inc = helperGen((x) => x * 10);
  assert.equal(inc(5), 51, 'wrapFunction with 1 arg should act as wrapper generator');

  const direct = wrapFunction((cb) => (x) => cb(x) - 1, (x) => x * 2);
  assert.equal(direct(5), 9, 'wrapFunction with 2 args should immediately wrap callback');
}

console.log('PASS: all wrappy contract assertions passed');

Origin Seeder

anonymous