@decimalturn/toml-patch 3.0.5 → 3.1.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/dev/comment-alignment.js +372 -0
  2. package/dist/dev/comment-alignment.js.map +1 -0
  3. package/dist/dev/comment-ownership.js +660 -0
  4. package/dist/dev/comment-ownership.js.map +1 -0
  5. package/dist/dev/cst-source.js +108 -0
  6. package/dist/dev/cst-source.js.map +1 -0
  7. package/dist/dev/cst.js +59 -0
  8. package/dist/dev/cst.js.map +1 -0
  9. package/dist/dev/cursor.js +66 -0
  10. package/dist/dev/cursor.js.map +1 -0
  11. package/dist/dev/date-format.js +196 -0
  12. package/dist/dev/date-format.js.map +1 -0
  13. package/dist/dev/decode-utf8.js +27 -0
  14. package/dist/dev/decode-utf8.js.map +1 -0
  15. package/dist/dev/diff.js +269 -0
  16. package/dist/dev/diff.js.map +1 -0
  17. package/dist/dev/escape-preference.js +144 -0
  18. package/dist/dev/escape-preference.js.map +1 -0
  19. package/dist/dev/find-by-path.js +111 -0
  20. package/dist/dev/find-by-path.js.map +1 -0
  21. package/dist/dev/formatter.js +295 -0
  22. package/dist/dev/formatter.js.map +1 -0
  23. package/dist/dev/generate.js +451 -0
  24. package/dist/dev/generate.js.map +1 -0
  25. package/dist/dev/inline-comma-space.js +13 -0
  26. package/dist/dev/inline-comma-space.js.map +1 -0
  27. package/dist/dev/inline-format.js +106 -0
  28. package/dist/dev/inline-format.js.map +1 -0
  29. package/dist/dev/inline-layout.js +107 -0
  30. package/dist/dev/inline-layout.js.map +1 -0
  31. package/dist/dev/line-ending-backslash.js +320 -0
  32. package/dist/dev/line-ending-backslash.js.map +1 -0
  33. package/dist/dev/location.js +77 -0
  34. package/dist/dev/location.js.map +1 -0
  35. package/dist/dev/parse-error.js +27 -0
  36. package/dist/dev/parse-error.js.map +1 -0
  37. package/dist/dev/parse-js.js +103 -0
  38. package/dist/dev/parse-js.js.map +1 -0
  39. package/dist/dev/parse-string.js +122 -0
  40. package/dist/dev/parse-string.js.map +1 -0
  41. package/dist/dev/parse-toml.js +669 -0
  42. package/dist/dev/parse-toml.js.map +1 -0
  43. package/dist/dev/patch.js +2537 -0
  44. package/dist/dev/patch.js.map +1 -0
  45. package/dist/dev/to-js.js +303 -0
  46. package/dist/dev/to-js.js.map +1 -0
  47. package/dist/dev/to-toml.js +569 -0
  48. package/dist/dev/to-toml.js.map +1 -0
  49. package/dist/dev/tokenizer.js +225 -0
  50. package/dist/dev/tokenizer.js.map +1 -0
  51. package/dist/dev/toml-document.js +215 -0
  52. package/dist/dev/toml-document.js.map +1 -0
  53. package/dist/dev/toml-format.js +476 -0
  54. package/dist/dev/toml-format.js.map +1 -0
  55. package/dist/dev/toml-patch.js +84 -0
  56. package/dist/dev/toml-patch.js.map +1 -0
  57. package/dist/dev/traverse.js +61 -0
  58. package/dist/dev/traverse.js.map +1 -0
  59. package/dist/dev/truncate.js +64 -0
  60. package/dist/dev/truncate.js.map +1 -0
  61. package/dist/dev/update-order.js +235 -0
  62. package/dist/dev/update-order.js.map +1 -0
  63. package/dist/dev/utils.js +223 -0
  64. package/dist/dev/utils.js.map +1 -0
  65. package/dist/dev/writer.js +758 -0
  66. package/dist/dev/writer.js.map +1 -0
  67. package/dist/toml-patch.d.ts +24 -2
  68. package/package.json +12 -88
  69. package/LICENSE +0 -22
  70. package/README.md +0 -163
  71. package/dist/toml-patch.js +0 -54
@@ -0,0 +1,225 @@
1
+ //! @decimalturn/toml-patch v3.1.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import { findPosition } from "./location.js";
3
+ import ParseError from "./parse-error.js";
4
+
5
+ //#region src/tokenizer.ts
6
+ const IS_BARE_KEY = /^[\w-]+$/;
7
+ const DOUBLE_QUOTE = `"`;
8
+ const SINGLE_QUOTE = `'`;
9
+ const ESCAPE = "\\";
10
+ const IS_VALID_LEADING_CHARACTER = /[\w,\d,",',+,\-,_]/;
11
+ const CH_TAB = 9;
12
+ const CH_LF = 10;
13
+ const CH_CR = 13;
14
+ const CH_SPACE = 32;
15
+ const CH_HASH = 35;
16
+ const CH_COMMA = 44;
17
+ const CH_DOT = 46;
18
+ const CH_EQUAL = 61;
19
+ const CH_LBRACKET = 91;
20
+ const CH_RBRACKET = 93;
21
+ const CH_LBRACE = 123;
22
+ const CH_RBRACE = 125;
23
+ const CH_DEL = 127;
24
+ /** Creates an empty newline scan state for use with tokenize(). */
25
+ function createNewlineScanState() {
26
+ return {
27
+ reference: null,
28
+ mixed: false
29
+ };
30
+ }
31
+ function* tokenize(input, newlineState) {
32
+ const len = input.length;
33
+ let pos = 0;
34
+ const nlState = newlineState ?? createNewlineScanState();
35
+ const lines = [];
36
+ const locate = (start, end) => ({
37
+ start: findPosition(lines, start),
38
+ end: findPosition(lines, end)
39
+ });
40
+ while (pos < len) {
41
+ const code = input.charCodeAt(pos);
42
+ if ((code <= 31 || code === CH_DEL) && code !== CH_TAB && code !== CH_CR && code !== CH_LF) throw new ParseError(input, findPosition(lines, pos), `Control char 0x${code.toString(16).toUpperCase().padStart(2, "0")} not allowed`);
43
+ if (code === CH_CR) {
44
+ if (pos + 1 >= len || input.charCodeAt(pos + 1) !== CH_LF) throw new ParseError(input, findPosition(lines, pos), "Standalone CR; must be CRLF or LF");
45
+ }
46
+ if (code === CH_SPACE || code === CH_TAB || code === CH_CR) {} else if (code === CH_LF) recordNewline(pos);
47
+ else if (code === CH_LBRACKET || code === CH_RBRACKET) yield {
48
+ type: "Bracket",
49
+ raw: input[pos],
50
+ loc: locate(pos, pos + 1)
51
+ };
52
+ else if (code === CH_LBRACE || code === CH_RBRACE) yield {
53
+ type: "Curly",
54
+ raw: input[pos],
55
+ loc: locate(pos, pos + 1)
56
+ };
57
+ else if (code === CH_EQUAL) yield {
58
+ type: "Equal",
59
+ raw: "=",
60
+ loc: locate(pos, pos + 1)
61
+ };
62
+ else if (code === CH_COMMA) yield {
63
+ type: "Comma",
64
+ raw: ",",
65
+ loc: locate(pos, pos + 1)
66
+ };
67
+ else if (code === CH_DOT) yield {
68
+ type: "Dot",
69
+ raw: ".",
70
+ loc: locate(pos, pos + 1)
71
+ };
72
+ else if (code === CH_HASH) yield comment();
73
+ else {
74
+ const multiline_char = checkThree(input, pos, SINGLE_QUOTE) || checkThree(input, pos, DOUBLE_QUOTE);
75
+ if (multiline_char) yield multilineToken(multiline_char);
76
+ else yield stringToken();
77
+ }
78
+ pos++;
79
+ }
80
+ function recordNewline(lfPos) {
81
+ lines.push(lfPos);
82
+ const style = lfPos > 0 && input.charCodeAt(lfPos - 1) === CH_CR ? "\r\n" : "\n";
83
+ if (nlState.reference === null) nlState.reference = style;
84
+ else if (nlState.reference !== style) nlState.mixed = true;
85
+ }
86
+ function comment() {
87
+ const start = pos;
88
+ while (pos + 1 < len) {
89
+ const nextCode = input.charCodeAt(pos + 1);
90
+ if (nextCode === CH_LF || nextCode === CH_CR) break;
91
+ pos++;
92
+ const cc = input.charCodeAt(pos);
93
+ if ((cc <= 31 || cc === CH_DEL) && cc !== CH_TAB) throw new ParseError(input, findPosition(lines, pos), `Control char 0x${cc.toString(16).toUpperCase().padStart(2, "0")} not allowed`);
94
+ }
95
+ return {
96
+ type: "Comment",
97
+ raw: input.slice(start, pos + 1),
98
+ loc: locate(start, pos + 1)
99
+ };
100
+ }
101
+ function multilineToken(multiline_char) {
102
+ const start = pos;
103
+ const quotes = multiline_char + multiline_char + multiline_char;
104
+ pos += 3;
105
+ while (pos < len) {
106
+ if (checkThree(input, pos, multiline_char)) {
107
+ let runLength = 3;
108
+ while (input[pos + runLength] === multiline_char) runLength++;
109
+ if (runLength >= 6) throw new ParseError(input, findPosition(lines, pos), `Invalid multiline string: ${runLength} consecutive ${multiline_char} characters`);
110
+ if (runLength === 3) {
111
+ pos += 2;
112
+ break;
113
+ }
114
+ pos += runLength - 3;
115
+ pos += 2;
116
+ break;
117
+ }
118
+ const cc = input.charCodeAt(pos);
119
+ if (cc === CH_CR) {
120
+ if (pos + 1 >= len || input.charCodeAt(pos + 1) !== CH_LF) throw new ParseError(input, findPosition(lines, pos), "Standalone CR in multiline string; must be CRLF or LF");
121
+ }
122
+ if ((cc <= 31 || cc === CH_DEL) && cc !== CH_TAB && cc !== CH_LF && cc !== CH_CR) {
123
+ const stringType = multiline_char === DOUBLE_QUOTE ? "multiline basic strings" : "multiline literal strings";
124
+ const hexCode = `0x${cc.toString(16).toUpperCase().padStart(2, "0")}`;
125
+ let charName = "";
126
+ if (cc === 0) charName = "Null";
127
+ else if (cc === CH_DEL) charName = "DEL";
128
+ const message = charName ? `${charName} (${hexCode}) not allowed in ${stringType}` : `Control char ${hexCode} not allowed in ${stringType}`;
129
+ throw new ParseError(input, findPosition(lines, pos), message);
130
+ }
131
+ if (cc === CH_LF) recordNewline(pos);
132
+ pos++;
133
+ }
134
+ if (pos >= len) {
135
+ if (multiline_char === DOUBLE_QUOTE) {
136
+ let bsCount = 0;
137
+ let bi = len - 1;
138
+ while (bi >= 0 && input[bi] === "\\") {
139
+ bsCount++;
140
+ bi--;
141
+ }
142
+ if (bsCount > 0 && bsCount % 2 !== 0) throw new ParseError(input, findPosition(lines, pos), `Unterminated multiline ${quotes} (possible escape issue)`);
143
+ }
144
+ throw new ParseError(input, findPosition(lines, pos), `Unterminated multiline ${quotes}`);
145
+ }
146
+ return {
147
+ type: "Literal",
148
+ raw: input.slice(start, pos + 1),
149
+ loc: locate(start, pos + 1)
150
+ };
151
+ }
152
+ function stringToken() {
153
+ const ch = input[pos];
154
+ if (!IS_VALID_LEADING_CHARACTER.test(ch)) throw new ParseError(input, findPosition(lines, pos), `Unexpected char "${ch}"`);
155
+ const start = pos;
156
+ let double_quoted = ch === DOUBLE_QUOTE;
157
+ let single_quoted = ch === SINGLE_QUOTE;
158
+ while (pos < len) {
159
+ if (pos + 1 >= len) break;
160
+ const nextCode = input.charCodeAt(pos + 1);
161
+ if (!(double_quoted || single_quoted)) {
162
+ if (nextCode === CH_SPACE || nextCode === CH_TAB || nextCode === CH_LF || nextCode === CH_CR || nextCode === CH_COMMA || nextCode === CH_DOT || nextCode === CH_RBRACKET || nextCode === CH_RBRACE || nextCode === CH_EQUAL || nextCode === CH_HASH) break;
163
+ }
164
+ pos++;
165
+ if (!(double_quoted || single_quoted)) {
166
+ const cc = input.charCodeAt(pos);
167
+ if (cc <= 31 || cc === CH_DEL) throw new ParseError(input, findPosition(lines, pos), `Control char 0x${cc.toString(16).toUpperCase().padStart(2, "0")} not allowed in unquoted value`);
168
+ }
169
+ if (double_quoted || single_quoted) {
170
+ const cc = input.charCodeAt(pos);
171
+ if ((cc <= 31 || cc === CH_DEL) && cc !== CH_TAB) {
172
+ const stringType = double_quoted ? "basic strings" : "literal strings";
173
+ const hexCode = `0x${cc.toString(16).toUpperCase().padStart(2, "0")}`;
174
+ let charName = "";
175
+ if (cc === CH_LF) charName = "Newline";
176
+ else if (cc === CH_CR) charName = "Carriage return";
177
+ else if (cc === 0) charName = "Null";
178
+ else if (cc === CH_DEL) charName = "DEL";
179
+ const message = charName ? `${charName} (${hexCode}) not allowed in ${stringType}` : `Control char ${hexCode} not allowed in ${stringType}`;
180
+ throw new ParseError(input, findPosition(lines, pos), message);
181
+ }
182
+ }
183
+ const currentChar = input[pos];
184
+ if (currentChar === DOUBLE_QUOTE && !single_quoted) double_quoted = !double_quoted;
185
+ if (currentChar === SINGLE_QUOTE && !double_quoted) single_quoted = !single_quoted;
186
+ if (pos + 1 >= len) break;
187
+ if (double_quoted && currentChar === "\\") {
188
+ const nextChar = input[pos + 1];
189
+ if (nextChar === DOUBLE_QUOTE || nextChar === "\\") pos++;
190
+ }
191
+ }
192
+ if (double_quoted || single_quoted) throw new ParseError(input, findPosition(lines, start), `Expected close of string with ${double_quoted ? DOUBLE_QUOTE : SINGLE_QUOTE}`);
193
+ return {
194
+ type: "Literal",
195
+ raw: input.slice(start, pos + 1),
196
+ loc: locate(start, pos + 1)
197
+ };
198
+ }
199
+ }
200
+ /**
201
+ * Check if the current character and the next two characters are the same
202
+ * and not escaped.
203
+ *
204
+ * @param input - The input string.
205
+ * @param current - The current index in the input string.
206
+ * @param check - The character to check for.
207
+ * @returns ⚠️The character if found, otherwise false.
208
+ */
209
+ function checkThree(input, current, check) {
210
+ if (!check) return false;
211
+ if (!(input[current] === check && input[current + 1] === check && input[current + 2] === check)) return false;
212
+ if (check === SINGLE_QUOTE) return check;
213
+ let bsCount = 0;
214
+ let i = current - 1;
215
+ while (i >= 0 && input[i] === "\\") {
216
+ bsCount++;
217
+ i--;
218
+ }
219
+ if (bsCount === 0) return check;
220
+ return bsCount % 2 !== 0 ? false : check;
221
+ }
222
+
223
+ //#endregion
224
+ export { DOUBLE_QUOTE, IS_BARE_KEY, SINGLE_QUOTE, createNewlineScanState, tokenize };
225
+ //# sourceMappingURL=tokenizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenizer.js","names":[],"sources":["../../src/tokenizer.ts"],"sourcesContent":["import { Location, Locator, findPosition } from './location';\nimport ParseError from './parse-error';\n\nexport enum TokenType {\n Bracket = 'Bracket',\n Curly = 'Curly',\n Equal = 'Equal',\n Comma = 'Comma',\n Dot = 'Dot',\n Comment = 'Comment',\n Literal = 'Literal'\n}\n\nexport interface Token {\n type: TokenType;\n raw: string;\n loc: Location;\n}\n\nexport const IS_WHITESPACE = /\\s/;\nexport const IS_NEW_LINE = /(\\r\\n|\\n)/;\nexport const IS_BARE_KEY = /^[\\w-]+$/;\nexport const DOUBLE_QUOTE = `\"`;\nexport const SINGLE_QUOTE = `'`;\nexport const SPACE = ' ';\nexport const ESCAPE = '\\\\';\n\nconst IS_VALID_LEADING_CHARACTER = /[\\w,\\d,\",',+,\\-,_]/;\n\n// Character code constants for hot-path comparisons\nconst CH_TAB = 0x09;\nconst CH_LF = 0x0a;\nconst CH_CR = 0x0d;\nconst CH_SPACE = 0x20;\nconst CH_HASH = 0x23;\nconst CH_COMMA = 0x2c;\nconst CH_DOT = 0x2e;\nconst CH_EQUAL = 0x3d;\nconst CH_LBRACKET = 0x5b;\nconst CH_RBRACKET = 0x5d;\nconst CH_LBRACE = 0x7b;\nconst CH_RBRACE = 0x7d;\nconst CH_DEL = 0x7f;\n\n/**\n * Mutable scan state used to detect mixed line endings while tokenizing.\n * The tokenizer updates this as it encounters newlines, so no second pass\n * over the input is required.\n */\nexport interface NewlineScanState {\n /** The first newline style seen, used as the reference for the document. */\n reference: '\\n' | '\\r\\n' | null;\n /** True once a newline style different from the reference is encountered. */\n mixed: boolean;\n}\n\n/** Creates an empty newline scan state for use with tokenize(). */\nexport function createNewlineScanState(): NewlineScanState {\n return { reference: null, mixed: false };\n}\n\nexport function* tokenize(input: string, newlineState?: NewlineScanState): IterableIterator<Token> {\n const len = input.length;\n let pos = 0;\n\n // Tracks mixed line endings without an extra pass: the first newline seen\n // sets the reference style and any later newline of the other style flags\n // the document as mixed.\n const nlState = newlineState ?? createNewlineScanState();\n\n // Build line index incrementally as we scan, instead of a separate\n // upfront findLines pass. Records newline positions in the main loop\n // and inside multilineToken.\n const lines: number[] = [];\n const locate: Locator = (start: number, end: number) => ({\n start: findPosition(lines, start),\n end: findPosition(lines, end)\n });\n\n while (pos < len) {\n const code = input.charCodeAt(pos);\n\n // TOML does not allow ASCII control characters other than HT (TAB), LF, and CR.\n // CR is only allowed as part of CRLF and is validated below.\n if ((code <= 0x1f || code === CH_DEL) && code !== CH_TAB && code !== CH_CR && code !== CH_LF) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Control char 0x${code.toString(16).toUpperCase().padStart(2, '0')} not allowed`\n );\n }\n\n // CR (0x0D) is only allowed as part of CRLF\n if (code === CH_CR) {\n if (pos + 1 >= len || input.charCodeAt(pos + 1) !== CH_LF) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n 'Standalone CR; must be CRLF or LF'\n );\n }\n }\n\n if (code === CH_SPACE || code === CH_TAB || code === CH_CR) {\n // skip non-newline whitespace (CR is part of CRLF; LF will be next)\n } else if (code === CH_LF) {\n recordNewline(pos);\n } else if (code === CH_LBRACKET || code === CH_RBRACKET) {\n yield { type: TokenType.Bracket, raw: input[pos], loc: locate(pos, pos + 1) };\n } else if (code === CH_LBRACE || code === CH_RBRACE) {\n yield { type: TokenType.Curly, raw: input[pos], loc: locate(pos, pos + 1) };\n } else if (code === CH_EQUAL) {\n yield { type: TokenType.Equal, raw: '=', loc: locate(pos, pos + 1) };\n } else if (code === CH_COMMA) {\n yield { type: TokenType.Comma, raw: ',', loc: locate(pos, pos + 1) };\n } else if (code === CH_DOT) {\n yield { type: TokenType.Dot, raw: '.', loc: locate(pos, pos + 1) };\n } else if (code === CH_HASH) {\n yield comment();\n } else {\n const multiline_char =\n checkThree(input, pos, SINGLE_QUOTE) ||\n checkThree(input, pos, DOUBLE_QUOTE);\n\n if (multiline_char) {\n yield multilineToken(multiline_char);\n } else {\n yield stringToken();\n }\n }\n\n pos++;\n }\n\n // ── Helper closures (capture pos by reference) ──────────────────────\n\n // Records a LF position in the incremental line index and updates the\n // mixed-newline scan state: the first style seen becomes the reference\n // and any later newline of the other style flags the document as mixed.\n function recordNewline(lfPos: number) {\n lines.push(lfPos);\n const style: '\\n' | '\\r\\n' = lfPos > 0 && input.charCodeAt(lfPos - 1) === CH_CR ? '\\r\\n' : '\\n';\n if (nlState.reference === null) {\n nlState.reference = style;\n } else if (nlState.reference !== style) {\n nlState.mixed = true;\n }\n }\n\n function comment(): Token {\n const start = pos;\n\n // TOML comment ends at CR or LF.\n while (pos + 1 < len) {\n const nextCode = input.charCodeAt(pos + 1);\n if (nextCode === CH_LF || nextCode === CH_CR) break;\n pos++;\n\n const cc = input.charCodeAt(pos);\n // Disallow ASCII control characters in comments (except HT / TAB).\n if ((cc <= 0x1f || cc === CH_DEL) && cc !== CH_TAB) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Control char 0x${cc.toString(16).toUpperCase().padStart(2, '0')} not allowed`\n );\n }\n }\n\n // Early exit is ok for comment, no closing conditions\n return {\n type: TokenType.Comment,\n raw: input.slice(start, pos + 1),\n loc: locate(start, pos + 1)\n };\n }\n\n function multilineToken(multiline_char: string): Token {\n const start = pos;\n const quotes = multiline_char + multiline_char + multiline_char;\n\n // Skip over opening quotes\n pos += 3;\n\n // Multiline strings close on the first unescaped \"\"\" / '''.\n // A run of 4 or 5 quote characters at the end is allowed to include 1 or 2 quotes\n // immediately before the closing delimiter, but 6+ consecutive quotes is invalid.\n while (pos < len) {\n const found = checkThree(input, pos, multiline_char);\n if (found) {\n let runLength = 3;\n while (input[pos + runLength] === multiline_char) {\n runLength++;\n }\n\n if (runLength >= 6) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Invalid multiline string: ${runLength} consecutive ${multiline_char} characters`\n );\n }\n\n if (runLength === 3) {\n // pos at first closing quote, advance to last closing quote\n pos += 2;\n break;\n }\n\n // runLength is 4 or 5: keep the leading 1 or 2 quote chars as content,\n // and close on the last 3.\n pos += runLength - 3; // skip content quotes\n pos += 2; // advance to last closing quote\n break;\n }\n\n const cc = input.charCodeAt(pos);\n\n if (cc === CH_CR) {\n if (pos + 1 >= len || input.charCodeAt(pos + 1) !== CH_LF) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n 'Standalone CR in multiline string; must be CRLF or LF'\n );\n }\n }\n\n // Validate control characters in multiline strings\n // In multiline strings, control characters are not allowed except tab (0x09), LF (0x0A), and CR (0x0D as part of CRLF)\n // DEL (0x7F) is also not allowed\n if ((cc <= 0x1f || cc === CH_DEL) && cc !== CH_TAB && cc !== CH_LF && cc !== CH_CR) {\n const stringType = multiline_char === DOUBLE_QUOTE ? 'multiline basic strings' : 'multiline literal strings';\n const hexCode = `0x${cc.toString(16).toUpperCase().padStart(2, '0')}`;\n\n // Provide friendly names for common control characters\n let charName = '';\n if (cc === 0x00) {\n charName = 'Null';\n } else if (cc === CH_DEL) {\n charName = 'DEL';\n }\n\n const message = charName\n ? `${charName} (${hexCode}) not allowed in ${stringType}`\n : `Control char ${hexCode} not allowed in ${stringType}`;\n\n throw new ParseError(\n input,\n findPosition(lines, pos),\n message\n );\n }\n\n // Record newlines inside multiline strings for incremental line index\n if (cc === CH_LF) {\n recordNewline(pos);\n }\n\n pos++;\n }\n\n if (pos >= len) {\n // Check if the issue might be caused by escape sequences preventing proper closure\n // For multiline basic strings (\"\"\"), check if there are backslashes near the end that might be escaping quotes\n if (multiline_char === DOUBLE_QUOTE) {\n // Count trailing backslashes before EOF\n let bsCount = 0;\n let bi = len - 1;\n while (bi >= 0 && input[bi] === '\\\\') { bsCount++; bi--; }\n const hasEscapedQuotes = bsCount > 0 && bsCount % 2 !== 0;\n\n if (hasEscapedQuotes) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Unterminated multiline ${quotes} (possible escape issue)`\n );\n }\n }\n\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Unterminated multiline ${quotes}`\n );\n }\n\n return {\n type: TokenType.Literal,\n raw: input.slice(start, pos + 1),\n loc: locate(start, pos + 1)\n };\n }\n\n function stringToken(): Token {\n // Remaining possibilities: keys, strings, literals, integer, float, boolean\n //\n // Special cases:\n // \"...\" -> quoted\n // '...' -> quoted\n // \"...\".'...' -> bare\n // 0000-00-00 00:00:00 -> bare\n //\n // See https://github.com/toml-lang/toml#offset-date-time\n //\n // | For the sake of readability, you may replace the T delimiter between date and time with a space (as permitted by RFC 3339 section 5.6).\n // | `odt4 = 1979-05-27 07:32:00Z`\n //\n // From RFC 3339:\n //\n // | NOTE: ISO 8601 defines date and time separated by \"T\".\n // | Applications using this syntax may choose, for the sake of\n // | readability, to specify a full-date and full-time separated by\n // | (say) a space character.\n\n const ch = input[pos];\n\n // First, check for invalid characters\n if (!IS_VALID_LEADING_CHARACTER.test(ch)) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Unexpected char \"${ch}\"`\n );\n }\n\n const start = pos;\n let double_quoted = ch === DOUBLE_QUOTE;\n let single_quoted = ch === SINGLE_QUOTE;\n\n while (pos < len) {\n // Peek at next character – if none, we're done\n if (pos + 1 >= len) break;\n\n const nextCode = input.charCodeAt(pos + 1);\n\n // isFinished: if not inside quotes and next char is a terminator, stop\n if (!(double_quoted || single_quoted)) {\n if (\n nextCode === CH_SPACE || nextCode === CH_TAB ||\n nextCode === CH_LF || nextCode === CH_CR ||\n nextCode === CH_COMMA || nextCode === CH_DOT ||\n nextCode === CH_RBRACKET || nextCode === CH_RBRACE ||\n nextCode === CH_EQUAL || nextCode === CH_HASH\n ) {\n break;\n }\n }\n\n // Advance to next character\n pos++;\n\n // Bare literals must not contain ASCII control chars.\n if (!(double_quoted || single_quoted)) {\n const cc = input.charCodeAt(pos);\n if (cc <= 0x1f || cc === CH_DEL) {\n throw new ParseError(\n input,\n findPosition(lines, pos),\n `Control char 0x${cc.toString(16).toUpperCase().padStart(2, '0')} not allowed in unquoted value`\n );\n }\n }\n\n // Validate control characters in quoted strings\n if (double_quoted || single_quoted) {\n const cc = input.charCodeAt(pos);\n // In basic strings (double-quoted) and literal strings (single-quoted),\n // control characters are not allowed except tab (0x09)\n // DEL (0x7F) is also not allowed\n if ((cc <= 0x1f || cc === CH_DEL) && cc !== CH_TAB) {\n const stringType = double_quoted ? 'basic strings' : 'literal strings';\n const hexCode = `0x${cc.toString(16).toUpperCase().padStart(2, '0')}`;\n\n // Provide friendly names for common control characters\n let charName = '';\n if (cc === CH_LF) {\n charName = 'Newline';\n } else if (cc === CH_CR) {\n charName = 'Carriage return';\n } else if (cc === 0x00) {\n charName = 'Null';\n } else if (cc === CH_DEL) {\n charName = 'DEL';\n }\n\n const message = charName\n ? `${charName} (${hexCode}) not allowed in ${stringType}`\n : `Control char ${hexCode} not allowed in ${stringType}`;\n\n throw new ParseError(\n input,\n findPosition(lines, pos),\n message\n );\n }\n }\n\n const currentChar = input[pos];\n if (currentChar === DOUBLE_QUOTE && !single_quoted) double_quoted = !double_quoted;\n if (currentChar === SINGLE_QUOTE && !double_quoted) single_quoted = !single_quoted;\n\n if (pos + 1 >= len) break;\n\n // If next character is escape and currently double-quoted,\n // check for escaped quote\n if (double_quoted && currentChar === ESCAPE) {\n const nextChar = input[pos + 1];\n if (nextChar === DOUBLE_QUOTE || nextChar === ESCAPE) {\n pos++; // skip escaped char\n }\n }\n }\n\n if (double_quoted || single_quoted) {\n throw new ParseError(\n input,\n findPosition(lines, start),\n `Expected close of string with ${double_quoted ? DOUBLE_QUOTE : SINGLE_QUOTE}`\n );\n }\n\n return {\n type: TokenType.Literal,\n raw: input.slice(start, pos + 1),\n loc: locate(start, pos + 1)\n };\n }\n}\n\n/**\n * Check if the current character and the next two characters are the same\n * and not escaped.\n *\n * @param input - The input string.\n * @param current - The current index in the input string.\n * @param check - The character to check for.\n * @returns ⚠️The character if found, otherwise false.\n */\nfunction checkThree(input: string, current: number, check: string): false | string {\n if (!check) {\n return false;\n }\n\n const has3 =\n input[current] === check &&\n input[current + 1] === check &&\n input[current + 2] === check;\n\n if (!has3) {\n return false;\n }\n\n // Only check for escaping in basic strings (double quotes)\n // Literal strings (single quotes) don't support escape sequences\n if (check === SINGLE_QUOTE) {\n return check; // No escaping in literal strings\n }\n\n // Check if the sequence is escaped by counting preceding backslashes\n let bsCount = 0;\n let i = current - 1;\n while (i >= 0 && input[i] === '\\\\') {\n bsCount++;\n i--;\n }\n\n if (bsCount === 0) {\n return check; // No backslashes means not escaped\n }\n\n const isEscaped = bsCount % 2 !== 0; // Odd number of backslashes means escaped\n\n return isEscaped ? false : check; // Return `check` if not escaped, otherwise `false`\n}\n"],"mappings":";;;;;AAqBA,MAAa,cAAc;AAC3B,MAAa,eAAe;AAC5B,MAAa,eAAe;AAE5B,MAAa,SAAS;AAEtB,MAAM,6BAA6B;AAGnC,MAAM,SAAS;AACf,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,WAAW;AACjB,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,SAAS;;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E9C,MAAM,IAAI,WACR,OACA,aAAa,OAAO,GAAG,GACvB,OACF;IACF;GACF;GAEA,MAAM,cAAc,MAAM;GAC1B,IAAI,gBAAgB,gBAAgB,CAAC,eAAe,gBAAgB,CAAC;GACrE,IAAI,gBAAgB,gBAAgB,CAAC,eAAe,gBAAgB,CAAC;GAErE,IAAI,MAAM,KAAK,KAAK;GAIpB,IAAI,iBAAiB,sBAAwB;IAC3C,MAAM,WAAW,MAAM,MAAM;IAC7B,IAAI,aAAa,gBAAgB,mBAC/B;GAEJ;EACF;EAEA,IAAI,iBAAiB,eACnB,MAAM,IAAI,WACR,OACA,aAAa,OAAO,KAAK,GACzB,iCAAiC,gBAAgB,eAAe,cAClE;EAGF,OAAO;GACL;GACA,KAAK,MAAM,MAAM,OAAO,MAAM,CAAC;GAC/B,KAAK,OAAO,OAAO,MAAM,CAAC;EAC5B;CACF;AACF;;;;;;;;;;AAWA,SAAS,WAAW,OAAe,SAAiB,OAA+B;CACjF,IAAI,CAAC,OACH,OAAO;CAQT,IAAI,EAJF,MAAM,aAAa,SACnB,MAAM,UAAU,OAAO,SACvB,MAAM,UAAU,OAAO,QAGvB,OAAO;CAKT,IAAI,UAAU,cACZ,OAAO;CAIT,IAAI,UAAU;CACd,IAAI,IAAI,UAAU;CAClB,OAAO,KAAK,KAAK,MAAM,OAAO,MAAM;EAClC;EACA;CACF;CAEA,IAAI,YAAY,GACd,OAAO;CAKT,OAFkB,UAAU,MAAM,IAEf,QAAQ;AAC7B"}
@@ -0,0 +1,215 @@
1
+ //! @decimalturn/toml-patch v3.1.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import parseTOML, { continueParsingTOML } from "./parse-toml.js";
3
+ import { isObject } from "./utils.js";
4
+ import { decodeUtf8Bytes, hasLeadingBom, stripLeadingBom } from "./decode-utf8.js";
5
+ import { TomlFormat, detectNewline, resolveTomlFormat } from "./toml-format.js";
6
+ import toJS from "./to-js.js";
7
+ import { patchCst } from "./patch.js";
8
+ import { truncateCst } from "./truncate.js";
9
+
10
+ //#region src/toml-document.ts
11
+ /**
12
+ * TomlDocument encapsulates a TOML CST and provides methods to interact with it.
13
+ */
14
+ var TomlDocument = class {
15
+ _cst;
16
+ _currentTomlString;
17
+ _format;
18
+ _integersAsBigInt;
19
+ _temporal;
20
+ /**
21
+ * Initializes the TomlDocument with TOML source, parsing it into a CST.
22
+ *
23
+ * When bytes are provided, they are decoded as UTF-8 in fatal mode.
24
+ * This rejects invalid UTF-8 sequences before parsing.
25
+ *
26
+ * @param tomlSource - The TOML source to parse (string or raw UTF-8 bytes)
27
+ * @param options - Optional parse options
28
+ * @param options.integersAsBigInt - Controls bigint vs number for TOML integers
29
+ * @param options.temporal - When true, returns Temporal objects for date/time values
30
+ */
31
+ constructor(tomlSource, options) {
32
+ const sourceString = typeof tomlSource === "string" ? tomlSource : decodeUtf8Bytes(tomlSource);
33
+ const tomlString = stripLeadingBom(sourceString);
34
+ this._currentTomlString = tomlString;
35
+ this._cst = Array.from(parseTOML(tomlString));
36
+ this._integersAsBigInt = (options === null || options === void 0 ? void 0 : options.integersAsBigInt) ?? "asNeeded";
37
+ this._temporal = (options === null || options === void 0 ? void 0 : options.temporal) ?? false;
38
+ this._format = TomlFormat.autoDetectFormatWithCst(sourceString, this._cst);
39
+ }
40
+ get toTomlString() {
41
+ return this._format.leadingBom ? `${""}${this._currentTomlString}` : this._currentTomlString;
42
+ }
43
+ /**
44
+ * Returns the JavaScript object representation of the TOML document.
45
+ */
46
+ get toJsObject() {
47
+ const jsObject = toJS(this._cst, this._currentTomlString, {
48
+ integersAsBigInt: this._integersAsBigInt,
49
+ temporal: this._temporal
50
+ });
51
+ if (this._temporal) return jsObject;
52
+ return convertCustomDateClasses(jsObject);
53
+ }
54
+ /**
55
+ * Returns the internal CST (for testing purposes).
56
+ * @internal
57
+ */
58
+ get cst() {
59
+ return this._cst;
60
+ }
61
+ /**
62
+ * Applies a patch to the current CST using a modified JS object.
63
+ * Updates the internal CST. Use toTomlString getter to retrieve the updated TOML string.
64
+ *
65
+ * @param updatedObject - The modified JS object to patch with
66
+ * @param format - Optional formatting options
67
+ */
68
+ patch(updatedObject, format) {
69
+ const fmt = resolveTomlFormat(format, this._format);
70
+ const sourceBefore = this._currentTomlString;
71
+ if (!this._temporal && hasPlainDate(updatedObject)) {
72
+ const originalObject = toJS(this._cst, sourceBefore, {
73
+ integersAsBigInt: this._integersAsBigInt,
74
+ temporal: false
75
+ });
76
+ updatedObject = restoreDateRepresentations(updatedObject, originalObject);
77
+ }
78
+ const indentWidthExplicit = format instanceof TomlFormat || format != null && Object.prototype.hasOwnProperty.call(format, "indentWidth");
79
+ const trailingCommaExplicit = format instanceof TomlFormat || format != null && Object.prototype.hasOwnProperty.call(format, "trailingComma");
80
+ const result = patchCst(this._cst, updatedObject, fmt, indentWidthExplicit, trailingCommaExplicit);
81
+ this._cst = Array.from(parseTOML(result.tomlString));
82
+ this._format = fmt;
83
+ this._currentTomlString = result.tomlString;
84
+ }
85
+ /**
86
+ * Updates the internal document by supplying a modified tomlString.
87
+ * Use toJsObject getter to retrieve the updated JS object representation.
88
+ * @param tomlString - The modified TOML string to update with
89
+ */
90
+ update(tomlString) {
91
+ const tomlContent = stripLeadingBom(tomlString);
92
+ if (tomlContent === this._currentTomlString) {
93
+ this._format.leadingBom = hasLeadingBom(tomlString);
94
+ return;
95
+ }
96
+ const existingLines = this._currentTomlString.split(this._format.newLine);
97
+ const newLineChar = detectNewline(tomlContent);
98
+ const newTextLines = tomlContent.split(newLineChar);
99
+ let firstDiffLineIndex = 0;
100
+ while (firstDiffLineIndex < existingLines.length && firstDiffLineIndex < newTextLines.length && existingLines[firstDiffLineIndex] === newTextLines[firstDiffLineIndex]) firstDiffLineIndex++;
101
+ let firstDiffColumn = 0;
102
+ if (firstDiffLineIndex < existingLines.length && firstDiffLineIndex < newTextLines.length) {
103
+ const existingLine = existingLines[firstDiffLineIndex];
104
+ const newLine = newTextLines[firstDiffLineIndex];
105
+ for (let i = 0; i < Math.max(existingLine.length, newLine.length); i++) if (existingLine[i] !== newLine[i]) {
106
+ firstDiffColumn = i;
107
+ break;
108
+ }
109
+ }
110
+ let firstDiffLine = firstDiffLineIndex + 1;
111
+ const { truncatedCst, lastEndPosition } = truncateCst(this._cst, firstDiffLine, firstDiffColumn);
112
+ const continueFromLine = lastEndPosition ? lastEndPosition.line : 1;
113
+ const continueFromColumn = lastEndPosition ? lastEndPosition.column + 1 : 0;
114
+ const remainingLines = newTextLines.slice(continueFromLine - 1);
115
+ if (remainingLines.length > 0 && continueFromColumn > 0) remainingLines[0] = remainingLines[0].substring(continueFromColumn);
116
+ const remainingToml = remainingLines.join(this._format.newLine);
117
+ this._cst = Array.from(continueParsingTOML(truncatedCst, remainingToml));
118
+ this._currentTomlString = tomlContent;
119
+ this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);
120
+ }
121
+ /**
122
+ * Overwrites the internal syntax tree by fully re-parsing the supplied tomlString.
123
+ * This is simpler but slower than update() which uses incremental parsing.
124
+ * @param tomlString - The TOML string to overwrite with
125
+ */
126
+ overwrite(tomlString) {
127
+ const tomlContent = stripLeadingBom(tomlString);
128
+ if (tomlContent === this._currentTomlString) {
129
+ this._format.leadingBom = hasLeadingBom(tomlString);
130
+ return;
131
+ }
132
+ this._cst = Array.from(parseTOML(tomlContent));
133
+ this._currentTomlString = tomlContent;
134
+ this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);
135
+ }
136
+ };
137
+ /**
138
+ * True when `value` holds a plain `Date` anywhere, i.e. one of the objects
139
+ * toJsObject() produced by stripping a TOML date class. Used to skip the work
140
+ * in restoreDateRepresentations() for the common case of a document with no
141
+ * dates in it. Cycle-safe.
142
+ */
143
+ function hasPlainDate(value, seen = /* @__PURE__ */ new WeakSet()) {
144
+ if (value instanceof Date) return value.constructor === Date;
145
+ if (!value || typeof value !== "object") return false;
146
+ if (seen.has(value)) return false;
147
+ seen.add(value);
148
+ if (Array.isArray(value)) return value.some((item) => hasPlainDate(item, seen));
149
+ return Object.keys(value).some((key) => hasPlainDate(value[key], seen));
150
+ }
151
+ /**
152
+ * Re-attaches the TOML date representation that toJsObject() strips.
153
+ *
154
+ * toJsObject() deliberately hands out plain `Date` objects so that callers get
155
+ * the standard Date contract, notably a standard toISOString(). But the writer
156
+ * derives a value's TOML text from toISOString(), and the TOML date classes
157
+ * override it to return the original spelling. A plain Date handed back in
158
+ * therefore writes as a full offset date-time, so read-modify-write turned
159
+ * `1986-03-02` into `1986-03-02T00:00:00.000Z` whenever the surrounding node was
160
+ * rewritten rather than preserved from the CST.
161
+ *
162
+ * Where the caller left a date alone (still a plain Date, same instant), the
163
+ * original typed instance goes back in so the original spelling is written. A
164
+ * date whose instant actually changed is left as-is: only the caller knows
165
+ * whether a new instant is still meant to be a local date, and they can say so
166
+ * by passing LocalDate / LocalTime / LocalDateTime / OffsetDateTime, which are
167
+ * exported for that purpose. Instances of those classes are never touched.
168
+ *
169
+ * The caller's object is not mutated; a node is copied only when something
170
+ * beneath it changed, so an untouched tree is returned by reference.
171
+ */
172
+ function restoreDateRepresentations(updated, original, seen = /* @__PURE__ */ new WeakSet()) {
173
+ if (updated instanceof Date) return updated.constructor === Date && original instanceof Date && original.constructor !== Date && original.getTime() === updated.getTime() ? original : updated;
174
+ if (!updated || typeof updated !== "object" || seen.has(updated)) return updated;
175
+ seen.add(updated);
176
+ if (Array.isArray(updated)) {
177
+ if (!Array.isArray(original)) return updated;
178
+ let changed = false;
179
+ const restored = updated.map((item, index) => {
180
+ const next = restoreDateRepresentations(item, original[index], seen);
181
+ if (next !== item) changed = true;
182
+ return next;
183
+ });
184
+ return changed ? restored : updated;
185
+ }
186
+ if (!isObject(original)) return updated;
187
+ let changed = false;
188
+ const restored = {};
189
+ for (const key of Object.keys(updated)) {
190
+ const value = updated[key];
191
+ const next = restoreDateRepresentations(value, original[key], seen);
192
+ restored[key] = next;
193
+ if (next !== value) changed = true;
194
+ }
195
+ return changed ? restored : updated;
196
+ }
197
+ /**
198
+ * Recursively converts custom date classes to regular JavaScript Date objects.
199
+ * This ensures that the toJsObject property returns standard Date objects
200
+ * while preserving the custom classes internally for TOML formatting.
201
+ */
202
+ function convertCustomDateClasses(obj) {
203
+ if (obj instanceof Date) return new Date(obj.getTime());
204
+ else if (Array.isArray(obj)) return obj.map(convertCustomDateClasses);
205
+ else if (obj && typeof obj === "object") {
206
+ const result = {};
207
+ for (const [key, value] of Object.entries(obj)) result[key] = convertCustomDateClasses(value);
208
+ return result;
209
+ }
210
+ return obj;
211
+ }
212
+
213
+ //#endregion
214
+ export { TomlDocument };
215
+ //# sourceMappingURL=toml-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toml-document.js","names":[],"sources":["../../src/toml-document.ts"],"sourcesContent":["import parseTOML, { continueParsingTOML } from './parse-toml';\nimport toJS from './to-js';\nimport { TomlFormat } from './toml-format';\nimport { Block } from './cst';\nimport { patchCst } from './patch';\nimport { detectNewline, resolveTomlFormat } from './toml-format';\nimport { truncateCst } from './truncate';\nimport type { ParseOptions, IntegersAsBigInt } from './parse-options';\nimport { decodeUtf8Bytes, hasLeadingBom, stripLeadingBom, UTF8_BOM } from './decode-utf8';\nimport { isObject } from './utils';\n\n/**\n * TomlDocument encapsulates a TOML CST and provides methods to interact with it.\n */\nexport class TomlDocument {\n private _cst: Block[];\n private _currentTomlString: string;\n private _format: TomlFormat;\n private _integersAsBigInt: IntegersAsBigInt;\n private _temporal: boolean;\n\n /**\n * Initializes the TomlDocument with TOML source, parsing it into a CST.\n *\n * When bytes are provided, they are decoded as UTF-8 in fatal mode.\n * This rejects invalid UTF-8 sequences before parsing.\n *\n * @param tomlSource - The TOML source to parse (string or raw UTF-8 bytes)\n * @param options - Optional parse options\n * @param options.integersAsBigInt - Controls bigint vs number for TOML integers\n * @param options.temporal - When true, returns Temporal objects for date/time values\n */\n constructor(tomlSource: string | Uint8Array, options?: ParseOptions) {\n const sourceString = typeof tomlSource === 'string'\n ? tomlSource\n : decodeUtf8Bytes(tomlSource);\n const tomlString = stripLeadingBom(sourceString);\n\n this._currentTomlString = tomlString;\n this._cst = Array.from(parseTOML(tomlString));\n this._integersAsBigInt = options?.integersAsBigInt ?? 'asNeeded';\n this._temporal = options?.temporal ?? false;\n // Auto-detect formatting preferences from the original TOML string\n this._format = TomlFormat.autoDetectFormatWithCst(sourceString, this._cst);\n }\n\n get toTomlString(): string {\n return this._format.leadingBom ? `${UTF8_BOM}${this._currentTomlString}` : this._currentTomlString;\n }\n\n /**\n * Returns the JavaScript object representation of the TOML document.\n */\n get toJsObject(): any {\n const jsObject = toJS(this._cst, this._currentTomlString, {\n integersAsBigInt: this._integersAsBigInt,\n temporal: this._temporal\n });\n // When temporal is enabled, Temporal objects are already returned — no conversion needed.\n // When temporal is disabled, convert custom date classes to regular JavaScript Date objects.\n if (this._temporal) {\n return jsObject;\n }\n return convertCustomDateClasses(jsObject);\n }\n\n /**\n * Returns the internal CST (for testing purposes).\n * @internal\n */\n get cst(): Block[] {\n return this._cst;\n }\n\n /**\n * Applies a patch to the current CST using a modified JS object.\n * Updates the internal CST. Use toTomlString getter to retrieve the updated TOML string.\n *\n * @param updatedObject - The modified JS object to patch with\n * @param format - Optional formatting options\n */\n patch(updatedObject: any, format?: Partial<TomlFormat> | TomlFormat) : void {\n\n const fmt = resolveTomlFormat(format, this._format);\n\n const sourceBefore = this._currentTomlString;\n\n // Only worth deriving the pre-patch values when a stripped date could\n // actually be present; temporal mode hands out Temporal objects untouched.\n if (!this._temporal && hasPlainDate(updatedObject)) {\n const originalObject = toJS(this._cst, sourceBefore, {\n integersAsBigInt: this._integersAsBigInt,\n temporal: false\n });\n updatedObject = restoreDateRepresentations(updatedObject, originalObject);\n }\n\n const indentWidthExplicit = format instanceof TomlFormat ||\n (format != null && Object.prototype.hasOwnProperty.call(format, 'indentWidth'));\n const trailingCommaExplicit = format instanceof TomlFormat ||\n (format != null && Object.prototype.hasOwnProperty.call(format, 'trailingComma'));\n const result = patchCst(\n this._cst,\n updatedObject,\n fmt,\n indentWidthExplicit,\n trailingCommaExplicit\n );\n this._cst = Array.from(parseTOML(result.tomlString));\n this._format = fmt;\n this._currentTomlString = result.tomlString;\n }\n\n /**\n * Updates the internal document by supplying a modified tomlString.\n * Use toJsObject getter to retrieve the updated JS object representation.\n * @param tomlString - The modified TOML string to update with\n */\n update(tomlString: string): void {\n const tomlContent = stripLeadingBom(tomlString);\n\n if (tomlContent === this._currentTomlString) {\n this._format.leadingBom = hasLeadingBom(tomlString);\n return;\n }\n\n // Now, let's check where the first difference is\n const existingLines = this._currentTomlString.split(this._format.newLine);\n const newLineChar = detectNewline(tomlContent);\n const newTextLines = tomlContent.split(newLineChar);\n let firstDiffLineIndex = 0;\n while (\n firstDiffLineIndex < existingLines.length &&\n firstDiffLineIndex < newTextLines.length &&\n existingLines[firstDiffLineIndex] === newTextLines[firstDiffLineIndex]\n ) {\n firstDiffLineIndex++;\n }\n\n // Calculate the 1-based line number and 0-based column where the first difference occurs\n \n let firstDiffColumn = 0;\n \n // If we're within the bounds of both arrays, find the column where they differ\n if (firstDiffLineIndex < existingLines.length && firstDiffLineIndex < newTextLines.length) {\n const existingLine = existingLines[firstDiffLineIndex];\n const newLine = newTextLines[firstDiffLineIndex];\n \n // Find the first character position where the lines differ\n for (let i = 0; i < Math.max(existingLine.length, newLine.length); i++) {\n if (existingLine[i] !== newLine[i]) {\n firstDiffColumn = i;\n break;\n }\n }\n }\n\n let firstDiffLine = firstDiffLineIndex + 1; // Convert to 1-based\n const { truncatedCst, lastEndPosition } = truncateCst(this._cst, firstDiffLine, firstDiffColumn);\n\n // Determine where to continue parsing from in the new string\n // If lastEndPosition exists, continue from there; otherwise from the start of the document\n const continueFromLine = lastEndPosition ? lastEndPosition.line : 1;\n const continueFromColumn = lastEndPosition ? lastEndPosition.column + 1 : 0;\n\n // Based on the first difference, we can re-parse only the affected part\n // We will need to supply the remaining string after where the CST was truncated\n const remainingLines = newTextLines.slice(continueFromLine - 1);\n \n // If there's a partial line match, we need to extract only the part after the continuation column\n if (remainingLines.length > 0 && continueFromColumn > 0) {\n remainingLines[0] = remainingLines[0].substring(continueFromColumn);\n }\n \n const remainingToml = remainingLines.join(this._format.newLine);\n \n this._cst = Array.from(continueParsingTOML(truncatedCst, remainingToml));\n this._currentTomlString = tomlContent;\n \n // Update the auto-detected format with the new string's characteristics\n this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);\n }\n\n /**\n * Overwrites the internal syntax tree by fully re-parsing the supplied tomlString.\n * This is simpler but slower than update() which uses incremental parsing.\n * @param tomlString - The TOML string to overwrite with\n */\n overwrite(tomlString: string): void {\n const tomlContent = stripLeadingBom(tomlString);\n\n if (tomlContent === this._currentTomlString) {\n this._format.leadingBom = hasLeadingBom(tomlString);\n return;\n }\n\n // Re-parse the entire document\n this._cst = Array.from(parseTOML(tomlContent));\n this._currentTomlString = tomlContent;\n \n // Update the auto-detected format with the new string's characteristics\n this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);\n }\n}\n\n/**\n * True when `value` holds a plain `Date` anywhere, i.e. one of the objects\n * toJsObject() produced by stripping a TOML date class. Used to skip the work\n * in restoreDateRepresentations() for the common case of a document with no\n * dates in it. Cycle-safe.\n */\nfunction hasPlainDate(value: any, seen: WeakSet<object> = new WeakSet()): boolean {\n if (value instanceof Date) return value.constructor === Date;\n if (!value || typeof value !== 'object') return false;\n if (seen.has(value)) return false;\n seen.add(value);\n if (Array.isArray(value)) return value.some(item => hasPlainDate(item, seen));\n return Object.keys(value).some(key => hasPlainDate(value[key], seen));\n}\n\n/**\n * Re-attaches the TOML date representation that toJsObject() strips.\n *\n * toJsObject() deliberately hands out plain `Date` objects so that callers get\n * the standard Date contract, notably a standard toISOString(). But the writer\n * derives a value's TOML text from toISOString(), and the TOML date classes\n * override it to return the original spelling. A plain Date handed back in\n * therefore writes as a full offset date-time, so read-modify-write turned\n * `1986-03-02` into `1986-03-02T00:00:00.000Z` whenever the surrounding node was\n * rewritten rather than preserved from the CST.\n *\n * Where the caller left a date alone (still a plain Date, same instant), the\n * original typed instance goes back in so the original spelling is written. A\n * date whose instant actually changed is left as-is: only the caller knows\n * whether a new instant is still meant to be a local date, and they can say so\n * by passing LocalDate / LocalTime / LocalDateTime / OffsetDateTime, which are\n * exported for that purpose. Instances of those classes are never touched.\n *\n * The caller's object is not mutated; a node is copied only when something\n * beneath it changed, so an untouched tree is returned by reference.\n */\nfunction restoreDateRepresentations(updated: any, original: any, seen: WeakSet<object> = new WeakSet()): any {\n if (updated instanceof Date) {\n const erased = updated.constructor === Date\n && original instanceof Date\n && original.constructor !== Date\n && original.getTime() === updated.getTime();\n return erased ? original : updated;\n }\n if (!updated || typeof updated !== 'object' || seen.has(updated)) return updated;\n seen.add(updated);\n\n if (Array.isArray(updated)) {\n if (!Array.isArray(original)) return updated;\n let changed = false;\n const restored = updated.map((item, index) => {\n const next = restoreDateRepresentations(item, original[index], seen);\n if (next !== item) changed = true;\n return next;\n });\n return changed ? restored : updated;\n }\n\n if (!isObject(original)) return updated;\n let changed = false;\n const restored: Record<string, any> = {};\n for (const key of Object.keys(updated)) {\n const value = updated[key];\n const next = restoreDateRepresentations(value, original[key], seen);\n restored[key] = next;\n if (next !== value) changed = true;\n }\n return changed ? restored : updated;\n}\n\n/**\n * Recursively converts custom date classes to regular JavaScript Date objects.\n * This ensures that the toJsObject property returns standard Date objects\n * while preserving the custom classes internally for TOML formatting.\n */\nfunction convertCustomDateClasses(obj: any): any {\n if (obj instanceof Date) {\n // Convert custom date classes to regular Date objects\n return new Date(obj.getTime());\n } else if (Array.isArray(obj)) {\n return obj.map(convertCustomDateClasses);\n } else if (obj && typeof obj === 'object') {\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = convertCustomDateClasses(value);\n }\n return result;\n }\n return obj;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;;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