@decimalturn/toml-patch 0.4.1 → 0.5.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/README.md CHANGED
@@ -10,6 +10,9 @@ Note that this is a maintenance fork of the original toml-patch package. This fo
10
10
  Hopefully, the work done here can go upstream one day if timhall returns, but until then, welcome aboard![^1]
11
11
 
12
12
 
13
+ **What's New in v0.5.0:**
14
+ - **truncateZeroTimeInDates option**: New formatting option to automatically serialize JavaScript Date objects with zero time components (midnight) as date-only values in TOML (`2024-01-15T00:00:00.000Z → 2024-01-15`).
15
+
13
16
  **What's New in v0.4.0:**
14
17
  - **TomlDocument class**: A new document-oriented API for stateful TOML manipulation
15
18
  - **TomlFormat class**: A class encapsulating all TOML formatting options
@@ -37,13 +40,13 @@ Note: The functional API (`patch`, `parse`, `stringify`) remains fully compatibl
37
40
  - [patch() Example](#patch-example)
38
41
  - [update() Example](#update-example)
39
42
  - [When to Use](#when-to-use-tomldocument-vs-functional-api)
40
- - [Formatting](#formatting)
41
- - [TomlFormat Class](#tomlformat-class)
42
- - [Basic Usage](#basic-usage)
43
- - [Formatting Options](#formatting-options)
44
- - [Auto-Detection and Patching](#auto-detection-and-patching)
45
- - [Complete Example](#complete-example)
46
- - [Legacy Format Objects](#legacy-format-objects)
43
+ - [Formatting](#formatting)
44
+ - [TomlFormat Class](#tomlformat-class)
45
+ - [Basic Usage](#basic-usage)
46
+ - [Formatting Options](#formatting-options)
47
+ - [Auto-Detection and Patching](#auto-detection-and-patching)
48
+ - [Complete Example](#complete-example)
49
+ - [Legacy Format Objects](#legacy-format-objects)
47
50
  - [Development](#development)
48
51
 
49
52
 
@@ -204,8 +207,7 @@ Converts a JavaScript object to a TOML string.
204
207
 
205
208
  **Format Options:**
206
209
 
207
- - `[trailingComma = false]` - Add trailing comma to inline tables
208
- - `[bracketSpacing = true]` - `true`: `{ key = "value" }`, `false`: `{key = "value"}`
210
+ See [Formatting Options](#formatting-options) for more details.
209
211
 
210
212
  ##### Example
211
213
 
@@ -378,11 +380,11 @@ console.log(doc.toJsObject.server.port); // 3000
378
380
  | Preserving document state | ✅ Built-in | ❌ Manual |
379
381
  | Working with large files | ✅ Better performance | ❌ Re-parses entirely |
380
382
 
381
- ### Formatting
383
+ ## Formatting
382
384
 
383
385
  The `TomlFormat` class provides comprehensive control over how TOML documents are formatted during stringification and patching operations. This class encapsulates all formatting preferences, making it easy to maintain consistent styling across your TOML documents.
384
386
 
385
- #### TomlFormat Class
387
+ ### TomlFormat Class
386
388
 
387
389
  ```typescript
388
390
  class TomlFormat {
@@ -391,13 +393,14 @@ class TomlFormat {
391
393
  trailingComma: boolean
392
394
  bracketSpacing: boolean
393
395
  inlineTableStart?: number
396
+ truncateZeroTimeInDates: boolean
394
397
 
395
398
  static default(): TomlFormat
396
399
  static autoDetectFormat(tomlString: string): TomlFormat
397
400
  }
398
401
  ```
399
402
 
400
- #### Basic Usage
403
+ ### Basic Usage
401
404
 
402
405
  The recommended approach is to start with `TomlFormat.default()` and override specific options as needed:
403
406
 
@@ -420,7 +423,7 @@ const toml = stringify({
420
423
 
421
424
  ```
422
425
 
423
- #### Formatting Options
426
+ ### Formatting Options
424
427
 
425
428
  **newLine**
426
429
  - **Type:** `string`
@@ -500,14 +503,43 @@ stringify({ database: { host: 'localhost', port: 5432 } }, format);
500
503
  // port = 5432
501
504
  ```
502
505
 
503
- #### Auto-Detection and Patching
506
+ **truncateZeroTimeInDates**
507
+ - **Type:** `boolean`
508
+ - **Default:** `false`
509
+ - **Description:** When `true`, JavaScript Date objects with all time components set to zero (midnight UTC) are automatically serialized as date-only values in TOML. This only affects new values during stringify operations; existing TOML dates maintain their original format during patch operations.
510
+
511
+ ```js
512
+ const format = TomlFormat.default();
513
+ format.truncateZeroTimeInDates = false; // new Date('2024-01-15T00:00:00.000Z') → 2024-01-15T00:00:00.000Z
514
+ format.truncateZeroTimeInDates = true; // new Date('2024-01-15T00:00:00.000Z') → 2024-01-15
515
+ ```
516
+
517
+ Example with mixed dates:
518
+ ```js
519
+ import { stringify, TomlFormat } from '@decimalturn/toml-patch';
520
+
521
+ const format = TomlFormat.default();
522
+ format.truncateZeroTimeInDates = true;
523
+
524
+ const data = {
525
+ startDate: new Date('2024-01-15T00:00:00.000Z'), // Will be: 2024-01-15
526
+ endDate: new Date('2024-12-31T23:59:59.999Z') // Will be: 2024-12-31T23:59:59.999Z
527
+ };
528
+
529
+ stringify(data, format);
530
+ // Output:
531
+ // startDate = 2024-01-15
532
+ // endDate = 2024-12-31T23:59:59.999Z
533
+ ```
534
+
535
+ ### Auto-Detection and Patching
504
536
 
505
537
  The `TomlFormat.autoDetectFormat()` method analyzes existing TOML strings to automatically detect and preserve their current formatting. If you don't supply the `format` argument when patching an existing document, this is what will be used to determine the formatting to use when inserting new elements.
506
538
 
507
539
  Note that formatting of existing elements of a TOML string won't be affected by the `format` passed to `patch()` except for `newLine` and `trailingNewline` which are applied at the document level.
508
540
 
509
541
 
510
- #### Complete Example
542
+ ### Complete Example
511
543
 
512
544
  Here's a comprehensive example showing different formatting configurations:
513
545
 
@@ -579,7 +611,7 @@ console.log(stringify(data, windows));
579
611
  // Same structure as compact but with \r\n line endings
580
612
  ```
581
613
 
582
- #### Legacy Format Objects
614
+ ### Legacy Format Objects
583
615
 
584
616
  For backward compatibility, you can still use anonymous objects for formatting options.
585
617
  ```js
@@ -1,3 +1,3 @@
1
- //! @decimalturn/toml-patch v0.4.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- "use strict";var e,t;function n(t){return t.type===e.Document}function r(t){return t.type===e.Table}function l(t){return t.type===e.TableArray}function o(t){return t.type===e.KeyValue}function i(t){return t.type===e.DateTime}function a(t){return t.type===e.InlineArray}function s(t){return t.type===e.InlineItem}function c(t){return t.type===e.InlineTable}function u(t){return t.type===e.Comment}function f(e){return n(e)||r(e)||l(e)||c(e)||a(e)}function m(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||s(t)}!function(e){e.Document="Document",e.Table="Table",e.TableKey="TableKey",e.TableArray="TableArray",e.TableArrayKey="TableArrayKey",e.KeyValue="KeyValue",e.Key="Key",e.String="String",e.Integer="Integer",e.Float="Float",e.Boolean="Boolean",e.DateTime="DateTime",e.InlineArray="InlineArray",e.InlineItem="InlineItem",e.InlineTable="InlineTable",e.Comment="Comment"}(e||(e={}));class d{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return p();const t=this.peeked||this.iterator.next();return this.index+=1,this.value=t.value,this.done=null!==(e=t.done)&&void 0!==e&&e,this.peeked=null,t}peek(){return this.done?p():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}function p(){return{value:void 0,done:!0}}function y(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function h(e,t){const n=Array.isArray(e)?e:g(e),r=n.findIndex((e=>e>=t))+1;return{line:r,column:t-(n[r-2]+1||0)}}function g(e){const t=/\r\n|\n/g,n=[];let r;for(;null!=(r=t.exec(e));)n.push(r.index+r[0].length-1);return n.push(e.length+1),n}function v(e){return{line:e.line,column:e.column}}function w(e){return{start:v(e.start),end:v(e.end)}}class S extends Error{constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=g(e),r=n[t.line-2]||0,l=n[t.line-1]||e.length;return e.substr(r,l-r)}(e,t),l=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(r+=`${n}\n${l}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}}!function(e){e.Bracket="Bracket",e.Curly="Curly",e.Equal="Equal",e.Comma="Comma",e.Dot="Dot",e.Comment="Comment",e.Literal="Literal"}(t||(t={}));const T=/\s/,b=/(\r\n|\n)/,$='"',k="'",I=/[\w,\d,\",\',\+,\-,\_]/;function*E(e){const n=new d(e[Symbol.iterator]());n.next();const r=function(e){const t=g(e);return(e,n)=>({start:h(t,e),end:h(t,n)})}(e);for(;!n.done;){if(T.test(n.value));else if("["===n.value||"]"===n.value)yield A(n,r,t.Bracket);else if("{"===n.value||"}"===n.value)yield A(n,r,t.Curly);else if("="===n.value)yield A(n,r,t.Equal);else if(","===n.value)yield A(n,r,t.Comma);else if("."===n.value)yield A(n,r,t.Dot);else if("#"===n.value)yield x(n,r);else{const t=_(e,n.index,k)||_(e,n.index,$);t?yield C(n,r,t,e):yield O(n,r,e)}n.next()}}function A(e,t,n){return{type:n,raw:e.value,loc:t(e.index,e.index+1)}}function x(e,n){const r=e.index;let l=e.value;for(;!e.peek().done&&!b.test(e.peek().value);)e.next(),l+=e.value;return{type:t.Comment,raw:l,loc:n(r,e.index+1)}}function C(e,n,r,l){const o=e.index;let i=r+r+r,a=i;for(e.next(),e.next(),e.next();!e.done&&(!_(l,e.index,r)||D(l,e.index,r));)a+=e.value,e.next();if(e.done)throw new S(l,h(l,e.index),`Expected close of multiline string with ${i}, reached end of file`);return a+=i,e.next(),e.next(),{type:t.Literal,raw:a,loc:n(o,e.index+1)}}function O(e,n,r){if(!I.test(e.value))throw new S(r,h(r,e.index),`Unsupported character "${e.value}". Expected ALPHANUMERIC, ", ', +, -, or _`);const l=e.index;let o=e.value,i=e.value===$,a=e.value===k;const s=e=>{if(e.peek().done)return!0;const t=e.peek().value;return!(i||a)&&(T.test(t)||","===t||"."===t||"]"===t||"}"===t||"="===t||"#"===t)};for(;!e.done&&!s(e)&&(e.next(),e.value===$&&(i=!i),e.value!==k||i||(a=!a),o+=e.value,!e.peek().done);){let t=e.peek().value;i&&"\\"===e.value&&(t===$?(o+=$,e.next()):"\\"===t&&(o+="\\",e.next()))}if(i||a)throw new S(r,h(r,l),`Expected close of string with ${i?$:k}`);return{type:t.Literal,raw:o,loc:n(l,e.index+1)}}function _(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;const r=e.slice(0,t).match(/\\+$/);if(!r)return n;return!(r[0].length%2!=0)&&n}function D(e,t,n){return!!n&&(e[t]===n&&e[t+1]===n&&e[t+2]===n&&e[t+3]===n)}function L(e){return e[e.length-1]}function F(){return Object.create(null)}function U(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function M(e){return"[object Date]"===Object.prototype.toString.call(e)}function K(e){return e&&"object"==typeof e&&!M(e)&&!Array.isArray(e)}function j(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function N(e,...t){return t.reduce(((e,t)=>t(e)),e)}function B(e){if(K(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${B(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(B).join(",")}]`:JSON.stringify(e)}function P(e,t){const n=e.length,r=t.length;e.length=n+r;for(let l=0;l<r;l++)e[n+l]=t[l]}const Z=/\r\n/g,W=/\n/g,z=/^(\r\n|\n)/,V=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function q(e){return e.startsWith("'''")?N(Y(e,3),J):e.startsWith(k)?Y(e,1):e.startsWith('"""')?N(Y(e,3),J,Q,G,H,R):e.startsWith($)?N(Y(e,1),R):e}function H(e){let t="",n=0;for(let r=0;r<e.length;r++){const l=e[r];t+='"'===l&&n%2==0?'\\"':l,"\\"===l?n++:n=0}return t}function R(e){const t=e.replace(/\\U[a-fA-F0-9]{8}/g,(e=>{const t=parseInt(e.replace("\\U",""),16),n=String.fromCodePoint(t);return Y(JSON.stringify(n),1)})),n=t.replace(/\t/g,"\\t");return JSON.parse(`"${n}"`)}function Y(e,t){return e.slice(t,e.length-t)}function J(e){return e.replace(z,"")}function G(e){return e.replace(Z,"\\r\\n").replace(W,"\\n")}function Q(e){return e.replace(V,((e,t)=>e.replace(t,"")))}class X{static createDateWithOriginalFormat(e,t){if(X.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof re)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new ne(t,!1)}const t=e.toISOString().split("T")[0];return new ee(t)}if(X.IS_TIME_ONLY.test(t)){if(e instanceof te)return e;{const n=t.match(/\.(\d+)\s*$/),r=e.toISOString();if(r&&r.includes("T")){let l=r.split("T")[1].split("Z")[0];if(n){const t=n[1].length,[r,o,i]=l.split(":"),[a]=i.split(".");l=`${r}:${o}:${a}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new te(l,t)}{const r=String(e.getUTCHours()).padStart(2,"0"),l=String(e.getUTCMinutes()).padStart(2,"0"),o=String(e.getUTCSeconds()).padStart(2,"0"),i=e.getUTCMilliseconds();let a;if(n){const e=n[1].length;a=`${r}:${l}:${o}.${String(i).padStart(3,"0").slice(0,e)}`}else if(i>0){a=`${r}:${l}:${o}.${String(i).padStart(3,"0").replace(/0+$/,"")}`}else a=`${r}:${l}:${o}`;return new te(a,t)}}}if(X.IS_LOCAL_DATETIME_T.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","");if(n){const t=n[1].length,[l,o]=r.split("T"),[i,a,s]=o.split(":"),[c]=s.split(".");r=`${l}T${i}:${a}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new ne(r,!1,t)}if(X.IS_LOCAL_DATETIME_SPACE.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","").replace("T"," ");if(n){const t=n[1].length,[l,o]=r.split(" "),[i,a,s]=o.split(":"),[c]=s.split(".");r=`${l} ${i}:${a}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new ne(r,!0,t)}if(X.IS_OFFSET_DATETIME_T.test(t)||X.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),r=n?"z"===n[1]?"Z":n[1]:"Z",l=X.IS_OFFSET_DATETIME_SPACE.test(t),o=t.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),i=e.getTime();let a=0;if("Z"!==r){const e="+"===r[0]?1:-1,[t,n]=r.slice(1).split(":");a=e*(60*parseInt(t)+parseInt(n))}const s=new Date(i+6e4*a),c=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),m=String(s.getUTCHours()).padStart(2,"0"),d=String(s.getUTCMinutes()).padStart(2,"0"),p=String(s.getUTCSeconds()).padStart(2,"0"),y=s.getUTCMilliseconds(),h=l?" ":"T";let g=`${m}:${d}:${p}`;if(o){const e=o[1].length;g+=`.${String(y).padStart(3,"0").slice(0,e)}`}else if(y>0){g+=`.${String(y).padStart(3,"0").replace(/0+$/,"")}`}return new re(`${c}-${u}-${f}${h}${g}${r}`,l)}return e}}X.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,X.IS_TIME_ONLY=/^\d{2}:\d{2}:\d{2}(?:\.\d+)?$/,X.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$/,X.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?$/,X.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,X.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,X.IS_FULL_DATE=/(\d{4})-(\d{2})-(\d{2})/,X.IS_FULL_TIME=/(\d{2}):(\d{2}):(\d{2})/;class ee extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class te extends Date{constructor(e,t){super(`1970-01-01T${e}`),this.originalFormat=t}toISOString(){const e=String(this.getUTCHours()).padStart(2,"0"),t=String(this.getUTCMinutes()).padStart(2,"0"),n=String(this.getUTCSeconds()).padStart(2,"0"),r=this.getUTCMilliseconds();if(this.originalFormat&&this.originalFormat.includes(".")){const l=this.originalFormat.match(/\.(\d+)\s*$/),o=l?l[1].length:3;return`${e}:${t}:${n}.${String(r).padStart(3,"0").slice(0,o)}`}if(r>0){return`${e}:${t}:${n}.${String(r).padStart(3,"0").replace(/0+$/,"")}`}return`${e}:${t}:${n}`}}class ne extends Date{constructor(e,t=!1,n){super(e.replace(" ","T")+"Z"),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=this.getUTCFullYear(),t=String(this.getUTCMonth()+1).padStart(2,"0"),n=String(this.getUTCDate()).padStart(2,"0"),r=String(this.getUTCHours()).padStart(2,"0"),l=String(this.getUTCMinutes()).padStart(2,"0"),o=String(this.getUTCSeconds()).padStart(2,"0"),i=this.getUTCMilliseconds(),a=`${e}-${t}-${n}`,s=this.useSpaceSeparator?" ":"T";if(this.originalFormat&&this.originalFormat.includes(".")){const e=this.originalFormat.match(/\.(\d+)\s*$/),t=e?e[1].length:3;return`${a}${s}${r}:${l}:${o}.${String(i).padStart(3,"0").slice(0,t)}`}if(i>0){return`${a}${s}${r}:${l}:${o}.${String(i).padStart(3,"0").replace(/0+$/,"")}`}return`${a}${s}${r}:${l}:${o}`}}class re extends Date{constructor(e,t=!1){super(e.replace(" ","T")),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=e;const n=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);n&&(this.originalOffset="z"===n[1]?"Z":n[1])}toISOString(){if(this.originalOffset){const e=this.getTime();let t=0;if("Z"!==this.originalOffset){const e="+"===this.originalOffset[0]?1:-1,[n,r]=this.originalOffset.slice(1).split(":");t=e*(60*parseInt(n)+parseInt(r))}const n=new Date(e+6e4*t),r=n.getUTCFullYear(),l=String(n.getUTCMonth()+1).padStart(2,"0"),o=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),s=String(n.getUTCSeconds()).padStart(2,"0"),c=n.getUTCMilliseconds(),u=`${r}-${l}-${o}`,f=this.useSpaceSeparator?" ":"T";if(this.originalFormat&&this.originalFormat.includes(".")){const e=this.originalFormat.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),t=e?e[1].length:3;return`${u}${f}${i}:${a}:${s}.${String(c).padStart(3,"0").slice(0,t)}${this.originalOffset}`}if(c>0){return`${u}${f}${i}:${a}:${s}.${String(c).padStart(3,"0").replace(/0+$/,"")}${this.originalOffset}`}return`${u}${f}${i}:${a}:${s}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const le=X,oe="true",ie=/e/i,ae=/\_/g,se=/inf/,ce=/nan/,ue=/^0x/,fe=/^0o/,me=/^0b/;function*de(e){const t=E(e),n=new d(t);for(;!n.next().done;)yield*pe(n,e)}function*pe(n,r){if(n.value.type===t.Comment)yield he(n);else if(n.value.type===t.Bracket)yield function(n,r){const l=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,o=l===e.Table;if(o&&"["!==n.value.raw)throw new S(r,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!o&&("["!==n.value.raw||"["!==n.peek().value.raw))throw new S(r,n.value.loc.start,`Expected array of tables opening "[[", found ${n.value.raw+n.peek().value.raw}`);const i=o?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};n.next(),l===e.TableArray&&n.next();if(n.done)throw new S(r,i.loc.start,"Expected table key, reached end of file");i.item={type:e.Key,loc:w(n.value.loc),raw:n.value.raw,value:[q(n.value.raw)]};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=" ".repeat(e.loc.start.column-i.item.loc.end.column),r=" ".repeat(n.value.loc.start.column-e.loc.end.column);i.item.loc.end=n.value.loc.end,i.item.raw+=`${t}.${r}${n.value.raw}`,i.item.value.push(q(n.value.raw))}if(n.next(),o&&(n.done||"]"!==n.value.raw))throw new S(r,n.done?i.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!o&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new S(r,n.done||n.peek().done?i.item.loc.end:n.value.loc.start,`Expected array of tables closing "]]", found ${n.done||n.peek().done?"end of file":n.value.raw+n.peek().value.raw}`);o||n.next();i.loc.end=n.value.loc.end;let a=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;)n.next(),P(a,[...pe(n,r)]);return{type:o?e.Table:e.TableArray,loc:{start:v(i.loc.start),end:a.length?v(a[a.length-1].loc.end):v(i.loc.end)},key:i,items:a}}(n,r);else{if(n.value.type!==t.Literal)throw new S(r,n.value.loc.start,`Unexpected token "${n.value.type}". Expected Comment, Bracket, or String`);yield*function(n,r){const l={type:e.Key,loc:w(n.value.loc),raw:n.value.raw,value:[q(n.value.raw)]};for(;!n.peek().done&&n.peek().value.type===t.Dot;)n.next(),n.next(),l.loc.end=n.value.loc.end,l.raw+=`.${n.value.raw}`,l.value.push(q(n.value.raw));if(n.next(),n.done||n.value.type!==t.Equal)throw new S(r,n.done?l.loc.end:n.value.loc.start,`Expected "=" for key-value, found ${n.done?"end of file":n.value.raw}`);const o=n.value.loc.start.column;if(n.next(),n.done)throw new S(r,l.loc.start,"Expected value for key-value, reached end of file");const[i,...a]=ye(n,r);return[{type:e.KeyValue,key:l,value:i,loc:{start:v(l.loc.start),end:v(i.loc.end)},equals:o},...a]}(n,r)}}function*ye(n,r){if(n.value.type===t.Literal)n.value.raw[0]===$||n.value.raw[0]===k?yield function(t){return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:q(t.value.raw)}}(n):n.value.raw===oe||"false"===n.value.raw?yield function(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===oe}}(n):le.IS_FULL_DATE.test(n.value.raw)||le.IS_FULL_TIME.test(n.value.raw)?yield function(n,r){let l,o=n.value.loc,i=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&le.IS_FULL_DATE.test(i)&&le.IS_FULL_TIME.test(n.peek().value.raw)){const e=o.start;n.next(),o={start:e,end:n.value.loc.end},i+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=o.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new S(r,n.value.loc.end,"Expected fractional value for DateTime");n.next(),o={start:e,end:n.value.loc.end},i+=`.${n.value.raw}`}if(le.IS_FULL_DATE.test(i))l=le.IS_DATE_ONLY.test(i)?new ee(i):le.IS_LOCAL_DATETIME_T.test(i)?new ne(i,!1):le.IS_LOCAL_DATETIME_SPACE.test(i)?new ne(i,!0):le.IS_OFFSET_DATETIME_T.test(i)?new re(i,!1):le.IS_OFFSET_DATETIME_SPACE.test(i)?new re(i,!0):new Date(i.replace(" ","T"));else if(le.IS_TIME_ONLY.test(i))l=new te(i,i);else{const[e]=(new Date).toISOString().split("T");l=new Date(`${e}T${i}`)}return{type:e.DateTime,loc:o,raw:i,value:l}}(n,r):!n.peek().done&&n.peek().value.type===t.Dot||se.test(n.value.raw)||ce.test(n.value.raw)||ie.test(n.value.raw)&&!ue.test(n.value.raw)?yield function(n,r){let l,o=n.value.loc,i=n.value.raw;if(se.test(i))l="-inf"===i?-1/0:1/0;else if(ce.test(i))l=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot)l=Number(i.replace(ae,""));else{const e=o.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new S(r,n.value.loc.end,"Expected fraction value for Float");n.next(),i+=`.${n.value.raw}`,o={start:e,end:n.value.loc.end},l=Number(i.replace(ae,""))}return{type:e.Float,loc:o,raw:i,value:l}}(n,r):yield function(t){if("-0"===t.value.raw||"+0"===t.value.raw)return{type:e.Integer,loc:t.value.loc,raw:t.value.raw,value:0};let n=10;ue.test(t.value.raw)?n=16:fe.test(t.value.raw)?n=8:me.test(t.value.raw)&&(n=2);const r=parseInt(t.value.raw.replace(ae,"").replace(fe,"").replace(me,""),n);return{type:e.Integer,loc:t.value.loc,raw:t.value.raw,value:r}}(n);else if(n.value.type===t.Curly)yield function(n,r){if("{"!==n.value.raw)throw new S(r,n.value.loc.start,`Expected "{" for inline table, found ${n.value.raw}`);const l={type:e.InlineTable,loc:w(n.value.loc),items:[]};n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comma){const e=l.items[l.items.length-1];if(!e)throw new S(r,n.value.loc.start,'Found "," without previous value in inline table');e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const[o]=pe(n,r);if(o.type!==e.KeyValue)throw new S(r,n.value.loc.start,`Only key-values are supported in inline tables, found ${o.type}`);const i={type:e.InlineItem,loc:w(o.loc),item:o,comma:!1};l.items.push(i),n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new S(r,n.done?l.loc.start:n.value.loc.start,`Expected "}", found ${n.done?"end of file":n.value.raw}`);return l.loc.end=n.value.loc.end,l}(n,r);else{if(n.value.type!==t.Bracket)throw new S(r,n.value.loc.start,`Unrecognized token type "${n.value.type}". Expected String, Curly, or Bracket`);{const[l,o]=function(n,r){if("["!==n.value.raw)throw new S(r,n.value.loc.start,`Expected "[" for inline array, found ${n.value.raw}`);const l={type:e.InlineArray,loc:w(n.value.loc),items:[]};let o=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=l.items[l.items.length-1];if(!e)throw new S(r,n.value.loc.start,'Found "," without previous value for inline array');e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)o.push(he(n));else{const[t,...i]=ye(n,r),a={type:e.InlineItem,loc:w(t.loc),item:t,comma:!1};l.items.push(a),P(o,i)}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new S(r,n.done?l.loc.start:n.value.loc.start,`Expected "]", found ${n.done?"end of file":n.value.raw}`);return l.loc.end=n.value.loc.end,[l,o]}(n,r);yield l,yield*o}}}function he(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function ge(t,n){var r;function l(e,t){for(const n of e)o(n,t)}function o(t,r){const i=n[t.type];switch(i&&"function"==typeof i&&i(t,r),i&&i.enter&&i.enter(t,r),t.type){case e.Document:l(t.items,t);break;case e.Table:o(t.key,t),l(t.items,t);break;case e.TableKey:o(t.item,t);break;case e.TableArray:o(t.key,t),l(t.items,t);break;case e.TableArrayKey:o(t.item,t);break;case e.KeyValue:o(t.key,t),o(t.value,t);break;case e.InlineArray:l(t.items,t);break;case e.InlineItem:o(t.item,t);break;case e.InlineTable:l(t.items,t);break;case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:break;default:throw new Error(`Unrecognized node type "${t.type}"`)}i&&i.exit&&i.exit(t,r)}null!=(r=t)&&"function"==typeof r[Symbol.iterator]?l(t,null):o(t,null)}const ve=X,we=new WeakMap,Se=e=>(we.has(e)||we.set(e,new WeakMap),we.get(e)),Te=new WeakMap,be=e=>(Te.has(e)||Te.set(e,new WeakMap),Te.get(e));function $e(e,t,n,r){if(i(n)&&i(r)){const e=n.raw,t=r.value,l=ve.createDateWithOriginalFormat(t,e);r.value=l,r.raw=l.toISOString();0!==r.raw.length-e.length&&(r.loc.end.column=r.loc.start.column+r.raw.length)}if(f(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.items.splice(e,1,r)}else if(o(t)&&c(t.value)&&!c(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,r)}else if(m(t))t.item=r;else{if(!o(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}Oe(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const l=y(n.loc),a=y(r.loc);_e({lines:a.lines-l.lines,columns:a.columns-l.columns},be(e),r,n)}function ke(e,t,i,m,d){if(!f(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,h;m=null!=m&&"number"==typeof m?m:t.items.length,a(t)||c(t)?({shift:p,offset:h}=function(e,t,n){if(!s(t))throw new Error(`Incompatible child type "${t.type}"`);const r=null!=n?e.items[n-1]:L(e.items),l=null==n||n===e.items.length;e.items.splice(n,0,t);const o=!!r,i=!l;o&&(r.comma=!0);i&&(t.comma=!0);const c=a(e)&&function(e){if(!e.items.length)return!1;return y(e.loc).lines>e.items.length}(e),u=l&&!0===t.comma;return Ie(e,t,n,{useNewLine:c,hasCommaHandling:!0,isLastElement:l,hasSeparatingCommaBefore:o,hasSeparatingCommaAfter:i,hasTrailingComma:u})}(t,i,m)):d&&n(t)?({shift:p,offset:h}=function(e,t,n){const r=Ie(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,i,m)):({shift:p,offset:h}=function(e,t,i){if(a=t,!(o(a)||r(a)||l(a)||u(a)))throw new Error(`Incompatible child type "${t.type}"`);var a;const s=e.items[i-1],c=n(e)&&!e.items.length;e.items.splice(i,0,t);const f=s?{line:s.loc.end.line,column:u(s)?e.loc.start.column:s.loc.start.column}:v(e.loc.start),m=r(t)||l(t);let d=0;c||(d=m?2:1);f.line+=d;const p={lines:f.line-t.loc.start.line,columns:f.column-t.loc.start.column},h=y(t.loc),g={lines:h.lines+(d-1),columns:h.columns};return{shift:p,offset:g}}(t,i,m)),Oe(i,p);const g=t.items[m-1],w=g&&be(e).get(g);w&&(h.lines+=w.lines,h.columns+=w.columns,be(e).delete(g));be(e).set(i,h)}function Ie(e,t,n,r={}){const{useNewLine:l=!1,skipCommaSpace:o=2,skipBracketSpace:i=1,hasCommaHandling:a=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:f=!1,hasTrailingComma:m=!1}=r,d=n>0?e.items[n-1]:void 0,p=d?{line:d.loc.end.line,column:l?u(d)?e.loc.start.column:d.loc.start.column:d.loc.end.column}:v(e.loc.start);let h=0;if(l)h=1;else{const e=c||!a&&!!d;e&&a?p.column+=o:(e||a&&!d)&&(p.column+=i)}p.line+=h;const g={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},w=y(t.loc);if(!a){return{shift:g,offset:{lines:w.lines+(h-1),columns:w.columns}}}let S=0;c&&m&&!f&&s&&(S=-1);return{shift:g,offset:{lines:w.lines+(h-1),columns:w.columns+(c||f?o:0)+(m?1+S:0)}}}function Ee(e,t,n){if(!f(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let r=t.items.indexOf(n);if(r<0){if(r=t.items.findIndex((e=>m(e)&&e.item===n)),r<0)throw new Error("Could not find node in parent for removal");n=t.items[r]}const l=t.items[r-1];let o=t.items[r+1];t.items.splice(r,1);let i=y(n.loc);o&&u(o)&&o.loc.start.line===n.loc.end.line&&(i=y({start:n.loc.start,end:o.loc.end}),o=t.items[r+1],t.items.splice(r,1));const a=l&&s(l)||o&&s(o),c=l&&l.loc.end.line===n.loc.start.line,d=o&&o.loc.start.line===n.loc.end.line,p=a&&(c||d),h={lines:-(i.lines-(p?1:0)),columns:-i.columns};if(void 0===l&&void 0===o&&(h.lines=0,h.columns=0),a&&c&&(h.columns-=2),a&&!l&&o&&(h.columns-=2),a&&l&&!o){const e=n.comma;l.comma=!!e}const g=l||t,v=l?be(e):Se(e),w=be(e),S=v.get(g);S&&(h.lines+=S.lines,h.columns+=S.columns);const T=w.get(n);T&&(h.lines+=T.lines,h.columns+=T.columns),v.set(g,h)}function Ae(e,t,n=!0){if(!n)return;if(!t.items.length)return;_e({lines:0,columns:1},Se(e),t);const r=L(t.items);_e({lines:0,columns:1},be(e),r)}function xe(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=L(t.items);r.comma=!0,_e({lines:0,columns:1},be(e),r)}function Ce(t){const n=Se(t),r=be(t),l={lines:0,columns:{}};function o(e){const t=l.lines;e.loc.start.line+=t;const r=l.columns[e.loc.start.line]||0;e.loc.start.column+=r;const o=n.get(e);o&&(l.lines+=o.lines,l.columns[e.loc.start.line]=(l.columns[e.loc.start.line]||0)+o.columns)}function i(e){const t=l.lines;e.loc.end.line+=t;const n=l.columns[e.loc.end.line]||0;e.loc.end.column+=n;const o=r.get(e);o&&(l.lines+=o.lines,l.columns[e.loc.end.line]=(l.columns[e.loc.end.line]||0)+o.columns)}const a={enter:o,exit:i};ge(t,{[e.Document]:a,[e.Table]:a,[e.TableArray]:a,[e.InlineTable]:a,[e.InlineArray]:a,[e.InlineItem]:a,[e.TableKey]:a,[e.TableArrayKey]:a,[e.KeyValue]:{enter(e){const t=e.loc.start.line+l.lines,n=r.get(e.key);e.equals+=(l.columns[t]||0)+(n?n.columns:0),o(e)},exit:i},[e.Key]:a,[e.String]:a,[e.Integer]:a,[e.Float]:a,[e.Boolean]:a,[e.DateTime]:a,[e.Comment]:a}),we.delete(t),Te.delete(t)}function Oe(t,n,r={}){const{first_line_only:l=!1}=r,o=t.loc.start.line,{lines:i,columns:a}=n,s=e=>{l&&e.loc.start.line!==o||(e.loc.start.column+=a,e.loc.end.column+=a),e.loc.start.line+=i,e.loc.end.line+=i};return ge(t,{[e.Table]:s,[e.TableKey]:s,[e.TableArray]:s,[e.TableArrayKey]:s,[e.KeyValue](e){s(e),e.equals+=a},[e.Key]:s,[e.String]:s,[e.Integer]:s,[e.Float]:s,[e.Boolean]:s,[e.DateTime]:s,[e.InlineArray]:s,[e.InlineItem]:s,[e.InlineTable]:s,[e.Comment]:s}),t}function _e(e,t,n,r){const l=t.get(r||n);l&&(e.lines+=l.lines,e.columns+=l.columns),t.set(n,e)}function De(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Le(t){const n=function(t){const n=Ke(t);return{type:e.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:e.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:t,raw:n}}}(t);return{type:e.Table,loc:w(n.loc),key:n,items:[]}}function Fe(t){const n=function(t){const n=Ke(t);return{type:e.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:e.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:t,raw:n}}}(t);return{type:e.TableArray,loc:w(n.loc),key:n,items:[]}}function Ue(t,n){const r=function(t){const n=Ke(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:l}=r.loc.end,o=l+1;return Oe(n,{lines:0,columns:l+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:v(r.loc.start),end:v(n.loc.end)},key:r,equals:o,value:n}}const Me=/^[\w-]+$/;function Ke(e){return e.map((e=>Me.test(e)?e:JSON.stringify(e))).join(".")}function je(t){return{type:e.InlineItem,loc:w(t.loc),item:t,comma:!1}}const Ne=!1,Be=!0;function Pe(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){var n;if(!e||!e.start||!e.end)return null;const r=t.split(/\r?\n/),l=e.start.line-1,o=e.end.line-1,i=e.start.column,a=e.end.column;let s="";if(l===o)s=(null===(n=r[l])||void 0===n?void 0:n.substring(i,a+1))||"";else{r[l]&&(s+=r[l].substring(i));for(let e=l+1;e<o;e++)s+="\n"+(r[e]||"");r[o]&&(s+="\n"+r[o].substring(0,a+1))}const c=s.match(/^\[(\s*)/),u=s.match(/^\{(\s*)/);if(c)return c[1].length>0;if(u)return u[1].length>0;return null}(e.loc,t);if(null!==n)return n}if(e.items&&Array.isArray(e.items))for(const n of e.items){const e=Pe(n,t);if(null!==e)return e;if(n.item){const e=Pe(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=Pe(e[n],t);if(null!==r)return r}return null}function Ze(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return We(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return We(e.items);if("KeyValue"===e.type&&e.value)return Ze(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=Ze(t);if(null!==e)return e}return null}function We(e){if(0===e.length)return null;const t=e[e.length-1];return!(!t||"object"!=typeof t||!("comma"in t))&&!0===t.comma}function ze(e){if(!a(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Ve(e){if(!c(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function qe(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function He(e,t){var n,r,l,o;if(e){if(e instanceof Re)return e;{const i=function(e){if(!e||"object"!=typeof e)return{};const t=new Set(["newLine","trailingNewline","trailingComma","bracketSpacing","inlineTableStart"]),n={},r=[],l=[];for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o))if(t.has(o)){const t=e[o];switch(o){case"newLine":"string"==typeof t?n.newLine=t:l.push(`${o} (expected string, got ${typeof t})`);break;case"trailingNewline":"boolean"==typeof t||"number"==typeof t?n.trailingNewline=t:l.push(`${o} (expected boolean or number, got ${typeof t})`);break;case"trailingComma":case"bracketSpacing":"boolean"==typeof t?n[o]=t:l.push(`${o} (expected boolean, got ${typeof t})`);break;case"inlineTableStart":"number"==typeof t&&Number.isInteger(t)&&t>=0||null==t?n.inlineTableStart=t:l.push(`${o} (expected non-negative integer or undefined, got ${typeof t})`)}}else r.push(o);if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Array.from(t).join(", ")}`),l.length>0)throw new TypeError(`Invalid types for format properties: ${l.join(", ")}`);return n}(e);return new Re(null!==(n=i.newLine)&&void 0!==n?n:t.newLine,null!==(r=i.trailingNewline)&&void 0!==r?r:t.trailingNewline,null!==(l=i.trailingComma)&&void 0!==l?l:t.trailingComma,null!==(o=i.bracketSpacing)&&void 0!==o?o:t.bracketSpacing,void 0!==i.inlineTableStart?i.inlineTableStart:t.inlineTableStart)}}return t}class Re{constructor(e,t,n,r,l){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:Ne,this.bracketSpacing=null!=r?r:Be,this.inlineTableStart=null!=l?l:1}static default(){return new Re("\n",1,Ne,Be,1)}static autoDetectFormat(e){const t=Re.default();t.newLine=qe(e),t.trailingNewline=function(e,t){let n=0,r=e.length;for(;r>=t.length&&e.substring(r-t.length,r)===t;)n++,r-=t.length;return n}(e,t.newLine);try{const n=de(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=Ze(e);if(null!==t)return t}return Ne}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=Pe(t,e);if(null!==n)return n}return Be}(e,r)}catch(e){t.trailingComma=Ne,t.bracketSpacing=Be}return t.inlineTableStart=1,t}}function Ye(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!o(e))return!1;const n=c(e.value),r=a(e.value)&&e.value.items.length&&c(e.value.items[0].item);if(n||r){const n=Qe(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{Ee(e,e,t),c(t.value)?ke(e,e,Je(t)):function(e){const t=De();for(const n of e.value.items){const r=Fe(e.key.value);ke(t,t,r);for(const e of n.item.items)ke(t,r,e.item)}return Ce(t),t.items}(t).forEach((t=>{ke(e,e,t)}))})),Ce(e),e}function Je(e){const t=Le(e.key.value);for(const n of e.value.items)ke(t,t,n.item);return Ce(t),t}function Ge(e){if(e.items.length>0){const t=e.items[e.items.length-1];e.loc.end.line=t.loc.end.line,e.loc.end.column=t.loc.end.column}else e.loc.end.line=e.key.loc.end.line,e.loc.end.column=e.key.loc.end.column}function Qe(e){return Math.max(0,e.length-1)}function Xe(e,t,n){var r;for(let l=e.items.length-1;l>=0;l--){const i=e.items[l];if(o(i)&&c(i.value)){const l=[...e.key.item.value,...i.key.value];if(Qe(l)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=Le(l);for(const e of i.value.items)ke(r,r,e.item);Ee(e,e,i),Ge(e),t.push(r),Xe(r,t,n)}}}}function et(e,t=Re.default()){e=function(e){const t=[],n=[];for(const r in e)K(e[r])||Array.isArray(e[r])?n.push(r):t.push(r);const r={};for(let n=0;n<t.length;n++){const l=t[n];r[l]=e[l]}for(let t=0;t<n.length;t++){const l=n[t];r[l]=e[l]}return r}(e=rt(e));const n=De();for(const r of tt(e,t))ke(n,n,r);Ce(n);const r=N(n,(e=>Ye(e,t)),(e=>function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const r of e.items)if(o(r)&&c(r.value)){if(Qe(r.key.value)<t.inlineTableStart){const l=Je(r);Ee(e,e,r),ke(e,e,l),Xe(l,n,t)}}else"Table"===r.type&&Xe(r,n,t);for(const t of n)ke(e,e,t);return Ce(e),e}(e,t)),(e=>function(e){return e}(e)));return function(e){let t=0,n=0;for(const r of e.items)0===n&&r.loc.start.line>1?t=1-r.loc.start.line:r.loc.start.line+t>n+2&&(t+=n+2-(r.loc.start.line+t)),Oe(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(r)}function*tt(e,t){for(const n of Object.keys(e))yield Ue([n],nt(e[n],t))}function nt(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?function(t){const n=JSON.stringify(t);return{type:e.String,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):U(t)?function(t){const n=t.toString();return{type:e.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):function(e){return"number"==typeof e&&(!U(e)||!isFinite(e)||Object.is(e,-0))}(t)?function(t){let n;return n=t===1/0?"inf":t===-1/0?"-inf":Number.isNaN(t)?"nan":Object.is(t,-0)?"-0.0":t.toString(),{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):function(e){return"boolean"==typeof e}(t)?function(t){return{type:e.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:t?4:5}},value:t}}(t):M(t)?function(t){const n=t.toISOString();return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):Array.isArray(t)?function(t,n){const r={type:e.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of t){ke(r,r,je(nt(e,n)))}return Ae(r,r,n.bracketSpacing),xe(r,r,n.trailingComma),Ce(r),r}(t,n):function(t,n){if(t=rt(t),!K(t))return nt(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},l=[...tt(t,n)];for(const e of l){ke(r,r,je(e))}return Ae(r,r,n.bracketSpacing),xe(r,r,n.trailingComma),Ce(r),r}(t,n)}function rt(e){return e?M(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const lt=/(\r\n|\n)/g;function ot(t,n){const r=[];return ge(t,{[e.TableKey](e){const{start:t,end:n}=e.loc;it(r,{start:t,end:{line:t.line,column:t.column+1}},"["),it(r,{start:{line:n.line,column:n.column-1},end:n},"]")},[e.TableArrayKey](e){const{start:t,end:n}=e.loc;it(r,{start:t,end:{line:t.line,column:t.column+2}},"[["),it(r,{start:{line:n.line,column:n.column-2},end:n},"]]")},[e.KeyValue](e){const{start:{line:t}}=e.loc;it(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=")},[e.Key](e){it(r,e.loc,e.raw)},[e.String](e){it(r,e.loc,e.raw)},[e.Integer](e){it(r,e.loc,e.raw)},[e.Float](e){it(r,e.loc,e.raw)},[e.Boolean](e){it(r,e.loc,e.value.toString())},[e.DateTime](e){it(r,e.loc,e.raw)},[e.InlineArray](e){const{start:t,end:n}=e.loc;it(r,{start:t,end:{line:t.line,column:t.column+1}},"["),it(r,{start:{line:n.line,column:n.column-1},end:n},"]")},[e.InlineTable](e){const{start:t,end:n}=e.loc;it(r,{start:t,end:{line:t.line,column:t.column+1}},"{"),it(r,{start:{line:n.line,column:n.column-1},end:n},"}")},[e.InlineItem](e){if(!e.comma)return;const t=e.loc.end;it(r,{start:t,end:{line:t.line,column:t.column+1}},",")},[e.Comment](e){it(r,e.loc,e.raw)}}),r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function it(e,t,n){const r=n.split(lt).filter((e=>"\n"!==e&&"\r\n"!==e)),l=t.end.line-t.start.line+1;if(r.length!==l)throw new Error(`Mismatch between location and raw string, expected ${l} lines for "${n}"`);for(let l=t.start.line;l<=t.end.line;l++){const o=at(e,l);if(void 0===o)throw new Error(`Line ${l} is uninitialized when writing "${n}" at ${t.start.line}:${t.start.column} to ${t.end.line}:${t.end.column}`);const i=l===t.start.line,a=l===t.end.line,s=i?o.substr(0,t.start.column).padEnd(t.start.column," "):"",c=a?o.substr(t.end.column):"";e[l-1]=s+r[l-t.start.line]+c}}function at(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function st(t,n=""){const r=F(),l=new Set,o=new Set,i=new Set;let a=r,s=0;return ge(t,{[e.Table](e){const t=e.key.item.value;try{ut(r,t,e.type,{tables:l,table_arrays:o,defined:i})}catch(t){const r=t;throw new S(n,e.key.loc.start,r.message)}const s=dt(t);l.add(s),i.add(s),a=ft(r,t)},[e.TableArray](e){const t=e.key.item.value;try{ut(r,t,e.type,{tables:l,table_arrays:o,defined:i})}catch(t){const r=t;throw new S(n,e.key.loc.start,r.message)}const s=dt(t);o.add(s),i.add(s),a=function(e,t){const n=mt(e,t.slice(0,-1)),r=L(t);n[r]||(n[r]=[]);const l=F();return n[L(t)].push(l),l}(r,t)},[e.KeyValue]:{enter(e){if(s>0)return;const t=e.key.value;try{ut(a,t,e.type,{tables:l,table_arrays:o,defined:i})}catch(t){const r=t;throw new S(n,e.key.loc.start,r.message)}const r=ct(e.value);(t.length>1?ft(a,t.slice(0,-1)):a)[L(t)]=r,i.add(dt(t))}},[e.InlineTable]:{enter(){s++},exit(){s--}}}),r}function ct(t){switch(t.type){case e.InlineTable:const n=F();return t.items.forEach((({item:e})=>{const t=e.key.value,r=ct(e.value);(t.length>1?ft(n,t.slice(0,-1)):n)[L(t)]=r})),n;case e.InlineArray:return t.items.map((e=>ct(e.item)));case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function ut(t,n,r,l){let o=[],i=0;for(const e of n){if(o.push(e),!j(t,e))return;if("object"!=typeof(a=t[e])&&!M(a))throw new Error(`Invalid key, a value has already been defined for ${o.join(".")}`);const r=dt(o);if(Array.isArray(t[e])&&!l.table_arrays.has(r))throw new Error(`Invalid key, cannot add to a static array at ${r}`);const s=i++<n.length-1;t=Array.isArray(t[e])&&s?L(t[e]):t[e]}var a;const s=dt(n);if(t&&r===e.Table&&l.defined.has(s))throw new Error(`Invalid key, a table has already been defined named ${s}`);if(t&&r===e.TableArray&&!l.table_arrays.has(s))throw new Error(`Invalid key, cannot add an array of tables to a table at ${s}`)}function ft(e,t){const n=mt(e,t.slice(0,-1)),r=L(t);return n[r]||(n[r]=F()),n[r]}function mt(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=F()),Array.isArray(e[t])?L(e[t]):e[t])),e)}function dt(e){return e.join(".")}var pt,yt,ht,gt;function vt(e){return e.type===pt.Remove}function wt(e,t,n=[]){return e===t||(l=t,M(r=e)&&M(l)&&r.toISOString()===l.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const l=e.map(B),o=t.map(B);o.forEach(((i,a)=>{const s=a>=l.length;if(!s&&l[a]===i)return;const c=l.indexOf(i,a+1);if(!s&&c>-1){r.push({type:pt.Move,path:n,from:c,to:a});const e=l.splice(c,1);return void l.splice(a,0,...e)}const u=!o.includes(l[a]);if(!s&&u)return P(r,wt(e[a],t[a],n.concat(a))),void(l[a]=i);r.push({type:pt.Add,path:n.concat(a)}),l.splice(a,0,i)}));for(let e=o.length;e<l.length;e++)r.push({type:pt.Remove,path:n.concat(e)});return r}(e,t,n):K(e)&&K(t)?function(e,t,n=[]){let r=[];const l=Object.keys(e),o=l.map((t=>B(e[t]))),i=Object.keys(t),a=i.map((e=>B(t[e]))),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=l[o.indexOf(e)];return!i.includes(n)};return l.forEach(((l,c)=>{const u=n.concat(l);if(i.includes(l))P(r,wt(e[l],t[l],u));else if(s(o[c],a)){const e=i[a.indexOf(o[c])];r.push({type:pt.Rename,path:n,from:l,to:e})}else r.push({type:pt.Remove,path:u})})),i.forEach(((e,t)=>{l.includes(e)||s(a[t],o)||r.push({type:pt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:pt.Edit,path:n}];var r,l}function St(e,t){if(!t.length)return s(e)&&o(e.item)?e.item:e;if(o(e))return St(e.value,t);const n={};let i;if(f(e)&&e.items.some(((e,a)=>{try{let c=[];if(o(e))c=e.key.value;else if(r(e))c=e.key.item.value;else if(l(e)){c=e.key.item.value;const t=B(c);n[t]||(n[t]=0);const r=n[t]++;c=c.concat(r)}else s(e)&&o(e.item)?c=e.item.key.value:s(e)&&(c=[a]);return!(!c.length||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(c,t.slice(0,c.length)))&&(i=St(e,t.slice(c.length)),!0)}catch(e){return!1}})),!i)throw new Error(`Could not find node at path ${t.join(".")}`);return i}function Tt(e,t){try{return St(e,t)}catch(e){}}function bt(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=Tt(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function $t(t,i,u){const f=[...t],d=st(f),p={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},y=et(i,He(Object.assign(Object.assign({},u),{inlineTableStart:void 0}),u)),h=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(vt(n)){let r=t+1;for(;r<e.length;){const l=e[r];if(vt(l)&&l.path[0]===n.path[0]&&l.path[1]>n.path[1]){e.splice(r,1),e.splice(t,0,l),t=0;break}r++}}}return e}(wt(d,i));if(0===h.length)return{tomlString:ot(f,u),document:p};const g=function(e,t,i,u){return i.forEach((i=>{if(function(e){return e.type===pt.Add}(i)){const f=St(t,i.path),m=i.path.slice(0,-1);let d,p=L(i.path),y=l(f);if(U(p)&&!m.some(U)){const t=Tt(e,m.concat(0));t&&l(t)&&(y=!0)}if(r(f))d=e;else if(y){d=e;const t=e,n=Tt(t,m.concat(p-1)),r=Tt(t,m.concat(p));p=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else d=bt(e,i.path),o(d)&&(d=d.value);if(l(d)||a(d)||n(d)){if(a(d)){const e=ze(d);s(f)&&(f.comma=e)}if(void 0!==u.inlineTableStart&&u.inlineTableStart>0&&n(d)&&r(f)){const t=kt(f,e,u);ke(e,d,f,p);for(const n of t)ke(e,e,n,void 0)}else ke(e,d,f,p)}else if(c(d)){const t=Ve(d);if(o(f)){const n=je(f);n.comma=t,ke(e,d,n)}else ke(e,d,f)}else if(void 0!==u.inlineTableStart&&u.inlineTableStart>0&&o(f)&&c(f.value)&&r(d)){Qe([...d.key.item.value,...f.key.value])<u.inlineTableStart?function(e,t,n,r){const l=t.key.item.value,i=[...l,...e.key.value],a=Le(i);if(c(e.value))for(const t of e.value.items)s(t)&&o(t.item)&&ke(n,a,t.item,void 0);ke(n,n,a,void 0),Ge(t);const u=kt(a,n,r);for(const e of u)ke(n,n,e,void 0)}(f,d,e,u):ke(e,d,f)}else 0===u.inlineTableStart&&o(f)&&c(f.value)&&n(d)?ke(e,d,f,void 0,!0):ke(e,d,f)}else if(function(e){return e.type===pt.Edit}(i)){let n,r=St(e,i.path),l=St(t,i.path);if(o(r)&&o(l)){if(a(r.value)&&a(l.value)){const e=ze(r.value),t=l.value;if(t.items.length>0){t.items[t.items.length-1].comma=e}}if(c(r.value)&&c(l.value)){const e=Ve(r.value),t=l.value;if(t.items.length>0){t.items[t.items.length-1].comma=e}}n=r,r=r.value,l=l.value}else if(o(r)&&s(l)&&o(l.item))n=r,r=r.value,l=l.item.value;else if(s(r)&&o(l))n=r,r=r.item;else if(n=bt(e,i.path),o(n)){const t=i.path.slice(0,-1),r=St(e,t);o(r)&&a(r.value)&&(n=r.value)}$e(e,n,r,l)}else if(vt(i)){let t=bt(e,i.path);o(t)&&(t=t.value);const n=St(e,i.path);Ee(e,t,n)}else if(function(e){return e.type===pt.Move}(i)){let t=St(e,i.path);m(t)&&(t=t.item),o(t)&&(t=t.value);const n=t.items[i.from];Ee(e,t,n),ke(e,t,n,i.to)}else if(function(e){return e.type===pt.Rename}(i)){let n=St(e,i.path.concat(i.from)),r=St(t,i.path.concat(i.to));m(n)&&(n=n.item),m(r)&&(r=r.item),$e(e,n,n.key,r.key)}})),Ce(e),e}(p,y,h,u);return{tomlString:ot(g.items,u),document:g}}function kt(e,t,n){const r=[],l=(e,r)=>{var i;for(let a=e.items.length-1;a>=0;a--){const u=e.items[a];if(o(u)&&c(u.value)){const c=[...e.key.item.value,...u.key.value];if(Qe(c)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Le(c);for(const e of u.value.items)s(e)&&o(e.item)&&ke(t,n,e.item,void 0);e.items.splice(a,1),Ge(e),r.push(n),l(n,r)}}}};return l(e,r),r}function It(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function Et(e,t,n,r,l){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!l:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?l.call(e,n):l?l.value=n:t.set(e,n),n}function At(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(pt||(pt={})),"function"==typeof SuppressedError&&SuppressedError;function xt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(xt);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=xt(r);return t}return e}yt=new WeakMap,ht=new WeakMap,gt=new WeakMap,exports.TomlDocument=class{constructor(e){yt.set(this,void 0),ht.set(this,void 0),gt.set(this,void 0),Et(this,ht,e,"f"),Et(this,yt,Array.from(de(e)),"f"),Et(this,gt,Re.autoDetectFormat(e),"f")}get toTomlString(){return It(this,ht,"f")}get toJsObject(){return xt(st(It(this,yt,"f")))}get ast(){return It(this,yt,"f")}patch(e,t){const n=He(t,It(this,gt,"f")),{tomlString:r,document:l}=$t(It(this,yt,"f"),e,n);Et(this,yt,l.items,"f"),Et(this,ht,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(It(this,gt,"f").newLine),n=qe(e),r=e.split(n);let l=0;for(;l<t.length&&l<r.length&&t[l]===r[l];)l++;let o=0;if(l<t.length&&l<r.length){const e=t[l],n=r[l];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){o=t;break}}let i=l+1;const{truncatedAst:a,lastEndPosition:s}=function(e,t,n){const r={line:t,column:n},l=[];let o=null;for(const t of e){const e=At(t.loc.end,r)<0,n=At(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}l.push(t),o=t.loc.end}return{truncatedAst:l,lastEndPosition:o}}(It(this,yt,"f"),i,o),c=s?s.line:1,u=s?s.column+1:0,f=r.slice(c-1);f.length>0&&u>0&&(f[0]=f[0].substring(u));const m=f.join(It(this,gt,"f").newLine);Et(this,yt,Array.from(function*(e,t){for(const t of e)yield t;for(const e of de(t))yield e}(a,m)),"f"),Et(this,ht,e,"f"),Et(this,gt,Re.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(Et(this,yt,Array.from(de(e)),"f"),Et(this,ht,e,"f"),Et(this,gt,Re.autoDetectFormat(e),"f"))}},exports.TomlFormat=Re,exports.parse=function(e){return st(de(e),e)},exports.patch=function(e,t,n){return $t(de(e),t,He(n,Re.autoDetectFormat(e))).tomlString},exports.stringify=function(e,t){const n=He(t,Re.default());return ot(et(e,n).items,n)};
1
+ //! @decimalturn/toml-patch v0.5.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ "use strict";var e,t;function n(t){return t.type===e.Document}function r(t){return t.type===e.Table}function l(t){return t.type===e.TableArray}function o(t){return t.type===e.KeyValue}function i(t){return t.type===e.String}function a(t){return t.type===e.DateTime}function s(t){return t.type===e.InlineArray}function c(t){return t.type===e.InlineItem}function u(t){return t.type===e.InlineTable}function f(t){return t.type===e.Comment}function m(e){return n(e)||r(e)||l(e)||u(e)||s(e)}function d(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}!function(e){e.Document="Document",e.Table="Table",e.TableKey="TableKey",e.TableArray="TableArray",e.TableArrayKey="TableArrayKey",e.KeyValue="KeyValue",e.Key="Key",e.String="String",e.Integer="Integer",e.Float="Float",e.Boolean="Boolean",e.DateTime="DateTime",e.InlineArray="InlineArray",e.InlineItem="InlineItem",e.InlineTable="InlineTable",e.Comment="Comment"}(e||(e={}));class p{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return h();const t=this.peeked||this.iterator.next();return this.index+=1,this.value=t.value,this.done=null!==(e=t.done)&&void 0!==e&&e,this.peeked=null,t}peek(){return this.done?h():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}function h(){return{value:void 0,done:!0}}function y(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function g(e,t){const n=Array.isArray(e)?e:v(e),r=n.findIndex((e=>e>=t))+1;return{line:r,column:t-(n[r-2]+1||0)}}function v(e){const t=/\r\n|\n/g,n=[];let r;for(;null!=(r=t.exec(e));)n.push(r.index+r[0].length-1);return n.push(e.length+1),n}function w(e){return{line:e.line,column:e.column}}function S(e){return{start:w(e.start),end:w(e.end)}}class T extends Error{constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=v(e),r=n[t.line-2]||0,l=n[t.line-1]||e.length;return e.substr(r,l-r)}(e,t),l=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(r+=`${n}\n${l}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}}!function(e){e.Bracket="Bracket",e.Curly="Curly",e.Equal="Equal",e.Comma="Comma",e.Dot="Dot",e.Comment="Comment",e.Literal="Literal"}(t||(t={}));const $=/\s/,b=/(\r\n|\n)/,k='"',I="'",E=/[\w,\d,\",\',\+,\-,\_]/;function*x(e){const n=new p(e[Symbol.iterator]());n.next();const r=function(e){const t=v(e);return(e,n)=>({start:g(t,e),end:g(t,n)})}(e);for(;!n.done;){if($.test(n.value));else if("["===n.value||"]"===n.value)yield A(n,r,t.Bracket);else if("{"===n.value||"}"===n.value)yield A(n,r,t.Curly);else if("="===n.value)yield A(n,r,t.Equal);else if(","===n.value)yield A(n,r,t.Comma);else if("."===n.value)yield A(n,r,t.Dot);else if("#"===n.value)yield C(n,r);else{const t=_(e,n.index,I)||_(e,n.index,k);t?yield O(n,r,t,e):yield D(n,r,e)}n.next()}}function A(e,t,n){return{type:n,raw:e.value,loc:t(e.index,e.index+1)}}function C(e,n){const r=e.index;let l=e.value;for(;!e.peek().done&&!b.test(e.peek().value);)e.next(),l+=e.value;return{type:t.Comment,raw:l,loc:n(r,e.index+1)}}function O(e,n,r,l){const o=e.index;let i=r+r+r,a=i;for(e.next(),e.next(),e.next();!e.done&&(!_(l,e.index,r)||F(l,e.index,r));)a+=e.value,e.next();if(e.done)throw new T(l,g(l,e.index),`Expected close of multiline string with ${i}, reached end of file`);return a+=i,e.next(),e.next(),{type:t.Literal,raw:a,loc:n(o,e.index+1)}}function D(e,n,r){if(!E.test(e.value))throw new T(r,g(r,e.index),`Unsupported character "${e.value}". Expected ALPHANUMERIC, ", ', +, -, or _`);const l=e.index;let o=e.value,i=e.value===k,a=e.value===I;const s=e=>{if(e.peek().done)return!0;const t=e.peek().value;return!(i||a)&&($.test(t)||","===t||"."===t||"]"===t||"}"===t||"="===t||"#"===t)};for(;!e.done&&!s(e)&&(e.next(),e.value===k&&(i=!i),e.value!==I||i||(a=!a),o+=e.value,!e.peek().done);){let t=e.peek().value;i&&"\\"===e.value&&(t===k?(o+=k,e.next()):"\\"===t&&(o+="\\",e.next()))}if(i||a)throw new T(r,g(r,l),`Expected close of string with ${i?k:I}`);return{type:t.Literal,raw:o,loc:n(l,e.index+1)}}function _(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;const r=e.slice(0,t).match(/\\+$/);if(!r)return n;return!(r[0].length%2!=0)&&n}function F(e,t,n){return!!n&&(e[t]===n&&e[t+1]===n&&e[t+2]===n&&e[t+3]===n)}function U(e){return e[e.length-1]}function L(){return Object.create(null)}function M(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function j(e){return"[object Date]"===Object.prototype.toString.call(e)}function K(e){return e&&"object"==typeof e&&!j(e)&&!Array.isArray(e)}function N(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function B(e,...t){return t.reduce(((e,t)=>t(e)),e)}function Z(e){if(K(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${Z(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(Z).join(",")}]`:JSON.stringify(e)}function W(e,t){const n=e.length,r=t.length;e.length=n+r;for(let l=0;l<r;l++)e[n+l]=t[l]}function P(e){return e.startsWith('"""')||e.startsWith("'''")}const z=/\r\n/g,V=/\n/g,H=/^(\r\n|\n)/,R=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function q(e){return e.startsWith("'''")?B(G(e,3),Q):e.startsWith(I)?G(e,1):e.startsWith('"""')?B(G(e,3),Q,ee,X,Y,J):e.startsWith(k)?B(G(e,1),J):e}function Y(e){let t="",n=0;for(let r=0;r<e.length;r++){const l=e[r];t+='"'===l&&n%2==0?'\\"':l,"\\"===l?n++:n=0}return t}function J(e){const t=e.replace(/\\U[a-fA-F0-9]{8}/g,(e=>{const t=parseInt(e.replace("\\U",""),16),n=String.fromCodePoint(t);return G(JSON.stringify(n),1)})),n=t.replace(/\t/g,"\\t");return JSON.parse(`"${n}"`)}function G(e,t){return e.slice(t,e.length-t)}function Q(e){return e.replace(H,"")}function X(e){return e.replace(z,"\\r\\n").replace(V,"\\n")}function ee(e){return e.replace(R,((e,t)=>e.replace(t,"")))}class te{static createDateWithOriginalFormat(e,t){if(te.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof oe)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new le(t,!1)}const t=e.toISOString().split("T")[0];return new ne(t)}if(te.IS_TIME_ONLY.test(t)){if(e instanceof re)return e;{const n=t.match(/\.(\d+)\s*$/),r=e.toISOString();if(r&&r.includes("T")){let l=r.split("T")[1].split("Z")[0];if(n){const t=n[1].length,[r,o,i]=l.split(":"),[a]=i.split(".");l=`${r}:${o}:${a}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new re(l,t)}{const r=String(e.getUTCHours()).padStart(2,"0"),l=String(e.getUTCMinutes()).padStart(2,"0"),o=String(e.getUTCSeconds()).padStart(2,"0"),i=e.getUTCMilliseconds();let a;if(n){const e=n[1].length;a=`${r}:${l}:${o}.${String(i).padStart(3,"0").slice(0,e)}`}else if(i>0){a=`${r}:${l}:${o}.${String(i).padStart(3,"0").replace(/0+$/,"")}`}else a=`${r}:${l}:${o}`;return new re(a,t)}}}if(te.IS_LOCAL_DATETIME_T.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","");if(n){const t=n[1].length,[l,o]=r.split("T"),[i,a,s]=o.split(":"),[c]=s.split(".");r=`${l}T${i}:${a}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new le(r,!1,t)}if(te.IS_LOCAL_DATETIME_SPACE.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","").replace("T"," ");if(n){const t=n[1].length,[l,o]=r.split(" "),[i,a,s]=o.split(":"),[c]=s.split(".");r=`${l} ${i}:${a}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new le(r,!0,t)}if(te.IS_OFFSET_DATETIME_T.test(t)||te.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),r=n?"z"===n[1]?"Z":n[1]:"Z",l=te.IS_OFFSET_DATETIME_SPACE.test(t),o=t.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),i=e.getTime();let a=0;if("Z"!==r){const e="+"===r[0]?1:-1,[t,n]=r.slice(1).split(":");a=e*(60*parseInt(t)+parseInt(n))}const s=new Date(i+6e4*a),c=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),m=String(s.getUTCHours()).padStart(2,"0"),d=String(s.getUTCMinutes()).padStart(2,"0"),p=String(s.getUTCSeconds()).padStart(2,"0"),h=s.getUTCMilliseconds(),y=l?" ":"T";let g=`${m}:${d}:${p}`;if(o){const e=o[1].length;g+=`.${String(h).padStart(3,"0").slice(0,e)}`}else if(h>0){g+=`.${String(h).padStart(3,"0").replace(/0+$/,"")}`}return new oe(`${c}-${u}-${f}${y}${g}${r}`,l)}return e}}te.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,te.IS_TIME_ONLY=/^\d{2}:\d{2}:\d{2}(?:\.\d+)?$/,te.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$/,te.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?$/,te.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,te.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,te.IS_FULL_DATE=/(\d{4})-(\d{2})-(\d{2})/,te.IS_FULL_TIME=/(\d{2}):(\d{2}):(\d{2})/;class ne extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class re extends Date{constructor(e,t){super(`1970-01-01T${e}Z`),this.originalFormat=t}toISOString(){const e=String(this.getUTCHours()).padStart(2,"0"),t=String(this.getUTCMinutes()).padStart(2,"0"),n=String(this.getUTCSeconds()).padStart(2,"0"),r=this.getUTCMilliseconds();if(this.originalFormat&&this.originalFormat.includes(".")){const l=this.originalFormat.match(/\.(\d+)\s*$/),o=l?l[1].length:3;return`${e}:${t}:${n}.${String(r).padStart(3,"0").slice(0,o)}`}if(r>0){return`${e}:${t}:${n}.${String(r).padStart(3,"0").replace(/0+$/,"")}`}return`${e}:${t}:${n}`}}class le extends Date{constructor(e,t=!1,n){super(e.replace(" ","T")+"Z"),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=this.getUTCFullYear(),t=String(this.getUTCMonth()+1).padStart(2,"0"),n=String(this.getUTCDate()).padStart(2,"0"),r=String(this.getUTCHours()).padStart(2,"0"),l=String(this.getUTCMinutes()).padStart(2,"0"),o=String(this.getUTCSeconds()).padStart(2,"0"),i=this.getUTCMilliseconds(),a=`${e}-${t}-${n}`,s=this.useSpaceSeparator?" ":"T";if(this.originalFormat&&this.originalFormat.includes(".")){const e=this.originalFormat.match(/\.(\d+)\s*$/),t=e?e[1].length:3;return`${a}${s}${r}:${l}:${o}.${String(i).padStart(3,"0").slice(0,t)}`}if(i>0){return`${a}${s}${r}:${l}:${o}.${String(i).padStart(3,"0").replace(/0+$/,"")}`}return`${a}${s}${r}:${l}:${o}`}}class oe extends Date{constructor(e,t=!1){super(e.replace(" ","T")),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=e;const n=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);n&&(this.originalOffset="z"===n[1]?"Z":n[1])}toISOString(){if(this.originalOffset){const e=this.getTime();let t=0;if("Z"!==this.originalOffset){const e="+"===this.originalOffset[0]?1:-1,[n,r]=this.originalOffset.slice(1).split(":");t=e*(60*parseInt(n)+parseInt(r))}const n=new Date(e+6e4*t),r=n.getUTCFullYear(),l=String(n.getUTCMonth()+1).padStart(2,"0"),o=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0"),s=String(n.getUTCSeconds()).padStart(2,"0"),c=n.getUTCMilliseconds(),u=`${r}-${l}-${o}`,f=this.useSpaceSeparator?" ":"T";if(this.originalFormat&&this.originalFormat.includes(".")){const e=this.originalFormat.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),t=e?e[1].length:3;return`${u}${f}${i}:${a}:${s}.${String(c).padStart(3,"0").slice(0,t)}${this.originalOffset}`}if(c>0){return`${u}${f}${i}:${a}:${s}.${String(c).padStart(3,"0").replace(/0+$/,"")}${this.originalOffset}`}return`${u}${f}${i}:${a}:${s}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const ie=te,ae="true",se=/e/i,ce=/\_/g,ue=/inf/,fe=/nan/,me=/^0x/,de=/^0o/,pe=/^0b/;function*he(e){const t=x(e),n=new p(t);for(;!n.next().done;)yield*ye(n,e)}function*ye(n,r){if(n.value.type===t.Comment)yield ve(n);else if(n.value.type===t.Bracket)yield function(n,r){const l=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,o=l===e.Table;if(o&&"["!==n.value.raw)throw new T(r,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!o&&("["!==n.value.raw||"["!==n.peek().value.raw))throw new T(r,n.value.loc.start,`Expected array of tables opening "[[", found ${n.value.raw+n.peek().value.raw}`);const i=o?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};n.next(),l===e.TableArray&&n.next();if(n.done)throw new T(r,i.loc.start,"Expected table key, reached end of file");i.item={type:e.Key,loc:S(n.value.loc),raw:n.value.raw,value:[q(n.value.raw)]};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=" ".repeat(e.loc.start.column-i.item.loc.end.column),r=" ".repeat(n.value.loc.start.column-e.loc.end.column);i.item.loc.end=n.value.loc.end,i.item.raw+=`${t}.${r}${n.value.raw}`,i.item.value.push(q(n.value.raw))}if(n.next(),o&&(n.done||"]"!==n.value.raw))throw new T(r,n.done?i.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!o&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new T(r,n.done||n.peek().done?i.item.loc.end:n.value.loc.start,`Expected array of tables closing "]]", found ${n.done||n.peek().done?"end of file":n.value.raw+n.peek().value.raw}`);o||n.next();i.loc.end=n.value.loc.end;let a=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;)n.next(),W(a,[...ye(n,r)]);return{type:o?e.Table:e.TableArray,loc:{start:w(i.loc.start),end:a.length?w(a[a.length-1].loc.end):w(i.loc.end)},key:i,items:a}}(n,r);else{if(n.value.type!==t.Literal)throw new T(r,n.value.loc.start,`Unexpected token "${n.value.type}". Expected Comment, Bracket, or String`);yield*function(n,r){const l={type:e.Key,loc:S(n.value.loc),raw:n.value.raw,value:[q(n.value.raw)]};for(;!n.peek().done&&n.peek().value.type===t.Dot;)n.next(),n.next(),l.loc.end=n.value.loc.end,l.raw+=`.${n.value.raw}`,l.value.push(q(n.value.raw));if(n.next(),n.done||n.value.type!==t.Equal)throw new T(r,n.done?l.loc.end:n.value.loc.start,`Expected "=" for key-value, found ${n.done?"end of file":n.value.raw}`);const o=n.value.loc.start.column;if(n.next(),n.done)throw new T(r,l.loc.start,"Expected value for key-value, reached end of file");const[i,...a]=ge(n,r);return[{type:e.KeyValue,key:l,value:i,loc:{start:w(l.loc.start),end:w(i.loc.end)},equals:o},...a]}(n,r)}}function*ge(n,r){if(n.value.type===t.Literal)n.value.raw[0]===k||n.value.raw[0]===I?yield function(t){return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:q(t.value.raw)}}(n):n.value.raw===ae||"false"===n.value.raw?yield function(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===ae}}(n):ie.IS_FULL_DATE.test(n.value.raw)||ie.IS_FULL_TIME.test(n.value.raw)?yield function(n,r){let l,o=n.value.loc,i=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&ie.IS_FULL_DATE.test(i)&&ie.IS_FULL_TIME.test(n.peek().value.raw)){const e=o.start;n.next(),o={start:e,end:n.value.loc.end},i+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=o.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new T(r,n.value.loc.end,"Expected fractional value for DateTime");n.next(),o={start:e,end:n.value.loc.end},i+=`.${n.value.raw}`}if(ie.IS_FULL_DATE.test(i))l=ie.IS_DATE_ONLY.test(i)?new ne(i):ie.IS_LOCAL_DATETIME_T.test(i)?new le(i,!1):ie.IS_LOCAL_DATETIME_SPACE.test(i)?new le(i,!0):ie.IS_OFFSET_DATETIME_T.test(i)?new oe(i,!1):ie.IS_OFFSET_DATETIME_SPACE.test(i)?new oe(i,!0):new Date(i.replace(" ","T"));else if(ie.IS_TIME_ONLY.test(i))l=new re(i,i);else{const[e]=(new Date).toISOString().split("T");l=new Date(`${e}T${i}`)}return{type:e.DateTime,loc:o,raw:i,value:l}}(n,r):!n.peek().done&&n.peek().value.type===t.Dot||ue.test(n.value.raw)||fe.test(n.value.raw)||se.test(n.value.raw)&&!me.test(n.value.raw)?yield function(n,r){let l,o=n.value.loc,i=n.value.raw;if(ue.test(i))l="-inf"===i?-1/0:1/0;else if(fe.test(i))l=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot)l=Number(i.replace(ce,""));else{const e=o.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new T(r,n.value.loc.end,"Expected fraction value for Float");n.next(),i+=`.${n.value.raw}`,o={start:e,end:n.value.loc.end},l=Number(i.replace(ce,""))}return{type:e.Float,loc:o,raw:i,value:l}}(n,r):yield function(t){if("-0"===t.value.raw||"+0"===t.value.raw)return{type:e.Integer,loc:t.value.loc,raw:t.value.raw,value:0};let n=10;me.test(t.value.raw)?n=16:de.test(t.value.raw)?n=8:pe.test(t.value.raw)&&(n=2);const r=parseInt(t.value.raw.replace(ce,"").replace(de,"").replace(pe,""),n);return{type:e.Integer,loc:t.value.loc,raw:t.value.raw,value:r}}(n);else if(n.value.type===t.Curly)yield function(n,r){if("{"!==n.value.raw)throw new T(r,n.value.loc.start,`Expected "{" for inline table, found ${n.value.raw}`);const l={type:e.InlineTable,loc:S(n.value.loc),items:[]};n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comma){const e=l.items[l.items.length-1];if(!e)throw new T(r,n.value.loc.start,'Found "," without previous value in inline table');e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const[o]=ye(n,r);if(o.type!==e.KeyValue)throw new T(r,n.value.loc.start,`Only key-values are supported in inline tables, found ${o.type}`);const i={type:e.InlineItem,loc:S(o.loc),item:o,comma:!1};l.items.push(i),n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new T(r,n.done?l.loc.start:n.value.loc.start,`Expected "}", found ${n.done?"end of file":n.value.raw}`);return l.loc.end=n.value.loc.end,l}(n,r);else{if(n.value.type!==t.Bracket)throw new T(r,n.value.loc.start,`Unrecognized token type "${n.value.type}". Expected String, Curly, or Bracket`);{const[l,o]=function(n,r){if("["!==n.value.raw)throw new T(r,n.value.loc.start,`Expected "[" for inline array, found ${n.value.raw}`);const l={type:e.InlineArray,loc:S(n.value.loc),items:[]};let o=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=l.items[l.items.length-1];if(!e)throw new T(r,n.value.loc.start,'Found "," without previous value for inline array');e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)o.push(ve(n));else{const[t,...i]=ge(n,r),a={type:e.InlineItem,loc:S(t.loc),item:t,comma:!1};l.items.push(a),W(o,i)}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new T(r,n.done?l.loc.start:n.value.loc.start,`Expected "]", found ${n.done?"end of file":n.value.raw}`);return l.loc.end=n.value.loc.end,[l,o]}(n,r);yield l,yield*o}}}function ve(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function we(t,n){var r;function l(e,t){for(const n of e)o(n,t)}function o(t,r){const i=n[t.type];switch(i&&"function"==typeof i&&i(t,r),i&&i.enter&&i.enter(t,r),t.type){case e.Document:l(t.items,t);break;case e.Table:o(t.key,t),l(t.items,t);break;case e.TableKey:o(t.item,t);break;case e.TableArray:o(t.key,t),l(t.items,t);break;case e.TableArrayKey:o(t.item,t);break;case e.KeyValue:o(t.key,t),o(t.value,t);break;case e.InlineArray:l(t.items,t);break;case e.InlineItem:o(t.item,t);break;case e.InlineTable:l(t.items,t);break;case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:break;default:throw new Error(`Unrecognized node type "${t.type}"`)}i&&i.exit&&i.exit(t,r)}null!=(r=t)&&"function"==typeof r[Symbol.iterator]?l(t,null):o(t,null)}const Se=te,Te=new WeakMap,$e=e=>(Te.has(e)||Te.set(e,new WeakMap),Te.get(e)),be=new WeakMap,ke=e=>(be.has(e)||be.set(e,new WeakMap),be.get(e));function Ie(e,t,n,r){if(i(n)&&i(r)){r=function(e,t){if(!P(t.raw))return t;const n=t.raw.includes("\r\n")?"\r\n":"\n",r=(t.raw.match(new RegExp("\r\n"===n?"\\r\\n":"\\n","g"))||[]).length;return r>0?Object.assign(Object.assign({},t),{loc:{start:e.loc.start,end:{line:e.loc.start.line+r,column:3}}}):Object.assign(Object.assign({},t),{loc:{start:e.loc.start,end:{line:e.loc.start.line,column:e.loc.start.column+t.raw.length}}})}(n,Be(r.value,n.raw))}if(a(n)&&a(r)){const e=n.raw,t=r.value,l=Se.createDateWithOriginalFormat(t,e);r.value=l,r.raw=l.toISOString();0!==r.raw.length-e.length&&(r.loc.end.column=r.loc.start.column+r.raw.length)}if(m(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.items.splice(e,1,r)}else if(o(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,r)}else if(d(t))t.item=r;else{if(!o(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}_e(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const l=y(n.loc),s=y(r.loc);Fe({lines:s.lines-l.lines,columns:s.columns-l.columns},ke(e),r,n)}function Ee(e,t,i,a,d){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,h;a=null!=a&&"number"==typeof a?a:t.items.length,s(t)||u(t)?({shift:p,offset:h}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const r=null!=n?e.items[n-1]:U(e.items),l=null==n||n===e.items.length;e.items.splice(n,0,t);const o=!!r,i=!l;o&&(r.comma=!0);i&&(t.comma=!0);const a=s(e)&&function(e){if(!e.items.length)return!1;return y(e.loc).lines>e.items.length}(e),u=l&&!0===t.comma;return xe(e,t,n,{useNewLine:a,hasCommaHandling:!0,isLastElement:l,hasSeparatingCommaBefore:o,hasSeparatingCommaAfter:i,hasTrailingComma:u})}(t,i,a)):d&&n(t)?({shift:p,offset:h}=function(e,t,n){const r=xe(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,i,a)):({shift:p,offset:h}=function(e,t,i){if(a=t,!(o(a)||r(a)||l(a)||f(a)))throw new Error(`Incompatible child type "${t.type}"`);var a;const s=e.items[i-1],c=n(e)&&!e.items.length;e.items.splice(i,0,t);const u=s?{line:s.loc.end.line,column:f(s)?e.loc.start.column:s.loc.start.column}:w(e.loc.start),m=r(t)||l(t);let d=0;c||(d=m?2:1);u.line+=d;const p={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},h=y(t.loc),g={lines:h.lines+(d-1),columns:h.columns};return{shift:p,offset:g}}(t,i,a)),_e(i,p);const g=t.items[a-1],v=g&&ke(e).get(g);v&&(h.lines+=v.lines,h.columns+=v.columns,ke(e).delete(g));ke(e).set(i,h)}function xe(e,t,n,r={}){const{useNewLine:l=!1,skipCommaSpace:o=2,skipBracketSpace:i=1,hasCommaHandling:a=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:m=!1}=r,d=n>0?e.items[n-1]:void 0,p=d?{line:d.loc.end.line,column:l?f(d)?e.loc.start.column:d.loc.start.column:d.loc.end.column}:w(e.loc.start);let h=0;if(l)h=1;else{const e=c||!a&&!!d;e&&a?p.column+=o:(e||a&&!d)&&(p.column+=i)}p.line+=h;const g={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=y(t.loc);if(!a){return{shift:g,offset:{lines:v.lines+(h-1),columns:v.columns}}}let S=0;c&&m&&!u&&s&&(S=-1);return{shift:g,offset:{lines:v.lines+(h-1),columns:v.columns+(c||u?o:0)+(m?1+S:0)}}}function Ae(e,t,n){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let r=t.items.indexOf(n);if(r<0){if(r=t.items.findIndex((e=>d(e)&&e.item===n)),r<0)throw new Error("Could not find node in parent for removal");n=t.items[r]}const l=t.items[r-1];let o=t.items[r+1];t.items.splice(r,1);let i=y(n.loc);o&&f(o)&&o.loc.start.line===n.loc.end.line&&(i=y({start:n.loc.start,end:o.loc.end}),o=t.items[r+1],t.items.splice(r,1));const a=l&&c(l)||o&&c(o),s=l&&l.loc.end.line===n.loc.start.line,u=o&&o.loc.start.line===n.loc.end.line,p=a&&(s||u),h={lines:-(i.lines-(p?1:0)),columns:-i.columns};if(void 0===l&&void 0===o&&(h.lines=0,h.columns=0),a&&s&&(h.columns-=2),a&&!l&&o&&(h.columns-=2),a&&l&&!o){const e=n.comma;l.comma=!!e}const g=l||t,v=l?ke(e):$e(e),w=ke(e),S=v.get(g);S&&(h.lines+=S.lines,h.columns+=S.columns);const T=w.get(n);T&&(h.lines+=T.lines,h.columns+=T.columns),v.set(g,h)}function Ce(e,t,n=!0){if(!n)return;if(!t.items.length)return;Fe({lines:0,columns:1},$e(e),t);const r=U(t.items);Fe({lines:0,columns:1},ke(e),r)}function Oe(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=U(t.items);r.comma=!0,Fe({lines:0,columns:1},ke(e),r)}function De(t){const n=$e(t),r=ke(t),l={lines:0,columns:{}};function o(e){const t=l.lines;e.loc.start.line+=t;const r=l.columns[e.loc.start.line]||0;e.loc.start.column+=r;const o=n.get(e);o&&(l.lines+=o.lines,l.columns[e.loc.start.line]=(l.columns[e.loc.start.line]||0)+o.columns)}function i(e){const t=l.lines;e.loc.end.line+=t;const n=l.columns[e.loc.end.line]||0;e.loc.end.column+=n;const o=r.get(e);o&&(l.lines+=o.lines,l.columns[e.loc.end.line]=(l.columns[e.loc.end.line]||0)+o.columns)}const a={enter:o,exit:i};we(t,{[e.Document]:a,[e.Table]:a,[e.TableArray]:a,[e.InlineTable]:a,[e.InlineArray]:a,[e.InlineItem]:a,[e.TableKey]:a,[e.TableArrayKey]:a,[e.KeyValue]:{enter(e){const t=e.loc.start.line+l.lines,n=r.get(e.key);e.equals+=(l.columns[t]||0)+(n?n.columns:0),o(e)},exit:i},[e.Key]:a,[e.String]:a,[e.Integer]:a,[e.Float]:a,[e.Boolean]:a,[e.DateTime]:a,[e.Comment]:a}),Te.delete(t),be.delete(t)}function _e(t,n,r={}){const{first_line_only:l=!1}=r,o=t.loc.start.line,{lines:i,columns:a}=n,s=e=>{l&&e.loc.start.line!==o||(e.loc.start.column+=a,e.loc.end.column+=a),e.loc.start.line+=i,e.loc.end.line+=i};return we(t,{[e.Table]:s,[e.TableKey]:s,[e.TableArray]:s,[e.TableArrayKey]:s,[e.KeyValue](e){s(e),e.equals+=a},[e.Key]:s,[e.String]:s,[e.Integer]:s,[e.Float]:s,[e.Boolean]:s,[e.DateTime]:s,[e.InlineArray]:s,[e.InlineItem]:s,[e.InlineTable]:s,[e.Comment]:s}),t}function Fe(e,t,n,r){const l=t.get(r||n);l&&(e.lines+=l.lines,e.columns+=l.columns),t.set(n,e)}function Ue(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Le(t){const n=function(t){const n=Ne(t);return{type:e.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:e.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:t,raw:n}}}(t);return{type:e.Table,loc:S(n.loc),key:n,items:[]}}function Me(t){const n=function(t){const n=Ne(t);return{type:e.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:e.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:t,raw:n}}}(t);return{type:e.TableArray,loc:S(n.loc),key:n,items:[]}}function je(t,n){const r=function(t){const n=Ne(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:l}=r.loc.end,o=l+1;return _e(n,{lines:0,columns:l+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:w(r.loc.start),end:w(n.loc.end)},key:r,equals:o,value:n}}const Ke=/^[\w-]+$/;function Ne(e){return e.map((e=>Ke.test(e)?e:JSON.stringify(e))).join(".")}function Be(t,n){let r;if(n&&P(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const l=e?"'''":'"""',o=n.includes("\r\n")?"\r\n":"\n",i=n.startsWith(`${l}${o}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!e;let a;a=e?t:t.replace(/\\/g,"\\\\").replace(/\x08/g,"\\b").replace(/\f/g,"\\f").replace(/\t/g,"\\t").replace(/[\x00-\x07\x0B\x0E-\x1F\x7F]/g,(e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase())).replace(/"""/g,'""\\"'),r=i?`${l}${o}${a}${l}`:`${l}${a}${l}`}else r=JSON.stringify(t);return{type:e.String,loc:{start:{line:1,column:0},end:{line:1,column:r.length}},raw:r,value:t}}function Ze(t){return{type:e.InlineItem,loc:S(t.loc),item:t,comma:!1}}const We=!1,Pe=!0,ze=!1;function Ve(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){var n;if(!e||!e.start||!e.end)return null;const r=t.split(/\r?\n/),l=e.start.line-1,o=e.end.line-1,i=e.start.column,a=e.end.column;let s="";if(l===o)s=(null===(n=r[l])||void 0===n?void 0:n.substring(i,a+1))||"";else{r[l]&&(s+=r[l].substring(i));for(let e=l+1;e<o;e++)s+="\n"+(r[e]||"");r[o]&&(s+="\n"+r[o].substring(0,a+1))}const c=s.match(/^\[(\s*)/),u=s.match(/^\{(\s*)/);if(c)return c[1].length>0;if(u)return u[1].length>0;return null}(e.loc,t);if(null!==n)return n}if(e.items&&Array.isArray(e.items))for(const n of e.items){const e=Ve(n,t);if(null!==e)return e;if(n.item){const e=Ve(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=Ve(e[n],t);if(null!==r)return r}return null}function He(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return Re(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return Re(e.items);if("KeyValue"===e.type&&e.value)return He(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=He(t);if(null!==e)return e}return null}function Re(e){if(0===e.length)return null;const t=e[e.length-1];return!(!t||"object"!=typeof t||!("comma"in t))&&!0===t.comma}function qe(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Ye(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Je(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function Ge(e,t){var n,r,l,o,i;if(e){if(e instanceof Qe)return e;{const a=function(e){if(!e||"object"!=typeof e)return{};const t=new Set(["newLine","trailingNewline","trailingComma","bracketSpacing","inlineTableStart","truncateZeroTimeInDates"]),n={},r=[],l=[];for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o))if(t.has(o)){const t=e[o];switch(o){case"newLine":"string"==typeof t?n.newLine=t:l.push(`${o} (expected string, got ${typeof t})`);break;case"trailingNewline":"boolean"==typeof t||"number"==typeof t?n.trailingNewline=t:l.push(`${o} (expected boolean or number, got ${typeof t})`);break;case"trailingComma":case"bracketSpacing":case"truncateZeroTimeInDates":"boolean"==typeof t?n[o]=t:l.push(`${o} (expected boolean, got ${typeof t})`);break;case"inlineTableStart":"number"==typeof t&&Number.isInteger(t)&&t>=0||null==t?n.inlineTableStart=t:l.push(`${o} (expected non-negative integer or undefined, got ${typeof t})`)}}else r.push(o);if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Array.from(t).join(", ")}`),l.length>0)throw new TypeError(`Invalid types for format properties: ${l.join(", ")}`);return n}(e);return new Qe(null!==(n=a.newLine)&&void 0!==n?n:t.newLine,null!==(r=a.trailingNewline)&&void 0!==r?r:t.trailingNewline,null!==(l=a.trailingComma)&&void 0!==l?l:t.trailingComma,null!==(o=a.bracketSpacing)&&void 0!==o?o:t.bracketSpacing,void 0!==a.inlineTableStart?a.inlineTableStart:t.inlineTableStart,null!==(i=a.truncateZeroTimeInDates)&&void 0!==i?i:t.truncateZeroTimeInDates)}}return t}class Qe{constructor(e,t,n,r,l,o){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:We,this.bracketSpacing=null!=r?r:Pe,this.inlineTableStart=null!=l?l:1,this.truncateZeroTimeInDates=null!=o?o:ze}static default(){return new Qe("\n",1,We,Pe,1,ze)}static autoDetectFormat(e){const t=Qe.default();t.newLine=Je(e),t.trailingNewline=function(e,t){let n=0,r=e.length;for(;r>=t.length&&e.substring(r-t.length,r)===t;)n++,r-=t.length;return n}(e,t.newLine);try{const n=he(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=He(e);if(null!==t)return t}return We}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=Ve(t,e);if(null!==n)return n}return Pe}(e,r)}catch(e){t.trailingComma=We,t.bracketSpacing=Pe}return t.inlineTableStart=1,t.truncateZeroTimeInDates=ze,t}}function Xe(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!o(e))return!1;const n=u(e.value),r=s(e.value)&&e.value.items.length&&u(e.value.items[0].item);if(n||r){const n=nt(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{Ae(e,e,t),u(t.value)?Ee(e,e,et(t)):function(e){const t=Ue();for(const n of e.value.items){const r=Me(e.key.value);Ee(t,t,r);for(const e of n.item.items)Ee(t,r,e.item)}return De(t),t.items}(t).forEach((t=>{Ee(e,e,t)}))})),De(e),e}function et(e){const t=Le(e.key.value);for(const n of e.value.items)Ee(t,t,n.item);return De(t),t}function tt(e){if(e.items.length>0){const t=e.items[e.items.length-1];e.loc.end.line=t.loc.end.line,e.loc.end.column=t.loc.end.column}else e.loc.end.line=e.key.loc.end.line,e.loc.end.column=e.key.loc.end.column}function nt(e){return Math.max(0,e.length-1)}function rt(e,t,n){var r;for(let l=e.items.length-1;l>=0;l--){const i=e.items[l];if(o(i)&&u(i.value)){const l=[...e.key.item.value,...i.key.value];if(nt(l)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=Le(l);for(const e of i.value.items)Ee(r,r,e.item);Ae(e,e,i),tt(e),t.push(r),rt(r,t,n)}}}}function lt(e,t=Qe.default()){e=function(e){const t=[],n=[];for(const r in e)K(e[r])||Array.isArray(e[r])?n.push(r):t.push(r);const r={};for(let n=0;n<t.length;n++){const l=t[n];r[l]=e[l]}for(let t=0;t<n.length;t++){const l=n[t];r[l]=e[l]}return r}(e=at(e));const n=Ue();for(const r of ot(e,t))Ee(n,n,r);De(n);const r=B(n,(e=>Xe(e,t)),(e=>function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const r of e.items)if(o(r)&&u(r.value)){if(nt(r.key.value)<t.inlineTableStart){const l=et(r);Ae(e,e,r),Ee(e,e,l),rt(l,n,t)}}else"Table"===r.type&&rt(r,n,t);for(const t of n)Ee(e,e,t);return De(e),e}(e,t)),(e=>function(e){return e}(e)));return function(e){let t=0,n=0;for(const r of e.items)0===n&&r.loc.start.line>1?t=1-r.loc.start.line:r.loc.start.line+t>n+2&&(t+=n+2-(r.loc.start.line+t)),_e(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(r)}function*ot(e,t){for(const n of Object.keys(e))yield je([n],it(e[n],t))}function it(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?Be(t):M(t)?function(t){const n=t.toString();return{type:e.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):function(e){return"number"==typeof e&&(!M(e)||!isFinite(e)||Object.is(e,-0))}(t)?function(t){let n;return n=t===1/0?"inf":t===-1/0?"-inf":Number.isNaN(t)?"nan":Object.is(t,-0)?"-0.0":t.toString(),{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):function(e){return"boolean"==typeof e}(t)?function(t){return{type:e.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:t?4:5}},value:t}}(t):j(t)?function(t,n){n.truncateZeroTimeInDates&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new ne(t.toISOString().split("T")[0]));const r=t.toISOString();return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:r.length}},raw:r,value:t}}(t,n):Array.isArray(t)?function(t,n){const r={type:e.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of t){Ee(r,r,Ze(it(e,n)))}return Ce(r,r,n.bracketSpacing),Oe(r,r,n.trailingComma),De(r),r}(t,n):function(t,n){if(t=at(t),!K(t))return it(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},l=[...ot(t,n)];for(const e of l){Ee(r,r,Ze(e))}return Ce(r,r,n.bracketSpacing),Oe(r,r,n.trailingComma),De(r),r}(t,n)}function at(e){return e?j(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const st=/(\r\n|\n)/g;function ct(t,n){const r=[];return we(t,{[e.TableKey](e){const{start:t,end:n}=e.loc;ut(r,{start:t,end:{line:t.line,column:t.column+1}},"["),ut(r,{start:{line:n.line,column:n.column-1},end:n},"]")},[e.TableArrayKey](e){const{start:t,end:n}=e.loc;ut(r,{start:t,end:{line:t.line,column:t.column+2}},"[["),ut(r,{start:{line:n.line,column:n.column-2},end:n},"]]")},[e.KeyValue](e){const{start:{line:t}}=e.loc;ut(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=")},[e.Key](e){ut(r,e.loc,e.raw)},[e.String](e){ut(r,e.loc,e.raw)},[e.Integer](e){ut(r,e.loc,e.raw)},[e.Float](e){ut(r,e.loc,e.raw)},[e.Boolean](e){ut(r,e.loc,e.value.toString())},[e.DateTime](e){ut(r,e.loc,e.raw)},[e.InlineArray](e){const{start:t,end:n}=e.loc;ut(r,{start:t,end:{line:t.line,column:t.column+1}},"["),ut(r,{start:{line:n.line,column:n.column-1},end:n},"]")},[e.InlineTable](e){const{start:t,end:n}=e.loc;ut(r,{start:t,end:{line:t.line,column:t.column+1}},"{"),ut(r,{start:{line:n.line,column:n.column-1},end:n},"}")},[e.InlineItem](e){if(!e.comma)return;const t=e.loc.end;ut(r,{start:t,end:{line:t.line,column:t.column+1}},",")},[e.Comment](e){ut(r,e.loc,e.raw)}}),r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function ut(e,t,n){const r=n.split(st).filter((e=>"\n"!==e&&"\r\n"!==e)),l=t.end.line-t.start.line+1;if(r.length!==l)throw new Error(`Mismatch between location and raw string, expected ${l} lines for "${n}"`);for(let l=t.start.line;l<=t.end.line;l++){const o=ft(e,l);if(void 0===o)throw new Error(`Line ${l} is uninitialized when writing "${n}" at ${t.start.line}:${t.start.column} to ${t.end.line}:${t.end.column}`);const i=l===t.start.line,a=l===t.end.line,s=i?o.substr(0,t.start.column).padEnd(t.start.column," "):"",c=a?o.substr(t.end.column):"";e[l-1]=s+r[l-t.start.line]+c}}function ft(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function mt(t,n=""){const r=L(),l=new Set,o=new Set,i=new Set;let a=r,s=0;return we(t,{[e.Table](e){const t=e.key.item.value;try{pt(r,t,e.type,{tables:l,table_arrays:o,defined:i})}catch(t){const r=t;throw new T(n,e.key.loc.start,r.message)}const s=gt(t);l.add(s),i.add(s),a=ht(r,t)},[e.TableArray](e){const t=e.key.item.value;try{pt(r,t,e.type,{tables:l,table_arrays:o,defined:i})}catch(t){const r=t;throw new T(n,e.key.loc.start,r.message)}const s=gt(t);o.add(s),i.add(s),a=function(e,t){const n=yt(e,t.slice(0,-1)),r=U(t);n[r]||(n[r]=[]);const l=L();return n[U(t)].push(l),l}(r,t)},[e.KeyValue]:{enter(e){if(s>0)return;const t=e.key.value;try{pt(a,t,e.type,{tables:l,table_arrays:o,defined:i})}catch(t){const r=t;throw new T(n,e.key.loc.start,r.message)}const r=dt(e.value);(t.length>1?ht(a,t.slice(0,-1)):a)[U(t)]=r,i.add(gt(t))}},[e.InlineTable]:{enter(){s++},exit(){s--}}}),r}function dt(t){switch(t.type){case e.InlineTable:const n=L();return t.items.forEach((({item:e})=>{const t=e.key.value,r=dt(e.value);(t.length>1?ht(n,t.slice(0,-1)):n)[U(t)]=r})),n;case e.InlineArray:return t.items.map((e=>dt(e.item)));case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function pt(t,n,r,l){let o=[],i=0;for(const e of n){if(o.push(e),!N(t,e))return;if("object"!=typeof(a=t[e])&&!j(a))throw new Error(`Invalid key, a value has already been defined for ${o.join(".")}`);const r=gt(o);if(Array.isArray(t[e])&&!l.table_arrays.has(r))throw new Error(`Invalid key, cannot add to a static array at ${r}`);const s=i++<n.length-1;t=Array.isArray(t[e])&&s?U(t[e]):t[e]}var a;const s=gt(n);if(t&&r===e.Table&&l.defined.has(s))throw new Error(`Invalid key, a table has already been defined named ${s}`);if(t&&r===e.TableArray&&!l.table_arrays.has(s))throw new Error(`Invalid key, cannot add an array of tables to a table at ${s}`)}function ht(e,t){const n=yt(e,t.slice(0,-1)),r=U(t);return n[r]||(n[r]=L()),n[r]}function yt(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=L()),Array.isArray(e[t])?U(e[t]):e[t])),e)}function gt(e){return e.join(".")}var vt,wt,St,Tt;function $t(e){return e.type===vt.Remove}function bt(e,t,n=[]){return e===t||(l=t,j(r=e)&&j(l)&&r.toISOString()===l.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const l=e.map(Z),o=t.map(Z);o.forEach(((i,a)=>{const s=a>=l.length;if(!s&&l[a]===i)return;const c=l.indexOf(i,a+1);if(!s&&c>-1){r.push({type:vt.Move,path:n,from:c,to:a});const e=l.splice(c,1);return void l.splice(a,0,...e)}const u=!o.includes(l[a]);if(!s&&u)return W(r,bt(e[a],t[a],n.concat(a))),void(l[a]=i);r.push({type:vt.Add,path:n.concat(a)}),l.splice(a,0,i)}));for(let e=o.length;e<l.length;e++)r.push({type:vt.Remove,path:n.concat(e)});return r}(e,t,n):K(e)&&K(t)?function(e,t,n=[]){let r=[];const l=Object.keys(e),o=l.map((t=>Z(e[t]))),i=Object.keys(t),a=i.map((e=>Z(t[e]))),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=l[o.indexOf(e)];return!i.includes(n)};return l.forEach(((l,c)=>{const u=n.concat(l);if(i.includes(l))W(r,bt(e[l],t[l],u));else if(s(o[c],a)){const e=i[a.indexOf(o[c])];r.push({type:vt.Rename,path:n,from:l,to:e})}else r.push({type:vt.Remove,path:u})})),i.forEach(((e,t)=>{l.includes(e)||s(a[t],o)||r.push({type:vt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:vt.Edit,path:n}];var r,l}function kt(e,t){if(!t.length)return c(e)&&o(e.item)?e.item:e;if(o(e))return kt(e.value,t);const n={};let i;if(m(e)&&e.items.some(((e,a)=>{try{let s=[];if(o(e))s=e.key.value;else if(r(e))s=e.key.item.value;else if(l(e)){s=e.key.item.value;const t=Z(s);n[t]||(n[t]=0);const r=n[t]++;s=s.concat(r)}else c(e)&&o(e.item)?s=e.item.key.value:c(e)&&(s=[a]);return!(!s.length||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(s,t.slice(0,s.length)))&&(i=kt(e,t.slice(s.length)),!0)}catch(e){return!1}})),!i)throw new Error(`Could not find node at path ${t.join(".")}`);return i}function It(e,t){try{return kt(e,t)}catch(e){}}function Et(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=It(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function xt(t,i,a){const f=[...t],m=mt(f),p={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},h=lt(i,Ge(Object.assign(Object.assign({},a),{inlineTableStart:void 0}),a)),y=function(e){for(let t=0;t<e.length;t++){const n=e[t];if($t(n)){let r=t+1;for(;r<e.length;){const l=e[r];if($t(l)&&l.path[0]===n.path[0]&&l.path[1]>n.path[1]){e.splice(r,1),e.splice(t,0,l),t=0;break}r++}}}return e}(bt(m,i));if(0===y.length)return{tomlString:ct(f,a),document:p};const g=function(e,t,i,a){return i.forEach((i=>{if(function(e){return e.type===vt.Add}(i)){const f=kt(t,i.path),m=i.path.slice(0,-1);let d,p=U(i.path),h=l(f);if(M(p)&&!m.some(M)){const t=It(e,m.concat(0));t&&l(t)&&(h=!0)}if(r(f))d=e;else if(h){d=e;const t=e,n=It(t,m.concat(p-1)),r=It(t,m.concat(p));p=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else d=Et(e,i.path),o(d)&&(d=d.value);if(l(d)||s(d)||n(d)){if(s(d)){const e=qe(d);c(f)&&(f.comma=e)}if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&n(d)&&r(f)){const t=At(f,e,a);Ee(e,d,f,p);for(const n of t)Ee(e,e,n,void 0)}else Ee(e,d,f,p)}else if(u(d)){const t=Ye(d);if(o(f)){const n=Ze(f);n.comma=t,Ee(e,d,n)}else Ee(e,d,f)}else if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&o(f)&&u(f.value)&&r(d)){nt([...d.key.item.value,...f.key.value])<a.inlineTableStart?function(e,t,n,r){const l=t.key.item.value,i=[...l,...e.key.value],a=Le(i);if(u(e.value))for(const t of e.value.items)c(t)&&o(t.item)&&Ee(n,a,t.item,void 0);Ee(n,n,a,void 0),tt(t);const s=At(a,n,r);for(const e of s)Ee(n,n,e,void 0)}(f,d,e,a):Ee(e,d,f)}else 0===a.inlineTableStart&&o(f)&&u(f.value)&&n(d)?Ee(e,d,f,void 0,!0):Ee(e,d,f)}else if(function(e){return e.type===vt.Edit}(i)){let n,r=kt(e,i.path),l=kt(t,i.path);if(o(r)&&o(l)){if(s(r.value)&&s(l.value)){const e=qe(r.value),t=l.value;if(t.items.length>0){t.items[t.items.length-1].comma=e}}if(u(r.value)&&u(l.value)){const e=Ye(r.value),t=l.value;if(t.items.length>0){t.items[t.items.length-1].comma=e}}n=r,r=r.value,l=l.value}else if(o(r)&&c(l)&&o(l.item))n=r,r=r.value,l=l.item.value;else if(c(r)&&o(l))n=r,r=r.item;else if(n=Et(e,i.path),o(n)){const t=i.path.slice(0,-1),r=kt(e,t);o(r)&&s(r.value)&&(n=r.value)}Ie(e,n,r,l)}else if($t(i)){let t=Et(e,i.path);o(t)&&(t=t.value);const n=kt(e,i.path);Ae(e,t,n)}else if(function(e){return e.type===vt.Move}(i)){let t=kt(e,i.path);d(t)&&(t=t.item),o(t)&&(t=t.value);const n=t.items[i.from];Ae(e,t,n),Ee(e,t,n,i.to)}else if(function(e){return e.type===vt.Rename}(i)){let n=kt(e,i.path.concat(i.from)),r=kt(t,i.path.concat(i.to));d(n)&&(n=n.item),d(r)&&(r=r.item),Ie(e,n,n.key,r.key)}})),De(e),e}(p,h,y,a);return{tomlString:ct(g.items,a),document:g}}function At(e,t,n){const r=[],l=(e,r)=>{var i;for(let a=e.items.length-1;a>=0;a--){const s=e.items[a];if(o(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(nt(u)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Le(u);for(const e of s.value.items)c(e)&&o(e.item)&&Ee(t,n,e.item,void 0);e.items.splice(a,1),tt(e),r.push(n),l(n,r)}}}};return l(e,r),r}function Ct(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function Ot(e,t,n,r,l){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!l:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?l.call(e,n):l?l.value=n:t.set(e,n),n}function Dt(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(vt||(vt={})),"function"==typeof SuppressedError&&SuppressedError;function _t(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(_t);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=_t(r);return t}return e}wt=new WeakMap,St=new WeakMap,Tt=new WeakMap,exports.TomlDocument=class{constructor(e){wt.set(this,void 0),St.set(this,void 0),Tt.set(this,void 0),Ot(this,St,e,"f"),Ot(this,wt,Array.from(he(e)),"f"),Ot(this,Tt,Qe.autoDetectFormat(e),"f")}get toTomlString(){return Ct(this,St,"f")}get toJsObject(){return _t(mt(Ct(this,wt,"f")))}get ast(){return Ct(this,wt,"f")}patch(e,t){const n=Ge(t,Ct(this,Tt,"f")),{tomlString:r,document:l}=xt(Ct(this,wt,"f"),e,n);Ot(this,wt,l.items,"f"),Ot(this,St,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Ct(this,Tt,"f").newLine),n=Je(e),r=e.split(n);let l=0;for(;l<t.length&&l<r.length&&t[l]===r[l];)l++;let o=0;if(l<t.length&&l<r.length){const e=t[l],n=r[l];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){o=t;break}}let i=l+1;const{truncatedAst:a,lastEndPosition:s}=function(e,t,n){const r={line:t,column:n},l=[];let o=null;for(const t of e){const e=Dt(t.loc.end,r)<0,n=Dt(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}l.push(t),o=t.loc.end}return{truncatedAst:l,lastEndPosition:o}}(Ct(this,wt,"f"),i,o),c=s?s.line:1,u=s?s.column+1:0,f=r.slice(c-1);f.length>0&&u>0&&(f[0]=f[0].substring(u));const m=f.join(Ct(this,Tt,"f").newLine);Ot(this,wt,Array.from(function*(e,t){for(const t of e)yield t;for(const e of he(t))yield e}(a,m)),"f"),Ot(this,St,e,"f"),Ot(this,Tt,Qe.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(Ot(this,wt,Array.from(he(e)),"f"),Ot(this,St,e,"f"),Ot(this,Tt,Qe.autoDetectFormat(e),"f"))}},exports.TomlFormat=Qe,exports.parse=function(e){return mt(he(e),e)},exports.patch=function(e,t,n){return xt(he(e),t,Ge(n,Qe.autoDetectFormat(e))).tomlString},exports.stringify=function(e,t){const n=Ge(t,Qe.default());return ct(lt(e,n).items,n)};
3
3
  //# sourceMappingURL=toml-patch.cjs.min.js.map