@decimalturn/toml-patch 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
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.
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.0 - 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=D(e,n.index,k)||D(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&&(!D(l,e.index,r)||_(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 D(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 _(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 U(){return Object.create(null)}function F(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 Z(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 P=/\r\n/g,W=/\n/g,z=/^(\r\n|\n)/,V=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function H(e){return e.startsWith("'''")?N(Y(e,3),J):e.startsWith(k)?Y(e,1):e.startsWith('"""')?N(Y(e,3),J,Q,G,q,R):e.startsWith($)?N(Y(e,1),R):e}function q(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(P,"\\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:[H(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(H(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(),Z(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:[H(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(H(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:H(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),Z(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);De({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;De({lines:0,columns:1},Se(e),t);const r=L(t.items);De({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,De({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 De(e,t,n,r){const l=t.get(r||n);l&&(e.lines+=l.lines,e.columns+=l.columns),t.set(n,e)}function _e(){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 Ue(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 Fe(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,Ze=!1;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 We(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return ze(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return ze(e.items);if("KeyValue"===e.type&&e.value)return We(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=We(t);if(null!==e)return e}return null}function ze(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 Ve(e){if(!a(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function He(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 Re(e,t){var n,r,l,o,i;if(e){if(e instanceof Ye)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 Ye(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 Ye{constructor(e,t,n,r,l,o){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,this.truncateZeroTimeInDates=null!=o?o:Ze}static default(){return new Ye("\n",1,Ne,Be,1,Ze)}static autoDetectFormat(e){const t=Ye.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=We(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.truncateZeroTimeInDates=Ze,t}}function Je(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=Xe(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,Ge(t)):function(e){const t=_e();for(const n of e.value.items){const r=Ue(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 Ge(e){const t=Le(e.key.value);for(const n of e.value.items)ke(t,t,n.item);return Ce(t),t}function Qe(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 Xe(e){return Math.max(0,e.length-1)}function et(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(Xe(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),Qe(e),t.push(r),et(r,t,n)}}}}function tt(e,t=Ye.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=lt(e));const n=_e();for(const r of nt(e,t))ke(n,n,r);Ce(n);const r=N(n,(e=>Je(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(Xe(r.key.value)<t.inlineTableStart){const l=Ge(r);Ee(e,e,r),ke(e,e,l),et(l,n,t)}}else"Table"===r.type&&et(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*nt(e,t){for(const n of Object.keys(e))yield Fe([n],rt(e[n],t))}function rt(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):F(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&&(!F(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,n){n.truncateZeroTimeInDates&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new ee(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){ke(r,r,je(rt(e,n)))}return Ae(r,r,n.bracketSpacing),xe(r,r,n.trailingComma),Ce(r),r}(t,n):function(t,n){if(t=lt(t),!K(t))return rt(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},l=[...nt(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 lt(e){return e?M(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const ot=/(\r\n|\n)/g;function it(t,n){const r=[];return ge(t,{[e.TableKey](e){const{start:t,end:n}=e.loc;at(r,{start:t,end:{line:t.line,column:t.column+1}},"["),at(r,{start:{line:n.line,column:n.column-1},end:n},"]")},[e.TableArrayKey](e){const{start:t,end:n}=e.loc;at(r,{start:t,end:{line:t.line,column:t.column+2}},"[["),at(r,{start:{line:n.line,column:n.column-2},end:n},"]]")},[e.KeyValue](e){const{start:{line:t}}=e.loc;at(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=")},[e.Key](e){at(r,e.loc,e.raw)},[e.String](e){at(r,e.loc,e.raw)},[e.Integer](e){at(r,e.loc,e.raw)},[e.Float](e){at(r,e.loc,e.raw)},[e.Boolean](e){at(r,e.loc,e.value.toString())},[e.DateTime](e){at(r,e.loc,e.raw)},[e.InlineArray](e){const{start:t,end:n}=e.loc;at(r,{start:t,end:{line:t.line,column:t.column+1}},"["),at(r,{start:{line:n.line,column:n.column-1},end:n},"]")},[e.InlineTable](e){const{start:t,end:n}=e.loc;at(r,{start:t,end:{line:t.line,column:t.column+1}},"{"),at(r,{start:{line:n.line,column:n.column-1},end:n},"}")},[e.InlineItem](e){if(!e.comma)return;const t=e.loc.end;at(r,{start:t,end:{line:t.line,column:t.column+1}},",")},[e.Comment](e){at(r,e.loc,e.raw)}}),r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function at(e,t,n){const r=n.split(ot).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=st(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 st(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function ct(t,n=""){const r=U(),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{ft(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=pt(t);l.add(s),i.add(s),a=mt(r,t)},[e.TableArray](e){const t=e.key.item.value;try{ft(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=pt(t);o.add(s),i.add(s),a=function(e,t){const n=dt(e,t.slice(0,-1)),r=L(t);n[r]||(n[r]=[]);const l=U();return n[L(t)].push(l),l}(r,t)},[e.KeyValue]:{enter(e){if(s>0)return;const t=e.key.value;try{ft(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=ut(e.value);(t.length>1?mt(a,t.slice(0,-1)):a)[L(t)]=r,i.add(pt(t))}},[e.InlineTable]:{enter(){s++},exit(){s--}}}),r}function ut(t){switch(t.type){case e.InlineTable:const n=U();return t.items.forEach((({item:e})=>{const t=e.key.value,r=ut(e.value);(t.length>1?mt(n,t.slice(0,-1)):n)[L(t)]=r})),n;case e.InlineArray:return t.items.map((e=>ut(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 ft(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=pt(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=pt(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 mt(e,t){const n=dt(e,t.slice(0,-1)),r=L(t);return n[r]||(n[r]=U()),n[r]}function dt(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=U()),Array.isArray(e[t])?L(e[t]):e[t])),e)}function pt(e){return e.join(".")}var yt,ht,gt,vt;function wt(e){return e.type===yt.Remove}function St(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:yt.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 Z(r,St(e[a],t[a],n.concat(a))),void(l[a]=i);r.push({type:yt.Add,path:n.concat(a)}),l.splice(a,0,i)}));for(let e=o.length;e<l.length;e++)r.push({type:yt.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))Z(r,St(e[l],t[l],u));else if(s(o[c],a)){const e=i[a.indexOf(o[c])];r.push({type:yt.Rename,path:n,from:l,to:e})}else r.push({type:yt.Remove,path:u})})),i.forEach(((e,t)=>{l.includes(e)||s(a[t],o)||r.push({type:yt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:yt.Edit,path:n}];var r,l}function Tt(e,t){if(!t.length)return s(e)&&o(e.item)?e.item:e;if(o(e))return Tt(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=Tt(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 bt(e,t){try{return Tt(e,t)}catch(e){}}function $t(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=bt(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function kt(t,i,u){const f=[...t],d=ct(f),p={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},y=tt(i,Re(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(wt(n)){let r=t+1;for(;r<e.length;){const l=e[r];if(wt(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}(St(d,i));if(0===h.length)return{tomlString:it(f,u),document:p};const g=function(e,t,i,u){return i.forEach((i=>{if(function(e){return e.type===yt.Add}(i)){const f=Tt(t,i.path),m=i.path.slice(0,-1);let d,p=L(i.path),y=l(f);if(F(p)&&!m.some(F)){const t=bt(e,m.concat(0));t&&l(t)&&(y=!0)}if(r(f))d=e;else if(y){d=e;const t=e,n=bt(t,m.concat(p-1)),r=bt(t,m.concat(p));p=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else d=$t(e,i.path),o(d)&&(d=d.value);if(l(d)||a(d)||n(d)){if(a(d)){const e=Ve(d);s(f)&&(f.comma=e)}if(void 0!==u.inlineTableStart&&u.inlineTableStart>0&&n(d)&&r(f)){const t=It(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=He(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)){Xe([...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),Qe(t);const u=It(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===yt.Edit}(i)){let n,r=Tt(e,i.path),l=Tt(t,i.path);if(o(r)&&o(l)){if(a(r.value)&&a(l.value)){const e=Ve(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=He(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=$t(e,i.path),o(n)){const t=i.path.slice(0,-1),r=Tt(e,t);o(r)&&a(r.value)&&(n=r.value)}$e(e,n,r,l)}else if(wt(i)){let t=$t(e,i.path);o(t)&&(t=t.value);const n=Tt(e,i.path);Ee(e,t,n)}else if(function(e){return e.type===yt.Move}(i)){let t=Tt(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===yt.Rename}(i)){let n=Tt(e,i.path.concat(i.from)),r=Tt(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:it(g.items,u),document:g}}function It(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(Xe(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),Qe(e),r.push(n),l(n,r)}}}};return l(e,r),r}function Et(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 At(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 xt(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"}(yt||(yt={})),"function"==typeof SuppressedError&&SuppressedError;function Ct(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Ct);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=Ct(r);return t}return e}ht=new WeakMap,gt=new WeakMap,vt=new WeakMap,exports.TomlDocument=class{constructor(e){ht.set(this,void 0),gt.set(this,void 0),vt.set(this,void 0),At(this,gt,e,"f"),At(this,ht,Array.from(de(e)),"f"),At(this,vt,Ye.autoDetectFormat(e),"f")}get toTomlString(){return Et(this,gt,"f")}get toJsObject(){return Ct(ct(Et(this,ht,"f")))}get ast(){return Et(this,ht,"f")}patch(e,t){const n=Re(t,Et(this,vt,"f")),{tomlString:r,document:l}=kt(Et(this,ht,"f"),e,n);At(this,ht,l.items,"f"),At(this,gt,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Et(this,vt,"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=xt(t.loc.end,r)<0,n=xt(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}l.push(t),o=t.loc.end}return{truncatedAst:l,lastEndPosition:o}}(Et(this,ht,"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(Et(this,vt,"f").newLine);At(this,ht,Array.from(function*(e,t){for(const t of e)yield t;for(const e of de(t))yield e}(a,m)),"f"),At(this,gt,e,"f"),At(this,vt,Ye.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(At(this,ht,Array.from(de(e)),"f"),At(this,gt,e,"f"),At(this,vt,Ye.autoDetectFormat(e),"f"))}},exports.TomlFormat=Ye,exports.parse=function(e){return ct(de(e),e)},exports.patch=function(e,t,n){return kt(de(e),t,Re(n,Ye.autoDetectFormat(e))).tomlString},exports.stringify=function(e,t){const n=Re(t,Ye.default());return it(tt(e,n).items,n)};
|
|
3
3
|
//# sourceMappingURL=toml-patch.cjs.min.js.map
|