CodeSampleX

Beispiel

node-abi 4.33.0: getAbi, getTarget

Verifiziertes Beispiel für npm node-abi 4.33.0: getAbi, getTarget. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:ef8e9917d74c4a1a694ad2b73a6eed2ce779a0785dea81198969eb81a7166e86

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-28

Fall

HOW
Ziel
verify pkg:npm/node-abi@4.33.0
Pakete
Symbole
  • node-abi.getAbi
  • node-abi.getTarget
Umgebung
node 22.23.2
Erstellt
2026-08-28T05:39:31Z

Contract

  1. getAbi resolves Node.js target version to corresponding ABI version string
  2. getAbi resolves Electron target version to corresponding ABI version string
  3. getAbi returns numeric ABI string input directly and strips leading v prefix from version string
  4. getAbi throws an Error for unsupported or unknown version ranges
  5. getTarget resolves Node.js ABI version string to target version
  6. getTarget resolves Electron ABI version string to target version
  7. getTarget returns non-numeric version string input directly
  8. getTarget throws an Error for unknown ABI versions
  9. allTargets and supportedTargets export target registry entries with runtime, target, abi, and lts properties

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/node-abi@4.33.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/node-abi@4.33.0
Demonstrate these symbols/APIs:
  - node-abi.getAbi
  - node-abi.getTarget

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:857c4b43d4194ddfc41ee5a22d9dabb8061595b3d725788c5a401f8674acd79e","contract":["getAbi resolves Node.js target version to corresponding ABI version string","getAbi resolves Electron target version to corresponding ABI version string","getAbi returns numeric ABI string input directly and strips leading v prefix from version string","getAbi throws an Error for unsupported or unknown version ranges","getTarget resolves Node.js ABI version string to target version","getTarget resolves Electron ABI version string to target version","getTarget returns non-numeric version string input directly","getTarget throws an Error for unknown ABI versions","allTargets and supportedTargets export target registry entries with runtime, target, abi, and lts properties"],"goal":"verify pkg:npm/node-abi@4.33.0","kind":"HOW","packages":["pkg:npm/node-abi@4.33.0"],"schemaVersion":1,"symbols":["node-abi.getAbi","node-abi.getTarget"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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/node-abi@4.33.0"],"schemaVersion":1,"subject":"pkg:npm/node-abi@4.33.0","symbols":["node-abi.getAbi","node-abi.getTarget"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-node-abi",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-node-abi",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "node-abi": "4.33.0"
      }
    },
    "node_modules/node-abi": {
      "version": "4.33.0",
      "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-4.33.0.tgz",
      "integrity": "sha512-vLBWCKb+7LWsX+TbfzWOkw0W81m377tyx3hOweBTjO43CXZnRGS1/JPWs20fr0PgZyDXk6ROYrylsEycK8raDA==",
      "license": "MIT",
      "dependencies": {
        "semver": "^7.6.3"
      },
      "engines": {
        "node": ">=22.12.0"
      }
    },
    "node_modules/semver": {
      "version": "7.8.5",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
      "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "sample-node-abi",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for node-abi",
  "type": "module",
  "main": "src/index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "node-abi": "4.33.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/node-abi@4.33.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-abi@4.33.0"
  ],
  "symbols": [
    "node-abi.getAbi",
    "node-abi.getTarget"
  ]
}
src/index.mjs
import {
  getAbi,
  getTarget,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  additionalTargets,
  futureTargets
} from 'node-abi';

export function getNodeAbi(target) {
  return getAbi(target, 'node');
}

export function getElectronAbi(target) {
  return getAbi(target, 'electron');
}

export function getNodeTarget(abi) {
  return getTarget(abi, 'node');
}

export function getElectronTarget(abi) {
  return getTarget(abi, 'electron');
}

export function isTargetSupported(target, runtime = 'node') {
  const normalized = target.replace(/^v/, '');
  return supportedTargets.some((t) => t.runtime === runtime && t.target === normalized);
}

export function getTargetInfo(abi, runtime = 'node') {
  return allTargets.find((t) => t.runtime === runtime && t.abi === String(abi)) || null;
}

export {
  getAbi,
  getTarget,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  additionalTargets,
  futureTargets
};
test/contract.mjs
import assert from 'node:assert';
import {
  getAbi,
  getTarget,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  additionalTargets,
  futureTargets,
  getNodeAbi,
  getElectronAbi,
  getNodeTarget,
  getElectronTarget,
  isTargetSupported,
  getTargetInfo
} from '../src/index.mjs';

// 1. getAbi resolves Node.js target version to corresponding ABI version string
{
  assert.strictEqual(getAbi('20.0.0', 'node'), '115');
  assert.strictEqual(getAbi('22.0.0', 'node'), '127');
  assert.strictEqual(getAbi('18.16.0', 'node'), '108');
  assert.strictEqual(getAbi('20.0.0'), '115');
  assert.strictEqual(getNodeAbi('20.0.0'), '115');
  assert.strictEqual(getNodeAbi('22.0.0'), '127');
}

// 2. getAbi resolves Electron target version to corresponding ABI version string
{
  assert.strictEqual(getAbi('25.0.0', 'electron'), '116');
  assert.strictEqual(getAbi('28.0.0', 'electron'), '119');
  assert.strictEqual(getAbi('30.0.0', 'electron'), '123');
  assert.strictEqual(getElectronAbi('25.0.0'), '116');
  assert.strictEqual(getElectronAbi('28.0.0'), '119');
}

// 3. getAbi returns numeric ABI string input directly and strips leading v prefix from version string
{
  assert.strictEqual(getAbi('115', 'node'), '115');
  assert.strictEqual(getAbi('116', 'electron'), '116');
  assert.strictEqual(getAbi('v20.0.0', 'node'), '115');
  assert.strictEqual(getAbi('v25.0.0', 'electron'), '116');
  assert.strictEqual(getNodeAbi('v22.0.0'), '127');
}

// 4. getAbi throws an Error for unsupported or unknown version ranges
{
  assert.throws(
    () => getAbi('999.0.0', 'node'),
    /Could not detect abi for version 999.0.0 and runtime node/
  );
  assert.throws(
    () => getAbi('999.0.0', 'electron'),
    /Could not detect abi for version 999.0.0 and runtime electron/
  );
  assert.throws(
    () => getNodeAbi('999.0.0'),
    /Could not detect abi for version 999.0.0 and runtime node/
  );
}

// 5. getTarget resolves Node.js ABI version string to target version
{
  assert.strictEqual(getTarget('115', 'node'), '20.0.0');
  assert.strictEqual(getTarget('127', 'node'), '22.0.0');
  assert.strictEqual(getTarget('108'), '18.0.0');
  assert.strictEqual(getNodeTarget('115'), '20.0.0');
  assert.strictEqual(getNodeTarget('127'), '22.0.0');
}

// 6. getTarget resolves Electron ABI version string to target version
{
  assert.strictEqual(getTarget('116', 'electron'), '25.0.0');
  assert.strictEqual(getTarget('119', 'electron'), '28.0.0');
  assert.strictEqual(getElectronTarget('116'), '25.0.0');
  assert.strictEqual(getElectronTarget('119'), '28.0.0');
}

// 7. getTarget returns non-numeric version string input directly
{
  assert.strictEqual(getTarget('20.0.0', 'node'), '20.0.0');
  assert.strictEqual(getTarget('25.0.0', 'electron'), '25.0.0');
  assert.strictEqual(getNodeTarget('20.0.0'), '20.0.0');
}

// 8. getTarget throws an Error for unknown ABI versions
{
  assert.throws(
    () => getTarget('99999', 'node'),
    /Could not detect target for abi 99999 and runtime node/
  );
  assert.throws(
    () => getTarget('99999', 'electron'),
    /Could not detect target for abi 99999 and runtime electron/
  );
  assert.throws(
    () => getNodeTarget('99999'),
    /Could not detect target for abi 99999 and runtime node/
  );
}

// 9. allTargets and supportedTargets export target registry entries with runtime, target, abi, and lts properties
{
  assert.ok(Array.isArray(allTargets) && allTargets.length > 0);
  assert.ok(Array.isArray(supportedTargets) && supportedTargets.length > 0);
  assert.ok(Array.isArray(deprecatedTargets) && deprecatedTargets.length > 0);
  assert.ok(Array.isArray(additionalTargets));
  assert.ok(Array.isArray(futureTargets));

  const targetNode20 = supportedTargets.find((t) => t.runtime === 'node' && t.abi === '115');
  assert.ok(targetNode20);
  assert.strictEqual(targetNode20.target, '20.0.0');
  assert.strictEqual(typeof targetNode20.lts, 'boolean');

  assert.strictEqual(isTargetSupported('20.0.0', 'node'), true);
  assert.strictEqual(isTargetSupported('v20.0.0', 'node'), true);
  assert.strictEqual(isTargetSupported('999.0.0', 'node'), false);

  const info = getTargetInfo('115', 'node');
  assert.ok(info);
  assert.strictEqual(info.target, '20.0.0');
  assert.strictEqual(info.abi, '115');
  assert.strictEqual(getTargetInfo('99999', 'node'), null);
}

console.log('Contract tests passed successfully.');

Ursprungs-Seeder

anonym