CodeSampleX

サンプル

pino-abstract-transport 3.0.0

検証済みサンプル — npm pino-abstract-transport 3.0.0. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: build returns a transform stream that parses JSON…

sha256:eb58fa0486b3785d387373f1cdc7a80770ae15fa597a283e2d84cae66cdffa7e

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify pkg:npm/pino-abstract-transport@3.0.0
パッケージ
環境
node 22.23.2
作成日
2026-09-18T14:33:48Z

コントラクト

  1. build returns a transform stream that parses JSON lines and delivers parsed log objects to an async iterator
  2. build tracks metadata on the transport stream updating lastLevel, lastTime, and lastObj by default
  3. build supports opts.metadata set to false to disable metadata properties on the transport stream
  4. build supports parse: 'lines' option to deliver raw line strings to the async iterator
  5. build supports custom parseLine option to transform line strings before processing
  6. build emits unknown event when unparseable content is written to the stream
  7. build emits unknown event when parsed value is null
  8. build invokes custom opts.close handler when the transport stream is destroyed or ended
  9. build supports enablePipelining returning a duplex stream for chained transformations
  10. build emits error when opts.expectPinoConfig is true without workerData pinoWillSendConfig

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

ソースアーティファクトをダウンロード (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/pino-abstract-transport@3.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pino-abstract-transport@3.0.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:bdc5322da493ad77af11c6d397357ee09ce6b639749db38979aa24271f83221f","contract":["build returns a transform stream that parses JSON lines and delivers parsed log objects to an async iterator","build tracks metadata on the transport stream updating lastLevel, lastTime, and lastObj by default","build supports opts.metadata set to false to disable metadata properties on the transport stream","build supports parse: 'lines' option to deliver raw line strings to the async iterator","build supports custom parseLine option to transform line strings before processing","build emits unknown event when unparseable content is written to the stream","build emits unknown event when parsed value is null","build invokes custom opts.close handler when the transport stream is destroyed or ended","build supports enablePipelining returning a duplex stream for chained transformations","build emits error when opts.expectPinoConfig is true without workerData pinoWillSendConfig"],"goal":"verify pkg:npm/pino-abstract-transport@3.0.0","kind":"HOW","packages":["pkg:npm/pino-abstract-transport@3.0.0"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/pino-abstract-transport@3.0.0"],"schemaVersion":1,"subject":"pkg:npm/pino-abstract-transport@3.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "pino-abstract-transport-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "pino-abstract-transport-verification",
      "version": "1.0.0",
      "dependencies": {
        "pino-abstract-transport": "3.0.0"
      }
    },
    "node_modules/pino-abstract-transport": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-3.0.0.tgz",
      "integrity": "sha512-wlfUczU+n7Hy/Ha5j9a/gZNy7We5+cXp8YL+X+PG8S0KXxw7n/JXA3c46Y0zQznIJ83URJiwy7Lh56WLokNuxg==",
      "license": "MIT",
      "dependencies": {
        "split2": "^4.0.0"
      }
    },
    "node_modules/split2": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
      "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
      "license": "ISC",
      "engines": {
        "node": ">= 10.x"
      }
    }
  }
}
package.json
{
  "name": "pino-abstract-transport-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for pino-abstract-transport",
  "dependencies": {
    "pino-abstract-transport": "3.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/pino-abstract-transport@3.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pino-abstract-transport@3.0.0"
  ]
}
test/contract.cjs
const assert = require('node:assert');
const { Transform } = require('node:stream');
const build = require('pino-abstract-transport');

async function testContract() {
  // 1. build returns a transform stream that parses JSON lines and delivers parsed log objects to an async iterator
  {
    const receivedLogs = [];
    const transport = build(async function (source) {
      for await (const obj of source) {
        receivedLogs.push(obj);
      }
    });

    transport.write(JSON.stringify({ level: 30, time: 1000, msg: 'log 1' }) + '\n');
    transport.write(JSON.stringify({ level: 40, time: 2000, msg: 'log 2' }) + '\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.strictEqual(receivedLogs.length, 2);
    assert.strictEqual(receivedLogs[0].msg, 'log 1');
    assert.strictEqual(receivedLogs[1].msg, 'log 2');
  }

  // 2. build tracks metadata on the transport stream updating lastLevel, lastTime, and lastObj by default
  {
    const transport = build(async function (source) {
      for await (const _ of source) {}
    });

    assert.strictEqual(transport.lastLevel, 0);
    assert.strictEqual(transport.lastTime, 0);
    assert.strictEqual(transport.lastObj, null);

    transport.write(JSON.stringify({ level: 50, time: 123456, msg: 'error occurred' }) + '\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.strictEqual(transport.lastLevel, 50);
    assert.strictEqual(transport.lastTime, 123456);
    assert.deepStrictEqual(transport.lastObj, { level: 50, time: 123456, msg: 'error occurred' });
  }

  // 3. build supports opts.metadata set to false to disable metadata properties on the transport stream
  {
    const receivedLogs = [];
    const transport = build(async function (source) {
      for await (const obj of source) {
        receivedLogs.push(obj);
      }
    }, { metadata: false });

    assert.strictEqual(transport.lastLevel, undefined);
    assert.strictEqual(transport.lastTime, undefined);
    assert.strictEqual(transport.lastObj, undefined);

    transport.write(JSON.stringify({ level: 20, time: 9999, msg: 'debug' }) + '\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.strictEqual(receivedLogs.length, 1);
  }

  // 4. build supports parse: 'lines' option to deliver raw line strings to the async iterator
  {
    const receivedLines = [];
    const transport = build(async function (source) {
      for await (const line of source) {
        receivedLines.push(line);
      }
    }, { parse: 'lines' });

    const rawLine = '{"custom":"json"}';
    transport.write(rawLine + '\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.strictEqual(receivedLines.length, 1);
    assert.strictEqual(receivedLines[0], rawLine);
  }

  // 5. build supports custom parseLine option to transform line strings before processing
  {
    const receivedLogs = [];
    const transport = build(async function (source) {
      for await (const obj of source) {
        receivedLogs.push(obj);
      }
    }, {
      parseLine: (str) => ({ customParsed: str.trim().toUpperCase() })
    });

    transport.write('sample line\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.strictEqual(receivedLogs.length, 1);
    assert.strictEqual(receivedLogs[0].customParsed, 'SAMPLE LINE');
  }

  // 6. build emits unknown event when unparseable content is written to the stream
  {
    let unknownEvent = null;
    const transport = build(async function (source) {
      for await (const _ of source) {}
    });

    transport.on('unknown', (line, err) => {
      unknownEvent = { line, hasErr: !!err };
    });

    transport.write('invalid json payload\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.ok(unknownEvent);
    assert.strictEqual(unknownEvent.line, 'invalid json payload');
    assert.strictEqual(unknownEvent.hasErr, true);
  }

  // 7. build emits unknown event when parsed value is null
  {
    let nullUnknown = null;
    const transport = build(async function (source) {
      for await (const _ of source) {}
    });

    transport.on('unknown', (line, reason) => {
      nullUnknown = { line, reason };
    });

    transport.write('null\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.ok(nullUnknown);
    assert.strictEqual(nullUnknown.line, 'null');
    assert.strictEqual(nullUnknown.reason, 'Null value ignored');
  }

  // 8. build invokes custom opts.close handler when the transport stream is destroyed or ended
  {
    let closedCalled = false;
    const transport = build(async function (source) {
      for await (const _ of source) {}
    }, {
      close(err, cb) {
        closedCalled = true;
        cb(err);
      }
    });

    transport.write(JSON.stringify({ msg: 'test' }) + '\n');
    transport.end();

    await new Promise((resolve) => transport.on('close', resolve));
    assert.strictEqual(closedCalled, true);
  }

  // 9. build supports enablePipelining returning a duplex stream for chained transformations
  {
    const transformStream = new Transform({
      objectMode: true,
      transform(chunk, enc, cb) {
        chunk.pipelined = true;
        cb(null, JSON.stringify(chunk) + '\n');
      }
    });

    const transport = build(function (source) {
      return source.pipe(transformStream);
    }, { enablePipelining: true });

    let collectedOutput = '';
    transport.on('data', (chunk) => {
      collectedOutput += chunk.toString();
    });

    transport.write(JSON.stringify({ msg: 'pipe' }) + '\n');
    transport.end();

    await new Promise((resolve) => transport.on('end', resolve));
    const parsed = JSON.parse(collectedOutput.trim());
    assert.strictEqual(parsed.msg, 'pipe');
    assert.strictEqual(parsed.pipelined, true);
  }

  // 10. build emits error when opts.expectPinoConfig is true without workerData pinoWillSendConfig
  {
    let caughtError = null;
    const transport = build(async function (source) {
      for await (const _ of source) {}
    }, { expectPinoConfig: true });

    await new Promise((resolve) => {
      transport.on('error', (err) => {
        caughtError = err;
        resolve();
      });
    });

    assert.ok(caughtError);
    assert.match(caughtError.message, /This transport is not compatible with the current version of pino/);
  }

  console.log('Contract passed');
}

testContract().catch((err) => {
  console.error(err);
  process.exit(1);
});

オリジンシーダー

匿名