CodeSampleX

サンプル

mime-db 1.54.0

検証済みサンプル — npm mime-db 1.54.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: mime-db contains standard MIME type entries with source…

sha256:09c1ef55abc26fb5d675288ee8ba2dc4fd875ded538d421dd0c3791a7f16cea5

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 windows 11 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
verify pkg:npm/mime-db@1.54.0
パッケージ
作成日
2026-08-18T18:10:20Z

コントラクト

  1. mime-db contains standard MIME type entries with source, extensions, charset, and compressible metadata
  2. db['application/json'] defines charset UTF-8, compressible true, and json extension
  3. db['text/html'] defines compressible true and html, htm extensions
  4. db['image/png'] defines non-compressible media type with png extension
  5. lookup retrieves MIME metadata for registered types and returns undefined for unknown types
  6. findTypeByExtension maps file extensions to corresponding media types
  7. isCompressible correctly identifies compressible text and data formats
  8. getExtensions retrieves all associated file extensions for a given MIME type

ファイル

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/mime-db@1.54.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/mime-db@1.54.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.
csx.json
{"case":{"caseId":"case:sha256:b3849d76cf31ccf2829ffb23ad948d8019d09175d758ce809ba865e0ef61a25f","contract":["mime-db contains standard MIME type entries with source, extensions, charset, and compressible metadata","db['application/json'] defines charset UTF-8, compressible true, and json extension","db['text/html'] defines compressible true and html, htm extensions","db['image/png'] defines non-compressible media type with png extension","lookup retrieves MIME metadata for registered types and returns undefined for unknown types","findTypeByExtension maps file extensions to corresponding media types","isCompressible correctly identifies compressible text and data formats","getExtensions retrieves all associated file extensions for a given MIME type"],"goal":"verify pkg:npm/mime-db@1.54.0","kind":"HOW","packages":["pkg:npm/mime-db@1.54.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/mime-db@1.54.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
index.mjs
import db from 'mime-db';

/**
 * Returns the MIME type entry for a given media type.
 * @param {string} type
 * @returns {object|undefined}
 */
export function lookup(type) {
  return db[type.toLowerCase()];
}

/**
 * Finds the first MIME type that has the given file extension.
 * @param {string} extension
 * @returns {string|undefined}
 */
export function findTypeByExtension(extension) {
  const ext = extension.toLowerCase().replace(/^\./, '');
  for (const [type, data] of Object.entries(db)) {
    if (data.extensions && data.extensions.includes(ext)) {
      return type;
    }
  }
  return undefined;
}

/**
 * Checks if a given MIME type is marked as compressible.
 * @param {string} type
 * @returns {boolean}
 */
export function isCompressible(type) {
  const entry = db[type.toLowerCase()];
  return Boolean(entry && entry.compressible);
}

/**
 * Returns the file extensions associated with a given MIME type.
 * @param {string} type
 * @returns {string[]}
 */
export function getExtensions(type) {
  const entry = db[type.toLowerCase()];
  return entry && entry.extensions ? [...entry.extensions] : [];
}

/**
 * Returns the default charset for a given MIME type.
 * @param {string} type
 * @returns {string|undefined}
 */
export function getCharset(type) {
  const entry = db[type.toLowerCase()];
  return entry ? entry.charset : undefined;
}

export { db };
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "mime-db": "1.54.0"
      }
    },
    "node_modules/mime-db": {
      "version": "1.54.0",
      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
      "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "mime-db": "1.54.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/mime-db@1.54.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/mime-db@1.54.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import db from 'mime-db';
import {
  lookup,
  findTypeByExtension,
  isCompressible,
  getExtensions,
  getCharset,
  db as exportedDb
} from '../index.mjs';

// Case 1: database contains standard MIME entries
{
  assert.equal(typeof db, 'object', 'mime-db export must be an object');
  assert(Object.keys(db).length > 1000, 'mime-db should contain thousands of MIME type entries');
  assert.equal(exportedDb, db, 'exported db must match imported db');
}

// Case 2: application/json entry validation
{
  const jsonEntry = db['application/json'];
  assert.ok(jsonEntry, 'application/json entry must exist');
  assert.equal(jsonEntry.source, 'iana', 'application/json source must be iana');
  assert.equal(jsonEntry.charset, 'UTF-8', 'application/json charset must be UTF-8');
  assert.equal(jsonEntry.compressible, true, 'application/json must be compressible');
  assert.ok(Array.isArray(jsonEntry.extensions), 'application/json extensions must be an array');
  assert(jsonEntry.extensions.includes('json'), 'application/json must include "json" extension');
}

// Case 3: text/html entry validation
{
  const htmlEntry = db['text/html'];
  assert.ok(htmlEntry, 'text/html entry must exist');
  assert.equal(htmlEntry.source, 'iana', 'text/html source must be iana');
  assert.equal(htmlEntry.compressible, true, 'text/html must be compressible');
  assert.ok(htmlEntry.extensions.includes('html'), 'text/html extensions must include "html"');
  assert.ok(htmlEntry.extensions.includes('htm'), 'text/html extensions must include "htm"');
}

// Case 4: image/png entry validation
{
  const pngEntry = db['image/png'];
  assert.ok(pngEntry, 'image/png entry must exist');
  assert.equal(pngEntry.compressible, false, 'image/png compressible must be false');
  assert.deepEqual(pngEntry.extensions, ['png'], 'image/png extensions must be ["png"]');
}

// Case 5: lookup wrapper function
{
  assert.deepEqual(lookup('application/json'), db['application/json'], 'lookup should find application/json');
  assert.deepEqual(lookup('TEXT/HTML'), db['text/html'], 'lookup should be case-insensitive');
  assert.equal(lookup('non-existent/fake-type'), undefined, 'lookup should return undefined for unknown types');
}

// Case 6: findTypeByExtension wrapper function
{
  assert.equal(findTypeByExtension('json'), 'application/json', 'extension "json" should map to application/json');
  assert.equal(findTypeByExtension('.html'), 'text/html', 'extension ".html" with leading dot should map to text/html');
  assert.equal(findTypeByExtension('PNG'), 'image/png', 'case-insensitive extension lookup should work');
  assert.equal(findTypeByExtension('nonexistentext12345'), undefined, 'unknown extension should return undefined');
}

// Case 7: isCompressible wrapper function
{
  assert.equal(isCompressible('text/html'), true, 'text/html must be compressible');
  assert.equal(isCompressible('application/json'), true, 'application/json must be compressible');
  assert.equal(isCompressible('image/png'), false, 'image/png must not be compressible');
  assert.equal(isCompressible('unknown/type'), false, 'unknown type should not be compressible');
}

// Case 8: getExtensions and getCharset wrapper functions
{
  const htmlExts = getExtensions('text/html');
  assert.ok(htmlExts.includes('html') && htmlExts.includes('htm'), 'getExtensions should return html extensions');
  assert.deepEqual(getExtensions('unknown/type'), [], 'getExtensions should return empty array for unknown types');

  assert.equal(getCharset('application/json'), 'UTF-8', 'getCharset should return UTF-8 for application/json');
  assert.equal(getCharset('unknown/type'), undefined, 'getCharset should return undefined for unknown types');
}

console.log('PASS: all mime-db contract assertions passed');

オリジンシーダー

匿名