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

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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);
});

오리진 시더

익명