CodeSampleX

サンプル

tslib 2.9.1: __awaiter

検証済みサンプル — npm tslib 2.9.1: __awaiter. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: require('tslib').__awaiter is exported as a function in…

sha256:8ff69536cb426afd1a6b53f914442d4c591abd31cca6d103e9cc3ff11b9442d0

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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-11-28

ケース

HOW
ゴール
verify tslib.__awaiter in pkg:npm/tslib@2.9.1
パッケージ
シンボル
  • tslib.__awaiter
環境
node 22.23.2
作成日
2026-11-28T01:05:38Z

コントラクト

  1. require('tslib').__awaiter is exported as a function in CommonJS on Node 22
  2. __awaiter binds thisArg and passes _arguments (defaulting to empty when undefined) while awaiting both plain values and Promises in generator yield order
  3. __awaiter defaults P to global Promise when undefined and returns an instance of a custom Promise subclass when P is provided, adopting existing P instances directly
  4. rejected yielded promises are thrown into the generator so try/catch inside the generator can recover and resolve
  5. uncaught errors thrown before or after a yield and unhandled yielded rejections reject the returned Promise instead of throwing synchronously

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

ソースアーティファクトをダウンロード (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 tslib.__awaiter in pkg:npm/tslib@2.9.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tslib@2.9.1
Demonstrate these symbols/APIs:
  - tslib.__awaiter
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:7b96e7f9505a8f5629a3b1fd55bd209007a1c9ad69e66c5848ef96e01143de4c","constraints":{"executionContext":"node"},"contract":["require('tslib').__awaiter is exported as a function in CommonJS on Node 22","__awaiter binds thisArg and passes _arguments (defaulting to empty when undefined) while awaiting both plain values and Promises in generator yield order","__awaiter defaults P to global Promise when undefined and returns an instance of a custom Promise subclass when P is provided, adopting existing P instances directly","rejected yielded promises are thrown into the generator so try/catch inside the generator can recover and resolve","uncaught errors thrown before or after a yield and unhandled yielded rejections reject the returned Promise instead of throwing synchronously"],"goal":"verify tslib.__awaiter in pkg:npm/tslib@2.9.1","kind":"HOW","packages":["pkg:npm/tslib@2.9.1"],"schemaVersion":1,"symbols":["tslib.__awaiter"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/tslib@2.9.1"],"schemaVersion":1,"subject":"pkg:npm/tslib@2.9.1","symbols":["tslib.__awaiter"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "tslib-awaiter-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "tslib-awaiter-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tslib": "2.9.1"
      }
    },
    "node_modules/tslib": {
      "version": "2.9.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
      "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "tslib-awaiter-sample",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "tslib": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify tslib.__awaiter in pkg:npm/tslib@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tslib@2.9.1"
  ],
  "symbols": [
    "tslib.__awaiter"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
"use strict";

const { __awaiter } = require("tslib");

function runSequence(thisArg, args, steps, PromiseCtor) {
  return __awaiter(thisArg, args, PromiseCtor, function* () {
    const receivedArgs = Array.prototype.slice.call(arguments);
    const results = [];
    for (const step of steps) {
      results.push(yield step());
    }
    return {
      receiver: this,
      args: receivedArgs,
      results,
    };
  });
}

function runWithRecovery(promise, fallbackPrefix) {
  return __awaiter(void 0, void 0, void 0, function* () {
    try {
      return yield promise;
    } catch (err) {
      return `${fallbackPrefix}:${err.message}`;
    }
  });
}

function runFailingAfterYield(message) {
  return __awaiter(void 0, void 0, void 0, function* () {
    yield Promise.resolve("ok");
    throw new Error(message);
  });
}

function runImmediateThrow(message) {
  return __awaiter(void 0, void 0, void 0, function* () {
    throw new Error(message);
  });
}

module.exports = {
  runSequence,
  runWithRecovery,
  runFailingAfterYield,
  runImmediateThrow,
};
test/contract.js
"use strict";

const assert = require("node:assert/strict");
const tslib = require("tslib");
const {
  runSequence,
  runWithRecovery,
  runFailingAfterYield,
  runImmediateThrow,
} = require("../src/index.js");

class TrackedPromise extends Promise {
  constructor(executor) {
    super(executor);
    TrackedPromise.constructions += 1;
  }
}
TrackedPromise.constructions = 0;

async function main() {
  // 1. CommonJS export check
  assert.equal(typeof tslib.__awaiter, "function");

  // 2. thisArg binding, _arguments forwarding, and sequential awaiting of plain values and Promises
  const receiver = { id: "ctx-1" };
  const order = [];
  const defaultPromise = runSequence(
    receiver,
    ["alpha", 2],
    [
      () => {
        order.push("plain");
        return 10;
      },
      () =>
        new Promise((resolve) => {
          setImmediate(() => {
            order.push("async");
            resolve(20);
          });
        }),
      () => {
        order.push("resolved");
        return Promise.resolve(30);
      },
    ],
    void 0
  );
  assert.equal(defaultPromise instanceof Promise, true);
  assert.equal(defaultPromise instanceof TrackedPromise, false);

  const seqResult = await defaultPromise;
  assert.equal(seqResult.receiver, receiver);
  assert.deepEqual(seqResult.args, ["alpha", 2]);
  assert.deepEqual(seqResult.results, [10, 20, 30]);
  assert.deepEqual(order, ["plain", "async", "resolved"]);

  // 2b. Omitted _arguments defaults to empty argument list
  const emptyArgsResult = await runSequence(
    receiver,
    void 0,
    [() => "single"],
    void 0
  );
  assert.equal(emptyArgsResult.receiver, receiver);
  assert.deepEqual(emptyArgsResult.args, []);
  assert.deepEqual(emptyArgsResult.results, ["single"]);

  // 3. Custom Promise constructor P is used and existing instances of P are adopted directly
  const existingTracked = TrackedPromise.resolve("already-tracked");
  let syncThenCalled = false;
  const origThen = existingTracked.then.bind(existingTracked);
  existingTracked.then = function (onFulfilled, onRejected) {
    syncThenCalled = true;
    return origThen(onFulfilled, onRejected);
  };

  TrackedPromise.constructions = 0;
  const adoptedPromise = tslib.__awaiter(
    receiver,
    void 0,
    TrackedPromise,
    function* () {
      return [this.id, yield existingTracked];
    }
  );
  assert.equal(syncThenCalled, true);
  assert.equal(adoptedPromise instanceof TrackedPromise, true);
  const adoptedConstructions = TrackedPromise.constructions;
  assert.deepEqual(await adoptedPromise, ["ctx-1", "already-tracked"]);

  TrackedPromise.constructions = 0;
  const wrappedPromise = tslib.__awaiter(
    receiver,
    void 0,
    TrackedPromise,
    function* () {
      return [this.id, yield "plain-wrapped"];
    }
  );
  assert.equal(wrappedPromise instanceof TrackedPromise, true);
  const wrappedConstructions = TrackedPromise.constructions;
  assert.deepEqual(await wrappedPromise, ["ctx-1", "plain-wrapped"]);
  // Plain value requires one additional TrackedPromise construction in adopt()
  assert.equal(wrappedConstructions, adoptedConstructions + 1);

  // 4. Rejected yielded promise enters generator catch block for recovery
  const recovered = await runWithRecovery(
    Promise.reject(new Error("boom")),
    "recovered"
  );
  assert.equal(recovered, "recovered:boom");

  // 5. Uncaught throws (after yield and before first yield) and unhandled yielded rejections reject the Promise
  let pAfterYield;
  assert.doesNotThrow(() => {
    pAfterYield = runFailingAfterYield("after-yield");
  });
  await assert.rejects(pAfterYield, { name: "Error", message: "after-yield" });

  let pImmediate;
  assert.doesNotThrow(() => {
    pImmediate = runImmediateThrow("before-yield");
  });
  await assert.rejects(pImmediate, { name: "Error", message: "before-yield" });

  let pUnhandledYield;
  assert.doesNotThrow(() => {
    pUnhandledYield = tslib.__awaiter(void 0, void 0, void 0, function* () {
      yield Promise.reject(new Error("unhandled-yield"));
    });
  });
  await assert.rejects(pUnhandledYield, {
    name: "Error",
    message: "unhandled-yield",
  });
}

main().catch((err) => {
  console.error(err);
  process.exitCode = 1;
});

オリジンシーダー

匿名