CodeSampleX

Ejemplo

@sinclair/typebox 0.27.12: Value.Check

Muestra verificada para npm @sinclair/typebox 0.27.12: Value.Check. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:b1dded2400f09b0b4630ec0d4c358ea76da6602cb60029b7576e1804147629b9

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-09-02

Caso

HOW
Objetivo
verify Value.Check in pkg:npm/%40sinclair/typebox@0.27.12
Paquetes
Símbolos
  • Value.Check
Creado
2026-09-02T14:30:39Z

Contrato

  1. Value.Check returns true for primitive values matching the schema and false for type mismatches
  2. Value.Check validates numeric constraints including minimum and maximum bounds
  3. Value.Check validates string constraints including minLength, maxLength, and regex patterns
  4. Value.Check returns true for object values having all required conforming properties
  5. Value.Check returns false for objects missing required properties or containing invalid property types
  6. Value.Check validates array elements and rejects non-array values or invalid elements
  7. Value.Check validates union types accepting values matching any branch and rejecting non-matching values
  8. Value.Check supports optional object properties permitting both omission and valid types
  9. Value.Check validates tuple types respecting fixed length and element-specific schemas

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 Value.Check in pkg:npm/%40sinclair/typebox@0.27.12
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40sinclair/typebox@0.27.12
Demonstrate these symbols/APIs:
  - Value.Check

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:29751d89ff307f4cbf0b935d34d24ce39edac44155f0a6aff9e2d18d4fde71bb","contract":["Value.Check returns true for primitive values matching the schema and false for type mismatches","Value.Check validates numeric constraints including minimum and maximum bounds","Value.Check validates string constraints including minLength, maxLength, and regex patterns","Value.Check returns true for object values having all required conforming properties","Value.Check returns false for objects missing required properties or containing invalid property types","Value.Check validates array elements and rejects non-array values or invalid elements","Value.Check validates union types accepting values matching any branch and rejecting non-matching values","Value.Check supports optional object properties permitting both omission and valid types","Value.Check validates tuple types respecting fixed length and element-specific schemas"],"goal":"verify Value.Check in pkg:npm/%40sinclair/typebox@0.27.12","kind":"HOW","packages":["pkg:npm/%40sinclair/typebox@0.27.12"],"schemaVersion":1,"symbols":["Value.Check"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40sinclair/typebox@0.27.12"],"schemaVersion":1,"subject":"pkg:npm/%40sinclair/typebox@0.27.12","symbols":["Value.Check"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { Type } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';

/**
 * Validates a value against a TypeBox schema.
 *
 * @param {import('@sinclair/typebox').TSchema} schema - TypeBox schema
 * @param {unknown} value - Value to validate
 * @returns {boolean} True if the value satisfies the schema, false otherwise
 */
export function checkValue(schema, value) {
  return Value.Check(schema, value);
}

/**
 * Asserts that a value conforms to a TypeBox schema, throwing if invalid.
 *
 * @param {import('@sinclair/typebox').TSchema} schema - TypeBox schema
 * @param {unknown} value - Value to validate
 * @returns {boolean} True if valid
 * @throws {Error} When value does not conform to the schema
 */
export function assertValue(schema, value) {
  if (!Value.Check(schema, value)) {
    throw new Error('Value does not conform to schema');
  }
  return true;
}

export { Type, Value };
export default {
  checkValue,
  assertValue,
  Type,
  Value,
};
package-lock.json
{
  "name": "sample-typebox-value-check",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-typebox-value-check",
      "version": "1.0.0",
      "dependencies": {
        "@sinclair/typebox": "0.27.12"
      }
    },
    "node_modules/@sinclair/typebox": {
      "version": "0.27.12",
      "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.12.tgz",
      "integrity": "sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-typebox-value-check",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "@sinclair/typebox": "0.27.12"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Value.Check in pkg:npm/%40sinclair/typebox@0.27.12",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40sinclair/typebox@0.27.12"
  ],
  "symbols": [
    "Value.Check"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { Type, Value, checkValue, assertValue } from '../index.mjs';

// Contract 1: Value.Check returns true for primitive values matching the schema and false for type mismatches
{
  const strSchema = Type.String();
  assert.strictEqual(Value.Check(strSchema, 'hello'), true);
  assert.strictEqual(Value.Check(strSchema, ''), true);
  assert.strictEqual(Value.Check(strSchema, 123), false);
  assert.strictEqual(Value.Check(strSchema, null), false);
  assert.strictEqual(Value.Check(strSchema, undefined), false);

  const numSchema = Type.Number();
  assert.strictEqual(Value.Check(numSchema, 42), true);
  assert.strictEqual(Value.Check(numSchema, 3.14), true);
  assert.strictEqual(Value.Check(numSchema, '42'), false);
  assert.strictEqual(Value.Check(numSchema, NaN), false);

  const boolSchema = Type.Boolean();
  assert.strictEqual(Value.Check(boolSchema, true), true);
  assert.strictEqual(Value.Check(boolSchema, false), true);
  assert.strictEqual(Value.Check(boolSchema, 'true'), false);

  assert.strictEqual(checkValue(strSchema, 'test'), true);
  assert.strictEqual(checkValue(strSchema, 42), false);
}

// Contract 2: Value.Check validates numeric constraints including minimum and maximum bounds
{
  const portSchema = Type.Number({ minimum: 1024, maximum: 65535 });
  assert.strictEqual(Value.Check(portSchema, 1024), true);
  assert.strictEqual(Value.Check(portSchema, 8080), true);
  assert.strictEqual(Value.Check(portSchema, 65535), true);
  assert.strictEqual(Value.Check(portSchema, 1023), false);
  assert.strictEqual(Value.Check(portSchema, 65536), false);
}

// Contract 3: Value.Check validates string constraints including minLength, maxLength, and regex patterns
{
  const codeSchema = Type.String({ minLength: 3, maxLength: 6, pattern: '^[A-Z]+$' });
  assert.strictEqual(Value.Check(codeSchema, 'ABC'), true);
  assert.strictEqual(Value.Check(codeSchema, 'ABCDEF'), true);
  assert.strictEqual(Value.Check(codeSchema, 'AB'), false);
  assert.strictEqual(Value.Check(codeSchema, 'ABCDEFG'), false);
  assert.strictEqual(Value.Check(codeSchema, 'abc'), false);
}

// Contract 4: Value.Check returns true for object values having all required conforming properties
{
  const userSchema = Type.Object({
    id: Type.Number(),
    name: Type.String(),
    active: Type.Boolean(),
  });

  const validUser = { id: 1, name: 'Alice', active: true };
  assert.strictEqual(Value.Check(userSchema, validUser), true);
  assert.strictEqual(assertValue(userSchema, validUser), true);
}

// Contract 5: Value.Check returns false for objects missing required properties or containing invalid property types
{
  const userSchema = Type.Object({
    id: Type.Number(),
    name: Type.String(),
  });

  assert.strictEqual(Value.Check(userSchema, { id: 1 }), false);
  assert.strictEqual(Value.Check(userSchema, { name: 'Bob' }), false);
  assert.strictEqual(Value.Check(userSchema, { id: 'one', name: 'Bob' }), false);
  assert.strictEqual(Value.Check(userSchema, null), false);
  assert.strictEqual(Value.Check(userSchema, 'not-an-object'), false);

  assert.throws(() => assertValue(userSchema, { id: 'invalid' }), /Value does not conform to schema/);
}

// Contract 6: Value.Check validates array elements and rejects non-array values or invalid elements
{
  const tagsSchema = Type.Array(Type.String());
  assert.strictEqual(Value.Check(tagsSchema, ['a', 'b', 'c']), true);
  assert.strictEqual(Value.Check(tagsSchema, []), true);
  assert.strictEqual(Value.Check(tagsSchema, ['a', 123]), false);
  assert.strictEqual(Value.Check(tagsSchema, 'not-an-array'), false);
  assert.strictEqual(Value.Check(tagsSchema, null), false);
}

// Contract 7: Value.Check validates union types accepting values matching any branch and rejecting non-matching values
{
  const statusSchema = Type.Union([
    Type.Literal('pending'),
    Type.Literal('active'),
    Type.Literal('completed'),
  ]);

  assert.strictEqual(Value.Check(statusSchema, 'pending'), true);
  assert.strictEqual(Value.Check(statusSchema, 'active'), true);
  assert.strictEqual(Value.Check(statusSchema, 'completed'), true);
  assert.strictEqual(Value.Check(statusSchema, 'archived'), false);
  assert.strictEqual(Value.Check(statusSchema, 123), false);
}

// Contract 8: Value.Check supports optional object properties permitting both omission and valid types
{
  const profileSchema = Type.Object({
    username: Type.String(),
    bio: Type.Optional(Type.String()),
    age: Type.Optional(Type.Number()),
  });

  assert.strictEqual(Value.Check(profileSchema, { username: 'john' }), true);
  assert.strictEqual(Value.Check(profileSchema, { username: 'john', bio: 'Developer' }), true);
  assert.strictEqual(Value.Check(profileSchema, { username: 'john', bio: 'Developer', age: 30 }), true);
  assert.strictEqual(Value.Check(profileSchema, { username: 'john', bio: 123 }), false);
}

// Contract 9: Value.Check validates tuple types respecting fixed length and element-specific schemas
{
  const coordinateSchema = Type.Tuple([Type.Number(), Type.Number()]);

  assert.strictEqual(Value.Check(coordinateSchema, [10, 20]), true);
  assert.strictEqual(Value.Check(coordinateSchema, [10]), false);
  assert.strictEqual(Value.Check(coordinateSchema, [10, 20, 30]), false);
  assert.strictEqual(Value.Check(coordinateSchema, ['10', 20]), false);
}

console.log('All Value.Check contracts passed.');

Seeder de origen

anónimo