rl-workspaces 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -193
- package/bin/rl +2 -54
- package/dist/agent-launch.js +1 -1
- package/dist/agent-presets.js +42 -17
- package/dist/agent-resume.js +2 -2
- package/dist/agent-runner.js +20 -0
- package/dist/agent-workflows.js +60 -16
- package/dist/automation-config.js +144 -5
- package/dist/bootstrap.js +74 -0
- package/dist/cli.js +2 -0
- package/dist/command-context.js +1 -1
- package/dist/common.js +3 -2
- package/dist/dependencies.js +197 -0
- package/dist/doctor.js +1 -1
- package/dist/git-workflow.js +8 -102
- package/dist/help.js +113 -116
- package/dist/hooks.js +1 -1
- package/dist/install.js +143 -0
- package/dist/mcp-setup.js +171 -0
- package/dist/mcp.js +13 -16
- package/dist/picker.js +24 -7
- package/dist/pr-workflow.js +7 -28
- package/dist/repos.js +5 -1
- package/dist/session-workflows.js +122 -18
- package/dist/session.js +1 -1
- package/dist/state.js +4 -14
- package/dist/storage.js +2 -2
- package/dist/store.js +2 -2
- package/dist/summary.js +1 -1
- package/dist/workflow-collaboration.js +531 -0
- package/dist/workflow.js +24 -38
- package/lib/entry.zsh +54 -0
- package/lib/rl.zsh +37 -9
- package/node_modules/proper-lockfile/CHANGELOG.md +108 -0
- package/node_modules/smol-toml/LICENSE +24 -0
- package/node_modules/smol-toml/README.md +605 -0
- package/node_modules/smol-toml/dist/date.d.ts +41 -0
- package/node_modules/smol-toml/dist/date.js +156 -0
- package/node_modules/smol-toml/dist/error.d.ts +37 -0
- package/node_modules/smol-toml/dist/error.js +67 -0
- package/node_modules/smol-toml/dist/extract.js +293 -0
- package/node_modules/smol-toml/dist/index.cjs +771 -0
- package/node_modules/smol-toml/dist/index.d.ts +44 -0
- package/node_modules/smol-toml/dist/index.js +34 -0
- package/node_modules/smol-toml/dist/parse.d.ts +73 -0
- package/node_modules/smol-toml/dist/parse.js +164 -0
- package/node_modules/smol-toml/dist/primitive.js +151 -0
- package/node_modules/smol-toml/dist/stringify.d.ts +32 -0
- package/node_modules/smol-toml/dist/stringify.js +219 -0
- package/node_modules/smol-toml/dist/struct.js +156 -0
- package/node_modules/smol-toml/dist/util.d.ts +43 -0
- package/node_modules/smol-toml/dist/util.js +57 -0
- package/node_modules/smol-toml/package.json +68 -0
- package/package.json +6 -3
- package/shell/rl.zsh +1 -1
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
*
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
* list of conditions and the following disclaimer.
|
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
* this list of conditions and the following disclaimer in the
|
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
|
13
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
* may be used to endorse or promote products derived from this software without
|
|
15
|
+
* specific prior written permission.
|
|
16
|
+
*
|
|
17
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
*/
|
|
28
|
+
"use strict";
|
|
29
|
+
Object.defineProperties(exports, {
|
|
30
|
+
__esModule: { value: true },
|
|
31
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
32
|
+
});
|
|
33
|
+
//#region src/error.ts
|
|
34
|
+
function getLineColFromPtr(string, ptr) {
|
|
35
|
+
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
36
|
+
return [lines.length, lines.pop().length + 1];
|
|
37
|
+
}
|
|
38
|
+
function makeCodeBlock(string, line, column) {
|
|
39
|
+
let lines = string.split(/\r?\n/);
|
|
40
|
+
let codeblock = "";
|
|
41
|
+
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
42
|
+
for (let i = line - 1; i <= line + 1; i++) {
|
|
43
|
+
let l = lines[i - 1];
|
|
44
|
+
if (!l) continue;
|
|
45
|
+
codeblock += i.toString().padEnd(numberLen, " ");
|
|
46
|
+
codeblock += ": ";
|
|
47
|
+
codeblock += l;
|
|
48
|
+
codeblock += "\n";
|
|
49
|
+
if (i === line) {
|
|
50
|
+
codeblock += " ".repeat(numberLen + column + 2);
|
|
51
|
+
codeblock += "^\n";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return codeblock;
|
|
55
|
+
}
|
|
56
|
+
var TomlError = class TomlError extends Error {
|
|
57
|
+
line;
|
|
58
|
+
column;
|
|
59
|
+
codeblock;
|
|
60
|
+
constructor(message, options) {
|
|
61
|
+
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
62
|
+
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
63
|
+
super(`Invalid TOML document: ${message}\n\n${codeblock}`, options);
|
|
64
|
+
this.line = line;
|
|
65
|
+
this.column = column;
|
|
66
|
+
this.codeblock = codeblock;
|
|
67
|
+
}
|
|
68
|
+
/** @internal */
|
|
69
|
+
static x(message, ctx, ptr) {
|
|
70
|
+
throw new TomlError(message, {
|
|
71
|
+
toml: ctx.s,
|
|
72
|
+
ptr: ptr ?? ctx.p
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/primitive.ts
|
|
78
|
+
/** @internal */
|
|
79
|
+
function parseString(ctx) {
|
|
80
|
+
let startPtr = ctx.p;
|
|
81
|
+
let c = ctx.s.charCodeAt(ctx.p++);
|
|
82
|
+
let first = c;
|
|
83
|
+
let isLiteral = c === 39;
|
|
84
|
+
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
85
|
+
if (isMultiline) {
|
|
86
|
+
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10) ctx.p++;
|
|
87
|
+
else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) ctx.p += 2;
|
|
88
|
+
}
|
|
89
|
+
let parsed = "";
|
|
90
|
+
let sliceStart = ctx.p;
|
|
91
|
+
let state = 0;
|
|
92
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
93
|
+
c = ctx.s.charCodeAt(ctx.p);
|
|
94
|
+
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) state = state && 3;
|
|
95
|
+
else if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in strings", ctx);
|
|
96
|
+
else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
97
|
+
if (isMultiline) {
|
|
98
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
|
|
99
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
|
|
100
|
+
}
|
|
101
|
+
if (!state) {
|
|
102
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
103
|
+
parsed = parsed ? parsed + s : s;
|
|
104
|
+
}
|
|
105
|
+
ctx.p += isMultiline ? 3 : 1;
|
|
106
|
+
return parsed;
|
|
107
|
+
} else if (!state) {
|
|
108
|
+
if (!isLiteral && c === 92) {
|
|
109
|
+
parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
|
|
110
|
+
state = 1;
|
|
111
|
+
}
|
|
112
|
+
} else if (state === 1) {
|
|
113
|
+
if (c === 120 || c === 117 || c === 85) {
|
|
114
|
+
let errPtr = ctx.p++ - 1;
|
|
115
|
+
let value = 0;
|
|
116
|
+
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
117
|
+
for (let j = 0; j < len; j++, ctx.p++) {
|
|
118
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
119
|
+
let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
|
|
120
|
+
if (digit < 0) TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
121
|
+
value = value << 4 | digit;
|
|
122
|
+
}
|
|
123
|
+
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
124
|
+
parsed += String.fromCodePoint(value);
|
|
125
|
+
sliceStart = ctx.p--;
|
|
126
|
+
state = 0;
|
|
127
|
+
} else if (isMultiline && (c === 32 || c === 9)) state = 2;
|
|
128
|
+
else {
|
|
129
|
+
if (c === 98) parsed += "\b";
|
|
130
|
+
else if (c === 116) parsed += " ";
|
|
131
|
+
else if (c === 110) parsed += "\n";
|
|
132
|
+
else if (c === 102) parsed += "\f";
|
|
133
|
+
else if (c === 114) parsed += "\r";
|
|
134
|
+
else if (c === 101) parsed += "\x1B";
|
|
135
|
+
else if (c === 34) parsed += "\"";
|
|
136
|
+
else if (c === 92) parsed += "\\";
|
|
137
|
+
else TomlError.x("unrecognised escape sequence", ctx);
|
|
138
|
+
sliceStart = ctx.p + 1;
|
|
139
|
+
state = 0;
|
|
140
|
+
}
|
|
141
|
+
} else if (c !== 32 && c !== 9) {
|
|
142
|
+
if (state === 2) TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
143
|
+
state = !isLiteral && c === 92 ? 1 : 0;
|
|
144
|
+
sliceStart = ctx.p;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
TomlError.x("unfinished string", ctx, startPtr);
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/date.ts
|
|
151
|
+
let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
152
|
+
var TomlDate = class TomlDate extends Date {
|
|
153
|
+
#hasDate = false;
|
|
154
|
+
#hasTime = false;
|
|
155
|
+
#offset = null;
|
|
156
|
+
constructor(date, fasttype, unsafeDelim) {
|
|
157
|
+
let hasDate = true;
|
|
158
|
+
let hasTime = true;
|
|
159
|
+
let offset = "Z";
|
|
160
|
+
let c;
|
|
161
|
+
if (typeof date === "string") {
|
|
162
|
+
if (fasttype) prep: {
|
|
163
|
+
if (fasttype < 3) {
|
|
164
|
+
if (+date.slice(11, 13) > 23) {
|
|
165
|
+
date = "";
|
|
166
|
+
break prep;
|
|
167
|
+
}
|
|
168
|
+
if (fasttype === 2) {
|
|
169
|
+
offset = null;
|
|
170
|
+
date += "Z";
|
|
171
|
+
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) offset = date.slice(date.length - 6);
|
|
172
|
+
if (unsafeDelim) date = date.slice(0, 10) + "T" + date.slice(11);
|
|
173
|
+
} else if (fasttype === 4) date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
174
|
+
hasDate = fasttype !== 4;
|
|
175
|
+
hasTime = fasttype !== 3;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
let match = date.match(DATE_TIME_RE);
|
|
179
|
+
if (match) {
|
|
180
|
+
if (!match[1]) {
|
|
181
|
+
hasDate = false;
|
|
182
|
+
date = `0000-01-01T${date}`;
|
|
183
|
+
}
|
|
184
|
+
hasTime = !!match[2];
|
|
185
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
186
|
+
if (match[2] && +match[2] > 23) date = "";
|
|
187
|
+
else {
|
|
188
|
+
offset = match[3] || null;
|
|
189
|
+
if (!offset && hasTime) date += "Z";
|
|
190
|
+
}
|
|
191
|
+
} else date = "";
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
super(date);
|
|
195
|
+
if (!isNaN(this.getTime())) {
|
|
196
|
+
this.#hasDate = hasDate;
|
|
197
|
+
this.#hasTime = hasTime;
|
|
198
|
+
this.#offset = offset;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
isDateTime() {
|
|
202
|
+
return this.#hasDate && this.#hasTime;
|
|
203
|
+
}
|
|
204
|
+
isLocal() {
|
|
205
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
206
|
+
}
|
|
207
|
+
isDate() {
|
|
208
|
+
return this.#hasDate && !this.#hasTime;
|
|
209
|
+
}
|
|
210
|
+
isTime() {
|
|
211
|
+
return this.#hasTime && !this.#hasDate;
|
|
212
|
+
}
|
|
213
|
+
isValid() {
|
|
214
|
+
return this.#hasDate || this.#hasTime;
|
|
215
|
+
}
|
|
216
|
+
toISOString() {
|
|
217
|
+
let iso = super.toISOString();
|
|
218
|
+
if (this.isDate()) return iso.slice(0, 10);
|
|
219
|
+
if (this.isTime()) return iso.slice(11, 23);
|
|
220
|
+
if (this.#offset === null) return iso.slice(0, -1);
|
|
221
|
+
if (this.#offset === "Z" || this.#offset === "z") return iso;
|
|
222
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
223
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
224
|
+
return (/* @__PURE__ */ new Date(this.getTime() - offset * 6e4)).toISOString().slice(0, -1) + this.#offset;
|
|
225
|
+
}
|
|
226
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
227
|
+
let date = new TomlDate(jsDate);
|
|
228
|
+
date.#offset = offset;
|
|
229
|
+
return date;
|
|
230
|
+
}
|
|
231
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
232
|
+
let date = new TomlDate(jsDate);
|
|
233
|
+
date.#offset = null;
|
|
234
|
+
return date;
|
|
235
|
+
}
|
|
236
|
+
static wrapAsLocalDate(jsDate) {
|
|
237
|
+
let date = new TomlDate(jsDate);
|
|
238
|
+
date.#hasTime = false;
|
|
239
|
+
date.#offset = null;
|
|
240
|
+
return date;
|
|
241
|
+
}
|
|
242
|
+
static wrapAsLocalTime(jsDate) {
|
|
243
|
+
let date = new TomlDate(jsDate);
|
|
244
|
+
date.#hasDate = false;
|
|
245
|
+
date.#offset = null;
|
|
246
|
+
return date;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/extract.ts
|
|
251
|
+
function isDigit(char, base = 10) {
|
|
252
|
+
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
253
|
+
}
|
|
254
|
+
function isEndOfValue(char, delim) {
|
|
255
|
+
return char === 32 || char === 9 || char === 10 || char === 13 || delim && (char === delim || char === 44) || char === 35;
|
|
256
|
+
}
|
|
257
|
+
/** @internal */
|
|
258
|
+
function extractValue(ctx, end) {
|
|
259
|
+
let errPtr = ctx.p;
|
|
260
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
261
|
+
if (c === 91 || c === 123) {
|
|
262
|
+
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
263
|
+
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
264
|
+
ctx.d++;
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
if (c === 34 || c === 39) return parseString(ctx);
|
|
268
|
+
if (c === 116) {
|
|
269
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
|
|
270
|
+
return ctx.p++, true;
|
|
271
|
+
}
|
|
272
|
+
if (c === 102) {
|
|
273
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
|
|
274
|
+
return ctx.p++, false;
|
|
275
|
+
}
|
|
276
|
+
if (c === 43 || c === 45) return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
277
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) return parseDate(ctx, c, end);
|
|
278
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 58) return parseTime(ctx, c, end);
|
|
279
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
280
|
+
}
|
|
281
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
282
|
+
let c = startChr;
|
|
283
|
+
let state = 0;
|
|
284
|
+
let hasUnderscores = false;
|
|
285
|
+
if (c === 105) {
|
|
286
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102) TomlError.x("invalid value", ctx, startPtr);
|
|
287
|
+
return ctx.p++, (sign || 1) / 0;
|
|
288
|
+
}
|
|
289
|
+
if (c === 110) {
|
|
290
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110) TomlError.x("invalid value", ctx, startPtr);
|
|
291
|
+
return ctx.p++, NaN;
|
|
292
|
+
}
|
|
293
|
+
if (c === 48) {
|
|
294
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr)) return ctx.bi === true ? 0n : 0;
|
|
295
|
+
if (!sign) {
|
|
296
|
+
if (c === 120) return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
297
|
+
else if (c === 98) return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
298
|
+
else if (c === 111) return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
299
|
+
}
|
|
300
|
+
if (c === 46) state = 2;
|
|
301
|
+
else if (c === 101 || c === 69) state = 4;
|
|
302
|
+
else TomlError.x("illegal leading zero", ctx, startPtr);
|
|
303
|
+
} else if (!isDigit(c)) TomlError.x("invalid value", ctx, startPtr);
|
|
304
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
305
|
+
if (!state) state = 1;
|
|
306
|
+
if (c === 95) {
|
|
307
|
+
if (!(state & 1)) TomlError.x("illegal underscore", ctx);
|
|
308
|
+
state += 11;
|
|
309
|
+
hasUnderscores = true;
|
|
310
|
+
} else if (state === 1 && c === 46) state = 2;
|
|
311
|
+
else if ((state === 1 || state === 3) && (c === 101 || c === 69)) state = 4;
|
|
312
|
+
else if (state === 4 && (c === 43 || c === 45)) state = 6;
|
|
313
|
+
else if (!isDigit(c)) TomlError.x(`illegal character in numeric literal`, ctx);
|
|
314
|
+
else if (state > 9) state -= 11;
|
|
315
|
+
else if (!(state & 1)) state++;
|
|
316
|
+
}
|
|
317
|
+
if (!state) {
|
|
318
|
+
let val = (startChr - 48) * (sign || 1);
|
|
319
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
320
|
+
}
|
|
321
|
+
if (!(state & 1)) TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
322
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
323
|
+
if (hasUnderscores) str = str.replaceAll("_", "");
|
|
324
|
+
return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
|
|
325
|
+
}
|
|
326
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
327
|
+
let c, underscore = 1;
|
|
328
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) if (c === 95) {
|
|
329
|
+
if (underscore & 1) TomlError.x("illegal underscore", ctx);
|
|
330
|
+
underscore = 3;
|
|
331
|
+
} else if (!isDigit(c, base)) TomlError.x(`illegal character in numeric literal`, ctx);
|
|
332
|
+
else if (underscore & 1) underscore--;
|
|
333
|
+
if (underscore & 1) TomlError.x("unfinished numeric value", ctx);
|
|
334
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
335
|
+
if (underscore) str = str.replaceAll("_", "");
|
|
336
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
337
|
+
}
|
|
338
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
339
|
+
if (ctx.bi !== true) int: {
|
|
340
|
+
let val = parseInt(str, base);
|
|
341
|
+
if (!Number.isSafeInteger(val)) {
|
|
342
|
+
if (ctx.bi) break int;
|
|
343
|
+
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
344
|
+
}
|
|
345
|
+
return val;
|
|
346
|
+
}
|
|
347
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
|
|
348
|
+
}
|
|
349
|
+
function parseDate(ctx, c, endChr) {
|
|
350
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
351
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
352
|
+
ctx.p += 5;
|
|
353
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++))) TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
354
|
+
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 3, false, startPtr);
|
|
355
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 58) TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
356
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 58) ctx.p += 3;
|
|
357
|
+
if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p)));
|
|
358
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
359
|
+
if (c === 90 || c === 122) return readDate(ctx, ctx.s.slice(startPtr, ++ctx.p), 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
360
|
+
if (c === 43 || c === 45) return readDate(ctx, ctx.s.slice(startPtr, ctx.p += 6), 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
361
|
+
}
|
|
362
|
+
return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 2, unsafeSeparator, startPtr);
|
|
363
|
+
}
|
|
364
|
+
function parseTime(ctx, c, endChr) {
|
|
365
|
+
let start = ctx.p;
|
|
366
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
367
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 58) ctx.p += 3;
|
|
368
|
+
if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p)));
|
|
369
|
+
return readDate(ctx, ctx.s.slice(start, ctx.p), 4, false, start);
|
|
370
|
+
}
|
|
371
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
372
|
+
if (ctx.ld) {
|
|
373
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
374
|
+
if (!date.isValid()) TomlError.x("invalid date", ctx, errPtr);
|
|
375
|
+
return date;
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
if (temporalSuffix) str += temporalSuffix;
|
|
379
|
+
switch (type) {
|
|
380
|
+
case 1: return Temporal.ZonedDateTime.from(str);
|
|
381
|
+
case 2: return Temporal.PlainDateTime.from(str);
|
|
382
|
+
case 3: return Temporal.PlainDate.from(str);
|
|
383
|
+
case 4: return Temporal.PlainTime.from(str);
|
|
384
|
+
}
|
|
385
|
+
} catch (e) {
|
|
386
|
+
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/util.ts
|
|
391
|
+
/** @internal */
|
|
392
|
+
function skipComment(ctx) {
|
|
393
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
394
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
395
|
+
if (c === 10) break;
|
|
396
|
+
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
397
|
+
ctx.p++;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in comments", ctx);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/** @internal */
|
|
404
|
+
function skipVoid(ctx, banNewLines, banComments) {
|
|
405
|
+
let c;
|
|
406
|
+
while (ctx.p < ctx.s.length) {
|
|
407
|
+
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))) ctx.p++;
|
|
408
|
+
if (banComments || c !== 35) break;
|
|
409
|
+
skipComment(ctx);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/struct.ts
|
|
414
|
+
/** @internal */
|
|
415
|
+
function parseKey(ctx, end = 61) {
|
|
416
|
+
let startPtr;
|
|
417
|
+
let state = 0;
|
|
418
|
+
let parsed = [];
|
|
419
|
+
let sliceStart;
|
|
420
|
+
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
421
|
+
do
|
|
422
|
+
if (c === end) {
|
|
423
|
+
if (!state) TomlError.x("unexpected end of key", ctx);
|
|
424
|
+
if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
425
|
+
return ctx.p++, parsed;
|
|
426
|
+
} else if (c === 46) {
|
|
427
|
+
if (!state) TomlError.x("illegal empty bare key", ctx);
|
|
428
|
+
if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
429
|
+
state = 0;
|
|
430
|
+
} else if (!state && (c === 34 || c === 39)) {
|
|
431
|
+
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
432
|
+
parsed.push(parseString(ctx));
|
|
433
|
+
state = 2;
|
|
434
|
+
ctx.p--;
|
|
435
|
+
} else if (c === 32 || c === 9) {
|
|
436
|
+
if (state === 1) {
|
|
437
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
438
|
+
state = 2;
|
|
439
|
+
}
|
|
440
|
+
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) TomlError.x("illegal character in key", ctx);
|
|
441
|
+
else if (!state) {
|
|
442
|
+
state = 1;
|
|
443
|
+
sliceStart = ctx.p;
|
|
444
|
+
}
|
|
445
|
+
while (c = ctx.s.charCodeAt(++ctx.p));
|
|
446
|
+
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
447
|
+
}
|
|
448
|
+
/** @internal */
|
|
449
|
+
function parseInlineTable(ctx) {
|
|
450
|
+
let startPtr = ctx.p++;
|
|
451
|
+
let res = Object.create(null);
|
|
452
|
+
let seen = /* @__PURE__ */ new Set();
|
|
453
|
+
let c;
|
|
454
|
+
while (ctx.p < ctx.s.length) {
|
|
455
|
+
skipVoid(ctx);
|
|
456
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
457
|
+
ctx.p++;
|
|
458
|
+
return res;
|
|
459
|
+
}
|
|
460
|
+
let k;
|
|
461
|
+
let t = res;
|
|
462
|
+
let hasOwn = false;
|
|
463
|
+
let errPtr = ctx.p;
|
|
464
|
+
let key = parseKey(ctx);
|
|
465
|
+
for (let i = 0; i < key.length; i++) {
|
|
466
|
+
if (i) t = hasOwn ? t[k] : t[k] = Object.create(null);
|
|
467
|
+
k = key[i];
|
|
468
|
+
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
469
|
+
let unsafe = k === "__proto__";
|
|
470
|
+
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
471
|
+
t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
if (!hasOwn && unsafe) Object.defineProperty(t, k, {
|
|
475
|
+
enumerable: true,
|
|
476
|
+
configurable: true,
|
|
477
|
+
writable: true
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
if (hasOwn) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
481
|
+
skipVoid(ctx, true, true);
|
|
482
|
+
let value = extractValue(ctx, 125);
|
|
483
|
+
if (t && typeof (t[k] = value) === "object") seen.add(value);
|
|
484
|
+
skipVoid(ctx);
|
|
485
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) return res;
|
|
486
|
+
if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
487
|
+
}
|
|
488
|
+
TomlError.x("unfinished table", ctx, startPtr);
|
|
489
|
+
}
|
|
490
|
+
/** @internal */
|
|
491
|
+
function parseArray(ctx) {
|
|
492
|
+
let startPtr = ctx.p++;
|
|
493
|
+
let res = [];
|
|
494
|
+
let c;
|
|
495
|
+
while (ctx.p < ctx.s.length) {
|
|
496
|
+
skipVoid(ctx);
|
|
497
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
498
|
+
ctx.p++;
|
|
499
|
+
return res;
|
|
500
|
+
}
|
|
501
|
+
res.push(extractValue(ctx, 93));
|
|
502
|
+
skipVoid(ctx);
|
|
503
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) return res;
|
|
504
|
+
if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
505
|
+
}
|
|
506
|
+
TomlError.x("unfinished array", ctx, startPtr);
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/parse.ts
|
|
510
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
511
|
+
let t = table;
|
|
512
|
+
let m = meta;
|
|
513
|
+
let k;
|
|
514
|
+
let hasOwn = false;
|
|
515
|
+
let state;
|
|
516
|
+
for (let i = 0; i < key.length; i++) {
|
|
517
|
+
if (i) {
|
|
518
|
+
t = hasOwn ? t[k] : t[k] = Object.create(null);
|
|
519
|
+
m = (state = m[k]).c;
|
|
520
|
+
if (type === 0 && (state.t === 1 || state.t === 2)) return null;
|
|
521
|
+
if (state.t === 2) {
|
|
522
|
+
let l = t.length - 1;
|
|
523
|
+
t = t[l];
|
|
524
|
+
m = m[l].c;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
k = key[i];
|
|
528
|
+
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) return null;
|
|
529
|
+
if (!hasOwn) {
|
|
530
|
+
let unsafe = k === "__proto__";
|
|
531
|
+
if (ctx.uk && (unsafe || k === "constructor")) return false;
|
|
532
|
+
if (unsafe) {
|
|
533
|
+
Object.defineProperty(t, k, {
|
|
534
|
+
enumerable: true,
|
|
535
|
+
configurable: true,
|
|
536
|
+
writable: true
|
|
537
|
+
});
|
|
538
|
+
Object.defineProperty(m, k, {
|
|
539
|
+
enumerable: true,
|
|
540
|
+
configurable: true,
|
|
541
|
+
writable: true
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
m[k] = {
|
|
545
|
+
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
546
|
+
d: false,
|
|
547
|
+
i: 0,
|
|
548
|
+
c: Object.create(null)
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
state = m[k];
|
|
553
|
+
if (state.t !== type && !(type === 1 && state.t === 3)) return null;
|
|
554
|
+
if (type === 2) {
|
|
555
|
+
if (!state.d) {
|
|
556
|
+
state.d = true;
|
|
557
|
+
t[k] = [];
|
|
558
|
+
}
|
|
559
|
+
t[k].push(t = Object.create(null));
|
|
560
|
+
state.c[state.i++] = state = {
|
|
561
|
+
t: 1,
|
|
562
|
+
d: false,
|
|
563
|
+
i: 0,
|
|
564
|
+
c: Object.create(null)
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
if (state.d) return null;
|
|
568
|
+
state.d = true;
|
|
569
|
+
if (type === 1) t = hasOwn ? t[k] : t[k] = Object.create(null);
|
|
570
|
+
else if (type === 0 && hasOwn) return null;
|
|
571
|
+
return [
|
|
572
|
+
k,
|
|
573
|
+
t,
|
|
574
|
+
state.c
|
|
575
|
+
];
|
|
576
|
+
}
|
|
577
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
578
|
+
if (peek === null || ctx.uk === 2) TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
579
|
+
}
|
|
580
|
+
function parse(toml, options = {}) {
|
|
581
|
+
let ctx = {
|
|
582
|
+
s: toml,
|
|
583
|
+
p: 0,
|
|
584
|
+
d: options.maxDepth ?? 1e3,
|
|
585
|
+
bi: options.integersAsBigInt ?? false,
|
|
586
|
+
ld: options.useLegacyDate ?? true,
|
|
587
|
+
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
588
|
+
};
|
|
589
|
+
let res = Object.create(null);
|
|
590
|
+
let meta = Object.create(null);
|
|
591
|
+
let tmp;
|
|
592
|
+
let skipping = false;
|
|
593
|
+
let tbl = res;
|
|
594
|
+
let m = meta;
|
|
595
|
+
if (toml.charCodeAt(0) === 65279) ctx.p++;
|
|
596
|
+
skipVoid(ctx);
|
|
597
|
+
while (ctx.p < toml.length) {
|
|
598
|
+
if (toml.charCodeAt(ctx.p) === 91) {
|
|
599
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
600
|
+
tmp = ctx.p += +isTableArray;
|
|
601
|
+
skipping = false;
|
|
602
|
+
let k = parseKey(ctx, 93);
|
|
603
|
+
if (isTableArray) {
|
|
604
|
+
if (toml.charCodeAt(ctx.p) !== 93) TomlError.x("expected end of table array declaration", ctx);
|
|
605
|
+
ctx.p++;
|
|
606
|
+
}
|
|
607
|
+
let p = peekTable(ctx, k, res, meta, isTableArray ? 2 : 1);
|
|
608
|
+
if (!p) {
|
|
609
|
+
validateTablePeek(ctx, p, tmp);
|
|
610
|
+
skipping = true;
|
|
611
|
+
} else {
|
|
612
|
+
m = p[2];
|
|
613
|
+
tbl = p[1];
|
|
614
|
+
}
|
|
615
|
+
} else {
|
|
616
|
+
tmp = ctx.p;
|
|
617
|
+
let p = peekTable(ctx, parseKey(ctx), tbl, m, 0);
|
|
618
|
+
if (!p && !skipping) validateTablePeek(ctx, p, tmp);
|
|
619
|
+
skipVoid(ctx, true, true);
|
|
620
|
+
let v = extractValue(ctx, void 0);
|
|
621
|
+
if (p && !skipping) p[1][p[0]] = v;
|
|
622
|
+
}
|
|
623
|
+
skipVoid(ctx, true);
|
|
624
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
625
|
+
skipVoid(ctx);
|
|
626
|
+
}
|
|
627
|
+
return res;
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/stringify.ts
|
|
631
|
+
let BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
632
|
+
let HAS_WELLFORMED = !!"".isWellFormed;
|
|
633
|
+
function extendedTypeOf(obj) {
|
|
634
|
+
let type = typeof obj;
|
|
635
|
+
if (type === "object") {
|
|
636
|
+
if (Array.isArray(obj)) return "array";
|
|
637
|
+
if (typeof obj.getUTCDate === "function" && obj instanceof Date) return "date";
|
|
638
|
+
if (globalThis.Temporal) {
|
|
639
|
+
if (obj.until) {
|
|
640
|
+
if (obj instanceof Temporal.ZonedDateTime) return "temporal/tz+uc";
|
|
641
|
+
if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate) return "temporal/uc";
|
|
642
|
+
if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant) return "temporal";
|
|
643
|
+
if (obj instanceof Temporal.PlainYearMonth) return "temporal/x";
|
|
644
|
+
} else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) return "temporal/x";
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return type;
|
|
648
|
+
}
|
|
649
|
+
function isArrayOfTables(obj) {
|
|
650
|
+
for (let i = 0; i < obj.length; i++) if (extendedTypeOf(obj[i]) !== "object") return false;
|
|
651
|
+
return obj.length != 0;
|
|
652
|
+
}
|
|
653
|
+
function formatWellFormedStringUnchecked(s) {
|
|
654
|
+
return JSON.stringify(s).replaceAll("", "\\u007f");
|
|
655
|
+
}
|
|
656
|
+
function formatString(s) {
|
|
657
|
+
return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
|
|
658
|
+
}
|
|
659
|
+
function formatKey(s) {
|
|
660
|
+
if (BARE_KEY.test(s)) return s;
|
|
661
|
+
if (HAS_WELLFORMED && !s.isWellFormed()) throw new RangeError("key contains illegal lone surrogates");
|
|
662
|
+
return formatWellFormedStringUnchecked(s);
|
|
663
|
+
}
|
|
664
|
+
function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
|
|
665
|
+
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
666
|
+
switch (type) {
|
|
667
|
+
case "number":
|
|
668
|
+
if (isNaN(val)) return "nan";
|
|
669
|
+
if (val === Infinity) return "inf";
|
|
670
|
+
if (val === -Infinity) return "-inf";
|
|
671
|
+
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val))) return val.toFixed(1);
|
|
672
|
+
case "bigint":
|
|
673
|
+
case "boolean":
|
|
674
|
+
case "temporal": return val.toString();
|
|
675
|
+
case "string": return formatString(val);
|
|
676
|
+
case "date":
|
|
677
|
+
if (isNaN(val.getTime())) throw new TypeError("cannot serialize invalid date");
|
|
678
|
+
return val.toISOString();
|
|
679
|
+
case "object": return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
|
|
680
|
+
case "array": return stringifyArray(val, depth, numberAsFloat, strictTemporal);
|
|
681
|
+
case "temporal/tz+uc": if (strictTemporal) {
|
|
682
|
+
let tz = val.timeZoneId;
|
|
683
|
+
let tzc = tz.charCodeAt(0);
|
|
684
|
+
if (tzc !== 43 && tzc !== 45 && (tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || tz !== "UTC" && tz !== "UCT" && tz !== "Universal" && tz !== "Zulu" && !tz.startsWith("GMT") && tz !== "Greenwich" && !tz.startsWith("Etc/"))) throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
|
|
685
|
+
}
|
|
686
|
+
case "temporal/uc":
|
|
687
|
+
if (strictTemporal && val.calendarId !== "iso8601") throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
|
|
688
|
+
return val.toString({
|
|
689
|
+
calendarName: "never",
|
|
690
|
+
timeZoneName: "never"
|
|
691
|
+
});
|
|
692
|
+
case "temporal/x": throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
|
|
696
|
+
let keys = Object.keys(obj);
|
|
697
|
+
if (keys.length === 0) return "{}";
|
|
698
|
+
let res = "{ ";
|
|
699
|
+
for (let i = 0; i < keys.length; i++) {
|
|
700
|
+
let k = keys[i];
|
|
701
|
+
if (i) res += ", ";
|
|
702
|
+
res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
|
|
703
|
+
}
|
|
704
|
+
return res + " }";
|
|
705
|
+
}
|
|
706
|
+
function stringifyArray(array, depth, numberAsFloat, strictTemporal) {
|
|
707
|
+
if (array.length === 0) return "[]";
|
|
708
|
+
let res = "[ ";
|
|
709
|
+
for (let i = 0; i < array.length; i++) {
|
|
710
|
+
if (i) res += ", ";
|
|
711
|
+
if (array[i] === null || array[i] === void 0) throw new TypeError("arrays cannot contain null or undefined values");
|
|
712
|
+
res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
713
|
+
}
|
|
714
|
+
return res + " ]";
|
|
715
|
+
}
|
|
716
|
+
function stringifyArrayTable(array, key, depth, numberAsFloat, strictTemporal) {
|
|
717
|
+
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
718
|
+
let res = "";
|
|
719
|
+
for (let i = 0; i < array.length; i++) {
|
|
720
|
+
res += `${res && "\n"}[[${key}]]\n`;
|
|
721
|
+
res += stringifyTable(0, array[i], key, depth, numberAsFloat, strictTemporal);
|
|
722
|
+
}
|
|
723
|
+
return res;
|
|
724
|
+
}
|
|
725
|
+
function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
|
|
726
|
+
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
727
|
+
let preamble = "";
|
|
728
|
+
let tables = "";
|
|
729
|
+
let keys = Object.keys(obj);
|
|
730
|
+
for (let i = 0; i < keys.length; i++) {
|
|
731
|
+
let k = keys[i];
|
|
732
|
+
if (obj[k] !== null && obj[k] !== void 0) {
|
|
733
|
+
let type = extendedTypeOf(obj[k]);
|
|
734
|
+
if (type === "symbol" || type === "function") throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
735
|
+
let key = formatKey(k);
|
|
736
|
+
if (type === "array" && isArrayOfTables(obj[k])) tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
|
|
737
|
+
else if (type === "object") {
|
|
738
|
+
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
739
|
+
tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
|
|
740
|
+
} else {
|
|
741
|
+
preamble += key;
|
|
742
|
+
preamble += " = ";
|
|
743
|
+
preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
|
|
744
|
+
preamble += "\n";
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (tableKey && (preamble || !tables)) preamble = preamble ? `[${tableKey}]\n${preamble}` : `[${tableKey}]`;
|
|
749
|
+
return preamble && tables ? `${preamble}\n${tables}` : preamble || tables;
|
|
750
|
+
}
|
|
751
|
+
function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
|
|
752
|
+
if (extendedTypeOf(obj) !== "object") throw new TypeError("stringify can only be called with an object");
|
|
753
|
+
let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
|
|
754
|
+
if (str[str.length - 1] !== "\n") return str + "\n";
|
|
755
|
+
return str;
|
|
756
|
+
}
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region src/index.ts
|
|
759
|
+
/** @deprecated use `import * as ... from 'smol-toml'` instead */
|
|
760
|
+
var src_default = {
|
|
761
|
+
parse,
|
|
762
|
+
stringify,
|
|
763
|
+
TomlDate,
|
|
764
|
+
TomlError
|
|
765
|
+
};
|
|
766
|
+
//#endregion
|
|
767
|
+
exports.TomlDate = TomlDate;
|
|
768
|
+
exports.TomlError = TomlError;
|
|
769
|
+
exports.default = src_default;
|
|
770
|
+
exports.parse = parse;
|
|
771
|
+
exports.stringify = stringify;
|