CodeSampleX

Sample

yaml 2.9.0: Manage YAML nested collections and nodes with getIn, setIn, and deleteIn

Verified sample for npm yaml 2.9.0: Manage YAML nested collections and nodes with getIn, setIn, and deleteIn. The contract ran on node 22 · linux alpine/x64…

sha256:c566bb475ef702e2740e64fcaa2081cd8483f721990ba0aae601af7c899ce0e4

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node windows 11 x64 node javascript npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

Case

HOW
Goal
Manage YAML nested collections and nodes with getIn, setIn, and deleteIn
Packages
Symbols
  • Document
  • deleteIn
  • getIn
  • setIn
Environment
node
Created
2026-08-19T02:23:28Z

Contract

  1. Document getIn retrieves scalar values and nested AST collection nodes along a path
  2. Document setIn updates existing values and creates nested intermediate collection maps
  3. Document deleteIn removes keys or elements at nested paths and returns boolean status
  4. Document getIn and setIn support zero-indexed paths for sequence elements
  5. Document toString serializes AST modifications made via setIn and deleteIn while preserving comments

Files

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

Download the source artifact (tar.gz)

Source

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: Manage YAML nested collections and nodes with getIn, setIn, and deleteIn
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/yaml@2.9.0
Demonstrate these symbols/APIs:
  - Document
  - deleteIn
  - getIn
  - setIn
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:57bef6d696b68204675163aef685dce9a948825358dcf2b50606df055e55fe7f","constraints":{"executionContext":"node"},"contract":["Document getIn retrieves scalar values and nested AST collection nodes along a path","Document setIn updates existing values and creates nested intermediate collection maps","Document deleteIn removes keys or elements at nested paths and returns boolean status","Document getIn and setIn support zero-indexed paths for sequence elements","Document toString serializes AST modifications made via setIn and deleteIn while preserving comments"],"goal":"Manage YAML nested collections and nodes with getIn, setIn, and deleteIn","kind":"HOW","packages":["pkg:npm/yaml@2.9.0"],"schemaVersion":1,"symbols":["Document","deleteIn","getIn","setIn"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"windows","osVersionBucket":"11","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/yaml@2.9.0"],"schemaVersion":1,"symbols":["Document","deleteIn","getIn","setIn"],"verifierAdapter":"node-typescript@1"}
index.js
const { Document, parseDocument } = require('yaml');

function createDocument(value) {
  return new Document(value);
}

function parseYaml(yamlString) {
  return parseDocument(yamlString);
}

function getValueIn(doc, path, keepScalar = false) {
  return doc.getIn(path, keepScalar);
}

function setValueIn(doc, path, value) {
  doc.setIn(path, value);
  return doc;
}

function removeValueIn(doc, path) {
  return doc.deleteIn(path);
}

module.exports = {
  Document,
  parseDocument,
  createDocument,
  parseYaml,
  getValueIn,
  setValueIn,
  removeValueIn
};
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "yaml": "2.9.0"
      }
    },
    "node_modules/yaml": {
      "version": "2.9.0",
      "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz",
      "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==",
      "license": "ISC",
      "bin": {
        "yaml": "bin.mjs"
      },
      "engines": {
        "node": ">= 14.6"
      },
      "funding": {
        "url": "https://github.com/sponsors/eemeli"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "dependencies": {
    "yaml": "2.9.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Manage YAML nested collections and nodes with getIn, setIn, and deleteIn",
  "kind": "HOW",
  "packages": [
    "pkg:npm/yaml@2.9.0"
  ],
  "symbols": [
    "Document",
    "deleteIn",
    "getIn",
    "setIn"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.js
const assert = require('assert');
const {
  Document,
  parseDocument,
  createDocument,
  parseYaml,
  getValueIn,
  setValueIn,
  removeValueIn
} = require('../index.js');

// 1. Document getIn retrieves scalar values and nested AST collection nodes along a path
const yamlText1 = 'server:\n  host: 127.0.0.1\n  port: 8080\n';
const doc1 = parseYaml(yamlText1);
assert.strictEqual(doc1.getIn(['server', 'host']), '127.0.0.1');
assert.strictEqual(getValueIn(doc1, ['server', 'port']), 8080);
assert.strictEqual(doc1.getIn(['nonexistent', 'path']), undefined);

// 2. Document setIn updates existing values and creates nested intermediate collection maps
const doc2 = new Document({ title: 'Config' });
doc2.setIn(['database', 'primary', 'port'], 5432);
setValueIn(doc2, ['database', 'primary', 'user'], 'admin');
assert.strictEqual(doc2.getIn(['database', 'primary', 'port']), 5432);
assert.strictEqual(doc2.getIn(['database', 'primary', 'user']), 'admin');

// 3. Document deleteIn removes keys or elements at nested paths and returns boolean status
const yamlText3 = 'services:\n  auth:\n    enabled: true\n    timeout: 30\n';
const doc3 = parseDocument(yamlText3);
const deleted1 = removeValueIn(doc3, ['services', 'auth', 'timeout']);
assert.strictEqual(deleted1, true);
assert.strictEqual(doc3.getIn(['services', 'auth', 'timeout']), undefined);
assert.strictEqual(doc3.getIn(['services', 'auth', 'enabled']), true);
const deleted2 = doc3.deleteIn(['services', 'unknown']);
assert.strictEqual(deleted2, false);

// 4. Document getIn and setIn support zero-indexed paths for sequence elements
const yamlText4 = 'pipeline:\n  stages:\n    - build\n    - test\n    - deploy\n';
const doc4 = parseDocument(yamlText4);
assert.strictEqual(doc4.getIn(['pipeline', 'stages', 1]), 'test');
doc4.setIn(['pipeline', 'stages', 1], 'integration-test');
assert.strictEqual(doc4.getIn(['pipeline', 'stages', 1]), 'integration-test');

// 5. Document toString serializes AST modifications made via setIn and deleteIn while preserving comments
const yamlText5 = '# Application configuration\napp:\n  name: service-a # main name\n  debug: true\n';
const doc5 = parseDocument(yamlText5);
doc5.setIn(['app', 'debug'], false);
doc5.setIn(['app', 'version'], '1.0.0');
doc5.deleteIn(['app', 'name']);
const serialized = doc5.toString();
assert.ok(serialized.includes('# Application configuration'));
assert.ok(serialized.includes('debug: false'));
assert.ok(serialized.includes('version: 1.0.0'));
assert.ok(!serialized.includes('service-a'));

console.log('PASS: all contract assertions passed for Document, getIn, setIn, and deleteIn');

Origin Seeder

anonymous