@effected/yaml 0.3.0 → 0.4.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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm](https://img.shields.io/npm/v/@effected%2Fyaml?label=npm&color=cb3837)](https://www.npmjs.com/package/@effected/yaml)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-4caf50.svg)](https://opensource.org/licenses/MIT)
5
5
  [![Node.js %3E%3D24.11.0](https://img.shields.io/badge/Node.js-%3E%3D24.11.0-5fa04e.svg)](https://nodejs.org/)
6
- [![TypeScript 6.0](https://img.shields.io/badge/TypeScript-6.0-3178c6.svg)](https://www.typescriptlang.org/)
6
+ [![TypeScript 7.0](https://img.shields.io/badge/TypeScript-7.0-3178c6.svg)](https://www.typescriptlang.org/)
7
7
 
8
8
  Zero-dependency YAML 1.2 parsing, editing and formatting expressed as Effect schemas and pure functions. Parse a single document or a multi-document stream into plain values or an offset-preserving AST, resolve anchors and aliases, strip comments, compute byte-minimal edits, format, modify by path, walk a document as a `Stream` and decode straight into a validated domain schema.
9
9
 
package/Yaml.js CHANGED
@@ -44,7 +44,9 @@ var YamlParseOptions = class extends Schema.Class("YamlParseOptions")({
44
44
  * no-fold behavior; a positive value folds long plain, double-quoted and
45
45
  * block-folded (`>`) scalars at approximately that column, inserting only
46
46
  * semantically transparent line breaks. Block-literal (`|`) content is never
47
- * folded — literal blocks preserve their bytes by definition.
47
+ * folded — literal blocks preserve their bytes by definition. Folding is a
48
+ * value-path feature only: `YamlDocument#stringify` and the `YamlFormat`
49
+ * helpers accept these options but do not fold (see `lineWidth`).
48
50
  *
49
51
  * `indentSequences` controls the presentation of block sequences nested under
50
52
  * a mapping key: `false` (the default) emits them at the key's column — the
@@ -75,6 +77,15 @@ var YamlStringifyOptions = class extends Schema.Class("YamlStringifyOptions")({
75
77
  * Column at which to fold long scalars. Default `0` (and any value `<= 0`)
76
78
  * never wraps; a positive value folds plain, double-quoted and block-folded
77
79
  * (`>`) scalars at approximately that column, never block-literal (`|`).
80
+ *
81
+ * Takes effect only through {@link Yaml.stringify} and
82
+ * {@link Yaml.stringifySync} — the two entry points that accept these
83
+ * options on the value path. The schema factories ({@link Yaml.fromString},
84
+ * {@link Yaml.schema}, {@link Yaml.YamlFromString}) encode with default
85
+ * stringify options (`lineWidth` `0`), so their output never folds. The
86
+ * document/node path — `YamlDocument#stringify` and the `YamlFormat`
87
+ * helpers built on it — threads the field into its render context but
88
+ * never reads it, so it is inert there.
78
89
  */
79
90
  lineWidth: Schema.optionalKey(Schema.Number),
80
91
  defaultScalarStyle: Schema.optionalKey(ScalarStyle),
@@ -181,7 +192,7 @@ const stringifyDefectToError = (defect, value) => {
181
192
  });
182
193
  };
183
194
  /**
184
- * Synchronous single-document parse returning a {@link Result}. The pure
195
+ * Synchronous single-document parse returning a `Result`. The pure
185
196
  * engine bypasses the Effect runtime entirely: the composer, the failure
186
197
  * collection and the alias-expansion budget all run inline, and every failure
187
198
  * mode (fatal diagnostics, duplicate keys, a "billion laughs" blow-up) yields
@@ -203,7 +214,7 @@ const parseSyncImpl = (text, options) => {
203
214
  }
204
215
  };
205
216
  /**
206
- * Synchronous stringify returning a {@link Result}. Mirrors {@link Yaml.stringify}
217
+ * Synchronous stringify returning a `Result`. Mirrors {@link Yaml.stringify}
207
218
  * without the Effect wrapper: a circular reference or a value nested past the
208
219
  * recursion budget yields a `Failure` carrying a typed {@link YamlStringifyError},
209
220
  * never a thrown defect.
@@ -333,7 +344,7 @@ var Yaml = class Yaml {
333
344
  return yield* stringifyOrFail(value, options);
334
345
  });
335
346
  /**
336
- * Synchronous single-document parse, returning a {@link Result} instead of
347
+ * Synchronous single-document parse, returning a `Result` instead of
337
348
  * an `Effect`. A pure escape hatch for config-time callers that cannot
338
349
  * `await` an Effect (a `vitest.config.ts` is the motivating case): it runs
339
350
  * the same engine as {@link Yaml.parse} inline.
@@ -362,7 +373,7 @@ var Yaml = class Yaml {
362
373
  return parseSyncImpl(text, options);
363
374
  }
364
375
  /**
365
- * Synchronous stringify, returning a {@link Result} instead of an `Effect`.
376
+ * Synchronous stringify, returning a `Result` instead of an `Effect`.
366
377
  * The pure counterpart to {@link Yaml.stringify} for config-time callers
367
378
  * that cannot `await`.
368
379
  *
@@ -516,6 +527,51 @@ var Yaml = class Yaml {
516
527
  static schema(target, options) {
517
528
  return Yaml.fromString(options).pipe(Schema.decodeTo(target));
518
529
  }
530
+ /**
531
+ * Bind a target schema to the YAML codec once, yielding the composed
532
+ * schema plus pre-derived `decode`/`encode` directions — the
533
+ * {@link Yaml.schema} composition without the generic `Schema` machinery
534
+ * at every use site. Binds the plain single-document form only: default
535
+ * {@link YamlParseOptions} on decode, default stringify options on encode;
536
+ * for multi-document streams compose over {@link Yaml.allFromString}
537
+ * directly.
538
+ *
539
+ * Both directions fail with `Schema.SchemaError`, exactly as
540
+ * `Schema.decodeEffect`/`Schema.encodeEffect` over {@link Yaml.schema}
541
+ * would; the target's decoding/encoding service requirements flow through.
542
+ *
543
+ * @remarks
544
+ * Schema-producing: each call composes a fresh schema and derives both
545
+ * directions from it. Bind the result to a `const` — that single binding is
546
+ * the point.
547
+ *
548
+ * @example
549
+ * ```ts
550
+ * import { Yaml } from "@effected/yaml";
551
+ * import { Effect, Schema } from "effect";
552
+ *
553
+ * const Config = Schema.Struct({ port: Schema.Number });
554
+ * const config = Yaml.bind(Config);
555
+ *
556
+ * const program = Effect.gen(function* () {
557
+ * const value = yield* config.decode("port: 3000");
558
+ * const text = yield* config.encode(value);
559
+ * return [value, text] as const;
560
+ * });
561
+ * ```
562
+ *
563
+ * @param target - The domain schema decoded values must satisfy.
564
+ * @returns A {@link YamlBoundCodec} carrying the composed schema and its
565
+ * two pre-bound directions.
566
+ */
567
+ static bind(target) {
568
+ const schema = Yaml.schema(target);
569
+ return {
570
+ schema,
571
+ decode: Schema.decodeEffect(schema),
572
+ encode: Schema.encodeEffect(schema)
573
+ };
574
+ }
519
575
  };
520
576
  /**
521
577
  * Parse for `equals`/`equalsValue`: any recorded error — fatal or not — or a
package/YamlDocument.js CHANGED
@@ -91,6 +91,17 @@ var YamlDocument = class YamlDocument extends Schema.Class("YamlDocument")({
91
91
  * deeper than the stringifier's recursion budget (`NestingDepthExceeded`)
92
92
  * — both surface through the typed error channel rather than as an
93
93
  * unhandled stack-overflow defect.
94
+ *
95
+ * @remarks
96
+ * `YamlStringifyOptions.lineWidth` is not honored here: column-based
97
+ * scalar folding exists only on the value path, through the entry points
98
+ * that accept stringify options ({@link Yaml.stringify} and
99
+ * {@link Yaml.stringifySync}). The
100
+ * document/node path threads `lineWidth` into its render context but
101
+ * never reads it, so long scalars are emitted unfolded regardless of the
102
+ * option. Callers that need folding should render the plain value
103
+ * instead — `Yaml.stringify(doc.toValue(), options)` — at the cost of
104
+ * the document-level framing and styles this path preserves.
94
105
  */
95
106
  stringify(options) {
96
107
  return Effect.try({
package/YamlEdit.js CHANGED
@@ -31,10 +31,16 @@ var YamlEdit = class extends Schema.Class("YamlEdit")({
31
31
  /**
32
32
  * Apply `edits` to `text`, producing a new string. Edits are applied in
33
33
  * reverse-offset order so earlier offsets stay valid; the input `edits`
34
- * array is not mutated. Pure and total.
34
+ * array is not mutated. Overlapping edits are a programmer error and throw
35
+ * as a defect — `YamlFormat` never produces them.
35
36
  */
36
37
  static applyAll(text, edits) {
37
38
  const sorted = [...edits].sort((a, b) => b.offset - a.offset);
39
+ for (let i = 0; i + 1 < sorted.length; i++) {
40
+ const upper = sorted[i];
41
+ const lower = sorted[i + 1];
42
+ if (lower.offset + lower.length > upper.offset) throw new Error(`YamlEdit.applyAll received overlapping edits at offsets ${lower.offset} and ${upper.offset} — overlapping edits are a programmer error`);
43
+ }
38
44
  let result = text;
39
45
  for (const edit of sorted) result = result.substring(0, edit.offset) + edit.content + result.substring(edit.offset + edit.length);
40
46
  return result;
package/index.d.ts CHANGED
@@ -149,6 +149,15 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
149
149
  * Column at which to fold long scalars. Default `0` (and any value `<= 0`)
150
150
  * never wraps; a positive value folds plain, double-quoted and block-folded
151
151
  * (`>`) scalars at approximately that column, never block-literal (`|`).
152
+ *
153
+ * Takes effect only through {@link Yaml.stringify} and
154
+ * {@link Yaml.stringifySync} — the two entry points that accept these
155
+ * options on the value path. The schema factories ({@link Yaml.fromString},
156
+ * {@link Yaml.schema}, {@link Yaml.YamlFromString}) encode with default
157
+ * stringify options (`lineWidth` `0`), so their output never folds. The
158
+ * document/node path — `YamlDocument#stringify` and the `YamlFormat`
159
+ * helpers built on it — threads the field into its render context but
160
+ * never reads it, so it is inert there.
152
161
  */
153
162
  readonly lineWidth: Schema.optionalKey<Schema.Number>;
154
163
  readonly defaultScalarStyle: Schema.optionalKey<Schema.Literals<readonly ["plain", "single-quoted", "double-quoted", "block-literal", "block-folded"]>>;
@@ -170,7 +179,9 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
170
179
  * no-fold behavior; a positive value folds long plain, double-quoted and
171
180
  * block-folded (`>`) scalars at approximately that column, inserting only
172
181
  * semantically transparent line breaks. Block-literal (`|`) content is never
173
- * folded — literal blocks preserve their bytes by definition.
182
+ * folded — literal blocks preserve their bytes by definition. Folding is a
183
+ * value-path feature only: `YamlDocument#stringify` and the `YamlFormat`
184
+ * helpers accept these options but do not fold (see `lineWidth`).
174
185
  *
175
186
  * `indentSequences` controls the presentation of block sequences nested under
176
187
  * a mapping key: `false` (the default) emits them at the key's column — the
@@ -226,6 +237,22 @@ declare const YamlStringifyError_base: Schema.Class<YamlStringifyError, Schema.T
226
237
  declare class YamlStringifyError extends YamlStringifyError_base {
227
238
  get message(): string;
228
239
  }
240
+ /**
241
+ * A domain codec pre-bound to its two directions, returned by
242
+ * {@link Yaml.bind}: the composed `schema` (what {@link Yaml.schema} returns)
243
+ * plus `decode` and `encode` functions derived from it once, so callers need
244
+ * no generic `Schema` machinery at the use site.
245
+ *
246
+ * @public
247
+ */
248
+ interface YamlBoundCodec<T, RD = never, RE = never> {
249
+ /** The composed codec decoding a YAML `string` straight into `T`. */
250
+ readonly schema: Schema.Codec<T, string, RD, RE>;
251
+ /** Decode a single-document YAML string into a validated `T`. */
252
+ readonly decode: (text: string) => Effect.Effect<T, Schema.SchemaError, RD>;
253
+ /** Encode a `T` back to YAML text with default stringify options. */
254
+ readonly encode: (value: T) => Effect.Effect<string, Schema.SchemaError, RE>;
255
+ }
229
256
  /**
230
257
  * Static entry points for YAML parsing, stringification, comment stripping,
231
258
  * semantic equality and the schema factories. Not instantiable.
@@ -284,7 +311,7 @@ declare class Yaml {
284
311
  */
285
312
  static readonly stringify: (value: unknown, options?: YamlStringifyOptions | undefined) => Effect.Effect<string, YamlStringifyError, never>;
286
313
  /**
287
- * Synchronous single-document parse, returning a {@link Result} instead of
314
+ * Synchronous single-document parse, returning a `Result` instead of
288
315
  * an `Effect`. A pure escape hatch for config-time callers that cannot
289
316
  * `await` an Effect (a `vitest.config.ts` is the motivating case): it runs
290
317
  * the same engine as {@link Yaml.parse} inline.
@@ -311,7 +338,7 @@ declare class Yaml {
311
338
  */
312
339
  static parseSync(text: string, options?: YamlParseOptions): Result.Result<unknown, YamlParseError>;
313
340
  /**
314
- * Synchronous stringify, returning a {@link Result} instead of an `Effect`.
341
+ * Synchronous stringify, returning a `Result` instead of an `Effect`.
315
342
  * The pure counterpart to {@link Yaml.stringify} for config-time callers
316
343
  * that cannot `await`.
317
344
  *
@@ -393,6 +420,44 @@ declare class Yaml {
393
420
  * {@link Yaml.fromString}).
394
421
  */
395
422
  static schema<T, E, RD = never, RE = never>(target: Schema.Codec<T, E, RD, RE>, options?: YamlParseOptions): Schema.Codec<T, string, RD, RE>;
423
+ /**
424
+ * Bind a target schema to the YAML codec once, yielding the composed
425
+ * schema plus pre-derived `decode`/`encode` directions — the
426
+ * {@link Yaml.schema} composition without the generic `Schema` machinery
427
+ * at every use site. Binds the plain single-document form only: default
428
+ * {@link YamlParseOptions} on decode, default stringify options on encode;
429
+ * for multi-document streams compose over {@link Yaml.allFromString}
430
+ * directly.
431
+ *
432
+ * Both directions fail with `Schema.SchemaError`, exactly as
433
+ * `Schema.decodeEffect`/`Schema.encodeEffect` over {@link Yaml.schema}
434
+ * would; the target's decoding/encoding service requirements flow through.
435
+ *
436
+ * @remarks
437
+ * Schema-producing: each call composes a fresh schema and derives both
438
+ * directions from it. Bind the result to a `const` — that single binding is
439
+ * the point.
440
+ *
441
+ * @example
442
+ * ```ts
443
+ * import { Yaml } from "@effected/yaml";
444
+ * import { Effect, Schema } from "effect";
445
+ *
446
+ * const Config = Schema.Struct({ port: Schema.Number });
447
+ * const config = Yaml.bind(Config);
448
+ *
449
+ * const program = Effect.gen(function* () {
450
+ * const value = yield* config.decode("port: 3000");
451
+ * const text = yield* config.encode(value);
452
+ * return [value, text] as const;
453
+ * });
454
+ * ```
455
+ *
456
+ * @param target - The domain schema decoded values must satisfy.
457
+ * @returns A {@link YamlBoundCodec} carrying the composed schema and its
458
+ * two pre-bound directions.
459
+ */
460
+ static bind<T, E, RD = never, RE = never>(target: Schema.Codec<T, E, RD, RE>): YamlBoundCodec<T, RD, RE>;
396
461
  }
397
462
  //#endregion
398
463
  //#region src/YamlEdit.d.ts
@@ -442,7 +507,8 @@ declare class YamlEdit extends YamlEdit_base {
442
507
  /**
443
508
  * Apply `edits` to `text`, producing a new string. Edits are applied in
444
509
  * reverse-offset order so earlier offsets stay valid; the input `edits`
445
- * array is not mutated. Pure and total.
510
+ * array is not mutated. Overlapping edits are a programmer error and throw
511
+ * as a defect — `YamlFormat` never produces them.
446
512
  */
447
513
  static applyAll(text: string, edits: ReadonlyArray<YamlEdit>): string;
448
514
  }
@@ -720,6 +786,17 @@ declare class YamlDocument extends YamlDocument_base {
720
786
  * deeper than the stringifier's recursion budget (`NestingDepthExceeded`)
721
787
  * — both surface through the typed error channel rather than as an
722
788
  * unhandled stack-overflow defect.
789
+ *
790
+ * @remarks
791
+ * `YamlStringifyOptions.lineWidth` is not honored here: column-based
792
+ * scalar folding exists only on the value path, through the entry points
793
+ * that accept stringify options ({@link Yaml.stringify} and
794
+ * {@link Yaml.stringifySync}). The
795
+ * document/node path threads `lineWidth` into its render context but
796
+ * never reads it, so long scalars are emitted unfolded regardless of the
797
+ * option. Callers that need folding should render the plain value
798
+ * instead — `Yaml.stringify(doc.toValue(), options)` — at the cost of
799
+ * the document-level framing and styles this path preserves.
723
800
  */
724
801
  stringify(options?: YamlStringifyOptions): Effect.Effect<string, YamlStringifyError>;
725
802
  /**
@@ -1444,5 +1521,5 @@ declare class YamlVisitor {
1444
1521
  static visit(text: string, options?: YamlParseOptions): Stream.Stream<YamlVisitorEvent>;
1445
1522
  }
1446
1523
  //#endregion
1447
- export { CollectionStyle, ScalarChomp, ScalarStyle, Yaml, YamlAlias, YamlComposerErrorCode, YamlDiagnostic, YamlDirective, YamlDocument, YamlEdit, YamlErrorCode, YamlFormat, YamlFormattingOptions, YamlLexErrorCode, YamlMap, YamlModificationError, YamlModifyErrorCode, YamlNode, YamlPair, YamlParseError, YamlParseErrorCode, YamlParseOptions, type YamlPath, YamlRange, type YamlRangeLike, YamlScalar, type YamlSegment, YamlSeq, YamlStringifyError, YamlStringifyErrorCode, YamlStringifyOptions, YamlVisitor, YamlVisitorEvent };
1524
+ export { CollectionStyle, ScalarChomp, ScalarStyle, Yaml, YamlAlias, type YamlBoundCodec, YamlComposerErrorCode, YamlDiagnostic, YamlDirective, YamlDocument, YamlEdit, YamlErrorCode, YamlFormat, YamlFormattingOptions, YamlLexErrorCode, YamlMap, YamlModificationError, YamlModifyErrorCode, YamlNode, YamlPair, YamlParseError, YamlParseErrorCode, YamlParseOptions, type YamlPath, YamlRange, type YamlRangeLike, YamlScalar, type YamlSegment, YamlSeq, YamlStringifyError, YamlStringifyErrorCode, YamlStringifyOptions, YamlVisitor, YamlVisitorEvent };
1448
1525
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/yaml",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "Zero-dependency YAML parsing, editing and formatting as Effect schemas.",
6
6
  "keywords": [
@@ -34,12 +34,13 @@
34
34
  "exports": {
35
35
  ".": {
36
36
  "types": "./index.d.ts",
37
- "import": "./index.js"
37
+ "import": "./index.js",
38
+ "default": "./index.js"
38
39
  },
39
40
  "./package.json": "./package.json"
40
41
  },
41
42
  "peerDependencies": {
42
- "effect": "4.0.0-beta.98"
43
+ "effect": "4.0.0-beta.99"
43
44
  },
44
45
  "engines": {
45
46
  "node": ">=24.11.0"
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.10"
8
+ "packageVersion": "7.58.11"
9
9
  }
10
10
  ]
11
11
  }