CodeSampleX

샘플

wrappy 1.0.2: wrappy

검증된 샘플 — npm wrappy 1.0.2: wrappy. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: wrappy returns a wrapper generator function when passed a…

sha256:fe88c89d35d48a347a6dcaeb0bb8ca0058a40c22fd24b3d754a9d7a8cc669ea9

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 windows 11 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/wrappy@1.0.2
패키지
심벌
  • wrappy
생성일
2026-08-18T18:16:16Z

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • 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 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');

오리진 시더

익명