CodeSampleX

Beispiel

flatted 3.4.4: parse

Verifiziertes Beispiel für npm flatted 3.4.4: parse. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: parse deserializes flatted string…

sha256:a395d98a098bcecee3a62cf5883b05df030eb6f1257ce4a14654a62330f202d5

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-27

Fall

HOW
Ziel
verify parse in pkg:npm/flatted@3.4.4
Pakete
Symbole
  • parse
Umgebung
node 22.23.2
Erstellt
2026-08-27T09:57:16Z

Contract

  1. parse deserializes flatted string with circular object reference into circular object graph
  2. parse deserializes flatted string with circular array reference into circular array
  3. parse restores shared object references preserving identity without duplication
  4. parse deserializes primitive values serialized with flatted
  5. parse deserializes nested objects and arrays correctly
  6. parse applies reviver function to transform parsed values
  7. parse throws SyntaxError when input contains invalid JSON syntax
  8. parse throws TypeError when input is not a flatted serialized array structure

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 parse in pkg:npm/flatted@3.4.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/flatted@3.4.4
Demonstrate these symbols/APIs:
  - parse

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:aa38f2a8a08d25f0bad6a701e3515e4e2efefb6c197d4aafc7f12ebc488303ed","contract":["parse deserializes flatted string with circular object reference into circular object graph","parse deserializes flatted string with circular array reference into circular array","parse restores shared object references preserving identity without duplication","parse deserializes primitive values serialized with flatted","parse deserializes nested objects and arrays correctly","parse applies reviver function to transform parsed values","parse throws SyntaxError when input contains invalid JSON syntax","parse throws TypeError when input is not a flatted serialized array structure"],"goal":"verify parse in pkg:npm/flatted@3.4.4","kind":"HOW","packages":["pkg:npm/flatted@3.4.4"],"schemaVersion":1,"symbols":["parse"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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.4"],"schemaVersion":1,"subject":"pkg:npm/flatted@3.4.4","symbols":["parse"],"verifierAdapter":"node-typescript@1"}
index.js
import { parse, stringify } from 'flatted';

export function parseFlatted(serialized, reviver) {
  return parse(serialized, reviver);
}

export function parseCircular(serialized) {
  return parse(serialized);
}

export function parseWithReviver(serialized, reviver) {
  return parse(serialized, reviver);
}

export { parse, stringify };
export default parse;
package-lock.json
{
  "name": "sample-flatted-parse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-flatted-parse",
      "version": "1.0.0",
      "dependencies": {
        "flatted": "3.4.4"
      }
    },
    "node_modules/flatted": {
      "version": "3.4.4",
      "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.4.tgz",
      "integrity": "sha512-5+ybhBZANEJxaH3X5evAFatUxLfEHSr7n6kYJ+1Qd0mUqr4eu9gIf6GDbWHf8RJijHrjjO8G+la14SlL2SeS1Q==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-flatted-parse",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "flatted": "3.4.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify parse in pkg:npm/flatted@3.4.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/flatted@3.4.4"
  ],
  "symbols": [
    "parse"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { stringify } from 'flatted';
import { parseFlatted, parseCircular, parseWithReviver } from '../index.js';

// 1. parse deserializes flatted string with circular object reference into circular object graph
{
  const circularObj = { name: 'root' };
  circularObj.self = circularObj;
  circularObj.child = { parent: circularObj };
  const serialized = stringify(circularObj);
  const parsed = parseCircular(serialized);
  assert.strictEqual(parsed.name, 'root', 'root name must match');
  assert.strictEqual(parsed.self, parsed, 'self reference must point to parsed root object');
  assert.strictEqual(parsed.child.parent, parsed, 'nested parent reference must point to parsed root object');
}

// 2. parse deserializes flatted string with circular array reference into circular array
{
  const circularArr = [10, 20];
  circularArr.push(circularArr);
  const serialized = stringify(circularArr);
  const parsed = parseFlatted(serialized);
  assert.strictEqual(parsed[0], 10, 'first element must match');
  assert.strictEqual(parsed[1], 20, 'second element must match');
  assert.strictEqual(parsed[2], parsed, 'third element must reference array itself');
}

// 3. parse restores shared object references preserving identity without duplication
{
  const shared = { id: 'shared-node', count: 100 };
  const container = { first: shared, second: shared };
  const serialized = stringify(container);
  const parsed = parseFlatted(serialized);
  assert.strictEqual(parsed.first, parsed.second, 'shared reference must maintain object identity');
  assert.strictEqual(parsed.first.id, 'shared-node', 'id property must match');
  parsed.first.count = 200;
  assert.strictEqual(parsed.second.count, 200, 'mutations via one reference must reflect on the other');
}

// 4. parse deserializes primitive values serialized with flatted
{
  assert.strictEqual(parseFlatted(stringify('hello world')), 'hello world');
  assert.strictEqual(parseFlatted(stringify(12345)), 12345);
  assert.strictEqual(parseFlatted(stringify(true)), true);
  assert.strictEqual(parseFlatted(stringify(null)), null);
}

// 5. parse deserializes nested objects and arrays correctly
{
  const nested = { a: [1, 2, { b: 'deep' }], flag: false };
  const serialized = stringify(nested);
  const parsed = parseFlatted(serialized);
  assert.deepStrictEqual(parsed, nested, 'parsed nested structure must match original');
}

// 6. parse applies reviver function to transform parsed values
{
  const data = { x: 10, y: 20, tag: 'keep' };
  const serialized = stringify(data);
  const parsed = parseWithReviver(serialized, (key, value) => {
    if (typeof value === 'number') {
      return value * 2;
    }
    return value;
  });
  assert.strictEqual(parsed.x, 20, 'reviver should double numeric value x');
  assert.strictEqual(parsed.y, 40, 'reviver should double numeric value y');
  assert.strictEqual(parsed.tag, 'keep', 'reviver should preserve tag');
}

// 7. parse throws SyntaxError when input contains invalid JSON syntax
{
  assert.throws(
    () => parseFlatted('invalid-json-syntax{'),
    SyntaxError,
    'parse must throw SyntaxError on malformed JSON string'
  );
}

// 8. parse throws TypeError when input is not a flatted serialized array structure
{
  assert.throws(
    () => parseFlatted('123'),
    TypeError,
    'parse must throw TypeError on non-flatted JSON primitive string'
  );
}

console.log('Contract verification finished successfully.');

Ursprungs-Seeder

anonym