CodeSampleX

Exemplo

flatted 3.4.3: toJSON

Amostra verificada para npm flatted 3.4.3: toJSON. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: flatted.toJSON converts primitive values…

sha256:409ab647c91f63e66d95a274377f536727b484865a868ae4e3c40bea0b0a202c

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-29

Caso

HOW
Objetivo
verify flatted.toJSON in pkg:npm/flatted@3.4.3
Pacotes
Símbolos
  • flatted.toJSON
Ambiente
node 22.23.2
Criado
2026-08-29T14:42:13Z

Contrato

  1. flatted.toJSON converts primitive values into array representation
  2. flatted.toJSON converts objects and arrays into indexed flat array representation
  3. flatted.toJSON converts self-referencing circular objects into flat array representation without recursion errors
  4. flatted.toJSON converts mutually circular objects into flat array representation
  5. flatted.toJSON preserves shared object references across multiple properties with single indexed instance
  6. flatted.toJSON output serialized with JSON.stringify matches flatted.stringify output
  7. flatted.fromJSON reconstructs original circular object graph from flatted.toJSON output
  8. flatted.toJSON handles nested arrays containing objects and circular references

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 flatted.toJSON in pkg:npm/flatted@3.4.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/flatted@3.4.3
Demonstrate these symbols/APIs:
  - flatted.toJSON

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:2a7ddb42c0228965c30b740dd47f567e7714306d51c6df4a7ec6296261b41f91","contract":["flatted.toJSON converts primitive values into array representation","flatted.toJSON converts objects and arrays into indexed flat array representation","flatted.toJSON converts self-referencing circular objects into flat array representation without recursion errors","flatted.toJSON converts mutually circular objects into flat array representation","flatted.toJSON preserves shared object references across multiple properties with single indexed instance","flatted.toJSON output serialized with JSON.stringify matches flatted.stringify output","flatted.fromJSON reconstructs original circular object graph from flatted.toJSON output","flatted.toJSON handles nested arrays containing objects and circular references"],"goal":"verify flatted.toJSON in pkg:npm/flatted@3.4.3","kind":"HOW","packages":["pkg:npm/flatted@3.4.3"],"schemaVersion":1,"symbols":["flatted.toJSON"]},"contractCommand":["node","test/contract.mjs"],"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/flatted@3.4.3"],"schemaVersion":1,"subject":"pkg:npm/flatted@3.4.3","symbols":["flatted.toJSON"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-3979932717",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-3979932717",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "flatted": "3.4.3"
      }
    },
    "node_modules/flatted": {
      "version": "3.4.3",
      "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.3.tgz",
      "integrity": "sha512-/zipXxyO6rGvuNGDiULY9MvEGSkb2gaG4GGH4ygMi0ZZzyMHdUZBmntJmx5x1G2VuPytCwGN4xsJP6cw+sK+vQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-3979932717",
  "version": "1.0.0",
  "description": "verify flatted.toJSON in pkg:npm/flatted@3.4.3",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "license": "MIT-0",
  "dependencies": {
    "flatted": "3.4.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify flatted.toJSON in pkg:npm/flatted@3.4.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/flatted@3.4.3"
  ],
  "symbols": [
    "flatted.toJSON"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { toJSON, fromJSON, stringify } from 'flatted';

// 1. flatted.toJSON converts primitive values into array representation
{
  assert.deepEqual(toJSON(42), [42]);
  assert.deepEqual(toJSON('hello'), ['hello']);
  assert.deepEqual(toJSON(true), [true]);
  assert.deepEqual(toJSON(null), [null]);
}

// 2. flatted.toJSON converts objects and arrays into indexed flat array representation
{
  const obj = { a: 1, b: 'two' };
  const arr = toJSON(obj);
  assert.ok(Array.isArray(arr));
  assert.equal(arr[0].a, 1);
  assert.equal(arr[0].b, '1');
  assert.equal(arr[1], 'two');

  const list = [10, 20, 30];
  const listArr = toJSON(list);
  assert.ok(Array.isArray(listArr));
  assert.deepEqual(listArr[0], [10, 20, 30]);
}

// 3. flatted.toJSON converts self-referencing circular objects into flat array representation without recursion errors
{
  const circular = { id: 1 };
  circular.self = circular;
  const jsonArr = toJSON(circular);
  assert.ok(Array.isArray(jsonArr));
  assert.equal(jsonArr[0].id, 1);
  assert.equal(jsonArr[0].self, '0');
}

// 4. flatted.toJSON converts mutually circular objects into flat array representation
{
  const a = { id: 1 };
  const b = { id: 2 };
  a.peer = b;
  b.peer = a;
  const jsonArr = toJSON(a);
  assert.ok(Array.isArray(jsonArr));
  assert.equal(jsonArr.length, 2);
  assert.equal(jsonArr[0].id, 1);
  assert.equal(jsonArr[0].peer, '1');
  assert.equal(jsonArr[1].id, 2);
  assert.equal(jsonArr[1].peer, '0');
}

// 5. flatted.toJSON preserves shared object references across multiple properties with single indexed instance
{
  const shared = { value: 100 };
  const container = { first: shared, second: shared };
  const jsonArr = toJSON(container);
  assert.ok(Array.isArray(jsonArr));
  assert.equal(jsonArr[0].first, '1');
  assert.equal(jsonArr[0].second, '1');
  assert.equal(jsonArr[1].value, 100);
}

// 6. flatted.toJSON output serialized with JSON.stringify matches flatted.stringify output
{
  const complex = { num: 1, str: 'test', list: [1, 2] };
  complex.self = complex;
  const viaToJSON = JSON.stringify(toJSON(complex));
  const viaStringify = stringify(complex);
  assert.equal(viaToJSON, viaStringify);
}

// 7. flatted.fromJSON reconstructs original circular object graph from flatted.toJSON output
{
  const original = { id: 42, meta: 'data' };
  original.cycle = original;
  const jsonArr = toJSON(original);
  const reconstructed = fromJSON(jsonArr);
  assert.equal(reconstructed.id, 42);
  assert.equal(reconstructed.meta, 'data');
  assert.equal(reconstructed.cycle, reconstructed);
}

// 8. flatted.toJSON handles nested arrays containing objects and circular references
{
  const item = { val: 1 };
  const arr = [item, [item]];
  item.parent = arr;
  const jsonArr = toJSON(arr);
  assert.ok(Array.isArray(jsonArr));
  const restored = fromJSON(jsonArr);
  assert.equal(restored[0].val, 1);
  assert.equal(restored[1][0], restored[0]);
  assert.equal(restored[0].parent, restored);
}

console.log('Contract passed');

Seeder de origem

anônimo