@decimalturn/toml-patch 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/toml-patch.d.ts +1 -1
- package/dist/toml-patch.js +2 -2
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.1] - 2026-02-14
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Improve parsing and conversion performance ([#105](https://github.com/DecimalTurn/toml-patch/pull/105))
|
|
14
|
+
- Better benchmarking ([#104](https://github.com/DecimalTurn/toml-patch/pull/104))
|
|
15
|
+
- Migrate benchmarks from CommonJS to ESM modules
|
|
16
|
+
- Improve benchmark output with colored tables and formatted results
|
|
17
|
+
- Support benchmarking multiple package versions with automatic caching (`--versions`)
|
|
18
|
+
- Add CLI filters for benchmarks (`--package`, `--file`, `--example`)
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- Profiling support via `npm run profile` ([#105](https://github.com/DecimalTurn/toml-patch/pull/105))
|
|
22
|
+
|
|
10
23
|
## [1.0.0] - 2026-02-12
|
|
11
24
|
|
|
12
25
|
### Changed
|
package/dist/toml-patch.d.ts
CHANGED
package/dist/toml-patch.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v1.0.
|
|
2
|
-
var e,t;function n(t){return t.type===e.Document}function r(t){return t.type===e.Table}function o(t){return t.type===e.TableArray}function i(t){return t.type===e.KeyValue}function l(t){return t.type===e.String}function a(t){return t.type===e.DateTime}function s(t){return t.type===e.InlineArray}function c(t){return t.type===e.InlineItem}function u(t){return t.type===e.InlineTable}function f(t){return t.type===e.Comment}function d(e){return n(e)||r(e)||o(e)||u(e)||s(e)}function m(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}!function(e){e.Document="Document",e.Table="Table",e.TableKey="TableKey",e.TableArray="TableArray",e.TableArrayKey="TableArrayKey",e.KeyValue="KeyValue",e.Key="Key",e.String="String",e.Integer="Integer",e.Float="Float",e.Boolean="Boolean",e.DateTime="DateTime",e.InlineArray="InlineArray",e.InlineItem="InlineItem",e.InlineTable="InlineTable",e.Comment="Comment"}(e||(e={}));class h{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 w(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function g(e,t){const n=Array.isArray(e)?e:y(e),r=n.findIndex((e=>e>=t))+1;return{line:r,column:t-(n[r-2]+1||0)}}function y(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];"\n"===r?t.push(n):"\r"===r&&("\n"===e[n+1]?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function v(e){return{line:e.line,column:e.column}}function b(e){return{start:v(e.start),end:v(e.end)}}class $ 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=y(e),r=void 0!==n[t.line-2]?n[t.line-2]+1:0,o=n[t.line-1]||e.length;return e.substring(r,o)}(e,t),o=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(r+=`${n}\n${o}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}}!function(e){e.Bracket="Bracket",e.Curly="Curly",e.Equal="Equal",e.Comma="Comma",e.Dot="Dot",e.Comment="Comment",e.Literal="Literal"}(t||(t={}));const S=/\s/,T='"',I="'",k=/[\w,\d,\",\',\+,\-,\_]/;function*x(e){const n=new h("string"==typeof(r=e)?function*(e){for(let t=0;t<e.length;t++)yield e[t]}(r):r[Symbol.iterator]());var r;n.next();const o=function(e){const t=y(e);return(e,n)=>({start:g(t,e),end:g(t,n)})}(e);for(;!n.done;){const r=n.value.charCodeAt(0);if((r<=31||127===r)&&9!==r&&13!==r&&10!==r)throw new $(e,g(e,n.index),`Control character 0x${r.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);if("\r"===n.value){const t=n.peek();if(t.done||"\n"!==t.value)throw new $(e,g(e,n.index),"Invalid standalone CR (\\r); CR must be part of a CRLF sequence")}if(S.test(n.value));else if("["===n.value||"]"===n.value)yield E(n,o,t.Bracket);else if("{"===n.value||"}"===n.value)yield E(n,o,t.Curly);else if("="===n.value)yield E(n,o,t.Equal);else if(","===n.value)yield E(n,o,t.Comma);else if("."===n.value)yield E(n,o,t.Dot);else if("#"===n.value)yield A(n,o,e);else{const t=O(e,n.index,I)||O(e,n.index,T);t?yield C(n,o,t,e):yield _(n,o,e)}n.next()}}function E(e,t,n){return{type:n,raw:e.value,loc:t(e.index,e.index+1)}}function A(e,n,r){const o=e.index;let i=e.value;for(;!e.peek().done&&"\n"!==e.peek().value&&"\r"!==e.peek().value;){e.next();const t=e.value.charCodeAt(0);if((t<=31||127===t)&&9!==t)throw new $(r,g(r,e.index),`Control character 0x${t.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);i+=e.value}return{type:t.Comment,raw:i,loc:n(o,e.index+1)}}function C(e,n,r,o){const i=e.index,l=r+r+r;let a=l;for(e.next(),e.next(),e.next();!e.done;){if(O(o,e.index,r)){let t=3;for(;o[e.index+t]===r;)t++;if(t>=6)throw new $(o,g(o,e.index),`Invalid multiline string: ${t} consecutive ${r} characters`);if(3===t)break;a+=r.repeat(t-3);for(let n=0;n<t-3;n++)e.next();break}if("\r"===e.value){const t=e.peek();if(t.done||"\n"!==t.value)throw new $(o,g(o,e.index),"Invalid standalone CR (\\r) in multiline string (must be part of CRLF sequence)")}const t=e.value.charCodeAt(0);if((t<=31||127===t)&&9!==t&&10!==t&&13!==t){const n=r===T?"multiline basic strings":"multiline literal strings",i=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let l="";0===t?l="Null":127===t&&(l="DEL");const a=l?`${l} (control character ${i}) is not allowed in ${n}`:`Control character ${i} is not allowed in ${n}`;throw new $(o,g(o,e.index),a)}a+=e.value,e.next()}if(e.done){if(r===T){const t=o.slice(0,e.index);if(/\\"+$/.test(t))throw new $(o,g(o,e.index),`Expected close of multiline string with ${l}, reached end of file. Check for escape sequences (\\) that may be preventing proper string closure`)}throw new $(o,g(o,e.index),`Expected close of multiline string with ${l}, reached end of file`)}return a+=l,e.next(),e.next(),{type:t.Literal,raw:a,loc:n(i,e.index+1)}}function _(e,n,r){if(!k.test(e.value))throw new $(r,g(r,e.index),`Unsupported character "${e.value}". Expected ALPHANUMERIC, ", ', +, -, or _`);const o=e.index;let i=e.value,l=e.value===T,a=e.value===I;const s=e=>{if(e.peek().done)return!0;const t=e.peek().value;return!(l||a)&&(S.test(t)||","===t||"."===t||"]"===t||"}"===t||"="===t||"#"===t)};for(;!e.done&&!s(e);){if(e.next(),l||a){const t=e.value.charCodeAt(0);if((t<=31||127===t)&&9!==t){const n=l?"basic strings":"literal strings",o=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let i="";10===t?i="Newline":13===t?i="Carriage return":0===t?i="Null":127===t&&(i="DEL");const a=i?`${i} (control character ${o}) is not allowed in ${n}`:`Control character ${o} is not allowed in ${n}`;throw new $(r,g(r,e.index),a)}}if(e.value===T&&(l=!l),e.value!==I||l||(a=!a),i+=e.value,e.peek().done)break;let t=e.peek().value;l&&"\\"===e.value&&(t===T?(i+=T,e.next()):"\\"===t&&(i+="\\",e.next()))}if(l||a)throw new $(r,g(r,o),`Expected close of string with ${l?T:I}`);return{type:t.Literal,raw:i,loc:n(o,e.index+1)}}function O(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===I)return n;const r=e.slice(0,t).match(/\\+$/);if(!r)return n;return!(r[0].length%2!=0)&&n}function U(e){return e[e.length-1]}function D(){return Object.create(null)}function F(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function L(e){return"[object Date]"===Object.prototype.toString.call(e)}function M(e){return e&&"object"==typeof e&&!L(e)&&!Array.isArray(e)}function K(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function N(e,...t){return t.reduce(((e,t)=>t(e)),e)}function j(e){if(M(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${j(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(j).join(",")}]`:JSON.stringify(e)}function Z(e,t){const n=e.length,r=t.length;e.length=n+r;for(let o=0;o<r;o++)e[n+o]=t[o]}function W(e){return e.startsWith('"""')||e.startsWith("'''")}const z=/\r\n/g,B=/\n/g,q=/^(\r\n|\n)/,V=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function P(e){return e.startsWith("'''")?N(Y(e,3),X):e.startsWith(I)?Y(e,1):e.startsWith('"""')?N(Y(e,3),X,Q,G,R,J):e.startsWith(T)?N(Y(e,1),J):e}function R(e){let t="",n=0;for(let r=0;r<e.length;r++){const o=e[r];t+='"'===o&&n%2==0?'\\"':o,"\\"===o?n++:n=0}return t}function H(e,t){let n=0;for(let r=t-1;r>=0&&"\\"===e[r];r--)n++;return n%2!=0}function J(e){const t=/\\(.)/g;let n;for(;null!==(n=t.exec(e));){if(H(e,n.index))continue;const t=n[1];if(!["b","t","n","f","r",'"',"\\","e","u","U","x"].includes(t))throw new Error(`Invalid escape sequence: \\${t}`)}const r=/\\u([a-fA-F0-9]{4})/g,o=e;for(;null!==(n=r.exec(o));){if(H(o,n.index))continue;const e=n[1],t=parseInt(e,16);if(t>=55296&&t<=57343)throw new Error(`Invalid Unicode escape: \\u${e} (surrogate codepoints are not allowed)`)}const i=e;let l=i.replace(/\\x([a-fA-F0-9]{2})/g,((e,t,n)=>{if(H(i,n))return e;const r=parseInt(t,16),o=String.fromCharCode(r);return r<32||34===r||92===r?Y(JSON.stringify(o),1):o}));const a=l;l=a.replace(/\\e/g,((e,t)=>H(a,t)?e:"\\u001b"));const s=l.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)})),c=s.replace(/\t/g,"\\t");return JSON.parse(`"${c}"`)}function Y(e,t){return e.slice(t,e.length-t)}function X(e){return e.replace(q,"")}function G(e){return e.replace(z,"\\r\\n").replace(B,"\\n")}function Q(e){return e.replace(V,((e,t)=>e.replace(t,"")))}class ee{static createDateWithOriginalFormat(e,t){if(ee.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof oe)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new re(t,!1)}const t=e.toISOString().split("T")[0];return new te(t)}if(ee.IS_TIME_ONLY.test(t)){if(e instanceof ne)return e;{const n=t.match(/\.(\d+)\s*$/),r=e.toISOString();if(r&&r.includes("T")){let o=r.split("T")[1].split("Z")[0];if(n){const t=n[1].length,[r,i,l]=o.split(":"),[a]=l.split(".");o=`${r}:${i}:${a}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new ne(o,t)}{const r=String(e.getUTCHours()).padStart(2,"0"),o=String(e.getUTCMinutes()).padStart(2,"0"),i=String(e.getUTCSeconds()).padStart(2,"0"),l=e.getUTCMilliseconds();let a;if(n){const e=n[1].length;a=`${r}:${o}:${i}.${String(l).padStart(3,"0").slice(0,e)}`}else if(l>0){a=`${r}:${o}:${i}.${String(l).padStart(3,"0").replace(/0+$/,"")}`}else a=`${r}:${o}:${i}`;return new ne(a,t)}}}if(ee.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,[o,i]=r.split("T"),[l,a,s]=i.split(":"),[c]=s.split(".");r=`${o}T${l}:${a}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new re(r,!1,t)}if(ee.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,[o,i]=r.split(" "),[l,a,s]=i.split(":"),[c]=s.split(".");r=`${o} ${l}:${a}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new re(r,!0,t)}if(ee.IS_OFFSET_DATETIME_T.test(t)||ee.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),r=n?"z"===n[1]?"Z":n[1]:"Z",o=ee.IS_OFFSET_DATETIME_SPACE.test(t),i=t.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),l=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(l+6e4*a),c=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=String(s.getUTCHours()).padStart(2,"0"),m=String(s.getUTCMinutes()).padStart(2,"0"),h=String(s.getUTCSeconds()).padStart(2,"0"),p=s.getUTCMilliseconds(),w=o?" ":"T";let g=`${d}:${m}:${h}`;if(i){const e=i[1].length;g+=`.${String(p).padStart(3,"0").slice(0,e)}`}else if(p>0){g+=`.${String(p).padStart(3,"0").replace(/0+$/,"")}`}return new oe(`${c}-${u}-${f}${w}${g}${r}`,o)}return e}}ee.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,ee.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,ee.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,ee.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,ee.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,ee.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,ee.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,ee.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class te extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class ne extends Date{constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+":00"),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){const e=String(this.getUTCHours()).padStart(2,"0"),t=String(this.getUTCMinutes()).padStart(2,"0"),n=String(this.getUTCSeconds()).padStart(2,"0"),r=this.getUTCMilliseconds();if(this.originalFormat&&this.originalFormat.includes(".")){const o=this.originalFormat.match(/\.(\d+)\s*$/),i=o?o[1].length:3;return`${e}:${t}:${n}.${String(r).padStart(3,"0").slice(0,i)}`}if(r>0){return`${e}:${t}:${n}.${String(r).padStart(3,"0").replace(/0+$/,"")}`}return`${e}:${t}:${n}`}}class re extends Date{constructor(e,t=!1,n){let r=e;/\d{2}:\d{2}:\d{2}/.test(e)||(r=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(r.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"),o=String(this.getUTCMinutes()).padStart(2,"0"),i=String(this.getUTCSeconds()).padStart(2,"0"),l=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}:${o}:${i}.${String(l).padStart(3,"0").slice(0,t)}`}if(l>0){return`${a}${s}${r}:${o}:${i}.${String(l).padStart(3,"0").replace(/0+$/,"")}`}return`${a}${s}${r}:${o}:${i}`}}class oe extends Date{constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(n.replace(" ","T")),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=e;const r=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);r&&(this.originalOffset="z"===r[1]?"Z":r[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(),o=String(n.getUTCMonth()+1).padStart(2,"0"),i=String(n.getUTCDate()).padStart(2,"0"),l=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}-${o}-${i}`,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}${l}:${a}:${s}.${String(c).padStart(3,"0").slice(0,t)}${this.originalOffset}`}if(c>0){return`${u}${f}${l}:${a}:${s}.${String(c).padStart(3,"0").replace(/0+$/,"")}${this.originalOffset}`}return`${u}${f}${l}:${a}:${s}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const ie=ee,le="true",ae=/e/i,se=/\_/g,ce=/^[+\-]?inf$/,ue=/^[+\-]?nan$/,fe=/^[+\-]?0x/i,de=/^[+\-]?0o/i,me=/^[+\-]?0b/i;function*he(e){const t=new h(x(e));for(;!t.next().done;){const n=Se(t,e);for(const e of n)yield e}}function pe(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function we(n,r){const o=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,i=o===e.Table;if(i&&"["!==n.value.raw)throw new $(r,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!i){const e=n.peek();if(e.done)throw new $(r,n.value.loc.start,'Expected second "[" for array of tables opening, found end of input');if("["!==n.value.raw||"["!==e.value.raw)throw new $(r,n.value.loc.start,`Expected array of tables opening "[[", found ${n.value.raw+e.value.raw}`);const t=n.value,o=e.value;if(t.loc.end.line!==o.loc.start.line||t.loc.end.column!==o.loc.start.column)throw new $(r,t.loc.start,"Array of tables opening brackets must be immediately adjacent with no whitespace: [[table]]")}const l=i?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};if(n.next(),o===e.TableArray&&n.next(),n.done)throw new $(r,l.loc.start,"Expected table key, reached end of file");if(n.value.type===t.Bracket&&"]"===n.value.raw)throw new $(r,n.value.loc.start,o===e.TableArray?"Array of tables header [[]] requires a table name":"Table header [] requires a table name");const a=n.value.raw;if(a.startsWith('"""')||a.startsWith("'''"))throw new $(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(a.startsWith('"')||a.startsWith("'")))for(let e=0;e<a.length;e++){const t=a[e];if(!/[A-Za-z0-9_-]/.test(t))throw new $(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${t}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}let s;try{s=[P(n.value.raw)]}catch(e){const t=e;throw new $(r,n.value.loc.start,t.message)}for(l.item={type:e.Key,loc:b(n.value.loc),raw:n.value.raw,value:s};!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=n.value.raw;if(!(t.startsWith('"')||t.startsWith("'")))for(let e=0;e<t.length;e++){const o=t[e];if(!/[A-Za-z0-9_-]/.test(o))throw new $(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${o}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}const o=" ".repeat(e.loc.start.column-l.item.loc.end.column),i=" ".repeat(n.value.loc.start.column-e.loc.end.column);l.item.loc.end=n.value.loc.end,l.item.raw+=`${o}.${i}${n.value.raw}`;try{l.item.value.push(P(n.value.raw))}catch(e){const t=e;throw new $(r,n.value.loc.start,t.message)}}if(n.next(),!n.done){const e=l.loc.start.line;if(n.value.loc.start.line!==e)throw new $(r,n.value.loc.start,i?`Table header must not contain newlines. Expected closing ']' on line ${e}, found on line ${n.value.loc.start.line}`:`Unclosed array of tables header: expected closing ']]' on line ${e}, found newline`)}if(i&&(n.done||"]"!==n.value.raw))throw new $(r,n.done?l.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!i&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new $(r,n.done||n.peek().done?l.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}`);if(!i){const e=n.value,t=n.peek().value;if(e.loc.end.line!==t.loc.start.line||e.loc.end.column!==t.loc.start.column)throw new $(r,e.loc.start,"Array of tables closing brackets must be immediately adjacent with no whitespace: ]]")}if(i||n.next(),l.loc.end=n.value.loc.end,!n.peek().done){const e=n.peek().value;if(e.loc.start.line===l.loc.end.line&&e.type!==t.Comment)throw new $(r,e.loc.start,`Unexpected content after ${i?"table":"array of tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;)n.next(),Z(c,Se(n,r));return{type:i?e.Table:e.TableArray,loc:{start:v(l.loc.start),end:v(c.length?c[c.length-1].loc.end:l.loc.end)},key:l,items:c}}function ge(t,n){let r;try{r=P(t.value.raw)}catch(e){const r=e;throw new $(n,t.value.loc.start,r.message)}return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:r}}function ye(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===le}}function ve(n,r){let o,i=n.value.loc,l=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&ie.IS_FULL_DATE.test(l)&&ie.IS_FULL_TIME.test(n.peek().value.raw)){const e=i.start;n.next(),i={start:e,end:n.value.loc.end},l+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=i.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new $(r,n.value.loc.end,"Expected fractional value for DateTime");n.next(),i={start:e,end:n.value.loc.end},l+=`.${n.value.raw}`}if(function(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new $(t,n,`Invalid datetime "${e}": fractional seconds must have at least one digit after decimal point`);if(/[+-]$/.test(e))throw new $(t,n,`Invalid datetime "${e}": timezone offset requires hour and minute components`);const r=/\d{2}:\d{2}/.test(e),o=r?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(o){const e=o[0],r=o[2],i=o[3],l=o[4];if(":"!==i)throw new $(t,n,`Invalid timezone offset "${e}": must use colon separator (e.g., +09:09)`);if(2!==r.length)throw new $(t,n,`Invalid timezone offset "${e}": hour must be exactly 2 digits`);if(!l||0===l.length)throw new $(t,n,`Invalid timezone offset "${e}": minute component is required`);if(2!==l.length)throw new $(t,n,`Invalid timezone offset "${e}": minute must be exactly 2 digits`);const a=parseInt(r,10);if(a<0||a>23)throw new $(t,n,`Invalid timezone offset "${e}": hour must be between 00 and 23, found ${r}`);const s=parseInt(l,10);if(s<0||s>59)throw new $(t,n,`Invalid timezone offset "${e}": minute must be between 00 and 59, found ${l}`)}const i=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!i.test(e)){if(/^\d{4}-\d{2}-\d{2}T$/.test(e))throw new $(t,n,`Invalid date "${e}": date cannot end with 'T' without a time component`);if(/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e))throw new $(t,n,`Invalid date "${e}": unexpected character after date`);if(/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e))throw new $(t,n,`Invalid datetime "${e}": missing separator 'T' or space between date and time`);throw new $(t,n,`Invalid datetime "${e}"`)}const l=e.match(/^(\d+)-/);if(l&&4!==l[1].length)throw new $(t,n,`Invalid date "${e}": year must be exactly 4 digits, found ${l[1].length}`);const a=/^(\d+)-(\d+)-(\d+)/,s=e.match(a);if(s){const[,,r,o]=s;if(2!==r.length)throw new $(t,n,`Invalid date "${e}": month must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new $(t,n,`Invalid date "${e}": day must be exactly 2 digits, found ${o.length}`)}const c=/[T ](\d+):(\d+)(?::(\d+))?/,u=e.match(c);if(u){const[,r,o,i]=u;if(2!==r.length)throw new $(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new $(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(i&&2!==i.length)throw new $(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${i.length}`)}const f=/^(\d+):(\d+)(?::(\d+))?/,d=e.match(f);if(d&&!s){const[,r,o,i]=d;if(2!==r.length)throw new $(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new $(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(i&&2!==i.length)throw new $(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${i.length}`)}const m=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),h=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(m){const[,r,o,i,l,a,s]=m,c=parseInt(o,10);if(c<1||c>12)throw new $(t,n,`Invalid date "${e}": month must be between 01 and 12`);const u=parseInt(i,10);if(u<1||u>31)throw new $(t,n,`Invalid date "${e}": day must be between 01 and 31`);const f=function(e,t){const n=[31,28,31,30,31,30,31,31,30,31,30,31];if(2===t){return e%4==0&&e%100!=0||e%400==0?29:28}return n[t-1]}(parseInt(r,10),c);if(u>f)throw new $(t,n,`Invalid date "${e}": day ${i} is invalid for month ${o} in year ${r}`);if(void 0!==l){const r=parseInt(l,10);if(r<0||r>23)throw new $(t,n,`Invalid time "${e}": hour must be between 00 and 23`)}if(void 0!==a){const r=parseInt(a,10);if(r<0||r>59)throw new $(t,n,`Invalid time "${e}": minute must be between 00 and 59`)}if(void 0!==s){const r=parseInt(s,10);if(r<0||r>60)throw new $(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}else if(h){const[,r,o,i]=h,l=parseInt(r,10);if(l<0||l>23)throw new $(t,n,`Invalid time "${e}": hour must be between 00 and 23`);const a=parseInt(o,10);if(a<0||a>59)throw new $(t,n,`Invalid time "${e}": minute must be between 00 and 59`);if(void 0!==i){const r=parseInt(i,10);if(r<0||r>60)throw new $(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}}(l,r,i.start),ie.IS_FULL_DATE.test(l))o=ie.IS_DATE_ONLY.test(l)?new te(l):ie.IS_LOCAL_DATETIME_T.test(l)?new re(l,!1):ie.IS_LOCAL_DATETIME_SPACE.test(l)?new re(l,!0):ie.IS_OFFSET_DATETIME_T.test(l)?new oe(l,!1):ie.IS_OFFSET_DATETIME_SPACE.test(l)?new oe(l,!0):new Date(l.replace(" ","T"));else if(ie.IS_TIME_ONLY.test(l))o=new ne(l,l);else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${l}`)}return{type:e.DateTime,loc:i,raw:l,value:o}}function be(n,r){let o,i=n.value.loc,l=n.value.raw;if(ce.test(l))o=l.startsWith("-")?-1/0:1/0;else if(ue.test(l))o=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(/_$/.test(l))throw new $(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(l))throw new $(r,i.start,"Leading underscore is not allowed");if(/__/.test(l))throw new $(r,i.start,"Consecutive underscores are not allowed");if(/[eE][+\-]?$/.test(l))throw new $(r,i.start,`Invalid float "${l}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(l))throw new $(r,i.start,`Invalid float "${l}": decimal point not allowed in exponent`);if(/_[eE]/.test(l))throw new $(r,i.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(l))throw new $(r,i.start,"Underscore at start of exponent is not allowed");if(!n.peek().done&&n.peek().value.type===t.Dot)throw new $(r,n.peek().value.loc.start,`Invalid float "${l}.": cannot have decimal point after exponent`);const e=l.replace(se,"");if(/^[+\-]?0\d/.test(e)&&!fe.test(l)&&!de.test(l)&&!me.test(l))throw new $(r,i.start,"Leading zeros are not allowed in the integer part of a float");o=Number(l.replace(se,""))}else{const e=i.start;{if(ae.test(l)&&!fe.test(l))throw new $(r,i.start,`Invalid float "${l}": cannot have decimal point after exponent`);const e=l,t=e.replace(se,"");if(/^[+\-]?0\d/.test(t)&&!fe.test(e)&&!de.test(e)&&!me.test(e))throw new $(r,i.start,"Leading zeros are not allowed in the integer part of a float");const n=e.replace(/^[+\-]/,"");if(""===n||"_"===n)throw new $(r,i.start,"Invalid float: decimal point must be preceded by at least one digit");if(/_$/.test(e))throw new $(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(e))throw new $(r,i.start,"Leading underscore is not allowed");if(/__/.test(e))throw new $(r,i.start,"Consecutive underscores are not allowed")}if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new $(r,n.value.loc.end,"Expected fraction value for Float");n.next(),l+=`.${n.value.raw}`,i={start:e,end:n.value.loc.end};{const e=n.value.raw;if(!/^\d/.test(e))throw new $(r,n.value.loc.start,`Invalid float: fractional part must start with a digit, found "${e}"`);if(/^_/.test(e))throw new $(r,n.value.loc.start,"Underscore after decimal point is not allowed");if(/_$/.test(e))throw new $(r,n.value.loc.start,"Trailing underscore in fractional part is not allowed");if(/_[eE]/.test(e))throw new $(r,n.value.loc.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(e))throw new $(r,n.value.loc.start,"Underscore at start of exponent is not allowed");if(/[eE][+\-]?$/.test(e))throw new $(r,n.value.loc.start,`Invalid float "${l}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(e))throw new $(r,n.value.loc.start,`Invalid float "${l}": decimal point not allowed in exponent`)}o=Number(l.replace(se,""))}if(Number.isNaN(o)&&!ue.test(l))throw new $(r,i.start,`Invalid float "${l}"`);return{type:e.Float,loc:i,raw:l,value:o}}function $e(t,n){const r=t.value.raw,o=t.value.loc;if(/^\d{1,}-\d{1,}/.test(r)||/^\d{1,}:\d{1,}/.test(r)||/^\d{6}-\d{2}$/.test(r))throw new $(n,o.start,`Invalid integer "${r}"`);{if("-0"===r||"+0"===r)return{type:e.Integer,loc:o,raw:r,value:0};if(/^[+\-]{2,}/.test(r))throw new $(n,o.start,"Double sign is not allowed in integers");const t=r.replace(/_/g,"");if(/^[+\-]?0\d/.test(t)&&!fe.test(r)&&!de.test(r)&&!me.test(r))throw new $(n,o.start,"Leading zeros are not allowed in decimal integers");if(/_$/.test(r))throw new $(n,o.start,"Underscores in numbers must be surrounded by digits");if(/^[+\-]?_/.test(r))throw new $(n,o.start,"Underscores in numbers must be surrounded by digits");if(/__/.test(r))throw new $(n,o.start,"Consecutive underscores in numbers are not allowed")}let i,l=10;if(fe.test(r)){if(l=16,/^[+\-]?0X/.test(r))throw new $(n,o.start,'Hexadecimal prefix must be lowercase "0x"');if(/^[+\-]?0x_/.test(r))throw new $(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0x/i,""),!i||"_"===i||/^_/.test(i))throw new $(n,o.start,"Incomplete hexadecimal number");const e=i.replace(/_/g,"");if(!/^[0-9a-fA-F]+$/.test(e))throw new $(n,o.start,"Invalid hexadecimal digits");if(/^[+\-]/.test(r))throw new $(n,o.start,"Hexadecimal numbers cannot have a sign prefix")}else if(de.test(r)){if(l=8,/^[+\-]?0O/.test(r))throw new $(n,o.start,'Octal prefix must be lowercase "0o"');if(/^[+\-]?0o_/.test(r))throw new $(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0o/i,""),!i||"_"===i||/^_/.test(i))throw new $(n,o.start,"Incomplete octal number");const e=i.replace(/_/g,"");if(!/^[0-7]+$/.test(e))throw new $(n,o.start,"Invalid octal digits (must be 0-7)");if(/^[+\-]/.test(r))throw new $(n,o.start,"Octal numbers cannot have a sign prefix")}else if(me.test(r)){if(l=2,/^[+\-]?0B/.test(r))throw new $(n,o.start,'Binary prefix must be lowercase "0b"');if(/^[+\-]?0b_/.test(r))throw new $(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0b/i,""),!i||"_"===i||/^_/.test(i))throw new $(n,o.start,"Incomplete binary number");const e=i.replace(/_/g,"");if(!/^[01]+$/.test(e))throw new $(n,o.start,"Invalid binary digits (must be 0 or 1)");if(/^[+\-]/.test(r))throw new $(n,o.start,"Binary numbers cannot have a sign prefix")}const a=parseInt(r.replace(se,"").replace(de,"").replace(me,""),l);if(Number.isNaN(a))throw new $(n,o.start,`Invalid integer "${r}"`);return{type:e.Integer,loc:o,raw:r,value:a}}function Se(n,r){if(n.value.type===t.Comment)return[pe(n)];if(n.value.type===t.Bracket)return[we(n,r)];if(n.value.type===t.Literal)return function(n,r){const o=n.value.raw;if(o.endsWith(":"))throw new $(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+[...o].length-1},"Use '=' to separate keys and values, not ':'");if(o.startsWith('"""')||o.startsWith("'''"))throw new $(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!o.startsWith('"')&&!o.startsWith("'"))for(let e=0;e<o.length;e++){const t=o[e];if(!/[A-Za-z0-9_-]/.test(t))throw new $(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${t}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}let i;try{i=[P(n.value.raw)]}catch(e){const t=e;throw new $(r,n.value.loc.start,t.message)}const l={type:e.Key,loc:b(n.value.loc),raw:n.value.raw,value:i};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next(),n.next();const e=n.value.raw;if(e.startsWith('"""')||e.startsWith("'''"))throw new $(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(e.startsWith('"')||e.startsWith("'")))for(let t=0;t<e.length;t++){const o=e[t];if(!/[A-Za-z0-9_-]/.test(o))throw new $(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+t},`Invalid character '${o}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}l.loc.end=n.value.loc.end,l.raw+=`.${n.value.raw}`;try{l.value.push(P(n.value.raw))}catch(e){const t=e;throw new $(r,n.value.loc.start,t.message)}}if(n.next(),!n.done&&n.value.loc.start.line!==l.loc.end.line)throw new $(r,n.value.loc.start,'Expected "=" for key-value on the same line as the key');if(n.done||n.value.type!==t.Equal){if(!n.done&&":"===n.value.raw)throw new $(r,n.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new $(r,n.done?l.loc.end:n.value.loc.start,'Expected "=" for key-value')}const a=n.value.loc.start.column,s=n.value.loc.start.line;if(n.next(),n.done)throw new $(r,l.loc.start,"Expected value for key-value, reached end of file");if(n.value.loc.start.line!==s)throw new $(r,n.value.loc.start,"Expected value on the same line as the '=' sign");if(n.done)throw new $(r,l.loc.start,"Expected value for key-value");const c=Te(n,r),u=c[0],f=c.slice(1);if(!n.peek().done){const o=n.peek().value;if(o.type===t.Dot&&o.loc.start.line===u.loc.end.line&&(u.type===e.Float||u.type===e.Integer))throw new $(r,o.loc.start,"Invalid number: multiple decimal points not allowed");if((o.type===t.Literal||o.type===t.Bracket)&&o.loc.start.line===u.loc.end.line)throw new $(r,o.loc.start,"Key/value pairs must be separated by a newline")}return[{type:e.KeyValue,key:l,value:u,loc:{start:v(l.loc.start),end:v(u.loc.end)},equals:a},...f]}(n,r);throw n.value.type===t.Equal?new $(r,n.value.loc.start,"Missing key before '='"):new $(r,n.value.loc.start,`Unexpected token "${n.value.type}". Expected Comment, Bracket, or String`)}function Te(n,r){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===T||e[0]===I?[ge(n,r)]:e===le||"false"===e?[ye(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[ve(n,r)]:!n.peek().done&&n.peek().value.type===t.Dot||ce.test(e)||ue.test(e)||ae.test(e)&&!fe.test(e)?[be(n,r)]:[$e(n,r)]}if(n.value.type===t.Curly){const[o,i]=function(n,r){if("{"!==n.value.raw)throw new $(r,n.value.loc.start,'Expected "{" for inline table');const o={type:e.InlineTable,loc:b(n.value.loc),items:[]},i=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){i.push(pe(n)),n.next();continue}if(n.value.type===t.Comma){const e=o.items[o.items.length-1];if(!e)throw new $(r,n.value.loc.start,'Found "," without previous value in inline table');if(e.comma)throw new $(r,n.value.loc.start,"Found consecutive commas in inline table (double comma is not allowed)");e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const l=o.items[o.items.length-1];if(l&&!l.comma)throw new $(r,n.value.loc.start,"Missing comma between inline table items");const a=Se(n,r),s=a[0],c=a.slice(1);s.type===e.KeyValue&&(o.items.push({type:e.InlineItem,loc:b(s.loc),item:s,comma:!1}),Z(i,c)),n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new $(r,n.done?o.loc.start:n.value.loc.start,'Expected "}"');return o.loc.end=n.value.loc.end,[o,i]}(n,r);return[o,...i]}if(n.value.type===t.Bracket){const[o,i]=function(n,r){if("["!==n.value.raw)throw new $(r,n.value.loc.start,'Expected "[" for inline array');const o={type:e.InlineArray,loc:b(n.value.loc),items:[]},i=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=o.items[o.items.length-1];if(!e)throw new $(r,n.value.loc.start,'Found "," without previous value for inline array');if(e.comma)throw new $(r,n.value.loc.start,"Found consecutive commas in array (double comma is not allowed)");e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)i.push(pe(n));else{const t=o.items[o.items.length-1];if(t&&!t.comma)throw new $(r,n.value.loc.start,"Missing comma between array elements");const l=Te(n,r),a=l[0],s=l.slice(1);o.items.push({type:e.InlineItem,loc:b(a.loc),item:a,comma:!1}),Z(i,s)}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new $(r,n.done?o.loc.start:n.value.loc.start,'Expected "]"');return o.loc.end=n.value.loc.end,[o,i]}(n,r);return[o,...i]}throw n.value.type===t.Dot?new $(r,n.value.loc.start,"Invalid number: cannot start with a dot. Numbers must start with a digit"):new $(r,n.value.loc.start,"Unrecognized token type")}function Ie(t,n){var r;function o(e,t){for(const n of e)i(n,t)}function i(t,r){const l=n[t.type];switch(l&&"function"==typeof l&&l(t,r),l&&l.enter&&l.enter(t,r),t.type){case e.Document:o(t.items,t);break;case e.Table:i(t.key,t),o(t.items,t);break;case e.TableKey:i(t.item,t);break;case e.TableArray:i(t.key,t),o(t.items,t);break;case e.TableArrayKey:i(t.item,t);break;case e.KeyValue:i(t.key,t),i(t.value,t);break;case e.InlineArray:o(t.items,t);break;case e.InlineItem:i(t.item,t);break;case e.InlineTable:o(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}"`)}l&&l.exit&&l.exit(t,r)}null!=(r=t)&&"function"==typeof r[Symbol.iterator]?o(t,null):i(t,null)}const ke=new WeakMap,xe=e=>(ke.has(e)||ke.set(e,new WeakMap),ke.get(e)),Ee=new WeakMap,Ae=e=>(Ee.has(e)||Ee.set(e,new WeakMap),Ee.get(e));function Ce(e,t,n,r){if(d(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(i(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,r)}else if(m(t))t.item=r;else{if(!i(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}Me(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const o=w(n.loc),l=w(r.loc);Ke({lines:l.lines-o.lines,columns:l.columns-o.columns},Ae(e),r,n)}function _e(e,t,l,a,m){if(!d(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let h,p;a=null!=a&&"number"==typeof a?a:t.items.length,s(t)||u(t)?({shift:h,offset:p}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const r=null!=n?e.items[n-1]:U(e.items),o=null==n||n===e.items.length;e.items.splice(n,0,t);const i=!!r,l=!o;i&&(r.comma=!0);l&&(t.comma=!0);const a=s(e)&&function(e){if(!e.items.length)return!1;return w(e.loc).lines>e.items.length}(e),u=o&&!0===t.comma;return Oe(e,t,n,{useNewLine:a,hasCommaHandling:!0,isLastElement:o,hasSeparatingCommaBefore:i,hasSeparatingCommaAfter:l,hasTrailingComma:u})}(t,l,a)):m&&n(t)?({shift:h,offset:p}=function(e,t,n){const r=Oe(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,l,a)):({shift:h,offset:p}=function(e,t,l){if(a=t,!(i(a)||r(a)||o(a)||f(a)))throw new Error(`Incompatible child type "${t.type}"`);var a;const s=e.items[l-1],c=n(e)&&!e.items.length;e.items.splice(l,0,t);const u=s?{line:s.loc.end.line,column:f(s)?e.loc.start.column:s.loc.start.column}:v(e.loc.start),d=r(t)||o(t);let m=0;c||(m=d?2:1);u.line+=m;const h={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},p=w(t.loc),g={lines:p.lines+(m-1),columns:p.columns};return{shift:h,offset:g}}(t,l,a)),Me(l,h);const g=t.items[a-1],y=g&&Ae(e).get(g);y&&(p.lines+=y.lines,p.columns+=y.columns,Ae(e).delete(g));Ae(e).set(l,p)}function Oe(e,t,n,r={}){const{useNewLine:o=!1,skipCommaSpace:i=2,skipBracketSpace:l=1,hasCommaHandling:a=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:d=!1}=r,m=n>0?e.items[n-1]:void 0,h=m?{line:m.loc.end.line,column:o?f(m)?e.loc.start.column:m.loc.start.column:m.loc.end.column}:v(e.loc.start);let p=0;if(o)p=1;else{const e=c||!a&&!!m;e&&a?h.column+=i:(e||a&&!m)&&(h.column+=l)}h.line+=p;const g={lines:h.line-t.loc.start.line,columns:h.column-t.loc.start.column},y=w(t.loc);if(!a){return{shift:g,offset:{lines:y.lines+(p-1),columns:y.columns}}}let b=0;c&&d&&!u&&s&&(b=-1);return{shift:g,offset:{lines:y.lines+(p-1),columns:y.columns+(c||u?i:0)+(d?1+b:0)}}}function Ue(e,t,n){if(!d(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 o=t.items[r-1];let i=t.items[r+1];t.items.splice(r,1);let l=w(n.loc);i&&f(i)&&i.loc.start.line===n.loc.end.line&&(l=w({start:n.loc.start,end:i.loc.end}),i=t.items[r+1],t.items.splice(r,1));const a=o&&c(o)||i&&c(i),s=o&&o.loc.end.line===n.loc.start.line,u=i&&i.loc.start.line===n.loc.end.line,h=a&&(s||u),p={lines:-(l.lines-(h?1:0)),columns:-l.columns};if(void 0===o&&void 0===i&&(p.lines=0,p.columns=0),a&&s&&(p.columns-=2),a&&!o&&i&&(p.columns-=2),a&&o&&!i){const e=n.comma;o.comma=!!e}const g=o||t,y=o?Ae(e):xe(e),v=Ae(e),b=y.get(g);b&&(p.lines+=b.lines,p.columns+=b.columns);const $=v.get(n);$&&(p.lines+=$.lines,p.columns+=$.columns),y.set(g,p)}function De(e,t,n=!0){if(!n)return;if(!t.items.length)return;Ke({lines:0,columns:1},xe(e),t);const r=U(t.items);Ke({lines:0,columns:1},Ae(e),r)}function Fe(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=U(t.items);r.comma=!0,Ke({lines:0,columns:1},Ae(e),r)}function Le(t){const n=xe(t),r=Ae(t),o={lines:0,columns:{}};function i(e){const t=o.lines;e.loc.start.line+=t;const r=o.columns[e.loc.start.line]||0;e.loc.start.column+=r;const i=n.get(e);i&&(o.lines+=i.lines,o.columns[e.loc.start.line]=(o.columns[e.loc.start.line]||0)+i.columns)}function l(e){const t=o.lines;e.loc.end.line+=t;const n=o.columns[e.loc.end.line]||0;e.loc.end.column+=n;const i=r.get(e);i&&(o.lines+=i.lines,o.columns[e.loc.end.line]=(o.columns[e.loc.end.line]||0)+i.columns)}const a={enter:i,exit:l};Ie(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+o.lines,n=r.get(e.key);e.equals+=(o.columns[t]||0)+(n?n.columns:0),i(e)},exit:l},[e.Key]:a,[e.String]:a,[e.Integer]:a,[e.Float]:a,[e.Boolean]:a,[e.DateTime]:a,[e.Comment]:a}),ke.delete(t),Ee.delete(t)}function Me(t,n,r={}){const{first_line_only:o=!1}=r,i=t.loc.start.line,{lines:l,columns:a}=n,s=e=>{o&&e.loc.start.line!==i||(e.loc.start.column+=a,e.loc.end.column+=a),e.loc.start.line+=l,e.loc.end.line+=l};return Ie(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 Ke(e,t,n,r){const o=t.get(r||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function Ne(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function je(t){const n=function(t){const n=Be(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:b(n.loc),key:n,items:[]}}function Ze(t){const n=function(t){const n=Be(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:b(n.loc),key:n,items:[]}}function We(t,n){const r=function(t){const n=Be(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:o}=r.loc.end,i=o+1;return Me(n,{lines:0,columns:o+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:i,value:n}}const ze=/^[\w-]+$/;function Be(e){return e.map((e=>ze.test(e)?e:JSON.stringify(e))).join(".")}function qe(t,n){let r,o;if(n&&W(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const o=e?"'''":'"""',i=n.includes("\r\n")?"\r\n":"\n",l=n.startsWith(`${o}${i}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!e;let a;a=e?t:t.replace(/\\/g,"\\\\").replace(/\x08/g,"\\b").replace(/\f/g,"\\f").replace(/\t/g,"\\t").replace(/[\x00-\x07\x0B\x0E-\x1F\x7F]/g,(e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase())).replace(/"""/g,'""\\"'),r=l?`${o}${i}${a}${o}`:`${o}${a}${o}`}else r=JSON.stringify(t);if(r.includes("\r\n")||r.includes("\n")&&!r.includes("\r\n")){const e=r.includes("\r\n")?"\r\n":"\n",t=(r.match(new RegExp("\r\n"===e?"\\r\\n":"\\n","g"))||[]).length;o=t>0?{line:1+t,column:3}:{line:1,column:r.length}}else o={line:1,column:r.length};return{type:e.String,loc:{start:{line:1,column:0},end:o},raw:r,value:t}}function Ve(t){return{type:e.InlineItem,loc:b(t.loc),item:t,comma:!1}}const Pe=!1,Re=!0,He=!1,Je=!1;function Ye(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/),o=e.start.line-1,i=e.end.line-1,l=e.start.column,a=e.end.column;let s="";if(o===i)s=(null===(n=r[o])||void 0===n?void 0:n.substring(l,a+1))||"";else{r[o]&&(s+=r[o].substring(l));for(let e=o+1;e<i;e++)s+="\n"+(r[e]||"");r[i]&&(s+="\n"+r[i].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=Ye(n,t);if(null!==e)return e;if(n.item){const e=Ye(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=Ye(e[n],t);if(null!==r)return r}return null}function Xe(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return Ge(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return Ge(e.items);if("KeyValue"===e.type&&e.value)return Xe(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=Xe(t);if(null!==e)return e}return null}function Ge(e){if(0===e.length)return null;const t=e[e.length-1];return!(!t||"object"!=typeof t||!("comma"in t))&&!0===t.comma}function Qe(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function et(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function tt(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function nt(e,t){var n,r,o,i,l,a;if(e){if(e instanceof rt)return e;{const s=function(e){if(!e||"object"!=typeof e)return{};const t=new Set(["newLine","trailingNewline","trailingComma","bracketSpacing","inlineTableStart","truncateZeroTimeInDates","useTabsForIndentation"]),n={},r=[],o=[];for(const i in e){const l=Object.prototype.hasOwnProperty.call(e,i);if(t.has(i)){const t=e[i];switch(i){case"newLine":"string"==typeof t?n.newLine=t:o.push(`${i} (expected string, got ${typeof t})`);break;case"trailingNewline":"boolean"==typeof t||"number"==typeof t?n.trailingNewline=t:o.push(`${i} (expected boolean or number, got ${typeof t})`);break;case"trailingComma":case"bracketSpacing":case"truncateZeroTimeInDates":case"useTabsForIndentation":"boolean"==typeof t?n[i]=t:o.push(`${i} (expected boolean, got ${typeof t})`);break;case"inlineTableStart":"number"==typeof t&&Number.isInteger(t)&&t>=0||null==t?n.inlineTableStart=t:o.push(`${i} (expected non-negative integer or undefined, got ${typeof t})`)}}else l&&r.push(i)}if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Array.from(t).join(", ")}`),o.length>0)throw new TypeError(`Invalid types for format properties: ${o.join(", ")}`);return n}(e);return new rt(null!==(n=s.newLine)&&void 0!==n?n:t.newLine,null!==(r=s.trailingNewline)&&void 0!==r?r:t.trailingNewline,null!==(o=s.trailingComma)&&void 0!==o?o:t.trailingComma,null!==(i=s.bracketSpacing)&&void 0!==i?i:t.bracketSpacing,void 0!==s.inlineTableStart?s.inlineTableStart:t.inlineTableStart,null!==(l=s.truncateZeroTimeInDates)&&void 0!==l?l:t.truncateZeroTimeInDates,null!==(a=s.useTabsForIndentation)&&void 0!==a?a:t.useTabsForIndentation)}}return t}class rt{constructor(e,t,n,r,o,i,l){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:Pe,this.bracketSpacing=null!=r?r:Re,this.inlineTableStart=null!=o?o:1,this.truncateZeroTimeInDates=null!=i?i:He,this.useTabsForIndentation=null!=l?l:Je}static default(){return new rt("\n",1,Pe,Re,1,He,Je)}static autoDetectFormat(e){const t=rt.default();t.newLine=tt(e),t.trailingNewline=function(e,t){let n=0,r=e.length;for(;r>=t.length&&e.substring(r-t.length,r)===t;)n++,r-=t.length;return n}(e,t.newLine);try{const n=he(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=Xe(e);if(null!==t)return t}return Pe}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=Ye(t,e);if(null!==n)return n}return Re}(e,r)}catch(e){t.trailingComma=Pe,t.bracketSpacing=Re}return t.useTabsForIndentation=function(e){const t=e.split(/\r?\n/);let n=0,r=0;for(const e of t)if(0!==e.length&&("\t"===e[0]?n++:" "===e[0]&&r++,n+r>=5))break;return n>r}(e),t.inlineTableStart=1,t.truncateZeroTimeInDates=He,t}}function ot(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!i(e))return!1;const n=u(e.value),r=s(e.value)&&e.value.items.length&&u(e.value.items[0].item);if(n||r){const n=at(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{Ue(e,e,t),u(t.value)?_e(e,e,it(t)):function(e){const t=Ne();for(const n of e.value.items){const r=Ze(e.key.value);_e(t,t,r);for(const e of n.item.items)_e(t,r,e.item)}return Le(t),t.items}(t).forEach((t=>{_e(e,e,t)}))})),Le(e),e}function it(e){const t=je(e.key.value);for(const n of e.value.items)_e(t,t,n.item);return Le(t),t}function lt(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 at(e){return Math.max(0,e.length-1)}function st(e,t,n){var r;for(let o=e.items.length-1;o>=0;o--){const l=e.items[o];if(i(l)&&u(l.value)){const o=[...e.key.item.value,...l.key.value];if(at(o)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=je(o);for(const e of l.value.items)_e(r,r,e.item);Ue(e,e,l),lt(e),t.push(r),st(r,t,n)}}}}function ct(e,t=rt.default()){e=function(e){const t=[],n=[];for(const r in e)M(e[r])||Array.isArray(e[r])?n.push(r):t.push(r);const r={};for(let n=0;n<t.length;n++){const o=t[n];r[o]=e[o]}for(let t=0;t<n.length;t++){const o=n[t];r[o]=e[o]}return r}(e=dt(e));const n=Ne();for(const r of ut(e,t))_e(n,n,r);Le(n);const r=N(n,(e=>ot(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(i(r)&&u(r.value)){if(at(r.key.value)<t.inlineTableStart){const o=it(r);Ue(e,e,r),_e(e,e,o),st(o,n,t)}}else"Table"===r.type&&st(r,n,t);for(const t of n)_e(e,e,t);return Le(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)),Me(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(r)}function*ut(e,t){for(const n of Object.keys(e))yield We([n],ft(e[n],t))}function ft(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?qe(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):L(t)?function(t,n){n.truncateZeroTimeInDates&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new te(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){_e(r,r,Ve(ft(e,n)))}return De(r,r,n.bracketSpacing),Fe(r,r,n.trailingComma),Le(r),r}(t,n):function(t,n){if(t=dt(t),!M(t))return ft(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},o=[...ut(t,n)];for(const e of o){_e(r,r,Ve(e))}return De(r,r,n.bracketSpacing),Fe(r,r,n.trailingComma),Le(r),r}(t,n)}function dt(e){return e?L(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const mt=/(\r\n|\n)/g;function ht(t,n){const r=[],o=n.useTabsForIndentation?"\t":" ";if(Ie(t,{[e.TableKey](e){const{start:t,end:n}=e.loc;pt(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),pt(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[e.TableArrayKey](e){const{start:t,end:n}=e.loc;pt(r,{start:t,end:{line:t.line,column:t.column+2}},"[[",o),pt(r,{start:{line:n.line,column:n.column-2},end:n},"]]",o)},[e.KeyValue](e){const{start:{line:t}}=e.loc;pt(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=",o)},[e.Key](e){pt(r,e.loc,e.raw,o)},[e.String](e){pt(r,e.loc,e.raw,o)},[e.Integer](e){pt(r,e.loc,e.raw,o)},[e.Float](e){pt(r,e.loc,e.raw,o)},[e.Boolean](e){pt(r,e.loc,e.value.toString(),o)},[e.DateTime](e){pt(r,e.loc,e.raw,o)},[e.InlineArray](e){const{start:t,end:n}=e.loc;pt(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),pt(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[e.InlineTable](e){const{start:t,end:n}=e.loc;pt(r,{start:t,end:{line:t.line,column:t.column+1}},"{",o),pt(r,{start:{line:n.line,column:n.column-1},end:n},"}",o)},[e.InlineItem](e){if(!e.comma)return;const t=e.loc.end;pt(r,{start:t,end:{line:t.line,column:t.column+1}},",",o)},[e.Comment](e){pt(r,e.loc,e.raw,o)}}),n.useTabsForIndentation)for(let e=0;e<r.length;e++){const t=r[e],n=t.match(/^( +)/);if(n){const o=n[1],i="\t".repeat(o.length);r[e]=i+t.substring(o.length)}}return r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function pt(e,t,n,r=" "){const o=n.split(mt).filter((e=>"\n"!==e&&"\r\n"!==e)),i=t.end.line-t.start.line+1;if(o.length!==i)throw new Error(`Mismatch between location and raw string, expected ${i} lines for "${n}"`);for(let r=t.start.line;r<=t.end.line;r++){const i=wt(e,r);if(void 0===i)throw new Error(`Line ${r} is uninitialized when writing "${n}" at ${t.start.line}:${t.start.column} to ${t.end.line}:${t.end.column}`);const l=r===t.start.line,a=r===t.end.line;let s="";if(l){const e=i.substring(0,t.start.column);s=e.length<t.start.column?e.padEnd(t.start.column," "):e}const c=a?i.substring(t.end.column):"";e[r-1]=s+o[r-t.start.line]+c}}function wt(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function gt(t,n,r){for(const o of t.items){const t=o.item,i=n.concat(t.key.value);t.value.type===e.InlineTable&&(r.add(It(i)),gt(t.value,i,r))}}function yt(t,n=""){const r=D(),o=new Set,i=new Set,l=new Set,a=new Set,s=new Set;let c=r,u=0,f=[];return Ie(t,{[e.Table](e){const t=e.key.item.value;try{bt(r,[],t,e.type,{tables:o,table_arrays:i,defined:l,implicit_tables:a,inline_tables:s})}catch(t){const r=t;throw new $(n,e.key.loc.start,r.message)}const u=It(t);o.add(u),l.add(u),c=$t(r,t),f=t},[e.TableArray](e){const t=e.key.item.value;try{bt(r,[],t,e.type,{tables:o,table_arrays:i,defined:l,implicit_tables:a,inline_tables:s})}catch(t){const r=t;throw new $(n,e.key.loc.start,r.message)}const u=It(t);i.add(u),l.add(u),c=function(e,t){const n=St(e,t.slice(0,-1)),r=U(t);n[r]||(n[r]=[]);const o=D();return n[U(t)].push(o),o}(r,t),f=t},[e.KeyValue]:{enter(t){if(u>0)return;const r=t.key.value;try{bt(c,f,r,t.type,{tables:o,table_arrays:i,defined:l,implicit_tables:a,inline_tables:s})}catch(e){const r=e;throw new $(n,t.key.loc.start,r.message)}if(r.length>1)for(let e=1;e<r.length;e++){const t=It(f.concat(r.slice(0,e)));a.add(t),l.add(t)}let d;try{d=vt(t.value)}catch(e){const r=e;throw new $(n,t.value.loc.start,r.message)}if(t.value.type===e.InlineTable){const e=f.concat(r);s.add(It(e)),gt(t.value,e,s)}(r.length>1?$t(c,r.slice(0,-1)):c)[U(r)]=d,l.add(It(f.concat(r)))}},[e.InlineTable]:{enter(){u++},exit(){u--}}}),r}function vt(t){switch(t.type){case e.InlineTable:const n=D(),r=new Set,o=new Map;return t.items.forEach((({item:e})=>{const t=e.key.value,i=vt(e.value),l=It(t);if(r.has(l))throw new Error(`Duplicate key "${l}" in inline table`);for(let e=1;e<t.length;e++){const n=It(t.slice(0,e));if(r.has(n))throw new Error(`Key "${l}" conflicts with already defined key "${n}" in inline table`)}if(o.has(l)){const e=o.get(l);throw new Error(`Key "${l}" conflicts with already defined key "${e}" in inline table`)}r.add(l);for(let e=1;e<t.length;e++){const n=It(t.slice(0,e));o.has(n)||o.set(n,l)}(t.length>1?$t(n,t.slice(0,-1)):n)[U(t)]=i})),n;case e.InlineArray:return t.items.map((e=>vt(e.item)));case e.DateTime:case e.String:case e.Integer:case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function bt(t,n,r,o,i){const l=It(n.concat(r));if(o===e.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=It(n.concat(r.slice(0,e)));if(i.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if((o===e.Table||o===e.TableArray)&&i.inline_tables.has(l))throw new Error(`Invalid key, cannot extend an inline table at ${l}`);if(o===e.Table||o===e.TableArray)for(let e=1;e<r.length;e++){const t=It(n.concat(r.slice(0,e)));if(i.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if(o===e.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=It(n.concat(r.slice(0,e)));if(i.table_arrays.has(t))throw new Error(`Invalid key, cannot traverse into an array of tables at ${t}`)}if((o===e.Table||o===e.TableArray)&&i.implicit_tables.has(l))throw new Error(`Invalid key, a table has already been defined implicitly named ${l}`);if(o===e.KeyValue&&i.implicit_tables.has(l))throw new Error(`Invalid key, a table has already been defined named ${l}`);if(o===e.KeyValue&&r.length>1)for(let e=1;e<=r.length;e++){const t=It(n.concat(r.slice(0,e)));if(i.tables.has(t))throw new Error(`Invalid key, cannot add to an explicitly defined table ${t} using dotted keys`)}let a=[],s=0;for(const e of r){if(a.push(e),!K(t,e))return;if(Tt(t[e])){const e=It(n.concat(a));throw new Error(`Invalid key, a value has already been defined for ${e}`)}const o=It(n.concat(a));if(Array.isArray(t[e])&&!i.table_arrays.has(o))throw new Error(`Invalid key, cannot add to a static array at ${o}`);const l=s++<r.length-1;t=Array.isArray(t[e])&&l?U(t[e]):t[e]}const c=l;if(t&&o===e.Table&&i.defined.has(c))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(t&&o===e.KeyValue&&1===r.length&&i.defined.has(c)&&!Tt(t))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(t&&o===e.TableArray&&!i.table_arrays.has(c))throw new Error(`Invalid key, cannot add an array of tables to a table at ${c}`)}function $t(e,t){const n=St(e,t.slice(0,-1)),r=U(t);return n[r]||(n[r]=D()),n[r]}function St(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=D()),Array.isArray(e[t])?U(e[t]):e[t])),e)}function Tt(e){return"object"!=typeof e&&!L(e)}function It(e){return e.join(".")}var kt,xt,Et,At;function Ct(e){return e.type===kt.Remove}function _t(e,t,n=[]){return e===t||(o=t,L(r=e)&&L(o)&&r.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const o=e.map(j),i=t.map(j);i.forEach(((l,a)=>{const s=a>=o.length;if(!s&&o[a]===l)return;const c=o.indexOf(l,a+1);if(!s&&c>-1){r.push({type:kt.Move,path:n,from:c,to:a});const e=o.splice(c,1);return void o.splice(a,0,...e)}const u=!i.includes(o[a]);if(!s&&u)return Z(r,_t(e[a],t[a],n.concat(a))),void(o[a]=l);r.push({type:kt.Add,path:n.concat(a)}),o.splice(a,0,l)}));for(let e=i.length;e<o.length;e++)r.push({type:kt.Remove,path:n.concat(e)});return r}(e,t,n):M(e)&&M(t)?function(e,t,n=[]){let r=[];const o=Object.keys(e),i=o.map((t=>j(e[t]))),l=Object.keys(t),a=l.map((e=>j(t[e]))),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=o[i.indexOf(e)];return!l.includes(n)};return o.forEach(((o,c)=>{const u=n.concat(o);if(l.includes(o))Z(r,_t(e[o],t[o],u));else if(s(i[c],a)){const e=l[a.indexOf(i[c])];r.push({type:kt.Rename,path:n,from:o,to:e})}else r.push({type:kt.Remove,path:u})})),l.forEach(((e,t)=>{o.includes(e)||s(a[t],i)||r.push({type:kt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:kt.Edit,path:n}];var r,o}function Ot(e,t){if(!t.length)return c(e)&&i(e.item)?e.item:e;if(i(e))return Ot(e.value,t);const n={};let l;if(d(e)&&e.items.some(((e,a)=>{try{let s=[];if(i(e))s=e.key.value;else if(r(e))s=e.key.item.value;else if(o(e)){s=e.key.item.value;const t=j(s);n[t]||(n[t]=0);const r=n[t]++;s=s.concat(r)}else c(e)&&i(e.item)?s=e.item.key.value:c(e)&&(s=[a]);return!(!s.length||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(s,t.slice(0,s.length)))&&(l=c(e)&&i(e.item)?t.length===s.length?e:Ot(e.item.value,t.slice(s.length)):Ot(e,t.slice(s.length)),!0)}catch(e){return!1}})),!l)throw new Error(`Could not find node at path ${t.join(".")}`);return l}function Ut(e,t){try{return Ot(e,t)}catch(e){}}function Dt(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=Ut(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function Ft(e,t,n){return Lt(he(e),t,nt(n,rt.autoDetectFormat(e))).tomlString}function Lt(t,l,a){const f=[...t],d=yt(f),h={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},p=ct(l,nt(Object.assign(Object.assign({},a),{inlineTableStart:void 0}),a)),w=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Ct(n)){let r=t+1;for(;r<e.length;){const o=e[r];if(Ct(o)&&o.path[0]===n.path[0]&&o.path[1]>n.path[1]){e.splice(r,1),e.splice(t,0,o),t=0;break}r++}}}return e}(_t(d,l));if(0===w.length)return{tomlString:ht(f,a),document:h};const g=function(e,t,l,a){return l.forEach((l=>{if(function(e){return e.type===kt.Add}(l)){const f=Ot(t,l.path),d=l.path.slice(0,-1);let m,h=U(l.path),p=o(f);if(F(h)&&!d.some(F)){const t=Ut(e,d.concat(0));t&&o(t)&&(p=!0)}if(r(f))m=e;else if(p){m=e;const t=e,n=Ut(t,d.concat(h-1)),r=Ut(t,d.concat(h));h=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else m=Dt(e,l.path),i(m)&&(m=m.value);if(o(m)||s(m)||n(m)){if(s(m)){const e=Qe(m);c(f)&&(f.comma=e)}if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&n(m)&&r(f)){const t=Kt(f,e,a);_e(e,m,f,h);for(const n of t)_e(e,e,n,void 0)}else _e(e,m,f,h)}else if(u(m)){const t=et(m);if(i(f)){const n=Ve(f);n.comma=t,_e(e,m,n)}else _e(e,m,f)}else if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&i(f)&&u(f.value)&&r(m)){at([...m.key.item.value,...f.key.value])<a.inlineTableStart?function(e,t,n,r){const o=t.key.item.value,l=[...o,...e.key.value],a=je(l);if(u(e.value))for(const t of e.value.items)c(t)&&i(t.item)&&_e(n,a,t.item,void 0);_e(n,n,a,void 0),lt(t);const s=Kt(a,n,r);for(const e of s)_e(n,n,e,void 0)}(f,m,e,a):_e(e,m,f)}else if(0===a.inlineTableStart&&i(f)&&u(f.value)&&n(m))_e(e,m,f,void 0,!0);else{let t=f;c(f)&&(r(m)||n(m))&&(t=f.item),_e(e,m,t)}}else if(function(e){return e.type===kt.Edit}(l)){let n,r=Ot(e,l.path),o=Ot(t,l.path);if(i(r)&&i(o))Mt(r.value,o.value),n=r,r=r.value,o=o.value;else if(i(r)&&c(o)&&i(o.item))n=r,r=r.value,o=o.item.value;else if(c(r)&&i(o))n=r,r=r.item;else if(c(r)&&c(o)&&i(r.item)&&i(o.item))Mt(r.item.value,o.item.value),n=r.item,r=r.item.value,o=o.item.value;else if(n=Dt(e,l.path),i(n)){const t=l.path.slice(0,-1),r=Ot(e,t);i(r)&&s(r.value)&&(n=r.value)}Ce(e,n,r,o)}else if(Ct(l)){let t=Dt(e,l.path);i(t)&&(t=t.value);const n=Ot(e,l.path);Ue(e,t,n)}else if(function(e){return e.type===kt.Move}(l)){let t=Ot(e,l.path);m(t)&&(t=t.item),i(t)&&(t=t.value);const n=t.items[l.from];Ue(e,t,n),_e(e,t,n,l.to)}else if(function(e){return e.type===kt.Rename}(l)){let n=Ot(e,l.path.concat(l.from)),r=Ot(t,l.path.concat(l.to));m(n)&&(n=n.item),m(r)&&(r=r.item),Ce(e,n,n.key,r.key)}})),Le(e),e}(h,p,w,a);return{tomlString:ht(g.items,a),document:g}}function Mt(e,t){if(l(e)&&l(t)&&W(e.raw)){const n=qe(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(a(e)&&a(t)){const n=e.raw,r=t.value,o=ee.createDateWithOriginalFormat(r,n);t.value=o,t.raw=o.toISOString();0!==t.raw.length-n.length&&(t.loc.end.column=t.loc.start.column+t.raw.length)}if(s(e)&&s(t)){const n=Qe(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=et(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function Kt(e,t,n){const r=[],o=(e,r)=>{var l;for(let a=e.items.length-1;a>=0;a--){const s=e.items[a];if(i(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(at(u)<(null!==(l=n.inlineTableStart)&&void 0!==l?l:1)&&0!==n.inlineTableStart){const n=je(u);for(const e of s.value.items)c(e)&&i(e.item)&&_e(t,n,e.item,void 0);e.items.splice(a,1),lt(e),r.push(n),o(n,r)}}}};return o(e,r),r}function Nt(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 jt(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function Zt(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"}(kt||(kt={})),"function"==typeof SuppressedError&&SuppressedError;class Wt{constructor(e){xt.set(this,void 0),Et.set(this,void 0),At.set(this,void 0),jt(this,Et,e,"f"),jt(this,xt,Array.from(he(e)),"f"),jt(this,At,rt.autoDetectFormat(e),"f")}get toTomlString(){return Nt(this,Et,"f")}get toJsObject(){return zt(yt(Nt(this,xt,"f")))}get ast(){return Nt(this,xt,"f")}patch(e,t){const n=nt(t,Nt(this,At,"f")),{tomlString:r,document:o}=Lt(Nt(this,xt,"f"),e,n);jt(this,xt,o.items,"f"),jt(this,Et,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Nt(this,At,"f").newLine),n=tt(e),r=e.split(n);let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];)o++;let i=0;if(o<t.length&&o<r.length){const e=t[o],n=r[o];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){i=t;break}}let l=o+1;const{truncatedAst:a,lastEndPosition:s}=function(e,t,n){const r={line:t,column:n},o=[];let i=null;for(const t of e){const e=Zt(t.loc.end,r)<0,n=Zt(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}o.push(t),i=t.loc.end}return{truncatedAst:o,lastEndPosition:i}}(Nt(this,xt,"f"),l,i),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 d=f.join(Nt(this,At,"f").newLine);jt(this,xt,Array.from(function*(e,t){for(const t of e)yield t;const n=new h(x(t));for(;!n.next().done;){const e=Se(n,t);for(const t of e)yield t}}(a,d)),"f"),jt(this,Et,e,"f"),jt(this,At,rt.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(jt(this,xt,Array.from(he(e)),"f"),jt(this,Et,e,"f"),jt(this,At,rt.autoDetectFormat(e),"f"))}}function zt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(zt);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=zt(r);return t}return e}function Bt(e){return yt(he(e),e)}function qt(e,t){const n=nt(t,rt.default());return ht(ct(e,n).items,n)}xt=new WeakMap,Et=new WeakMap,At=new WeakMap;export{Wt as TomlDocument,rt as TomlFormat,Bt as parse,Ft as patch,qt as stringify};
|
|
1
|
+
//! @decimalturn/toml-patch v1.0.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
+
var e,t;function n(t){return t.type===e.Document}function r(t){return t.type===e.Table}function o(t){return t.type===e.TableArray}function i(t){return t.type===e.KeyValue}function a(t){return t.type===e.String}function l(t){return t.type===e.DateTime}function s(t){return t.type===e.InlineArray}function c(t){return t.type===e.InlineItem}function u(t){return t.type===e.InlineTable}function f(t){return t.type===e.Comment}function d(e){return n(e)||r(e)||o(e)||u(e)||s(e)}function m(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}function h(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function p(e,t){const n=Array.isArray(e)?e:w(e);if(0===n.length)return{line:1,column:t};let r=0,o=n.length-1;for(;r<o;){const e=r+o>>>1;n[e]<t?r=e+1:o=e}n[r]<t&&r++;const i=r+1;return{line:i,column:t-(n[i-2]+1||0)}}function w(e){const t=[];for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);10===r?t.push(n):13===r&&(10===e.charCodeAt(n+1)?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function g(e){return{line:e.line,column:e.column}}function y(e){return{start:g(e.start),end:g(e.end)}}!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 v 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=w(e),r=void 0!==n[t.line-2]?n[t.line-2]+1:0,o=n[t.line-1]||e.length;return e.substring(r,o)}(e,t),o=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(r+=`${n}\n${o}\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 b='"',$="'",S=/[\w,\d,\",\',\+,\-,\_]/,T=10,I=13,k=127;function*C(e){const n=e.length;let r=0;const o=[],i=(e,t)=>({start:p(o,e),end:p(o,t)});for(;r<n;){const c=e.charCodeAt(r);if((c<=31||c===k)&&9!==c&&c!==I&&c!==T)throw new v(e,p(o,r),`Control character 0x${c.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);if(c===I&&(r+1>=n||e.charCodeAt(r+1)!==T))throw new v(e,p(o,r),"Invalid standalone CR (\\r); CR must be part of a CRLF sequence");if(32===c||9===c||c===I);else if(c===T)o.push(r);else if(91===c||93===c)yield{type:t.Bracket,raw:e[r],loc:i(r,r+1)};else if(123===c||125===c)yield{type:t.Curly,raw:e[r],loc:i(r,r+1)};else if(61===c)yield{type:t.Equal,raw:"=",loc:i(r,r+1)};else if(44===c)yield{type:t.Comma,raw:",",loc:i(r,r+1)};else if(46===c)yield{type:t.Dot,raw:".",loc:i(r,r+1)};else if(35===c)yield a();else{const t=E(e,r,$)||E(e,r,b);t?yield l(t):yield s()}r++}function a(){const a=r;for(;r+1<n;){const t=e.charCodeAt(r+1);if(t===T||t===I)break;r++;const n=e.charCodeAt(r);if((n<=31||n===k)&&9!==n)throw new v(e,p(o,r),`Control character 0x${n.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`)}return{type:t.Comment,raw:e.slice(a,r+1),loc:i(a,r+1)}}function l(a){const l=r,s=a+a+a;for(r+=3;r<n;){if(E(e,r,a)){let t=3;for(;e[r+t]===a;)t++;if(t>=6)throw new v(e,p(o,r),`Invalid multiline string: ${t} consecutive ${a} characters`);if(3===t){r+=2;break}r+=t-3,r+=2;break}const t=e.charCodeAt(r);if(t===I&&(r+1>=n||e.charCodeAt(r+1)!==T))throw new v(e,p(o,r),"Invalid standalone CR (\\r) in multiline string (must be part of CRLF sequence)");if((t<=31||t===k)&&9!==t&&t!==T&&t!==I){const n=a===b?"multiline basic strings":"multiline literal strings",i=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let l="";0===t?l="Null":t===k&&(l="DEL");const s=l?`${l} (control character ${i}) is not allowed in ${n}`:`Control character ${i} is not allowed in ${n}`;throw new v(e,p(o,r),s)}t===T&&o.push(r),r++}if(r>=n){if(a===b){let t=0,i=n-1;for(;i>=0&&"\\"===e[i];)t++,i--;if(t>0&&t%2!=0)throw new v(e,p(o,r),`Expected close of multiline string with ${s}, reached end of file. Check for escape sequences (\\) that may be preventing proper string closure`)}throw new v(e,p(o,r),`Expected close of multiline string with ${s}, reached end of file`)}return{type:t.Literal,raw:e.slice(l,r+1),loc:i(l,r+1)}}function s(){const a=e[r];if(!S.test(a))throw new v(e,p(o,r),`Unsupported character "${a}". Expected ALPHANUMERIC, ", ', +, -, or _`);const l=r;let s=a===b,c=a===$;for(;r<n&&!(r+1>=n);){const t=e.charCodeAt(r+1);if(!(s||c||32!==t&&9!==t&&t!==T&&t!==I&&44!==t&&46!==t&&93!==t&&125!==t&&61!==t&&35!==t))break;if(r++,s||c){const t=e.charCodeAt(r);if((t<=31||t===k)&&9!==t){const n=s?"basic strings":"literal strings",i=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let a="";t===T?a="Newline":t===I?a="Carriage return":0===t?a="Null":t===k&&(a="DEL");const l=a?`${a} (control character ${i}) is not allowed in ${n}`:`Control character ${i} is not allowed in ${n}`;throw new v(e,p(o,r),l)}}const i=e[r];if(i===b&&(s=!s),i!==$||s||(c=!c),r+1>=n)break;if(s&&"\\"===i){const t=e[r+1];t!==b&&"\\"!==t||r++}}if(s||c)throw new v(e,p(o,l),`Expected close of string with ${s?b:$}`);return{type:t.Literal,raw:e.slice(l,r+1),loc:i(l,r+1)}}}function E(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===$)return n;let r=0,o=t-1;for(;o>=0&&"\\"===e[o];)r++,o--;if(0===r)return n;return!(r%2!=0)&&n}const A=new Int8Array(128);A.fill(-1);for(let e=0;e<10;e++)A[48+e]=e;for(let e=0;e<6;e++)A[65+e]=10+e,A[97+e]=10+e;function x(e){const t=e.charCodeAt(0);return t<128&&-1!==A[t]}function _(e,t){return A[e.charCodeAt(t)]<<12|A[e.charCodeAt(t+1)]<<8|A[e.charCodeAt(t+2)]<<4|A[e.charCodeAt(t+3)]}function U(e){return e.startsWith("'''")?D(e.slice(3,e.length-3)):e.startsWith($)?e.slice(1,e.length-1):e.startsWith('"""')?O(D(e.slice(3,e.length-3)),!0):e.startsWith(b)?O(e.slice(1,e.length-1),!1):e}function O(e,t){const n=e.length;if(!t&&-1===e.indexOf("\\"))return e;const r=[];let o=0;for(let i=0;i<n;i++){if("\\"!==e[i])continue;if(i>o&&r.push(e.slice(o,i)),i++,i>=n)throw new Error("Invalid escape sequence: trailing backslash");const a=e[i];switch(a){case"b":r.push("\b");break;case"t":r.push("\t");break;case"n":r.push("\n");break;case"f":r.push("\f");break;case"r":r.push("\r");break;case'"':r.push('"');break;case"\\":r.push("\\");break;case"e":r.push("");break;case"u":{if(i+4>n||!x(e[i+1])||!x(e[i+2])||!x(e[i+3])||!x(e[i+4]))throw new Error(`Invalid Unicode escape: \\u${e.slice(i+1,i+5)}`);const t=_(e,i+1);if(t>=55296&&t<=57343)throw new Error(`Invalid Unicode escape: \\u${e.slice(i+1,i+5)} (surrogate codepoints are not allowed)`);r.push(String.fromCharCode(t)),i+=4;break}case"U":{if(i+8>n)throw new Error(`Invalid Unicode escape: \\U${e.slice(i+1,i+9)}`);for(let t=1;t<=8;t++)if(!x(e[i+t]))throw new Error(`Invalid Unicode escape: \\U${e.slice(i+1,i+9)}`);const t=parseInt(e.slice(i+1,i+9),16);r.push(String.fromCodePoint(t)),i+=8;break}case"x":{if(i+2>n||!x(e[i+1])||!x(e[i+2]))throw new Error(`Invalid hex escape: \\x${e.slice(i+1,i+3)}`);const t=A[e.charCodeAt(i+1)]<<4|A[e.charCodeAt(i+2)];r.push(String.fromCharCode(t)),i+=2;break}default:if(t&&("\n"===a||"\r"===a||" "===a||"\t"===a)){let t="\n"===a||"\r"===a,r=i;for(;r<n&&(" "===e[r]||"\t"===e[r]||"\n"===e[r]||"\r"===e[r]);)"\n"!==e[r]&&"\r"!==e[r]||(t=!0),r++;if(!t)throw new Error(`Invalid escape sequence: \\${a}`);i=r-1;break}throw new Error(`Invalid escape sequence: \\${a}`)}o=i+1}return 0===o?e:(o<n&&r.push(e.slice(o)),r.join(""))}function D(e){return 10===e.charCodeAt(0)?e.slice(1):13===e.charCodeAt(0)&&10===e.charCodeAt(1)?e.slice(2):e}class F{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 M();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?M():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}const L=Object.freeze({value:void 0,done:!0});function M(){return L}class K{static createDateWithOriginalFormat(e,t){if(K.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof Z)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new W(t,!1)}const t=e.toISOString().split("T")[0];return new N(t)}if(K.IS_TIME_ONLY.test(t)){if(e instanceof j)return e;{const n=t.match(/\.(\d+)\s*$/),r=e.toISOString();if(r&&r.includes("T")){let o=r.split("T")[1].split("Z")[0];if(n){const t=n[1].length,[r,i,a]=o.split(":"),[l]=a.split(".");o=`${r}:${i}:${l}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new j(o,t)}{const r=String(e.getUTCHours()).padStart(2,"0"),o=String(e.getUTCMinutes()).padStart(2,"0"),i=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds();let l;if(n){const e=n[1].length;l=`${r}:${o}:${i}.${String(a).padStart(3,"0").slice(0,e)}`}else if(a>0){l=`${r}:${o}:${i}.${String(a).padStart(3,"0").replace(/0+$/,"")}`}else l=`${r}:${o}:${i}`;return new j(l,t)}}}if(K.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,[o,i]=r.split("T"),[a,l,s]=i.split(":"),[c]=s.split(".");r=`${o}T${a}:${l}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new W(r,!1,t)}if(K.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,[o,i]=r.split(" "),[a,l,s]=i.split(":"),[c]=s.split(".");r=`${o} ${a}:${l}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new W(r,!0,t)}if(K.IS_OFFSET_DATETIME_T.test(t)||K.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),r=n?"z"===n[1]?"Z":n[1]:"Z",o=K.IS_OFFSET_DATETIME_SPACE.test(t),i=t.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),a=e.getTime();let l=0;if("Z"!==r){const e="+"===r[0]?1:-1,[t,n]=r.slice(1).split(":");l=e*(60*parseInt(t)+parseInt(n))}const s=new Date(a+6e4*l),c=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=String(s.getUTCHours()).padStart(2,"0"),m=String(s.getUTCMinutes()).padStart(2,"0"),h=String(s.getUTCSeconds()).padStart(2,"0"),p=s.getUTCMilliseconds(),w=o?" ":"T";let g=`${d}:${m}:${h}`;if(i){const e=i[1].length;g+=`.${String(p).padStart(3,"0").slice(0,e)}`}else if(p>0){g+=`.${String(p).padStart(3,"0").replace(/0+$/,"")}`}return new Z(`${c}-${u}-${f}${w}${g}${r}`,o)}return e}}K.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,K.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,K.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,K.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,K.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,K.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,K.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,K.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class N extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class j extends Date{constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+":00"),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){const e=String(this.getUTCHours()).padStart(2,"0"),t=String(this.getUTCMinutes()).padStart(2,"0"),n=String(this.getUTCSeconds()).padStart(2,"0"),r=this.getUTCMilliseconds();if(this.originalFormat&&this.originalFormat.includes(".")){const o=this.originalFormat.match(/\.(\d+)\s*$/),i=o?o[1].length:3;return`${e}:${t}:${n}.${String(r).padStart(3,"0").slice(0,i)}`}if(r>0){return`${e}:${t}:${n}.${String(r).padStart(3,"0").replace(/0+$/,"")}`}return`${e}:${t}:${n}`}}class W extends Date{constructor(e,t=!1,n){let r=e;/\d{2}:\d{2}:\d{2}/.test(e)||(r=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(r.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"),o=String(this.getUTCMinutes()).padStart(2,"0"),i=String(this.getUTCSeconds()).padStart(2,"0"),a=this.getUTCMilliseconds(),l=`${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`${l}${s}${r}:${o}:${i}.${String(a).padStart(3,"0").slice(0,t)}`}if(a>0){return`${l}${s}${r}:${o}:${i}.${String(a).padStart(3,"0").replace(/0+$/,"")}`}return`${l}${s}${r}:${o}:${i}`}}class Z extends Date{constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(n.replace(" ","T")),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=e;const r=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);r&&(this.originalOffset="z"===r[1]?"Z":r[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(),o=String(n.getUTCMonth()+1).padStart(2,"0"),i=String(n.getUTCDate()).padStart(2,"0"),a=String(n.getUTCHours()).padStart(2,"0"),l=String(n.getUTCMinutes()).padStart(2,"0"),s=String(n.getUTCSeconds()).padStart(2,"0"),c=n.getUTCMilliseconds(),u=`${r}-${o}-${i}`,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}${a}:${l}:${s}.${String(c).padStart(3,"0").slice(0,t)}${this.originalOffset}`}if(c>0){return`${u}${f}${a}:${l}:${s}.${String(c).padStart(3,"0").replace(/0+$/,"")}${this.originalOffset}`}return`${u}${f}${a}:${l}:${s}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const B=K,z="true",q=/e/i,V=/\_/g,R=/^[+\-]?inf$/,P=/^[+\-]?nan$/,H=/^[+\-]?0x/i;function Y(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const J=/^[+\-]?0o/i,X=/^[+\-]?0b/i;function*G(e){const t=new F(C(e));for(;!t.next().done;){const n=ae(t,e);for(const e of n)yield e}}function Q(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function ee(n,r){const o=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,i=o===e.Table;if(i&&"["!==n.value.raw)throw new v(r,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!i){const e=n.peek();if(e.done)throw new v(r,n.value.loc.start,'Expected second "[" for array of tables opening, found end of input');if("["!==n.value.raw||"["!==e.value.raw)throw new v(r,n.value.loc.start,`Expected array of tables opening "[[", found ${n.value.raw+e.value.raw}`);const t=n.value,o=e.value;if(t.loc.end.line!==o.loc.start.line||t.loc.end.column!==o.loc.start.column)throw new v(r,t.loc.start,"Array of tables opening brackets must be immediately adjacent with no whitespace: [[table]]")}const a=i?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};if(n.next(),o===e.TableArray&&n.next(),n.done)throw new v(r,a.loc.start,"Expected table key, reached end of file");if(n.value.type===t.Bracket&&"]"===n.value.raw)throw new v(r,n.value.loc.start,o===e.TableArray?"Array of tables header [[]] requires a table name":"Table header [] requires a table name");const l=n.value.raw;if(l.startsWith('"""')||l.startsWith("'''"))throw new v(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(l.startsWith('"')||l.startsWith("'")))for(let e=0;e<l.length;e++)if(!Y(l.charCodeAt(e)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${l[e]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);let s;try{s=[U(n.value.raw)]}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}for(a.item={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:s};!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=n.value.raw;if(!(t.startsWith('"')||t.startsWith("'")))for(let e=0;e<t.length;e++)if(!Y(t.charCodeAt(e)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${t[e]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);const o=" ".repeat(e.loc.start.column-a.item.loc.end.column),i=" ".repeat(n.value.loc.start.column-e.loc.end.column);a.item.loc.end=n.value.loc.end,a.item.raw+=`${o}.${i}${n.value.raw}`;try{a.item.value.push(U(n.value.raw))}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}}if(n.next(),!n.done){const e=a.loc.start.line;if(n.value.loc.start.line!==e)throw new v(r,n.value.loc.start,i?`Table header must not contain newlines. Expected closing ']' on line ${e}, found on line ${n.value.loc.start.line}`:`Unclosed array of tables header: expected closing ']]' on line ${e}, found newline`)}if(i&&(n.done||"]"!==n.value.raw))throw new v(r,n.done?a.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!i&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new v(r,n.done||n.peek().done?a.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}`);if(!i){const e=n.value,t=n.peek().value;if(e.loc.end.line!==t.loc.start.line||e.loc.end.column!==t.loc.start.column)throw new v(r,e.loc.start,"Array of tables closing brackets must be immediately adjacent with no whitespace: ]]")}if(i||n.next(),a.loc.end=n.value.loc.end,!n.peek().done){const e=n.peek().value;if(e.loc.start.line===a.loc.end.line&&e.type!==t.Comment)throw new v(r,e.loc.start,`Unexpected content after ${i?"table":"array of tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;){n.next();const e=ae(n,r);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:i?e.Table:e.TableArray,loc:{start:g(a.loc.start),end:c.length?g(c[c.length-1].loc.end):g(a.loc.end)},key:a,items:c}}function te(t,n){let r;try{r=U(t.value.raw)}catch(e){const r=e;throw new v(n,t.value.loc.start,r.message)}return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:r}}function ne(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===z}}function re(n,r){let o,i=n.value.loc,a=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&B.IS_FULL_DATE.test(a)&&B.IS_FULL_TIME.test(n.peek().value.raw)){const e=i.start;n.next(),i={start:e,end:n.value.loc.end},a+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=i.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(r,n.value.loc.end,"Expected fractional value for DateTime");n.next(),i={start:e,end:n.value.loc.end},a+=`.${n.value.raw}`}if(function(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new v(t,n,`Invalid datetime "${e}": fractional seconds must have at least one digit after decimal point`);if(/[+-]$/.test(e))throw new v(t,n,`Invalid datetime "${e}": timezone offset requires hour and minute components`);const r=/\d{2}:\d{2}/.test(e),o=r?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(o){const e=o[0],r=o[2],i=o[3],a=o[4];if(":"!==i)throw new v(t,n,`Invalid timezone offset "${e}": must use colon separator (e.g., +09:09)`);if(2!==r.length)throw new v(t,n,`Invalid timezone offset "${e}": hour must be exactly 2 digits`);if(!a||0===a.length)throw new v(t,n,`Invalid timezone offset "${e}": minute component is required`);if(2!==a.length)throw new v(t,n,`Invalid timezone offset "${e}": minute must be exactly 2 digits`);const l=parseInt(r,10);if(l<0||l>23)throw new v(t,n,`Invalid timezone offset "${e}": hour must be between 00 and 23, found ${r}`);const s=parseInt(a,10);if(s<0||s>59)throw new v(t,n,`Invalid timezone offset "${e}": minute must be between 00 and 59, found ${a}`)}const i=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!i.test(e)){if(/^\d{4}-\d{2}-\d{2}T$/.test(e))throw new v(t,n,`Invalid date "${e}": date cannot end with 'T' without a time component`);if(/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e))throw new v(t,n,`Invalid date "${e}": unexpected character after date`);if(/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e))throw new v(t,n,`Invalid datetime "${e}": missing separator 'T' or space between date and time`);throw new v(t,n,`Invalid datetime "${e}"`)}const a=e.match(/^(\d+)-/);if(a&&4!==a[1].length)throw new v(t,n,`Invalid date "${e}": year must be exactly 4 digits, found ${a[1].length}`);const l=/^(\d+)-(\d+)-(\d+)/,s=e.match(l);if(s){const[,,r,o]=s;if(2!==r.length)throw new v(t,n,`Invalid date "${e}": month must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new v(t,n,`Invalid date "${e}": day must be exactly 2 digits, found ${o.length}`)}const c=/[T ](\d+):(\d+)(?::(\d+))?/,u=e.match(c);if(u){const[,r,o,i]=u;if(2!==r.length)throw new v(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new v(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(i&&2!==i.length)throw new v(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${i.length}`)}const f=/^(\d+):(\d+)(?::(\d+))?/,d=e.match(f);if(d&&!s){const[,r,o,i]=d;if(2!==r.length)throw new v(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new v(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(i&&2!==i.length)throw new v(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${i.length}`)}const m=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),h=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(m){const[,r,o,i,a,l,s]=m,c=parseInt(o,10);if(c<1||c>12)throw new v(t,n,`Invalid date "${e}": month must be between 01 and 12`);const u=parseInt(i,10);if(u<1||u>31)throw new v(t,n,`Invalid date "${e}": day must be between 01 and 31`);const f=function(e,t){const n=[31,28,31,30,31,30,31,31,30,31,30,31];if(2===t){return e%4==0&&e%100!=0||e%400==0?29:28}return n[t-1]}(parseInt(r,10),c);if(u>f)throw new v(t,n,`Invalid date "${e}": day ${i} is invalid for month ${o} in year ${r}`);if(void 0!==a){const r=parseInt(a,10);if(r<0||r>23)throw new v(t,n,`Invalid time "${e}": hour must be between 00 and 23`)}if(void 0!==l){const r=parseInt(l,10);if(r<0||r>59)throw new v(t,n,`Invalid time "${e}": minute must be between 00 and 59`)}if(void 0!==s){const r=parseInt(s,10);if(r<0||r>60)throw new v(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}else if(h){const[,r,o,i]=h,a=parseInt(r,10);if(a<0||a>23)throw new v(t,n,`Invalid time "${e}": hour must be between 00 and 23`);const l=parseInt(o,10);if(l<0||l>59)throw new v(t,n,`Invalid time "${e}": minute must be between 00 and 59`);if(void 0!==i){const r=parseInt(i,10);if(r<0||r>60)throw new v(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}}(a,r,i.start),B.IS_FULL_DATE.test(a))o=B.IS_DATE_ONLY.test(a)?new N(a):B.IS_LOCAL_DATETIME_T.test(a)?new W(a,!1):B.IS_LOCAL_DATETIME_SPACE.test(a)?new W(a,!0):B.IS_OFFSET_DATETIME_T.test(a)?new Z(a,!1):B.IS_OFFSET_DATETIME_SPACE.test(a)?new Z(a,!0):new Date(a.replace(" ","T"));else if(B.IS_TIME_ONLY.test(a))o=new j(a,a);else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${a}`)}return{type:e.DateTime,loc:i,raw:a,value:o}}function oe(n,r){let o,i=n.value.loc,a=n.value.raw;if(R.test(a))o=a.startsWith("-")?-1/0:1/0;else if(P.test(a))o=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(/_$/.test(a))throw new v(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(a))throw new v(r,i.start,"Leading underscore is not allowed");if(/__/.test(a))throw new v(r,i.start,"Consecutive underscores are not allowed");if(/[eE][+\-]?$/.test(a))throw new v(r,i.start,`Invalid float "${a}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(a))throw new v(r,i.start,`Invalid float "${a}": decimal point not allowed in exponent`);if(/_[eE]/.test(a))throw new v(r,i.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(a))throw new v(r,i.start,"Underscore at start of exponent is not allowed");if(!n.peek().done&&n.peek().value.type===t.Dot)throw new v(r,n.peek().value.loc.start,`Invalid float "${a}.": cannot have decimal point after exponent`);const e=a.replace(V,"");if(/^[+\-]?0\d/.test(e)&&!H.test(a)&&!J.test(a)&&!X.test(a))throw new v(r,i.start,"Leading zeros are not allowed in the integer part of a float");o=Number(a.replace(V,""))}else{const e=i.start;{if(q.test(a)&&!H.test(a))throw new v(r,i.start,`Invalid float "${a}": cannot have decimal point after exponent`);const e=a,t=e.replace(V,"");if(/^[+\-]?0\d/.test(t)&&!H.test(e)&&!J.test(e)&&!X.test(e))throw new v(r,i.start,"Leading zeros are not allowed in the integer part of a float");const n=e.replace(/^[+\-]/,"");if(""===n||"_"===n)throw new v(r,i.start,"Invalid float: decimal point must be preceded by at least one digit");if(/_$/.test(e))throw new v(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(e))throw new v(r,i.start,"Leading underscore is not allowed");if(/__/.test(e))throw new v(r,i.start,"Consecutive underscores are not allowed")}if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(r,n.value.loc.end,"Expected fraction value for Float");n.next(),a+=`.${n.value.raw}`,i={start:e,end:n.value.loc.end};{const e=n.value.raw;if(!/^\d/.test(e))throw new v(r,n.value.loc.start,`Invalid float: fractional part must start with a digit, found "${e}"`);if(/^_/.test(e))throw new v(r,n.value.loc.start,"Underscore after decimal point is not allowed");if(/_$/.test(e))throw new v(r,n.value.loc.start,"Trailing underscore in fractional part is not allowed");if(/_[eE]/.test(e))throw new v(r,n.value.loc.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(e))throw new v(r,n.value.loc.start,"Underscore at start of exponent is not allowed");if(/[eE][+\-]?$/.test(e))throw new v(r,n.value.loc.start,`Invalid float "${a}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(e))throw new v(r,n.value.loc.start,`Invalid float "${a}": decimal point not allowed in exponent`)}o=Number(a.replace(V,""))}if(Number.isNaN(o)&&!P.test(a))throw new v(r,i.start,`Invalid float "${a}"`);return{type:e.Float,loc:i,raw:a,value:o}}function ie(t,n){const r=t.value.raw,o=t.value.loc;if(/^\d{1,}-\d{1,}/.test(r)||/^\d{1,}:\d{1,}/.test(r)||/^\d{6}-\d{2}$/.test(r))throw new v(n,o.start,`Invalid integer "${r}"`);{if("-0"===r||"+0"===r)return{type:e.Integer,loc:o,raw:r,value:0};if(/^[+\-]{2,}/.test(r))throw new v(n,o.start,"Double sign is not allowed in integers");const t=r.replace(/_/g,"");if(/^[+\-]?0\d/.test(t)&&!H.test(r)&&!J.test(r)&&!X.test(r))throw new v(n,o.start,"Leading zeros are not allowed in decimal integers");if(/_$/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(/^[+\-]?_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(/__/.test(r))throw new v(n,o.start,"Consecutive underscores in numbers are not allowed")}let i,a=10;if(H.test(r)){if(a=16,/^[+\-]?0X/.test(r))throw new v(n,o.start,'Hexadecimal prefix must be lowercase "0x"');if(/^[+\-]?0x_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0x/i,""),!i||"_"===i||/^_/.test(i))throw new v(n,o.start,"Incomplete hexadecimal number");const e=i.replace(/_/g,"");if(!/^[0-9a-fA-F]+$/.test(e))throw new v(n,o.start,"Invalid hexadecimal digits");if(/^[+\-]/.test(r))throw new v(n,o.start,"Hexadecimal numbers cannot have a sign prefix")}else if(J.test(r)){if(a=8,/^[+\-]?0O/.test(r))throw new v(n,o.start,'Octal prefix must be lowercase "0o"');if(/^[+\-]?0o_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0o/i,""),!i||"_"===i||/^_/.test(i))throw new v(n,o.start,"Incomplete octal number");const e=i.replace(/_/g,"");if(!/^[0-7]+$/.test(e))throw new v(n,o.start,"Invalid octal digits (must be 0-7)");if(/^[+\-]/.test(r))throw new v(n,o.start,"Octal numbers cannot have a sign prefix")}else if(X.test(r)){if(a=2,/^[+\-]?0B/.test(r))throw new v(n,o.start,'Binary prefix must be lowercase "0b"');if(/^[+\-]?0b_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0b/i,""),!i||"_"===i||/^_/.test(i))throw new v(n,o.start,"Incomplete binary number");const e=i.replace(/_/g,"");if(!/^[01]+$/.test(e))throw new v(n,o.start,"Invalid binary digits (must be 0 or 1)");if(/^[+\-]/.test(r))throw new v(n,o.start,"Binary numbers cannot have a sign prefix")}const l=parseInt(r.replace(V,"").replace(J,"").replace(X,""),a);if(Number.isNaN(l))throw new v(n,o.start,`Invalid integer "${r}"`);return{type:e.Integer,loc:o,raw:r,value:l}}function ae(n,r){if(n.value.type===t.Comment)return[Q(n)];if(n.value.type===t.Bracket)return[ee(n,r)];if(n.value.type===t.Literal)return function(n,r){const o=n.value.raw;if(o.endsWith(":"))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+[...o].length-1},"Use '=' to separate keys and values, not ':'");if(o.startsWith('"""')||o.startsWith("'''"))throw new v(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!o.startsWith('"')&&!o.startsWith("'"))for(let e=0;e<o.length;e++)if(!Y(o.charCodeAt(e)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${o[e]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);let i;try{i=[U(n.value.raw)]}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}const a={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:i};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next(),n.next();const e=n.value.raw;if(e.startsWith('"""')||e.startsWith("'''"))throw new v(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(e.startsWith('"')||e.startsWith("'")))for(let t=0;t<e.length;t++)if(!Y(e.charCodeAt(t)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+t},`Invalid character '${e[t]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);a.loc.end=n.value.loc.end,a.raw+=`.${n.value.raw}`;try{a.value.push(U(n.value.raw))}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}}if(n.next(),!n.done&&n.value.loc.start.line!==a.loc.end.line)throw new v(r,n.value.loc.start,'Expected "=" for key-value on the same line as the key');if(n.done||n.value.type!==t.Equal){if(!n.done&&":"===n.value.raw)throw new v(r,n.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new v(r,n.done?a.loc.end:n.value.loc.start,'Expected "=" for key-value')}const l=n.value.loc.start.column,s=n.value.loc.start.line;if(n.next(),n.done)throw new v(r,a.loc.start,"Expected value for key-value, reached end of file");if(n.value.loc.start.line!==s)throw new v(r,n.value.loc.start,"Expected value on the same line as the '=' sign");if(n.done)throw new v(r,a.loc.start,"Expected value for key-value");const c=le(n,r),u=c[0];if(!n.peek().done){const o=n.peek().value;if(o.type===t.Dot&&o.loc.start.line===u.loc.end.line&&(u.type===e.Float||u.type===e.Integer))throw new v(r,o.loc.start,"Invalid number: multiple decimal points not allowed");if((o.type===t.Literal||o.type===t.Bracket)&&o.loc.start.line===u.loc.end.line)throw new v(r,o.loc.start,"Key/value pairs must be separated by a newline")}return c[0]={type:e.KeyValue,key:a,value:u,loc:{start:g(a.loc.start),end:g(u.loc.end)},equals:l},c}(n,r);throw n.value.type===t.Equal?new v(r,n.value.loc.start,"Missing key before '='"):new v(r,n.value.loc.start,`Unexpected token "${n.value.type}". Expected Comment, Bracket, or String`)}function le(n,r){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===b||e[0]===$?[te(n,r)]:e===z||"false"===e?[ne(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[re(n,r)]:!n.peek().done&&n.peek().value.type===t.Dot||R.test(e)||P.test(e)||q.test(e)&&!H.test(e)?[oe(n,r)]:[ie(n,r)]}if(n.value.type===t.Curly){const[o,i]=function(n,r){if("{"!==n.value.raw)throw new v(r,n.value.loc.start,'Expected "{" for inline table');const o={type:e.InlineTable,loc:n.value.loc,items:[]},i=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){i.push(Q(n)),n.next();continue}if(n.value.type===t.Comma){const e=o.items[o.items.length-1];if(!e)throw new v(r,n.value.loc.start,'Found "," without previous value in inline table');if(e.comma)throw new v(r,n.value.loc.start,"Found consecutive commas in inline table (double comma is not allowed)");e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const a=o.items[o.items.length-1];if(a&&!a.comma)throw new v(r,n.value.loc.start,"Missing comma between inline table items");const l=ae(n,r),s=l[0];if(s.type===e.KeyValue){o.items.push({type:e.InlineItem,loc:y(s.loc),item:s,comma:!1});for(let e=1;e<l.length;e++)i.push(l[e])}n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new v(r,n.done?o.loc.start:n.value.loc.start,'Expected "}"');return o.loc.end=n.value.loc.end,[o,i]}(n,r);return[o,...i]}if(n.value.type===t.Bracket){const[o,i]=function(n,r){if("["!==n.value.raw)throw new v(r,n.value.loc.start,'Expected "[" for inline array');const o={type:e.InlineArray,loc:n.value.loc,items:[]},i=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=o.items[o.items.length-1];if(!e)throw new v(r,n.value.loc.start,'Found "," without previous value for inline array');if(e.comma)throw new v(r,n.value.loc.start,"Found consecutive commas in array (double comma is not allowed)");e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)i.push(Q(n));else{const t=o.items[o.items.length-1];if(t&&!t.comma)throw new v(r,n.value.loc.start,"Missing comma between array elements");const a=le(n,r),l=a[0];o.items.push({type:e.InlineItem,loc:y(l.loc),item:l,comma:!1});for(let e=1;e<a.length;e++)i.push(a[e])}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new v(r,n.done?o.loc.start:n.value.loc.start,'Expected "]"');return o.loc.end=n.value.loc.end,[o,i]}(n,r);return[o,...i]}throw n.value.type===t.Dot?new v(r,n.value.loc.start,"Invalid number: cannot start with a dot. Numbers must start with a digit"):new v(r,n.value.loc.start,"Unrecognized token type")}function se(e){return e[e.length-1]}function ce(){return Object.create(null)}function ue(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function fe(e){return"[object Date]"===Object.prototype.toString.call(e)}function de(e){return e&&"object"==typeof e&&!fe(e)&&!Array.isArray(e)}function me(e,t){return t in e}function he(e){if(de(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${he(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(he).join(",")}]`:JSON.stringify(e)}function pe(e,t){const n=e.length,r=t.length;e.length=n+r;for(let o=0;o<r;o++)e[n+o]=t[o]}function we(e){return e.startsWith('"""')||e.startsWith("'''")}function ge(t,n){var r;function o(e,t){for(const n of e)i(n,t)}function i(t,r){const a=n[t.type];switch(a&&"function"==typeof a&&a(t,r),a&&a.enter&&a.enter(t,r),t.type){case e.Document:o(t.items,t);break;case e.Table:i(t.key,t),o(t.items,t);break;case e.TableKey:i(t.item,t);break;case e.TableArray:i(t.key,t),o(t.items,t);break;case e.TableArrayKey:i(t.item,t);break;case e.KeyValue:i(t.key,t),i(t.value,t);break;case e.InlineArray:o(t.items,t);break;case e.InlineItem:i(t.item,t);break;case e.InlineTable:o(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}"`)}a&&a.exit&&a.exit(t,r)}null!=(r=t)&&"function"==typeof r[Symbol.iterator]?o(t,null):i(t,null)}const ye=new WeakMap,ve=e=>(ye.has(e)||ye.set(e,new WeakMap),ye.get(e)),be=new WeakMap,$e=e=>(be.has(e)||be.set(e,new WeakMap),be.get(e));function Se(e,t,n,r){if(d(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(i(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,r)}else if(m(t))t.item=r;else{if(!i(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}xe(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const o=h(n.loc),a=h(r.loc);_e({lines:a.lines-o.lines,columns:a.columns-o.columns},$e(e),r,n)}function Te(e,t,a,l,m){if(!d(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,w;l=null!=l&&"number"==typeof l?l:t.items.length,s(t)||u(t)?({shift:p,offset:w}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const r=null!=n?e.items[n-1]:se(e.items),o=null==n||n===e.items.length;e.items.splice(n,0,t);const i=!!r,a=!o;i&&(r.comma=!0);a&&(t.comma=!0);const l=s(e)&&function(e){if(!e.items.length)return!1;return h(e.loc).lines>e.items.length}(e),u=o&&!0===t.comma;return Ie(e,t,n,{useNewLine:l,hasCommaHandling:!0,isLastElement:o,hasSeparatingCommaBefore:i,hasSeparatingCommaAfter:a,hasTrailingComma:u})}(t,a,l)):m&&n(t)?({shift:p,offset:w}=function(e,t,n){const r=Ie(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,a,l)):({shift:p,offset:w}=function(e,t,a){if(l=t,!(i(l)||r(l)||o(l)||f(l)))throw new Error(`Incompatible child type "${t.type}"`);var l;const s=e.items[a-1],c=n(e)&&!e.items.length;e.items.splice(a,0,t);const u=s?{line:s.loc.end.line,column:f(s)?e.loc.start.column:s.loc.start.column}:g(e.loc.start),d=r(t)||o(t);let m=0;c||(m=d?2:1);u.line+=m;const p={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},w=h(t.loc),y={lines:w.lines+(m-1),columns:w.columns};return{shift:p,offset:y}}(t,a,l)),xe(a,p);const y=t.items[l-1],v=y&&$e(e).get(y);v&&(w.lines+=v.lines,w.columns+=v.columns,$e(e).delete(y));$e(e).set(a,w)}function Ie(e,t,n,r={}){const{useNewLine:o=!1,skipCommaSpace:i=2,skipBracketSpace:a=1,hasCommaHandling:l=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:d=!1}=r,m=n>0?e.items[n-1]:void 0,p=m?{line:m.loc.end.line,column:o?f(m)?e.loc.start.column:m.loc.start.column:m.loc.end.column}:g(e.loc.start);let w=0;if(o)w=1;else{const e=c||!l&&!!m;e&&l?p.column+=i:(e||l&&!m)&&(p.column+=a)}p.line+=w;const y={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=h(t.loc);if(!l){return{shift:y,offset:{lines:v.lines+(w-1),columns:v.columns}}}let b=0;c&&d&&!u&&s&&(b=-1);return{shift:y,offset:{lines:v.lines+(w-1),columns:v.columns+(c||u?i:0)+(d?1+b:0)}}}function ke(e,t,n){if(!d(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 o=t.items[r-1];let i=t.items[r+1];t.items.splice(r,1);let a=h(n.loc);i&&f(i)&&i.loc.start.line===n.loc.end.line&&(a=h({start:n.loc.start,end:i.loc.end}),i=t.items[r+1],t.items.splice(r,1));const l=o&&c(o)||i&&c(i),s=o&&o.loc.end.line===n.loc.start.line,u=i&&i.loc.start.line===n.loc.end.line,p=l&&(s||u),w={lines:-(a.lines-(p?1:0)),columns:-a.columns};if(void 0===o&&void 0===i&&(w.lines=0,w.columns=0),l&&s&&(w.columns-=2),l&&!o&&i&&(w.columns-=2),l&&o&&!i){const e=n.comma;o.comma=!!e}const g=o||t,y=o?$e(e):ve(e),v=$e(e),b=y.get(g);b&&(w.lines+=b.lines,w.columns+=b.columns);const $=v.get(n);$&&(w.lines+=$.lines,w.columns+=$.columns),y.set(g,w)}function Ce(e,t,n=!0){if(!n)return;if(!t.items.length)return;_e({lines:0,columns:1},ve(e),t);const r=se(t.items);_e({lines:0,columns:1},$e(e),r)}function Ee(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=se(t.items);r.comma=!0,_e({lines:0,columns:1},$e(e),r)}function Ae(t){const n=ve(t),r=$e(t),o={lines:0,columns:{}};function i(e){const t=o.lines;e.loc.start.line+=t;const r=o.columns[e.loc.start.line]||0;e.loc.start.column+=r;const i=n.get(e);i&&(o.lines+=i.lines,o.columns[e.loc.start.line]=(o.columns[e.loc.start.line]||0)+i.columns)}function a(e){const t=o.lines;e.loc.end.line+=t;const n=o.columns[e.loc.end.line]||0;e.loc.end.column+=n;const i=r.get(e);i&&(o.lines+=i.lines,o.columns[e.loc.end.line]=(o.columns[e.loc.end.line]||0)+i.columns)}const l={enter:i,exit:a};ge(t,{[e.Document]:l,[e.Table]:l,[e.TableArray]:l,[e.InlineTable]:l,[e.InlineArray]:l,[e.InlineItem]:l,[e.TableKey]:l,[e.TableArrayKey]:l,[e.KeyValue]:{enter(e){const t=e.loc.start.line+o.lines,n=r.get(e.key);e.equals+=(o.columns[t]||0)+(n?n.columns:0),i(e)},exit:a},[e.Key]:l,[e.String]:l,[e.Integer]:l,[e.Float]:l,[e.Boolean]:l,[e.DateTime]:l,[e.Comment]:l}),ye.delete(t),be.delete(t)}function xe(t,n,r={}){const{first_line_only:o=!1}=r,i=t.loc.start.line,{lines:a,columns:l}=n,s=e=>{o&&e.loc.start.line!==i||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=a,e.loc.end.line+=a};return ge(t,{[e.Table]:s,[e.TableKey]:s,[e.TableArray]:s,[e.TableArrayKey]:s,[e.KeyValue](e){s(e),e.equals+=l},[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 o=t.get(r||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function Ue(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Oe(t){const n=function(t){const n=Me(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:y(n.loc),key:n,items:[]}}function De(t){const n=function(t){const n=Me(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:y(n.loc),key:n,items:[]}}function Fe(t,n){const r=function(t){const n=Me(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:o}=r.loc.end,i=o+1;return xe(n,{lines:0,columns:o+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:g(r.loc.start),end:g(n.loc.end)},key:r,equals:i,value:n}}const Le=/^[\w-]+$/;function Me(e){return e.map((e=>Le.test(e)?e:JSON.stringify(e))).join(".")}function Ke(t,n){let r,o;if(n&&we(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const o=e?"'''":'"""',i=n.includes("\r\n")?"\r\n":"\n",a=n.startsWith(`${o}${i}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!e;let l;l=e?t:t.replace(/\\/g,"\\\\").replace(/\x08/g,"\\b").replace(/\f/g,"\\f").replace(/\t/g,"\\t").replace(/[\x00-\x07\x0B\x0E-\x1F\x7F]/g,(e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase())).replace(/"""/g,'""\\"'),r=a?`${o}${i}${l}${o}`:`${o}${l}${o}`}else r=JSON.stringify(t);if(r.includes("\r\n")||r.includes("\n")&&!r.includes("\r\n")){const e=r.includes("\r\n")?"\r\n":"\n",t=(r.match(new RegExp("\r\n"===e?"\\r\\n":"\\n","g"))||[]).length;o=t>0?{line:1+t,column:3}:{line:1,column:r.length}}else o={line:1,column:r.length};return{type:e.String,loc:{start:{line:1,column:0},end:o},raw:r,value:t}}function Ne(t){return{type:e.InlineItem,loc:y(t.loc),item:t,comma:!1}}const je=!1,We=!0,Ze=!1,Be=!1;function ze(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/),o=e.start.line-1,i=e.end.line-1,a=e.start.column,l=e.end.column;let s="";if(o===i)s=(null===(n=r[o])||void 0===n?void 0:n.substring(a,l+1))||"";else{r[o]&&(s+=r[o].substring(a));for(let e=o+1;e<i;e++)s+="\n"+(r[e]||"");r[i]&&(s+="\n"+r[i].substring(0,l+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=ze(n,t);if(null!==e)return e;if(n.item){const e=ze(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=ze(e[n],t);if(null!==r)return r}return null}function qe(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return Ve(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return Ve(e.items);if("KeyValue"===e.type&&e.value)return qe(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=qe(t);if(null!==e)return e}return null}function Ve(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 Re(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Pe(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function He(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function Ye(e,t){var n,r,o,i,a,l;if(e){if(e instanceof Je)return e;{const s=function(e){if(!e||"object"!=typeof e)return{};const t=new Set(["newLine","trailingNewline","trailingComma","bracketSpacing","inlineTableStart","truncateZeroTimeInDates","useTabsForIndentation"]),n={},r=[],o=[];for(const i in e){const a=Object.prototype.hasOwnProperty.call(e,i);if(t.has(i)){const t=e[i];switch(i){case"newLine":"string"==typeof t?n.newLine=t:o.push(`${i} (expected string, got ${typeof t})`);break;case"trailingNewline":"boolean"==typeof t||"number"==typeof t?n.trailingNewline=t:o.push(`${i} (expected boolean or number, got ${typeof t})`);break;case"trailingComma":case"bracketSpacing":case"truncateZeroTimeInDates":case"useTabsForIndentation":"boolean"==typeof t?n[i]=t:o.push(`${i} (expected boolean, got ${typeof t})`);break;case"inlineTableStart":"number"==typeof t&&Number.isInteger(t)&&t>=0||null==t?n.inlineTableStart=t:o.push(`${i} (expected non-negative integer or undefined, got ${typeof t})`)}}else a&&r.push(i)}if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Array.from(t).join(", ")}`),o.length>0)throw new TypeError(`Invalid types for format properties: ${o.join(", ")}`);return n}(e);return new Je(null!==(n=s.newLine)&&void 0!==n?n:t.newLine,null!==(r=s.trailingNewline)&&void 0!==r?r:t.trailingNewline,null!==(o=s.trailingComma)&&void 0!==o?o:t.trailingComma,null!==(i=s.bracketSpacing)&&void 0!==i?i:t.bracketSpacing,void 0!==s.inlineTableStart?s.inlineTableStart:t.inlineTableStart,null!==(a=s.truncateZeroTimeInDates)&&void 0!==a?a:t.truncateZeroTimeInDates,null!==(l=s.useTabsForIndentation)&&void 0!==l?l:t.useTabsForIndentation)}}return t}class Je{constructor(e,t,n,r,o,i,a){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:je,this.bracketSpacing=null!=r?r:We,this.inlineTableStart=null!=o?o:1,this.truncateZeroTimeInDates=null!=i?i:Ze,this.useTabsForIndentation=null!=a?a:Be}static default(){return new Je("\n",1,je,We,1,Ze,Be)}static autoDetectFormat(e){const t=Je.default();t.newLine=He(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=G(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=qe(e);if(null!==t)return t}return je}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=ze(t,e);if(null!==n)return n}return We}(e,r)}catch(e){t.trailingComma=je,t.bracketSpacing=We}return t.useTabsForIndentation=function(e){const t=e.split(/\r?\n/);let n=0,r=0;for(const e of t)if(0!==e.length&&("\t"===e[0]?n++:" "===e[0]&&r++,n+r>=5))break;return n>r}(e),t.inlineTableStart=1,t.truncateZeroTimeInDates=Ze,t}}function Xe(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!i(e))return!1;const n=u(e.value),r=s(e.value)&&e.value.items.length&&u(e.value.items[0].item);if(n||r){const n=et(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{ke(e,e,t),u(t.value)?Te(e,e,Ge(t)):function(e){const t=Ue();for(const n of e.value.items){const r=De(e.key.value);Te(t,t,r);for(const e of n.item.items)Te(t,r,e.item)}return Ae(t),t.items}(t).forEach((t=>{Te(e,e,t)}))})),Ae(e),e}function Ge(e){const t=Oe(e.key.value);for(const n of e.value.items)Te(t,t,n.item);return Ae(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 et(e){return Math.max(0,e.length-1)}function tt(e,t,n){var r;for(let o=e.items.length-1;o>=0;o--){const a=e.items[o];if(i(a)&&u(a.value)){const o=[...e.key.item.value,...a.key.value];if(et(o)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=Oe(o);for(const e of a.value.items)Te(r,r,e.item);ke(e,e,a),Qe(e),t.push(r),tt(r,t,n)}}}}function nt(e,t=Je.default()){e=function(e){const t=[],n=[];for(const r in e)de(e[r])||Array.isArray(e[r])?n.push(r):t.push(r);const r={};for(let n=0;n<t.length;n++){const o=t[n];r[o]=e[o]}for(let t=0;t<n.length;t++){const o=n[t];r[o]=e[o]}return r}(e=it(e));const n=Ue();for(const r of rt(e,t))Te(n,n,r);Ae(n);const r=function(e,...t){return t.reduce(((e,t)=>t(e)),e)}(n,(e=>Xe(e,t)),(e=>function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const r of e.items)if(i(r)&&u(r.value)){if(et(r.key.value)<t.inlineTableStart){const o=Ge(r);ke(e,e,r),Te(e,e,o),tt(o,n,t)}}else"Table"===r.type&&tt(r,n,t);for(const t of n)Te(e,e,t);return Ae(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)),xe(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(r)}function*rt(e,t){for(const n of Object.keys(e))yield Fe([n],ot(e[n],t))}function ot(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?Ke(t):ue(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&&(!ue(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):fe(t)?function(t,n){n.truncateZeroTimeInDates&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new N(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){Te(r,r,Ne(ot(e,n)))}return Ce(r,r,n.bracketSpacing),Ee(r,r,n.trailingComma),Ae(r),r}(t,n):function(t,n){if(t=it(t),!de(t))return ot(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},o=[...rt(t,n)];for(const e of o){Te(r,r,Ne(e))}return Ce(r,r,n.bracketSpacing),Ee(r,r,n.trailingComma),Ae(r),r}(t,n)}function it(e){return e?fe(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const at=/(\r\n|\n)/g;function lt(t,n){const r=[],o=n.useTabsForIndentation?"\t":" ";if(ge(t,{[e.TableKey](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),st(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[e.TableArrayKey](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+2}},"[[",o),st(r,{start:{line:n.line,column:n.column-2},end:n},"]]",o)},[e.KeyValue](e){const{start:{line:t}}=e.loc;st(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=",o)},[e.Key](e){st(r,e.loc,e.raw,o)},[e.String](e){st(r,e.loc,e.raw,o)},[e.Integer](e){st(r,e.loc,e.raw,o)},[e.Float](e){st(r,e.loc,e.raw,o)},[e.Boolean](e){st(r,e.loc,e.value.toString(),o)},[e.DateTime](e){st(r,e.loc,e.raw,o)},[e.InlineArray](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),st(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[e.InlineTable](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+1}},"{",o),st(r,{start:{line:n.line,column:n.column-1},end:n},"}",o)},[e.InlineItem](e){if(!e.comma)return;const t=e.loc.end;st(r,{start:t,end:{line:t.line,column:t.column+1}},",",o)},[e.Comment](e){st(r,e.loc,e.raw,o)}}),n.useTabsForIndentation)for(let e=0;e<r.length;e++){const t=r[e],n=t.match(/^( +)/);if(n){const o=n[1],i="\t".repeat(o.length);r[e]=i+t.substring(o.length)}}return r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function st(e,t,n,r=" "){const o=n.split(at).filter((e=>"\n"!==e&&"\r\n"!==e)),i=t.end.line-t.start.line+1;if(o.length!==i)throw new Error(`Mismatch between location and raw string, expected ${i} lines for "${n}"`);for(let r=t.start.line;r<=t.end.line;r++){const i=ct(e,r);if(void 0===i)throw new Error(`Line ${r} is uninitialized when writing "${n}" at ${t.start.line}:${t.start.column} to ${t.end.line}:${t.end.column}`);const a=r===t.start.line,l=r===t.end.line;let s="";if(a){const e=i.substring(0,t.start.column);s=e.length<t.start.column?e.padEnd(t.start.column," "):e}const c=l?i.substring(t.end.column):"";e[r-1]=s+o[r-t.start.line]+c}}function ct(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function ut(t,n,r){for(const o of t.items){const t=o.item;if(t.value.type===e.InlineTable){const e=n.concat(t.key.value);r.add(gt(e)),ut(t.value,e,r)}}}function ft(t,n=""){const r=ce(),o=new Set,i=new Set,a=new Set,l=new Set,s=new Set;let c=r,u=[];const f={tables:o,table_arrays:i,defined:a,implicit_tables:l,inline_tables:s};for(const n of t)switch(n.type){case e.Table:d(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.TableArray:m(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.KeyValue:h(n)}return r;function d(e){const t=e.key.item.value;try{mt(r,[],t,e.type,f)}catch(t){const r=t;throw new v(n,e.key.loc.start,r.message)}const i=gt(t);o.add(i),a.add(i),c=ht(r,t),u=t}function m(e){const t=e.key.item.value;try{mt(r,[],t,e.type,f)}catch(t){const r=t;throw new v(n,e.key.loc.start,r.message)}const o=gt(t);i.add(o),a.add(o),c=function(e,t){const n=pt(e,t.slice(0,-1)),r=se(t);n[r]||(n[r]=[]);const o=ce();return n[se(t)].push(o),o}(r,t),u=t}function h(t){const r=t.key.value;try{mt(c,u,r,t.type,f)}catch(e){const r=e;throw new v(n,t.key.loc.start,r.message)}if(r.length>1)for(let e=1;e<r.length;e++){const t=gt(u.concat(r.slice(0,e)));l.add(t),a.add(t)}let o;try{o=dt(t.value)}catch(e){const r=e;throw new v(n,t.value.loc.start,r.message)}if(t.value.type===e.InlineTable){const e=u.concat(r);s.add(gt(e)),ut(t.value,e,s)}(r.length>1?ht(c,r.slice(0,-1)):c)[se(r)]=o,a.add(gt(u.concat(r)))}}function dt(t){switch(t.type){case e.InlineTable:const n=ce(),r=new Set,o=new Map;return t.items.forEach((({item:e})=>{const t=e.key.value,i=dt(e.value),a=gt(t);if(r.has(a))throw new Error(`Duplicate key "${a}" in inline table`);for(let e=1;e<t.length;e++){const n=gt(t.slice(0,e));if(r.has(n))throw new Error(`Key "${a}" conflicts with already defined key "${n}" in inline table`)}if(o.has(a)){const e=o.get(a);throw new Error(`Key "${a}" conflicts with already defined key "${e}" in inline table`)}r.add(a);for(let e=1;e<t.length;e++){const n=gt(t.slice(0,e));o.has(n)||o.set(n,a)}(t.length>1?ht(n,t.slice(0,-1)):n)[se(t)]=i})),n;case e.InlineArray:return t.items.map((e=>dt(e.item)));case e.DateTime:case e.String:case e.Integer:case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function mt(t,n,r,o,i){const a=n.length>0?gt(n):"",l=new Array(r.length);let s=a;for(let e=0;e<r.length;e++)s=s?s+"."+r[e]:r[e],l[e]=s;const c=l[r.length-1];if(o===e.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=l[e-1];if(i.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if((o===e.Table||o===e.TableArray)&&i.inline_tables.has(c))throw new Error(`Invalid key, cannot extend an inline table at ${c}`);if(o===e.Table||o===e.TableArray)for(let e=1;e<r.length;e++){const t=l[e-1];if(i.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if(o===e.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=l[e-1];if(i.table_arrays.has(t))throw new Error(`Invalid key, cannot traverse into an array of tables at ${t}`)}if((o===e.Table||o===e.TableArray)&&i.implicit_tables.has(c))throw new Error(`Invalid key, a table has already been defined implicitly named ${c}`);if(o===e.KeyValue&&i.implicit_tables.has(c))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(o===e.KeyValue&&r.length>1)for(let e=1;e<=r.length;e++){const t=l[e-1];if(i.tables.has(t))throw new Error(`Invalid key, cannot add to an explicitly defined table ${t} using dotted keys`)}let u=0;for(const e of r){if(!me(t,e))return;if(wt(t[e]))throw new Error(`Invalid key, a value has already been defined for ${l[u]}`);const n=l[u];if(Array.isArray(t[e])&&!i.table_arrays.has(n))throw new Error(`Invalid key, cannot add to a static array at ${n}`);const o=u++<r.length-1;t=Array.isArray(t[e])&&o?se(t[e]):t[e]}const f=c;if(t&&o===e.Table&&i.defined.has(f))throw new Error(`Invalid key, a table has already been defined named ${f}`);if(t&&o===e.KeyValue&&1===r.length&&i.defined.has(f)&&!wt(t))throw new Error(`Invalid key, a table has already been defined named ${f}`);if(t&&o===e.TableArray&&!i.table_arrays.has(f))throw new Error(`Invalid key, cannot add an array of tables to a table at ${f}`)}function ht(e,t){const n=pt(e,t.slice(0,-1)),r=se(t);return n[r]||(n[r]=ce()),n[r]}function pt(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=ce()),Array.isArray(e[t])?se(e[t]):e[t])),e)}function wt(e){return"object"!=typeof e&&!fe(e)}function gt(e){return e.join(".")}var yt,vt,bt,$t;function St(e){return e.type===yt.Remove}function Tt(e,t,n=[]){return e===t||(o=t,fe(r=e)&&fe(o)&&r.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const o=e.map(he),i=t.map(he);i.forEach(((a,l)=>{const s=l>=o.length;if(!s&&o[l]===a)return;const c=o.indexOf(a,l+1);if(!s&&c>-1){r.push({type:yt.Move,path:n,from:c,to:l});const e=o.splice(c,1);return void o.splice(l,0,...e)}const u=!i.includes(o[l]);if(!s&&u)return pe(r,Tt(e[l],t[l],n.concat(l))),void(o[l]=a);r.push({type:yt.Add,path:n.concat(l)}),o.splice(l,0,a)}));for(let e=i.length;e<o.length;e++)r.push({type:yt.Remove,path:n.concat(e)});return r}(e,t,n):de(e)&&de(t)?function(e,t,n=[]){let r=[];const o=Object.keys(e),i=o.map((t=>he(e[t]))),a=Object.keys(t),l=a.map((e=>he(t[e]))),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=o[i.indexOf(e)];return!a.includes(n)};return o.forEach(((o,c)=>{const u=n.concat(o);if(a.includes(o))pe(r,Tt(e[o],t[o],u));else if(s(i[c],l)){const e=a[l.indexOf(i[c])];r.push({type:yt.Rename,path:n,from:o,to:e})}else r.push({type:yt.Remove,path:u})})),a.forEach(((e,t)=>{o.includes(e)||s(l[t],i)||r.push({type:yt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:yt.Edit,path:n}];var r,o}function It(e,t){if(!t.length)return c(e)&&i(e.item)?e.item:e;if(i(e))return It(e.value,t);const n={};let a;if(d(e)&&e.items.some(((e,l)=>{try{let s=[];if(i(e))s=e.key.value;else if(r(e))s=e.key.item.value;else if(o(e)){s=e.key.item.value;const t=he(s);n[t]||(n[t]=0);const r=n[t]++;s=s.concat(r)}else c(e)&&i(e.item)?s=e.item.key.value:c(e)&&(s=[l]);return!(!s.length||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(s,t.slice(0,s.length)))&&(a=c(e)&&i(e.item)?t.length===s.length?e:It(e.item.value,t.slice(s.length)):It(e,t.slice(s.length)),!0)}catch(e){return!1}})),!a)throw new Error(`Could not find node at path ${t.join(".")}`);return a}function kt(e,t){try{return It(e,t)}catch(e){}}function Ct(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=kt(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function Et(e,t,n){return At(G(e),t,Ye(n,Je.autoDetectFormat(e))).tomlString}function At(t,a,l){const f=[...t],d=ft(f),h={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},p=nt(a,Ye(Object.assign(Object.assign({},l),{inlineTableStart:void 0}),l)),w=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(St(n)){let r=t+1;for(;r<e.length;){const o=e[r];if(St(o)&&o.path[0]===n.path[0]&&o.path[1]>n.path[1]){e.splice(r,1),e.splice(t,0,o),t=0;break}r++}}}return e}(Tt(d,a));if(0===w.length)return{tomlString:lt(f,l),document:h};const g=function(e,t,a,l){return a.forEach((a=>{if(function(e){return e.type===yt.Add}(a)){const f=It(t,a.path),d=a.path.slice(0,-1);let m,h=se(a.path),p=o(f);if(ue(h)&&!d.some(ue)){const t=kt(e,d.concat(0));t&&o(t)&&(p=!0)}if(r(f))m=e;else if(p){m=e;const t=e,n=kt(t,d.concat(h-1)),r=kt(t,d.concat(h));h=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else m=Ct(e,a.path),i(m)&&(m=m.value);if(o(m)||s(m)||n(m)){if(s(m)){const e=Re(m);c(f)&&(f.comma=e)}if(void 0!==l.inlineTableStart&&l.inlineTableStart>0&&n(m)&&r(f)){const t=_t(f,e,l);Te(e,m,f,h);for(const n of t)Te(e,e,n,void 0)}else Te(e,m,f,h)}else if(u(m)){const t=Pe(m);if(i(f)){const n=Ne(f);n.comma=t,Te(e,m,n)}else Te(e,m,f)}else if(void 0!==l.inlineTableStart&&l.inlineTableStart>0&&i(f)&&u(f.value)&&r(m)){et([...m.key.item.value,...f.key.value])<l.inlineTableStart?function(e,t,n,r){const o=t.key.item.value,a=[...o,...e.key.value],l=Oe(a);if(u(e.value))for(const t of e.value.items)c(t)&&i(t.item)&&Te(n,l,t.item,void 0);Te(n,n,l,void 0),Qe(t);const s=_t(l,n,r);for(const e of s)Te(n,n,e,void 0)}(f,m,e,l):Te(e,m,f)}else if(0===l.inlineTableStart&&i(f)&&u(f.value)&&n(m))Te(e,m,f,void 0,!0);else{let t=f;c(f)&&(r(m)||n(m))&&(t=f.item),Te(e,m,t)}}else if(function(e){return e.type===yt.Edit}(a)){let n,r=It(e,a.path),o=It(t,a.path);if(i(r)&&i(o))xt(r.value,o.value),n=r,r=r.value,o=o.value;else if(i(r)&&c(o)&&i(o.item))n=r,r=r.value,o=o.item.value;else if(c(r)&&i(o))n=r,r=r.item;else if(c(r)&&c(o)&&i(r.item)&&i(o.item))xt(r.item.value,o.item.value),n=r.item,r=r.item.value,o=o.item.value;else if(n=Ct(e,a.path),i(n)){const t=a.path.slice(0,-1),r=It(e,t);i(r)&&s(r.value)&&(n=r.value)}Se(e,n,r,o)}else if(St(a)){let t=Ct(e,a.path);i(t)&&(t=t.value);const n=It(e,a.path);ke(e,t,n)}else if(function(e){return e.type===yt.Move}(a)){let t=It(e,a.path);m(t)&&(t=t.item),i(t)&&(t=t.value);const n=t.items[a.from];ke(e,t,n),Te(e,t,n,a.to)}else if(function(e){return e.type===yt.Rename}(a)){let n=It(e,a.path.concat(a.from)),r=It(t,a.path.concat(a.to));m(n)&&(n=n.item),m(r)&&(r=r.item),Se(e,n,n.key,r.key)}})),Ae(e),e}(h,p,w,l);return{tomlString:lt(g.items,l),document:g}}function xt(e,t){if(a(e)&&a(t)&&we(e.raw)){const n=Ke(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(l(e)&&l(t)){const n=e.raw,r=t.value,o=K.createDateWithOriginalFormat(r,n);t.value=o,t.raw=o.toISOString();0!==t.raw.length-n.length&&(t.loc.end.column=t.loc.start.column+t.raw.length)}if(s(e)&&s(t)){const n=Re(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=Pe(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function _t(e,t,n){const r=[],o=(e,r)=>{var a;for(let l=e.items.length-1;l>=0;l--){const s=e.items[l];if(i(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(et(u)<(null!==(a=n.inlineTableStart)&&void 0!==a?a:1)&&0!==n.inlineTableStart){const n=Oe(u);for(const e of s.value.items)c(e)&&i(e.item)&&Te(t,n,e.item,void 0);e.items.splice(l,1),Qe(e),r.push(n),o(n,r)}}}};return o(e,r),r}function Ut(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function Ot(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function Dt(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(yt||(yt={})),"function"==typeof SuppressedError&&SuppressedError;class Ft{constructor(e){vt.set(this,void 0),bt.set(this,void 0),$t.set(this,void 0),Ot(this,bt,e,"f"),Ot(this,vt,Array.from(G(e)),"f"),Ot(this,$t,Je.autoDetectFormat(e),"f")}get toTomlString(){return Ut(this,bt,"f")}get toJsObject(){return Lt(ft(Ut(this,vt,"f")))}get ast(){return Ut(this,vt,"f")}patch(e,t){const n=Ye(t,Ut(this,$t,"f")),{tomlString:r,document:o}=At(Ut(this,vt,"f"),e,n);Ot(this,vt,o.items,"f"),Ot(this,bt,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Ut(this,$t,"f").newLine),n=He(e),r=e.split(n);let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];)o++;let i=0;if(o<t.length&&o<r.length){const e=t[o],n=r[o];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){i=t;break}}let a=o+1;const{truncatedAst:l,lastEndPosition:s}=function(e,t,n){const r={line:t,column:n},o=[];let i=null;for(const t of e){const e=Dt(t.loc.end,r)<0,n=Dt(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}o.push(t),i=t.loc.end}return{truncatedAst:o,lastEndPosition:i}}(Ut(this,vt,"f"),a,i),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 d=f.join(Ut(this,$t,"f").newLine);Ot(this,vt,Array.from(function*(e,t){for(const t of e)yield t;const n=new F(C(t));for(;!n.next().done;){const e=ae(n,t);for(const t of e)yield t}}(l,d)),"f"),Ot(this,bt,e,"f"),Ot(this,$t,Je.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(Ot(this,vt,Array.from(G(e)),"f"),Ot(this,bt,e,"f"),Ot(this,$t,Je.autoDetectFormat(e),"f"))}}function Lt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Lt);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=Lt(r);return t}return e}function Mt(e){return ft(G(e),e)}function Kt(e,t){const n=Ye(t,Je.default());return lt(nt(e,n).items,n)}vt=new WeakMap,bt=new WeakMap,$t=new WeakMap;export{Ft as TomlDocument,Je as TomlFormat,Mt as parse,Et as patch,Kt as stringify};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decimalturn/toml-patch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"contributors": [
|
|
5
5
|
"Tim Hall <tim.hall.engr@gmail.com>",
|
|
6
6
|
"Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"specs": "jest --config specs.config.cjs",
|
|
43
43
|
"benchmark": "npm-run-all2 bench:*",
|
|
44
44
|
"benchmark:example": "npm-run-all2 \"bench:* -- --example\"",
|
|
45
|
-
"bench:parse": "node benchmark/parse-benchmark.
|
|
46
|
-
"bench:stringify": "node benchmark/stringify-benchmark.
|
|
45
|
+
"bench:parse": "node benchmark/parse-benchmark.mjs",
|
|
46
|
+
"bench:stringify": "node benchmark/stringify-benchmark.mjs",
|
|
47
|
+
"profile": "node benchmark/profile.mjs",
|
|
47
48
|
"build": "rimraf dist && rollup -c",
|
|
48
49
|
"prepublishOnly": "npm run build"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@0.
|
|
52
|
+
"@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@1.0.0",
|
|
52
53
|
"@rollup/plugin-terser": "^0.4.4",
|
|
53
54
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
54
55
|
"@types/dedent": "^0.7.2",
|