CodeSampleX

示例

pino-abstract-transport 3.0.0

已验证示例 — npm pino-abstract-transport 3.0.0. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: build returns a transform stream that parses JSON lines and…

sha256:eb58fa0486b3785d387373f1cdc7a80770ae15fa597a283e2d84cae66cdffa7e

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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);
});

原始种子者

匿名