@cloudflare/config 0.8.0 → 0.10.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/dist/index.d.mts +16 -9
- package/dist/index.mjs +29 -2457
- package/dist/{public-C3uXDKsB.d.mts → public-DZgNmLyp.d.mts} +26 -20
- package/dist/public.d.mts +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { a as triggers, i as exports$1, n as defineWorker, o as bindings, r as resolveExportDefinition, t as defineSettings } from "./public-BwQqexwo.mjs";
|
|
2
2
|
import * as nodeModule from "node:module";
|
|
3
3
|
import * as z from "zod";
|
|
4
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
|
-
import path2__default, { dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
6
|
|
|
@@ -35,7 +33,7 @@ const BrowserBindingSchema = z.strictObject({
|
|
|
35
33
|
});
|
|
36
34
|
const WorkerBindingSchema = z.strictObject({
|
|
37
35
|
type: z.literal("worker"),
|
|
38
|
-
|
|
36
|
+
worker: z.string(),
|
|
39
37
|
exportName: z.string().optional(),
|
|
40
38
|
props: z.record(z.string(), z.unknown()).optional(),
|
|
41
39
|
dev: RemoteBindingDevSchema.optional()
|
|
@@ -113,14 +111,14 @@ const KnownBindingSchema = z.discriminatedUnion("type", [
|
|
|
113
111
|
type: z.literal("dispatch-namespace"),
|
|
114
112
|
namespace: z.string().optional(),
|
|
115
113
|
outbound: z.strictObject({
|
|
116
|
-
|
|
114
|
+
worker: z.string(),
|
|
117
115
|
parameters: z.array(z.string()).optional()
|
|
118
116
|
}).optional(),
|
|
119
117
|
dev: RemoteBindingDevSchema.optional()
|
|
120
118
|
}),
|
|
121
119
|
z.strictObject({
|
|
122
120
|
type: z.literal("durable-object"),
|
|
123
|
-
|
|
121
|
+
worker: z.string(),
|
|
124
122
|
exportName: z.string()
|
|
125
123
|
}),
|
|
126
124
|
FlagshipBindingSchema,
|
|
@@ -317,6 +315,7 @@ const LimitsSchema = z.strictObject({
|
|
|
317
315
|
const ObservabilitySchema = z.strictObject({
|
|
318
316
|
enabled: z.boolean().optional(),
|
|
319
317
|
headSamplingRate: z.number().optional(),
|
|
318
|
+
redactQueryString: z.boolean().optional(),
|
|
320
319
|
logs: z.strictObject({
|
|
321
320
|
enabled: z.boolean().optional(),
|
|
322
321
|
headSamplingRate: z.number().optional(),
|
|
@@ -350,7 +349,7 @@ const PlacementSchema = z.union([
|
|
|
350
349
|
})
|
|
351
350
|
]);
|
|
352
351
|
const TailConsumerSchema = z.strictObject({
|
|
353
|
-
|
|
352
|
+
worker: z.string(),
|
|
354
353
|
streaming: z.boolean().optional()
|
|
355
354
|
});
|
|
356
355
|
const TriggerSchema = z.discriminatedUnion("type", [
|
|
@@ -496,9 +495,23 @@ const ModuleTypeSchema = z.enum([
|
|
|
496
495
|
"json",
|
|
497
496
|
"sourcemap"
|
|
498
497
|
]);
|
|
498
|
+
const ManifestModulesSchema = z.record(z.string(), z.strictObject({ type: ModuleTypeSchema }));
|
|
499
499
|
const ManifestSchema = z.strictObject({
|
|
500
|
+
type: z.enum(["partial", "complete"]),
|
|
500
501
|
mainModule: z.string(),
|
|
501
|
-
modules:
|
|
502
|
+
modules: ManifestModulesSchema
|
|
503
|
+
}).superRefine((manifest, ctx) => {
|
|
504
|
+
const mainModuleEntry = manifest.modules[manifest.mainModule];
|
|
505
|
+
if (manifest.type === "complete" && mainModuleEntry === void 0) ctx.addIssue({
|
|
506
|
+
code: "custom",
|
|
507
|
+
path: ["modules", manifest.mainModule],
|
|
508
|
+
message: "A complete manifest must include its main module."
|
|
509
|
+
});
|
|
510
|
+
if (manifest.type === "partial" && mainModuleEntry !== void 0) ctx.addIssue({
|
|
511
|
+
code: "custom",
|
|
512
|
+
path: ["modules", manifest.mainModule],
|
|
513
|
+
message: "A partial manifest must not include its main module."
|
|
514
|
+
});
|
|
502
515
|
});
|
|
503
516
|
/**
|
|
504
517
|
* Output Worker schema — the shape of the Worker's `config.json` in the
|
|
@@ -512,7 +525,7 @@ const OutputWorkerSchema = BaseWorkerSchema.extend({ manifest: ManifestSchema.op
|
|
|
512
525
|
var require_dist = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ts-dedent@2.2.0/node_modules/ts-dedent/dist/index.js": ((exports) => {
|
|
513
526
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
514
527
|
exports.dedent = void 0;
|
|
515
|
-
function dedent$
|
|
528
|
+
function dedent$1(templ) {
|
|
516
529
|
var values = [];
|
|
517
530
|
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
518
531
|
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
@@ -544,7 +557,7 @@ var require_dist = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ts-ded
|
|
|
544
557
|
});
|
|
545
558
|
return string;
|
|
546
559
|
}
|
|
547
|
-
exports.dedent = dedent$
|
|
560
|
+
exports.dedent = dedent$1;
|
|
548
561
|
}) });
|
|
549
562
|
|
|
550
563
|
//#endregion
|
|
@@ -593,54 +606,7 @@ var __name = (target, value) => __defProp(target, "name", {
|
|
|
593
606
|
});
|
|
594
607
|
|
|
595
608
|
//#endregion
|
|
596
|
-
//#region ../workers-utils/dist/chunk-
|
|
597
|
-
function hasKnownExportType(entry) {
|
|
598
|
-
const type = entry?.type;
|
|
599
|
-
return type === "durable-object" || type === "worker";
|
|
600
|
-
}
|
|
601
|
-
__name(hasKnownExportType, "hasKnownExportType");
|
|
602
|
-
function partitionExports(exports$1$1) {
|
|
603
|
-
const partitioned = {
|
|
604
|
-
"durable-object": {},
|
|
605
|
-
worker: {}
|
|
606
|
-
};
|
|
607
|
-
if (exports$1$1 === void 0) return partitioned;
|
|
608
|
-
for (const [name, entry] of Object.entries(exports$1$1)) {
|
|
609
|
-
if (!hasKnownExportType(entry)) continue;
|
|
610
|
-
partitioned[entry.type][name] = entry;
|
|
611
|
-
}
|
|
612
|
-
return partitioned;
|
|
613
|
-
}
|
|
614
|
-
__name(partitionExports, "partitionExports");
|
|
615
|
-
function getDurableObjectExports(exports$1$1) {
|
|
616
|
-
return partitionExports(exports$1$1)["durable-object"];
|
|
617
|
-
}
|
|
618
|
-
__name(getDurableObjectExports, "getDurableObjectExports");
|
|
619
|
-
function hasDurableObjectExports(exports$1$1) {
|
|
620
|
-
return Object.keys(getDurableObjectExports(exports$1$1)).length > 0;
|
|
621
|
-
}
|
|
622
|
-
__name(hasDurableObjectExports, "hasDurableObjectExports");
|
|
623
|
-
function getContainerNameToClassNameMap(exports$1$1) {
|
|
624
|
-
const containerNameToClassName = /* @__PURE__ */ new Map();
|
|
625
|
-
for (const [className, entry] of Object.entries(getDurableObjectExports(exports$1$1))) if ("container" in entry && typeof entry.container === "string" && !containerNameToClassName.has(entry.container)) containerNameToClassName.set(entry.container, className);
|
|
626
|
-
return containerNameToClassName;
|
|
627
|
-
}
|
|
628
|
-
__name(getContainerNameToClassNameMap, "getContainerNameToClassNameMap");
|
|
629
|
-
function resolveContainerClassName(container, exports$1$1) {
|
|
630
|
-
if (container.class_name !== void 0) return container.class_name;
|
|
631
|
-
if (container.name === void 0) return;
|
|
632
|
-
return getContainerNameToClassNameMap(exports$1$1).get(container.name);
|
|
633
|
-
}
|
|
634
|
-
__name(resolveContainerClassName, "resolveContainerClassName");
|
|
635
|
-
function getContainerDurableObjectClassNames(containers, exports$1$1) {
|
|
636
|
-
const classNames = /* @__PURE__ */ new Set();
|
|
637
|
-
for (const container of containers ?? []) {
|
|
638
|
-
const className = resolveContainerClassName(container, exports$1$1);
|
|
639
|
-
if (className !== void 0) classNames.add(className);
|
|
640
|
-
}
|
|
641
|
-
return classNames;
|
|
642
|
-
}
|
|
643
|
-
__name(getContainerDurableObjectClassNames, "getContainerDurableObjectClassNames");
|
|
609
|
+
//#region ../workers-utils/dist/chunk-WO2IAW6M.mjs
|
|
644
610
|
var UserError = class extends Error {
|
|
645
611
|
static {
|
|
646
612
|
__name(this, "UserError");
|
|
@@ -696,2401 +662,6 @@ function createFatalError(message, isJson, options) {
|
|
|
696
662
|
return new FatalError(`${message}`, options);
|
|
697
663
|
}
|
|
698
664
|
__name(createFatalError, "createFatalError");
|
|
699
|
-
function createScanner(text, ignoreTrivia = false) {
|
|
700
|
-
const len = text.length;
|
|
701
|
-
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
702
|
-
function scanHexDigits(count, exact) {
|
|
703
|
-
let digits = 0;
|
|
704
|
-
let value2 = 0;
|
|
705
|
-
while (digits < count || !exact) {
|
|
706
|
-
let ch = text.charCodeAt(pos);
|
|
707
|
-
if (ch >= 48 && ch <= 57) value2 = value2 * 16 + ch - 48;
|
|
708
|
-
else if (ch >= 65 && ch <= 70) value2 = value2 * 16 + ch - 65 + 10;
|
|
709
|
-
else if (ch >= 97 && ch <= 102) value2 = value2 * 16 + ch - 97 + 10;
|
|
710
|
-
else break;
|
|
711
|
-
pos++;
|
|
712
|
-
digits++;
|
|
713
|
-
}
|
|
714
|
-
if (digits < count) value2 = -1;
|
|
715
|
-
return value2;
|
|
716
|
-
}
|
|
717
|
-
__name(scanHexDigits, "scanHexDigits");
|
|
718
|
-
function setPosition(newPosition) {
|
|
719
|
-
pos = newPosition;
|
|
720
|
-
value = "";
|
|
721
|
-
tokenOffset = 0;
|
|
722
|
-
token = 16;
|
|
723
|
-
scanError = 0;
|
|
724
|
-
}
|
|
725
|
-
__name(setPosition, "setPosition");
|
|
726
|
-
function scanNumber() {
|
|
727
|
-
let start = pos;
|
|
728
|
-
if (text.charCodeAt(pos) === 48) pos++;
|
|
729
|
-
else {
|
|
730
|
-
pos++;
|
|
731
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
732
|
-
}
|
|
733
|
-
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
734
|
-
pos++;
|
|
735
|
-
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
736
|
-
pos++;
|
|
737
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
738
|
-
} else {
|
|
739
|
-
scanError = 3;
|
|
740
|
-
return text.substring(start, pos);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
let end = pos;
|
|
744
|
-
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
745
|
-
pos++;
|
|
746
|
-
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) pos++;
|
|
747
|
-
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
748
|
-
pos++;
|
|
749
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
750
|
-
end = pos;
|
|
751
|
-
} else scanError = 3;
|
|
752
|
-
}
|
|
753
|
-
return text.substring(start, end);
|
|
754
|
-
}
|
|
755
|
-
__name(scanNumber, "scanNumber");
|
|
756
|
-
function scanString() {
|
|
757
|
-
let result = "", start = pos;
|
|
758
|
-
while (true) {
|
|
759
|
-
if (pos >= len) {
|
|
760
|
-
result += text.substring(start, pos);
|
|
761
|
-
scanError = 2;
|
|
762
|
-
break;
|
|
763
|
-
}
|
|
764
|
-
const ch = text.charCodeAt(pos);
|
|
765
|
-
if (ch === 34) {
|
|
766
|
-
result += text.substring(start, pos);
|
|
767
|
-
pos++;
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
|
-
if (ch === 92) {
|
|
771
|
-
result += text.substring(start, pos);
|
|
772
|
-
pos++;
|
|
773
|
-
if (pos >= len) {
|
|
774
|
-
scanError = 2;
|
|
775
|
-
break;
|
|
776
|
-
}
|
|
777
|
-
switch (text.charCodeAt(pos++)) {
|
|
778
|
-
case 34:
|
|
779
|
-
result += "\"";
|
|
780
|
-
break;
|
|
781
|
-
case 92:
|
|
782
|
-
result += "\\";
|
|
783
|
-
break;
|
|
784
|
-
case 47:
|
|
785
|
-
result += "/";
|
|
786
|
-
break;
|
|
787
|
-
case 98:
|
|
788
|
-
result += "\b";
|
|
789
|
-
break;
|
|
790
|
-
case 102:
|
|
791
|
-
result += "\f";
|
|
792
|
-
break;
|
|
793
|
-
case 110:
|
|
794
|
-
result += "\n";
|
|
795
|
-
break;
|
|
796
|
-
case 114:
|
|
797
|
-
result += "\r";
|
|
798
|
-
break;
|
|
799
|
-
case 116:
|
|
800
|
-
result += " ";
|
|
801
|
-
break;
|
|
802
|
-
case 117:
|
|
803
|
-
const ch3 = scanHexDigits(4, true);
|
|
804
|
-
if (ch3 >= 0) result += String.fromCharCode(ch3);
|
|
805
|
-
else scanError = 4;
|
|
806
|
-
break;
|
|
807
|
-
default: scanError = 5;
|
|
808
|
-
}
|
|
809
|
-
start = pos;
|
|
810
|
-
continue;
|
|
811
|
-
}
|
|
812
|
-
if (ch >= 0 && ch <= 31) if (isLineBreak(ch)) {
|
|
813
|
-
result += text.substring(start, pos);
|
|
814
|
-
scanError = 2;
|
|
815
|
-
break;
|
|
816
|
-
} else scanError = 6;
|
|
817
|
-
pos++;
|
|
818
|
-
}
|
|
819
|
-
return result;
|
|
820
|
-
}
|
|
821
|
-
__name(scanString, "scanString");
|
|
822
|
-
function scanNext() {
|
|
823
|
-
value = "";
|
|
824
|
-
scanError = 0;
|
|
825
|
-
tokenOffset = pos;
|
|
826
|
-
lineStartOffset = lineNumber;
|
|
827
|
-
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
828
|
-
if (pos >= len) {
|
|
829
|
-
tokenOffset = len;
|
|
830
|
-
return token = 17;
|
|
831
|
-
}
|
|
832
|
-
let code = text.charCodeAt(pos);
|
|
833
|
-
if (isWhiteSpace(code)) {
|
|
834
|
-
do {
|
|
835
|
-
pos++;
|
|
836
|
-
value += String.fromCharCode(code);
|
|
837
|
-
code = text.charCodeAt(pos);
|
|
838
|
-
} while (isWhiteSpace(code));
|
|
839
|
-
return token = 15;
|
|
840
|
-
}
|
|
841
|
-
if (isLineBreak(code)) {
|
|
842
|
-
pos++;
|
|
843
|
-
value += String.fromCharCode(code);
|
|
844
|
-
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
845
|
-
pos++;
|
|
846
|
-
value += "\n";
|
|
847
|
-
}
|
|
848
|
-
lineNumber++;
|
|
849
|
-
tokenLineStartOffset = pos;
|
|
850
|
-
return token = 14;
|
|
851
|
-
}
|
|
852
|
-
switch (code) {
|
|
853
|
-
case 123:
|
|
854
|
-
pos++;
|
|
855
|
-
return token = 1;
|
|
856
|
-
case 125:
|
|
857
|
-
pos++;
|
|
858
|
-
return token = 2;
|
|
859
|
-
case 91:
|
|
860
|
-
pos++;
|
|
861
|
-
return token = 3;
|
|
862
|
-
case 93:
|
|
863
|
-
pos++;
|
|
864
|
-
return token = 4;
|
|
865
|
-
case 58:
|
|
866
|
-
pos++;
|
|
867
|
-
return token = 6;
|
|
868
|
-
case 44:
|
|
869
|
-
pos++;
|
|
870
|
-
return token = 5;
|
|
871
|
-
case 34:
|
|
872
|
-
pos++;
|
|
873
|
-
value = scanString();
|
|
874
|
-
return token = 10;
|
|
875
|
-
case 47:
|
|
876
|
-
const start = pos - 1;
|
|
877
|
-
if (text.charCodeAt(pos + 1) === 47) {
|
|
878
|
-
pos += 2;
|
|
879
|
-
while (pos < len) {
|
|
880
|
-
if (isLineBreak(text.charCodeAt(pos))) break;
|
|
881
|
-
pos++;
|
|
882
|
-
}
|
|
883
|
-
value = text.substring(start, pos);
|
|
884
|
-
return token = 12;
|
|
885
|
-
}
|
|
886
|
-
if (text.charCodeAt(pos + 1) === 42) {
|
|
887
|
-
pos += 2;
|
|
888
|
-
const safeLength = len - 1;
|
|
889
|
-
let commentClosed = false;
|
|
890
|
-
while (pos < safeLength) {
|
|
891
|
-
const ch = text.charCodeAt(pos);
|
|
892
|
-
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
893
|
-
pos += 2;
|
|
894
|
-
commentClosed = true;
|
|
895
|
-
break;
|
|
896
|
-
}
|
|
897
|
-
pos++;
|
|
898
|
-
if (isLineBreak(ch)) {
|
|
899
|
-
if (ch === 13 && text.charCodeAt(pos) === 10) pos++;
|
|
900
|
-
lineNumber++;
|
|
901
|
-
tokenLineStartOffset = pos;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
if (!commentClosed) {
|
|
905
|
-
pos++;
|
|
906
|
-
scanError = 1;
|
|
907
|
-
}
|
|
908
|
-
value = text.substring(start, pos);
|
|
909
|
-
return token = 13;
|
|
910
|
-
}
|
|
911
|
-
value += String.fromCharCode(code);
|
|
912
|
-
pos++;
|
|
913
|
-
return token = 16;
|
|
914
|
-
case 45:
|
|
915
|
-
value += String.fromCharCode(code);
|
|
916
|
-
pos++;
|
|
917
|
-
if (pos === len || !isDigit(text.charCodeAt(pos))) return token = 16;
|
|
918
|
-
case 48:
|
|
919
|
-
case 49:
|
|
920
|
-
case 50:
|
|
921
|
-
case 51:
|
|
922
|
-
case 52:
|
|
923
|
-
case 53:
|
|
924
|
-
case 54:
|
|
925
|
-
case 55:
|
|
926
|
-
case 56:
|
|
927
|
-
case 57:
|
|
928
|
-
value += scanNumber();
|
|
929
|
-
return token = 11;
|
|
930
|
-
default:
|
|
931
|
-
while (pos < len && isUnknownContentCharacter(code)) {
|
|
932
|
-
pos++;
|
|
933
|
-
code = text.charCodeAt(pos);
|
|
934
|
-
}
|
|
935
|
-
if (tokenOffset !== pos) {
|
|
936
|
-
value = text.substring(tokenOffset, pos);
|
|
937
|
-
switch (value) {
|
|
938
|
-
case "true": return token = 8;
|
|
939
|
-
case "false": return token = 9;
|
|
940
|
-
case "null": return token = 7;
|
|
941
|
-
}
|
|
942
|
-
return token = 16;
|
|
943
|
-
}
|
|
944
|
-
value += String.fromCharCode(code);
|
|
945
|
-
pos++;
|
|
946
|
-
return token = 16;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
__name(scanNext, "scanNext");
|
|
950
|
-
function isUnknownContentCharacter(code) {
|
|
951
|
-
if (isWhiteSpace(code) || isLineBreak(code)) return false;
|
|
952
|
-
switch (code) {
|
|
953
|
-
case 125:
|
|
954
|
-
case 93:
|
|
955
|
-
case 123:
|
|
956
|
-
case 91:
|
|
957
|
-
case 34:
|
|
958
|
-
case 58:
|
|
959
|
-
case 44:
|
|
960
|
-
case 47: return false;
|
|
961
|
-
}
|
|
962
|
-
return true;
|
|
963
|
-
}
|
|
964
|
-
__name(isUnknownContentCharacter, "isUnknownContentCharacter");
|
|
965
|
-
function scanNextNonTrivia() {
|
|
966
|
-
let result;
|
|
967
|
-
do
|
|
968
|
-
result = scanNext();
|
|
969
|
-
while (result >= 12 && result <= 15);
|
|
970
|
-
return result;
|
|
971
|
-
}
|
|
972
|
-
__name(scanNextNonTrivia, "scanNextNonTrivia");
|
|
973
|
-
return {
|
|
974
|
-
setPosition,
|
|
975
|
-
getPosition: /* @__PURE__ */ __name(() => pos, "getPosition"),
|
|
976
|
-
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
977
|
-
getToken: /* @__PURE__ */ __name(() => token, "getToken"),
|
|
978
|
-
getTokenValue: /* @__PURE__ */ __name(() => value, "getTokenValue"),
|
|
979
|
-
getTokenOffset: /* @__PURE__ */ __name(() => tokenOffset, "getTokenOffset"),
|
|
980
|
-
getTokenLength: /* @__PURE__ */ __name(() => pos - tokenOffset, "getTokenLength"),
|
|
981
|
-
getTokenStartLine: /* @__PURE__ */ __name(() => lineStartOffset, "getTokenStartLine"),
|
|
982
|
-
getTokenStartCharacter: /* @__PURE__ */ __name(() => tokenOffset - prevTokenLineStartOffset, "getTokenStartCharacter"),
|
|
983
|
-
getTokenError: /* @__PURE__ */ __name(() => scanError, "getTokenError")
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
__name(createScanner, "createScanner");
|
|
987
|
-
function isWhiteSpace(ch) {
|
|
988
|
-
return ch === 32 || ch === 9;
|
|
989
|
-
}
|
|
990
|
-
__name(isWhiteSpace, "isWhiteSpace");
|
|
991
|
-
function isLineBreak(ch) {
|
|
992
|
-
return ch === 10 || ch === 13;
|
|
993
|
-
}
|
|
994
|
-
__name(isLineBreak, "isLineBreak");
|
|
995
|
-
function isDigit(ch) {
|
|
996
|
-
return ch >= 48 && ch <= 57;
|
|
997
|
-
}
|
|
998
|
-
__name(isDigit, "isDigit");
|
|
999
|
-
var CharacterCodes;
|
|
1000
|
-
(function(CharacterCodes2) {
|
|
1001
|
-
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
1002
|
-
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
1003
|
-
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
1004
|
-
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
1005
|
-
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
1006
|
-
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
1007
|
-
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
1008
|
-
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
1009
|
-
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
1010
|
-
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
1011
|
-
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
1012
|
-
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
1013
|
-
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
1014
|
-
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
1015
|
-
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
1016
|
-
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
1017
|
-
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
1018
|
-
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
1019
|
-
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
1020
|
-
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
1021
|
-
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
1022
|
-
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
1023
|
-
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
1024
|
-
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
1025
|
-
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
1026
|
-
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
1027
|
-
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
1028
|
-
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
1029
|
-
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
1030
|
-
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
1031
|
-
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
1032
|
-
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
1033
|
-
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
1034
|
-
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
1035
|
-
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
1036
|
-
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
1037
|
-
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
1038
|
-
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
1039
|
-
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
1040
|
-
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
1041
|
-
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
1042
|
-
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
1043
|
-
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
1044
|
-
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
1045
|
-
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
1046
|
-
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
1047
|
-
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
1048
|
-
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
1049
|
-
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
1050
|
-
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
1051
|
-
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
1052
|
-
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
1053
|
-
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
1054
|
-
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
1055
|
-
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
1056
|
-
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
1057
|
-
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
1058
|
-
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
1059
|
-
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
1060
|
-
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
1061
|
-
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
1062
|
-
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
1063
|
-
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
1064
|
-
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
1065
|
-
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
1066
|
-
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
1067
|
-
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
1068
|
-
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
1069
|
-
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
1070
|
-
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
1071
|
-
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
1072
|
-
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
1073
|
-
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
1074
|
-
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
1075
|
-
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
1076
|
-
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
1077
|
-
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
1078
|
-
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
1079
|
-
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
1080
|
-
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
1081
|
-
})(CharacterCodes || (CharacterCodes = {}));
|
|
1082
|
-
function format(documentText, range, options) {
|
|
1083
|
-
let initialIndentLevel;
|
|
1084
|
-
let formatText;
|
|
1085
|
-
let formatTextStart;
|
|
1086
|
-
let rangeStart;
|
|
1087
|
-
let rangeEnd;
|
|
1088
|
-
if (range) {
|
|
1089
|
-
rangeStart = range.offset;
|
|
1090
|
-
rangeEnd = rangeStart + range.length;
|
|
1091
|
-
formatTextStart = rangeStart;
|
|
1092
|
-
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) formatTextStart--;
|
|
1093
|
-
let endOffset = rangeEnd;
|
|
1094
|
-
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) endOffset++;
|
|
1095
|
-
formatText = documentText.substring(formatTextStart, endOffset);
|
|
1096
|
-
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
1097
|
-
} else {
|
|
1098
|
-
formatText = documentText;
|
|
1099
|
-
initialIndentLevel = 0;
|
|
1100
|
-
formatTextStart = 0;
|
|
1101
|
-
rangeStart = 0;
|
|
1102
|
-
rangeEnd = documentText.length;
|
|
1103
|
-
}
|
|
1104
|
-
const eol = getEOL(options, documentText);
|
|
1105
|
-
let numberLineBreaks = 0;
|
|
1106
|
-
let indentLevel = 0;
|
|
1107
|
-
let indentValue;
|
|
1108
|
-
if (options.insertSpaces) indentValue = repeat(" ", options.tabSize || 4);
|
|
1109
|
-
else indentValue = " ";
|
|
1110
|
-
let scanner = createScanner(formatText, false);
|
|
1111
|
-
let hasError = false;
|
|
1112
|
-
function newLinesAndIndent() {
|
|
1113
|
-
if (numberLineBreaks > 1) return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
1114
|
-
else return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
1115
|
-
}
|
|
1116
|
-
__name(newLinesAndIndent, "newLinesAndIndent");
|
|
1117
|
-
function scanNext() {
|
|
1118
|
-
let token = scanner.scan();
|
|
1119
|
-
numberLineBreaks = 0;
|
|
1120
|
-
while (token === 15 || token === 14) {
|
|
1121
|
-
if (token === 14 && options.keepLines) numberLineBreaks += 1;
|
|
1122
|
-
else if (token === 14) numberLineBreaks = 1;
|
|
1123
|
-
token = scanner.scan();
|
|
1124
|
-
}
|
|
1125
|
-
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
1126
|
-
return token;
|
|
1127
|
-
}
|
|
1128
|
-
__name(scanNext, "scanNext");
|
|
1129
|
-
const editOperations = [];
|
|
1130
|
-
function addEdit(text, startOffset, endOffset) {
|
|
1131
|
-
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) editOperations.push({
|
|
1132
|
-
offset: startOffset,
|
|
1133
|
-
length: endOffset - startOffset,
|
|
1134
|
-
content: text
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
__name(addEdit, "addEdit");
|
|
1138
|
-
let firstToken = scanNext();
|
|
1139
|
-
if (options.keepLines && numberLineBreaks > 0) addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
1140
|
-
if (firstToken !== 17) {
|
|
1141
|
-
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1142
|
-
addEdit(repeat(indentValue, initialIndentLevel), formatTextStart, firstTokenStart);
|
|
1143
|
-
}
|
|
1144
|
-
while (firstToken !== 17) {
|
|
1145
|
-
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
1146
|
-
let secondToken = scanNext();
|
|
1147
|
-
let replaceContent = "";
|
|
1148
|
-
let needsLineBreak = false;
|
|
1149
|
-
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
1150
|
-
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1151
|
-
addEdit(" ", firstTokenEnd, commentTokenStart);
|
|
1152
|
-
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
1153
|
-
needsLineBreak = secondToken === 12;
|
|
1154
|
-
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
1155
|
-
secondToken = scanNext();
|
|
1156
|
-
}
|
|
1157
|
-
if (secondToken === 2) {
|
|
1158
|
-
if (firstToken !== 1) indentLevel--;
|
|
1159
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) replaceContent = newLinesAndIndent();
|
|
1160
|
-
else if (options.keepLines) replaceContent = " ";
|
|
1161
|
-
} else if (secondToken === 4) {
|
|
1162
|
-
if (firstToken !== 3) indentLevel--;
|
|
1163
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) replaceContent = newLinesAndIndent();
|
|
1164
|
-
else if (options.keepLines) replaceContent = " ";
|
|
1165
|
-
} else {
|
|
1166
|
-
switch (firstToken) {
|
|
1167
|
-
case 3:
|
|
1168
|
-
case 1:
|
|
1169
|
-
indentLevel++;
|
|
1170
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) replaceContent = newLinesAndIndent();
|
|
1171
|
-
else replaceContent = " ";
|
|
1172
|
-
break;
|
|
1173
|
-
case 5:
|
|
1174
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) replaceContent = newLinesAndIndent();
|
|
1175
|
-
else replaceContent = " ";
|
|
1176
|
-
break;
|
|
1177
|
-
case 12:
|
|
1178
|
-
replaceContent = newLinesAndIndent();
|
|
1179
|
-
break;
|
|
1180
|
-
case 13:
|
|
1181
|
-
if (numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
1182
|
-
else if (!needsLineBreak) replaceContent = " ";
|
|
1183
|
-
break;
|
|
1184
|
-
case 6:
|
|
1185
|
-
if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
1186
|
-
else if (!needsLineBreak) replaceContent = " ";
|
|
1187
|
-
break;
|
|
1188
|
-
case 10:
|
|
1189
|
-
if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
1190
|
-
else if (secondToken === 6 && !needsLineBreak) replaceContent = "";
|
|
1191
|
-
break;
|
|
1192
|
-
case 7:
|
|
1193
|
-
case 8:
|
|
1194
|
-
case 9:
|
|
1195
|
-
case 11:
|
|
1196
|
-
case 2:
|
|
1197
|
-
case 4:
|
|
1198
|
-
if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
1199
|
-
else if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) replaceContent = " ";
|
|
1200
|
-
else if (secondToken !== 5 && secondToken !== 17) hasError = true;
|
|
1201
|
-
break;
|
|
1202
|
-
case 16:
|
|
1203
|
-
hasError = true;
|
|
1204
|
-
break;
|
|
1205
|
-
}
|
|
1206
|
-
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) replaceContent = newLinesAndIndent();
|
|
1207
|
-
}
|
|
1208
|
-
if (secondToken === 17) if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
1209
|
-
else replaceContent = options.insertFinalNewline ? eol : "";
|
|
1210
|
-
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1211
|
-
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
1212
|
-
firstToken = secondToken;
|
|
1213
|
-
}
|
|
1214
|
-
return editOperations;
|
|
1215
|
-
}
|
|
1216
|
-
__name(format, "format");
|
|
1217
|
-
function repeat(s, count) {
|
|
1218
|
-
let result = "";
|
|
1219
|
-
for (let i = 0; i < count; i++) result += s;
|
|
1220
|
-
return result;
|
|
1221
|
-
}
|
|
1222
|
-
__name(repeat, "repeat");
|
|
1223
|
-
function computeIndentLevel(content, options) {
|
|
1224
|
-
let i = 0;
|
|
1225
|
-
let nChars = 0;
|
|
1226
|
-
const tabSize = options.tabSize || 4;
|
|
1227
|
-
while (i < content.length) {
|
|
1228
|
-
let ch = content.charAt(i);
|
|
1229
|
-
if (ch === " ") nChars++;
|
|
1230
|
-
else if (ch === " ") nChars += tabSize;
|
|
1231
|
-
else break;
|
|
1232
|
-
i++;
|
|
1233
|
-
}
|
|
1234
|
-
return Math.floor(nChars / tabSize);
|
|
1235
|
-
}
|
|
1236
|
-
__name(computeIndentLevel, "computeIndentLevel");
|
|
1237
|
-
function getEOL(options, text) {
|
|
1238
|
-
for (let i = 0; i < text.length; i++) {
|
|
1239
|
-
const ch = text.charAt(i);
|
|
1240
|
-
if (ch === "\r") {
|
|
1241
|
-
if (i + 1 < text.length && text.charAt(i + 1) === "\n") return "\r\n";
|
|
1242
|
-
return "\r";
|
|
1243
|
-
} else if (ch === "\n") return "\n";
|
|
1244
|
-
}
|
|
1245
|
-
return options && options.eol || "\n";
|
|
1246
|
-
}
|
|
1247
|
-
__name(getEOL, "getEOL");
|
|
1248
|
-
function isEOL(text, offset) {
|
|
1249
|
-
return "\r\n".indexOf(text.charAt(offset)) !== -1;
|
|
1250
|
-
}
|
|
1251
|
-
__name(isEOL, "isEOL");
|
|
1252
|
-
var ParseOptions;
|
|
1253
|
-
(function(ParseOptions2) {
|
|
1254
|
-
ParseOptions2.DEFAULT = { allowTrailingComma: false };
|
|
1255
|
-
})(ParseOptions || (ParseOptions = {}));
|
|
1256
|
-
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1257
|
-
let currentProperty = null;
|
|
1258
|
-
let currentParent = [];
|
|
1259
|
-
const previousParents = [];
|
|
1260
|
-
function onValue(value) {
|
|
1261
|
-
if (Array.isArray(currentParent)) currentParent.push(value);
|
|
1262
|
-
else if (currentProperty !== null) currentParent[currentProperty] = value;
|
|
1263
|
-
}
|
|
1264
|
-
__name(onValue, "onValue");
|
|
1265
|
-
visit(text, {
|
|
1266
|
-
onObjectBegin: /* @__PURE__ */ __name(() => {
|
|
1267
|
-
const object = {};
|
|
1268
|
-
onValue(object);
|
|
1269
|
-
previousParents.push(currentParent);
|
|
1270
|
-
currentParent = object;
|
|
1271
|
-
currentProperty = null;
|
|
1272
|
-
}, "onObjectBegin"),
|
|
1273
|
-
onObjectProperty: /* @__PURE__ */ __name((name) => {
|
|
1274
|
-
currentProperty = name;
|
|
1275
|
-
}, "onObjectProperty"),
|
|
1276
|
-
onObjectEnd: /* @__PURE__ */ __name(() => {
|
|
1277
|
-
currentParent = previousParents.pop();
|
|
1278
|
-
}, "onObjectEnd"),
|
|
1279
|
-
onArrayBegin: /* @__PURE__ */ __name(() => {
|
|
1280
|
-
const array = [];
|
|
1281
|
-
onValue(array);
|
|
1282
|
-
previousParents.push(currentParent);
|
|
1283
|
-
currentParent = array;
|
|
1284
|
-
currentProperty = null;
|
|
1285
|
-
}, "onArrayBegin"),
|
|
1286
|
-
onArrayEnd: /* @__PURE__ */ __name(() => {
|
|
1287
|
-
currentParent = previousParents.pop();
|
|
1288
|
-
}, "onArrayEnd"),
|
|
1289
|
-
onLiteralValue: onValue,
|
|
1290
|
-
onError: /* @__PURE__ */ __name((error, offset, length) => {
|
|
1291
|
-
errors.push({
|
|
1292
|
-
error,
|
|
1293
|
-
offset,
|
|
1294
|
-
length
|
|
1295
|
-
});
|
|
1296
|
-
}, "onError")
|
|
1297
|
-
}, options);
|
|
1298
|
-
return currentParent[0];
|
|
1299
|
-
}
|
|
1300
|
-
__name(parse, "parse");
|
|
1301
|
-
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1302
|
-
let currentParent = {
|
|
1303
|
-
type: "array",
|
|
1304
|
-
offset: -1,
|
|
1305
|
-
length: -1,
|
|
1306
|
-
children: [],
|
|
1307
|
-
parent: void 0
|
|
1308
|
-
};
|
|
1309
|
-
function ensurePropertyComplete(endOffset) {
|
|
1310
|
-
if (currentParent.type === "property") {
|
|
1311
|
-
currentParent.length = endOffset - currentParent.offset;
|
|
1312
|
-
currentParent = currentParent.parent;
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
__name(ensurePropertyComplete, "ensurePropertyComplete");
|
|
1316
|
-
function onValue(valueNode) {
|
|
1317
|
-
currentParent.children.push(valueNode);
|
|
1318
|
-
return valueNode;
|
|
1319
|
-
}
|
|
1320
|
-
__name(onValue, "onValue");
|
|
1321
|
-
visit(text, {
|
|
1322
|
-
onObjectBegin: /* @__PURE__ */ __name((offset) => {
|
|
1323
|
-
currentParent = onValue({
|
|
1324
|
-
type: "object",
|
|
1325
|
-
offset,
|
|
1326
|
-
length: -1,
|
|
1327
|
-
parent: currentParent,
|
|
1328
|
-
children: []
|
|
1329
|
-
});
|
|
1330
|
-
}, "onObjectBegin"),
|
|
1331
|
-
onObjectProperty: /* @__PURE__ */ __name((name, offset, length) => {
|
|
1332
|
-
currentParent = onValue({
|
|
1333
|
-
type: "property",
|
|
1334
|
-
offset,
|
|
1335
|
-
length: -1,
|
|
1336
|
-
parent: currentParent,
|
|
1337
|
-
children: []
|
|
1338
|
-
});
|
|
1339
|
-
currentParent.children.push({
|
|
1340
|
-
type: "string",
|
|
1341
|
-
value: name,
|
|
1342
|
-
offset,
|
|
1343
|
-
length,
|
|
1344
|
-
parent: currentParent
|
|
1345
|
-
});
|
|
1346
|
-
}, "onObjectProperty"),
|
|
1347
|
-
onObjectEnd: /* @__PURE__ */ __name((offset, length) => {
|
|
1348
|
-
ensurePropertyComplete(offset + length);
|
|
1349
|
-
currentParent.length = offset + length - currentParent.offset;
|
|
1350
|
-
currentParent = currentParent.parent;
|
|
1351
|
-
ensurePropertyComplete(offset + length);
|
|
1352
|
-
}, "onObjectEnd"),
|
|
1353
|
-
onArrayBegin: /* @__PURE__ */ __name((offset, length) => {
|
|
1354
|
-
currentParent = onValue({
|
|
1355
|
-
type: "array",
|
|
1356
|
-
offset,
|
|
1357
|
-
length: -1,
|
|
1358
|
-
parent: currentParent,
|
|
1359
|
-
children: []
|
|
1360
|
-
});
|
|
1361
|
-
}, "onArrayBegin"),
|
|
1362
|
-
onArrayEnd: /* @__PURE__ */ __name((offset, length) => {
|
|
1363
|
-
currentParent.length = offset + length - currentParent.offset;
|
|
1364
|
-
currentParent = currentParent.parent;
|
|
1365
|
-
ensurePropertyComplete(offset + length);
|
|
1366
|
-
}, "onArrayEnd"),
|
|
1367
|
-
onLiteralValue: /* @__PURE__ */ __name((value, offset, length) => {
|
|
1368
|
-
onValue({
|
|
1369
|
-
type: getNodeType(value),
|
|
1370
|
-
offset,
|
|
1371
|
-
length,
|
|
1372
|
-
parent: currentParent,
|
|
1373
|
-
value
|
|
1374
|
-
});
|
|
1375
|
-
ensurePropertyComplete(offset + length);
|
|
1376
|
-
}, "onLiteralValue"),
|
|
1377
|
-
onSeparator: /* @__PURE__ */ __name((sep, offset, length) => {
|
|
1378
|
-
if (currentParent.type === "property") {
|
|
1379
|
-
if (sep === ":") currentParent.colonOffset = offset;
|
|
1380
|
-
else if (sep === ",") ensurePropertyComplete(offset);
|
|
1381
|
-
}
|
|
1382
|
-
}, "onSeparator"),
|
|
1383
|
-
onError: /* @__PURE__ */ __name((error, offset, length) => {
|
|
1384
|
-
errors.push({
|
|
1385
|
-
error,
|
|
1386
|
-
offset,
|
|
1387
|
-
length
|
|
1388
|
-
});
|
|
1389
|
-
}, "onError")
|
|
1390
|
-
}, options);
|
|
1391
|
-
const result = currentParent.children[0];
|
|
1392
|
-
if (result) delete result.parent;
|
|
1393
|
-
return result;
|
|
1394
|
-
}
|
|
1395
|
-
__name(parseTree, "parseTree");
|
|
1396
|
-
function findNodeAtLocation(root, path2) {
|
|
1397
|
-
if (!root) return;
|
|
1398
|
-
let node = root;
|
|
1399
|
-
for (let segment of path2) if (typeof segment === "string") {
|
|
1400
|
-
if (node.type !== "object" || !Array.isArray(node.children)) return;
|
|
1401
|
-
let found = false;
|
|
1402
|
-
for (const propertyNode of node.children) if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1403
|
-
node = propertyNode.children[1];
|
|
1404
|
-
found = true;
|
|
1405
|
-
break;
|
|
1406
|
-
}
|
|
1407
|
-
if (!found) return;
|
|
1408
|
-
} else {
|
|
1409
|
-
const index = segment;
|
|
1410
|
-
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) return;
|
|
1411
|
-
node = node.children[index];
|
|
1412
|
-
}
|
|
1413
|
-
return node;
|
|
1414
|
-
}
|
|
1415
|
-
__name(findNodeAtLocation, "findNodeAtLocation");
|
|
1416
|
-
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1417
|
-
const _scanner = createScanner(text, false);
|
|
1418
|
-
const _jsonPath = [];
|
|
1419
|
-
function toNoArgVisit(visitFunction) {
|
|
1420
|
-
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1421
|
-
}
|
|
1422
|
-
__name(toNoArgVisit, "toNoArgVisit");
|
|
1423
|
-
function toNoArgVisitWithPath(visitFunction) {
|
|
1424
|
-
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1425
|
-
}
|
|
1426
|
-
__name(toNoArgVisitWithPath, "toNoArgVisitWithPath");
|
|
1427
|
-
function toOneArgVisit(visitFunction) {
|
|
1428
|
-
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1429
|
-
}
|
|
1430
|
-
__name(toOneArgVisit, "toOneArgVisit");
|
|
1431
|
-
function toOneArgVisitWithPath(visitFunction) {
|
|
1432
|
-
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1433
|
-
}
|
|
1434
|
-
__name(toOneArgVisitWithPath, "toOneArgVisitWithPath");
|
|
1435
|
-
const onObjectBegin = toNoArgVisitWithPath(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisitWithPath(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1436
|
-
const disallowComments = options && options.disallowComments;
|
|
1437
|
-
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1438
|
-
function scanNext() {
|
|
1439
|
-
while (true) {
|
|
1440
|
-
const token = _scanner.scan();
|
|
1441
|
-
switch (_scanner.getTokenError()) {
|
|
1442
|
-
case 4:
|
|
1443
|
-
handleError(14);
|
|
1444
|
-
break;
|
|
1445
|
-
case 5:
|
|
1446
|
-
handleError(15);
|
|
1447
|
-
break;
|
|
1448
|
-
case 3:
|
|
1449
|
-
handleError(13);
|
|
1450
|
-
break;
|
|
1451
|
-
case 1:
|
|
1452
|
-
if (!disallowComments) handleError(11);
|
|
1453
|
-
break;
|
|
1454
|
-
case 2:
|
|
1455
|
-
handleError(12);
|
|
1456
|
-
break;
|
|
1457
|
-
case 6:
|
|
1458
|
-
handleError(16);
|
|
1459
|
-
break;
|
|
1460
|
-
}
|
|
1461
|
-
switch (token) {
|
|
1462
|
-
case 12:
|
|
1463
|
-
case 13:
|
|
1464
|
-
if (disallowComments) handleError(10);
|
|
1465
|
-
else onComment();
|
|
1466
|
-
break;
|
|
1467
|
-
case 16:
|
|
1468
|
-
handleError(1);
|
|
1469
|
-
break;
|
|
1470
|
-
case 15:
|
|
1471
|
-
case 14: break;
|
|
1472
|
-
default: return token;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
__name(scanNext, "scanNext");
|
|
1477
|
-
function handleError(error, skipUntilAfter = [], skipUntil2 = []) {
|
|
1478
|
-
onError(error);
|
|
1479
|
-
if (skipUntilAfter.length + skipUntil2.length > 0) {
|
|
1480
|
-
let token = _scanner.getToken();
|
|
1481
|
-
while (token !== 17) {
|
|
1482
|
-
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1483
|
-
scanNext();
|
|
1484
|
-
break;
|
|
1485
|
-
} else if (skipUntil2.indexOf(token) !== -1) break;
|
|
1486
|
-
token = scanNext();
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
__name(handleError, "handleError");
|
|
1491
|
-
function parseString2(isValue) {
|
|
1492
|
-
const value = _scanner.getTokenValue();
|
|
1493
|
-
if (isValue) onLiteralValue(value);
|
|
1494
|
-
else {
|
|
1495
|
-
onObjectProperty(value);
|
|
1496
|
-
_jsonPath.push(value);
|
|
1497
|
-
}
|
|
1498
|
-
scanNext();
|
|
1499
|
-
return true;
|
|
1500
|
-
}
|
|
1501
|
-
__name(parseString2, "parseString");
|
|
1502
|
-
function parseLiteral() {
|
|
1503
|
-
switch (_scanner.getToken()) {
|
|
1504
|
-
case 11:
|
|
1505
|
-
const tokenValue = _scanner.getTokenValue();
|
|
1506
|
-
let value = Number(tokenValue);
|
|
1507
|
-
if (isNaN(value)) {
|
|
1508
|
-
handleError(2);
|
|
1509
|
-
value = 0;
|
|
1510
|
-
}
|
|
1511
|
-
onLiteralValue(value);
|
|
1512
|
-
break;
|
|
1513
|
-
case 7:
|
|
1514
|
-
onLiteralValue(null);
|
|
1515
|
-
break;
|
|
1516
|
-
case 8:
|
|
1517
|
-
onLiteralValue(true);
|
|
1518
|
-
break;
|
|
1519
|
-
case 9:
|
|
1520
|
-
onLiteralValue(false);
|
|
1521
|
-
break;
|
|
1522
|
-
default: return false;
|
|
1523
|
-
}
|
|
1524
|
-
scanNext();
|
|
1525
|
-
return true;
|
|
1526
|
-
}
|
|
1527
|
-
__name(parseLiteral, "parseLiteral");
|
|
1528
|
-
function parseProperty() {
|
|
1529
|
-
if (_scanner.getToken() !== 10) {
|
|
1530
|
-
handleError(3, [], [2, 5]);
|
|
1531
|
-
return false;
|
|
1532
|
-
}
|
|
1533
|
-
parseString2(false);
|
|
1534
|
-
if (_scanner.getToken() === 6) {
|
|
1535
|
-
onSeparator(":");
|
|
1536
|
-
scanNext();
|
|
1537
|
-
if (!parseValue2()) handleError(4, [], [2, 5]);
|
|
1538
|
-
} else handleError(5, [], [2, 5]);
|
|
1539
|
-
_jsonPath.pop();
|
|
1540
|
-
return true;
|
|
1541
|
-
}
|
|
1542
|
-
__name(parseProperty, "parseProperty");
|
|
1543
|
-
function parseObject() {
|
|
1544
|
-
onObjectBegin();
|
|
1545
|
-
scanNext();
|
|
1546
|
-
let needsComma = false;
|
|
1547
|
-
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1548
|
-
if (_scanner.getToken() === 5) {
|
|
1549
|
-
if (!needsComma) handleError(4, [], []);
|
|
1550
|
-
onSeparator(",");
|
|
1551
|
-
scanNext();
|
|
1552
|
-
if (_scanner.getToken() === 2 && allowTrailingComma) break;
|
|
1553
|
-
} else if (needsComma) handleError(6, [], []);
|
|
1554
|
-
if (!parseProperty()) handleError(4, [], [2, 5]);
|
|
1555
|
-
needsComma = true;
|
|
1556
|
-
}
|
|
1557
|
-
onObjectEnd();
|
|
1558
|
-
if (_scanner.getToken() !== 2) handleError(7, [2], []);
|
|
1559
|
-
else scanNext();
|
|
1560
|
-
return true;
|
|
1561
|
-
}
|
|
1562
|
-
__name(parseObject, "parseObject");
|
|
1563
|
-
function parseArray2() {
|
|
1564
|
-
onArrayBegin();
|
|
1565
|
-
scanNext();
|
|
1566
|
-
let isFirstElement = true;
|
|
1567
|
-
let needsComma = false;
|
|
1568
|
-
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1569
|
-
if (_scanner.getToken() === 5) {
|
|
1570
|
-
if (!needsComma) handleError(4, [], []);
|
|
1571
|
-
onSeparator(",");
|
|
1572
|
-
scanNext();
|
|
1573
|
-
if (_scanner.getToken() === 4 && allowTrailingComma) break;
|
|
1574
|
-
} else if (needsComma) handleError(6, [], []);
|
|
1575
|
-
if (isFirstElement) {
|
|
1576
|
-
_jsonPath.push(0);
|
|
1577
|
-
isFirstElement = false;
|
|
1578
|
-
} else _jsonPath[_jsonPath.length - 1]++;
|
|
1579
|
-
if (!parseValue2()) handleError(4, [], [4, 5]);
|
|
1580
|
-
needsComma = true;
|
|
1581
|
-
}
|
|
1582
|
-
onArrayEnd();
|
|
1583
|
-
if (!isFirstElement) _jsonPath.pop();
|
|
1584
|
-
if (_scanner.getToken() !== 4) handleError(8, [4], []);
|
|
1585
|
-
else scanNext();
|
|
1586
|
-
return true;
|
|
1587
|
-
}
|
|
1588
|
-
__name(parseArray2, "parseArray");
|
|
1589
|
-
function parseValue2() {
|
|
1590
|
-
switch (_scanner.getToken()) {
|
|
1591
|
-
case 3: return parseArray2();
|
|
1592
|
-
case 1: return parseObject();
|
|
1593
|
-
case 10: return parseString2(true);
|
|
1594
|
-
default: return parseLiteral();
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
__name(parseValue2, "parseValue");
|
|
1598
|
-
scanNext();
|
|
1599
|
-
if (_scanner.getToken() === 17) {
|
|
1600
|
-
if (options.allowEmptyContent) return true;
|
|
1601
|
-
handleError(4, [], []);
|
|
1602
|
-
return false;
|
|
1603
|
-
}
|
|
1604
|
-
if (!parseValue2()) {
|
|
1605
|
-
handleError(4, [], []);
|
|
1606
|
-
return false;
|
|
1607
|
-
}
|
|
1608
|
-
if (_scanner.getToken() !== 17) handleError(9, [], []);
|
|
1609
|
-
return true;
|
|
1610
|
-
}
|
|
1611
|
-
__name(visit, "visit");
|
|
1612
|
-
function getNodeType(value) {
|
|
1613
|
-
switch (typeof value) {
|
|
1614
|
-
case "boolean": return "boolean";
|
|
1615
|
-
case "number": return "number";
|
|
1616
|
-
case "string": return "string";
|
|
1617
|
-
case "object":
|
|
1618
|
-
if (!value) return "null";
|
|
1619
|
-
else if (Array.isArray(value)) return "array";
|
|
1620
|
-
return "object";
|
|
1621
|
-
default: return "null";
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
__name(getNodeType, "getNodeType");
|
|
1625
|
-
function setProperty(text, originalPath, value, options) {
|
|
1626
|
-
const path2 = originalPath.slice();
|
|
1627
|
-
const root = parseTree(text, []);
|
|
1628
|
-
let parent = void 0;
|
|
1629
|
-
let lastSegment = void 0;
|
|
1630
|
-
while (path2.length > 0) {
|
|
1631
|
-
lastSegment = path2.pop();
|
|
1632
|
-
parent = findNodeAtLocation(root, path2);
|
|
1633
|
-
if (parent === void 0 && value !== void 0) if (typeof lastSegment === "string") value = { [lastSegment]: value };
|
|
1634
|
-
else value = [value];
|
|
1635
|
-
else break;
|
|
1636
|
-
}
|
|
1637
|
-
if (!parent) {
|
|
1638
|
-
if (value === void 0) throw new Error("Can not delete in empty document");
|
|
1639
|
-
return withFormatting(text, {
|
|
1640
|
-
offset: root ? root.offset : 0,
|
|
1641
|
-
length: root ? root.length : 0,
|
|
1642
|
-
content: JSON.stringify(value)
|
|
1643
|
-
}, options);
|
|
1644
|
-
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1645
|
-
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1646
|
-
if (existing !== void 0) if (value === void 0) {
|
|
1647
|
-
if (!existing.parent) throw new Error("Malformed AST");
|
|
1648
|
-
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1649
|
-
let removeBegin;
|
|
1650
|
-
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1651
|
-
if (propertyIndex > 0) {
|
|
1652
|
-
let previous = parent.children[propertyIndex - 1];
|
|
1653
|
-
removeBegin = previous.offset + previous.length;
|
|
1654
|
-
} else {
|
|
1655
|
-
removeBegin = parent.offset + 1;
|
|
1656
|
-
if (parent.children.length > 1) removeEnd = parent.children[1].offset;
|
|
1657
|
-
}
|
|
1658
|
-
return withFormatting(text, {
|
|
1659
|
-
offset: removeBegin,
|
|
1660
|
-
length: removeEnd - removeBegin,
|
|
1661
|
-
content: ""
|
|
1662
|
-
}, options);
|
|
1663
|
-
} else return withFormatting(text, {
|
|
1664
|
-
offset: existing.offset,
|
|
1665
|
-
length: existing.length,
|
|
1666
|
-
content: JSON.stringify(value)
|
|
1667
|
-
}, options);
|
|
1668
|
-
else {
|
|
1669
|
-
if (value === void 0) return [];
|
|
1670
|
-
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1671
|
-
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1672
|
-
let edit;
|
|
1673
|
-
if (index > 0) {
|
|
1674
|
-
let previous = parent.children[index - 1];
|
|
1675
|
-
edit = {
|
|
1676
|
-
offset: previous.offset + previous.length,
|
|
1677
|
-
length: 0,
|
|
1678
|
-
content: "," + newProperty
|
|
1679
|
-
};
|
|
1680
|
-
} else if (parent.children.length === 0) edit = {
|
|
1681
|
-
offset: parent.offset + 1,
|
|
1682
|
-
length: 0,
|
|
1683
|
-
content: newProperty
|
|
1684
|
-
};
|
|
1685
|
-
else edit = {
|
|
1686
|
-
offset: parent.offset + 1,
|
|
1687
|
-
length: 0,
|
|
1688
|
-
content: newProperty + ","
|
|
1689
|
-
};
|
|
1690
|
-
return withFormatting(text, edit, options);
|
|
1691
|
-
}
|
|
1692
|
-
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1693
|
-
const insertIndex = lastSegment;
|
|
1694
|
-
if (insertIndex === -1) {
|
|
1695
|
-
const newProperty = `${JSON.stringify(value)}`;
|
|
1696
|
-
let edit;
|
|
1697
|
-
if (parent.children.length === 0) edit = {
|
|
1698
|
-
offset: parent.offset + 1,
|
|
1699
|
-
length: 0,
|
|
1700
|
-
content: newProperty
|
|
1701
|
-
};
|
|
1702
|
-
else {
|
|
1703
|
-
const previous = parent.children[parent.children.length - 1];
|
|
1704
|
-
edit = {
|
|
1705
|
-
offset: previous.offset + previous.length,
|
|
1706
|
-
length: 0,
|
|
1707
|
-
content: "," + newProperty
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
1710
|
-
return withFormatting(text, edit, options);
|
|
1711
|
-
} else if (value === void 0 && parent.children.length >= 0) {
|
|
1712
|
-
const removalIndex = lastSegment;
|
|
1713
|
-
const toRemove = parent.children[removalIndex];
|
|
1714
|
-
let edit;
|
|
1715
|
-
if (parent.children.length === 1) edit = {
|
|
1716
|
-
offset: parent.offset + 1,
|
|
1717
|
-
length: parent.length - 2,
|
|
1718
|
-
content: ""
|
|
1719
|
-
};
|
|
1720
|
-
else if (parent.children.length - 1 === removalIndex) {
|
|
1721
|
-
let previous = parent.children[removalIndex - 1];
|
|
1722
|
-
let offset = previous.offset + previous.length;
|
|
1723
|
-
edit = {
|
|
1724
|
-
offset,
|
|
1725
|
-
length: parent.offset + parent.length - 2 - offset,
|
|
1726
|
-
content: ""
|
|
1727
|
-
};
|
|
1728
|
-
} else edit = {
|
|
1729
|
-
offset: toRemove.offset,
|
|
1730
|
-
length: parent.children[removalIndex + 1].offset - toRemove.offset,
|
|
1731
|
-
content: ""
|
|
1732
|
-
};
|
|
1733
|
-
return withFormatting(text, edit, options);
|
|
1734
|
-
} else if (value !== void 0) {
|
|
1735
|
-
let edit;
|
|
1736
|
-
const newProperty = `${JSON.stringify(value)}`;
|
|
1737
|
-
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1738
|
-
const toModify = parent.children[lastSegment];
|
|
1739
|
-
edit = {
|
|
1740
|
-
offset: toModify.offset,
|
|
1741
|
-
length: toModify.length,
|
|
1742
|
-
content: newProperty
|
|
1743
|
-
};
|
|
1744
|
-
} else if (parent.children.length === 0 || lastSegment === 0) edit = {
|
|
1745
|
-
offset: parent.offset + 1,
|
|
1746
|
-
length: 0,
|
|
1747
|
-
content: parent.children.length === 0 ? newProperty : newProperty + ","
|
|
1748
|
-
};
|
|
1749
|
-
else {
|
|
1750
|
-
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1751
|
-
const previous = parent.children[index - 1];
|
|
1752
|
-
edit = {
|
|
1753
|
-
offset: previous.offset + previous.length,
|
|
1754
|
-
length: 0,
|
|
1755
|
-
content: "," + newProperty
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
return withFormatting(text, edit, options);
|
|
1759
|
-
} else throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1760
|
-
} else throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1761
|
-
}
|
|
1762
|
-
__name(setProperty, "setProperty");
|
|
1763
|
-
function withFormatting(text, edit, options) {
|
|
1764
|
-
if (!options.formattingOptions) return [edit];
|
|
1765
|
-
let newText = applyEdit(text, edit);
|
|
1766
|
-
let begin = edit.offset;
|
|
1767
|
-
let end = edit.offset + edit.content.length;
|
|
1768
|
-
if (edit.length === 0 || edit.content.length === 0) {
|
|
1769
|
-
while (begin > 0 && !isEOL(newText, begin - 1)) begin--;
|
|
1770
|
-
while (end < newText.length && !isEOL(newText, end)) end++;
|
|
1771
|
-
}
|
|
1772
|
-
const edits = format(newText, {
|
|
1773
|
-
offset: begin,
|
|
1774
|
-
length: end - begin
|
|
1775
|
-
}, {
|
|
1776
|
-
...options.formattingOptions,
|
|
1777
|
-
keepLines: false
|
|
1778
|
-
});
|
|
1779
|
-
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1780
|
-
const edit2 = edits[i];
|
|
1781
|
-
newText = applyEdit(newText, edit2);
|
|
1782
|
-
begin = Math.min(begin, edit2.offset);
|
|
1783
|
-
end = Math.max(end, edit2.offset + edit2.length);
|
|
1784
|
-
end += edit2.content.length - edit2.length;
|
|
1785
|
-
}
|
|
1786
|
-
const editLength = text.length - (newText.length - end) - begin;
|
|
1787
|
-
return [{
|
|
1788
|
-
offset: begin,
|
|
1789
|
-
length: editLength,
|
|
1790
|
-
content: newText.substring(begin, end)
|
|
1791
|
-
}];
|
|
1792
|
-
}
|
|
1793
|
-
__name(withFormatting, "withFormatting");
|
|
1794
|
-
function applyEdit(text, edit) {
|
|
1795
|
-
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1796
|
-
}
|
|
1797
|
-
__name(applyEdit, "applyEdit");
|
|
1798
|
-
var ScanError;
|
|
1799
|
-
(function(ScanError2) {
|
|
1800
|
-
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1801
|
-
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1802
|
-
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1803
|
-
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1804
|
-
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1805
|
-
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1806
|
-
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1807
|
-
})(ScanError || (ScanError = {}));
|
|
1808
|
-
var SyntaxKind;
|
|
1809
|
-
(function(SyntaxKind2) {
|
|
1810
|
-
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1811
|
-
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1812
|
-
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1813
|
-
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1814
|
-
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1815
|
-
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1816
|
-
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1817
|
-
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1818
|
-
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1819
|
-
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1820
|
-
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1821
|
-
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1822
|
-
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1823
|
-
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1824
|
-
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1825
|
-
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1826
|
-
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1827
|
-
})(SyntaxKind || (SyntaxKind = {}));
|
|
1828
|
-
var parse2 = parse;
|
|
1829
|
-
var ParseErrorCode;
|
|
1830
|
-
(function(ParseErrorCode2) {
|
|
1831
|
-
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1832
|
-
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1833
|
-
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1834
|
-
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1835
|
-
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1836
|
-
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1837
|
-
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1838
|
-
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1839
|
-
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1840
|
-
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1841
|
-
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1842
|
-
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1843
|
-
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1844
|
-
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1845
|
-
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1846
|
-
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1847
|
-
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1848
|
-
function printParseErrorCode(code) {
|
|
1849
|
-
switch (code) {
|
|
1850
|
-
case 1: return "InvalidSymbol";
|
|
1851
|
-
case 2: return "InvalidNumberFormat";
|
|
1852
|
-
case 3: return "PropertyNameExpected";
|
|
1853
|
-
case 4: return "ValueExpected";
|
|
1854
|
-
case 5: return "ColonExpected";
|
|
1855
|
-
case 6: return "CommaExpected";
|
|
1856
|
-
case 7: return "CloseBraceExpected";
|
|
1857
|
-
case 8: return "CloseBracketExpected";
|
|
1858
|
-
case 9: return "EndOfFileExpected";
|
|
1859
|
-
case 10: return "InvalidCommentToken";
|
|
1860
|
-
case 11: return "UnexpectedEndOfComment";
|
|
1861
|
-
case 12: return "UnexpectedEndOfString";
|
|
1862
|
-
case 13: return "UnexpectedEndOfNumber";
|
|
1863
|
-
case 14: return "InvalidUnicode";
|
|
1864
|
-
case 15: return "InvalidEscapeCharacter";
|
|
1865
|
-
case 16: return "InvalidCharacter";
|
|
1866
|
-
}
|
|
1867
|
-
return "<unknown ParseErrorCode>";
|
|
1868
|
-
}
|
|
1869
|
-
__name(printParseErrorCode, "printParseErrorCode");
|
|
1870
|
-
function format2(documentText, range, options) {
|
|
1871
|
-
return format(documentText, range, options);
|
|
1872
|
-
}
|
|
1873
|
-
__name(format2, "format");
|
|
1874
|
-
function modify(text, path2, value, options) {
|
|
1875
|
-
return setProperty(text, path2, value, options);
|
|
1876
|
-
}
|
|
1877
|
-
__name(modify, "modify");
|
|
1878
|
-
function applyEdits(text, edits) {
|
|
1879
|
-
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1880
|
-
const diff = a.offset - b.offset;
|
|
1881
|
-
if (diff === 0) return a.length - b.length;
|
|
1882
|
-
return diff;
|
|
1883
|
-
});
|
|
1884
|
-
let lastModifiedOffset = text.length;
|
|
1885
|
-
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
1886
|
-
let e = sortedEdits[i];
|
|
1887
|
-
if (e.offset + e.length <= lastModifiedOffset) text = applyEdit(text, e);
|
|
1888
|
-
else throw new Error("Overlapping edit");
|
|
1889
|
-
lastModifiedOffset = e.offset;
|
|
1890
|
-
}
|
|
1891
|
-
return text;
|
|
1892
|
-
}
|
|
1893
|
-
__name(applyEdits, "applyEdits");
|
|
1894
|
-
function getLineColFromPtr(string, ptr) {
|
|
1895
|
-
let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
|
|
1896
|
-
return [lines.length, lines.pop().length + 1];
|
|
1897
|
-
}
|
|
1898
|
-
__name(getLineColFromPtr, "getLineColFromPtr");
|
|
1899
|
-
function makeCodeBlock(string, line, column) {
|
|
1900
|
-
let lines = string.split(/\r\n|\n|\r/g);
|
|
1901
|
-
let codeblock = "";
|
|
1902
|
-
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
1903
|
-
for (let i = line - 1; i <= line + 1; i++) {
|
|
1904
|
-
let l = lines[i - 1];
|
|
1905
|
-
if (!l) continue;
|
|
1906
|
-
codeblock += i.toString().padEnd(numberLen, " ");
|
|
1907
|
-
codeblock += ": ";
|
|
1908
|
-
codeblock += l;
|
|
1909
|
-
codeblock += "\n";
|
|
1910
|
-
if (i === line) {
|
|
1911
|
-
codeblock += " ".repeat(numberLen + column + 2);
|
|
1912
|
-
codeblock += "^\n";
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
return codeblock;
|
|
1916
|
-
}
|
|
1917
|
-
__name(makeCodeBlock, "makeCodeBlock");
|
|
1918
|
-
var TomlError = class extends Error {
|
|
1919
|
-
static {
|
|
1920
|
-
__name(this, "TomlError");
|
|
1921
|
-
}
|
|
1922
|
-
line;
|
|
1923
|
-
column;
|
|
1924
|
-
codeblock;
|
|
1925
|
-
constructor(message, options) {
|
|
1926
|
-
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
1927
|
-
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
1928
|
-
super(`Invalid TOML document: ${message}
|
|
1929
|
-
|
|
1930
|
-
${codeblock}`, options);
|
|
1931
|
-
this.line = line;
|
|
1932
|
-
this.column = column;
|
|
1933
|
-
this.codeblock = codeblock;
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1936
|
-
function isEscaped(str, ptr) {
|
|
1937
|
-
let i = 0;
|
|
1938
|
-
while (str[ptr - ++i] === "\\");
|
|
1939
|
-
return --i && i % 2;
|
|
1940
|
-
}
|
|
1941
|
-
__name(isEscaped, "isEscaped");
|
|
1942
|
-
function indexOfNewline(str, start = 0, end = str.length) {
|
|
1943
|
-
let idx = str.indexOf("\n", start);
|
|
1944
|
-
if (str[idx - 1] === "\r") idx--;
|
|
1945
|
-
return idx <= end ? idx : -1;
|
|
1946
|
-
}
|
|
1947
|
-
__name(indexOfNewline, "indexOfNewline");
|
|
1948
|
-
function skipComment(str, ptr) {
|
|
1949
|
-
for (let i = ptr; i < str.length; i++) {
|
|
1950
|
-
let c = str[i];
|
|
1951
|
-
if (c === "\n") return i;
|
|
1952
|
-
if (c === "\r" && str[i + 1] === "\n") return i + 1;
|
|
1953
|
-
if (c < " " && c !== " " || c === "") throw new TomlError("control characters are not allowed in comments", {
|
|
1954
|
-
toml: str,
|
|
1955
|
-
ptr
|
|
1956
|
-
});
|
|
1957
|
-
}
|
|
1958
|
-
return str.length;
|
|
1959
|
-
}
|
|
1960
|
-
__name(skipComment, "skipComment");
|
|
1961
|
-
function skipVoid(str, ptr, banNewLines, banComments) {
|
|
1962
|
-
let c;
|
|
1963
|
-
while ((c = str[ptr]) === " " || c === " " || !banNewLines && (c === "\n" || c === "\r" && str[ptr + 1] === "\n")) ptr++;
|
|
1964
|
-
return banComments || c !== "#" ? ptr : skipVoid(str, skipComment(str, ptr), banNewLines);
|
|
1965
|
-
}
|
|
1966
|
-
__name(skipVoid, "skipVoid");
|
|
1967
|
-
function skipUntil(str, ptr, sep, end, banNewLines = false) {
|
|
1968
|
-
if (!end) {
|
|
1969
|
-
ptr = indexOfNewline(str, ptr);
|
|
1970
|
-
return ptr < 0 ? str.length : ptr;
|
|
1971
|
-
}
|
|
1972
|
-
for (let i = ptr; i < str.length; i++) {
|
|
1973
|
-
let c = str[i];
|
|
1974
|
-
if (c === "#") i = indexOfNewline(str, i);
|
|
1975
|
-
else if (c === sep) return i + 1;
|
|
1976
|
-
else if (c === end || banNewLines && (c === "\n" || c === "\r" && str[i + 1] === "\n")) return i;
|
|
1977
|
-
}
|
|
1978
|
-
throw new TomlError("cannot find end of structure", {
|
|
1979
|
-
toml: str,
|
|
1980
|
-
ptr
|
|
1981
|
-
});
|
|
1982
|
-
}
|
|
1983
|
-
__name(skipUntil, "skipUntil");
|
|
1984
|
-
function getStringEnd(str, seek) {
|
|
1985
|
-
let first = str[seek];
|
|
1986
|
-
let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2] ? str.slice(seek, seek + 3) : first;
|
|
1987
|
-
seek += target.length - 1;
|
|
1988
|
-
do
|
|
1989
|
-
seek = str.indexOf(target, ++seek);
|
|
1990
|
-
while (seek > -1 && first !== "'" && isEscaped(str, seek));
|
|
1991
|
-
if (seek > -1) {
|
|
1992
|
-
seek += target.length;
|
|
1993
|
-
if (target.length > 1) {
|
|
1994
|
-
if (str[seek] === first) seek++;
|
|
1995
|
-
if (str[seek] === first) seek++;
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
return seek;
|
|
1999
|
-
}
|
|
2000
|
-
__name(getStringEnd, "getStringEnd");
|
|
2001
|
-
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}:\d{2}(?:\.\d+)?)?(Z|[-+]\d{2}:\d{2})?$/i;
|
|
2002
|
-
var TomlDate = class _TomlDate extends Date {
|
|
2003
|
-
static {
|
|
2004
|
-
__name(this, "TomlDate");
|
|
2005
|
-
}
|
|
2006
|
-
#hasDate = false;
|
|
2007
|
-
#hasTime = false;
|
|
2008
|
-
#offset = null;
|
|
2009
|
-
constructor(date) {
|
|
2010
|
-
let hasDate = true;
|
|
2011
|
-
let hasTime = true;
|
|
2012
|
-
let offset = "Z";
|
|
2013
|
-
if (typeof date === "string") {
|
|
2014
|
-
let match = date.match(DATE_TIME_RE);
|
|
2015
|
-
if (match) {
|
|
2016
|
-
if (!match[1]) {
|
|
2017
|
-
hasDate = false;
|
|
2018
|
-
date = `0000-01-01T${date}`;
|
|
2019
|
-
}
|
|
2020
|
-
hasTime = !!match[2];
|
|
2021
|
-
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
2022
|
-
if (match[2] && +match[2] > 23) date = "";
|
|
2023
|
-
else {
|
|
2024
|
-
offset = match[3] || null;
|
|
2025
|
-
date = date.toUpperCase();
|
|
2026
|
-
if (!offset && hasTime) date += "Z";
|
|
2027
|
-
}
|
|
2028
|
-
} else date = "";
|
|
2029
|
-
}
|
|
2030
|
-
super(date);
|
|
2031
|
-
if (!isNaN(this.getTime())) {
|
|
2032
|
-
this.#hasDate = hasDate;
|
|
2033
|
-
this.#hasTime = hasTime;
|
|
2034
|
-
this.#offset = offset;
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
isDateTime() {
|
|
2038
|
-
return this.#hasDate && this.#hasTime;
|
|
2039
|
-
}
|
|
2040
|
-
isLocal() {
|
|
2041
|
-
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
2042
|
-
}
|
|
2043
|
-
isDate() {
|
|
2044
|
-
return this.#hasDate && !this.#hasTime;
|
|
2045
|
-
}
|
|
2046
|
-
isTime() {
|
|
2047
|
-
return this.#hasTime && !this.#hasDate;
|
|
2048
|
-
}
|
|
2049
|
-
isValid() {
|
|
2050
|
-
return this.#hasDate || this.#hasTime;
|
|
2051
|
-
}
|
|
2052
|
-
toISOString() {
|
|
2053
|
-
let iso = super.toISOString();
|
|
2054
|
-
if (this.isDate()) return iso.slice(0, 10);
|
|
2055
|
-
if (this.isTime()) return iso.slice(11, 23);
|
|
2056
|
-
if (this.#offset === null) return iso.slice(0, -1);
|
|
2057
|
-
if (this.#offset === "Z") return iso;
|
|
2058
|
-
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
2059
|
-
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
2060
|
-
return (/* @__PURE__ */ new Date(this.getTime() - offset * 6e4)).toISOString().slice(0, -1) + this.#offset;
|
|
2061
|
-
}
|
|
2062
|
-
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
2063
|
-
let date = new _TomlDate(jsDate);
|
|
2064
|
-
date.#offset = offset;
|
|
2065
|
-
return date;
|
|
2066
|
-
}
|
|
2067
|
-
static wrapAsLocalDateTime(jsDate) {
|
|
2068
|
-
let date = new _TomlDate(jsDate);
|
|
2069
|
-
date.#offset = null;
|
|
2070
|
-
return date;
|
|
2071
|
-
}
|
|
2072
|
-
static wrapAsLocalDate(jsDate) {
|
|
2073
|
-
let date = new _TomlDate(jsDate);
|
|
2074
|
-
date.#hasTime = false;
|
|
2075
|
-
date.#offset = null;
|
|
2076
|
-
return date;
|
|
2077
|
-
}
|
|
2078
|
-
static wrapAsLocalTime(jsDate) {
|
|
2079
|
-
let date = new _TomlDate(jsDate);
|
|
2080
|
-
date.#hasDate = false;
|
|
2081
|
-
date.#offset = null;
|
|
2082
|
-
return date;
|
|
2083
|
-
}
|
|
2084
|
-
};
|
|
2085
|
-
var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
|
|
2086
|
-
var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
|
|
2087
|
-
var LEADING_ZERO = /^[+-]?0[0-9_]/;
|
|
2088
|
-
var ESCAPE_REGEX = /^[0-9a-f]{4,8}$/i;
|
|
2089
|
-
var ESC_MAP = {
|
|
2090
|
-
b: "\b",
|
|
2091
|
-
t: " ",
|
|
2092
|
-
n: "\n",
|
|
2093
|
-
f: "\f",
|
|
2094
|
-
r: "\r",
|
|
2095
|
-
"\"": "\"",
|
|
2096
|
-
"\\": "\\"
|
|
2097
|
-
};
|
|
2098
|
-
function parseString(str, ptr = 0, endPtr = str.length) {
|
|
2099
|
-
let isLiteral = str[ptr] === "'";
|
|
2100
|
-
let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
|
|
2101
|
-
if (isMultiline) {
|
|
2102
|
-
endPtr -= 2;
|
|
2103
|
-
if (str[ptr += 2] === "\r") ptr++;
|
|
2104
|
-
if (str[ptr] === "\n") ptr++;
|
|
2105
|
-
}
|
|
2106
|
-
let tmp = 0;
|
|
2107
|
-
let isEscape;
|
|
2108
|
-
let parsed = "";
|
|
2109
|
-
let sliceStart = ptr;
|
|
2110
|
-
while (ptr < endPtr - 1) {
|
|
2111
|
-
let c = str[ptr++];
|
|
2112
|
-
if (c === "\n" || c === "\r" && str[ptr] === "\n") {
|
|
2113
|
-
if (!isMultiline) throw new TomlError("newlines are not allowed in strings", {
|
|
2114
|
-
toml: str,
|
|
2115
|
-
ptr: ptr - 1
|
|
2116
|
-
});
|
|
2117
|
-
} else if (c < " " && c !== " " || c === "") throw new TomlError("control characters are not allowed in strings", {
|
|
2118
|
-
toml: str,
|
|
2119
|
-
ptr: ptr - 1
|
|
2120
|
-
});
|
|
2121
|
-
if (isEscape) {
|
|
2122
|
-
isEscape = false;
|
|
2123
|
-
if (c === "u" || c === "U") {
|
|
2124
|
-
let code = str.slice(ptr, ptr += c === "u" ? 4 : 8);
|
|
2125
|
-
if (!ESCAPE_REGEX.test(code)) throw new TomlError("invalid unicode escape", {
|
|
2126
|
-
toml: str,
|
|
2127
|
-
ptr: tmp
|
|
2128
|
-
});
|
|
2129
|
-
try {
|
|
2130
|
-
parsed += String.fromCodePoint(parseInt(code, 16));
|
|
2131
|
-
} catch {
|
|
2132
|
-
throw new TomlError("invalid unicode escape", {
|
|
2133
|
-
toml: str,
|
|
2134
|
-
ptr: tmp
|
|
2135
|
-
});
|
|
2136
|
-
}
|
|
2137
|
-
} else if (isMultiline && (c === "\n" || c === " " || c === " " || c === "\r")) {
|
|
2138
|
-
ptr = skipVoid(str, ptr - 1, true);
|
|
2139
|
-
if (str[ptr] !== "\n" && str[ptr] !== "\r") throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
|
|
2140
|
-
toml: str,
|
|
2141
|
-
ptr: tmp
|
|
2142
|
-
});
|
|
2143
|
-
ptr = skipVoid(str, ptr);
|
|
2144
|
-
} else if (c in ESC_MAP) parsed += ESC_MAP[c];
|
|
2145
|
-
else throw new TomlError("unrecognized escape sequence", {
|
|
2146
|
-
toml: str,
|
|
2147
|
-
ptr: tmp
|
|
2148
|
-
});
|
|
2149
|
-
sliceStart = ptr;
|
|
2150
|
-
} else if (!isLiteral && c === "\\") {
|
|
2151
|
-
tmp = ptr - 1;
|
|
2152
|
-
isEscape = true;
|
|
2153
|
-
parsed += str.slice(sliceStart, tmp);
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
return parsed + str.slice(sliceStart, endPtr - 1);
|
|
2157
|
-
}
|
|
2158
|
-
__name(parseString, "parseString");
|
|
2159
|
-
function parseValue(value, toml, ptr, integersAsBigInt) {
|
|
2160
|
-
if (value === "true") return true;
|
|
2161
|
-
if (value === "false") return false;
|
|
2162
|
-
if (value === "-inf") return -Infinity;
|
|
2163
|
-
if (value === "inf" || value === "+inf") return Infinity;
|
|
2164
|
-
if (value === "nan" || value === "+nan" || value === "-nan") return NaN;
|
|
2165
|
-
if (value === "-0") return integersAsBigInt ? 0n : 0;
|
|
2166
|
-
let isInt = INT_REGEX.test(value);
|
|
2167
|
-
if (isInt || FLOAT_REGEX.test(value)) {
|
|
2168
|
-
if (LEADING_ZERO.test(value)) throw new TomlError("leading zeroes are not allowed", {
|
|
2169
|
-
toml,
|
|
2170
|
-
ptr
|
|
2171
|
-
});
|
|
2172
|
-
value = value.replace(/_/g, "");
|
|
2173
|
-
let numeric = +value;
|
|
2174
|
-
if (isNaN(numeric)) throw new TomlError("invalid number", {
|
|
2175
|
-
toml,
|
|
2176
|
-
ptr
|
|
2177
|
-
});
|
|
2178
|
-
if (isInt) {
|
|
2179
|
-
if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) throw new TomlError("integer value cannot be represented losslessly", {
|
|
2180
|
-
toml,
|
|
2181
|
-
ptr
|
|
2182
|
-
});
|
|
2183
|
-
if (isInt || integersAsBigInt === true) numeric = BigInt(value);
|
|
2184
|
-
}
|
|
2185
|
-
return numeric;
|
|
2186
|
-
}
|
|
2187
|
-
const date = new TomlDate(value);
|
|
2188
|
-
if (!date.isValid()) throw new TomlError("invalid value", {
|
|
2189
|
-
toml,
|
|
2190
|
-
ptr
|
|
2191
|
-
});
|
|
2192
|
-
return date;
|
|
2193
|
-
}
|
|
2194
|
-
__name(parseValue, "parseValue");
|
|
2195
|
-
function sliceAndTrimEndOf(str, startPtr, endPtr, allowNewLines) {
|
|
2196
|
-
let value = str.slice(startPtr, endPtr);
|
|
2197
|
-
let commentIdx = value.indexOf("#");
|
|
2198
|
-
if (commentIdx > -1) {
|
|
2199
|
-
skipComment(str, commentIdx);
|
|
2200
|
-
value = value.slice(0, commentIdx);
|
|
2201
|
-
}
|
|
2202
|
-
let trimmed = value.trimEnd();
|
|
2203
|
-
if (!allowNewLines) {
|
|
2204
|
-
let newlineIdx = value.indexOf("\n", trimmed.length);
|
|
2205
|
-
if (newlineIdx > -1) throw new TomlError("newlines are not allowed in inline tables", {
|
|
2206
|
-
toml: str,
|
|
2207
|
-
ptr: startPtr + newlineIdx
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
return [trimmed, commentIdx];
|
|
2211
|
-
}
|
|
2212
|
-
__name(sliceAndTrimEndOf, "sliceAndTrimEndOf");
|
|
2213
|
-
function extractValue(str, ptr, end, depth, integersAsBigInt) {
|
|
2214
|
-
if (depth === 0) throw new TomlError("document contains excessively nested structures. aborting.", {
|
|
2215
|
-
toml: str,
|
|
2216
|
-
ptr
|
|
2217
|
-
});
|
|
2218
|
-
let c = str[ptr];
|
|
2219
|
-
if (c === "[" || c === "{") {
|
|
2220
|
-
let [value, endPtr2] = c === "[" ? parseArray(str, ptr, depth, integersAsBigInt) : parseInlineTable(str, ptr, depth, integersAsBigInt);
|
|
2221
|
-
let newPtr = end ? skipUntil(str, endPtr2, ",", end) : endPtr2;
|
|
2222
|
-
if (endPtr2 - newPtr && end === "}") {
|
|
2223
|
-
let nextNewLine = indexOfNewline(str, endPtr2, newPtr);
|
|
2224
|
-
if (nextNewLine > -1) throw new TomlError("newlines are not allowed in inline tables", {
|
|
2225
|
-
toml: str,
|
|
2226
|
-
ptr: nextNewLine
|
|
2227
|
-
});
|
|
2228
|
-
}
|
|
2229
|
-
return [value, newPtr];
|
|
2230
|
-
}
|
|
2231
|
-
let endPtr;
|
|
2232
|
-
if (c === "\"" || c === "'") {
|
|
2233
|
-
endPtr = getStringEnd(str, ptr);
|
|
2234
|
-
let parsed = parseString(str, ptr, endPtr);
|
|
2235
|
-
if (end) {
|
|
2236
|
-
endPtr = skipVoid(str, endPtr, end !== "]");
|
|
2237
|
-
if (str[endPtr] && str[endPtr] !== "," && str[endPtr] !== end && str[endPtr] !== "\n" && str[endPtr] !== "\r") throw new TomlError("unexpected character encountered", {
|
|
2238
|
-
toml: str,
|
|
2239
|
-
ptr: endPtr
|
|
2240
|
-
});
|
|
2241
|
-
endPtr += +(str[endPtr] === ",");
|
|
2242
|
-
}
|
|
2243
|
-
return [parsed, endPtr];
|
|
2244
|
-
}
|
|
2245
|
-
endPtr = skipUntil(str, ptr, ",", end);
|
|
2246
|
-
let slice = sliceAndTrimEndOf(str, ptr, endPtr - +(str[endPtr - 1] === ","), end === "]");
|
|
2247
|
-
if (!slice[0]) throw new TomlError("incomplete key-value declaration: no value specified", {
|
|
2248
|
-
toml: str,
|
|
2249
|
-
ptr
|
|
2250
|
-
});
|
|
2251
|
-
if (end && slice[1] > -1) {
|
|
2252
|
-
endPtr = skipVoid(str, ptr + slice[1]);
|
|
2253
|
-
endPtr += +(str[endPtr] === ",");
|
|
2254
|
-
}
|
|
2255
|
-
return [parseValue(slice[0], str, ptr, integersAsBigInt), endPtr];
|
|
2256
|
-
}
|
|
2257
|
-
__name(extractValue, "extractValue");
|
|
2258
|
-
var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
|
|
2259
|
-
function parseKey(str, ptr, end = "=") {
|
|
2260
|
-
let dot = ptr - 1;
|
|
2261
|
-
let parsed = [];
|
|
2262
|
-
let endPtr = str.indexOf(end, ptr);
|
|
2263
|
-
if (endPtr < 0) throw new TomlError("incomplete key-value: cannot find end of key", {
|
|
2264
|
-
toml: str,
|
|
2265
|
-
ptr
|
|
2266
|
-
});
|
|
2267
|
-
do {
|
|
2268
|
-
let c = str[ptr = ++dot];
|
|
2269
|
-
if (c !== " " && c !== " ") if (c === "\"" || c === "'") {
|
|
2270
|
-
if (c === str[ptr + 1] && c === str[ptr + 2]) throw new TomlError("multiline strings are not allowed in keys", {
|
|
2271
|
-
toml: str,
|
|
2272
|
-
ptr
|
|
2273
|
-
});
|
|
2274
|
-
let eos = getStringEnd(str, ptr);
|
|
2275
|
-
if (eos < 0) throw new TomlError("unfinished string encountered", {
|
|
2276
|
-
toml: str,
|
|
2277
|
-
ptr
|
|
2278
|
-
});
|
|
2279
|
-
dot = str.indexOf(".", eos);
|
|
2280
|
-
let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
|
|
2281
|
-
let newLine = indexOfNewline(strEnd);
|
|
2282
|
-
if (newLine > -1) throw new TomlError("newlines are not allowed in keys", {
|
|
2283
|
-
toml: str,
|
|
2284
|
-
ptr: ptr + dot + newLine
|
|
2285
|
-
});
|
|
2286
|
-
if (strEnd.trimStart()) throw new TomlError("found extra tokens after the string part", {
|
|
2287
|
-
toml: str,
|
|
2288
|
-
ptr: eos
|
|
2289
|
-
});
|
|
2290
|
-
if (endPtr < eos) {
|
|
2291
|
-
endPtr = str.indexOf(end, eos);
|
|
2292
|
-
if (endPtr < 0) throw new TomlError("incomplete key-value: cannot find end of key", {
|
|
2293
|
-
toml: str,
|
|
2294
|
-
ptr
|
|
2295
|
-
});
|
|
2296
|
-
}
|
|
2297
|
-
parsed.push(parseString(str, ptr, eos));
|
|
2298
|
-
} else {
|
|
2299
|
-
dot = str.indexOf(".", ptr);
|
|
2300
|
-
let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
|
|
2301
|
-
if (!KEY_PART_RE.test(part)) throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
|
|
2302
|
-
toml: str,
|
|
2303
|
-
ptr
|
|
2304
|
-
});
|
|
2305
|
-
parsed.push(part.trimEnd());
|
|
2306
|
-
}
|
|
2307
|
-
} while (dot + 1 && dot < endPtr);
|
|
2308
|
-
return [parsed, skipVoid(str, endPtr + 1, true, true)];
|
|
2309
|
-
}
|
|
2310
|
-
__name(parseKey, "parseKey");
|
|
2311
|
-
function parseInlineTable(str, ptr, depth, integersAsBigInt) {
|
|
2312
|
-
let res = {};
|
|
2313
|
-
let seen = /* @__PURE__ */ new Set();
|
|
2314
|
-
let c;
|
|
2315
|
-
let comma = 0;
|
|
2316
|
-
ptr++;
|
|
2317
|
-
while ((c = str[ptr++]) !== "}" && c) {
|
|
2318
|
-
let err = {
|
|
2319
|
-
toml: str,
|
|
2320
|
-
ptr: ptr - 1
|
|
2321
|
-
};
|
|
2322
|
-
if (c === "\n") throw new TomlError("newlines are not allowed in inline tables", err);
|
|
2323
|
-
else if (c === "#") throw new TomlError("inline tables cannot contain comments", err);
|
|
2324
|
-
else if (c === ",") throw new TomlError("expected key-value, found comma", err);
|
|
2325
|
-
else if (c !== " " && c !== " ") {
|
|
2326
|
-
let k;
|
|
2327
|
-
let t = res;
|
|
2328
|
-
let hasOwn = false;
|
|
2329
|
-
let [key, keyEndPtr] = parseKey(str, ptr - 1);
|
|
2330
|
-
for (let i = 0; i < key.length; i++) {
|
|
2331
|
-
if (i) t = hasOwn ? t[k] : t[k] = {};
|
|
2332
|
-
k = key[i];
|
|
2333
|
-
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) throw new TomlError("trying to redefine an already defined value", {
|
|
2334
|
-
toml: str,
|
|
2335
|
-
ptr
|
|
2336
|
-
});
|
|
2337
|
-
if (!hasOwn && k === "__proto__") Object.defineProperty(t, k, {
|
|
2338
|
-
enumerable: true,
|
|
2339
|
-
configurable: true,
|
|
2340
|
-
writable: true
|
|
2341
|
-
});
|
|
2342
|
-
}
|
|
2343
|
-
if (hasOwn) throw new TomlError("trying to redefine an already defined value", {
|
|
2344
|
-
toml: str,
|
|
2345
|
-
ptr
|
|
2346
|
-
});
|
|
2347
|
-
let [value, valueEndPtr] = extractValue(str, keyEndPtr, "}", depth - 1, integersAsBigInt);
|
|
2348
|
-
seen.add(value);
|
|
2349
|
-
t[k] = value;
|
|
2350
|
-
ptr = valueEndPtr;
|
|
2351
|
-
comma = str[ptr - 1] === "," ? ptr - 1 : 0;
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
if (comma) throw new TomlError("trailing commas are not allowed in inline tables", {
|
|
2355
|
-
toml: str,
|
|
2356
|
-
ptr: comma
|
|
2357
|
-
});
|
|
2358
|
-
if (!c) throw new TomlError("unfinished table encountered", {
|
|
2359
|
-
toml: str,
|
|
2360
|
-
ptr
|
|
2361
|
-
});
|
|
2362
|
-
return [res, ptr];
|
|
2363
|
-
}
|
|
2364
|
-
__name(parseInlineTable, "parseInlineTable");
|
|
2365
|
-
function parseArray(str, ptr, depth, integersAsBigInt) {
|
|
2366
|
-
let res = [];
|
|
2367
|
-
let c;
|
|
2368
|
-
ptr++;
|
|
2369
|
-
while ((c = str[ptr++]) !== "]" && c) if (c === ",") throw new TomlError("expected value, found comma", {
|
|
2370
|
-
toml: str,
|
|
2371
|
-
ptr: ptr - 1
|
|
2372
|
-
});
|
|
2373
|
-
else if (c === "#") ptr = skipComment(str, ptr);
|
|
2374
|
-
else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
|
|
2375
|
-
let e = extractValue(str, ptr - 1, "]", depth - 1, integersAsBigInt);
|
|
2376
|
-
res.push(e[0]);
|
|
2377
|
-
ptr = e[1];
|
|
2378
|
-
}
|
|
2379
|
-
if (!c) throw new TomlError("unfinished array encountered", {
|
|
2380
|
-
toml: str,
|
|
2381
|
-
ptr
|
|
2382
|
-
});
|
|
2383
|
-
return [res, ptr];
|
|
2384
|
-
}
|
|
2385
|
-
__name(parseArray, "parseArray");
|
|
2386
|
-
function peekTable(key, table, meta, type) {
|
|
2387
|
-
let t = table;
|
|
2388
|
-
let m = meta;
|
|
2389
|
-
let k;
|
|
2390
|
-
let hasOwn = false;
|
|
2391
|
-
let state;
|
|
2392
|
-
for (let i = 0; i < key.length; i++) {
|
|
2393
|
-
if (i) {
|
|
2394
|
-
t = hasOwn ? t[k] : t[k] = {};
|
|
2395
|
-
m = (state = m[k]).c;
|
|
2396
|
-
if (type === 0 && (state.t === 1 || state.t === 2)) return null;
|
|
2397
|
-
if (state.t === 2) {
|
|
2398
|
-
let l = t.length - 1;
|
|
2399
|
-
t = t[l];
|
|
2400
|
-
m = m[l].c;
|
|
2401
|
-
}
|
|
2402
|
-
}
|
|
2403
|
-
k = key[i];
|
|
2404
|
-
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) return null;
|
|
2405
|
-
if (!hasOwn) {
|
|
2406
|
-
if (k === "__proto__") {
|
|
2407
|
-
Object.defineProperty(t, k, {
|
|
2408
|
-
enumerable: true,
|
|
2409
|
-
configurable: true,
|
|
2410
|
-
writable: true
|
|
2411
|
-
});
|
|
2412
|
-
Object.defineProperty(m, k, {
|
|
2413
|
-
enumerable: true,
|
|
2414
|
-
configurable: true,
|
|
2415
|
-
writable: true
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
m[k] = {
|
|
2419
|
-
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
2420
|
-
d: false,
|
|
2421
|
-
i: 0,
|
|
2422
|
-
c: {}
|
|
2423
|
-
};
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
state = m[k];
|
|
2427
|
-
if (state.t !== type && !(type === 1 && state.t === 3)) return null;
|
|
2428
|
-
if (type === 2) {
|
|
2429
|
-
if (!state.d) {
|
|
2430
|
-
state.d = true;
|
|
2431
|
-
t[k] = [];
|
|
2432
|
-
}
|
|
2433
|
-
t[k].push(t = {});
|
|
2434
|
-
state.c[state.i++] = state = {
|
|
2435
|
-
t: 1,
|
|
2436
|
-
d: false,
|
|
2437
|
-
i: 0,
|
|
2438
|
-
c: {}
|
|
2439
|
-
};
|
|
2440
|
-
}
|
|
2441
|
-
if (state.d) return null;
|
|
2442
|
-
state.d = true;
|
|
2443
|
-
if (type === 1) t = hasOwn ? t[k] : t[k] = {};
|
|
2444
|
-
else if (type === 0 && hasOwn) return null;
|
|
2445
|
-
return [
|
|
2446
|
-
k,
|
|
2447
|
-
t,
|
|
2448
|
-
state.c
|
|
2449
|
-
];
|
|
2450
|
-
}
|
|
2451
|
-
__name(peekTable, "peekTable");
|
|
2452
|
-
function parse3(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
|
|
2453
|
-
let res = {};
|
|
2454
|
-
let meta = {};
|
|
2455
|
-
let tbl = res;
|
|
2456
|
-
let m = meta;
|
|
2457
|
-
for (let ptr = skipVoid(toml, 0); ptr < toml.length;) {
|
|
2458
|
-
if (toml[ptr] === "[") {
|
|
2459
|
-
let isTableArray = toml[++ptr] === "[";
|
|
2460
|
-
let k = parseKey(toml, ptr += +isTableArray, "]");
|
|
2461
|
-
if (isTableArray) {
|
|
2462
|
-
if (toml[k[1] - 1] !== "]") throw new TomlError("expected end of table declaration", {
|
|
2463
|
-
toml,
|
|
2464
|
-
ptr: k[1] - 1
|
|
2465
|
-
});
|
|
2466
|
-
k[1]++;
|
|
2467
|
-
}
|
|
2468
|
-
let p = peekTable(k[0], res, meta, isTableArray ? 2 : 1);
|
|
2469
|
-
if (!p) throw new TomlError("trying to redefine an already defined table or value", {
|
|
2470
|
-
toml,
|
|
2471
|
-
ptr
|
|
2472
|
-
});
|
|
2473
|
-
m = p[2];
|
|
2474
|
-
tbl = p[1];
|
|
2475
|
-
ptr = k[1];
|
|
2476
|
-
} else {
|
|
2477
|
-
let k = parseKey(toml, ptr);
|
|
2478
|
-
let p = peekTable(k[0], tbl, m, 0);
|
|
2479
|
-
if (!p) throw new TomlError("trying to redefine an already defined table or value", {
|
|
2480
|
-
toml,
|
|
2481
|
-
ptr
|
|
2482
|
-
});
|
|
2483
|
-
let v = extractValue(toml, k[1], void 0, maxDepth, integersAsBigInt);
|
|
2484
|
-
p[1][p[0]] = v[0];
|
|
2485
|
-
ptr = v[1];
|
|
2486
|
-
}
|
|
2487
|
-
ptr = skipVoid(toml, ptr, true);
|
|
2488
|
-
if (toml[ptr] && toml[ptr] !== "\n" && toml[ptr] !== "\r") throw new TomlError("each key-value declaration must be followed by an end-of-line", {
|
|
2489
|
-
toml,
|
|
2490
|
-
ptr
|
|
2491
|
-
});
|
|
2492
|
-
ptr = skipVoid(toml, ptr);
|
|
2493
|
-
}
|
|
2494
|
-
return res;
|
|
2495
|
-
}
|
|
2496
|
-
__name(parse3, "parse");
|
|
2497
|
-
var BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
2498
|
-
function extendedTypeOf(obj) {
|
|
2499
|
-
let type = typeof obj;
|
|
2500
|
-
if (type === "object") {
|
|
2501
|
-
if (Array.isArray(obj)) return "array";
|
|
2502
|
-
if (obj instanceof Date) return "date";
|
|
2503
|
-
}
|
|
2504
|
-
return type;
|
|
2505
|
-
}
|
|
2506
|
-
__name(extendedTypeOf, "extendedTypeOf");
|
|
2507
|
-
function isArrayOfTables(obj) {
|
|
2508
|
-
for (let i = 0; i < obj.length; i++) if (extendedTypeOf(obj[i]) !== "object") return false;
|
|
2509
|
-
return obj.length != 0;
|
|
2510
|
-
}
|
|
2511
|
-
__name(isArrayOfTables, "isArrayOfTables");
|
|
2512
|
-
function formatString(s) {
|
|
2513
|
-
return JSON.stringify(s).replace(/\x7f/g, "\\u007f");
|
|
2514
|
-
}
|
|
2515
|
-
__name(formatString, "formatString");
|
|
2516
|
-
function stringifyValue(val, type, depth, numberAsFloat) {
|
|
2517
|
-
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
2518
|
-
if (type === "number") {
|
|
2519
|
-
if (isNaN(val)) return "nan";
|
|
2520
|
-
if (val === Infinity) return "inf";
|
|
2521
|
-
if (val === -Infinity) return "-inf";
|
|
2522
|
-
if (numberAsFloat && Number.isInteger(val)) return val.toFixed(1);
|
|
2523
|
-
return val.toString();
|
|
2524
|
-
}
|
|
2525
|
-
if (type === "bigint" || type === "boolean") return val.toString();
|
|
2526
|
-
if (type === "string") return formatString(val);
|
|
2527
|
-
if (type === "date") {
|
|
2528
|
-
if (isNaN(val.getTime())) throw new TypeError("cannot serialize invalid date");
|
|
2529
|
-
return val.toISOString();
|
|
2530
|
-
}
|
|
2531
|
-
if (type === "object") return stringifyInlineTable(val, depth, numberAsFloat);
|
|
2532
|
-
if (type === "array") return stringifyArray(val, depth, numberAsFloat);
|
|
2533
|
-
}
|
|
2534
|
-
__name(stringifyValue, "stringifyValue");
|
|
2535
|
-
function stringifyInlineTable(obj, depth, numberAsFloat) {
|
|
2536
|
-
let keys = Object.keys(obj);
|
|
2537
|
-
if (keys.length === 0) return "{}";
|
|
2538
|
-
let res = "{ ";
|
|
2539
|
-
for (let i = 0; i < keys.length; i++) {
|
|
2540
|
-
let k = keys[i];
|
|
2541
|
-
if (i) res += ", ";
|
|
2542
|
-
res += BARE_KEY.test(k) ? k : formatString(k);
|
|
2543
|
-
res += " = ";
|
|
2544
|
-
res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat);
|
|
2545
|
-
}
|
|
2546
|
-
return res + " }";
|
|
2547
|
-
}
|
|
2548
|
-
__name(stringifyInlineTable, "stringifyInlineTable");
|
|
2549
|
-
function stringifyArray(array, depth, numberAsFloat) {
|
|
2550
|
-
if (array.length === 0) return "[]";
|
|
2551
|
-
let res = "[ ";
|
|
2552
|
-
for (let i = 0; i < array.length; i++) {
|
|
2553
|
-
if (i) res += ", ";
|
|
2554
|
-
if (array[i] === null || array[i] === void 0) throw new TypeError("arrays cannot contain null or undefined values");
|
|
2555
|
-
res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat);
|
|
2556
|
-
}
|
|
2557
|
-
return res + " ]";
|
|
2558
|
-
}
|
|
2559
|
-
__name(stringifyArray, "stringifyArray");
|
|
2560
|
-
function stringifyArrayTable(array, key, depth, numberAsFloat) {
|
|
2561
|
-
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
2562
|
-
let res = "";
|
|
2563
|
-
for (let i = 0; i < array.length; i++) {
|
|
2564
|
-
res += `${res && "\n"}[[${key}]]
|
|
2565
|
-
`;
|
|
2566
|
-
res += stringifyTable(0, array[i], key, depth, numberAsFloat);
|
|
2567
|
-
}
|
|
2568
|
-
return res;
|
|
2569
|
-
}
|
|
2570
|
-
__name(stringifyArrayTable, "stringifyArrayTable");
|
|
2571
|
-
function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
|
|
2572
|
-
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
2573
|
-
let preamble = "";
|
|
2574
|
-
let tables = "";
|
|
2575
|
-
let keys = Object.keys(obj);
|
|
2576
|
-
for (let i = 0; i < keys.length; i++) {
|
|
2577
|
-
let k = keys[i];
|
|
2578
|
-
if (obj[k] !== null && obj[k] !== void 0) {
|
|
2579
|
-
let type = extendedTypeOf(obj[k]);
|
|
2580
|
-
if (type === "symbol" || type === "function") throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
2581
|
-
let key = BARE_KEY.test(k) ? k : formatString(k);
|
|
2582
|
-
if (type === "array" && isArrayOfTables(obj[k])) tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
|
|
2583
|
-
else if (type === "object") {
|
|
2584
|
-
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
2585
|
-
tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
|
|
2586
|
-
} else {
|
|
2587
|
-
preamble += key;
|
|
2588
|
-
preamble += " = ";
|
|
2589
|
-
preamble += stringifyValue(obj[k], type, depth, numberAsFloat);
|
|
2590
|
-
preamble += "\n";
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
if (tableKey && (preamble || !tables)) preamble = preamble ? `[${tableKey}]
|
|
2595
|
-
${preamble}` : `[${tableKey}]`;
|
|
2596
|
-
return preamble && tables ? `${preamble}
|
|
2597
|
-
${tables}` : preamble || tables;
|
|
2598
|
-
}
|
|
2599
|
-
__name(stringifyTable, "stringifyTable");
|
|
2600
|
-
function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
|
|
2601
|
-
if (extendedTypeOf(obj) !== "object") throw new TypeError("stringify can only be called with an object");
|
|
2602
|
-
let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
|
|
2603
|
-
if (str[str.length - 1] !== "\n") return str + "\n";
|
|
2604
|
-
return str;
|
|
2605
|
-
}
|
|
2606
|
-
__name(stringify, "stringify");
|
|
2607
|
-
var dist_default = {
|
|
2608
|
-
parse: parse3,
|
|
2609
|
-
stringify,
|
|
2610
|
-
TomlDate,
|
|
2611
|
-
TomlError
|
|
2612
|
-
};
|
|
2613
|
-
var ParseError = class extends UserError {
|
|
2614
|
-
static {
|
|
2615
|
-
__name(this, "ParseError");
|
|
2616
|
-
}
|
|
2617
|
-
text;
|
|
2618
|
-
notes;
|
|
2619
|
-
location;
|
|
2620
|
-
kind;
|
|
2621
|
-
constructor({ text, notes, location, kind, telemetryMessage }) {
|
|
2622
|
-
super(text, { telemetryMessage });
|
|
2623
|
-
this.name = this.constructor.name;
|
|
2624
|
-
this.text = text;
|
|
2625
|
-
this.notes = notes ?? [];
|
|
2626
|
-
this.location = location;
|
|
2627
|
-
this.kind = kind ?? "error";
|
|
2628
|
-
}
|
|
2629
|
-
};
|
|
2630
|
-
var APIError = class extends ParseError {
|
|
2631
|
-
static {
|
|
2632
|
-
__name(this, "APIError");
|
|
2633
|
-
}
|
|
2634
|
-
#status;
|
|
2635
|
-
code;
|
|
2636
|
-
accountTag;
|
|
2637
|
-
/**
|
|
2638
|
-
* Optional structured metadata hoisted from the first `FetchError.meta`
|
|
2639
|
-
* on the v4 response envelope. Consumers can inspect this to render
|
|
2640
|
-
* endpoint-specific structured error payloads.
|
|
2641
|
-
*/
|
|
2642
|
-
meta;
|
|
2643
|
-
/**
|
|
2644
|
-
* Optional number of milliseconds the API asked us to wait before retrying,
|
|
2645
|
-
* derived from the response's `Retry-After` header (if present).
|
|
2646
|
-
*/
|
|
2647
|
-
retryAfterMs;
|
|
2648
|
-
constructor({ status, retryAfterMs,...rest }) {
|
|
2649
|
-
super(rest);
|
|
2650
|
-
this.name = this.constructor.name;
|
|
2651
|
-
this.#status = status;
|
|
2652
|
-
this.retryAfterMs = retryAfterMs;
|
|
2653
|
-
}
|
|
2654
|
-
get status() {
|
|
2655
|
-
return this.#status;
|
|
2656
|
-
}
|
|
2657
|
-
isGatewayError() {
|
|
2658
|
-
if (this.#status !== void 0) return [524].includes(this.#status);
|
|
2659
|
-
return false;
|
|
2660
|
-
}
|
|
2661
|
-
isRetryable() {
|
|
2662
|
-
return String(this.#status).startsWith("5");
|
|
2663
|
-
}
|
|
2664
|
-
#reportable = true;
|
|
2665
|
-
get reportable() {
|
|
2666
|
-
return this.#reportable;
|
|
2667
|
-
}
|
|
2668
|
-
preventReport() {
|
|
2669
|
-
this.#reportable = false;
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2672
|
-
function parseTOML(tomlContent, filePath) {
|
|
2673
|
-
try {
|
|
2674
|
-
return dist_default.parse(tomlContent);
|
|
2675
|
-
} catch (err) {
|
|
2676
|
-
if (!(err instanceof TomlError)) throw err;
|
|
2677
|
-
const location = {
|
|
2678
|
-
lineText: tomlContent.split("\n")[err.line - 1],
|
|
2679
|
-
line: err.line,
|
|
2680
|
-
column: err.column - 1,
|
|
2681
|
-
file: filePath,
|
|
2682
|
-
fileText: tomlContent
|
|
2683
|
-
};
|
|
2684
|
-
throw new ParseError({
|
|
2685
|
-
text: err.message.substring(0, err.message.indexOf("\n")),
|
|
2686
|
-
location,
|
|
2687
|
-
telemetryMessage: "TOML parse error"
|
|
2688
|
-
});
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
__name(parseTOML, "parseTOML");
|
|
2692
|
-
function parsePackageJSON(input, file2) {
|
|
2693
|
-
return parseJSON(input, file2);
|
|
2694
|
-
}
|
|
2695
|
-
__name(parsePackageJSON, "parsePackageJSON");
|
|
2696
|
-
function parseJSON(input, file2) {
|
|
2697
|
-
return parseJSONC(input, file2, {
|
|
2698
|
-
allowEmptyContent: false,
|
|
2699
|
-
allowTrailingComma: false,
|
|
2700
|
-
disallowComments: true
|
|
2701
|
-
});
|
|
2702
|
-
}
|
|
2703
|
-
__name(parseJSON, "parseJSON");
|
|
2704
|
-
function parseJSONC(input, file2, options = { allowTrailingComma: true }) {
|
|
2705
|
-
const errors = [];
|
|
2706
|
-
const data = parse2(input, errors, options);
|
|
2707
|
-
if (errors.length) throw new ParseError({
|
|
2708
|
-
text: printParseErrorCode(errors[0].error),
|
|
2709
|
-
location: {
|
|
2710
|
-
...indexLocation({
|
|
2711
|
-
file: file2,
|
|
2712
|
-
fileText: input
|
|
2713
|
-
}, errors[0].offset + 1),
|
|
2714
|
-
length: errors[0].length
|
|
2715
|
-
},
|
|
2716
|
-
telemetryMessage: "JSON(C) parse error"
|
|
2717
|
-
});
|
|
2718
|
-
return data;
|
|
2719
|
-
}
|
|
2720
|
-
__name(parseJSONC, "parseJSONC");
|
|
2721
|
-
function readFileSyncToBuffer(file2) {
|
|
2722
|
-
try {
|
|
2723
|
-
return readFileSync(file2);
|
|
2724
|
-
} catch (err) {
|
|
2725
|
-
const { message } = err;
|
|
2726
|
-
throw new ParseError({
|
|
2727
|
-
text: `Could not read file: ${file2}`,
|
|
2728
|
-
notes: [{ text: message.replace(file2, resolve(file2)) }],
|
|
2729
|
-
telemetryMessage: false
|
|
2730
|
-
});
|
|
2731
|
-
}
|
|
2732
|
-
}
|
|
2733
|
-
__name(readFileSyncToBuffer, "readFileSyncToBuffer");
|
|
2734
|
-
function readFileSync$1(file2) {
|
|
2735
|
-
try {
|
|
2736
|
-
return removeBOMAndValidate(readFileSync(file2), file2);
|
|
2737
|
-
} catch (err) {
|
|
2738
|
-
if (err instanceof ParseError) throw err;
|
|
2739
|
-
const { message } = err;
|
|
2740
|
-
throw new ParseError({
|
|
2741
|
-
text: `Could not read file: ${file2}`,
|
|
2742
|
-
notes: [{ text: message.replace(file2, resolve(file2)) }],
|
|
2743
|
-
telemetryMessage: "Could not read file"
|
|
2744
|
-
});
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
__name(readFileSync$1, "readFileSync");
|
|
2748
|
-
function indexLocation(file2, index) {
|
|
2749
|
-
let lineText, line = 0, column = 0, cursor = 0;
|
|
2750
|
-
const { fileText = "" } = file2;
|
|
2751
|
-
for (const row of fileText.split("\n")) {
|
|
2752
|
-
line++;
|
|
2753
|
-
cursor += row.length + 1;
|
|
2754
|
-
if (cursor >= index) {
|
|
2755
|
-
lineText = row;
|
|
2756
|
-
column = row.length - (cursor - index);
|
|
2757
|
-
break;
|
|
2758
|
-
}
|
|
2759
|
-
}
|
|
2760
|
-
return {
|
|
2761
|
-
lineText,
|
|
2762
|
-
line,
|
|
2763
|
-
column,
|
|
2764
|
-
...file2
|
|
2765
|
-
};
|
|
2766
|
-
}
|
|
2767
|
-
__name(indexLocation, "indexLocation");
|
|
2768
|
-
function searchLocation(file2, query) {
|
|
2769
|
-
let lineText, length, line = 0, column = 0;
|
|
2770
|
-
const queryText = String(query);
|
|
2771
|
-
const { fileText = "" } = file2;
|
|
2772
|
-
for (const content of fileText.split("\n")) {
|
|
2773
|
-
line++;
|
|
2774
|
-
const index = content.indexOf(queryText);
|
|
2775
|
-
if (index >= 0) {
|
|
2776
|
-
lineText = content;
|
|
2777
|
-
column = index;
|
|
2778
|
-
length = queryText.length;
|
|
2779
|
-
break;
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2782
|
-
return {
|
|
2783
|
-
lineText,
|
|
2784
|
-
line,
|
|
2785
|
-
column,
|
|
2786
|
-
length,
|
|
2787
|
-
...file2
|
|
2788
|
-
};
|
|
2789
|
-
}
|
|
2790
|
-
__name(searchLocation, "searchLocation");
|
|
2791
|
-
var units = {
|
|
2792
|
-
nanoseconds: 1e-9,
|
|
2793
|
-
nanosecond: 1e-9,
|
|
2794
|
-
microseconds: 1e-6,
|
|
2795
|
-
microsecond: 1e-6,
|
|
2796
|
-
milliseconds: .001,
|
|
2797
|
-
millisecond: .001,
|
|
2798
|
-
seconds: 1,
|
|
2799
|
-
second: 1,
|
|
2800
|
-
minutes: 60,
|
|
2801
|
-
minute: 60,
|
|
2802
|
-
hours: 3600,
|
|
2803
|
-
hour: 3600,
|
|
2804
|
-
days: 86400,
|
|
2805
|
-
day: 86400,
|
|
2806
|
-
weeks: 604800,
|
|
2807
|
-
week: 604800,
|
|
2808
|
-
month: 18144e3,
|
|
2809
|
-
year: 220752e3,
|
|
2810
|
-
nsecs: 1e-9,
|
|
2811
|
-
nsec: 1e-9,
|
|
2812
|
-
usecs: 1e-6,
|
|
2813
|
-
usec: 1e-6,
|
|
2814
|
-
msecs: .001,
|
|
2815
|
-
msec: .001,
|
|
2816
|
-
secs: 1,
|
|
2817
|
-
sec: 1,
|
|
2818
|
-
mins: 60,
|
|
2819
|
-
min: 60,
|
|
2820
|
-
ns: 1e-9,
|
|
2821
|
-
us: 1e-6,
|
|
2822
|
-
ms: .001,
|
|
2823
|
-
mo: 18144e3,
|
|
2824
|
-
yr: 220752e3,
|
|
2825
|
-
s: 1,
|
|
2826
|
-
m: 60,
|
|
2827
|
-
h: 3600,
|
|
2828
|
-
d: 86400,
|
|
2829
|
-
w: 604800,
|
|
2830
|
-
y: 220752e3
|
|
2831
|
-
};
|
|
2832
|
-
function parseHumanDuration(s) {
|
|
2833
|
-
const unitsMap = new Map(Object.entries(units));
|
|
2834
|
-
s = s.trim().toLowerCase();
|
|
2835
|
-
let base = 1;
|
|
2836
|
-
for (const [name, _] of unitsMap) if (s.endsWith(name)) {
|
|
2837
|
-
s = s.substring(0, s.length - name.length);
|
|
2838
|
-
base = unitsMap.get(name) || 1;
|
|
2839
|
-
break;
|
|
2840
|
-
}
|
|
2841
|
-
return Number(s) * base;
|
|
2842
|
-
}
|
|
2843
|
-
__name(parseHumanDuration, "parseHumanDuration");
|
|
2844
|
-
function parseNonHyphenedUuid(uuid) {
|
|
2845
|
-
if (uuid == null || uuid.includes("-")) return uuid;
|
|
2846
|
-
if (uuid.length != 32) return null;
|
|
2847
|
-
const uuid_parts = [];
|
|
2848
|
-
uuid_parts.push(uuid.slice(0, 8));
|
|
2849
|
-
uuid_parts.push(uuid.slice(8, 12));
|
|
2850
|
-
uuid_parts.push(uuid.slice(12, 16));
|
|
2851
|
-
uuid_parts.push(uuid.slice(16, 20));
|
|
2852
|
-
uuid_parts.push(uuid.slice(20));
|
|
2853
|
-
let hyphenated = "";
|
|
2854
|
-
uuid_parts.forEach((part) => hyphenated += part + "-");
|
|
2855
|
-
return hyphenated.slice(0, 36);
|
|
2856
|
-
}
|
|
2857
|
-
__name(parseNonHyphenedUuid, "parseNonHyphenedUuid");
|
|
2858
|
-
function parseByteSize(s, base = void 0) {
|
|
2859
|
-
const match = s.match(/^(\d*\.*\d*)\s*([kKmMgGtTpP]{0,1})([i]{0,1}[bB]{0,1})$/);
|
|
2860
|
-
if (!match) return NaN;
|
|
2861
|
-
const size = match[1];
|
|
2862
|
-
if (size.length === 0 || isNaN(Number(size))) return NaN;
|
|
2863
|
-
const unit = match[2].toLowerCase();
|
|
2864
|
-
const sizeUnits = {
|
|
2865
|
-
k: 1,
|
|
2866
|
-
m: 2,
|
|
2867
|
-
g: 3,
|
|
2868
|
-
t: 4,
|
|
2869
|
-
p: 5
|
|
2870
|
-
};
|
|
2871
|
-
if (unit.length !== 0 && !(unit in sizeUnits)) return NaN;
|
|
2872
|
-
const binary = match[3].toLowerCase() == "ib";
|
|
2873
|
-
if (binary && unit.length === 0) return NaN;
|
|
2874
|
-
const pow = sizeUnits[unit] || 0;
|
|
2875
|
-
return Math.floor(Number(size) * Math.pow(base ?? (binary ? 1024 : 1e3), pow));
|
|
2876
|
-
}
|
|
2877
|
-
__name(parseByteSize, "parseByteSize");
|
|
2878
|
-
var UNSUPPORTED_BOMS = [
|
|
2879
|
-
{
|
|
2880
|
-
buffer: Buffer.from([
|
|
2881
|
-
0,
|
|
2882
|
-
0,
|
|
2883
|
-
254,
|
|
2884
|
-
255
|
|
2885
|
-
]),
|
|
2886
|
-
encoding: "UTF-32 BE"
|
|
2887
|
-
},
|
|
2888
|
-
{
|
|
2889
|
-
buffer: Buffer.from([
|
|
2890
|
-
255,
|
|
2891
|
-
254,
|
|
2892
|
-
0,
|
|
2893
|
-
0
|
|
2894
|
-
]),
|
|
2895
|
-
encoding: "UTF-32 LE"
|
|
2896
|
-
},
|
|
2897
|
-
{
|
|
2898
|
-
buffer: Buffer.from([254, 255]),
|
|
2899
|
-
encoding: "UTF-16 BE"
|
|
2900
|
-
},
|
|
2901
|
-
{
|
|
2902
|
-
buffer: Buffer.from([255, 254]),
|
|
2903
|
-
encoding: "UTF-16 LE"
|
|
2904
|
-
}
|
|
2905
|
-
];
|
|
2906
|
-
function removeBOMAndValidate(buffer, file2) {
|
|
2907
|
-
for (const bom of UNSUPPORTED_BOMS) if (buffer.length >= bom.buffer.length && buffer.subarray(0, bom.buffer.length).equals(bom.buffer)) throw new ParseError({
|
|
2908
|
-
text: `Configuration file contains ${bom.encoding} byte order marker`,
|
|
2909
|
-
notes: [{ text: `The file "${file2}" appears to be encoded as ${bom.encoding}. Please save the file as UTF-8 without BOM.` }],
|
|
2910
|
-
location: {
|
|
2911
|
-
file: file2,
|
|
2912
|
-
line: 1,
|
|
2913
|
-
column: 0
|
|
2914
|
-
},
|
|
2915
|
-
telemetryMessage: `${bom.encoding} BOM detected`
|
|
2916
|
-
});
|
|
2917
|
-
const content = buffer.toString("utf-8");
|
|
2918
|
-
if (content.charCodeAt(0) === 65279) return content.slice(1);
|
|
2919
|
-
return content;
|
|
2920
|
-
}
|
|
2921
|
-
__name(removeBOMAndValidate, "removeBOMAndValidate");
|
|
2922
|
-
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
2923
|
-
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
2924
|
-
function absolute(input, root) {
|
|
2925
|
-
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
2926
|
-
}
|
|
2927
|
-
__name(absolute, "absolute");
|
|
2928
|
-
function up(base, options) {
|
|
2929
|
-
let { last, cwd } = options || {};
|
|
2930
|
-
let tmp = absolute(base, cwd);
|
|
2931
|
-
let root = absolute(last || "/", cwd);
|
|
2932
|
-
let prev, arr = [];
|
|
2933
|
-
while (prev !== root) {
|
|
2934
|
-
arr.push(tmp);
|
|
2935
|
-
tmp = dirname(prev = tmp);
|
|
2936
|
-
if (tmp === prev) break;
|
|
2937
|
-
}
|
|
2938
|
-
return arr;
|
|
2939
|
-
}
|
|
2940
|
-
__name(up, "up");
|
|
2941
|
-
function file(name, options) {
|
|
2942
|
-
let dir2, tmp;
|
|
2943
|
-
for (dir2 of up(options && options.cwd || "", options)) try {
|
|
2944
|
-
tmp = join(dir2, name);
|
|
2945
|
-
if (statSync(tmp).isFile()) return tmp;
|
|
2946
|
-
} catch {}
|
|
2947
|
-
}
|
|
2948
|
-
__name(file, "file");
|
|
2949
|
-
function dir(name, options) {
|
|
2950
|
-
let dir2, tmp;
|
|
2951
|
-
for (dir2 of up(options && options.cwd || "", options)) try {
|
|
2952
|
-
tmp = join(dir2, name);
|
|
2953
|
-
if (statSync(tmp).isDirectory()) return tmp;
|
|
2954
|
-
} catch {}
|
|
2955
|
-
}
|
|
2956
|
-
__name(dir, "dir");
|
|
2957
|
-
function dedent(templ) {
|
|
2958
|
-
var values = [];
|
|
2959
|
-
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
2960
|
-
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
2961
|
-
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
2962
|
-
var indentLengths = strings.reduce(function(arr, str) {
|
|
2963
|
-
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
2964
|
-
if (matches) return arr.concat(matches.map(function(match) {
|
|
2965
|
-
var _a, _b;
|
|
2966
|
-
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
2967
|
-
}));
|
|
2968
|
-
return arr;
|
|
2969
|
-
}, []);
|
|
2970
|
-
if (indentLengths.length) {
|
|
2971
|
-
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
|
|
2972
|
-
strings = strings.map(function(str) {
|
|
2973
|
-
return str.replace(pattern_1, "\n");
|
|
2974
|
-
});
|
|
2975
|
-
}
|
|
2976
|
-
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
2977
|
-
var string = strings[0];
|
|
2978
|
-
values.forEach(function(value, i) {
|
|
2979
|
-
var endentations = string.match(/(?:^|\n)( *)$/);
|
|
2980
|
-
var endentation = endentations ? endentations[1] : "";
|
|
2981
|
-
var indentedValue = value;
|
|
2982
|
-
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map(function(str, i2) {
|
|
2983
|
-
return i2 === 0 ? str : "" + endentation + str;
|
|
2984
|
-
}).join("\n");
|
|
2985
|
-
string += indentedValue + strings[i + 1];
|
|
2986
|
-
});
|
|
2987
|
-
return string;
|
|
2988
|
-
}
|
|
2989
|
-
__name(dedent, "dedent");
|
|
2990
|
-
var esm_default = dedent;
|
|
2991
|
-
function resolveWranglerConfigPath({ config, script }, options) {
|
|
2992
|
-
if (config !== void 0) return {
|
|
2993
|
-
userConfigPath: config,
|
|
2994
|
-
configPath: config,
|
|
2995
|
-
deployConfigPath: void 0,
|
|
2996
|
-
redirected: false
|
|
2997
|
-
};
|
|
2998
|
-
return findWranglerConfig(script !== void 0 ? path2__default.dirname(script) : process.cwd(), options);
|
|
2999
|
-
}
|
|
3000
|
-
__name(resolveWranglerConfigPath, "resolveWranglerConfigPath");
|
|
3001
|
-
function findWranglerConfig(referencePath = process.cwd(), { useRedirectIfAvailable = false } = {}) {
|
|
3002
|
-
const userConfigPath = file(`wrangler.json`, { cwd: referencePath }) ?? file(`wrangler.jsonc`, { cwd: referencePath }) ?? file(`wrangler.toml`, { cwd: referencePath });
|
|
3003
|
-
if (!useRedirectIfAvailable) return {
|
|
3004
|
-
userConfigPath,
|
|
3005
|
-
configPath: userConfigPath,
|
|
3006
|
-
deployConfigPath: void 0,
|
|
3007
|
-
redirected: false
|
|
3008
|
-
};
|
|
3009
|
-
const { configPath, deployConfigPath, redirected } = findRedirectedWranglerConfig(referencePath, userConfigPath);
|
|
3010
|
-
return {
|
|
3011
|
-
userConfigPath,
|
|
3012
|
-
configPath,
|
|
3013
|
-
deployConfigPath,
|
|
3014
|
-
redirected
|
|
3015
|
-
};
|
|
3016
|
-
}
|
|
3017
|
-
__name(findWranglerConfig, "findWranglerConfig");
|
|
3018
|
-
function findRedirectedWranglerConfig(cwd, userConfigPath) {
|
|
3019
|
-
const deployConfigPath = file(PATH_TO_DEPLOY_CONFIG, { cwd });
|
|
3020
|
-
if (deployConfigPath === void 0) return {
|
|
3021
|
-
configPath: userConfigPath,
|
|
3022
|
-
deployConfigPath,
|
|
3023
|
-
redirected: false
|
|
3024
|
-
};
|
|
3025
|
-
let redirectedConfigPath;
|
|
3026
|
-
const deployConfigFile = readFileSync$1(deployConfigPath);
|
|
3027
|
-
try {
|
|
3028
|
-
const deployConfig = parseJSONC(deployConfigFile, deployConfigPath);
|
|
3029
|
-
redirectedConfigPath = deployConfig.configPath && path2__default.resolve(path2__default.dirname(deployConfigPath), deployConfig.configPath);
|
|
3030
|
-
} catch (e) {
|
|
3031
|
-
throw new UserError(`Failed to parse the deploy configuration file at ${path2__default.relative(".", deployConfigPath)}`, {
|
|
3032
|
-
cause: e,
|
|
3033
|
-
telemetryMessage: false
|
|
3034
|
-
});
|
|
3035
|
-
}
|
|
3036
|
-
if (!redirectedConfigPath) throw new UserError(esm_default`
|
|
3037
|
-
A deploy configuration file was found at "${path2__default.relative(".", deployConfigPath)}".
|
|
3038
|
-
But this is not valid - the required "configPath" property was not found.
|
|
3039
|
-
Instead this file contains:
|
|
3040
|
-
\`\`\`
|
|
3041
|
-
${deployConfigFile}
|
|
3042
|
-
\`\`\`
|
|
3043
|
-
`, { telemetryMessage: false });
|
|
3044
|
-
if (!existsSync(redirectedConfigPath)) throw new UserError(esm_default`
|
|
3045
|
-
There is a deploy configuration at "${path2__default.relative(".", deployConfigPath)}".
|
|
3046
|
-
But the redirected configuration path it points to, "${path2__default.relative(".", redirectedConfigPath)}", does not exist.
|
|
3047
|
-
`, { telemetryMessage: false });
|
|
3048
|
-
if (userConfigPath) {
|
|
3049
|
-
if (path2__default.join(path2__default.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) throw new UserError(esm_default`
|
|
3050
|
-
Found both a user configuration file at "${path2__default.relative(".", userConfigPath)}"
|
|
3051
|
-
and a deploy configuration file at "${path2__default.relative(".", deployConfigPath)}".
|
|
3052
|
-
But these do not share the same base path so it is not clear which should be used.
|
|
3053
|
-
`, { telemetryMessage: false });
|
|
3054
|
-
}
|
|
3055
|
-
return {
|
|
3056
|
-
configPath: redirectedConfigPath,
|
|
3057
|
-
deployConfigPath,
|
|
3058
|
-
redirected: true
|
|
3059
|
-
};
|
|
3060
|
-
}
|
|
3061
|
-
__name(findRedirectedWranglerConfig, "findRedirectedWranglerConfig");
|
|
3062
|
-
function isRedirectedConfig(config) {
|
|
3063
|
-
return config.configPath !== void 0 && config.configPath !== config.userConfigPath;
|
|
3064
|
-
}
|
|
3065
|
-
__name(isRedirectedConfig, "isRedirectedConfig");
|
|
3066
|
-
function isRedirectedRawConfig(rawConfig, configPath, userConfigPath) {
|
|
3067
|
-
return isRedirectedConfig({
|
|
3068
|
-
configPath,
|
|
3069
|
-
userConfigPath
|
|
3070
|
-
});
|
|
3071
|
-
}
|
|
3072
|
-
__name(isRedirectedRawConfig, "isRedirectedRawConfig");
|
|
3073
|
-
function configFormat(configPath) {
|
|
3074
|
-
if (configPath?.endsWith("toml")) return "toml";
|
|
3075
|
-
if (configPath?.endsWith("jsonc")) return "jsonc";
|
|
3076
|
-
if (configPath?.endsWith("json")) return "json";
|
|
3077
|
-
return "none";
|
|
3078
|
-
}
|
|
3079
|
-
__name(configFormat, "configFormat");
|
|
3080
|
-
function configFileName(configPath) {
|
|
3081
|
-
switch (configFormat(configPath)) {
|
|
3082
|
-
case "toml": return "wrangler.toml";
|
|
3083
|
-
case "json": return "wrangler.json";
|
|
3084
|
-
case "jsonc": return "wrangler.jsonc";
|
|
3085
|
-
default: return "Wrangler configuration";
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
__name(configFileName, "configFileName");
|
|
3089
|
-
function formatConfigSnippet(snippet, configPath, formatted = true) {
|
|
3090
|
-
if (configFormat(configPath) === "toml") return dist_default.stringify(snippet);
|
|
3091
|
-
else return formatted ? JSON.stringify(snippet, null, 2) : JSON.stringify(snippet);
|
|
3092
|
-
}
|
|
3093
|
-
__name(formatConfigSnippet, "formatConfigSnippet");
|
|
3094
665
|
|
|
3095
666
|
//#endregion
|
|
3096
667
|
//#region src/convert.ts
|
|
@@ -3152,6 +723,7 @@ function convertObservability(observability) {
|
|
|
3152
723
|
const out = {};
|
|
3153
724
|
if (observability.enabled !== void 0) out.enabled = observability.enabled;
|
|
3154
725
|
if (observability.headSamplingRate !== void 0) out.head_sampling_rate = observability.headSamplingRate;
|
|
726
|
+
if (observability.redactQueryString !== void 0) out.redact_query_string = observability.redactQueryString;
|
|
3155
727
|
if (observability.logs !== void 0) {
|
|
3156
728
|
const logs = {};
|
|
3157
729
|
const { logs: src } = observability;
|
|
@@ -3289,7 +861,7 @@ function convertBindingsAndAssets(config, result) {
|
|
|
3289
861
|
namespace: binding.namespace
|
|
3290
862
|
};
|
|
3291
863
|
if (binding.outbound) entry.outbound = omitUndefined({
|
|
3292
|
-
service: binding.outbound.
|
|
864
|
+
service: binding.outbound.worker,
|
|
3293
865
|
parameters: binding.outbound.parameters
|
|
3294
866
|
});
|
|
3295
867
|
if (binding.dev?.remote !== void 0) entry.remote = binding.dev.remote;
|
|
@@ -3300,7 +872,7 @@ function convertBindingsAndAssets(config, result) {
|
|
|
3300
872
|
durableObjectBindings.push({
|
|
3301
873
|
name,
|
|
3302
874
|
class_name: binding.exportName,
|
|
3303
|
-
script_name: binding.
|
|
875
|
+
script_name: binding.worker
|
|
3304
876
|
});
|
|
3305
877
|
break;
|
|
3306
878
|
case "flagship":
|
|
@@ -3451,7 +1023,7 @@ function convertBindingsAndAssets(config, result) {
|
|
|
3451
1023
|
case "worker":
|
|
3452
1024
|
services.push(omitUndefined({
|
|
3453
1025
|
binding: name,
|
|
3454
|
-
service: binding.
|
|
1026
|
+
service: binding.worker,
|
|
3455
1027
|
entrypoint: binding.exportName,
|
|
3456
1028
|
props: binding.props,
|
|
3457
1029
|
remote: binding.dev?.remote
|
|
@@ -3632,8 +1204,8 @@ function convertTailConsumers(config, result) {
|
|
|
3632
1204
|
if (!consumers || consumers.length === 0) return;
|
|
3633
1205
|
const tail = [];
|
|
3634
1206
|
const streaming = [];
|
|
3635
|
-
for (const consumer of consumers) if (consumer.streaming) streaming.push({ service: consumer.
|
|
3636
|
-
else tail.push({ service: consumer.
|
|
1207
|
+
for (const consumer of consumers) if (consumer.streaming) streaming.push({ service: consumer.worker });
|
|
1208
|
+
else tail.push({ service: consumer.worker });
|
|
3637
1209
|
if (tail.length) result.tail_consumers = tail;
|
|
3638
1210
|
if (streaming.length) result.streaming_tail_consumers = streaming;
|
|
3639
1211
|
}
|