@effected/yaml 0.1.0 → 0.2.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 +2 -0
- package/Yaml.js +37 -1
- package/YamlDocument.js +1 -0
- package/YamlFormat.js +20 -3
- package/index.d.ts +56 -4
- package/internal/stringifier.js +6 -2
- package/package.json +1 -1
- package/tsdoc-metadata.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,8 @@ pnpm add @effected/yaml effect
|
|
|
39
39
|
|
|
40
40
|
Requires Node.js >=24.11.0. `effect` v4 is a peer dependency; the package itself adds no other runtime dependencies.
|
|
41
41
|
|
|
42
|
+
All `@effected/*` packages are ESM-only: the exports maps publish only `import` conditions, so `require()` — including tools that resolve in CJS mode — fails with Node's `ERR_PACKAGE_PATH_NOT_EXPORTED` rather than loading a CJS build that does not exist. Import from an ES module.
|
|
43
|
+
|
|
42
44
|
## Quick start
|
|
43
45
|
|
|
44
46
|
Compose your schema with `Yaml.schema` to decode YAML straight into a validated domain value:
|
package/Yaml.js
CHANGED
|
@@ -13,6 +13,18 @@ import { Effect, Option, Schema, SchemaIssue, SchemaTransformation } from "effec
|
|
|
13
13
|
* denial-of-service guard) and `uniqueKeys` `true` (duplicate mapping keys
|
|
14
14
|
* are errors).
|
|
15
15
|
*
|
|
16
|
+
* Construct with the validated `YamlParseOptions.make({ ... })` static — the
|
|
17
|
+
* kit convention (never `new`). Call sites that take a `YamlParseOptions`
|
|
18
|
+
* also accept a structurally-matching plain literal.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { Yaml, YamlParseOptions } from "@effected/yaml";
|
|
23
|
+
*
|
|
24
|
+
* const options = YamlParseOptions.make({ maxAliasCount: 50 });
|
|
25
|
+
* const parsed = Yaml.parse("a: 1", options);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
16
28
|
* @public
|
|
17
29
|
*/
|
|
18
30
|
var YamlParseOptions = class extends Schema.Class("YamlParseOptions")({
|
|
@@ -24,7 +36,29 @@ var YamlParseOptions = class extends Schema.Class("YamlParseOptions")({
|
|
|
24
36
|
* Options controlling stringify behavior. All fields are omissible; absent
|
|
25
37
|
* fields resolve to `indent` `2`, `lineWidth` `80`, `defaultScalarStyle`
|
|
26
38
|
* `"plain"`, `defaultCollectionStyle` `"block"`, `sortKeys` `false`,
|
|
27
|
-
* `finalNewline` `true` and `forceDefaultStyles`
|
|
39
|
+
* `indentSequences` `false`, `finalNewline` `true` and `forceDefaultStyles`
|
|
40
|
+
* `false`.
|
|
41
|
+
*
|
|
42
|
+
* `indentSequences` controls the presentation of block sequences nested under
|
|
43
|
+
* a mapping key: `false` (the default) emits them at the key's column — the
|
|
44
|
+
* kit's byte-compatible legacy form — while `true` indents them one level,
|
|
45
|
+
* matching the `yaml` npm package's default output. Top-level sequences stay
|
|
46
|
+
* at column zero in both modes.
|
|
47
|
+
*
|
|
48
|
+
* Construct with the validated `YamlStringifyOptions.make({ ... })` static —
|
|
49
|
+
* the kit convention (never `new`). Call sites that take a
|
|
50
|
+
* `YamlStringifyOptions` also accept a structurally-matching plain literal.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { Yaml, YamlStringifyOptions } from "@effected/yaml";
|
|
55
|
+
*
|
|
56
|
+
* const options = YamlStringifyOptions.make({ indentSequences: true });
|
|
57
|
+
* const yaml = Yaml.stringify({ key: ["a", "b"] }, options);
|
|
58
|
+
* // key:
|
|
59
|
+
* // - a
|
|
60
|
+
* // - b
|
|
61
|
+
* ```
|
|
28
62
|
*
|
|
29
63
|
* @public
|
|
30
64
|
*/
|
|
@@ -34,6 +68,7 @@ var YamlStringifyOptions = class extends Schema.Class("YamlStringifyOptions")({
|
|
|
34
68
|
defaultScalarStyle: Schema.optionalKey(ScalarStyle),
|
|
35
69
|
defaultCollectionStyle: Schema.optionalKey(CollectionStyle),
|
|
36
70
|
sortKeys: Schema.optionalKey(Schema.Boolean),
|
|
71
|
+
indentSequences: Schema.optionalKey(Schema.Boolean),
|
|
37
72
|
finalNewline: Schema.optionalKey(Schema.Boolean),
|
|
38
73
|
forceDefaultStyles: Schema.optionalKey(Schema.Boolean)
|
|
39
74
|
}) {};
|
|
@@ -82,6 +117,7 @@ const toStringifyInput = (options) => options === void 0 ? {} : {
|
|
|
82
117
|
defaultScalarStyle: options.defaultScalarStyle,
|
|
83
118
|
defaultCollectionStyle: options.defaultCollectionStyle,
|
|
84
119
|
sortKeys: options.sortKeys,
|
|
120
|
+
indentSequences: options.indentSequences,
|
|
85
121
|
finalNewline: options.finalNewline,
|
|
86
122
|
forceDefaultStyles: options.forceDefaultStyles
|
|
87
123
|
};
|
package/YamlDocument.js
CHANGED
|
@@ -144,6 +144,7 @@ const toStringifyInput = (options) => options === void 0 ? {} : {
|
|
|
144
144
|
defaultScalarStyle: options.defaultScalarStyle,
|
|
145
145
|
defaultCollectionStyle: options.defaultCollectionStyle,
|
|
146
146
|
sortKeys: options.sortKeys,
|
|
147
|
+
indentSequences: options.indentSequences,
|
|
147
148
|
finalNewline: options.finalNewline,
|
|
148
149
|
forceDefaultStyles: options.forceDefaultStyles
|
|
149
150
|
};
|
package/YamlFormat.js
CHANGED
|
@@ -11,9 +11,25 @@ import { Effect, Schema } from "effect";
|
|
|
11
11
|
//#region src/YamlFormat.ts
|
|
12
12
|
/**
|
|
13
13
|
* Options controlling formatting behavior: every {@link YamlStringifyOptions}
|
|
14
|
-
* field (derived, not hand-duplicated
|
|
15
|
-
* `true`) and `range` (restrict edits to a
|
|
16
|
-
* remarks on the `range` parameter vs. this
|
|
14
|
+
* field (derived, not hand-duplicated — including `indentSequences`) plus
|
|
15
|
+
* `preserveComments` (default `true`) and `range` (restrict edits to a
|
|
16
|
+
* region; see the module-level remarks on the `range` parameter vs. this
|
|
17
|
+
* field).
|
|
18
|
+
*
|
|
19
|
+
* Construct with the validated `YamlFormattingOptions.make({ ... })` static —
|
|
20
|
+
* the kit convention (never `new`). Call sites that take a
|
|
21
|
+
* `YamlFormattingOptions` also accept a structurally-matching plain literal.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { YamlFormat, YamlFormattingOptions } from "@effected/yaml";
|
|
26
|
+
*
|
|
27
|
+
* const options = YamlFormattingOptions.make({ indentSequences: true });
|
|
28
|
+
* const formatted = YamlFormat.formatToString("key:\n- a\n- b\n", undefined, options);
|
|
29
|
+
* // key:
|
|
30
|
+
* // - a
|
|
31
|
+
* // - b
|
|
32
|
+
* ```
|
|
17
33
|
*
|
|
18
34
|
* @public
|
|
19
35
|
*/
|
|
@@ -61,6 +77,7 @@ const toStringifyInput = (options) => options === void 0 ? {} : {
|
|
|
61
77
|
defaultScalarStyle: options.defaultScalarStyle,
|
|
62
78
|
defaultCollectionStyle: options.defaultCollectionStyle,
|
|
63
79
|
sortKeys: options.sortKeys,
|
|
80
|
+
indentSequences: options.indentSequences,
|
|
64
81
|
finalNewline: options.finalNewline,
|
|
65
82
|
forceDefaultStyles: options.forceDefaultStyles
|
|
66
83
|
};
|
package/index.d.ts
CHANGED
|
@@ -128,6 +128,18 @@ declare const YamlParseOptions_base: Schema.Class<YamlParseOptions, Schema.Struc
|
|
|
128
128
|
* denial-of-service guard) and `uniqueKeys` `true` (duplicate mapping keys
|
|
129
129
|
* are errors).
|
|
130
130
|
*
|
|
131
|
+
* Construct with the validated `YamlParseOptions.make({ ... })` static — the
|
|
132
|
+
* kit convention (never `new`). Call sites that take a `YamlParseOptions`
|
|
133
|
+
* also accept a structurally-matching plain literal.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { Yaml, YamlParseOptions } from "@effected/yaml";
|
|
138
|
+
*
|
|
139
|
+
* const options = YamlParseOptions.make({ maxAliasCount: 50 });
|
|
140
|
+
* const parsed = Yaml.parse("a: 1", options);
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
131
143
|
* @public
|
|
132
144
|
*/
|
|
133
145
|
declare class YamlParseOptions extends YamlParseOptions_base {}
|
|
@@ -137,6 +149,7 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
|
|
|
137
149
|
readonly defaultScalarStyle: Schema.optionalKey<Schema.Literals<readonly ["plain", "single-quoted", "double-quoted", "block-literal", "block-folded"]>>;
|
|
138
150
|
readonly defaultCollectionStyle: Schema.optionalKey<Schema.Literals<readonly ["block", "flow"]>>;
|
|
139
151
|
readonly sortKeys: Schema.optionalKey<Schema.Boolean>;
|
|
152
|
+
readonly indentSequences: Schema.optionalKey<Schema.Boolean>;
|
|
140
153
|
readonly finalNewline: Schema.optionalKey<Schema.Boolean>;
|
|
141
154
|
readonly forceDefaultStyles: Schema.optionalKey<Schema.Boolean>;
|
|
142
155
|
}>, {}>;
|
|
@@ -144,7 +157,29 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
|
|
|
144
157
|
* Options controlling stringify behavior. All fields are omissible; absent
|
|
145
158
|
* fields resolve to `indent` `2`, `lineWidth` `80`, `defaultScalarStyle`
|
|
146
159
|
* `"plain"`, `defaultCollectionStyle` `"block"`, `sortKeys` `false`,
|
|
147
|
-
* `finalNewline` `true` and `forceDefaultStyles`
|
|
160
|
+
* `indentSequences` `false`, `finalNewline` `true` and `forceDefaultStyles`
|
|
161
|
+
* `false`.
|
|
162
|
+
*
|
|
163
|
+
* `indentSequences` controls the presentation of block sequences nested under
|
|
164
|
+
* a mapping key: `false` (the default) emits them at the key's column — the
|
|
165
|
+
* kit's byte-compatible legacy form — while `true` indents them one level,
|
|
166
|
+
* matching the `yaml` npm package's default output. Top-level sequences stay
|
|
167
|
+
* at column zero in both modes.
|
|
168
|
+
*
|
|
169
|
+
* Construct with the validated `YamlStringifyOptions.make({ ... })` static —
|
|
170
|
+
* the kit convention (never `new`). Call sites that take a
|
|
171
|
+
* `YamlStringifyOptions` also accept a structurally-matching plain literal.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { Yaml, YamlStringifyOptions } from "@effected/yaml";
|
|
176
|
+
*
|
|
177
|
+
* const options = YamlStringifyOptions.make({ indentSequences: true });
|
|
178
|
+
* const yaml = Yaml.stringify({ key: ["a", "b"] }, options);
|
|
179
|
+
* // key:
|
|
180
|
+
* // - a
|
|
181
|
+
* // - b
|
|
182
|
+
* ```
|
|
148
183
|
*
|
|
149
184
|
* @public
|
|
150
185
|
*/
|
|
@@ -648,6 +683,7 @@ declare const YamlFormattingOptions_base: Schema.Class<YamlFormattingOptions, Sc
|
|
|
648
683
|
readonly defaultScalarStyle: Schema.optionalKey<Schema.Literals<readonly ["plain", "single-quoted", "double-quoted", "block-literal", "block-folded"]>>;
|
|
649
684
|
readonly defaultCollectionStyle: Schema.optionalKey<Schema.Literals<readonly ["block", "flow"]>>;
|
|
650
685
|
readonly sortKeys: Schema.optionalKey<Schema.Boolean>;
|
|
686
|
+
readonly indentSequences: Schema.optionalKey<Schema.Boolean>;
|
|
651
687
|
readonly finalNewline: Schema.optionalKey<Schema.Boolean>;
|
|
652
688
|
readonly forceDefaultStyles: Schema.optionalKey<Schema.Boolean>;
|
|
653
689
|
readonly preserveComments: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -655,9 +691,25 @@ declare const YamlFormattingOptions_base: Schema.Class<YamlFormattingOptions, Sc
|
|
|
655
691
|
}>, {}>;
|
|
656
692
|
/**
|
|
657
693
|
* Options controlling formatting behavior: every {@link YamlStringifyOptions}
|
|
658
|
-
* field (derived, not hand-duplicated
|
|
659
|
-
* `true`) and `range` (restrict edits to a
|
|
660
|
-
* remarks on the `range` parameter vs. this
|
|
694
|
+
* field (derived, not hand-duplicated — including `indentSequences`) plus
|
|
695
|
+
* `preserveComments` (default `true`) and `range` (restrict edits to a
|
|
696
|
+
* region; see the module-level remarks on the `range` parameter vs. this
|
|
697
|
+
* field).
|
|
698
|
+
*
|
|
699
|
+
* Construct with the validated `YamlFormattingOptions.make({ ... })` static —
|
|
700
|
+
* the kit convention (never `new`). Call sites that take a
|
|
701
|
+
* `YamlFormattingOptions` also accept a structurally-matching plain literal.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```ts
|
|
705
|
+
* import { YamlFormat, YamlFormattingOptions } from "@effected/yaml";
|
|
706
|
+
*
|
|
707
|
+
* const options = YamlFormattingOptions.make({ indentSequences: true });
|
|
708
|
+
* const formatted = YamlFormat.formatToString("key:\n- a\n- b\n", undefined, options);
|
|
709
|
+
* // key:
|
|
710
|
+
* // - a
|
|
711
|
+
* // - b
|
|
712
|
+
* ```
|
|
661
713
|
*
|
|
662
714
|
* @public
|
|
663
715
|
*/
|
package/internal/stringifier.js
CHANGED
|
@@ -256,6 +256,7 @@ function createContext(options) {
|
|
|
256
256
|
defaultScalarStyle: options?.defaultScalarStyle ?? "plain",
|
|
257
257
|
defaultCollectionStyle: options?.defaultCollectionStyle ?? "block",
|
|
258
258
|
sortKeys: options?.sortKeys ?? false,
|
|
259
|
+
indentSequences: options?.indentSequences ?? false,
|
|
259
260
|
forceDefaultStyles: options?.forceDefaultStyles ?? false,
|
|
260
261
|
seen: /* @__PURE__ */ new Set()
|
|
261
262
|
};
|
|
@@ -354,7 +355,7 @@ function stringifyObjectLines(obj, ctx, depth) {
|
|
|
354
355
|
for (let i = 1; i < valLines.length; i++) lines.push(valLines[i]);
|
|
355
356
|
} else if (Array.isArray(val) && val.length > 0) {
|
|
356
357
|
lines.push(`${keyStr}:`);
|
|
357
|
-
for (const vl of valLines) lines.push(vl);
|
|
358
|
+
for (const vl of valLines) lines.push(ctx.indentSequences && vl !== "" ? `${pad}${vl}` : vl);
|
|
358
359
|
} else {
|
|
359
360
|
lines.push(`${keyStr}:`);
|
|
360
361
|
for (const vl of valLines) lines.push(`${pad}${vl}`);
|
|
@@ -619,7 +620,10 @@ function stringifyMapNodeLines(node, ctx, depth) {
|
|
|
619
620
|
const seqMeta = buildMetadataPrefix(valNode.tag, valNode.anchor);
|
|
620
621
|
const startIdx = seqMeta ? 1 : 0;
|
|
621
622
|
lines.push(seqMeta ? `${keyStr}${sep} ${seqMeta}` : `${keyStr}${sep}`);
|
|
622
|
-
for (let i = startIdx; i < valLines.length; i++)
|
|
623
|
+
for (let i = startIdx; i < valLines.length; i++) {
|
|
624
|
+
const vl = valLines[i];
|
|
625
|
+
lines.push(ctx.indentSequences && vl !== "" ? `${pad}${vl}` : vl);
|
|
626
|
+
}
|
|
623
627
|
} else if (valNode instanceof YamlMap && valNode.items.length > 0 && (ctx.forceDefaultStyles ? ctx.defaultCollectionStyle : valNode.style ?? ctx.defaultCollectionStyle) === "block") {
|
|
624
628
|
const mapMeta = buildMetadataPrefix(valNode.tag, valNode.anchor);
|
|
625
629
|
const startIdx = mapMeta ? 1 : 0;
|
package/package.json
CHANGED