@effected/yaml 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/YamlFormat.js CHANGED
@@ -238,8 +238,56 @@ function formatStream(text, documents, streamErrors, options) {
238
238
  }
239
239
  return parts.join("");
240
240
  }
241
- /** Convert a plain JS scalar value into a synthetic `YamlScalar` (offset/length are irrelevant — immediately re-stringified). */
242
- function jsValueToNode(value) {
241
+ /**
242
+ * Lower a plain JavaScript value into synthetic AST nodes (offset/length are
243
+ * irrelevant — the result is immediately re-stringified).
244
+ *
245
+ * Recursive by design: an array becomes a block {@link YamlSeq} and any other
246
+ * non-null object a block {@link YamlMap} over its own enumerable string keys,
247
+ * matching what `Yaml.stringify` does with the same value on the value path.
248
+ * Before this was recursive, a mapping or sequence value fell through to the
249
+ * node stringifier's `String(value)` fallback and landed in the document as
250
+ * the literal text `[object Object]` — a silent corruption that only surfaced
251
+ * on the next read (#642).
252
+ *
253
+ * The two conditions with no finite rendering fail typed rather than hanging
254
+ * or overflowing the stack: a cycle raises `CircularReference` and a graph
255
+ * deeper than `MAX_NESTING_DEPTH` raises `NestingDepthExceeded`. `seen` holds
256
+ * the ancestors of the value being lowered, so a value repeated across
257
+ * siblings (a shared, acyclic sub-object) is lowered twice rather than
258
+ * rejected.
259
+ */
260
+ function jsValueToNode(value, seen, depth) {
261
+ if (depth > 256) throw new ModifyFailure("NestingDepthExceeded", `Replacement value nests deeper than the maximum of ${256}`, 0, 0);
262
+ if (typeof value === "object" && value !== null) {
263
+ if (seen.has(value)) throw new ModifyFailure("CircularReference", "Replacement value contains a circular reference", 0, 0);
264
+ seen.add(value);
265
+ try {
266
+ if (Array.isArray(value)) return YamlSeq.make({
267
+ items: value.map((item) => jsValueToNode(item, seen, depth + 1)),
268
+ style: "block",
269
+ offset: 0,
270
+ length: 0
271
+ });
272
+ const record = value;
273
+ return YamlMap.make({
274
+ items: Object.keys(record).map((key) => YamlPair.make({
275
+ key: YamlScalar.make({
276
+ value: key,
277
+ style: "plain",
278
+ offset: 0,
279
+ length: 0
280
+ }),
281
+ value: jsValueToNode(record[key], seen, depth + 1)
282
+ })),
283
+ style: "block",
284
+ offset: 0,
285
+ length: 0
286
+ });
287
+ } finally {
288
+ seen.delete(value);
289
+ }
290
+ }
243
291
  return YamlScalar.make({
244
292
  value,
245
293
  style: "plain",
@@ -247,8 +295,12 @@ function jsValueToNode(value) {
247
295
  length: 0
248
296
  });
249
297
  }
298
+ /** Entry point for {@link jsValueToNode}: one `seen` set per lowering. */
299
+ function lowerValue(value) {
300
+ return jsValueToNode(value, /* @__PURE__ */ new Set(), 0);
301
+ }
250
302
  function modifyDocument(doc, path, value) {
251
- if (path.length === 0) return value === void 0 ? null : jsValueToNode(value);
303
+ if (path.length === 0) return value === void 0 ? null : lowerValue(value);
252
304
  if (doc.contents === null) throw new ModifyFailure("EmptyDocument", "Cannot navigate path in empty document", 0, 0);
253
305
  return modifyNode(doc.contents, path, 0, value);
254
306
  }
@@ -264,7 +316,7 @@ function modifyNode(node, path, depth, value) {
264
316
  newItems.splice(pairIndex, 1);
265
317
  return rebuildMap(node, newItems);
266
318
  }
267
- const newValueNode = jsValueToNode(value);
319
+ const newValueNode = lowerValue(value);
268
320
  if (pairIndex >= 0) {
269
321
  const newItems = [...node.items];
270
322
  const oldPair = newItems[pairIndex];
@@ -304,8 +356,8 @@ function modifyNode(node, path, depth, value) {
304
356
  const newItems = [...node.items];
305
357
  if (value === void 0) {
306
358
  if (idx < newItems.length) newItems.splice(idx, 1);
307
- } else if (idx < newItems.length) newItems[idx] = jsValueToNode(value);
308
- else newItems.push(jsValueToNode(value));
359
+ } else if (idx < newItems.length) newItems[idx] = lowerValue(value);
360
+ else newItems.push(lowerValue(value));
309
361
  return rebuildSeq(node, newItems);
310
362
  }
311
363
  if (idx >= node.items.length) throw new ModifyFailure("InvalidIndex", `Index ${idx} out of bounds`, node.offset, node.length);
@@ -456,12 +508,27 @@ var YamlFormat = class YamlFormat {
456
508
  /**
457
509
  * Compute the edits that insert, replace, or remove a value at `path`.
458
510
  * Passing `value === undefined` removes the target key/element; a missing
459
- * insertion target appends after the last pair/element. Only
460
- * scalar-compatible values are supported (matching v3 — arbitrary object
461
- * graphs are not recursively lowered into AST nodes). Fails with
511
+ * insertion target appends after the last pair/element. Fails with
462
512
  * {@link YamlModificationError} on a fatal parse error or a structural
463
513
  * navigation mismatch.
464
514
  *
515
+ * **`value` may be a whole object graph.** An array is written as a block
516
+ * sequence and any other non-null object as a block mapping over its own
517
+ * enumerable string keys, recursively — the same lowering
518
+ * {@link Yaml.stringify} applies to the same value, so `modify` and
519
+ * `stringify` agree on what a given JavaScript value means. (Before
520
+ * 0.14.0 only scalars were lowered and a mapping or sequence value was
521
+ * coerced through `String(value)`, writing the literal text
522
+ * `[object Object]` into the document — see #642.) Only the surrounding
523
+ * document is preserved byte-for-byte; the replacement subtree is
524
+ * synthesized, so it carries no comments and takes the stringifier's
525
+ * styles.
526
+ *
527
+ * Two replacement values have no finite rendering and fail typed rather
528
+ * than hanging or overflowing the stack: one containing a circular
529
+ * reference (`CircularReference`) and one nesting deeper than 256 levels
530
+ * (`NestingDepthExceeded`).
531
+ *
465
532
  * **Single-document contract.** A `path` carries no document index, so on
466
533
  * a multi-document stream there is no rule for which document it names —
467
534
  * `modify` fails with {@link YamlModificationError} carrying a
package/index.d.ts CHANGED
@@ -5,77 +5,77 @@ import { Data, Effect, Option, Result, Schema, Stream } from "effect";
5
5
  *
6
6
  * @public
7
7
  */
8
- declare const YamlLexErrorCode: Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>;
8
+ export declare const YamlLexErrorCode: Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>;
9
9
  /**
10
10
  * The union of all lexer-stage error code string literals.
11
11
  *
12
12
  * @public
13
13
  */
14
- type YamlLexErrorCode = typeof YamlLexErrorCode.Type;
14
+ export type YamlLexErrorCode = typeof YamlLexErrorCode.Type;
15
15
  /**
16
16
  * Error codes emitted by the CST-parser stage.
17
17
  *
18
18
  * @public
19
19
  */
20
- declare const YamlParseErrorCode: Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>;
20
+ export declare const YamlParseErrorCode: Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>;
21
21
  /**
22
22
  * The union of all parser-stage error code string literals.
23
23
  *
24
24
  * @public
25
25
  */
26
- type YamlParseErrorCode = typeof YamlParseErrorCode.Type;
26
+ export type YamlParseErrorCode = typeof YamlParseErrorCode.Type;
27
27
  /**
28
28
  * Error codes emitted by the composer stage.
29
29
  *
30
30
  * @public
31
31
  */
32
- declare const YamlComposerErrorCode: Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>;
32
+ export declare const YamlComposerErrorCode: Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>;
33
33
  /**
34
34
  * The union of all composer-stage error code string literals.
35
35
  *
36
36
  * @public
37
37
  */
38
- type YamlComposerErrorCode = typeof YamlComposerErrorCode.Type;
38
+ export type YamlComposerErrorCode = typeof YamlComposerErrorCode.Type;
39
39
  /**
40
40
  * Error codes emitted by the stringifier (the circular-reference guard).
41
41
  *
42
42
  * @public
43
43
  */
44
- declare const YamlStringifyErrorCode: Schema.Literals<readonly ["CircularReference"]>;
44
+ export declare const YamlStringifyErrorCode: Schema.Literals<readonly ["CircularReference"]>;
45
45
  /**
46
46
  * The union of all stringifier-stage error code string literals.
47
47
  *
48
48
  * @public
49
49
  */
50
- type YamlStringifyErrorCode = typeof YamlStringifyErrorCode.Type;
50
+ export type YamlStringifyErrorCode = typeof YamlStringifyErrorCode.Type;
51
51
  /**
52
52
  * Error codes emitted by `YamlFormat.modify`'s path navigation against an
53
53
  * already-composed AST — not raised by the parser/composer/stringifier.
54
54
  *
55
55
  * @public
56
56
  */
57
- declare const YamlModifyErrorCode: Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument"]>;
57
+ export declare const YamlModifyErrorCode: Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument", "CircularReference", "NestingDepthExceeded"]>;
58
58
  /**
59
59
  * The union of all modify-stage error code string literals.
60
60
  *
61
61
  * @public
62
62
  */
63
- type YamlModifyErrorCode = typeof YamlModifyErrorCode.Type;
63
+ export type YamlModifyErrorCode = typeof YamlModifyErrorCode.Type;
64
64
  /**
65
65
  * Union of all YAML error codes across all pipeline stages. Stage
66
66
  * discrimination lives here (in the code), not in separate error classes.
67
67
  *
68
68
  * @public
69
69
  */
70
- declare const YamlErrorCode: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument"]>]>;
70
+ export declare const YamlErrorCode: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument", "CircularReference", "NestingDepthExceeded"]>]>;
71
71
  /**
72
72
  * The union of all YAML error code string literals.
73
73
  *
74
74
  * @public
75
75
  */
76
- type YamlErrorCode = typeof YamlErrorCode.Type;
76
+ export type YamlErrorCode = typeof YamlErrorCode.Type;
77
77
  declare const YamlDiagnostic_base: Schema.Class<YamlDiagnostic, Schema.Struct<{
78
- readonly code: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument"]>]>;
78
+ readonly code: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument", "CircularReference", "NestingDepthExceeded"]>]>;
79
79
  readonly message: Schema.String;
80
80
  readonly offset: Schema.Number;
81
81
  readonly length: Schema.Number;
@@ -95,7 +95,7 @@ declare const YamlDiagnostic_base: Schema.Class<YamlDiagnostic, Schema.Struct<{
95
95
  *
96
96
  * @public
97
97
  */
98
- declare class YamlDiagnostic extends YamlDiagnostic_base {
98
+ export declare class YamlDiagnostic extends YamlDiagnostic_base {
99
99
  /**
100
100
  * The single fatal-code predicate: whether diagnostics with this code
101
101
  * abort a parse (vs. being recoverable warnings-as-data). Declared once,
@@ -142,7 +142,7 @@ declare const YamlParseOptions_base: Schema.Class<YamlParseOptions, Schema.Struc
142
142
  *
143
143
  * @public
144
144
  */
145
- declare class YamlParseOptions extends YamlParseOptions_base {}
145
+ export declare class YamlParseOptions extends YamlParseOptions_base {}
146
146
  declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Schema.Struct<{
147
147
  readonly indent: Schema.optionalKey<Schema.Number>;
148
148
  /**
@@ -257,7 +257,7 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
257
257
  *
258
258
  * @public
259
259
  */
260
- declare class YamlStringifyOptions extends YamlStringifyOptions_base {}
260
+ export declare class YamlStringifyOptions extends YamlStringifyOptions_base {}
261
261
  declare const YamlParseError_base: Schema.Class<YamlParseError, Schema.TaggedStruct<"YamlParseError", {
262
262
  readonly diagnostics: Schema.$Array<typeof YamlDiagnostic>;
263
263
  readonly input: Schema.String;
@@ -272,7 +272,7 @@ declare const YamlParseError_base: Schema.Class<YamlParseError, Schema.TaggedStr
272
272
  *
273
273
  * @public
274
274
  */
275
- declare class YamlParseError extends YamlParseError_base {
275
+ export declare class YamlParseError extends YamlParseError_base {
276
276
  get message(): string;
277
277
  }
278
278
  declare const YamlStringifyError_base: Schema.Class<YamlStringifyError, Schema.TaggedStruct<"YamlStringifyError", {
@@ -288,7 +288,7 @@ declare const YamlStringifyError_base: Schema.Class<YamlStringifyError, Schema.T
288
288
  *
289
289
  * @public
290
290
  */
291
- declare class YamlStringifyError extends YamlStringifyError_base {
291
+ export declare class YamlStringifyError extends YamlStringifyError_base {
292
292
  get message(): string;
293
293
  }
294
294
  /**
@@ -331,7 +331,7 @@ interface YamlBoundCodec<T, RD = never, RE = never> {
331
331
  *
332
332
  * @public
333
333
  */
334
- declare class Yaml {
334
+ export declare class Yaml {
335
335
  private constructor();
336
336
  /**
337
337
  * Parse a single YAML document into a plain JavaScript value, resolving
@@ -601,7 +601,7 @@ declare const YamlRange_base: Schema.Class<YamlRange, Schema.Struct<{
601
601
  *
602
602
  * @public
603
603
  */
604
- declare class YamlRange extends YamlRange_base {}
604
+ export declare class YamlRange extends YamlRange_base {}
605
605
  declare const YamlEdit_base: Schema.Class<YamlEdit, Schema.Struct<{
606
606
  readonly offset: Schema.Number;
607
607
  readonly length: Schema.Number;
@@ -618,7 +618,7 @@ declare const YamlEdit_base: Schema.Class<YamlEdit, Schema.Struct<{
618
618
  *
619
619
  * @public
620
620
  */
621
- declare class YamlEdit extends YamlEdit_base {
621
+ export declare class YamlEdit extends YamlEdit_base {
622
622
  /**
623
623
  * Apply `edits` to `text`, producing a new string. Edits are applied in
624
624
  * reverse-offset order so earlier offsets stay valid; the input `edits`
@@ -634,25 +634,25 @@ declare class YamlEdit extends YamlEdit_base {
634
634
  *
635
635
  * @public
636
636
  */
637
- declare const ScalarStyle: Schema.Literals<readonly ["plain", "single-quoted", "double-quoted", "block-literal", "block-folded"]>;
637
+ export declare const ScalarStyle: Schema.Literals<readonly ["plain", "single-quoted", "double-quoted", "block-literal", "block-folded"]>;
638
638
  /**
639
639
  * The union of all scalar style string literals.
640
640
  *
641
641
  * @public
642
642
  */
643
- type ScalarStyle = typeof ScalarStyle.Type;
643
+ export type ScalarStyle = typeof ScalarStyle.Type;
644
644
  /**
645
645
  * YAML collection presentation styles.
646
646
  *
647
647
  * @public
648
648
  */
649
- declare const CollectionStyle: Schema.Literals<readonly ["block", "flow"]>;
649
+ export declare const CollectionStyle: Schema.Literals<readonly ["block", "flow"]>;
650
650
  /**
651
651
  * The union of all collection style string literals.
652
652
  *
653
653
  * @public
654
654
  */
655
- type CollectionStyle = typeof CollectionStyle.Type;
655
+ export type CollectionStyle = typeof CollectionStyle.Type;
656
656
  /**
657
657
  * Quote characters available to the stringifier's plain-scalar fallback: the
658
658
  * style a `plain`-styled scalar is rendered in when it turns out to require
@@ -662,13 +662,13 @@ type CollectionStyle = typeof CollectionStyle.Type;
662
662
  *
663
663
  * @public
664
664
  */
665
- declare const QuoteStyle: Schema.Literals<readonly ["single", "double"]>;
665
+ export declare const QuoteStyle: Schema.Literals<readonly ["single", "double"]>;
666
666
  /**
667
667
  * The union of all fallback quote style string literals.
668
668
  *
669
669
  * @public
670
670
  */
671
- type QuoteStyle = typeof QuoteStyle.Type;
671
+ export type QuoteStyle = typeof QuoteStyle.Type;
672
672
  /**
673
673
  * Foreign resolution dialects the stringifier's plain-scalar fallback can
674
674
  * defend against: setting the `quoteCompat` field of `YamlStringifyOptions`
@@ -683,26 +683,26 @@ type QuoteStyle = typeof QuoteStyle.Type;
683
683
  *
684
684
  * @public
685
685
  */
686
- declare const QuoteCompat: Schema.Literals<readonly ["yaml-1.1"]>;
686
+ export declare const QuoteCompat: Schema.Literals<readonly ["yaml-1.1"]>;
687
687
  /**
688
688
  * The union of all quote-compat dialect string literals.
689
689
  *
690
690
  * @public
691
691
  */
692
- type QuoteCompat = typeof QuoteCompat.Type;
692
+ export type QuoteCompat = typeof QuoteCompat.Type;
693
693
  /**
694
694
  * Block-scalar chomping indicators (`-` strip, default clip, `+` keep).
695
695
  * Referenced by the {@link YamlScalar} `chomp` field schema.
696
696
  *
697
697
  * @public
698
698
  */
699
- declare const ScalarChomp: Schema.Literals<readonly ["strip", "clip", "keep"]>;
699
+ export declare const ScalarChomp: Schema.Literals<readonly ["strip", "clip", "keep"]>;
700
700
  /**
701
701
  * The union of all block-scalar chomping indicator string literals.
702
702
  *
703
703
  * @public
704
704
  */
705
- type ScalarChomp = typeof ScalarChomp.Type;
705
+ export type ScalarChomp = typeof ScalarChomp.Type;
706
706
  declare const YamlScalar_base: Schema.Class<YamlScalar, Schema.TaggedStruct<"YamlScalar", {
707
707
  readonly value: Schema.Unknown;
708
708
  readonly tag: Schema.optionalKey<Schema.String>;
@@ -746,7 +746,7 @@ declare const YamlScalar_base: Schema.Class<YamlScalar, Schema.TaggedStruct<"Yam
746
746
  *
747
747
  * @public
748
748
  */
749
- declare class YamlScalar extends YamlScalar_base {
749
+ export declare class YamlScalar extends YamlScalar_base {
750
750
  /**
751
751
  * Navigate to a descendant by path (string segments for mapping keys,
752
752
  * numbers for sequence indices). `Option.none()` when any segment cannot
@@ -790,7 +790,7 @@ declare const YamlAlias_base: Schema.Class<YamlAlias, Schema.TaggedStruct<"YamlA
790
790
  *
791
791
  * @public
792
792
  */
793
- declare class YamlAlias extends YamlAlias_base {
793
+ export declare class YamlAlias extends YamlAlias_base {
794
794
  /** See `YamlScalar.find`. Pure. */
795
795
  find(path: YamlPath): Option.Option<YamlNode>;
796
796
  /** See `YamlScalar.findAtOffset`. Pure. */
@@ -843,13 +843,13 @@ interface YamlAliasEncoded extends Schema.Codec.Encoded<typeof YamlAlias> {}
843
843
  *
844
844
  * @public
845
845
  */
846
- declare const YamlNode: Schema.Codec<YamlScalar | YamlMap | YamlSeq | YamlAlias, YamlScalarEncoded | YamlMapEncoded | YamlSeqEncoded | YamlAliasEncoded>;
846
+ export declare const YamlNode: Schema.Codec<YamlScalar | YamlMap | YamlSeq | YamlAlias, YamlScalarEncoded | YamlMapEncoded | YamlSeqEncoded | YamlAliasEncoded>;
847
847
  /**
848
848
  * The union of all YAML AST value node types.
849
849
  *
850
850
  * @public
851
851
  */
852
- type YamlNode = YamlScalar | YamlMap | YamlSeq | YamlAlias;
852
+ export type YamlNode = YamlScalar | YamlMap | YamlSeq | YamlAlias;
853
853
  declare const YamlPair_base: Schema.Class<YamlPair, Schema.TaggedStruct<"YamlPair", {
854
854
  readonly key: Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>;
855
855
  readonly value: Schema.NullOr<Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>>;
@@ -867,7 +867,7 @@ declare const YamlPair_base: Schema.Class<YamlPair, Schema.TaggedStruct<"YamlPai
867
867
  *
868
868
  * @public
869
869
  */
870
- declare class YamlPair extends YamlPair_base {}
870
+ export declare class YamlPair extends YamlPair_base {}
871
871
  declare const YamlMap_base: Schema.Class<YamlMap, Schema.TaggedStruct<"YamlMap", {
872
872
  readonly items: Schema.$Array<Schema.suspend<typeof YamlPair>>;
873
873
  readonly tag: Schema.optionalKey<Schema.String>;
@@ -895,7 +895,7 @@ declare const YamlMap_base: Schema.Class<YamlMap, Schema.TaggedStruct<"YamlMap",
895
895
  *
896
896
  * @public
897
897
  */
898
- declare class YamlMap extends YamlMap_base {
898
+ export declare class YamlMap extends YamlMap_base {
899
899
  /** See `YamlScalar.find`. Pure. */
900
900
  find(path: YamlPath): Option.Option<YamlNode>;
901
901
  /** See `YamlScalar.findAtOffset`. Pure. */
@@ -929,7 +929,7 @@ declare const YamlSeq_base: Schema.Class<YamlSeq, Schema.TaggedStruct<"YamlSeq",
929
929
  *
930
930
  * @public
931
931
  */
932
- declare class YamlSeq extends YamlSeq_base {
932
+ export declare class YamlSeq extends YamlSeq_base {
933
933
  /** See `YamlScalar.find`. Pure. */
934
934
  find(path: YamlPath): Option.Option<YamlNode>;
935
935
  /** See `YamlScalar.findAtOffset`. Pure. */
@@ -953,7 +953,7 @@ declare const YamlDirective_base: Schema.Class<YamlDirective, Schema.Struct<{
953
953
  *
954
954
  * @public
955
955
  */
956
- declare class YamlDirective extends YamlDirective_base {}
956
+ export declare class YamlDirective extends YamlDirective_base {}
957
957
  declare const YamlDocument_base: Schema.Class<YamlDocument, Schema.Struct<{
958
958
  readonly contents: Schema.NullOr<Schema.suspend<Schema.Schema<YamlNode>>>;
959
959
  readonly errors: Schema.$Array<typeof YamlDiagnostic>;
@@ -982,7 +982,7 @@ declare const YamlDocument_base: Schema.Class<YamlDocument, Schema.Struct<{
982
982
  *
983
983
  * @public
984
984
  */
985
- declare class YamlDocument extends YamlDocument_base {
985
+ export declare class YamlDocument extends YamlDocument_base {
986
986
  /**
987
987
  * Parse a single YAML document, keeping the full AST, directives and
988
988
  * recovered diagnostics. Fails with the aggregate {@link YamlParseError}
@@ -1102,7 +1102,7 @@ declare const YamlFormattingOptions_base: Schema.Class<YamlFormattingOptions, Sc
1102
1102
  *
1103
1103
  * @public
1104
1104
  */
1105
- declare class YamlFormattingOptions extends YamlFormattingOptions_base {}
1105
+ export declare class YamlFormattingOptions extends YamlFormattingOptions_base {}
1106
1106
  declare const YamlModificationError_base: Schema.Class<YamlModificationError, Schema.TaggedStruct<"YamlModificationError", {
1107
1107
  readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
1108
1108
  readonly diagnostics: Schema.$Array<typeof YamlDiagnostic>;
@@ -1122,7 +1122,7 @@ declare const YamlModificationError_base: Schema.Class<YamlModificationError, Sc
1122
1122
  *
1123
1123
  * @public
1124
1124
  */
1125
- declare class YamlModificationError extends YamlModificationError_base {
1125
+ export declare class YamlModificationError extends YamlModificationError_base {
1126
1126
  get message(): string;
1127
1127
  }
1128
1128
  /**
@@ -1157,7 +1157,7 @@ declare class YamlModificationError extends YamlModificationError_base {
1157
1157
  *
1158
1158
  * @public
1159
1159
  */
1160
- declare class YamlFormat {
1160
+ export declare class YamlFormat {
1161
1161
  private constructor();
1162
1162
  /**
1163
1163
  * Compute formatting edits for a YAML document. Non-mutating — apply the
@@ -1219,12 +1219,27 @@ declare class YamlFormat {
1219
1219
  /**
1220
1220
  * Compute the edits that insert, replace, or remove a value at `path`.
1221
1221
  * Passing `value === undefined` removes the target key/element; a missing
1222
- * insertion target appends after the last pair/element. Only
1223
- * scalar-compatible values are supported (matching v3 — arbitrary object
1224
- * graphs are not recursively lowered into AST nodes). Fails with
1222
+ * insertion target appends after the last pair/element. Fails with
1225
1223
  * {@link YamlModificationError} on a fatal parse error or a structural
1226
1224
  * navigation mismatch.
1227
1225
  *
1226
+ * **`value` may be a whole object graph.** An array is written as a block
1227
+ * sequence and any other non-null object as a block mapping over its own
1228
+ * enumerable string keys, recursively — the same lowering
1229
+ * {@link Yaml.stringify} applies to the same value, so `modify` and
1230
+ * `stringify` agree on what a given JavaScript value means. (Before
1231
+ * 0.14.0 only scalars were lowered and a mapping or sequence value was
1232
+ * coerced through `String(value)`, writing the literal text
1233
+ * `[object Object]` into the document — see #642.) Only the surrounding
1234
+ * document is preserved byte-for-byte; the replacement subtree is
1235
+ * synthesized, so it carries no comments and takes the stringifier's
1236
+ * styles.
1237
+ *
1238
+ * Two replacement values have no finite rendering and fail typed rather
1239
+ * than hanging or overflowing the stack: one containing a circular
1240
+ * reference (`CircularReference`) and one nesting deeper than 256 levels
1241
+ * (`NestingDepthExceeded`).
1242
+ *
1228
1243
  * **Single-document contract.** A `path` carries no document index, so on
1229
1244
  * a multi-document stream there is no rule for which document it names —
1230
1245
  * `modify` fails with {@link YamlModificationError} carrying a
@@ -1264,13 +1279,13 @@ declare class YamlFormat {
1264
1279
  *
1265
1280
  * @public
1266
1281
  */
1267
- declare const YamlTokenKind: Schema.Literals<readonly ["document-start", "document-end", "directive", "tag", "anchor", "alias", "scalar", "block-map-start", "block-map-key", "block-map-value", "block-seq-start", "block-seq-entry", "flow-map-start", "flow-map-end", "flow-seq-start", "flow-seq-end", "flow-separator", "newline", "whitespace", "comment", "byte-order-mark", "error"]>;
1282
+ export declare const YamlTokenKind: Schema.Literals<readonly ["document-start", "document-end", "directive", "tag", "anchor", "alias", "scalar", "block-map-start", "block-map-key", "block-map-value", "block-seq-start", "block-seq-entry", "flow-map-start", "flow-map-end", "flow-seq-start", "flow-seq-end", "flow-separator", "newline", "whitespace", "comment", "byte-order-mark", "error"]>;
1268
1283
  /**
1269
1284
  * The union of all lexical token kind string literals.
1270
1285
  *
1271
1286
  * @public
1272
1287
  */
1273
- type YamlTokenKind = typeof YamlTokenKind.Type;
1288
+ export type YamlTokenKind = typeof YamlTokenKind.Type;
1274
1289
  declare const YamlToken_base: Schema.Class<YamlToken, Schema.Struct<{
1275
1290
  readonly kind: Schema.Literals<readonly ["document-start", "document-end", "directive", "tag", "anchor", "alias", "scalar", "block-map-start", "block-map-key", "block-map-value", "block-seq-start", "block-seq-entry", "flow-map-start", "flow-map-end", "flow-seq-start", "flow-seq-end", "flow-separator", "newline", "whitespace", "comment", "byte-order-mark", "error"]>;
1276
1291
  readonly text: Schema.String;
@@ -1291,13 +1306,13 @@ declare const YamlToken_base: Schema.Class<YamlToken, Schema.Struct<{
1291
1306
  *
1292
1307
  * @public
1293
1308
  */
1294
- declare class YamlToken extends YamlToken_base {}
1309
+ export declare class YamlToken extends YamlToken_base {}
1295
1310
  /**
1296
1311
  * Tokenizer statics. Not instantiable.
1297
1312
  *
1298
1313
  * @public
1299
1314
  */
1300
- declare class YamlTokens {
1315
+ export declare class YamlTokens {
1301
1316
  private constructor();
1302
1317
  /**
1303
1318
  * Tokenize YAML text into the full positioned token array — the sync
@@ -1346,13 +1361,13 @@ declare class YamlTokens {
1346
1361
  *
1347
1362
  * @public
1348
1363
  */
1349
- declare const YamlLintSeverity: Schema.Literals<readonly ["error", "warning"]>;
1364
+ export declare const YamlLintSeverity: Schema.Literals<readonly ["error", "warning"]>;
1350
1365
  /**
1351
1366
  * The union of lint severity string literals.
1352
1367
  *
1353
1368
  * @public
1354
1369
  */
1355
- type YamlLintSeverity = typeof YamlLintSeverity.Type;
1370
+ export type YamlLintSeverity = typeof YamlLintSeverity.Type;
1356
1371
  declare const YamlLintDiagnostic_base: Schema.Class<YamlLintDiagnostic, Schema.Struct<{
1357
1372
  readonly rule: Schema.String;
1358
1373
  readonly severity: Schema.Literals<readonly ["error", "warning"]>;
@@ -1375,7 +1390,7 @@ declare const YamlLintDiagnostic_base: Schema.Class<YamlLintDiagnostic, Schema.S
1375
1390
  *
1376
1391
  * @public
1377
1392
  */
1378
- declare class YamlLintDiagnostic extends YamlLintDiagnostic_base {}
1393
+ export declare class YamlLintDiagnostic extends YamlLintDiagnostic_base {}
1379
1394
  /**
1380
1395
  * One source line of the linted document: its text (without the line
1381
1396
  * terminator — the `\n`, and for CRLF input the `\r\n` pair), the offset of
@@ -1438,7 +1453,7 @@ declare const StyleVote_base: Schema.Class<StyleVote, Schema.TaggedStruct<"Style
1438
1453
  *
1439
1454
  * @public
1440
1455
  */
1441
- declare class StyleVote extends StyleVote_base {}
1456
+ export declare class StyleVote extends StyleVote_base {}
1442
1457
  declare const StyleFloor_base: Schema.Class<StyleFloor, Schema.TaggedStruct<"StyleFloor", {
1443
1458
  readonly dimension: Schema.String;
1444
1459
  readonly value: Schema.Number;
@@ -1456,7 +1471,7 @@ declare const StyleFloor_base: Schema.Class<StyleFloor, Schema.TaggedStruct<"Sty
1456
1471
  *
1457
1472
  * @public
1458
1473
  */
1459
- declare class StyleFloor extends StyleFloor_base {}
1474
+ export declare class StyleFloor extends StyleFloor_base {}
1460
1475
  /**
1461
1476
  * What a rule's `infer` hook yields per occurrence: a categorical
1462
1477
  * {@link StyleVote} or a measured {@link StyleFloor}.
@@ -1497,13 +1512,13 @@ interface YamlRule {
1497
1512
  *
1498
1513
  * @public
1499
1514
  */
1500
- declare const YamlLintRuleSetting: Schema.Union<readonly [Schema.Literals<readonly ["error", "warning", "off"]>, Schema.$Record<Schema.String, Schema.Unknown>]>;
1515
+ export declare const YamlLintRuleSetting: Schema.Union<readonly [Schema.Literals<readonly ["error", "warning", "off"]>, Schema.$Record<Schema.String, Schema.Unknown>]>;
1501
1516
  /**
1502
1517
  * The union type of one `rules`-map entry.
1503
1518
  *
1504
1519
  * @public
1505
1520
  */
1506
- type YamlLintRuleSetting = typeof YamlLintRuleSetting.Type;
1521
+ export type YamlLintRuleSetting = typeof YamlLintRuleSetting.Type;
1507
1522
  declare const YamlLintConfig_base: Schema.Class<YamlLintConfig, Schema.Struct<{
1508
1523
  readonly rules: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Literals<readonly ["error", "warning", "off"]>, Schema.$Record<Schema.String, Schema.Unknown>]>>;
1509
1524
  }>, {}>;
@@ -1524,7 +1539,7 @@ declare const YamlLintConfig_base: Schema.Class<YamlLintConfig, Schema.Struct<{
1524
1539
  *
1525
1540
  * @public
1526
1541
  */
1527
- declare class YamlLintConfig extends YamlLintConfig_base {
1542
+ export declare class YamlLintConfig extends YamlLintConfig_base {
1528
1543
  /**
1529
1544
  * The default preset. Rule entries accrete as built-ins land; the
1530
1545
  * `quoted-strings` rule defaults to DOUBLE quotes here (the one taste
@@ -1552,7 +1567,7 @@ declare const StyleVoteTally_base: Schema.Class<StyleVoteTally, Schema.Struct<{
1552
1567
  *
1553
1568
  * @public
1554
1569
  */
1555
- declare class StyleVoteTally extends StyleVoteTally_base {}
1570
+ export declare class StyleVoteTally extends StyleVoteTally_base {}
1556
1571
  declare const StyleFloorTally_base: Schema.Class<StyleFloorTally, Schema.Struct<{
1557
1572
  readonly rule: Schema.String;
1558
1573
  readonly dimension: Schema.String;
@@ -1566,7 +1581,7 @@ declare const StyleFloorTally_base: Schema.Class<StyleFloorTally, Schema.Struct<
1566
1581
  *
1567
1582
  * @public
1568
1583
  */
1569
- declare class StyleFloorTally extends StyleFloorTally_base {}
1584
+ export declare class StyleFloorTally extends StyleFloorTally_base {}
1570
1585
  declare const StyleEvidence_base: Schema.Class<StyleEvidence, Schema.Struct<{
1571
1586
  readonly votes: Schema.$Array<typeof StyleVoteTally>;
1572
1587
  readonly floors: Schema.$Array<typeof StyleFloorTally>;
@@ -1587,7 +1602,7 @@ declare const StyleEvidence_base: Schema.Class<StyleEvidence, Schema.Struct<{
1587
1602
  *
1588
1603
  * @public
1589
1604
  */
1590
- declare class StyleEvidence extends StyleEvidence_base {
1605
+ export declare class StyleEvidence extends StyleEvidence_base {
1591
1606
  /** The monoid identity: no observations. */
1592
1607
  static readonly empty: StyleEvidence;
1593
1608
  /**
@@ -1618,7 +1633,7 @@ declare const StyleConflict_base: Schema.Class<StyleConflict, Schema.Struct<{
1618
1633
  *
1619
1634
  * @public
1620
1635
  */
1621
- declare class StyleConflict extends StyleConflict_base {}
1636
+ export declare class StyleConflict extends StyleConflict_base {}
1622
1637
  declare const YamlStyleConflictError_base: Schema.Class<YamlStyleConflictError, Schema.TaggedStruct<"YamlStyleConflictError", {
1623
1638
  readonly conflicts: Schema.$Array<typeof StyleConflict>;
1624
1639
  }>, import("effect/Cause").YieldableError>;
@@ -1632,7 +1647,7 @@ declare const YamlStyleConflictError_base: Schema.Class<YamlStyleConflictError,
1632
1647
  *
1633
1648
  * @public
1634
1649
  */
1635
- declare class YamlStyleConflictError extends YamlStyleConflictError_base {
1650
+ export declare class YamlStyleConflictError extends YamlStyleConflictError_base {
1636
1651
  get message(): string;
1637
1652
  }
1638
1653
  /**
@@ -1656,7 +1671,7 @@ interface YamlLintInference {
1656
1671
  *
1657
1672
  * @public
1658
1673
  */
1659
- declare class YamlLint {
1674
+ export declare class YamlLint {
1660
1675
  private constructor();
1661
1676
  /**
1662
1677
  * The built-in rule catalog. Custom usage is array concatenation:
@@ -1752,7 +1767,7 @@ declare class YamlLint {
1752
1767
  *
1753
1768
  * @public
1754
1769
  */
1755
- type YamlVisitorEvent = Data.TaggedEnum<{
1770
+ export type YamlVisitorEvent = Data.TaggedEnum<{
1756
1771
  DocumentStart: {
1757
1772
  readonly path: YamlPath;
1758
1773
  readonly depth: number;
@@ -1832,7 +1847,7 @@ type YamlVisitorEvent = Data.TaggedEnum<{
1832
1847
  *
1833
1848
  * @public
1834
1849
  */
1835
- declare const YamlVisitorEvent: {
1850
+ export declare const YamlVisitorEvent: {
1836
1851
  readonly $is: <Tag extends "Alias" | "Comment" | "Directive" | "DocumentEnd" | "DocumentStart" | "Error" | "MapEnd" | "MapStart" | "Pair" | "Scalar" | "SeqEnd" | "SeqStart">(tag: Tag) => (u: unknown) => u is Extract<{
1837
1852
  readonly _tag: "Alias";
1838
1853
  readonly path: YamlPath;
@@ -2326,7 +2341,7 @@ declare const YamlVisitorEvent: {
2326
2341
  *
2327
2342
  * @public
2328
2343
  */
2329
- declare class YamlVisitor {
2344
+ export declare class YamlVisitor {
2330
2345
  private constructor();
2331
2346
  /**
2332
2347
  * Create a lazy `Stream` of `YamlVisitorEvent` from YAML text, in document
@@ -2344,5 +2359,5 @@ declare class YamlVisitor {
2344
2359
  static visit(text: string, options?: YamlParseOptions): Stream.Stream<YamlVisitorEvent>;
2345
2360
  }
2346
2361
  //#endregion
2347
- export { CollectionStyle, type LintContext, type LintLine, QuoteCompat, QuoteStyle, ScalarChomp, ScalarStyle, StyleConflict, StyleEvidence, StyleFloor, StyleFloorTally, type StyleObservation, StyleVote, StyleVoteTally, Yaml, YamlAlias, type YamlAliasEncoded, type YamlBoundCodec, YamlComposerErrorCode, YamlDiagnostic, YamlDirective, YamlDocument, YamlEdit, YamlErrorCode, YamlFormat, YamlFormattingOptions, YamlLexErrorCode, YamlLint, YamlLintConfig, YamlLintDiagnostic, type YamlLintInference, YamlLintRuleSetting, YamlLintSeverity, YamlMap, type YamlMapEncoded, YamlModificationError, YamlModifyErrorCode, YamlNode, YamlPair, YamlParseError, YamlParseErrorCode, YamlParseOptions, type YamlPath, YamlRange, type YamlRangeLike, type YamlRule, YamlScalar, type YamlScalarEncoded, type YamlSegment, YamlSeq, type YamlSeqEncoded, YamlStringifyError, YamlStringifyErrorCode, YamlStringifyOptions, YamlStyleConflictError, YamlToken, YamlTokenKind, YamlTokens, YamlVisitor, YamlVisitorEvent };
2362
+ export type { LintContext, LintLine, StyleObservation, YamlAliasEncoded, YamlBoundCodec, YamlLintInference, YamlMapEncoded, YamlPath, YamlRangeLike, YamlRule, YamlScalarEncoded, YamlSegment, YamlSeqEncoded };
2348
2363
  //# sourceMappingURL=index.d.ts.map
@@ -40,7 +40,7 @@ function composeBlockMapInner(blockMapCst, state, externalFirstKey, meta) {
40
40
  if (state.options.uniqueKeys) checkDuplicateKeys(pairs, state);
41
41
  checkMultilineImplicitKeys(pairs, state);
42
42
  const offset = externalFirstKey ? "offset" in externalFirstKey ? externalFirstKey.offset : blockMapCst.offset : blockMapCst.offset;
43
- const length = blockMapCst.offset + blockMapCst.length - offset;
43
+ const length = trimDisownedTrailingComments(state.text, offset, blockMapCst.offset + blockMapCst.length, state.escapedComments) - offset;
44
44
  const mapComment = meta?.comment !== void 0 ? trailingComment !== void 0 ? `${meta.comment}\n${trailingComment}` : meta.comment : trailingComment;
45
45
  const map = new YamlMap({
46
46
  items: pairs,
@@ -54,6 +54,49 @@ function composeBlockMapInner(blockMapCst, state, externalFirstKey, meta) {
54
54
  if (meta?.anchor) registerAnchor(map, meta.anchor, state, offset);
55
55
  return map;
56
56
  }
57
+ /**
58
+ * Narrow a block collection's raw CST span so it stops before any trailing
59
+ * comment line the collection's own comment model has already DISOWNED.
60
+ *
61
+ * The CST length of a block map/seq runs to the end of the last physical line
62
+ * the parser consumed, which includes a floating comment sitting at a column
63
+ * shallower than the collection's content. The comment model deliberately
64
+ * does not give that comment to the collection — `buildPairs` and the block-seq
65
+ * terminal partition push it onto `state.escapedComments`, where the enclosing
66
+ * scope re-attributes it (see `EscapedComment` in `comments.ts`: "it belongs to
67
+ * an outer scope"). The span was the one place that disagreed, reporting an
68
+ * `offset`/`length` whose end lay past a comment the node does not own — so a
69
+ * caller splicing text at the end of the collection inserted AFTER the comment
70
+ * (#642's sibling, #643).
71
+ *
72
+ * The disowned set is the input rather than a re-derived column test, so the
73
+ * span and the comment model cannot drift apart: whatever the partition threw
74
+ * out, the span excludes.
75
+ *
76
+ * Blank lines immediately above a trimmed run go with the run, not with the
77
+ * last entry — but only when something was trimmed, so a collection whose span
78
+ * merely ends in blank lines keeps the end it has always reported.
79
+ *
80
+ * Composition is bottom-up, so a nested collection's own span has already been
81
+ * trimmed by the time its parent's items are read.
82
+ */
83
+ function trimDisownedTrailingComments(text, offset, end, disowned) {
84
+ let cut = end;
85
+ for (const ec of disowned) {
86
+ if (ec.offset < offset || ec.offset >= cut) continue;
87
+ const lineStart = text.lastIndexOf("\n", ec.offset - 1) + 1;
88
+ if (lineStart <= offset || lineStart >= cut) continue;
89
+ cut = lineStart;
90
+ }
91
+ if (cut === end) return end;
92
+ while (cut > offset && text[cut - 1] === "\n") {
93
+ const prevLineStart = text.lastIndexOf("\n", cut - 2) + 1;
94
+ if (prevLineStart <= offset) break;
95
+ if (text.slice(prevLineStart, cut - 1).trim() !== "") break;
96
+ cut = prevLineStart;
97
+ }
98
+ return cut;
99
+ }
57
100
  function flattenBlockMapChildren(children, state, externalKeyColumn, externalKeyOffset) {
58
101
  const items = [];
59
102
  let pendingMeta = {};
@@ -1344,11 +1387,12 @@ function composeBlockSeqInner(cst, state, meta) {
1344
1387
  } else seqTrailing = withLeadingBlank(pending);
1345
1388
  }
1346
1389
  const seqComment = meta?.comment !== void 0 ? seqTrailing !== void 0 ? `${meta.comment}\n${seqTrailing}` : meta.comment : seqTrailing;
1390
+ const seqEnd = trimDisownedTrailingComments(state.text, cst.offset, cst.offset + cst.length, state.escapedComments);
1347
1391
  const seq = new YamlSeq({
1348
1392
  items: rawItems,
1349
1393
  style: "block",
1350
1394
  offset: cst.offset,
1351
- length: cst.length,
1395
+ length: seqEnd - cst.offset,
1352
1396
  ...meta?.tag !== void 0 ? { tag: meta.tag } : {},
1353
1397
  ...meta?.anchor !== void 0 ? { anchor: meta.anchor } : {},
1354
1398
  ...seqComment !== void 0 ? { comment: seqComment } : {}
@@ -1371,7 +1415,7 @@ function composeFlatBlockMap(children, startIdx, parentCst, state, externalFirst
1371
1415
  if (state.options.uniqueKeys) checkDuplicateKeys(pairs, state);
1372
1416
  checkMultilineImplicitKeys(pairs, state);
1373
1417
  const offset = "offset" in externalFirstKey ? externalFirstKey.offset : parentCst.offset;
1374
- const end = parentCst.offset + parentCst.length;
1418
+ const end = trimDisownedTrailingComments(state.text, offset, parentCst.offset + parentCst.length, state.escapedComments);
1375
1419
  const mapComment = meta?.comment !== void 0 ? trailingComment !== void 0 ? `${meta.comment}\n${trailingComment}` : meta.comment : trailingComment;
1376
1420
  const map = new YamlMap({
1377
1421
  items: pairs,
@@ -52,6 +52,13 @@ const YAML_STRINGIFY_ERROR_CODES = ["CircularReference"];
52
52
  * not re-emit `%YAML`/`%TAG` directive lines, and re-emitting a document
53
53
  * without its `%TAG` orphans every shorthand tag that depends on it — the
54
54
  * output would be unparseable — so modify fails typed rather than corrupting.
55
+ *
56
+ * `CircularReference` and `NestingDepthExceeded` are the two limits on the
57
+ * replacement value itself: `modify` lowers a plain JavaScript value into
58
+ * AST nodes, and an object graph that points back at itself or nests deeper
59
+ * than `MAX_NESTING_DEPTH` has no finite YAML rendering. Both names are
60
+ * deliberately the ones the stringify and compose stages already use for the
61
+ * same conditions, so `YamlErrorCode` gains no member.
55
62
  */
56
63
  const YAML_MODIFY_ERROR_CODES = [
57
64
  "EmptyDocument",
@@ -59,7 +66,9 @@ const YAML_MODIFY_ERROR_CODES = [
59
66
  "InvalidIndex",
60
67
  "NotNavigable",
61
68
  "MultiDocumentStream",
62
- "DirectiveCarryingDocument"
69
+ "DirectiveCarryingDocument",
70
+ "CircularReference",
71
+ "NestingDepthExceeded"
63
72
  ];
64
73
  /**
65
74
  * The single source of truth for which diagnostic codes are fatal to a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/yaml",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "private": false,
5
5
  "description": "Zero-dependency YAML parsing, editing, formatting and linting as Effect schemas.",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "./package.json": "./package.json"
42
42
  },
43
43
  "peerDependencies": {
44
- "effect": "4.0.0-rc.109"
44
+ "effect": "4.0.0-rc.112"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24.11.0"