CodeSampleX

サンプル

fast-uri 3.1.4: resolveComponent

検証済みサンプル — npm fast-uri 3.1.4: resolveComponent. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: fast-uri.resolveComponent is exported as a…

sha256:9a11ad119fb73205937c168c617a22385dc0e010825b253783e6e7fb107c2b0c

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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-17

ケース

HOW
ゴール
verify fast-uri.resolveComponent in pkg:npm/fast-uri@3.1.4
パッケージ
シンボル
  • fast-uri.resolveComponent
作成日
2026-09-17T03:19:01Z

コントラクト

  1. fast-uri.resolveComponent is exported as a function
  2. fast-uri.resolveComponent resolves relative path against a base URI component
  3. fast-uri.resolveComponent replaces path when relative path is root-relative
  4. fast-uri.resolveComponent overrides target scheme and authority when relative is an absolute URI
  5. fast-uri.resolveComponent preserves base path when relative contains query or fragment only
  6. fast-uri.resolveComponent preserves dot segments when skipNormalization is true
  7. fast-uri.resolveComponent accepts raw URIComponent objects and helper wrappers work correctly

ファイル

  • PROMPT.md
  • csx.json
  • index.js
  • 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 fast-uri.resolveComponent in pkg:npm/fast-uri@3.1.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fast-uri@3.1.4
Demonstrate these symbols/APIs:
  - fast-uri.resolveComponent

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:b4917604fa3200c8bafbdebca3330fefe4e62ef37cef2fe616b4cff6866427ce","contract":["fast-uri.resolveComponent is exported as a function","fast-uri.resolveComponent resolves relative path against a base URI component","fast-uri.resolveComponent replaces path when relative path is root-relative","fast-uri.resolveComponent overrides target scheme and authority when relative is an absolute URI","fast-uri.resolveComponent preserves base path when relative contains query or fragment only","fast-uri.resolveComponent preserves dot segments when skipNormalization is true","fast-uri.resolveComponent accepts raw URIComponent objects and helper wrappers work correctly"],"goal":"verify fast-uri.resolveComponent in pkg:npm/fast-uri@3.1.4","kind":"HOW","packages":["pkg:npm/fast-uri@3.1.4"],"schemaVersion":1,"symbols":["fast-uri.resolveComponent"]},"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/fast-uri@3.1.4"],"schemaVersion":1,"subject":"pkg:npm/fast-uri@3.1.4","symbols":["fast-uri.resolveComponent"],"verifierAdapter":"node-typescript@1"}
index.js
const fastUri = require('fast-uri');

/**
 * Resolves a relative URI reference or component object against a base URI or component.
 *
 * @param {import('fast-uri').URIComponent|string} base - Base URI string or parsed URIComponent object.
 * @param {import('fast-uri').URIComponent|string} relative - Relative URI string or parsed URIComponent object.
 * @param {import('fast-uri').Options} [options] - Optional resolution settings.
 * @param {boolean} [skipNormalization] - Whether to skip preliminary component normalization.
 * @returns {import('fast-uri').URIComponent} Resolved URIComponent object.
 */
function resolveUriComponent(base, relative, options, skipNormalization) {
  const baseComponent = typeof base === 'string' ? fastUri.parse(base, options) : base;
  const relativeComponent = typeof relative === 'string' ? fastUri.parse(relative, options) : relative;
  return fastUri.resolveComponent(baseComponent, relativeComponent, options, skipNormalization);
}

/**
 * Resolves a relative URI reference against a base URI and returns the serialized URI string.
 *
 * @param {import('fast-uri').URIComponent|string} base - Base URI string or component.
 * @param {import('fast-uri').URIComponent|string} relative - Relative URI string or component.
 * @param {import('fast-uri').Options} [options] - Optional resolution settings.
 * @returns {string} Serialized resolved URI.
 */
function resolveAndSerialize(base, relative, options) {
  const resolved = resolveUriComponent(base, relative, options);
  return fastUri.serialize(resolved, options);
}

module.exports = {
  resolveUriComponent,
  resolveAndSerialize,
  fastUri
};
package-lock.json
{
  "name": "sample-fast-uri-resolve-component",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-fast-uri-resolve-component",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "fast-uri": "3.1.4"
      }
    },
    "node_modules/fast-uri": {
      "version": "3.1.4",
      "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.4.tgz",
      "integrity": "sha512-8JnbkQ4juDyvYs4mgFGQqg4yCYtFDtUtmp2QIQq11ZZe5CFQ5wcqm1rqDgAh/QdMySuBnPzMUiJUNZG5N/AiQw==",
      "license": "BSD-3-Clause"
    }
  }
}
package.json
{
  "name": "sample-fast-uri-resolve-component",
  "version": "1.0.0",
  "description": "Clean-room sample verifying fast-uri.resolveComponent in pkg:npm/fast-uri@3.1.4",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "fast-uri": "3.1.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify fast-uri.resolveComponent in pkg:npm/fast-uri@3.1.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fast-uri@3.1.4"
  ],
  "symbols": [
    "fast-uri.resolveComponent"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fastUri from 'fast-uri';
import { resolveUriComponent, resolveAndSerialize } from '../index.js';

// 1. fast-uri.resolveComponent is exported as a function
assert.equal(typeof fastUri.resolveComponent, 'function', 'fast-uri.resolveComponent is exported as a function');

// 2. fast-uri.resolveComponent resolves relative path against a base URI component
const base = fastUri.parse('http://example.com/a/b/c/d?q');
const relChild = fastUri.parse('g');
const resolvedChild = fastUri.resolveComponent(base, relChild);
assert.equal(resolvedChild.scheme, 'http');
assert.equal(resolvedChild.host, 'example.com');
assert.equal(resolvedChild.path, '/a/b/c/g');

// 3. fast-uri.resolveComponent replaces path when relative path is root-relative
const relRoot = fastUri.parse('/rooted/path');
const resolvedRoot = fastUri.resolveComponent(base, relRoot);
assert.equal(resolvedRoot.scheme, 'http');
assert.equal(resolvedRoot.host, 'example.com');
assert.equal(resolvedRoot.path, '/rooted/path');

// 4. fast-uri.resolveComponent overrides target scheme and authority when relative is an absolute URI
const relAbsolute = fastUri.parse('https://example.org/different');
const resolvedAbsolute = fastUri.resolveComponent(base, relAbsolute);
assert.equal(resolvedAbsolute.scheme, 'https');
assert.equal(resolvedAbsolute.host, 'example.org');
assert.equal(resolvedAbsolute.path, '/different');

// 5. fast-uri.resolveComponent preserves base path when relative contains query or fragment only
const relQueryFrag = fastUri.parse('?newquery#newfrag');
const resolvedQueryFrag = fastUri.resolveComponent(base, relQueryFrag);
assert.equal(resolvedQueryFrag.path, '/a/b/c/d');
assert.equal(resolvedQueryFrag.query, 'newquery');
assert.equal(resolvedQueryFrag.fragment, 'newfrag');

// 6. fast-uri.resolveComponent preserves dot segments when skipNormalization is true
const relParent = fastUri.parse('../g');
const resolvedWithSkip = fastUri.resolveComponent(base, relParent, {}, true);
assert.equal(resolvedWithSkip.path, '/a/b/g');

// 7. fast-uri.resolveComponent accepts raw URIComponent objects and helper wrappers work correctly
const rawBase = { scheme: 'http', host: 'example.com', path: '/dir/sub/' };
const rawRel = { path: 'file.html' };
const rawResolved = resolveUriComponent(rawBase, rawRel);
assert.equal(rawResolved.path, '/dir/sub/file.html');
assert.equal(resolveAndSerialize('http://example.com/dir/sub/', 'file.html'), 'http://example.com/dir/sub/file.html');

console.log('All fast-uri.resolveComponent contract assertions passed.');

オリジンシーダー

匿名