CodeSampleX

サンプル

hono 4.6.0: Hono

検証済みサンプル — npm hono 4.6.0: Hono. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: Hono constructor initializes an instance that registers route…

sha256:5729673478850131e78d1a12716eb3bf9818a77447684cc0bf9f055aedd6d9b8

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify pkg:npm/hono@4.6.0
パッケージ
シンボル
  • Hono
作成日
2026-09-05T07:30:30Z

コントラクト

  1. Hono constructor initializes an instance that registers route handlers
  2. Hono router matches GET requests and extracts path and query parameters
  3. Hono router dispatches POST requests and parses incoming JSON payload
  4. Hono middleware executes in onion model modifying context variables and headers
  5. Hono mounts sub-applications using route method preserving nested path prefixes
  6. Hono handles custom error responses via onError and unmatched routes via notFound

ファイル

  • 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 pkg:npm/hono@4.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/hono@4.6.0
Demonstrate these symbols/APIs:
  - Hono

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:7b80e48eed58f07b50860beb78124e9a8f35bed2053139d3d84b5fb4c582b105","contract":["Hono constructor initializes an instance that registers route handlers","Hono router matches GET requests and extracts path and query parameters","Hono router dispatches POST requests and parses incoming JSON payload","Hono middleware executes in onion model modifying context variables and headers","Hono mounts sub-applications using route method preserving nested path prefixes","Hono handles custom error responses via onError and unmatched routes via notFound"],"goal":"verify pkg:npm/hono@4.6.0","kind":"HOW","packages":["pkg:npm/hono@4.6.0"],"schemaVersion":1,"symbols":["Hono"]},"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/hono@4.6.0"],"schemaVersion":1,"subject":"pkg:npm/hono@4.6.0","symbols":["Hono"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-hono-core",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hono-core",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "hono": "4.6.0"
      }
    },
    "node_modules/hono": {
      "version": "4.6.0",
      "resolved": "https://registry.npmjs.org/hono/-/hono-4.6.0.tgz",
      "integrity": "sha512-2jN7gHRCbfFXpHitg87ZDsComUB+PEm+rf2aDjy6e9SCwgnxkpQBCTKYumWQ4q4D3a+KuSW8VJAHzl4EnqYfeg==",
      "license": "MIT",
      "engines": {
        "node": ">=16.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-core",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for Hono in hono@4.6.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "hono": "4.6.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/hono@4.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/hono@4.6.0"
  ],
  "symbols": [
    "Hono"
  ]
}
src/index.js
'use strict';

const { Hono } = require('hono');

/**
 * Creates and configures a Hono web application demonstrating core features:
 * routing, URL parameters, query strings, JSON payloads, middleware,
 * sub-application mounting, onError and notFound handling.
 *
 * @returns {Hono} The configured Hono application.
 */
function createApp() {
  const app = new Hono();

  // Middleware modifying context and response headers
  app.use('*', async (c, next) => {
    c.set('customContextKey', 'context-value-123');
    await next();
    c.header('X-Custom-Middleware', 'hono-processed');
  });

  // GET route with JSON response, status code and custom header
  app.get('/api/hello', (c) => {
    return c.json(
      { message: 'Hello Hono', ctx: c.get('customContextKey') },
      200,
      { 'X-Hello-Response': 'true' }
    );
  });

  // Route with path parameter and query parameter
  app.get('/api/users/:id', (c) => {
    const id = c.req.param('id');
    const role = c.req.query('role');
    return c.json({ id, role });
  });

  // POST route parsing JSON body
  app.post('/api/items', async (c) => {
    const body = await c.req.json();
    return c.json({ success: true, item: body }, 201);
  });

  // Sub-application mounted via route()
  const subApp = new Hono();
  subApp.get('/status', (c) => c.json({ subStatus: 'operational' }));
  app.route('/api/sub', subApp);

  // Route that throws to test onError
  app.get('/api/error', () => {
    throw new Error('Test server exception');
  });

  // Custom error handler
  app.onError((err, c) => {
    return c.json(
      { error: err.message, handled: true },
      500
    );
  });

  // Custom not found handler
  app.notFound((c) => {
    return c.json(
      { error: 'Resource Not Found', pathname: c.req.path },
      404
    );
  });

  return app;
}

module.exports = {
  createApp,
  Hono
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { createApp, Hono } = require('../src/index.js');

async function testAll() {
  // Contract 1: Hono constructor initializes an instance that registers route handlers
  assert.equal(typeof Hono, 'function', 'Hono must be a constructor function');
  const app = createApp();
  assert.ok(app instanceof Hono, 'createApp must return a Hono instance');

  // Contract 2: Hono router matches GET requests and extracts path and query parameters
  const userRes = await app.fetch(new Request('http://localhost/api/users/user-456?role=editor'));
  assert.equal(userRes.status, 200, 'GET /api/users/:id must return 200');
  const userBody = await userRes.json();
  assert.deepEqual(userBody, { id: 'user-456', role: 'editor' });

  // Contract 3: Hono router dispatches POST requests and parses incoming JSON payload
  const payload = { title: 'Sample Item', count: 10 };
  const postRes = await app.fetch(
    new Request('http://localhost/api/items', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(payload)
    })
  );
  assert.equal(postRes.status, 201, 'POST /api/items must return 201');
  const postBody = await postRes.json();
  assert.deepEqual(postBody, { success: true, item: payload });

  // Contract 4: Hono middleware executes in onion model modifying context variables and headers
  const helloRes = await app.fetch(new Request('http://localhost/api/hello'));
  assert.equal(helloRes.status, 200, 'GET /api/hello must return 200');
  assert.equal(helloRes.headers.get('x-hello-response'), 'true');
  assert.equal(helloRes.headers.get('x-custom-middleware'), 'hono-processed');
  const helloBody = await helloRes.json();
  assert.equal(helloBody.message, 'Hello Hono');
  assert.equal(helloBody.ctx, 'context-value-123');

  // Contract 5: Hono mounts sub-applications using route method preserving nested path prefixes
  const subRes = await app.fetch(new Request('http://localhost/api/sub/status'));
  assert.equal(subRes.status, 200, 'GET /api/sub/status must return 200');
  const subBody = await subRes.json();
  assert.deepEqual(subBody, { subStatus: 'operational' });

  // Contract 6: Hono handles custom error responses via onError and unmatched routes via notFound
  const errorRes = await app.fetch(new Request('http://localhost/api/error'));
  assert.equal(errorRes.status, 500, 'Error route must return status 500');
  const errorBody = await errorRes.json();
  assert.deepEqual(errorBody, { error: 'Test server exception', handled: true });

  const notFoundRes = await app.fetch(new Request('http://localhost/api/unmatched-route'));
  assert.equal(notFoundRes.status, 404, 'Unmatched route must return status 404');
  const notFoundBody = await notFoundRes.json();
  assert.deepEqual(notFoundBody, { error: 'Resource Not Found', pathname: '/api/unmatched-route' });

  console.log('All contract assertions for Hono in pkg:npm/hono@4.6.0 passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

オリジンシーダー

匿名