@effected/yaml 0.6.0 → 0.6.1

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
@@ -106,7 +106,7 @@ function formatDocument(text, options) {
106
106
  const doc = composeFirstDocument(text, {});
107
107
  if (doc.errors.some((e) => isFatalCode(e.code))) return void 0;
108
108
  const preserveComments = options?.preserveComments ?? true;
109
- return stringifyDocument({
109
+ const outputDoc = {
110
110
  contents: !preserveComments && doc.contents !== null ? stripNodeComments(doc.contents) : doc.contents,
111
111
  errors: doc.errors,
112
112
  warnings: doc.warnings,
@@ -115,7 +115,8 @@ function formatDocument(text, options) {
115
115
  hasDocumentStart: doc.hasDocumentStart,
116
116
  hasDocumentEnd: doc.hasDocumentEnd,
117
117
  hasDocumentStartTab: doc.hasDocumentStartTab
118
- }, toStringifyInput(options));
118
+ };
119
+ return stringifyDocument(outputDoc, toStringifyInput(options));
119
120
  }
120
121
  /** Convert a plain JS scalar value into a synthetic `YamlScalar` (offset/length are irrelevant — immediately re-stringified). */
121
122
  function jsValueToNode(value) {
@@ -317,10 +318,12 @@ var YamlFormat = class YamlFormat {
317
318
  }, text)]
318
319
  });
319
320
  }
320
- return computeEdits(text, stringifyDocument({
321
+ const outputDoc = {
321
322
  ...doc,
322
323
  contents: newContents
323
- }, toStringifyInput(options))).map((e) => YamlEdit.make(e));
324
+ };
325
+ const formatted = stringifyDocument(outputDoc, toStringifyInput(options));
326
+ return computeEdits(text, formatted).map((e) => YamlEdit.make(e));
324
327
  });
325
328
  /**
326
329
  * Modify `text` and apply the resulting edits in one step
package/index.d.ts CHANGED
@@ -1168,8 +1168,8 @@ declare const YamlVisitorEvent: {
1168
1168
  readonly path: YamlPath;
1169
1169
  readonly depth: number;
1170
1170
  readonly style: CollectionStyle;
1171
- readonly tag?: string | undefined;
1172
- readonly anchor?: string | undefined;
1171
+ readonly tag?: string;
1172
+ readonly anchor?: string;
1173
1173
  }, {
1174
1174
  readonly _tag: Tag;
1175
1175
  }> | Extract<{
@@ -1186,8 +1186,8 @@ declare const YamlVisitorEvent: {
1186
1186
  readonly depth: number;
1187
1187
  readonly value: unknown;
1188
1188
  readonly style: ScalarStyle;
1189
- readonly tag?: string | undefined;
1190
- readonly anchor?: string | undefined;
1189
+ readonly tag?: string;
1190
+ readonly anchor?: string;
1191
1191
  }, {
1192
1192
  readonly _tag: Tag;
1193
1193
  }> | Extract<{
@@ -1201,8 +1201,8 @@ declare const YamlVisitorEvent: {
1201
1201
  readonly path: YamlPath;
1202
1202
  readonly depth: number;
1203
1203
  readonly style: CollectionStyle;
1204
- readonly tag?: string | undefined;
1205
- readonly anchor?: string | undefined;
1204
+ readonly tag?: string;
1205
+ readonly anchor?: string;
1206
1206
  }, {
1207
1207
  readonly _tag: Tag;
1208
1208
  }>;
@@ -1257,8 +1257,8 @@ declare const YamlVisitorEvent: {
1257
1257
  readonly path: YamlPath;
1258
1258
  readonly depth: number;
1259
1259
  readonly style: CollectionStyle;
1260
- readonly tag?: string | undefined;
1261
- readonly anchor?: string | undefined;
1260
+ readonly tag?: string;
1261
+ readonly anchor?: string;
1262
1262
  }) => any;
1263
1263
  readonly Pair: (args: {
1264
1264
  readonly _tag: "Pair";
@@ -1273,8 +1273,8 @@ declare const YamlVisitorEvent: {
1273
1273
  readonly depth: number;
1274
1274
  readonly value: unknown;
1275
1275
  readonly style: ScalarStyle;
1276
- readonly tag?: string | undefined;
1277
- readonly anchor?: string | undefined;
1276
+ readonly tag?: string;
1277
+ readonly anchor?: string;
1278
1278
  }) => any;
1279
1279
  readonly SeqEnd: (args: {
1280
1280
  readonly _tag: "SeqEnd";
@@ -1286,8 +1286,8 @@ declare const YamlVisitorEvent: {
1286
1286
  readonly path: YamlPath;
1287
1287
  readonly depth: number;
1288
1288
  readonly style: CollectionStyle;
1289
- readonly tag?: string | undefined;
1290
- readonly anchor?: string | undefined;
1289
+ readonly tag?: string;
1290
+ readonly anchor?: string;
1291
1291
  }) => any;
1292
1292
  }>(cases: Cases): (value: {
1293
1293
  readonly _tag: "Alias";
@@ -1331,8 +1331,8 @@ declare const YamlVisitorEvent: {
1331
1331
  readonly path: YamlPath;
1332
1332
  readonly depth: number;
1333
1333
  readonly style: CollectionStyle;
1334
- readonly tag?: string | undefined;
1335
- readonly anchor?: string | undefined;
1334
+ readonly tag?: string;
1335
+ readonly anchor?: string;
1336
1336
  } | {
1337
1337
  readonly _tag: "Pair";
1338
1338
  readonly path: YamlPath;
@@ -1345,8 +1345,8 @@ declare const YamlVisitorEvent: {
1345
1345
  readonly depth: number;
1346
1346
  readonly value: unknown;
1347
1347
  readonly style: ScalarStyle;
1348
- readonly tag?: string | undefined;
1349
- readonly anchor?: string | undefined;
1348
+ readonly tag?: string;
1349
+ readonly anchor?: string;
1350
1350
  } | {
1351
1351
  readonly _tag: "SeqEnd";
1352
1352
  readonly path: YamlPath;
@@ -1356,8 +1356,8 @@ declare const YamlVisitorEvent: {
1356
1356
  readonly path: YamlPath;
1357
1357
  readonly depth: number;
1358
1358
  readonly style: CollectionStyle;
1359
- readonly tag?: string | undefined;
1360
- readonly anchor?: string | undefined;
1359
+ readonly tag?: string;
1360
+ readonly anchor?: string;
1361
1361
  }) => import("effect/Unify").Unify<ReturnType<Cases["Alias" | "Comment" | "Directive" | "DocumentEnd" | "DocumentStart" | "Error" | "MapEnd" | "MapStart" | "Pair" | "Scalar" | "SeqEnd" | "SeqStart"]>>;
1362
1362
  <Cases extends {
1363
1363
  readonly Alias: (args: {
@@ -1409,8 +1409,8 @@ declare const YamlVisitorEvent: {
1409
1409
  readonly path: YamlPath;
1410
1410
  readonly depth: number;
1411
1411
  readonly style: CollectionStyle;
1412
- readonly tag?: string | undefined;
1413
- readonly anchor?: string | undefined;
1412
+ readonly tag?: string;
1413
+ readonly anchor?: string;
1414
1414
  }) => any;
1415
1415
  readonly Pair: (args: {
1416
1416
  readonly _tag: "Pair";
@@ -1425,8 +1425,8 @@ declare const YamlVisitorEvent: {
1425
1425
  readonly depth: number;
1426
1426
  readonly value: unknown;
1427
1427
  readonly style: ScalarStyle;
1428
- readonly tag?: string | undefined;
1429
- readonly anchor?: string | undefined;
1428
+ readonly tag?: string;
1429
+ readonly anchor?: string;
1430
1430
  }) => any;
1431
1431
  readonly SeqEnd: (args: {
1432
1432
  readonly _tag: "SeqEnd";
@@ -1438,8 +1438,8 @@ declare const YamlVisitorEvent: {
1438
1438
  readonly path: YamlPath;
1439
1439
  readonly depth: number;
1440
1440
  readonly style: CollectionStyle;
1441
- readonly tag?: string | undefined;
1442
- readonly anchor?: string | undefined;
1441
+ readonly tag?: string;
1442
+ readonly anchor?: string;
1443
1443
  }) => any;
1444
1444
  }>(value: {
1445
1445
  readonly _tag: "Alias";
@@ -1483,8 +1483,8 @@ declare const YamlVisitorEvent: {
1483
1483
  readonly path: YamlPath;
1484
1484
  readonly depth: number;
1485
1485
  readonly style: CollectionStyle;
1486
- readonly tag?: string | undefined;
1487
- readonly anchor?: string | undefined;
1486
+ readonly tag?: string;
1487
+ readonly anchor?: string;
1488
1488
  } | {
1489
1489
  readonly _tag: "Pair";
1490
1490
  readonly path: YamlPath;
@@ -1497,8 +1497,8 @@ declare const YamlVisitorEvent: {
1497
1497
  readonly depth: number;
1498
1498
  readonly value: unknown;
1499
1499
  readonly style: ScalarStyle;
1500
- readonly tag?: string | undefined;
1501
- readonly anchor?: string | undefined;
1500
+ readonly tag?: string;
1501
+ readonly anchor?: string;
1502
1502
  } | {
1503
1503
  readonly _tag: "SeqEnd";
1504
1504
  readonly path: YamlPath;
@@ -1508,8 +1508,8 @@ declare const YamlVisitorEvent: {
1508
1508
  readonly path: YamlPath;
1509
1509
  readonly depth: number;
1510
1510
  readonly style: CollectionStyle;
1511
- readonly tag?: string | undefined;
1512
- readonly anchor?: string | undefined;
1511
+ readonly tag?: string;
1512
+ readonly anchor?: string;
1513
1513
  }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Alias" | "Comment" | "Directive" | "DocumentEnd" | "DocumentStart" | "Error" | "MapEnd" | "MapStart" | "Pair" | "Scalar" | "SeqEnd" | "SeqStart"]>>;
1514
1514
  };
1515
1515
  readonly Alias: Data.TaggedEnum.ConstructorFrom<{
@@ -1561,8 +1561,8 @@ declare const YamlVisitorEvent: {
1561
1561
  readonly path: YamlPath;
1562
1562
  readonly depth: number;
1563
1563
  readonly style: CollectionStyle;
1564
- readonly tag?: string | undefined;
1565
- readonly anchor?: string | undefined;
1564
+ readonly tag?: string;
1565
+ readonly anchor?: string;
1566
1566
  }, "_tag">;
1567
1567
  readonly Pair: Data.TaggedEnum.ConstructorFrom<{
1568
1568
  readonly _tag: "Pair";
@@ -1577,8 +1577,8 @@ declare const YamlVisitorEvent: {
1577
1577
  readonly depth: number;
1578
1578
  readonly value: unknown;
1579
1579
  readonly style: ScalarStyle;
1580
- readonly tag?: string | undefined;
1581
- readonly anchor?: string | undefined;
1580
+ readonly tag?: string;
1581
+ readonly anchor?: string;
1582
1582
  }, "_tag">;
1583
1583
  readonly SeqEnd: Data.TaggedEnum.ConstructorFrom<{
1584
1584
  readonly _tag: "SeqEnd";
@@ -1590,8 +1590,8 @@ declare const YamlVisitorEvent: {
1590
1590
  readonly path: YamlPath;
1591
1591
  readonly depth: number;
1592
1592
  readonly style: CollectionStyle;
1593
- readonly tag?: string | undefined;
1594
- readonly anchor?: string | undefined;
1593
+ readonly tag?: string;
1594
+ readonly anchor?: string;
1595
1595
  }, "_tag">;
1596
1596
  };
1597
1597
  /**
@@ -39,11 +39,12 @@ function composeBlockMapInner(blockMapCst, state, externalFirstKey, meta) {
39
39
  if (state.options.uniqueKeys) checkDuplicateKeys(pairs, state);
40
40
  checkMultilineImplicitKeys(pairs, state);
41
41
  const offset = externalFirstKey ? "offset" in externalFirstKey ? externalFirstKey.offset : blockMapCst.offset : blockMapCst.offset;
42
+ const length = blockMapCst.offset + blockMapCst.length - offset;
42
43
  const map = new YamlMap({
43
44
  items: pairs,
44
45
  style: "block",
45
46
  offset,
46
- length: blockMapCst.offset + blockMapCst.length - offset,
47
+ length,
47
48
  ...meta?.tag !== void 0 ? { tag: meta.tag } : {},
48
49
  ...meta?.anchor !== void 0 ? { anchor: meta.anchor } : {},
49
50
  ...meta?.comment !== void 0 ? { comment: meta.comment } : {}
@@ -135,11 +136,12 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
135
136
  const firstC = findFirstContent(sliceChildren);
136
137
  const lastC = findLastContent(sliceChildren);
137
138
  const innerOffset = firstC ? firstC.offset : child.offset;
139
+ const innerEnd = lastC ? lastC.offset + lastC.length : child.offset + child.length;
138
140
  pushNode(new YamlMap({
139
141
  items: innerPairs,
140
142
  style: "block",
141
143
  offset: innerOffset,
142
- length: (lastC ? lastC.offset + lastC.length : child.offset + child.length) - innerOffset
144
+ length: innerEnd - innerOffset
143
145
  }), innerOffset);
144
146
  i = lookahead.endIdx - 1;
145
147
  continue;
@@ -150,8 +152,9 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
150
152
  validateNoTabAfterContinuationValueSep(child, children, i, state);
151
153
  const flushMeta = combinedPending();
152
154
  if (hasMeta(flushMeta)) {
155
+ const value = resolveScalar("", "plain", flushMeta.tag, state);
153
156
  const scalar = new YamlScalar({
154
- value: resolveScalar("", "plain", flushMeta.tag, state),
157
+ value,
155
158
  style: "plain",
156
159
  offset: child.offset,
157
160
  length: 0,
@@ -211,8 +214,9 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
211
214
  if (afterValueSep && sepOnSameLine) {
212
215
  const flushMeta = combinedPending();
213
216
  if (hasMeta(flushMeta)) {
217
+ const value = resolveScalar("", "plain", flushMeta.tag, state);
214
218
  const scalar = new YamlScalar({
215
- value: resolveScalar("", "plain", flushMeta.tag, state),
219
+ value,
216
220
  style: "plain",
217
221
  offset: child.offset,
218
222
  length: 0,
@@ -277,8 +281,9 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
277
281
  if (isExplicitKey) {
278
282
  const { value: keyValue, nextIdx: keyNextIdx } = collectMultilineKey(children, i);
279
283
  const keyMeta = combinedPending();
284
+ const resolved = resolveScalar(keyValue, "plain", keyMeta.tag, state);
280
285
  const scalar = new YamlScalar({
281
- value: resolveScalar(keyValue, "plain", keyMeta.tag, state),
286
+ value: resolved,
282
287
  style: "plain",
283
288
  offset: child.offset,
284
289
  length: child.length,
@@ -386,7 +391,8 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
386
391
  i = nextAlias.idx;
387
392
  continue;
388
393
  }
389
- checkAnchorOnAlias(combinedPending(), child, state);
394
+ const aliasMeta = combinedPending();
395
+ checkAnchorOnAlias(aliasMeta, child, state);
390
396
  const alias = makeAlias(child, state);
391
397
  resetAllMeta();
392
398
  pushNode(alias);
@@ -451,8 +457,9 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
451
457
  }
452
458
  const trailingMeta = combinedPending();
453
459
  if (hasMeta(trailingMeta)) {
460
+ const value = resolveScalar("", "plain", trailingMeta.tag, state);
454
461
  const scalar = new YamlScalar({
455
- value: resolveScalar("", "plain", trailingMeta.tag, state),
462
+ value,
456
463
  style: "plain",
457
464
  offset: 0,
458
465
  length: 0,
@@ -643,7 +650,8 @@ function keyIdentity(key, text) {
643
650
  case "string": return `s:${v}`;
644
651
  case "bigint": return `i:${v.toString()}`;
645
652
  case "number": {
646
- let kind = classifyPlainNumeric(text.slice(key.offset, key.offset + key.length).trim());
653
+ const raw = text.slice(key.offset, key.offset + key.length).trim();
654
+ let kind = classifyPlainNumeric(raw);
647
655
  if (key.tag !== void 0) {
648
656
  if (key.tag.includes("float")) kind = "float";
649
657
  else if (key.tag.includes("int")) kind = "int";
@@ -1012,8 +1020,9 @@ function composeBlockSeqInner(cst, state, meta) {
1012
1020
  if (child.type === "flow-scalar" && getScalarStyle(child) === "plain") {
1013
1021
  const { value: merged, nextIdx: mergeEnd, partsCount, endOffset } = collectMultilinePlainScalar(children, ci, void 0, state.text);
1014
1022
  if (partsCount > 1) {
1023
+ const resolved = resolveScalar(merged, "plain", pendingMeta.tag, state);
1015
1024
  const scalar = new YamlScalar({
1016
- value: resolveScalar(merged, "plain", pendingMeta.tag, state),
1025
+ value: resolved,
1017
1026
  style: "plain",
1018
1027
  offset: child.offset,
1019
1028
  length: endOffset - child.offset,
@@ -1100,8 +1109,9 @@ function composeBlockSeqInner(cst, state, meta) {
1100
1109
  length: 0
1101
1110
  }));
1102
1111
  if (hasMeta(pendingMeta)) {
1112
+ const value = resolveScalar("", "plain", pendingMeta.tag, state);
1103
1113
  const scalar = new YamlScalar({
1104
- value: resolveScalar("", "plain", pendingMeta.tag, state),
1114
+ value,
1105
1115
  style: "plain",
1106
1116
  offset: 0,
1107
1117
  length: 0,
@@ -1138,11 +1148,12 @@ function composeFlatBlockMap(children, startIdx, parentCst, state, externalFirst
1138
1148
  if (state.options.uniqueKeys) checkDuplicateKeys(pairs, state);
1139
1149
  checkMultilineImplicitKeys(pairs, state);
1140
1150
  const offset = "offset" in externalFirstKey ? externalFirstKey.offset : parentCst.offset;
1151
+ const end = parentCst.offset + parentCst.length;
1141
1152
  const map = new YamlMap({
1142
1153
  items: pairs,
1143
1154
  style: "block",
1144
1155
  offset,
1145
- length: parentCst.offset + parentCst.length - offset,
1156
+ length: end - offset,
1146
1157
  ...meta?.tag !== void 0 ? { tag: meta.tag } : {},
1147
1158
  ...meta?.anchor !== void 0 ? { anchor: meta.anchor } : {},
1148
1159
  ...meta?.comment !== void 0 ? { comment: meta.comment } : {}
@@ -116,7 +116,8 @@ function composeFlowMapInner(cst, state, meta, parentBlockColumn) {
116
116
  });
117
117
  validateFlowContentIndent(cst, state, parentBlockColumn);
118
118
  validateFlowSeparators(children, state, "{", "}");
119
- buildPairs(flattenFlowChildren(children.filter((c) => !(c.type === "whitespace" && (c.source === "{" || c.source === "}" || c.source.trim() === ""))), state), pairs, state.text);
119
+ const items = flattenFlowChildren(children.filter((c) => !(c.type === "whitespace" && (c.source === "{" || c.source === "}" || c.source.trim() === ""))), state);
120
+ buildPairs(items, pairs, state.text);
120
121
  if (state.options.uniqueKeys) checkDuplicateKeys(pairs, state);
121
122
  const map = new YamlMap({
122
123
  items: pairs,
@@ -140,8 +141,9 @@ function flattenFlowChildren(children, state) {
140
141
  if (child.type === "whitespace") {
141
142
  if (child.source === ",") {
142
143
  if (hasMeta(pendingMeta)) {
144
+ const value = resolveScalar("", "plain", pendingMeta.tag, state);
143
145
  const scalar = new YamlScalar({
144
- value: resolveScalar("", "plain", pendingMeta.tag, state),
146
+ value,
145
147
  style: "plain",
146
148
  offset: child.offset,
147
149
  length: 0,
@@ -159,8 +161,9 @@ function flattenFlowChildren(children, state) {
159
161
  }
160
162
  if (child.source === ":") {
161
163
  if (hasMeta(pendingMeta)) {
164
+ const value = resolveScalar("", "plain", pendingMeta.tag, state);
162
165
  const scalar = new YamlScalar({
163
- value: resolveScalar("", "plain", pendingMeta.tag, state),
166
+ value,
164
167
  style: "plain",
165
168
  offset: child.offset,
166
169
  length: 0,
@@ -225,8 +228,9 @@ function flattenFlowChildren(children, state) {
225
228
  if (child.type === "flow-scalar" && getScalarStyle(child) === "plain") {
226
229
  if (hasValueSepThroughPlainScalars(children, i + 1)) {
227
230
  const { value, nextIdx } = collectMultilineKey(children, i);
231
+ const resolved = resolveScalar(value, "plain", pendingMeta.tag, state);
228
232
  const scalar = new YamlScalar({
229
- value: resolveScalar(value, "plain", pendingMeta.tag, state),
233
+ value: resolved,
230
234
  style: "plain",
231
235
  offset: child.offset,
232
236
  length: child.length,
@@ -243,8 +247,9 @@ function flattenFlowChildren(children, state) {
243
247
  continue;
244
248
  }
245
249
  const { value, nextIdx, partsCount, endOffset } = collectMultilinePlainScalar(children, i, void 0, state.text);
250
+ const resolved = resolveScalar(value, "plain", pendingMeta.tag, state);
246
251
  const scalar = new YamlScalar({
247
- value: resolveScalar(value, "plain", pendingMeta.tag, state),
252
+ value: resolved,
248
253
  style: "plain",
249
254
  offset: child.offset,
250
255
  length: partsCount > 1 ? endOffset - child.offset : child.length,
@@ -297,8 +302,9 @@ function flattenFlowChildren(children, state) {
297
302
  }
298
303
  }
299
304
  if (hasMeta(pendingMeta)) {
305
+ const value = resolveScalar("", "plain", pendingMeta.tag, state);
300
306
  const scalar = new YamlScalar({
301
- value: resolveScalar("", "plain", pendingMeta.tag, state),
307
+ value,
302
308
  style: "plain",
303
309
  offset: 0,
304
310
  length: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/yaml",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "description": "Zero-dependency YAML parsing, editing and formatting as Effect schemas.",
6
6
  "keywords": [