CodeSampleX

Пример

nanoid 3.3.17: async

Проверенный пример — npm nanoid 3.3.17: async. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: import nanoid, customAlphabet, and random…

sha256:ea72e7da28f81a217f6f599266c591696d47d740b837935410b739c8f88ac131

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify nanoid/async in pkg:npm/nanoid@3.3.17
Пакеты
Символы
  • nanoid/async
Окружение
node 22.23.2
Создан
2026-08-26T04:46:07Z

Контракт

  1. import nanoid, customAlphabet, and random from nanoid/async in ESM
  2. assert async nanoid resolves to 21 URL-safe characters
  3. assert async nanoid with custom size resolves to specified character count
  4. assert async customAlphabet returns generator that resolves to custom alphabet characters and length
  5. assert async random resolves to Uint8Array of requested byte size
  6. assert concurrently generated async nanoid IDs are unique

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 nanoid/async in pkg:npm/nanoid@3.3.17
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/nanoid@3.3.17
Demonstrate these symbols/APIs:
  - nanoid/async

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:325c92f4249ab162f353e2df67d3263bb2495807f0584af812c1fc606ab1db4d","contract":["import nanoid, customAlphabet, and random from nanoid/async in ESM","assert async nanoid resolves to 21 URL-safe characters","assert async nanoid with custom size resolves to specified character count","assert async customAlphabet returns generator that resolves to custom alphabet characters and length","assert async random resolves to Uint8Array of requested byte size","assert concurrently generated async nanoid IDs are unique"],"goal":"verify nanoid/async in pkg:npm/nanoid@3.3.17","kind":"HOW","packages":["pkg:npm/nanoid@3.3.17"],"schemaVersion":1,"symbols":["nanoid/async"]},"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/nanoid@3.3.17"],"schemaVersion":1,"subject":"pkg:npm/nanoid@3.3.17","symbols":["nanoid/async"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-nanoid-async",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-nanoid-async",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "nanoid": "3.3.17"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.17",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.17.tgz",
      "integrity": "sha512-xQLf0A3HOMlgHq0n247/LRuAOYmB7dXJ/DvAxGvsSBij45XtBSmQycu+F8ODbHwns/XyFZagyL1+J0Offw1E0g==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    }
  }
}
package.json
{
  "name": "csx-sample-nanoid-async",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "nanoid": "3.3.17"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify nanoid/async in pkg:npm/nanoid@3.3.17",
  "kind": "HOW",
  "packages": [
    "pkg:npm/nanoid@3.3.17"
  ],
  "symbols": [
    "nanoid/async"
  ]
}
src/index.js
import { nanoid, customAlphabet, random } from 'nanoid/async';

export async function generateAsyncId(size) {
  return size ? nanoid(size) : nanoid();
}

export function createAsyncCustomGenerator(alphabet, size) {
  return customAlphabet(alphabet, size);
}

export async function generateAsyncRandomBytes(bytes) {
  return random(bytes);
}

export { nanoid, customAlphabet, random };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  generateAsyncId,
  createAsyncCustomGenerator,
  generateAsyncRandomBytes,
  nanoid,
  customAlphabet,
  random
} from '../src/index.js';

// 1. ESM exports are functions
assert.equal(typeof nanoid, 'function', 'nanoid should be an async function');
assert.equal(typeof customAlphabet, 'function', 'customAlphabet should be a function returning an async generator');
assert.equal(typeof random, 'function', 'random should be an async function');

// 2. Default async nanoid produces 21 URL-safe characters
const defaultId = await generateAsyncId();
assert.equal(typeof defaultId, 'string', 'defaultId should be a string');
assert.equal(defaultId.length, 21, 'default nanoid should have length 21');
assert.match(defaultId, /^[A-Za-z0-9_-]{21}$/, 'default nanoid should only contain URL-safe chars');

// 3. Async nanoid with custom length produces specified character count
const customLengthId = await generateAsyncId(32);
assert.equal(customLengthId.length, 32, 'nanoid(32) should have length 32');
assert.match(customLengthId, /^[A-Za-z0-9_-]{32}$/, 'nanoid(32) should only contain URL-safe chars');

// 4. Custom alphabet generator produces IDs matching alphabet and size
const hexGenerator = createAsyncCustomGenerator('0123456789abcdef', 16);
const hexId = await hexGenerator();
assert.equal(hexId.length, 16, 'customAlphabet id should have length 16');
assert.match(hexId, /^[0-9a-f]{16}$/, 'customAlphabet id should only contain hex chars');

const customSizeHexId = await hexGenerator(8);
assert.equal(customSizeHexId.length, 8, 'customAlphabet id with override size should have length 8');
assert.match(customSizeHexId, /^[0-9a-f]{8}$/, 'customAlphabet id with override size should only contain hex chars');

// 5. Async random produces Uint8Array of requested byte size
const randomBytes = await generateAsyncRandomBytes(16);
assert.ok(randomBytes instanceof Uint8Array, 'random should resolve to a Uint8Array');
assert.equal(randomBytes.length, 16, 'random(16) should have length 16');

// 6. Concurrent generation produces unique IDs
const idPromises = Array.from({ length: 500 }, () => generateAsyncId());
const ids = await Promise.all(idPromises);
const uniqueIds = new Set(ids);
assert.equal(uniqueIds.size, 500, '500 concurrently generated nanoids should all be unique');

console.log('CONTRACT PASS: nanoid/async verified successfully');

Исходный сидер

аноним