@treeseed/sdk 0.6.13 → 0.6.14
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.
|
@@ -55,10 +55,33 @@ function loadAppliedMigrations({ cwd, wranglerConfig, persistTo }) {
|
|
|
55
55
|
capture: true,
|
|
56
56
|
command: "SELECT name FROM treeseed_schema_migrations ORDER BY name ASC;"
|
|
57
57
|
});
|
|
58
|
-
const parsed =
|
|
58
|
+
const parsed = parseWranglerJsonOutput(result.stdout);
|
|
59
59
|
const rows = (Array.isArray(parsed) ? parsed : [parsed]).flatMap((entry) => entry.results ?? []);
|
|
60
60
|
return new Set(rows.map((row) => row.name).filter(Boolean));
|
|
61
61
|
}
|
|
62
|
+
function parseWranglerJsonOutput(stdout) {
|
|
63
|
+
const trimmed = String(stdout ?? "").trim();
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(trimmed);
|
|
66
|
+
} catch {
|
|
67
|
+
const firstArray = trimmed.indexOf("[");
|
|
68
|
+
const firstObject = trimmed.indexOf("{");
|
|
69
|
+
const candidates = [firstArray, firstObject].filter((index) => index >= 0).sort((left, right) => left - right);
|
|
70
|
+
for (const start of candidates) {
|
|
71
|
+
const opener = trimmed[start];
|
|
72
|
+
const closer = opener === "[" ? "]" : "}";
|
|
73
|
+
const end = trimmed.lastIndexOf(closer);
|
|
74
|
+
if (end <= start) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(trimmed.slice(start, end + 1));
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
throw new Error("Unable to parse JSON output from Wrangler D1.");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
62
85
|
function markMigrationApplied({ cwd, wranglerConfig, persistTo, migration }) {
|
|
63
86
|
executeSqlCommand({
|
|
64
87
|
cwd,
|