@thoughtspot/visual-embed-sdk 1.49.2 → 1.49.3

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 (58) hide show
  1. package/cjs/package.json +4 -10
  2. package/cjs/src/embed/app.d.ts +7 -1
  3. package/cjs/src/embed/app.d.ts.map +1 -1
  4. package/cjs/src/embed/app.js.map +1 -1
  5. package/cjs/src/embed/liveboard.d.ts +6 -0
  6. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  7. package/cjs/src/embed/liveboard.js.map +1 -1
  8. package/cjs/src/embed/spotter-viz-utils.d.ts +29 -0
  9. package/cjs/src/embed/spotter-viz-utils.d.ts.map +1 -1
  10. package/cjs/src/embed/spotter-viz-utils.js.map +1 -1
  11. package/cjs/src/index.d.ts +2 -2
  12. package/cjs/src/index.d.ts.map +1 -1
  13. package/cjs/src/index.js.map +1 -1
  14. package/cjs/src/utils/graphql/answerService/answerService.spec.js +15 -0
  15. package/cjs/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
  16. package/cjs/src/utils.js +2 -3
  17. package/cjs/src/utils.js.map +1 -1
  18. package/dist/{index-CS7yJ2Jj.js → index-DsSQndIB.js} +303 -187
  19. package/dist/src/embed/app.d.ts +7 -1
  20. package/dist/src/embed/app.d.ts.map +1 -1
  21. package/dist/src/embed/liveboard.d.ts +6 -0
  22. package/dist/src/embed/liveboard.d.ts.map +1 -1
  23. package/dist/src/embed/spotter-viz-utils.d.ts +29 -0
  24. package/dist/src/embed/spotter-viz-utils.d.ts.map +1 -1
  25. package/dist/src/index.d.ts +2 -2
  26. package/dist/src/index.d.ts.map +1 -1
  27. package/dist/tsembed-react.es.js +32 -15
  28. package/dist/tsembed-react.js +333 -200
  29. package/dist/tsembed.es.js +32 -15
  30. package/dist/tsembed.js +333 -200
  31. package/dist/visual-embed-sdk-react-full.d.ts +42 -1
  32. package/dist/visual-embed-sdk-react.d.ts +42 -1
  33. package/dist/visual-embed-sdk.d.ts +42 -1
  34. package/lib/package.json +4 -10
  35. package/lib/src/embed/app.d.ts +7 -1
  36. package/lib/src/embed/app.d.ts.map +1 -1
  37. package/lib/src/embed/app.js.map +1 -1
  38. package/lib/src/embed/liveboard.d.ts +6 -0
  39. package/lib/src/embed/liveboard.d.ts.map +1 -1
  40. package/lib/src/embed/liveboard.js.map +1 -1
  41. package/lib/src/embed/spotter-viz-utils.d.ts +29 -0
  42. package/lib/src/embed/spotter-viz-utils.d.ts.map +1 -1
  43. package/lib/src/embed/spotter-viz-utils.js.map +1 -1
  44. package/lib/src/index.d.ts +2 -2
  45. package/lib/src/index.d.ts.map +1 -1
  46. package/lib/src/index.js.map +1 -1
  47. package/lib/src/utils/graphql/answerService/answerService.spec.js +15 -0
  48. package/lib/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
  49. package/lib/src/utils.js +1 -1
  50. package/lib/src/utils.js.map +1 -1
  51. package/lib/src/visual-embed-sdk.d.ts +42 -1
  52. package/package.json +4 -10
  53. package/src/embed/app.ts +7 -1
  54. package/src/embed/liveboard.ts +6 -0
  55. package/src/embed/spotter-viz-utils.ts +30 -0
  56. package/src/index.ts +2 -1
  57. package/src/utils/graphql/answerService/answerService.spec.ts +18 -0
  58. package/src/utils.ts +1 -1
package/dist/tsembed.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @thoughtspot/visual-embed-sdk version 1.49.2 */
1
+ /* @thoughtspot/visual-embed-sdk version 1.49.3 */
2
2
  'use client';
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -6461,7 +6461,7 @@
6461
6461
  TableContentDensity["Compact"] = "COMPACT";
6462
6462
  })(exports.TableContentDensity || (exports.TableContentDensity = {}));
6463
6463
 
6464
- var version$1="1.49.2";var pkg = {version:version$1};
6464
+ var version$1="1.49.3";var pkg = {version:version$1};
6465
6465
 
6466
6466
  const { version } = pkg;
6467
6467
 
@@ -6546,28 +6546,45 @@
6546
6546
  }
6547
6547
  return false;
6548
6548
  };
6549
- const merge = (...objects) => objects.reduce((result, current) => {
6549
+ const UNSAFE_KEYS = new Set([
6550
+ "__proto__",
6551
+ "constructor",
6552
+ "prototype",
6553
+ "toString",
6554
+ "valueOf",
6555
+ "hasOwnProperty",
6556
+ "isPrototypeOf",
6557
+ "propertyIsEnumerable",
6558
+ "toLocaleString",
6559
+ ]);
6560
+ const merge$1 = (...objects) => objects.reduce((result, current) => {
6561
+ if (current === undefined) {
6562
+ return result;
6563
+ }
6550
6564
  if (Array.isArray(current)) {
6551
6565
  throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
6552
6566
  }
6553
6567
  Object.keys(current).forEach((key) => {
6554
- if (["__proto__", "constructor", "prototype"].includes(key)) {
6568
+ if (UNSAFE_KEYS.has(key)) {
6555
6569
  return;
6556
6570
  }
6557
6571
  if (Array.isArray(result[key]) && Array.isArray(current[key])) {
6558
- result[key] = merge.options.mergeArrays
6559
- ? merge.options.uniqueArrayItems
6572
+ result[key] = merge$1.options.mergeArrays
6573
+ ? merge$1.options.uniqueArrayItems
6560
6574
  ? Array.from(new Set(result[key].concat(current[key])))
6561
6575
  : [...result[key], ...current[key]]
6562
6576
  : current[key];
6563
6577
  }
6564
6578
  else if (isObject$1(result[key]) && isObject$1(current[key])) {
6565
- result[key] = merge(result[key], current[key]);
6579
+ result[key] = merge$1(result[key], current[key]);
6580
+ }
6581
+ else if (!isObject$1(result[key]) && isObject$1(current[key])) {
6582
+ result[key] = merge$1(current[key], undefined);
6566
6583
  }
6567
6584
  else {
6568
6585
  result[key] =
6569
6586
  current[key] === undefined
6570
- ? merge.options.allowUndefinedOverrides
6587
+ ? merge$1.options.allowUndefinedOverrides
6571
6588
  ? current[key]
6572
6589
  : result[key]
6573
6590
  : current[key];
@@ -6580,11 +6597,11 @@
6580
6597
  mergeArrays: true,
6581
6598
  uniqueArrayItems: true,
6582
6599
  };
6583
- merge.options = defaultOptions;
6584
- merge.withOptions = (options, ...objects) => {
6585
- merge.options = Object.assign(Object.assign({}, defaultOptions), options);
6586
- const result = merge(...objects);
6587
- merge.options = defaultOptions;
6600
+ merge$1.options = defaultOptions;
6601
+ merge$1.withOptions = (options, ...objects) => {
6602
+ merge$1.options = Object.assign(Object.assign({}, defaultOptions), options);
6603
+ const result = merge$1(...objects);
6604
+ merge$1.options = defaultOptions;
6588
6605
  return result;
6589
6606
  };
6590
6607
 
@@ -6881,7 +6898,7 @@
6881
6898
  }
6882
6899
  return null;
6883
6900
  }
6884
- const deepMerge = (target, source) => merge(target, source);
6901
+ const deepMerge = (target, source) => merge$1(target, source);
6885
6902
  const getOperationNameFromQuery = (query) => {
6886
6903
  const regex = /(?:query|mutation)\s+(\w+)/;
6887
6904
  const matches = query.match(regex);
@@ -25422,8 +25439,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
25422
25439
  return {
25423
25440
  onAnchor: (source) => {
25424
25441
  aliasObjects.push(source);
25425
- if (!prevAnchors)
25426
- prevAnchors = anchorNames(doc);
25442
+ prevAnchors ?? (prevAnchors = anchorNames(doc));
25427
25443
  const anchor = findNewAnchor(prefix, prevAnchors);
25428
25444
  prevAnchors.add(anchor);
25429
25445
  return anchor;
@@ -25587,23 +25603,38 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
25587
25603
  * Resolve the value of this alias within `doc`, finding the last
25588
25604
  * instance of the `source` anchor before this node.
25589
25605
  */
25590
- resolve(doc) {
25606
+ resolve(doc, ctx) {
25607
+ if (ctx?.maxAliasCount === 0)
25608
+ throw new ReferenceError('Alias resolution is disabled');
25609
+ let nodes;
25610
+ if (ctx?.aliasResolveCache) {
25611
+ nodes = ctx.aliasResolveCache;
25612
+ }
25613
+ else {
25614
+ nodes = [];
25615
+ visit$1(doc, {
25616
+ Node: (_key, node) => {
25617
+ if (isAlias(node) || hasAnchor(node))
25618
+ nodes.push(node);
25619
+ }
25620
+ });
25621
+ if (ctx)
25622
+ ctx.aliasResolveCache = nodes;
25623
+ }
25591
25624
  let found = undefined;
25592
- visit$1(doc, {
25593
- Node: (_key, node) => {
25594
- if (node === this)
25595
- return visit$1.BREAK;
25596
- if (node.anchor === this.source)
25597
- found = node;
25598
- }
25599
- });
25625
+ for (const node of nodes) {
25626
+ if (node === this)
25627
+ break;
25628
+ if (node.anchor === this.source)
25629
+ found = node;
25630
+ }
25600
25631
  return found;
25601
25632
  }
25602
25633
  toJSON(_arg, ctx) {
25603
25634
  if (!ctx)
25604
25635
  return { source: this.source };
25605
25636
  const { anchors, doc, maxAliasCount } = ctx;
25606
- const source = this.resolve(doc);
25637
+ const source = this.resolve(doc, ctx);
25607
25638
  if (!source) {
25608
25639
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
25609
25640
  throw new ReferenceError(msg);
@@ -25615,7 +25646,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
25615
25646
  data = anchors.get(source);
25616
25647
  }
25617
25648
  /* istanbul ignore if */
25618
- if (!data || data.res === undefined) {
25649
+ if (data?.res === undefined) {
25619
25650
  const msg = 'This should not happen: Alias anchor was not resolved?';
25620
25651
  throw new ReferenceError(msg);
25621
25652
  }
@@ -25722,8 +25753,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
25722
25753
  if (aliasDuplicateObjects && value && typeof value === 'object') {
25723
25754
  ref = sourceObjects.get(value);
25724
25755
  if (ref) {
25725
- if (!ref.anchor)
25726
- ref.anchor = onAnchor(value);
25756
+ ref.anchor ?? (ref.anchor = onAnchor(value));
25727
25757
  return new Alias(ref.anchor);
25728
25758
  }
25729
25759
  else {
@@ -26234,7 +26264,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26234
26264
  const { blockQuote, commentString, lineWidth } = ctx.options;
26235
26265
  // 1. Block can't end in whitespace unless the last line is non-empty.
26236
26266
  // 2. Strings consisting of only whitespace are best rendered explicitly.
26237
- if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
26267
+ if (!blockQuote || /\n[\t ]+$/.test(value)) {
26238
26268
  return quotedString(value, ctx);
26239
26269
  }
26240
26270
  const indent = ctx.indent ||
@@ -26294,23 +26324,32 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26294
26324
  start = start.replace(/\n+/g, `$&${indent}`);
26295
26325
  }
26296
26326
  const indentSize = indent ? '2' : '1'; // root is at -1
26297
- let header = (literal ? '|' : '>') + (startWithSpace ? indentSize : '') + chomp;
26327
+ // Leading | or > is added later
26328
+ let header = (startWithSpace ? indentSize : '') + chomp;
26298
26329
  if (comment) {
26299
26330
  header += ' ' + commentString(comment.replace(/ ?[\r\n]+/g, ' '));
26300
26331
  if (onComment)
26301
26332
  onComment();
26302
26333
  }
26303
- if (literal) {
26304
- value = value.replace(/\n+/g, `$&${indent}`);
26305
- return `${header}\n${indent}${start}${value}${end}`;
26334
+ if (!literal) {
26335
+ const foldedValue = value
26336
+ .replace(/\n+/g, '\n$&')
26337
+ .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
26338
+ // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
26339
+ .replace(/\n+/g, `$&${indent}`);
26340
+ let literalFallback = false;
26341
+ const foldOptions = getFoldOptions(ctx, true);
26342
+ if (blockQuote !== 'folded' && type !== Scalar.BLOCK_FOLDED) {
26343
+ foldOptions.onOverflow = () => {
26344
+ literalFallback = true;
26345
+ };
26346
+ }
26347
+ const body = foldFlowLines(`${start}${foldedValue}${end}`, indent, FOLD_BLOCK, foldOptions);
26348
+ if (!literalFallback)
26349
+ return `>${header}\n${indent}${body}`;
26306
26350
  }
26307
- value = value
26308
- .replace(/\n+/g, '\n$&')
26309
- .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
26310
- // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
26311
- .replace(/\n+/g, `$&${indent}`);
26312
- const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
26313
- return `${header}\n${indent}${body}`;
26351
+ value = value.replace(/\n+/g, `$&${indent}`);
26352
+ return `|${header}\n${indent}${start}${value}${end}`;
26314
26353
  }
26315
26354
  function plainString(item, ctx, onComment, onChompKeep) {
26316
26355
  const { type, value } = item;
@@ -26319,10 +26358,9 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26319
26358
  (inFlow && /[[\]{},]/.test(value))) {
26320
26359
  return quotedString(value, ctx);
26321
26360
  }
26322
- if (!value ||
26323
- /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
26361
+ if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
26324
26362
  // not allowed:
26325
- // - empty string, '-' or '?'
26363
+ // - '-' or '?'
26326
26364
  // - start with an indicator character (except [?:-]) or /[?-] /
26327
26365
  // - '\n ', ': ' or ' \n' anywhere
26328
26366
  // - '#' not preceded by a non-space char
@@ -26417,6 +26455,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26417
26455
  nullStr: 'null',
26418
26456
  simpleKeys: false,
26419
26457
  singleQuote: null,
26458
+ trailingComma: false,
26420
26459
  trueStr: 'true',
26421
26460
  verifyAliasOrder: true
26422
26461
  }, doc.schema.toStringOptions, options);
@@ -26451,7 +26490,12 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26451
26490
  let obj;
26452
26491
  if (isScalar$1(item)) {
26453
26492
  obj = item.value;
26454
- const match = tags.filter(t => t.identify?.(obj));
26493
+ let match = tags.filter(t => t.identify?.(obj));
26494
+ if (match.length > 1) {
26495
+ const testMatch = match.filter(t => t.test);
26496
+ if (testMatch.length > 0)
26497
+ match = testMatch;
26498
+ }
26455
26499
  tagObj =
26456
26500
  match.find(t => t.format === item.format) ?? match.find(t => !t.format);
26457
26501
  }
@@ -26460,7 +26504,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26460
26504
  tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
26461
26505
  }
26462
26506
  if (!tagObj) {
26463
- const name = obj?.constructor?.name ?? typeof obj;
26507
+ const name = obj?.constructor?.name ?? (obj === null ? 'null' : typeof obj);
26464
26508
  throw new Error(`Tag not resolved for ${name} value`);
26465
26509
  }
26466
26510
  return tagObj;
@@ -26475,7 +26519,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26475
26519
  anchors.add(anchor);
26476
26520
  props.push(`&${anchor}`);
26477
26521
  }
26478
- const tag = node.tag ? node.tag : tagObj.default ? null : tagObj.tag;
26522
+ const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
26479
26523
  if (tag)
26480
26524
  props.push(doc.directives.tagString(tag));
26481
26525
  return props.join(' ');
@@ -26501,8 +26545,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26501
26545
  const node = isNode(item)
26502
26546
  ? item
26503
26547
  : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
26504
- if (!tagObj)
26505
- tagObj = getTagObject(ctx.doc.schema.tags, node);
26548
+ tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
26506
26549
  const props = stringifyProps(node, tagObj, ctx);
26507
26550
  if (props.length > 0)
26508
26551
  ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
@@ -26616,7 +26659,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26616
26659
  ws += `\n${indentComment(cs, ctx.indent)}`;
26617
26660
  }
26618
26661
  if (valueStr === '' && !ctx.inFlow) {
26619
- if (ws === '\n')
26662
+ if (ws === '\n' && valueComment)
26620
26663
  ws = '\n\n';
26621
26664
  }
26622
26665
  else {
@@ -26664,54 +26707,10 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26664
26707
 
26665
26708
  function warn(logLevel, warning) {
26666
26709
  if (logLevel === 'debug' || logLevel === 'warn') {
26667
- if (typeof process !== 'undefined' && process.emitWarning)
26668
- process.emitWarning(warning);
26669
- else
26670
- console.warn(warning);
26710
+ console.warn(warning);
26671
26711
  }
26672
26712
  }
26673
26713
 
26674
- const MERGE_KEY = '<<';
26675
- function addPairToJSMap(ctx, map, { key, value }) {
26676
- if (ctx?.doc.schema.merge && isMergeKey(key)) {
26677
- value = isAlias(value) ? value.resolve(ctx.doc) : value;
26678
- if (isSeq(value))
26679
- for (const it of value.items)
26680
- mergeToJSMap(ctx, map, it);
26681
- else if (Array.isArray(value))
26682
- for (const it of value)
26683
- mergeToJSMap(ctx, map, it);
26684
- else
26685
- mergeToJSMap(ctx, map, value);
26686
- }
26687
- else {
26688
- const jsKey = toJS(key, '', ctx);
26689
- if (map instanceof Map) {
26690
- map.set(jsKey, toJS(value, jsKey, ctx));
26691
- }
26692
- else if (map instanceof Set) {
26693
- map.add(jsKey);
26694
- }
26695
- else {
26696
- const stringKey = stringifyKey(key, jsKey, ctx);
26697
- const jsValue = toJS(value, stringKey, ctx);
26698
- if (stringKey in map)
26699
- Object.defineProperty(map, stringKey, {
26700
- value: jsValue,
26701
- writable: true,
26702
- enumerable: true,
26703
- configurable: true
26704
- });
26705
- else
26706
- map[stringKey] = jsValue;
26707
- }
26708
- }
26709
- return map;
26710
- }
26711
- const isMergeKey = (key) => key === MERGE_KEY ||
26712
- (isScalar$1(key) &&
26713
- key.value === MERGE_KEY &&
26714
- (!key.type || key.type === Scalar.PLAIN));
26715
26714
  // If the value associated with a merge key is a single mapping node, each of
26716
26715
  // its key/value pairs is inserted into the current mapping, unless the key
26717
26716
  // already exists in it. If the value associated with the merge key is a
@@ -26719,8 +26718,36 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26719
26718
  // of these nodes is merged in turn according to its order in the sequence.
26720
26719
  // Keys in mapping nodes earlier in the sequence override keys specified in
26721
26720
  // later mapping nodes. -- http://yaml.org/type/merge.html
26722
- function mergeToJSMap(ctx, map, value) {
26723
- const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
26721
+ const MERGE_KEY = '<<';
26722
+ const merge = {
26723
+ identify: value => value === MERGE_KEY ||
26724
+ (typeof value === 'symbol' && value.description === MERGE_KEY),
26725
+ default: 'key',
26726
+ tag: 'tag:yaml.org,2002:merge',
26727
+ test: /^<<$/,
26728
+ resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {
26729
+ addToJSMap: addMergeToJSMap
26730
+ }),
26731
+ stringify: () => MERGE_KEY
26732
+ };
26733
+ const isMergeKey = (ctx, key) => (merge.identify(key) ||
26734
+ (isScalar$1(key) &&
26735
+ (!key.type || key.type === Scalar.PLAIN) &&
26736
+ merge.identify(key.value))) &&
26737
+ ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
26738
+ function addMergeToJSMap(ctx, map, value) {
26739
+ const source = resolveAliasValue(ctx, value);
26740
+ if (isSeq(source))
26741
+ for (const it of source.items)
26742
+ mergeValue(ctx, map, it);
26743
+ else if (Array.isArray(source))
26744
+ for (const it of source)
26745
+ mergeValue(ctx, map, it);
26746
+ else
26747
+ mergeValue(ctx, map, source);
26748
+ }
26749
+ function mergeValue(ctx, map, value) {
26750
+ const source = resolveAliasValue(ctx, value);
26724
26751
  if (!isMap(source))
26725
26752
  throw new Error('Merge sources must be maps or map aliases');
26726
26753
  const srcMap = source.toJSON(null, ctx, Map);
@@ -26743,9 +26770,44 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26743
26770
  }
26744
26771
  return map;
26745
26772
  }
26773
+ function resolveAliasValue(ctx, value) {
26774
+ return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
26775
+ }
26776
+
26777
+ function addPairToJSMap(ctx, map, { key, value }) {
26778
+ if (isNode(key) && key.addToJSMap)
26779
+ key.addToJSMap(ctx, map, value);
26780
+ // TODO: Should drop this special case for bare << handling
26781
+ else if (isMergeKey(ctx, key))
26782
+ addMergeToJSMap(ctx, map, value);
26783
+ else {
26784
+ const jsKey = toJS(key, '', ctx);
26785
+ if (map instanceof Map) {
26786
+ map.set(jsKey, toJS(value, jsKey, ctx));
26787
+ }
26788
+ else if (map instanceof Set) {
26789
+ map.add(jsKey);
26790
+ }
26791
+ else {
26792
+ const stringKey = stringifyKey(key, jsKey, ctx);
26793
+ const jsValue = toJS(value, stringKey, ctx);
26794
+ if (stringKey in map)
26795
+ Object.defineProperty(map, stringKey, {
26796
+ value: jsValue,
26797
+ writable: true,
26798
+ enumerable: true,
26799
+ configurable: true
26800
+ });
26801
+ else
26802
+ map[stringKey] = jsValue;
26803
+ }
26804
+ }
26805
+ return map;
26806
+ }
26746
26807
  function stringifyKey(key, jsKey, ctx) {
26747
26808
  if (jsKey === null)
26748
26809
  return '';
26810
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
26749
26811
  if (typeof jsKey !== 'object')
26750
26812
  return String(jsKey);
26751
26813
  if (isNode(key) && ctx?.doc) {
@@ -26898,12 +26960,22 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
26898
26960
  if (comment)
26899
26961
  reqNewline = true;
26900
26962
  let str = stringify$2(item, itemCtx, () => (comment = null));
26901
- if (i < items.length - 1)
26963
+ reqNewline || (reqNewline = lines.length > linesAtValue || str.includes('\n'));
26964
+ if (i < items.length - 1) {
26902
26965
  str += ',';
26966
+ }
26967
+ else if (ctx.options.trailingComma) {
26968
+ if (ctx.options.lineWidth > 0) {
26969
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) +
26970
+ (str.length + 2) >
26971
+ ctx.options.lineWidth);
26972
+ }
26973
+ if (reqNewline) {
26974
+ str += ',';
26975
+ }
26976
+ }
26903
26977
  if (comment)
26904
26978
  str += lineComment(str, itemIndent, commentString(comment));
26905
- if (!reqNewline && (lines.length > linesAtValue || str.includes('\n')))
26906
- reqNewline = true;
26907
26979
  lines.push(str);
26908
26980
  linesAtValue = lines.length;
26909
26981
  }
@@ -27248,11 +27320,12 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27248
27320
  const num = typeof value === 'number' ? value : Number(value);
27249
27321
  if (!isFinite(num))
27250
27322
  return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
27251
- let n = JSON.stringify(value);
27323
+ let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);
27252
27324
  if (!format &&
27253
27325
  minFractionDigits &&
27254
27326
  (!tag || tag === 'tag:yaml.org,2002:float') &&
27255
- /^\d/.test(n)) {
27327
+ /^-?\d/.test(n) &&
27328
+ !n.includes('e')) {
27256
27329
  let i = n.indexOf('.');
27257
27330
  if (i < 0) {
27258
27331
  i = n.length;
@@ -27378,7 +27451,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27378
27451
  identify: value => typeof value === 'boolean',
27379
27452
  default: true,
27380
27453
  tag: 'tag:yaml.org,2002:bool',
27381
- test: /^true|false$/,
27454
+ test: /^true$|^false$/,
27382
27455
  resolve: str => str === 'true',
27383
27456
  stringify: stringifyJSON
27384
27457
  },
@@ -27423,10 +27496,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27423
27496
  * document.querySelector('#photo').src = URL.createObjectURL(blob)
27424
27497
  */
27425
27498
  resolve(src, onError) {
27426
- if (typeof Buffer === 'function') {
27427
- return Buffer.from(src, 'base64');
27428
- }
27429
- else if (typeof atob === 'function') {
27499
+ if (typeof atob === 'function') {
27430
27500
  // On IE 11, atob() can't handle newlines
27431
27501
  const str = atob(src.replace(/[\n\r]/g, ''));
27432
27502
  const buffer = new Uint8Array(str.length);
@@ -27440,15 +27510,11 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27440
27510
  }
27441
27511
  },
27442
27512
  stringify({ comment, type, value }, ctx, onComment, onChompKeep) {
27513
+ if (!value)
27514
+ return '';
27443
27515
  const buf = value; // checked earlier by binary.identify()
27444
27516
  let str;
27445
- if (typeof Buffer === 'function') {
27446
- str =
27447
- buf instanceof Buffer
27448
- ? buf.toString('base64')
27449
- : Buffer.from(buf.buffer).toString('base64');
27450
- }
27451
- else if (typeof btoa === 'function') {
27517
+ if (typeof btoa === 'function') {
27452
27518
  let s = '';
27453
27519
  for (let i = 0; i < buf.length; ++i)
27454
27520
  s += String.fromCharCode(buf[i]);
@@ -27457,8 +27523,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27457
27523
  else {
27458
27524
  throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
27459
27525
  }
27460
- if (!type)
27461
- type = Scalar.BLOCK_LITERAL;
27526
+ type ?? (type = Scalar.BLOCK_LITERAL);
27462
27527
  if (type !== Scalar.QUOTE_DOUBLE) {
27463
27528
  const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
27464
27529
  const n = Math.ceil(str.length / lineWidth);
@@ -27927,7 +27992,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27927
27992
  }
27928
27993
  return new Date(date);
27929
27994
  },
27930
- stringify: ({ value }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
27995
+ stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\.000Z$/, '') ?? ''
27931
27996
  };
27932
27997
 
27933
27998
  const schema = [
@@ -27945,6 +28010,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27945
28010
  floatExp,
27946
28011
  float,
27947
28012
  binary,
28013
+ merge,
27948
28014
  omap,
27949
28015
  pairs,
27950
28016
  set,
@@ -27972,6 +28038,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27972
28038
  intOct: intOct$1,
27973
28039
  intTime,
27974
28040
  map,
28041
+ merge,
27975
28042
  null: nullTag,
27976
28043
  omap,
27977
28044
  pairs,
@@ -27981,13 +28048,20 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
27981
28048
  };
27982
28049
  const coreKnownTags = {
27983
28050
  'tag:yaml.org,2002:binary': binary,
28051
+ 'tag:yaml.org,2002:merge': merge,
27984
28052
  'tag:yaml.org,2002:omap': omap,
27985
28053
  'tag:yaml.org,2002:pairs': pairs,
27986
28054
  'tag:yaml.org,2002:set': set,
27987
28055
  'tag:yaml.org,2002:timestamp': timestamp
27988
28056
  };
27989
- function getTags(customTags, schemaName) {
27990
- let tags = schemas.get(schemaName);
28057
+ function getTags(customTags, schemaName, addMergeTag) {
28058
+ const schemaTags = schemas.get(schemaName);
28059
+ if (schemaTags && !customTags) {
28060
+ return addMergeTag && !schemaTags.includes(merge)
28061
+ ? schemaTags.concat(merge)
28062
+ : schemaTags.slice();
28063
+ }
28064
+ let tags = schemaTags;
27991
28065
  if (!tags) {
27992
28066
  if (Array.isArray(customTags))
27993
28067
  tags = [];
@@ -28006,17 +28080,21 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28006
28080
  else if (typeof customTags === 'function') {
28007
28081
  tags = customTags(tags.slice());
28008
28082
  }
28009
- return tags.map(tag => {
28010
- if (typeof tag !== 'string')
28011
- return tag;
28012
- const tagObj = tagsByName[tag];
28013
- if (tagObj)
28014
- return tagObj;
28015
- const keys = Object.keys(tagsByName)
28016
- .map(key => JSON.stringify(key))
28017
- .join(', ');
28018
- throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
28019
- });
28083
+ if (addMergeTag)
28084
+ tags = tags.concat(merge);
28085
+ return tags.reduce((tags, tag) => {
28086
+ const tagObj = typeof tag === 'string' ? tagsByName[tag] : tag;
28087
+ if (!tagObj) {
28088
+ const tagName = JSON.stringify(tag);
28089
+ const keys = Object.keys(tagsByName)
28090
+ .map(key => JSON.stringify(key))
28091
+ .join(', ');
28092
+ throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
28093
+ }
28094
+ if (!tags.includes(tagObj))
28095
+ tags.push(tagObj);
28096
+ return tags;
28097
+ }, []);
28020
28098
  }
28021
28099
 
28022
28100
  const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
@@ -28027,10 +28105,9 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28027
28105
  : compat
28028
28106
  ? getTags(null, compat)
28029
28107
  : null;
28030
- this.merge = !!merge;
28031
28108
  this.name = (typeof schema === 'string' && schema) || 'core';
28032
28109
  this.knownTags = resolveKnownTags ? coreKnownTags : {};
28033
- this.tags = getTags(customTags, this.name);
28110
+ this.tags = getTags(customTags, this.name, merge);
28034
28111
  this.toStringOptions = toStringDefaults ?? null;
28035
28112
  Object.defineProperty(this, MAP, { value: map });
28036
28113
  Object.defineProperty(this, SCALAR$1, { value: string });
@@ -28155,6 +28232,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28155
28232
  logLevel: 'warn',
28156
28233
  prettyErrors: true,
28157
28234
  strict: true,
28235
+ stringKeys: false,
28158
28236
  uniqueKeys: true,
28159
28237
  version: '1.2'
28160
28238
  }, options);
@@ -28378,7 +28456,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28378
28456
  this.directives.yaml.version = '1.1';
28379
28457
  else
28380
28458
  this.directives = new Directives({ version: '1.1' });
28381
- opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
28459
+ opt = { resolveKnownTags: false, schema: 'yaml-1.1' };
28382
28460
  break;
28383
28461
  case '1.2':
28384
28462
  case 'next':
@@ -28386,7 +28464,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28386
28464
  this.directives.yaml.version = version;
28387
28465
  else
28388
28466
  this.directives = new Directives({ version });
28389
- opt = { merge: false, resolveKnownTags: true, schema: 'core' };
28467
+ opt = { resolveKnownTags: true, schema: 'core' };
28390
28468
  break;
28391
28469
  case null:
28392
28470
  if (this.directives)
@@ -28499,7 +28577,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28499
28577
  if (/[^ ]/.test(lineStr)) {
28500
28578
  let count = 1;
28501
28579
  const end = error.linePos[1];
28502
- if (end && end.line === line && end.col > col) {
28580
+ if (end?.line === line && end.col > col) {
28503
28581
  count = Math.max(1, Math.min(end.col - col, 80 - ci));
28504
28582
  }
28505
28583
  const pointer = ' '.repeat(ci) + '^'.repeat(count);
@@ -28564,7 +28642,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28564
28642
  if (atNewline) {
28565
28643
  if (comment)
28566
28644
  comment += token.source;
28567
- else
28645
+ else if (!found || indicator !== 'seq-item-ind')
28568
28646
  spaceBefore = true;
28569
28647
  }
28570
28648
  else
@@ -28581,8 +28659,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28581
28659
  if (token.source.endsWith(':'))
28582
28660
  onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
28583
28661
  anchor = token;
28584
- if (start === null)
28585
- start = token.offset;
28662
+ start ?? (start = token.offset);
28586
28663
  atNewline = false;
28587
28664
  hasSpace = false;
28588
28665
  reqSpace = true;
@@ -28591,8 +28668,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28591
28668
  if (tag)
28592
28669
  onError(token, 'MULTIPLE_TAGS', 'A node can have at most one tag');
28593
28670
  tag = token;
28594
- if (start === null)
28595
- start = token.offset;
28671
+ start ?? (start = token.offset);
28596
28672
  atNewline = false;
28597
28673
  hasSpace = false;
28598
28674
  reqSpace = true;
@@ -28705,11 +28781,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28705
28781
  return false;
28706
28782
  const isEqual = typeof uniqueKeys === 'function'
28707
28783
  ? uniqueKeys
28708
- : (a, b) => a === b ||
28709
- (isScalar$1(a) &&
28710
- isScalar$1(b) &&
28711
- a.value === b.value &&
28712
- !(a.value === '<<' && ctx.schema.merge));
28784
+ : (a, b) => a === b || (isScalar$1(a) && isScalar$1(b) && a.value === b.value);
28713
28785
  return items.some(pair => isEqual(pair.key, search));
28714
28786
  }
28715
28787
 
@@ -28758,12 +28830,14 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28758
28830
  onError(offset, 'BAD_INDENT', startColMsg);
28759
28831
  }
28760
28832
  // key value
28833
+ ctx.atKey = true;
28761
28834
  const keyStart = keyProps.end;
28762
28835
  const keyNode = key
28763
28836
  ? composeNode(ctx, key, keyProps, onError)
28764
28837
  : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
28765
28838
  if (ctx.schema.compat)
28766
28839
  flowIndentCheck(bm.indent, key, onError);
28840
+ ctx.atKey = false;
28767
28841
  if (mapIncludes(ctx, map.items, keyNode))
28768
28842
  onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
28769
28843
  // value properties
@@ -28823,6 +28897,8 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28823
28897
  const seq = new NodeClass(ctx.schema);
28824
28898
  if (ctx.atRoot)
28825
28899
  ctx.atRoot = false;
28900
+ if (ctx.atKey)
28901
+ ctx.atKey = false;
28826
28902
  let offset = bs.offset;
28827
28903
  let commentEnd = null;
28828
28904
  for (const { start, value } of bs.items) {
@@ -28836,7 +28912,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28836
28912
  });
28837
28913
  if (!props.found) {
28838
28914
  if (props.anchor || props.tag || value) {
28839
- if (value && value.type === 'block-seq')
28915
+ if (value?.type === 'block-seq')
28840
28916
  onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
28841
28917
  else
28842
28918
  onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
@@ -28907,6 +28983,8 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28907
28983
  const atRoot = ctx.atRoot;
28908
28984
  if (atRoot)
28909
28985
  ctx.atRoot = false;
28986
+ if (ctx.atKey)
28987
+ ctx.atKey = false;
28910
28988
  let offset = fc.offset + fc.start.source.length;
28911
28989
  for (let i = 0; i < fc.items.length; ++i) {
28912
28990
  const collItem = fc.items[i];
@@ -28986,12 +29064,14 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
28986
29064
  else {
28987
29065
  // item is a key+value pair
28988
29066
  // key value
29067
+ ctx.atKey = true;
28989
29068
  const keyStart = props.end;
28990
29069
  const keyNode = key
28991
29070
  ? composeNode(ctx, key, props, onError)
28992
29071
  : composeEmptyNode(ctx, keyStart, start, null, props, onError);
28993
29072
  if (isBlock(key))
28994
29073
  onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
29074
+ ctx.atKey = false;
28995
29075
  // value properties
28996
29076
  const valueProps = resolveProps(sep ?? [], {
28997
29077
  flow: fcName,
@@ -29018,7 +29098,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29018
29098
  }
29019
29099
  }
29020
29100
  else if (value) {
29021
- if ('source' in value && value.source && value.source[0] === ':')
29101
+ if ('source' in value && value.source?.[0] === ':')
29022
29102
  onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
29023
29103
  else
29024
29104
  onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
@@ -29062,7 +29142,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29062
29142
  const expectedEnd = isMap ? '}' : ']';
29063
29143
  const [ce, ...ee] = fc.end;
29064
29144
  let cePos = offset;
29065
- if (ce && ce.source === expectedEnd)
29145
+ if (ce?.source === expectedEnd)
29066
29146
  cePos = ce.offset + ce.source.length;
29067
29147
  else {
29068
29148
  const name = fcName[0].toUpperCase() + fcName.substring(1);
@@ -29142,13 +29222,13 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29142
29222
  let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
29143
29223
  if (!tag) {
29144
29224
  const kt = ctx.schema.knownTags[tagName];
29145
- if (kt && kt.collection === expType) {
29225
+ if (kt?.collection === expType) {
29146
29226
  ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
29147
29227
  tag = kt;
29148
29228
  }
29149
29229
  else {
29150
- if (kt?.collection) {
29151
- onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection}`, true);
29230
+ if (kt) {
29231
+ onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection ?? 'scalar'}`, true);
29152
29232
  }
29153
29233
  else {
29154
29234
  onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);
@@ -29504,7 +29584,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29504
29584
  next = source[++i + 1];
29505
29585
  }
29506
29586
  else if (next === 'x' || next === 'u' || next === 'U') {
29507
- const length = { x: 2, u: 4, U: 8 }[next];
29587
+ const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
29508
29588
  res += parseCharCode(source, i + 1, length, onError);
29509
29589
  i += length;
29510
29590
  }
@@ -29574,12 +29654,14 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29574
29654
  const cc = source.substr(offset, length);
29575
29655
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
29576
29656
  const code = ok ? parseInt(cc, 16) : NaN;
29577
- if (isNaN(code)) {
29657
+ try {
29658
+ return String.fromCodePoint(code);
29659
+ }
29660
+ catch {
29578
29661
  const raw = source.substr(offset - 2, length + 2);
29579
29662
  onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
29580
29663
  return raw;
29581
29664
  }
29582
- return String.fromCodePoint(code);
29583
29665
  }
29584
29666
 
29585
29667
  function composeScalar(ctx, token, tagToken, onError) {
@@ -29589,11 +29671,16 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29589
29671
  const tagName = tagToken
29590
29672
  ? ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg))
29591
29673
  : null;
29592
- const tag = tagToken && tagName
29593
- ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
29594
- : token.type === 'scalar'
29595
- ? findScalarTagByTest(ctx, value, token, onError)
29596
- : ctx.schema[SCALAR$1];
29674
+ let tag;
29675
+ if (ctx.options.stringKeys && ctx.atKey) {
29676
+ tag = ctx.schema[SCALAR$1];
29677
+ }
29678
+ else if (tagName)
29679
+ tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
29680
+ else if (token.type === 'scalar')
29681
+ tag = findScalarTagByTest(ctx, value, token, onError);
29682
+ else
29683
+ tag = ctx.schema[SCALAR$1];
29597
29684
  let scalar;
29598
29685
  try {
29599
29686
  const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
@@ -29641,8 +29728,9 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29641
29728
  onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
29642
29729
  return schema[SCALAR$1];
29643
29730
  }
29644
- function findScalarTagByTest({ directives, schema }, value, token, onError) {
29645
- const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[SCALAR$1];
29731
+ function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
29732
+ const tag = schema.tags.find(tag => (tag.default === true || (atKey && tag.default === 'key')) &&
29733
+ tag.test?.test(value)) || schema[SCALAR$1];
29646
29734
  if (schema.compat) {
29647
29735
  const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
29648
29736
  schema[SCALAR$1];
@@ -29658,8 +29746,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29658
29746
 
29659
29747
  function emptyScalarPosition(offset, before, pos) {
29660
29748
  if (before) {
29661
- if (pos === null)
29662
- pos = before.length;
29749
+ pos ?? (pos = before.length);
29663
29750
  for (let i = pos - 1; i >= 0; --i) {
29664
29751
  let st = before[i];
29665
29752
  switch (st.type) {
@@ -29684,6 +29771,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29684
29771
 
29685
29772
  const CN = { composeNode, composeEmptyNode };
29686
29773
  function composeNode(ctx, token, props, onError) {
29774
+ const atKey = ctx.atKey;
29687
29775
  const { spaceBefore, comment, anchor, tag } = props;
29688
29776
  let node;
29689
29777
  let isSrcToken = true;
@@ -29704,21 +29792,36 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29704
29792
  case 'block-map':
29705
29793
  case 'block-seq':
29706
29794
  case 'flow-collection':
29707
- node = composeCollection(CN, ctx, token, props, onError);
29708
- if (anchor)
29709
- node.anchor = anchor.source.substring(1);
29795
+ try {
29796
+ node = composeCollection(CN, ctx, token, props, onError);
29797
+ if (anchor)
29798
+ node.anchor = anchor.source.substring(1);
29799
+ }
29800
+ catch (error) {
29801
+ // Almost certainly here due to a stack overflow
29802
+ const message = error instanceof Error ? error.message : String(error);
29803
+ onError(token, 'RESOURCE_EXHAUSTION', message);
29804
+ }
29710
29805
  break;
29711
29806
  default: {
29712
29807
  const message = token.type === 'error'
29713
29808
  ? token.message
29714
29809
  : `Unsupported token (type: ${token.type})`;
29715
29810
  onError(token, 'UNEXPECTED_TOKEN', message);
29716
- node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
29717
29811
  isSrcToken = false;
29718
29812
  }
29719
29813
  }
29814
+ node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError));
29720
29815
  if (anchor && node.anchor === '')
29721
29816
  onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
29817
+ if (atKey &&
29818
+ ctx.options.stringKeys &&
29819
+ (!isScalar$1(node) ||
29820
+ typeof node.value !== 'string' ||
29821
+ (node.tag && node.tag !== 'tag:yaml.org,2002:str'))) {
29822
+ const msg = 'With stringKeys, all keys must be strings';
29823
+ onError(tag ?? token, 'NON_STRING_KEY', msg);
29824
+ }
29722
29825
  if (spaceBefore)
29723
29826
  node.spaceBefore = true;
29724
29827
  if (comment) {
@@ -29771,6 +29874,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29771
29874
  const opts = Object.assign({ _directives: directives }, options);
29772
29875
  const doc = new Document(undefined, opts);
29773
29876
  const ctx = {
29877
+ atKey: false,
29774
29878
  atRoot: true,
29775
29879
  directives: doc.directives,
29776
29880
  options: doc.options,
@@ -29892,8 +29996,10 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
29892
29996
  }
29893
29997
  }
29894
29998
  if (afterDoc) {
29895
- Array.prototype.push.apply(doc.errors, this.errors);
29896
- Array.prototype.push.apply(doc.warnings, this.warnings);
29999
+ for (let i = 0; i < this.errors.length; ++i)
30000
+ doc.errors.push(this.errors[i]);
30001
+ for (let i = 0; i < this.warnings.length; ++i)
30002
+ doc.warnings.push(this.warnings[i]);
29897
30003
  }
29898
30004
  else {
29899
30005
  doc.errors = this.errors;
@@ -30796,7 +30902,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
30796
30902
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
30797
30903
  this.indentNext = this.indentValue + 1;
30798
30904
  this.indentValue += n;
30799
- return yield* this.parseBlockStart();
30905
+ return 'block-start';
30800
30906
  }
30801
30907
  return 'doc';
30802
30908
  }
@@ -31117,32 +31223,36 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31117
31223
  return 0;
31118
31224
  }
31119
31225
  *pushIndicators() {
31120
- switch (this.charAt(0)) {
31121
- case '!':
31122
- return ((yield* this.pushTag()) +
31123
- (yield* this.pushSpaces(true)) +
31124
- (yield* this.pushIndicators()));
31125
- case '&':
31126
- return ((yield* this.pushUntil(isNotAnchorChar)) +
31127
- (yield* this.pushSpaces(true)) +
31128
- (yield* this.pushIndicators()));
31129
- case '-': // this is an error
31130
- case '?': // this is an error outside flow collections
31131
- case ':': {
31132
- const inFlow = this.flowLevel > 0;
31133
- const ch1 = this.charAt(1);
31134
- if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
31135
- if (!inFlow)
31136
- this.indentNext = this.indentValue + 1;
31137
- else if (this.flowKey)
31138
- this.flowKey = false;
31139
- return ((yield* this.pushCount(1)) +
31140
- (yield* this.pushSpaces(true)) +
31141
- (yield* this.pushIndicators()));
31226
+ let n = 0;
31227
+ loop: while (true) {
31228
+ switch (this.charAt(0)) {
31229
+ case '!':
31230
+ n += yield* this.pushTag();
31231
+ n += yield* this.pushSpaces(true);
31232
+ continue loop;
31233
+ case '&':
31234
+ n += yield* this.pushUntil(isNotAnchorChar);
31235
+ n += yield* this.pushSpaces(true);
31236
+ continue loop;
31237
+ case '-': // this is an error
31238
+ case '?': // this is an error outside flow collections
31239
+ case ':': {
31240
+ const inFlow = this.flowLevel > 0;
31241
+ const ch1 = this.charAt(1);
31242
+ if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
31243
+ if (!inFlow)
31244
+ this.indentNext = this.indentValue + 1;
31245
+ else if (this.flowKey)
31246
+ this.flowKey = false;
31247
+ n += yield* this.pushCount(1);
31248
+ n += yield* this.pushSpaces(true);
31249
+ continue loop;
31250
+ }
31142
31251
  }
31143
31252
  }
31253
+ break loop;
31144
31254
  }
31145
- return 0;
31255
+ return n;
31146
31256
  }
31147
31257
  *pushTag() {
31148
31258
  if (this.charAt(1) === '<') {
@@ -31304,6 +31414,14 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31304
31414
  }
31305
31415
  return prev.splice(i, prev.length);
31306
31416
  }
31417
+ function arrayPushArray(target, source) {
31418
+ // May exhaust call stack with large `source` array
31419
+ if (source.length < 1e5)
31420
+ Array.prototype.push.apply(target, source);
31421
+ else
31422
+ for (let i = 0; i < source.length; ++i)
31423
+ target.push(source[i]);
31424
+ }
31307
31425
  function fixFlowSeqItems(fc) {
31308
31426
  if (fc.start.type === 'flow-seq-start') {
31309
31427
  for (const it of fc.items) {
@@ -31316,12 +31434,12 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31316
31434
  delete it.key;
31317
31435
  if (isFlowToken(it.value)) {
31318
31436
  if (it.value.end)
31319
- Array.prototype.push.apply(it.value.end, it.sep);
31437
+ arrayPushArray(it.value.end, it.sep);
31320
31438
  else
31321
31439
  it.value.end = it.sep;
31322
31440
  }
31323
31441
  else
31324
- Array.prototype.push.apply(it.start, it.sep);
31442
+ arrayPushArray(it.start, it.sep);
31325
31443
  delete it.sep;
31326
31444
  }
31327
31445
  }
@@ -31463,7 +31581,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31463
31581
  }
31464
31582
  *step() {
31465
31583
  const top = this.peek(1);
31466
- if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
31584
+ if (this.type === 'doc-end' && top?.type !== 'doc-end') {
31467
31585
  while (this.stack.length > 0)
31468
31586
  yield* this.pop();
31469
31587
  this.stack.push({
@@ -31739,7 +31857,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31739
31857
  const prev = map.items[map.items.length - 2];
31740
31858
  const end = prev?.value?.end;
31741
31859
  if (Array.isArray(end)) {
31742
- Array.prototype.push.apply(end, it.start);
31860
+ arrayPushArray(end, it.start);
31743
31861
  end.push(this.sourceToken);
31744
31862
  map.items.pop();
31745
31863
  return;
@@ -31905,7 +32023,20 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31905
32023
  default: {
31906
32024
  const bv = this.startBlockValue(map);
31907
32025
  if (bv) {
31908
- if (atMapIndent && bv.type !== 'block-seq') {
32026
+ if (bv.type === 'block-seq') {
32027
+ if (!it.explicitKey &&
32028
+ it.sep &&
32029
+ !includesToken(it.sep, 'newline')) {
32030
+ yield* this.pop({
32031
+ type: 'error',
32032
+ offset: this.offset,
32033
+ message: 'Unexpected block-seq-ind on same line with key',
32034
+ source: this.source
32035
+ });
32036
+ return;
32037
+ }
32038
+ }
32039
+ else if (atMapIndent) {
31909
32040
  map.items.push({ start });
31910
32041
  }
31911
32042
  this.stack.push(bv);
@@ -31941,7 +32072,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31941
32072
  const prev = seq.items[seq.items.length - 2];
31942
32073
  const end = prev?.value?.end;
31943
32074
  if (Array.isArray(end)) {
31944
- Array.prototype.push.apply(end, it.start);
32075
+ arrayPushArray(end, it.start);
31945
32076
  end.push(this.sourceToken);
31946
32077
  seq.items.pop();
31947
32078
  return;
@@ -31982,7 +32113,7 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
31982
32113
  do {
31983
32114
  yield* this.pop();
31984
32115
  top = this.peek(1);
31985
- } while (top && top.type === 'flow-collection');
32116
+ } while (top?.type === 'flow-collection');
31986
32117
  }
31987
32118
  else if (fc.end.length === 0) {
31988
32119
  switch (this.type) {
@@ -32276,6 +32407,8 @@ query GetEurekaResults($params: Input_eureka_SearchRequest) {
32276
32407
  if (!keepUndefined)
32277
32408
  return undefined;
32278
32409
  }
32410
+ if (isDocument(value) && !_replacer)
32411
+ return value.toString(options);
32279
32412
  return new Document(value, _replacer, options).toString(options);
32280
32413
  }
32281
32414