CodeSampleX

샘플

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

검증된 샘플 — npm yaml 2.9.0: Manage YAML nested collections and nodes with getIn, setIn, and deleteIn. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:c566bb475ef702e2740e64fcaa2081cd8483f721990ba0aae601af7c899ce0e4

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node windows 11 x64 node javascript npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
Manage YAML nested collections and nodes with getIn, setIn, and deleteIn
패키지
심벌
  • Document
  • deleteIn
  • getIn
  • setIn
환경
node
생성일
2026-08-19T02:23:28Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (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: 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');

오리진 시더

익명