Exemplo
mime-db 1.52.0: lookup MIME type metadata and extensions in mime-db
Amostra verificada para npm mime-db 1.52.0: lookup MIME type metadata and extensions in mime-db. O contrato rodou em node 22 · linux alpine/x64 · docker e…
sha256:6c1dfc987b0995d378c70092b5b3e3b468e22be8dfefe5dfd8a7f8cb73366be6
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22 linux x64 node 22 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-19 |
Caso
HOW- Objetivo
- lookup MIME type metadata and extensions in mime-db
- Pacotes
- Símbolos
-
- mime-db
- Ambiente
- node 22
- Criado
- 2026-08-18T18:07:59Z
Contrato
- db is an object mapping MIME type strings to metadata entries
- getType performs case-insensitive lookup and returns metadata entry with source, extensions, and charset
- getExtensions returns array of associated file extensions or empty array
- getDefaultExtension returns primary file extension without leading dot
- isCompressible returns boolean compressibility status of the media type
- findTypeByExtension looks up media type corresponding to a file extension
- getSource returns database origin source such as iana or apache
- getCharset returns defined charset encoding or undefined
Arquivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Código-fonte
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: lookup MIME type metadata and extensions in mime-db
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/mime-db@1.52.0
Demonstrate these symbols/APIs:
- mime-db
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@11.8.0
- runtime: node@24.13.1
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:12d74e8c2f394fabd1db4b5c503120475dd8d1c7c9d7602d55ed428b9dea38a5","constraints":{"executionContext":"node"},"contract":["db is an object mapping MIME type strings to metadata entries","getType performs case-insensitive lookup and returns metadata entry with source, extensions, and charset","getExtensions returns array of associated file extensions or empty array","getDefaultExtension returns primary file extension without leading dot","isCompressible returns boolean compressibility status of the media type","findTypeByExtension looks up media type corresponding to a file extension","getSource returns database origin source such as iana or apache","getCharset returns defined charset encoding or undefined"],"goal":"lookup MIME type metadata and extensions in mime-db","kind":"HOW","packages":["pkg:npm/mime-db@1.52.0"],"schemaVersion":1,"symbols":["mime-db"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"linux","packageManager":"npm","packageManagerVersion":"10","runtime":"node","runtimeVersion":"22","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/mime-db@1.52.0"],"schemaVersion":1,"symbols":["mime-db"],"verifierAdapter":"node-typescript@1"}
'use strict';
var db = require('mime-db');
/**
* Get the metadata entry for a MIME type (case-insensitive).
* @param {string} type - MIME type string (e.g., 'application/json')
* @returns {object|undefined}
*/
function getType(type) {
if (typeof type !== 'string') {
return undefined;
}
return db[type.toLowerCase().trim()];
}
/**
* Get all extensions associated with a MIME type.
* @param {string} type - MIME type string
* @returns {string[]}
*/
function getExtensions(type) {
var entry = getType(type);
return (entry && Array.isArray(entry.extensions)) ? entry.extensions.slice() : [];
}
/**
* Get the primary default extension for a MIME type.
* @param {string} type - MIME type string
* @returns {string|undefined}
*/
function getDefaultExtension(type) {
var extensions = getExtensions(type);
return extensions.length > 0 ? extensions[0] : undefined;
}
/**
* Check whether a MIME type is marked as compressible.
* @param {string} type - MIME type string
* @returns {boolean}
*/
function isCompressible(type) {
var entry = getType(type);
return Boolean(entry && entry.compressible === true);
}
/**
* Find a MIME type by file extension (without leading dot).
* @param {string} ext - File extension (e.g., 'json', 'png')
* @returns {string|undefined}
*/
function findTypeByExtension(ext) {
if (typeof ext !== 'string') {
return undefined;
}
var cleanExt = ext.replace(/^\./, '').toLowerCase().trim();
for (var mimeType in db) {
if (Object.prototype.hasOwnProperty.call(db, mimeType)) {
var entry = db[mimeType];
if (entry && Array.isArray(entry.extensions) && entry.extensions.indexOf(cleanExt) !== -1) {
return mimeType;
}
}
}
return undefined;
}
/**
* Get the source of a MIME type definition (e.g., 'iana', 'apache', 'nginx').
* @param {string} type - MIME type string
* @returns {string|undefined}
*/
function getSource(type) {
var entry = getType(type);
return entry ? entry.source : undefined;
}
/**
* Get the charset of a MIME type if specified.
* @param {string} type - MIME type string
* @returns {string|undefined}
*/
function getCharset(type) {
var entry = getType(type);
return entry ? entry.charset : undefined;
}
module.exports = {
db: db,
getType: getType,
getExtensions: getExtensions,
getDefaultExtension: getDefaultExtension,
isCompressible: isCompressible,
findTypeByExtension: findTypeByExtension,
getSource: getSource,
getCharset: getCharset
};
{
"name": "sample-mime-db",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-mime-db",
"version": "1.0.0",
"dependencies": {
"mime-db": "1.52.0"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
}
}
}
{
"name": "sample-mime-db",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of mime-db MIME type lookup and metadata query",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"mime-db": "1.52.0"
}
}
{
"schemaVersion": 1,
"goal": "lookup MIME type metadata and extensions in mime-db",
"kind": "HOW",
"packages": [
"pkg:npm/mime-db@1.52.0"
],
"symbols": [
"mime-db"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
'use strict';
var assert = require('assert');
var sample = require('../index.js');
// 1. Raw database sanity check
assert.strictEqual(typeof sample.db, 'object');
assert.ok(sample.db !== null);
assert.ok(Object.keys(sample.db).length > 1000);
// 2. application/json entry check
var jsonEntry = sample.getType('application/json');
assert.ok(jsonEntry, 'application/json should exist in mime-db');
assert.strictEqual(jsonEntry.source, 'iana');
assert.strictEqual(jsonEntry.charset, 'UTF-8');
assert.strictEqual(jsonEntry.compressible, true);
assert.deepStrictEqual(jsonEntry.extensions, ['json', 'map']);
// 3. text/html entry check
var htmlEntry = sample.getType('text/html');
assert.ok(htmlEntry, 'text/html should exist in mime-db');
assert.strictEqual(htmlEntry.source, 'iana');
assert.strictEqual(htmlEntry.compressible, true);
assert.ok(Array.isArray(htmlEntry.extensions));
assert.ok(htmlEntry.extensions.indexOf('html') !== -1);
assert.ok(htmlEntry.extensions.indexOf('htm') !== -1);
// 4. image/png entry check
var pngEntry = sample.getType('image/png');
assert.ok(pngEntry, 'image/png should exist in mime-db');
assert.strictEqual(pngEntry.source, 'iana');
assert.strictEqual(pngEntry.compressible, false);
assert.deepStrictEqual(pngEntry.extensions, ['png']);
// 5. Non-existent MIME type
assert.strictEqual(sample.getType('application/x-non-existent-fake-type'), undefined);
assert.strictEqual(sample.getType(null), undefined);
assert.strictEqual(sample.getType(123), undefined);
// 6. Case-insensitivity in getType
assert.deepStrictEqual(sample.getType('Application/JSON'), jsonEntry);
assert.deepStrictEqual(sample.getType('TEXT/HTML '), htmlEntry);
// 7. getExtensions
assert.deepStrictEqual(sample.getExtensions('application/json'), ['json', 'map']);
assert.deepStrictEqual(sample.getExtensions('image/png'), ['png']);
assert.deepStrictEqual(sample.getExtensions('non/existent'), []);
// 8. getDefaultExtension
assert.strictEqual(sample.getDefaultExtension('application/json'), 'json');
assert.strictEqual(sample.getDefaultExtension('image/png'), 'png');
assert.strictEqual(sample.getDefaultExtension('text/html'), 'html');
assert.strictEqual(sample.getDefaultExtension('non/existent'), undefined);
// 9. isCompressible
assert.strictEqual(sample.isCompressible('application/json'), true);
assert.strictEqual(sample.isCompressible('text/html'), true);
assert.strictEqual(sample.isCompressible('image/png'), false);
assert.strictEqual(sample.isCompressible('application/pdf'), false);
assert.strictEqual(sample.isCompressible('image/svg+xml'), true);
assert.strictEqual(sample.isCompressible('non/existent'), false);
// 10. findTypeByExtension
assert.strictEqual(sample.findTypeByExtension('json'), 'application/json');
assert.strictEqual(sample.findTypeByExtension('.json'), 'application/json');
assert.strictEqual(sample.findTypeByExtension('png'), 'image/png');
assert.strictEqual(sample.findTypeByExtension('svg'), 'image/svg+xml');
assert.strictEqual(sample.findTypeByExtension('unknownext123'), undefined);
assert.strictEqual(sample.findTypeByExtension(null), undefined);
// 11. getSource
assert.strictEqual(sample.getSource('application/json'), 'iana');
assert.strictEqual(sample.getSource('text/html'), 'iana');
assert.strictEqual(sample.getSource('non/existent'), undefined);
// 12. getCharset
assert.strictEqual(sample.getCharset('application/json'), 'UTF-8');
assert.strictEqual(sample.getCharset('image/png'), undefined);
assert.strictEqual(sample.getCharset('non/existent'), undefined);
console.log('PASS: mime-db contract verified');
Seeder de origem
anônimo