Exemple
media-typer 0.3.0
Échantillon vérifié pour npm media-typer 0.3.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:7f27940dbda0abff5d5ff727693c058106c5f65e678dbd7bc8db58090d9d8946
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
windows 10 x64 npm vm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-20 |
Cas
HOW- Objectif
- verify pkg:npm/media-typer@0.3.0
- Paquets
- Créé
- 2026-08-20T00:36:54Z
Contrat
- mediaTyper.parse parses a media type string into type, subtype, suffix, and parameters
- mediaTyper.format formats a media type object into a media type string
- mediaTyper.parse and format throw TypeError for invalid media types
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- sample.mjs
- spec.json
- test/contract.mjs
Code source
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/media-typer@0.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/media-typer@0.3.0
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.
{"case":{"caseId":"case:sha256:87bab51dfd8371addd9f30cadb64b562db97d1efa4ac3039bb1b5361a24624af","contract":["mediaTyper.parse parses a media type string into type, subtype, suffix, and parameters","mediaTyper.format formats a media type object into a media type string","mediaTyper.parse and format throw TypeError for invalid media types"],"goal":"verify pkg:npm/media-typer@0.3.0","kind":"HOW","packages":["pkg:npm/media-typer@0.3.0"],"schemaVersion":1,"symbols":["media-typer.parse","media-typer.format"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"10","packageManager":"npm","schemaVersion":1,"virtualization":"vm"},"license":"MIT-0","packages":["pkg:npm/media-typer@0.3.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
{
"name": "sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample",
"version": "1.0.0",
"dependencies": {
"media-typer": "0.3.0"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
"engines": {
"node": ">= 0.6"
}
}
}
}
{
"name": "sample",
"version": "1.0.0",
"type": "module",
"dependencies": {
"media-typer": "0.3.0"
}
}
import typer from 'media-typer';
/**
* Parses a media type string into an object describing its components.
* @param {string} mediaType - Media type string (e.g., 'application/json; charset=utf-8')
* @returns {{ type: string, subtype: string, suffix?: string, parameters: Record<string, string> }}
*/
export function parseMediaType(mediaType) {
return typer.parse(mediaType);
}
/**
* Formats a media type object into a media type string.
* @param {{ type: string, subtype: string, suffix?: string, parameters?: Record<string, string> }} obj
* @returns {string}
*/
export function formatMediaType(obj) {
return typer.format(obj);
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/media-typer@0.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/media-typer@0.3.0"
]
}
import assert from 'node:assert/strict';
import typer from 'media-typer';
import { parseMediaType, formatMediaType } from '../sample.mjs';
function testParseMediaType() {
const parsed1 = parseMediaType('application/json');
assert.equal(parsed1.type, 'application');
assert.equal(parsed1.subtype, 'json');
assert.equal(parsed1.suffix, undefined);
assert.deepEqual(parsed1.parameters, {});
const parsed2 = parseMediaType('application/vnd.api+json; charset=utf-8');
assert.equal(parsed2.type, 'application');
assert.equal(parsed2.subtype, 'vnd.api');
assert.equal(parsed2.suffix, 'json');
assert.deepEqual(parsed2.parameters, { charset: 'utf-8' });
const parsed3 = typer.parse('image/svg+xml; q=0.8');
assert.equal(parsed3.type, 'image');
assert.equal(parsed3.subtype, 'svg');
assert.equal(parsed3.suffix, 'xml');
assert.deepEqual(parsed3.parameters, { q: '0.8' });
console.log('Contract 1 passed: parseMediaType parses media types correctly');
}
function testFormatMediaType() {
const formatted1 = formatMediaType({ type: 'text', subtype: 'html' });
assert.equal(formatted1, 'text/html');
const formatted2 = formatMediaType({ type: 'image', subtype: 'svg', suffix: 'xml' });
assert.equal(formatted2, 'image/svg+xml');
const formatted3 = typer.format({
type: 'application',
subtype: 'json',
parameters: { charset: 'utf-8', q: '1' }
});
assert.equal(formatted3, 'application/json; charset=utf-8; q=1');
console.log('Contract 2 passed: formatMediaType formats objects into media type strings');
}
function testInvalidInputs() {
assert.throws(() => {
parseMediaType('invalid type');
}, TypeError);
assert.throws(() => {
parseMediaType('');
}, TypeError);
assert.throws(() => {
formatMediaType({ type: 'invalid type', subtype: 'json' });
}, TypeError);
assert.throws(() => {
formatMediaType(null);
}, TypeError);
console.log('Contract 3 passed: validation errors thrown for invalid inputs');
}
function main() {
testParseMediaType();
testFormatMediaType();
testInvalidInputs();
console.log('All contracts passed successfully.');
}
main();
Seeder d'origine
anonyme