@effected/yaml 0.5.1 → 0.6.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.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/index.d.ts +35 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -73,6 +73,17 @@ Effect.runPromise(Yaml.stringify({ port: 3000, hosts: ["a", "b"] })).then(consol
73
73
  // - b
74
74
  ```
75
75
 
76
+ Both directions have a synchronous counterpart that returns a `Result` for callers that cannot await an Effect, a `vitest.config.ts` being the motivating case. `Yaml.parse` is defined in terms of `Yaml.parseResult`, so the two forms cannot disagree about what a document means:
77
+
78
+ ```ts
79
+ import { Yaml } from "@effected/yaml";
80
+ import { Result } from "effect";
81
+
82
+ const result = Yaml.parseResult("port: 3000 # dev server");
83
+ console.log(Result.isSuccess(result) ? result.success : result.failure);
84
+ // { port: 3000 }
85
+ ```
86
+
76
87
  ## Hostile input fails typed
77
88
 
78
89
  An alias bomb — nested anchors whose expansion multiplies at every level — is bounded by an expansion budget and surfaces as a `YamlParseError`, not as an out-of-memory kill:
@@ -99,6 +110,7 @@ Collection nesting past the depth cap behaves the same way, yielding a `NestingD
99
110
 
100
111
  - `Yaml.parse` / `Yaml.parseAll` — error-recovery parsing of a single document or a `---`-separated stream into plain values, resolving anchors and aliases and aggregating every diagnostic into one `YamlParseError`.
101
112
  - `Yaml.stringify` — serialize a plain value back to YAML, failing typed with `YamlStringifyError` on circular references or on excessively deep nesting.
113
+ - `Yaml.parseResult` / `Yaml.stringifyResult` — the pure synchronous counterparts, returning a `Result` instead of an `Effect` for config-time callers that cannot await; each runs the same engine call as its `Effect` variant, so the two forms cannot diverge, and a fatal diagnostic, a duplicate key, an alias bomb or a circular reference still fails typed rather than throwing.
102
114
  - `Yaml.stripComments` — quote-aware comment removal that keeps line numbers stable, or every byte offset stable when given a replacement character.
103
115
  - `Yaml.equals` / `Yaml.equalsValue` — semantic equality that ignores comments, whitespace, formatting and mapping key order while keeping sequence order significant.
104
116
  - `Yaml.schema` / `Yaml.fromString` / `Yaml.YamlFromString` / `Yaml.allFromString` — string→domain schema factories that decode a single document or a whole stream into a validated Effect `Schema` value.
package/index.d.ts CHANGED
@@ -687,6 +687,35 @@ declare class YamlAlias extends YamlAlias_base {
687
687
  /** See `YamlScalar.toValue`. Pure and total. */
688
688
  toValue(anchors?: Map<string, YamlNode>): unknown;
689
689
  }
690
+ /**
691
+ * The encoded (plain-object) form of a {@link YamlScalar} — the class fields
692
+ * without the instance methods. Named so the recursive {@link (YamlNode:variable)}
693
+ * codec can state its encoded side without a circular type annotation.
694
+ *
695
+ * @public
696
+ */
697
+ interface YamlScalarEncoded extends Schema.Codec.Encoded<typeof YamlScalar> {}
698
+ /**
699
+ * The encoded (plain-object) form of a {@link YamlMap}. See
700
+ * {@link YamlScalarEncoded} for why the encoded forms are named interfaces.
701
+ *
702
+ * @public
703
+ */
704
+ interface YamlMapEncoded extends Schema.Codec.Encoded<typeof YamlMap> {}
705
+ /**
706
+ * The encoded (plain-object) form of a {@link YamlSeq}. See
707
+ * {@link YamlScalarEncoded} for why the encoded forms are named interfaces.
708
+ *
709
+ * @public
710
+ */
711
+ interface YamlSeqEncoded extends Schema.Codec.Encoded<typeof YamlSeq> {}
712
+ /**
713
+ * The encoded (plain-object) form of a {@link YamlAlias}. See
714
+ * {@link YamlScalarEncoded} for why the encoded forms are named interfaces.
715
+ *
716
+ * @public
717
+ */
718
+ interface YamlAliasEncoded extends Schema.Codec.Encoded<typeof YamlAlias> {}
690
719
  /**
691
720
  * A discriminated-union schema covering all four YAML AST value node types:
692
721
  * {@link YamlScalar}, {@link YamlMap}, {@link YamlSeq} and {@link YamlAlias}.
@@ -701,7 +730,7 @@ declare class YamlAlias extends YamlAlias_base {
701
730
  *
702
731
  * @public
703
732
  */
704
- declare const YamlNode: Schema.Schema<YamlScalar | YamlMap | YamlSeq | YamlAlias>;
733
+ declare const YamlNode: Schema.Codec<YamlScalar | YamlMap | YamlSeq | YamlAlias, YamlScalarEncoded | YamlMapEncoded | YamlSeqEncoded | YamlAliasEncoded>;
705
734
  /**
706
735
  * The union of all YAML AST value node types.
707
736
  *
@@ -709,8 +738,8 @@ declare const YamlNode: Schema.Schema<YamlScalar | YamlMap | YamlSeq | YamlAlias
709
738
  */
710
739
  type YamlNode = YamlScalar | YamlMap | YamlSeq | YamlAlias;
711
740
  declare const YamlPair_base: Schema.Class<YamlPair, Schema.TaggedStruct<"YamlPair", {
712
- readonly key: Schema.suspend<Schema.Schema<YamlNode>>;
713
- readonly value: Schema.NullOr<Schema.suspend<Schema.Schema<YamlNode>>>;
741
+ readonly key: Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>;
742
+ readonly value: Schema.NullOr<Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>>;
714
743
  readonly comment: Schema.optionalKey<Schema.String>;
715
744
  }>, {}>;
716
745
  /**
@@ -721,7 +750,7 @@ declare const YamlPair_base: Schema.Class<YamlPair, Schema.TaggedStruct<"YamlPai
721
750
  */
722
751
  declare class YamlPair extends YamlPair_base {}
723
752
  declare const YamlMap_base: Schema.Class<YamlMap, Schema.TaggedStruct<"YamlMap", {
724
- readonly items: Schema.$Array<Schema.suspend<Schema.Schema<YamlPair>>>;
753
+ readonly items: Schema.$Array<Schema.suspend<typeof YamlPair>>;
725
754
  readonly tag: Schema.optionalKey<Schema.String>;
726
755
  readonly anchor: Schema.optionalKey<Schema.String>;
727
756
  readonly style: Schema.Literals<readonly ["block", "flow"]>;
@@ -751,7 +780,7 @@ declare class YamlMap extends YamlMap_base {
751
780
  toValue(anchors?: Map<string, YamlNode>): unknown;
752
781
  }
753
782
  declare const YamlSeq_base: Schema.Class<YamlSeq, Schema.TaggedStruct<"YamlSeq", {
754
- readonly items: Schema.$Array<Schema.suspend<Schema.Schema<YamlNode>>>;
783
+ readonly items: Schema.$Array<Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>>;
755
784
  readonly tag: Schema.optionalKey<Schema.String>;
756
785
  readonly anchor: Schema.optionalKey<Schema.String>;
757
786
  readonly style: Schema.Literals<readonly ["block", "flow"]>;
@@ -1588,5 +1617,5 @@ declare class YamlVisitor {
1588
1617
  static visit(text: string, options?: YamlParseOptions): Stream.Stream<YamlVisitorEvent>;
1589
1618
  }
1590
1619
  //#endregion
1591
- export { CollectionStyle, QuoteStyle, 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 };
1620
+ export { CollectionStyle, QuoteStyle, ScalarChomp, ScalarStyle, Yaml, YamlAlias, type YamlAliasEncoded, type YamlBoundCodec, YamlComposerErrorCode, YamlDiagnostic, YamlDirective, YamlDocument, YamlEdit, YamlErrorCode, YamlFormat, YamlFormattingOptions, YamlLexErrorCode, YamlMap, type YamlMapEncoded, YamlModificationError, YamlModifyErrorCode, YamlNode, YamlPair, YamlParseError, YamlParseErrorCode, YamlParseOptions, type YamlPath, YamlRange, type YamlRangeLike, YamlScalar, type YamlScalarEncoded, type YamlSegment, YamlSeq, type YamlSeqEncoded, YamlStringifyError, YamlStringifyErrorCode, YamlStringifyOptions, YamlVisitor, YamlVisitorEvent };
1592
1621
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/yaml",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
5
  "description": "Zero-dependency YAML parsing, editing and formatting as Effect schemas.",
6
6
  "keywords": [