@decimalturn/toml-patch 0.7.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 +158 -0
- package/README.md +6 -12
- package/dist/toml-patch.d.ts +1 -1
- package/dist/toml-patch.js +2 -0
- package/package.json +19 -21
- package/dist/toml-patch.cjs.min.js +0 -3
- package/dist/toml-patch.cjs.min.js.map +0 -1
- package/dist/toml-patch.es.js +0 -5232
- package/dist/toml-patch.umd.min.js +0 -3
- package/dist/toml-patch.umd.min.js.map +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v0.7.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TOML={})}(this,(function(e){"use strict";var t,n;function r(e){return e.type===t.Document}function o(e){return e.type===t.Table}function i(e){return e.type===t.TableArray}function l(e){return e.type===t.KeyValue}function a(e){return e.type===t.String}function s(e){return e.type===t.DateTime}function c(e){return e.type===t.InlineArray}function u(e){return e.type===t.InlineItem}function f(e){return e.type===t.InlineTable}function d(e){return e.type===t.Comment}function m(e){return r(e)||o(e)||i(e)||f(e)||c(e)}function h(e){return function(e){return e.type===t.TableKey}(e)||function(e){return e.type===t.TableArrayKey}(e)||u(e)}!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"}(t||(t={}));class p{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return w();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?w():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}function w(){return{value:void 0,done:!0}}function g(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function y(e,t){const n=Array.isArray(e)?e:v(e),r=n.findIndex((e=>e>=t))+1;return{line:r,column:t-(n[r-2]+1||0)}}function v(e){const t=[];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 b(e){return{line:e.line,column:e.column}}function $(e){return{start:b(e.start),end:b(e.end)}}class T extends Error{constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=v(e),r=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"}(n||(n={}));const S=/\s/,I='"',k="'",x=/[\w,\d,\",\',\+,\-,\_]/;function*E(e){const t=new p("string"==typeof(r=e)?function*(e){for(let t=0;t<e.length;t++)yield e[t]}(r):r[Symbol.iterator]());var r;t.next();const o=function(e){const t=v(e);return(e,n)=>({start:y(t,e),end:y(t,n)})}(e);for(;!t.done;){const r=t.value.charCodeAt(0);if((r<=31||127===r)&&9!==r&&13!==r&&10!==r)throw new T(e,y(e,t.index),`Control character 0x${r.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);if("\r"===t.value){const n=t.peek();if(n.done||"\n"!==n.value)throw new T(e,y(e,t.index),"Invalid standalone CR (\\r); CR must be part of a CRLF sequence")}if(S.test(t.value));else if("["===t.value||"]"===t.value)yield A(t,o,n.Bracket);else if("{"===t.value||"}"===t.value)yield A(t,o,n.Curly);else if("="===t.value)yield A(t,o,n.Equal);else if(","===t.value)yield A(t,o,n.Comma);else if("."===t.value)yield A(t,o,n.Dot);else if("#"===t.value)yield C(t,o,e);else{const n=D(e,t.index,k)||D(e,t.index,I);n?yield _(t,o,n,e):yield O(t,o,e)}t.next()}}function A(e,t,n){return{type:n,raw:e.value,loc:t(e.index,e.index+1)}}function C(e,t,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 T(r,y(r,e.index),`Control character 0x${t.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);i+=e.value}return{type:n.Comment,raw:i,loc:t(o,e.index+1)}}function _(e,t,r,o){const i=e.index,l=r+r+r;let a=l;for(e.next(),e.next(),e.next();!e.done;){if(D(o,e.index,r)){let t=3;for(;o[e.index+t]===r;)t++;if(t>=6)throw new T(o,y(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 T(o,y(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===I?"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 T(o,y(o,e.index),a)}a+=e.value,e.next()}if(e.done){if(r===I){const t=o.slice(0,e.index);if(/\\"+$/.test(t))throw new T(o,y(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 T(o,y(o,e.index),`Expected close of multiline string with ${l}, reached end of file`)}return a+=l,e.next(),e.next(),{type:n.Literal,raw:a,loc:t(i,e.index+1)}}function O(e,t,r){if(!x.test(e.value))throw new T(r,y(r,e.index),`Unsupported character "${e.value}". Expected ALPHANUMERIC, ", ', +, -, or _`);const o=e.index;let i=e.value,l=e.value===I,a=e.value===k;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 T(r,y(r,e.index),a)}}if(e.value===I&&(l=!l),e.value!==k||l||(a=!a),i+=e.value,e.peek().done)break;let t=e.peek().value;l&&"\\"===e.value&&(t===I?(i+=I,e.next()):"\\"===t&&(i+="\\",e.next()))}if(l||a)throw new T(r,y(r,o),`Expected close of string with ${l?I:k}`);return{type:n.Literal,raw:i,loc:t(o,e.index+1)}}function D(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===k)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 F(){return Object.create(null)}function L(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function M(e){return"[object Date]"===Object.prototype.toString.call(e)}function K(e){return e&&"object"==typeof e&&!M(e)&&!Array.isArray(e)}function N(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function j(e,...t){return t.reduce(((e,t)=>t(e)),e)}function Z(e){if(K(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${Z(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(Z).join(",")}]`:JSON.stringify(e)}function W(e,t){const n=e.length,r=t.length;e.length=n+r;for(let o=0;o<r;o++)e[n+o]=t[o]}function z(e){return e.startsWith('"""')||e.startsWith("'''")}const B=/\r\n/g,q=/\n/g,V=/^(\r\n|\n)/,P=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function R(e){return e.startsWith("'''")?j(X(e,3),G):e.startsWith(k)?X(e,1):e.startsWith('"""')?j(X(e,3),G,ee,Q,H,Y):e.startsWith(I)?j(X(e,1),Y):e}function H(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 J(e,t){let n=0;for(let r=t-1;r>=0&&"\\"===e[r];r--)n++;return n%2!=0}function Y(e){const t=/\\(.)/g;let n;for(;null!==(n=t.exec(e));){if(J(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(J(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(J(i,n))return e;const r=parseInt(t,16),o=String.fromCharCode(r);return r<32||34===r||92===r?X(JSON.stringify(o),1):o}));const a=l;l=a.replace(/\\e/g,((e,t)=>J(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 X(JSON.stringify(n),1)})),c=s.replace(/\t/g,"\\t");return JSON.parse(`"${c}"`)}function X(e,t){return e.slice(t,e.length-t)}function G(e){return e.replace(V,"")}function Q(e){return e.replace(B,"\\r\\n").replace(q,"\\n")}function ee(e){return e.replace(P,((e,t)=>e.replace(t,"")))}class te{static createDateWithOriginalFormat(e,t){if(te.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof ie)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new oe(t,!1)}const t=e.toISOString().split("T")[0];return new ne(t)}if(te.IS_TIME_ONLY.test(t)){if(e instanceof re)return e;{const n=t.match(/\.(\d+)\s*$/),r=e.toISOString();if(r&&r.includes("T")){let 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 re(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 re(a,t)}}}if(te.IS_LOCAL_DATETIME_T.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","");if(n){const t=n[1].length,[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 oe(r,!1,t)}if(te.IS_LOCAL_DATETIME_SPACE.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","").replace("T"," ");if(n){const t=n[1].length,[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 oe(r,!0,t)}if(te.IS_OFFSET_DATETIME_T.test(t)||te.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),r=n?"z"===n[1]?"Z":n[1]:"Z",o=te.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 ie(`${c}-${u}-${f}${w}${g}${r}`,o)}return e}}te.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,te.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,te.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,te.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,te.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,te.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,te.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,te.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class ne extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class re extends Date{constructor(e,t){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 oe 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 ie 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 le=te,ae="true",se=/e/i,ce=/\_/g,ue=/^[+\-]?inf$/,fe=/^[+\-]?nan$/,de=/^[+\-]?0x/i,me=/^[+\-]?0o/i,he=/^[+\-]?0b/i;function*pe(e){const t=new p(E(e));for(;!t.next().done;){const n=Se(t,e);for(const e of n)yield e}}function we(e){return{type:t.Comment,loc:e.value.loc,raw:e.value.raw}}function ge(e,r){const o=e.peek().done||e.peek().value.type!==n.Bracket?t.Table:t.TableArray,i=o===t.Table;if(i&&"["!==e.value.raw)throw new T(r,e.value.loc.start,`Expected table opening "[", found ${e.value.raw}`);if(!i){const t=e.peek();if(t.done)throw new T(r,e.value.loc.start,'Expected second "[" for array of tables opening, found end of input');if("["!==e.value.raw||"["!==t.value.raw)throw new T(r,e.value.loc.start,`Expected array of tables opening "[[", found ${e.value.raw+t.value.raw}`);const n=e.value,o=t.value;if(n.loc.end.line!==o.loc.start.line||n.loc.end.column!==o.loc.start.column)throw new T(r,n.loc.start,"Array of tables opening brackets must be immediately adjacent with no whitespace: [[table]]")}const l=i?{type:t.TableKey,loc:e.value.loc}:{type:t.TableArrayKey,loc:e.value.loc};if(e.next(),o===t.TableArray&&e.next(),e.done)throw new T(r,l.loc.start,"Expected table key, reached end of file");if(e.value.type===n.Bracket&&"]"===e.value.raw)throw new T(r,e.value.loc.start,o===t.TableArray?"Array of tables header [[]] requires a table name":"Table header [] requires a table name");const a=e.value.raw;if(a.startsWith('"""')||a.startsWith("'''"))throw new T(r,e.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(a.startsWith('"')||a.startsWith("'")))for(let t=0;t<a.length;t++){const n=a[t];if(!/[A-Za-z0-9_-]/.test(n))throw new T(r,{line:e.value.loc.start.line,column:e.value.loc.start.column+t},`Invalid character '${n}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}let s;try{s=[R(e.value.raw)]}catch(t){const n=t;throw new T(r,e.value.loc.start,n.message)}for(l.item={type:t.Key,loc:$(e.value.loc),raw:e.value.raw,value:s};!e.peek().done&&e.peek().value.type===n.Dot;){e.next();const t=e.value;e.next();const n=e.value.raw;if(!(n.startsWith('"')||n.startsWith("'")))for(let t=0;t<n.length;t++){const o=n[t];if(!/[A-Za-z0-9_-]/.test(o))throw new T(r,{line:e.value.loc.start.line,column:e.value.loc.start.column+t},`Invalid character '${o}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}const o=" ".repeat(t.loc.start.column-l.item.loc.end.column),i=" ".repeat(e.value.loc.start.column-t.loc.end.column);l.item.loc.end=e.value.loc.end,l.item.raw+=`${o}.${i}${e.value.raw}`;try{l.item.value.push(R(e.value.raw))}catch(t){const n=t;throw new T(r,e.value.loc.start,n.message)}}if(e.next(),!e.done){const t=l.loc.start.line;if(e.value.loc.start.line!==t)throw new T(r,e.value.loc.start,i?`Table header must not contain newlines. Expected closing ']' on line ${t}, found on line ${e.value.loc.start.line}`:`Unclosed array of tables header: expected closing ']]' on line ${t}, found newline`)}if(i&&(e.done||"]"!==e.value.raw))throw new T(r,e.done?l.item.loc.end:e.value.loc.start,`Expected table closing "]", found ${e.done?"end of file":e.value.raw}`);if(!i&&(e.done||e.peek().done||"]"!==e.value.raw||"]"!==e.peek().value.raw))throw new T(r,e.done||e.peek().done?l.item.loc.end:e.value.loc.start,`Expected array of tables closing "]]", found ${e.done||e.peek().done?"end of file":e.value.raw+e.peek().value.raw}`);if(!i){const t=e.value,n=e.peek().value;if(t.loc.end.line!==n.loc.start.line||t.loc.end.column!==n.loc.start.column)throw new T(r,t.loc.start,"Array of tables closing brackets must be immediately adjacent with no whitespace: ]]")}if(i||e.next(),l.loc.end=e.value.loc.end,!e.peek().done){const t=e.peek().value;if(t.loc.start.line===l.loc.end.line&&t.type!==n.Comment)throw new T(r,t.loc.start,`Unexpected content after ${i?"table":"array of tables"} header`)}let c=[];for(;!e.peek().done&&e.peek().value.type!==n.Bracket;)e.next(),W(c,Se(e,r));return{type:i?t.Table:t.TableArray,loc:{start:b(l.loc.start),end:b(c.length?c[c.length-1].loc.end:l.loc.end)},key:l,items:c}}function ye(e,n){let r;try{r=R(e.value.raw)}catch(t){const r=t;throw new T(n,e.value.loc.start,r.message)}return{type:t.String,loc:e.value.loc,raw:e.value.raw,value:r}}function ve(e){return{type:t.Boolean,loc:e.value.loc,value:e.value.raw===ae}}function be(e,r){let o,i=e.value.loc,l=e.value.raw;if(!e.peek().done&&e.peek().value.type===n.Literal&&le.IS_FULL_DATE.test(l)&&le.IS_FULL_TIME.test(e.peek().value.raw)){const t=i.start;e.next(),i={start:t,end:e.value.loc.end},l+=` ${e.value.raw}`}if(!e.peek().done&&e.peek().value.type===n.Dot){const t=i.start;if(e.next(),e.peek().done||e.peek().value.type!==n.Literal)throw new T(r,e.value.loc.end,"Expected fractional value for DateTime");e.next(),i={start:t,end:e.value.loc.end},l+=`.${e.value.raw}`}if(function(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new T(t,n,`Invalid datetime "${e}": fractional seconds must have at least one digit after decimal point`);if(/[+-]$/.test(e))throw new T(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(t,n,`Invalid timezone offset "${e}": must use colon separator (e.g., +09:09)`);if(2!==r.length)throw new T(t,n,`Invalid timezone offset "${e}": hour must be exactly 2 digits`);if(!l||0===l.length)throw new T(t,n,`Invalid timezone offset "${e}": minute component is required`);if(2!==l.length)throw new T(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(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(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(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(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(t,n,`Invalid datetime "${e}": missing separator 'T' or space between date and time`);throw new T(t,n,`Invalid datetime "${e}"`)}const l=e.match(/^(\d+)-/);if(l&&4!==l[1].length)throw new T(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(t,n,`Invalid date "${e}": month must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new T(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(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new T(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(i&&2!==i.length)throw new T(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(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new T(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(i&&2!==i.length)throw new T(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(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(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(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(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(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(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(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(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(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}}(l,r,i.start),le.IS_FULL_DATE.test(l))o=le.IS_DATE_ONLY.test(l)?new ne(l):le.IS_LOCAL_DATETIME_T.test(l)?new oe(l,!1):le.IS_LOCAL_DATETIME_SPACE.test(l)?new oe(l,!0):le.IS_OFFSET_DATETIME_T.test(l)?new ie(l,!1):le.IS_OFFSET_DATETIME_SPACE.test(l)?new ie(l,!0):new Date(l.replace(" ","T"));else if(le.IS_TIME_ONLY.test(l))o=new re(l,l);else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${l}`)}return{type:t.DateTime,loc:i,raw:l,value:o}}function $e(e,r){let o,i=e.value.loc,l=e.value.raw;if(ue.test(l))o=l.startsWith("-")?-1/0:1/0;else if(fe.test(l))o=NaN;else if(e.peek().done||e.peek().value.type!==n.Dot){if(/_$/.test(l))throw new T(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(l))throw new T(r,i.start,"Leading underscore is not allowed");if(/__/.test(l))throw new T(r,i.start,"Consecutive underscores are not allowed");if(/[eE][+\-]?$/.test(l))throw new T(r,i.start,`Invalid float "${l}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(l))throw new T(r,i.start,`Invalid float "${l}": decimal point not allowed in exponent`);if(/_[eE]/.test(l))throw new T(r,i.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(l))throw new T(r,i.start,"Underscore at start of exponent is not allowed");if(!e.peek().done&&e.peek().value.type===n.Dot)throw new T(r,e.peek().value.loc.start,`Invalid float "${l}.": cannot have decimal point after exponent`);const t=l.replace(ce,"");if(/^[+\-]?0\d/.test(t)&&!de.test(l)&&!me.test(l)&&!he.test(l))throw new T(r,i.start,"Leading zeros are not allowed in the integer part of a float");o=Number(l.replace(ce,""))}else{const t=i.start;{if(se.test(l)&&!de.test(l))throw new T(r,i.start,`Invalid float "${l}": cannot have decimal point after exponent`);const e=l,t=e.replace(ce,"");if(/^[+\-]?0\d/.test(t)&&!de.test(e)&&!me.test(e)&&!he.test(e))throw new T(r,i.start,"Leading zeros are not allowed in the integer part of a float");const n=e.replace(/^[+\-]/,"");if(""===n||"_"===n)throw new T(r,i.start,"Invalid float: decimal point must be preceded by at least one digit");if(/_$/.test(e))throw new T(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(e))throw new T(r,i.start,"Leading underscore is not allowed");if(/__/.test(e))throw new T(r,i.start,"Consecutive underscores are not allowed")}if(e.next(),e.peek().done||e.peek().value.type!==n.Literal)throw new T(r,e.value.loc.end,"Expected fraction value for Float");e.next(),l+=`.${e.value.raw}`,i={start:t,end:e.value.loc.end};{const t=e.value.raw;if(!/^\d/.test(t))throw new T(r,e.value.loc.start,`Invalid float: fractional part must start with a digit, found "${t}"`);if(/^_/.test(t))throw new T(r,e.value.loc.start,"Underscore after decimal point is not allowed");if(/_$/.test(t))throw new T(r,e.value.loc.start,"Trailing underscore in fractional part is not allowed");if(/_[eE]/.test(t))throw new T(r,e.value.loc.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(t))throw new T(r,e.value.loc.start,"Underscore at start of exponent is not allowed");if(/[eE][+\-]?$/.test(t))throw new T(r,e.value.loc.start,`Invalid float "${l}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(t))throw new T(r,e.value.loc.start,`Invalid float "${l}": decimal point not allowed in exponent`)}o=Number(l.replace(ce,""))}if(Number.isNaN(o)&&!fe.test(l))throw new T(r,i.start,`Invalid float "${l}"`);return{type:t.Float,loc:i,raw:l,value:o}}function Te(e,n){const r=e.value.raw,o=e.value.loc;if(/^\d{1,}-\d{1,}/.test(r)||/^\d{1,}:\d{1,}/.test(r)||/^\d{6}-\d{2}$/.test(r))throw new T(n,o.start,`Invalid integer "${r}"`);{if("-0"===r||"+0"===r)return{type:t.Integer,loc:o,raw:r,value:0};if(/^[+\-]{2,}/.test(r))throw new T(n,o.start,"Double sign is not allowed in integers");const e=r.replace(/_/g,"");if(/^[+\-]?0\d/.test(e)&&!de.test(r)&&!me.test(r)&&!he.test(r))throw new T(n,o.start,"Leading zeros are not allowed in decimal integers");if(/_$/.test(r))throw new T(n,o.start,"Underscores in numbers must be surrounded by digits");if(/^[+\-]?_/.test(r))throw new T(n,o.start,"Underscores in numbers must be surrounded by digits");if(/__/.test(r))throw new T(n,o.start,"Consecutive underscores in numbers are not allowed")}let i,l=10;if(de.test(r)){if(l=16,/^[+\-]?0X/.test(r))throw new T(n,o.start,'Hexadecimal prefix must be lowercase "0x"');if(/^[+\-]?0x_/.test(r))throw new T(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0x/i,""),!i||"_"===i||/^_/.test(i))throw new T(n,o.start,"Incomplete hexadecimal number");const e=i.replace(/_/g,"");if(!/^[0-9a-fA-F]+$/.test(e))throw new T(n,o.start,"Invalid hexadecimal digits");if(/^[+\-]/.test(r))throw new T(n,o.start,"Hexadecimal numbers cannot have a sign prefix")}else if(me.test(r)){if(l=8,/^[+\-]?0O/.test(r))throw new T(n,o.start,'Octal prefix must be lowercase "0o"');if(/^[+\-]?0o_/.test(r))throw new T(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0o/i,""),!i||"_"===i||/^_/.test(i))throw new T(n,o.start,"Incomplete octal number");const e=i.replace(/_/g,"");if(!/^[0-7]+$/.test(e))throw new T(n,o.start,"Invalid octal digits (must be 0-7)");if(/^[+\-]/.test(r))throw new T(n,o.start,"Octal numbers cannot have a sign prefix")}else if(he.test(r)){if(l=2,/^[+\-]?0B/.test(r))throw new T(n,o.start,'Binary prefix must be lowercase "0b"');if(/^[+\-]?0b_/.test(r))throw new T(n,o.start,"Underscores in numbers must be surrounded by digits");if(i=r.replace(/^[+\-]?0b/i,""),!i||"_"===i||/^_/.test(i))throw new T(n,o.start,"Incomplete binary number");const e=i.replace(/_/g,"");if(!/^[01]+$/.test(e))throw new T(n,o.start,"Invalid binary digits (must be 0 or 1)");if(/^[+\-]/.test(r))throw new T(n,o.start,"Binary numbers cannot have a sign prefix")}const a=parseInt(r.replace(ce,"").replace(me,"").replace(he,""),l);if(Number.isNaN(a))throw new T(n,o.start,`Invalid integer "${r}"`);return{type:t.Integer,loc:o,raw:r,value:a}}function Se(e,r){if(e.value.type===n.Comment)return[we(e)];if(e.value.type===n.Bracket)return[ge(e,r)];if(e.value.type===n.Literal)return function(e,r){const o=e.value.raw;if(o.endsWith(":"))throw new T(r,{line:e.value.loc.start.line,column:e.value.loc.start.column+[...o].length-1},"Use '=' to separate keys and values, not ':'");if(o.startsWith('"""')||o.startsWith("'''"))throw new T(r,e.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!o.startsWith('"')&&!o.startsWith("'"))for(let t=0;t<o.length;t++){const n=o[t];if(!/[A-Za-z0-9_-]/.test(n))throw new T(r,{line:e.value.loc.start.line,column:e.value.loc.start.column+t},`Invalid character '${n}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}let i;try{i=[R(e.value.raw)]}catch(t){const n=t;throw new T(r,e.value.loc.start,n.message)}const l={type:t.Key,loc:$(e.value.loc),raw:e.value.raw,value:i};for(;!e.peek().done&&e.peek().value.type===n.Dot;){e.next(),e.next();const t=e.value.raw;if(t.startsWith('"""')||t.startsWith("'''"))throw new T(r,e.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(t.startsWith('"')||t.startsWith("'")))for(let n=0;n<t.length;n++){const o=t[n];if(!/[A-Za-z0-9_-]/.test(o))throw new T(r,{line:e.value.loc.start.line,column:e.value.loc.start.column+n},`Invalid character '${o}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`)}l.loc.end=e.value.loc.end,l.raw+=`.${e.value.raw}`;try{l.value.push(R(e.value.raw))}catch(t){const n=t;throw new T(r,e.value.loc.start,n.message)}}if(e.next(),!e.done&&e.value.loc.start.line!==l.loc.end.line)throw new T(r,e.value.loc.start,'Expected "=" for key-value on the same line as the key');if(e.done||e.value.type!==n.Equal){if(!e.done&&":"===e.value.raw)throw new T(r,e.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new T(r,e.done?l.loc.end:e.value.loc.start,'Expected "=" for key-value')}const a=e.value.loc.start.column,s=e.value.loc.start.line;if(e.next(),e.done)throw new T(r,l.loc.start,"Expected value for key-value, reached end of file");if(e.value.loc.start.line!==s)throw new T(r,e.value.loc.start,"Expected value on the same line as the '=' sign");if(e.done)throw new T(r,l.loc.start,"Expected value for key-value");const c=Ie(e,r),u=c[0],f=c.slice(1);if(!e.peek().done){const o=e.peek().value;if(o.type===n.Dot&&o.loc.start.line===u.loc.end.line&&(u.type===t.Float||u.type===t.Integer))throw new T(r,o.loc.start,"Invalid number: multiple decimal points not allowed");if((o.type===n.Literal||o.type===n.Bracket)&&o.loc.start.line===u.loc.end.line)throw new T(r,o.loc.start,"Key/value pairs must be separated by a newline")}return[{type:t.KeyValue,key:l,value:u,loc:{start:b(l.loc.start),end:b(u.loc.end)},equals:a},...f]}(e,r);throw e.value.type===n.Equal?new T(r,e.value.loc.start,"Missing key before '='"):new T(r,e.value.loc.start,`Unexpected token "${e.value.type}". Expected Comment, Bracket, or String`)}function Ie(e,r){if(e.value.type===n.Literal){const t=e.value.raw;return t[0]===I||t[0]===k?[ye(e,r)]:t===ae||"false"===t?[ve(e)]:/^\d/.test(t)&&(/^\d{1,}-\d{1,}/.test(t)||/^\d{1,}:\d{1,}/.test(t))?[be(e,r)]:!e.peek().done&&e.peek().value.type===n.Dot||ue.test(t)||fe.test(t)||se.test(t)&&!de.test(t)?[$e(e,r)]:[Te(e,r)]}if(e.value.type===n.Curly){const[o,i]=function(e,r){if("{"!==e.value.raw)throw new T(r,e.value.loc.start,'Expected "{" for inline table');const o={type:t.InlineTable,loc:$(e.value.loc),items:[]},i=[];e.next();for(;!e.done&&(e.value.type!==n.Curly||"}"!==e.value.raw);){if(e.value.type===n.Comment){i.push(we(e)),e.next();continue}if(e.value.type===n.Comma){const t=o.items[o.items.length-1];if(!t)throw new T(r,e.value.loc.start,'Found "," without previous value in inline table');if(t.comma)throw new T(r,e.value.loc.start,"Found consecutive commas in inline table (double comma is not allowed)");t.comma=!0,t.loc.end=e.value.loc.start,e.next();continue}const l=o.items[o.items.length-1];if(l&&!l.comma)throw new T(r,e.value.loc.start,"Missing comma between inline table items");const a=Se(e,r),s=a[0],c=a.slice(1);s.type===t.KeyValue&&(o.items.push({type:t.InlineItem,loc:$(s.loc),item:s,comma:!1}),W(i,c)),e.next()}if(e.done||e.value.type!==n.Curly||"}"!==e.value.raw)throw new T(r,e.done?o.loc.start:e.value.loc.start,'Expected "}"');return o.loc.end=e.value.loc.end,[o,i]}(e,r);return[o,...i]}if(e.value.type===n.Bracket){const[o,i]=function(e,r){if("["!==e.value.raw)throw new T(r,e.value.loc.start,'Expected "[" for inline array');const o={type:t.InlineArray,loc:$(e.value.loc),items:[]},i=[];e.next();for(;!e.done&&(e.value.type!==n.Bracket||"]"!==e.value.raw);){if(e.value.type===n.Comma){const t=o.items[o.items.length-1];if(!t)throw new T(r,e.value.loc.start,'Found "," without previous value for inline array');if(t.comma)throw new T(r,e.value.loc.start,"Found consecutive commas in array (double comma is not allowed)");t.comma=!0,t.loc.end=e.value.loc.start}else if(e.value.type===n.Comment)i.push(we(e));else{const n=o.items[o.items.length-1];if(n&&!n.comma)throw new T(r,e.value.loc.start,"Missing comma between array elements");const l=Ie(e,r),a=l[0],s=l.slice(1);o.items.push({type:t.InlineItem,loc:$(a.loc),item:a,comma:!1}),W(i,s)}e.next()}if(e.done||e.value.type!==n.Bracket||"]"!==e.value.raw)throw new T(r,e.done?o.loc.start:e.value.loc.start,'Expected "]"');return o.loc.end=e.value.loc.end,[o,i]}(e,r);return[o,...i]}throw e.value.type===n.Dot?new T(r,e.value.loc.start,"Invalid number: cannot start with a dot. Numbers must start with a digit"):new T(r,e.value.loc.start,"Unrecognized token type")}function ke(e,n){var r;function o(e,t){for(const n of e)i(n,t)}function i(e,r){const l=n[e.type];switch(l&&"function"==typeof l&&l(e,r),l&&l.enter&&l.enter(e,r),e.type){case t.Document:o(e.items,e);break;case t.Table:i(e.key,e),o(e.items,e);break;case t.TableKey:i(e.item,e);break;case t.TableArray:i(e.key,e),o(e.items,e);break;case t.TableArrayKey:i(e.item,e);break;case t.KeyValue:i(e.key,e),i(e.value,e);break;case t.InlineArray:o(e.items,e);break;case t.InlineItem:i(e.item,e);break;case t.InlineTable:o(e.items,e);break;case t.Key:case t.String:case t.Integer:case t.Float:case t.Boolean:case t.DateTime:case t.Comment:break;default:throw new Error(`Unrecognized node type "${e.type}"`)}l&&l.exit&&l.exit(e,r)}null!=(r=e)&&"function"==typeof r[Symbol.iterator]?o(e,null):i(e,null)}const xe=new WeakMap,Ee=e=>(xe.has(e)||xe.set(e,new WeakMap),xe.get(e)),Ae=new WeakMap,Ce=e=>(Ae.has(e)||Ae.set(e,new WeakMap),Ae.get(e));function _e(e,t,n,r){if(m(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.items.splice(e,1,r)}else if(l(t)&&f(t.value)&&!f(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(h(t))t.item=r;else{if(!l(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}Ke(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const o=g(n.loc),i=g(r.loc);Ne({lines:i.lines-o.lines,columns:i.columns-o.columns},Ce(e),r,n)}function Oe(e,t,n,a,s){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let h,p;a=null!=a&&"number"==typeof a?a:t.items.length,c(t)||f(t)?({shift:h,offset:p}=function(e,t,n){if(!u(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=c(e)&&function(e){if(!e.items.length)return!1;return g(e.loc).lines>e.items.length}(e),s=o&&!0===t.comma;return De(e,t,n,{useNewLine:a,hasCommaHandling:!0,isLastElement:o,hasSeparatingCommaBefore:i,hasSeparatingCommaAfter:l,hasTrailingComma:s})}(t,n,a)):s&&r(t)?({shift:h,offset:p}=function(e,t,n){const r=De(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,n,a)):({shift:h,offset:p}=function(e,t,n){if(a=t,!(l(a)||o(a)||i(a)||d(a)))throw new Error(`Incompatible child type "${t.type}"`);var a;const s=e.items[n-1],c=r(e)&&!e.items.length;e.items.splice(n,0,t);const u=s?{line:s.loc.end.line,column:d(s)?e.loc.start.column:s.loc.start.column}:b(e.loc.start),f=o(t)||i(t);let m=0;c||(m=f?2:1);u.line+=m;const h={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},p=g(t.loc),w={lines:p.lines+(m-1),columns:p.columns};return{shift:h,offset:w}}(t,n,a)),Ke(n,h);const w=t.items[a-1],y=w&&Ce(e).get(w);y&&(p.lines+=y.lines,p.columns+=y.columns,Ce(e).delete(w));Ce(e).set(n,p)}function De(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:f=!1}=r,m=n>0?e.items[n-1]:void 0,h=m?{line:m.loc.end.line,column:o?d(m)?e.loc.start.column:m.loc.start.column:m.loc.end.column}:b(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 w={lines:h.line-t.loc.start.line,columns:h.column-t.loc.start.column},y=g(t.loc);if(!a){return{shift:w,offset:{lines:y.lines+(p-1),columns:y.columns}}}let v=0;c&&f&&!u&&s&&(v=-1);return{shift:w,offset:{lines:y.lines+(p-1),columns:y.columns+(c||u?i:0)+(f?1+v:0)}}}function Ue(e,t,n){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let r=t.items.indexOf(n);if(r<0){if(r=t.items.findIndex((e=>h(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=g(n.loc);i&&d(i)&&i.loc.start.line===n.loc.end.line&&(l=g({start:n.loc.start,end:i.loc.end}),i=t.items[r+1],t.items.splice(r,1));const a=o&&u(o)||i&&u(i),s=o&&o.loc.end.line===n.loc.start.line,c=i&&i.loc.start.line===n.loc.end.line,f=a&&(s||c),p={lines:-(l.lines-(f?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 w=o||t,y=o?Ce(e):Ee(e),v=Ce(e),b=y.get(w);b&&(p.lines+=b.lines,p.columns+=b.columns);const $=v.get(n);$&&(p.lines+=$.lines,p.columns+=$.columns),y.set(w,p)}function Fe(e,t,n=!0){if(!n)return;if(!t.items.length)return;Ne({lines:0,columns:1},Ee(e),t);const r=U(t.items);Ne({lines:0,columns:1},Ce(e),r)}function Le(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=U(t.items);r.comma=!0,Ne({lines:0,columns:1},Ce(e),r)}function Me(e){const n=Ee(e),r=Ce(e),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};ke(e,{[t.Document]:a,[t.Table]:a,[t.TableArray]:a,[t.InlineTable]:a,[t.InlineArray]:a,[t.InlineItem]:a,[t.TableKey]:a,[t.TableArrayKey]:a,[t.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},[t.Key]:a,[t.String]:a,[t.Integer]:a,[t.Float]:a,[t.Boolean]:a,[t.DateTime]:a,[t.Comment]:a}),xe.delete(e),Ae.delete(e)}function Ke(e,n,r={}){const{first_line_only:o=!1}=r,i=e.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 ke(e,{[t.Table]:s,[t.TableKey]:s,[t.TableArray]:s,[t.TableArrayKey]:s,[t.KeyValue](e){s(e),e.equals+=a},[t.Key]:s,[t.String]:s,[t.Integer]:s,[t.Float]:s,[t.Boolean]:s,[t.DateTime]:s,[t.InlineArray]:s,[t.InlineItem]:s,[t.InlineTable]:s,[t.Comment]:s}),e}function Ne(e,t,n,r){const o=t.get(r||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function je(){return{type:t.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Ze(e){const n=function(e){const n=qe(e);return{type:t.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:t.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:e,raw:n}}}(e);return{type:t.Table,loc:$(n.loc),key:n,items:[]}}function We(e){const n=function(e){const n=qe(e);return{type:t.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:t.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:e,raw:n}}}(e);return{type:t.TableArray,loc:$(n.loc),key:n,items:[]}}function ze(e,n){const r=function(e){const n=qe(e);return{type:t.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e),{column:o}=r.loc.end,i=o+1;return Ke(n,{lines:0,columns:o+3-n.loc.start.column},{first_line_only:!0}),{type:t.KeyValue,loc:{start:b(r.loc.start),end:b(n.loc.end)},key:r,equals:i,value:n}}const Be=/^[\w-]+$/;function qe(e){return e.map((e=>Be.test(e)?e:JSON.stringify(e))).join(".")}function Ve(e,n){let r,o;if(n&&z(n)){let t=n.startsWith("'''");t&&e.includes("'''")&&(t=!1);const o=t?"'''":'"""',i=n.includes("\r\n")?"\r\n":"\n",l=n.startsWith(`${o}${i}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!t;let a;a=t?e:e.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(e);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:t.String,loc:{start:{line:1,column:0},end:o},raw:r,value:e}}function Pe(e){return{type:t.InlineItem,loc:$(e.loc),item:e,comma:!1}}const Re=!1,He=!0,Je=!1,Ye=!1;function Xe(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=Xe(n,t);if(null!==e)return e;if(n.item){const e=Xe(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=Xe(e[n],t);if(null!==r)return r}return null}function Ge(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return Qe(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return Qe(e.items);if("KeyValue"===e.type&&e.value)return Ge(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=Ge(t);if(null!==e)return e}return null}function Qe(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 et(e){if(!c(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function tt(e){if(!f(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function nt(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function rt(e,t){var n,r,o,i,l,a;if(e){if(e instanceof ot)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 ot(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 ot{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:Re,this.bracketSpacing=null!=r?r:He,this.inlineTableStart=null!=o?o:1,this.truncateZeroTimeInDates=null!=i?i:Je,this.useTabsForIndentation=null!=l?l:Ye}static default(){return new ot("\n",1,Re,He,1,Je,Ye)}static autoDetectFormat(e){const t=ot.default();t.newLine=nt(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=pe(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=Ge(e);if(null!==t)return t}return Re}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=Xe(t,e);if(null!==n)return n}return He}(e,r)}catch(e){t.trailingComma=Re,t.bracketSpacing=He}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=Je,t}}function it(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!l(e))return!1;const n=f(e.value),r=c(e.value)&&e.value.items.length&&f(e.value.items[0].item);if(n||r){const n=st(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{Ue(e,e,t),f(t.value)?Oe(e,e,lt(t)):function(e){const t=je();for(const n of e.value.items){const r=We(e.key.value);Oe(t,t,r);for(const e of n.item.items)Oe(t,r,e.item)}return Me(t),t.items}(t).forEach((t=>{Oe(e,e,t)}))})),Me(e),e}function lt(e){const t=Ze(e.key.value);for(const n of e.value.items)Oe(t,t,n.item);return Me(t),t}function at(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 st(e){return Math.max(0,e.length-1)}function ct(e,t,n){var r;for(let o=e.items.length-1;o>=0;o--){const i=e.items[o];if(l(i)&&f(i.value)){const o=[...e.key.item.value,...i.key.value];if(st(o)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=Ze(o);for(const e of i.value.items)Oe(r,r,e.item);Ue(e,e,i),at(e),t.push(r),ct(r,t,n)}}}}function ut(e,t=ot.default()){e=function(e){const t=[],n=[];for(const r in e)K(e[r])||Array.isArray(e[r])?n.push(r):t.push(r);const r={};for(let n=0;n<t.length;n++){const 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=mt(e));const n=je();for(const r of ft(e,t))Oe(n,n,r);Me(n);const r=j(n,(e=>it(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(l(r)&&f(r.value)){if(st(r.key.value)<t.inlineTableStart){const o=lt(r);Ue(e,e,r),Oe(e,e,o),ct(o,n,t)}}else"Table"===r.type&&ct(r,n,t);for(const t of n)Oe(e,e,t);return Me(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)),Ke(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(r)}function*ft(e,t){for(const n of Object.keys(e))yield ze([n],dt(e[n],t))}function dt(e,n){if(null==e)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(e)?Ve(e):L(e)?function(e){const n=e.toString();return{type:t.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):function(e){return"number"==typeof e&&(!L(e)||!isFinite(e)||Object.is(e,-0))}(e)?function(e){let n;return n=e===1/0?"inf":e===-1/0?"-inf":Number.isNaN(e)?"nan":Object.is(e,-0)?"-0.0":e.toString(),{type:t.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):function(e){return"boolean"==typeof e}(e)?function(e){return{type:t.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:e?4:5}},value:e}}(e):M(e)?function(e,n){n.truncateZeroTimeInDates&&0===e.getUTCHours()&&0===e.getUTCMinutes()&&0===e.getUTCSeconds()&&0===e.getUTCMilliseconds()&&(e=new ne(e.toISOString().split("T")[0]));const r=e.toISOString();return{type:t.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:r.length}},raw:r,value:e}}(e,n):Array.isArray(e)?function(e,n){const r={type:t.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const t of e){Oe(r,r,Pe(dt(t,n)))}return Fe(r,r,n.bracketSpacing),Le(r,r,n.trailingComma),Me(r),r}(e,n):function(e,n){if(e=mt(e),!K(e))return dt(e,n);const r={type:t.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},o=[...ft(e,n)];for(const e of o){Oe(r,r,Pe(e))}return Fe(r,r,n.bracketSpacing),Le(r,r,n.trailingComma),Me(r),r}(e,n)}function mt(e){return e?M(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const ht=/(\r\n|\n)/g;function pt(e,n){const r=[],o=n.useTabsForIndentation?"\t":" ";if(ke(e,{[t.TableKey](e){const{start:t,end:n}=e.loc;wt(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),wt(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[t.TableArrayKey](e){const{start:t,end:n}=e.loc;wt(r,{start:t,end:{line:t.line,column:t.column+2}},"[[",o),wt(r,{start:{line:n.line,column:n.column-2},end:n},"]]",o)},[t.KeyValue](e){const{start:{line:t}}=e.loc;wt(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=",o)},[t.Key](e){wt(r,e.loc,e.raw,o)},[t.String](e){wt(r,e.loc,e.raw,o)},[t.Integer](e){wt(r,e.loc,e.raw,o)},[t.Float](e){wt(r,e.loc,e.raw,o)},[t.Boolean](e){wt(r,e.loc,e.value.toString(),o)},[t.DateTime](e){wt(r,e.loc,e.raw,o)},[t.InlineArray](e){const{start:t,end:n}=e.loc;wt(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),wt(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[t.InlineTable](e){const{start:t,end:n}=e.loc;wt(r,{start:t,end:{line:t.line,column:t.column+1}},"{",o),wt(r,{start:{line:n.line,column:n.column-1},end:n},"}",o)},[t.InlineItem](e){if(!e.comma)return;const t=e.loc.end;wt(r,{start:t,end:{line:t.line,column:t.column+1}},",",o)},[t.Comment](e){wt(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 wt(e,t,n,r=" "){const o=n.split(ht).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=gt(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 gt(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function yt(e,n,r){for(const o of e.items){const e=o.item,i=n.concat(e.key.value);e.value.type===t.InlineTable&&(r.add(kt(i)),yt(e.value,i,r))}}function vt(e,n=""){const r=F(),o=new Set,i=new Set,l=new Set,a=new Set,s=new Set;let c=r,u=0,f=[];return ke(e,{[t.Table](e){const t=e.key.item.value;try{$t(r,[],t,e.type,{tables:o,table_arrays:i,defined:l,implicit_tables:a,inline_tables:s})}catch(t){const r=t;throw new T(n,e.key.loc.start,r.message)}const u=kt(t);o.add(u),l.add(u),c=Tt(r,t),f=t},[t.TableArray](e){const t=e.key.item.value;try{$t(r,[],t,e.type,{tables:o,table_arrays:i,defined:l,implicit_tables:a,inline_tables:s})}catch(t){const r=t;throw new T(n,e.key.loc.start,r.message)}const u=kt(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=F();return n[U(t)].push(o),o}(r,t),f=t},[t.KeyValue]:{enter(e){if(u>0)return;const r=e.key.value;try{$t(c,f,r,e.type,{tables:o,table_arrays:i,defined:l,implicit_tables:a,inline_tables:s})}catch(t){const r=t;throw new T(n,e.key.loc.start,r.message)}if(r.length>1)for(let e=1;e<r.length;e++){const t=kt(f.concat(r.slice(0,e)));a.add(t),l.add(t)}let d;try{d=bt(e.value)}catch(t){const r=t;throw new T(n,e.value.loc.start,r.message)}if(e.value.type===t.InlineTable){const t=f.concat(r);s.add(kt(t)),yt(e.value,t,s)}(r.length>1?Tt(c,r.slice(0,-1)):c)[U(r)]=d,l.add(kt(f.concat(r)))}},[t.InlineTable]:{enter(){u++},exit(){u--}}}),r}function bt(e){switch(e.type){case t.InlineTable:const n=F(),r=new Set,o=new Map;return e.items.forEach((({item:e})=>{const t=e.key.value,i=bt(e.value),l=kt(t);if(r.has(l))throw new Error(`Duplicate key "${l}" in inline table`);for(let e=1;e<t.length;e++){const n=kt(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=kt(t.slice(0,e));o.has(n)||o.set(n,l)}(t.length>1?Tt(n,t.slice(0,-1)):n)[U(t)]=i})),n;case t.InlineArray:return e.items.map((e=>bt(e.item)));case t.DateTime:case t.String:case t.Integer:case t.Float:case t.Boolean:return e.value;default:throw new Error(`Unrecognized value type "${e.type}"`)}}function $t(e,n,r,o,i){const l=kt(n.concat(r));if(o===t.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=kt(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===t.Table||o===t.TableArray)&&i.inline_tables.has(l))throw new Error(`Invalid key, cannot extend an inline table at ${l}`);if(o===t.Table||o===t.TableArray)for(let e=1;e<r.length;e++){const t=kt(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===t.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=kt(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===t.Table||o===t.TableArray)&&i.implicit_tables.has(l))throw new Error(`Invalid key, a table has already been defined implicitly named ${l}`);if(o===t.KeyValue&&i.implicit_tables.has(l))throw new Error(`Invalid key, a table has already been defined named ${l}`);if(o===t.KeyValue&&r.length>1)for(let e=1;e<=r.length;e++){const t=kt(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 t of r){if(a.push(t),!N(e,t))return;if(It(e[t])){const e=kt(n.concat(a));throw new Error(`Invalid key, a value has already been defined for ${e}`)}const o=kt(n.concat(a));if(Array.isArray(e[t])&&!i.table_arrays.has(o))throw new Error(`Invalid key, cannot add to a static array at ${o}`);const l=s++<r.length-1;e=Array.isArray(e[t])&&l?U(e[t]):e[t]}const c=l;if(e&&o===t.Table&&i.defined.has(c))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(e&&o===t.KeyValue&&1===r.length&&i.defined.has(c)&&!It(e))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(e&&o===t.TableArray&&!i.table_arrays.has(c))throw new Error(`Invalid key, cannot add an array of tables to a table at ${c}`)}function Tt(e,t){const n=St(e,t.slice(0,-1)),r=U(t);return n[r]||(n[r]=F()),n[r]}function St(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=F()),Array.isArray(e[t])?U(e[t]):e[t])),e)}function It(e){return"object"!=typeof e&&!M(e)}function kt(e){return e.join(".")}var xt,Et,At,Ct;function _t(e){return e.type===xt.Remove}function Ot(e,t,n=[]){return e===t||(o=t,M(r=e)&&M(o)&&r.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const o=e.map(Z),i=t.map(Z);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:xt.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 W(r,Ot(e[a],t[a],n.concat(a))),void(o[a]=l);r.push({type:xt.Add,path:n.concat(a)}),o.splice(a,0,l)}));for(let e=i.length;e<o.length;e++)r.push({type:xt.Remove,path:n.concat(e)});return r}(e,t,n):K(e)&&K(t)?function(e,t,n=[]){let r=[];const o=Object.keys(e),i=o.map((t=>Z(e[t]))),l=Object.keys(t),a=l.map((e=>Z(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))W(r,Ot(e[o],t[o],u));else if(s(i[c],a)){const e=l[a.indexOf(i[c])];r.push({type:xt.Rename,path:n,from:o,to:e})}else r.push({type:xt.Remove,path:u})})),l.forEach(((e,t)=>{o.includes(e)||s(a[t],i)||r.push({type:xt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:xt.Edit,path:n}];var r,o}function Dt(e,t){if(!t.length)return u(e)&&l(e.item)?e.item:e;if(l(e))return Dt(e.value,t);const n={};let r;if(m(e)&&e.items.some(((e,a)=>{try{let s=[];if(l(e))s=e.key.value;else if(o(e))s=e.key.item.value;else if(i(e)){s=e.key.item.value;const t=Z(s);n[t]||(n[t]=0);const r=n[t]++;s=s.concat(r)}else u(e)&&l(e.item)?s=e.item.key.value:u(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)))&&(r=u(e)&&l(e.item)?t.length===s.length?e:Dt(e.item.value,t.slice(s.length)):Dt(e,t.slice(s.length)),!0)}catch(e){return!1}})),!r)throw new Error(`Could not find node at path ${t.join(".")}`);return r}function Ut(e,t){try{return Dt(e,t)}catch(e){}}function Ft(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 Lt(e,n,a){const s=[...e],d=vt(s),m={type:t.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:s},p=ut(n,rt(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(_t(n)){let r=t+1;for(;r<e.length;){const o=e[r];if(_t(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}(Ot(d,n));if(0===w.length)return{tomlString:pt(s,a),document:m};const g=function(e,t,n,a){return n.forEach((n=>{if(function(e){return e.type===xt.Add}(n)){const s=Dt(t,n.path),d=n.path.slice(0,-1);let m,h=U(n.path),p=i(s);if(L(h)&&!d.some(L)){const t=Ut(e,d.concat(0));t&&i(t)&&(p=!0)}if(o(s))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=Ft(e,n.path),l(m)&&(m=m.value);if(i(m)||c(m)||r(m)){if(c(m)){const e=et(m);u(s)&&(s.comma=e)}if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&r(m)&&o(s)){const t=Kt(s,e,a);Oe(e,m,s,h);for(const n of t)Oe(e,e,n,void 0)}else Oe(e,m,s,h)}else if(f(m)){const t=tt(m);if(l(s)){const n=Pe(s);n.comma=t,Oe(e,m,n)}else Oe(e,m,s)}else if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&l(s)&&f(s.value)&&o(m)){st([...m.key.item.value,...s.key.value])<a.inlineTableStart?function(e,t,n,r){const o=t.key.item.value,i=[...o,...e.key.value],a=Ze(i);if(f(e.value))for(const t of e.value.items)u(t)&&l(t.item)&&Oe(n,a,t.item,void 0);Oe(n,n,a,void 0),at(t);const s=Kt(a,n,r);for(const e of s)Oe(n,n,e,void 0)}(s,m,e,a):Oe(e,m,s)}else if(0===a.inlineTableStart&&l(s)&&f(s.value)&&r(m))Oe(e,m,s,void 0,!0);else{let t=s;u(s)&&(o(m)||r(m))&&(t=s.item),Oe(e,m,t)}}else if(function(e){return e.type===xt.Edit}(n)){let r,o=Dt(e,n.path),i=Dt(t,n.path);if(l(o)&&l(i))Mt(o.value,i.value),r=o,o=o.value,i=i.value;else if(l(o)&&u(i)&&l(i.item))r=o,o=o.value,i=i.item.value;else if(u(o)&&l(i))r=o,o=o.item;else if(u(o)&&u(i)&&l(o.item)&&l(i.item))Mt(o.item.value,i.item.value),r=o.item,o=o.item.value,i=i.item.value;else if(r=Ft(e,n.path),l(r)){const t=n.path.slice(0,-1),o=Dt(e,t);l(o)&&c(o.value)&&(r=o.value)}_e(e,r,o,i)}else if(_t(n)){let t=Ft(e,n.path);l(t)&&(t=t.value);const r=Dt(e,n.path);Ue(e,t,r)}else if(function(e){return e.type===xt.Move}(n)){let t=Dt(e,n.path);h(t)&&(t=t.item),l(t)&&(t=t.value);const r=t.items[n.from];Ue(e,t,r),Oe(e,t,r,n.to)}else if(function(e){return e.type===xt.Rename}(n)){let r=Dt(e,n.path.concat(n.from)),o=Dt(t,n.path.concat(n.to));h(r)&&(r=r.item),h(o)&&(o=o.item),_e(e,r,r.key,o.key)}})),Me(e),e}(m,p,w,a);return{tomlString:pt(g.items,a),document:g}}function Mt(e,t){if(a(e)&&a(t)&&z(e.raw)){const n=Ve(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(s(e)&&s(t)){const n=e.raw,r=t.value,o=te.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(c(e)&&c(t)){const n=et(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(f(e)&&f(t)){const n=tt(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 i;for(let a=e.items.length-1;a>=0;a--){const s=e.items[a];if(l(s)&&f(s.value)){const c=[...e.key.item.value,...s.key.value];if(st(c)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Ze(c);for(const e of s.value.items)u(e)&&l(e.item)&&Oe(t,n,e.item,void 0);e.items.splice(a,1),at(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"}(xt||(xt={})),"function"==typeof SuppressedError&&SuppressedError;function Wt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Wt);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=Wt(r);return t}return e}Et=new WeakMap,At=new WeakMap,Ct=new WeakMap,e.TomlDocument=class{constructor(e){Et.set(this,void 0),At.set(this,void 0),Ct.set(this,void 0),jt(this,At,e,"f"),jt(this,Et,Array.from(pe(e)),"f"),jt(this,Ct,ot.autoDetectFormat(e),"f")}get toTomlString(){return Nt(this,At,"f")}get toJsObject(){return Wt(vt(Nt(this,Et,"f")))}get ast(){return Nt(this,Et,"f")}patch(e,t){const n=rt(t,Nt(this,Ct,"f")),{tomlString:r,document:o}=Lt(Nt(this,Et,"f"),e,n);jt(this,Et,o.items,"f"),jt(this,At,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Nt(this,Ct,"f").newLine),n=nt(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,Et,"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,Ct,"f").newLine);jt(this,Et,Array.from(function*(e,t){for(const t of e)yield t;const n=new p(E(t));for(;!n.next().done;){const e=Se(n,t);for(const t of e)yield t}}(a,d)),"f"),jt(this,At,e,"f"),jt(this,Ct,ot.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(jt(this,Et,Array.from(pe(e)),"f"),jt(this,At,e,"f"),jt(this,Ct,ot.autoDetectFormat(e),"f"))}},e.TomlFormat=ot,e.parse=function(e){return vt(pe(e),e)},e.patch=function(e,t,n){return Lt(pe(e),t,rt(n,ot.autoDetectFormat(e))).tomlString},e.stringify=function(e,t){const n=rt(t,ot.default());return pt(ut(e,n).items,n)}}));
|
|
3
|
-
//# sourceMappingURL=toml-patch.umd.min.js.map
|