edhvault-mcp 0.2.22 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +1293 -224
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -820,6 +820,15 @@ async function call(t, url2, init, timeoutMs = FETCH_TIMEOUTS.sync.timeoutMs) {
|
|
|
820
820
|
if (why === "scope") {
|
|
821
821
|
throw new SyncHttpError("no-scope", "This access code can't read that part of your library.");
|
|
822
822
|
}
|
|
823
|
+
if (why === "off") {
|
|
824
|
+
throw new SyncHttpError("off", "This link was turned off or has expired. Ask whoever sent it for a new one.");
|
|
825
|
+
}
|
|
826
|
+
if (why === "too many links") {
|
|
827
|
+
throw new SyncHttpError("forbidden", "You already have the most suggest links you can (50). Turn one off first.");
|
|
828
|
+
}
|
|
829
|
+
if (why === "too many for deck") {
|
|
830
|
+
throw new SyncHttpError("forbidden", "This deck already has the most suggest links it can (10). Turn one off first.");
|
|
831
|
+
}
|
|
823
832
|
if (why === "too many codes") {
|
|
824
833
|
throw new SyncHttpError("forbidden", "You already have the most access codes you can (10). Remove one first.");
|
|
825
834
|
}
|
|
@@ -1691,6 +1700,51 @@ var init_aiMarks = __esm({
|
|
|
1691
1700
|
}
|
|
1692
1701
|
});
|
|
1693
1702
|
|
|
1703
|
+
// ../src/lib/deckPlan/checkpointStore.ts
|
|
1704
|
+
var init_checkpointStore = __esm({
|
|
1705
|
+
"../src/lib/deckPlan/checkpointStore.ts"() {
|
|
1706
|
+
"use strict";
|
|
1707
|
+
init_build();
|
|
1708
|
+
init_storage();
|
|
1709
|
+
init_storageKey();
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1712
|
+
|
|
1713
|
+
// ../src/lib/sync/syncHistory.ts
|
|
1714
|
+
async function pipe(bytes, stream) {
|
|
1715
|
+
const out = new Response(new Blob([bytes]).stream().pipeThrough(stream));
|
|
1716
|
+
return new Uint8Array(await out.arrayBuffer());
|
|
1717
|
+
}
|
|
1718
|
+
async function unpackHistory(text) {
|
|
1719
|
+
try {
|
|
1720
|
+
let json3 = text;
|
|
1721
|
+
if (text.startsWith(GZ)) {
|
|
1722
|
+
if (typeof DecompressionStream === "undefined") return null;
|
|
1723
|
+
const z2 = base64UrlToBytes(text.slice(GZ.length));
|
|
1724
|
+
if (!z2) return null;
|
|
1725
|
+
json3 = new TextDecoder().decode(await pipe(z2, new DecompressionStream("gzip")));
|
|
1726
|
+
}
|
|
1727
|
+
const doc = JSON.parse(json3);
|
|
1728
|
+
if (!doc || doc.v !== 1 || !Array.isArray(doc.list)) return null;
|
|
1729
|
+
return doc;
|
|
1730
|
+
} catch {
|
|
1731
|
+
return null;
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
var SYNC_HISTORY_MAX_BYTES, DAY_MS2, GZ;
|
|
1735
|
+
var init_syncHistory = __esm({
|
|
1736
|
+
"../src/lib/sync/syncHistory.ts"() {
|
|
1737
|
+
"use strict";
|
|
1738
|
+
init_checkpointStore();
|
|
1739
|
+
init_sealedBox();
|
|
1740
|
+
init_syncKeys();
|
|
1741
|
+
init_syncApi();
|
|
1742
|
+
SYNC_HISTORY_MAX_BYTES = 4 * 1024 * 1024;
|
|
1743
|
+
DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
1744
|
+
GZ = "gz1:";
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
|
|
1694
1748
|
// ../../commander/node_modules/ajv/dist/compile/codegen/code.js
|
|
1695
1749
|
var require_code = __commonJS({
|
|
1696
1750
|
"../../commander/node_modules/ajv/dist/compile/codegen/code.js"(exports) {
|
|
@@ -8591,11 +8645,12 @@ function mergeDuplicates(entries2) {
|
|
|
8591
8645
|
const existing = merged.get(key2);
|
|
8592
8646
|
if (existing) {
|
|
8593
8647
|
existing.quantity += entry.quantity;
|
|
8648
|
+
if (entry.acquired) mergeAcquired(existing, entry);
|
|
8594
8649
|
if (entry.tags && entry.tags.length > 0) {
|
|
8595
8650
|
existing.tags = unionTags(existing.tags, entry.tags);
|
|
8596
8651
|
}
|
|
8597
8652
|
} else {
|
|
8598
|
-
merged.set(key2, { ...entry });
|
|
8653
|
+
merged.set(key2, entry.acquired ? { ...entry, acquired: entry.acquired.map((l) => ({ ...l })) } : { ...entry });
|
|
8599
8654
|
}
|
|
8600
8655
|
}
|
|
8601
8656
|
return Array.from(merged.values());
|
|
@@ -8612,6 +8667,44 @@ function unionTags(a, b) {
|
|
|
8612
8667
|
}
|
|
8613
8668
|
return out;
|
|
8614
8669
|
}
|
|
8670
|
+
function mergeAcquired(into, from) {
|
|
8671
|
+
const lots = into.acquired ??= [];
|
|
8672
|
+
const currency = into.purchaseCurrency ?? from.purchaseCurrency;
|
|
8673
|
+
const clash = !!from.purchaseCurrency && !!into.purchaseCurrency && from.purchaseCurrency !== into.purchaseCurrency;
|
|
8674
|
+
for (const lot of from.acquired ?? []) {
|
|
8675
|
+
if (clash && lot.price !== void 0) {
|
|
8676
|
+
const { price: _dropped, ...rest } = lot;
|
|
8677
|
+
lots.push(rest);
|
|
8678
|
+
} else lots.push({ ...lot });
|
|
8679
|
+
}
|
|
8680
|
+
if (currency && !into.purchaseCurrency && lots.some((l) => l.price !== void 0)) into.purchaseCurrency = currency;
|
|
8681
|
+
}
|
|
8682
|
+
function parsePurchasePrice(raw) {
|
|
8683
|
+
if (!raw) return void 0;
|
|
8684
|
+
let t = raw.replace(/[^\d.,-]/g, "");
|
|
8685
|
+
if (!t) return void 0;
|
|
8686
|
+
if (t.includes(",") && !t.includes(".") && /,\d{1,2}$/.test(t)) t = t.replace(",", ".");
|
|
8687
|
+
else t = t.replace(/,/g, "");
|
|
8688
|
+
const n = Number(t);
|
|
8689
|
+
return Number.isFinite(n) && n > 0 && n < 1e6 ? Math.round(n * 100) / 100 : void 0;
|
|
8690
|
+
}
|
|
8691
|
+
function parseAddedDate(raw) {
|
|
8692
|
+
const t = raw?.trim();
|
|
8693
|
+
if (!t) return void 0;
|
|
8694
|
+
const iso = /^(\d{4})-(\d{2})-(\d{2})/.exec(t);
|
|
8695
|
+
let ms;
|
|
8696
|
+
if (iso && t.length === 10) ms = Date.UTC(+iso[1], +iso[2] - 1, +iso[3]);
|
|
8697
|
+
else if (iso) ms = Date.parse(t);
|
|
8698
|
+
else {
|
|
8699
|
+
const us = /^(\d{1,2})\/(\d{1,2})\/(\d{4})/.exec(t);
|
|
8700
|
+
if (!us) return void 0;
|
|
8701
|
+
ms = Date.UTC(+us[3], +us[1] - 1, +us[2]);
|
|
8702
|
+
}
|
|
8703
|
+
if (!Number.isFinite(ms)) return void 0;
|
|
8704
|
+
const day2 = new Date(ms).toISOString().slice(0, 10);
|
|
8705
|
+
const year = +day2.slice(0, 4);
|
|
8706
|
+
return year >= 1993 && year <= 2100 ? day2 : void 0;
|
|
8707
|
+
}
|
|
8615
8708
|
var init_normalize = __esm({
|
|
8616
8709
|
"../src/lib/parser/normalize.ts"() {
|
|
8617
8710
|
"use strict";
|
|
@@ -9954,95 +10047,144 @@ function parsePrice(raw) {
|
|
|
9954
10047
|
const n = Number.parseFloat(raw);
|
|
9955
10048
|
return Number.isFinite(n) ? n : null;
|
|
9956
10049
|
}
|
|
10050
|
+
function printingsFetchPaused(now = Date.now()) {
|
|
10051
|
+
return now < trippedUntil;
|
|
10052
|
+
}
|
|
10053
|
+
function takeSlot() {
|
|
10054
|
+
const turn = gate.then(async () => {
|
|
10055
|
+
if (printingsFetchPaused()) return false;
|
|
10056
|
+
const wait = Math.max(nextSlotAt, pausedUntil) - Date.now();
|
|
10057
|
+
if (wait > 0) await sleep(wait);
|
|
10058
|
+
if (printingsFetchPaused()) return false;
|
|
10059
|
+
nextSlotAt = Date.now() + MIN_GAP_MS;
|
|
10060
|
+
return true;
|
|
10061
|
+
});
|
|
10062
|
+
gate = turn.catch(() => void 0);
|
|
10063
|
+
return turn;
|
|
10064
|
+
}
|
|
10065
|
+
function noteFailure() {
|
|
10066
|
+
consecutiveFailures++;
|
|
10067
|
+
if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
|
|
10068
|
+
trips++;
|
|
10069
|
+
trippedUntil = Date.now() + TRIP_MS * 2 ** Math.min(trips - 1, 4);
|
|
10070
|
+
consecutiveFailures = 0;
|
|
10071
|
+
if (false) {
|
|
10072
|
+
console.warn("printings: Scryfall keeps failing; pausing /cards/collection");
|
|
10073
|
+
}
|
|
10074
|
+
return;
|
|
10075
|
+
}
|
|
10076
|
+
pausedUntil = Date.now() + FAILURE_PAUSE_MS;
|
|
10077
|
+
}
|
|
10078
|
+
async function requestBatch(batch) {
|
|
10079
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
10080
|
+
if (!await takeSlot()) return null;
|
|
10081
|
+
try {
|
|
10082
|
+
const res = await fetchWithTimeout(COLLECTION_URL, {
|
|
10083
|
+
...FETCH_TIMEOUTS.scryfall,
|
|
10084
|
+
method: "POST",
|
|
10085
|
+
headers: {
|
|
10086
|
+
"Content-Type": "application/json",
|
|
10087
|
+
Accept: "application/json"
|
|
10088
|
+
},
|
|
10089
|
+
body: JSON.stringify({ identifiers: batch })
|
|
10090
|
+
});
|
|
10091
|
+
if (res.ok) {
|
|
10092
|
+
consecutiveFailures = 0;
|
|
10093
|
+
return await res.json();
|
|
10094
|
+
}
|
|
10095
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 429) return null;
|
|
10096
|
+
noteFailure();
|
|
10097
|
+
} catch (e) {
|
|
10098
|
+
if (false) console.warn("printings: batch fetch failed:", e);
|
|
10099
|
+
noteFailure();
|
|
10100
|
+
}
|
|
10101
|
+
}
|
|
10102
|
+
return null;
|
|
10103
|
+
}
|
|
9957
10104
|
async function fetchPrintings(identifiers, onProgress) {
|
|
9958
10105
|
const result = /* @__PURE__ */ new Map();
|
|
10106
|
+
const shared = [];
|
|
9959
10107
|
const toFetch = [];
|
|
10108
|
+
const settle2 = /* @__PURE__ */ new Map();
|
|
9960
10109
|
for (const id of identifiers) {
|
|
9961
10110
|
const key2 = printingKey(id.set, id.collector_number);
|
|
9962
10111
|
const cached2 = cache.get(key2);
|
|
9963
10112
|
if (cached2) {
|
|
9964
10113
|
result.set(key2, cached2);
|
|
9965
|
-
|
|
9966
|
-
|
|
10114
|
+
continue;
|
|
10115
|
+
}
|
|
10116
|
+
if (notFound.has(key2) || settle2.has(key2)) continue;
|
|
10117
|
+
const running = inflight.get(key2);
|
|
10118
|
+
if (running) {
|
|
10119
|
+
shared.push(running.then((rec) => void (rec && result.set(key2, rec))));
|
|
10120
|
+
continue;
|
|
9967
10121
|
}
|
|
10122
|
+
const mine = new Promise((resolve) => {
|
|
10123
|
+
settle2.set(key2, (rec) => {
|
|
10124
|
+
settle2.delete(key2);
|
|
10125
|
+
inflight.delete(key2);
|
|
10126
|
+
resolve(rec);
|
|
10127
|
+
});
|
|
10128
|
+
});
|
|
10129
|
+
inflight.set(key2, mine);
|
|
10130
|
+
toFetch.push(id);
|
|
9968
10131
|
}
|
|
9969
10132
|
const total = toFetch.length;
|
|
9970
10133
|
if (total === 0) {
|
|
10134
|
+
await Promise.all(shared);
|
|
9971
10135
|
onProgress?.(0, 0);
|
|
9972
10136
|
return result;
|
|
9973
10137
|
}
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
9979
|
-
|
|
9980
|
-
|
|
9981
|
-
|
|
9982
|
-
|
|
9983
|
-
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
|
|
9991
|
-
|
|
9992
|
-
|
|
9993
|
-
|
|
9994
|
-
|
|
9995
|
-
|
|
9996
|
-
|
|
9997
|
-
|
|
10138
|
+
try {
|
|
10139
|
+
for (let i = 0; i < toFetch.length; i += BATCH) {
|
|
10140
|
+
if (printingsFetchPaused()) break;
|
|
10141
|
+
const batch = toFetch.slice(i, i + BATCH);
|
|
10142
|
+
const json3 = await requestBatch(batch);
|
|
10143
|
+
if (json3) {
|
|
10144
|
+
try {
|
|
10145
|
+
const missing = new Set(
|
|
10146
|
+
(json3.not_found ?? []).map((n) => printingKey(n.set, n.collector_number))
|
|
10147
|
+
);
|
|
10148
|
+
let dataIdx = 0;
|
|
10149
|
+
for (const reqId of batch) {
|
|
10150
|
+
const key2 = printingKey(reqId.set, reqId.collector_number);
|
|
10151
|
+
if (missing.has(key2)) {
|
|
10152
|
+
notFound.add(key2);
|
|
10153
|
+
settle2.get(key2)?.(null);
|
|
10154
|
+
continue;
|
|
10155
|
+
}
|
|
10156
|
+
const card = json3.data[dataIdx++];
|
|
10157
|
+
if (!card?.oracle_id) continue;
|
|
10158
|
+
const image = pickImage(card);
|
|
10159
|
+
if (!image) continue;
|
|
10160
|
+
const backImage = card.card_faces?.[1]?.image_uris?.normal;
|
|
10161
|
+
const record2 = {
|
|
10162
|
+
oracleId: card.oracle_id,
|
|
10163
|
+
image,
|
|
10164
|
+
...backImage ? { backImage } : {},
|
|
10165
|
+
priceUsd: parsePrice(card.prices?.usd),
|
|
10166
|
+
priceUsdFoil: parsePrice(card.prices?.usd_foil)
|
|
10167
|
+
};
|
|
10168
|
+
result.set(key2, record2);
|
|
10169
|
+
cache.set(key2, record2);
|
|
10170
|
+
settle2.get(key2)?.(record2);
|
|
10171
|
+
}
|
|
10172
|
+
} catch (e) {
|
|
10173
|
+
if (false) console.warn("printings: batch parse failed:", e);
|
|
9998
10174
|
}
|
|
9999
10175
|
}
|
|
10000
|
-
const delay = 300 * Math.pow(3, attempt);
|
|
10001
|
-
await new Promise((r) => setTimeout(r, delay));
|
|
10002
|
-
}
|
|
10003
|
-
if (!json3) {
|
|
10004
|
-
onProgress?.(Math.min(i + BATCH, total), total);
|
|
10005
|
-
if (i + BATCH < toFetch.length) {
|
|
10006
|
-
await new Promise((r) => setTimeout(r, REQUEST_GAP_MS));
|
|
10007
|
-
}
|
|
10008
|
-
continue;
|
|
10009
|
-
}
|
|
10010
|
-
try {
|
|
10011
|
-
const notFound = new Set(
|
|
10012
|
-
json3.not_found.map((n) => printingKey(n.set, n.collector_number))
|
|
10013
|
-
);
|
|
10014
|
-
let dataIdx = 0;
|
|
10015
10176
|
for (const reqId of batch) {
|
|
10016
|
-
|
|
10017
|
-
if (notFound.has(key2)) continue;
|
|
10018
|
-
const card = json3.data[dataIdx++];
|
|
10019
|
-
if (!card?.oracle_id) continue;
|
|
10020
|
-
const image = pickImage(card);
|
|
10021
|
-
if (!image) continue;
|
|
10022
|
-
const backImage = card.card_faces?.[1]?.image_uris?.normal;
|
|
10023
|
-
const record2 = {
|
|
10024
|
-
oracleId: card.oracle_id,
|
|
10025
|
-
image,
|
|
10026
|
-
...backImage ? { backImage } : {},
|
|
10027
|
-
priceUsd: parsePrice(card.prices?.usd),
|
|
10028
|
-
priceUsdFoil: parsePrice(card.prices?.usd_foil)
|
|
10029
|
-
};
|
|
10030
|
-
result.set(key2, record2);
|
|
10031
|
-
cache.set(key2, record2);
|
|
10032
|
-
}
|
|
10033
|
-
} catch (e) {
|
|
10034
|
-
if (false) {
|
|
10035
|
-
console.warn(`printings: batch ${i / BATCH} parse failed:`, e);
|
|
10177
|
+
settle2.get(printingKey(reqId.set, reqId.collector_number))?.(null);
|
|
10036
10178
|
}
|
|
10179
|
+
onProgress?.(Math.min(i + BATCH, total), total);
|
|
10037
10180
|
}
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
await new Promise((r) => setTimeout(r, REQUEST_GAP_MS));
|
|
10041
|
-
}
|
|
10181
|
+
} finally {
|
|
10182
|
+
for (const done of [...settle2.values()]) done(null);
|
|
10042
10183
|
}
|
|
10184
|
+
await Promise.all(shared);
|
|
10043
10185
|
return result;
|
|
10044
10186
|
}
|
|
10045
|
-
var COLLECTION_URL, BATCH,
|
|
10187
|
+
var COLLECTION_URL, BATCH, MIN_GAP_MS, FAILURE_PAUSE_MS, MAX_CONSECUTIVE_FAILURES, TRIP_MS, cache, gate, nextSlotAt, pausedUntil, trippedUntil, consecutiveFailures, trips, notFound, inflight, sleep;
|
|
10046
10188
|
var init_printings = __esm({
|
|
10047
10189
|
"../src/lib/scryfall/printings.ts"() {
|
|
10048
10190
|
"use strict";
|
|
@@ -10050,8 +10192,20 @@ var init_printings = __esm({
|
|
|
10050
10192
|
init_fetchWithTimeout();
|
|
10051
10193
|
COLLECTION_URL = "https://api.scryfall.com/cards/collection";
|
|
10052
10194
|
BATCH = 75;
|
|
10053
|
-
|
|
10195
|
+
MIN_GAP_MS = 550;
|
|
10196
|
+
FAILURE_PAUSE_MS = 3e4;
|
|
10197
|
+
MAX_CONSECUTIVE_FAILURES = 3;
|
|
10198
|
+
TRIP_MS = 10 * 6e4;
|
|
10054
10199
|
cache = /* @__PURE__ */ new Map();
|
|
10200
|
+
gate = Promise.resolve();
|
|
10201
|
+
nextSlotAt = 0;
|
|
10202
|
+
pausedUntil = 0;
|
|
10203
|
+
trippedUntil = 0;
|
|
10204
|
+
consecutiveFailures = 0;
|
|
10205
|
+
trips = 0;
|
|
10206
|
+
notFound = /* @__PURE__ */ new Set();
|
|
10207
|
+
inflight = /* @__PURE__ */ new Map();
|
|
10208
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
10055
10209
|
}
|
|
10056
10210
|
});
|
|
10057
10211
|
|
|
@@ -11001,7 +11155,7 @@ var init_countRows = __esm({
|
|
|
11001
11155
|
what: "treasures",
|
|
11002
11156
|
label: "Treasure",
|
|
11003
11157
|
of: (n) => `${n} Treasure`,
|
|
11004
|
-
when: "Treasure you still hold as the turn ends. While this
|
|
11158
|
+
when: "Treasure you still hold as the turn ends. While this step is short, Treasure is only spent on what another step needs.",
|
|
11005
11159
|
start: 3,
|
|
11006
11160
|
max: 30
|
|
11007
11161
|
},
|
|
@@ -13696,8 +13850,8 @@ var init_syncCollection = __esm({
|
|
|
13696
13850
|
});
|
|
13697
13851
|
|
|
13698
13852
|
// src/cli.ts
|
|
13699
|
-
import { rmSync as
|
|
13700
|
-
import { join as
|
|
13853
|
+
import { rmSync as rmSync5 } from "node:fs";
|
|
13854
|
+
import { join as join10 } from "node:path";
|
|
13701
13855
|
import { createInterface } from "node:readline/promises";
|
|
13702
13856
|
|
|
13703
13857
|
// src/catalog.ts
|
|
@@ -14944,6 +15098,38 @@ function tokenize(input2) {
|
|
|
14944
15098
|
let chars = [];
|
|
14945
15099
|
let inQuote = false;
|
|
14946
15100
|
const flush = () => {
|
|
15101
|
+
if (chars.length === 0) return;
|
|
15102
|
+
const isComma = (c) => c.ch === "," && !c.q;
|
|
15103
|
+
const segs = [[]];
|
|
15104
|
+
for (const c of chars) {
|
|
15105
|
+
if (isComma(c)) segs.push([]);
|
|
15106
|
+
else segs[segs.length - 1].push(c);
|
|
15107
|
+
}
|
|
15108
|
+
if (segs.length > 1) {
|
|
15109
|
+
const parts = segs.filter((g) => g.length > 0);
|
|
15110
|
+
const all = chars;
|
|
15111
|
+
if (parts.length === 0) {
|
|
15112
|
+
chars = [];
|
|
15113
|
+
return;
|
|
15114
|
+
}
|
|
15115
|
+
if (parts.every(isClauseChars)) {
|
|
15116
|
+
for (const g of parts) {
|
|
15117
|
+
chars = g;
|
|
15118
|
+
pushTok();
|
|
15119
|
+
}
|
|
15120
|
+
chars = [];
|
|
15121
|
+
return;
|
|
15122
|
+
}
|
|
15123
|
+
let a = 0;
|
|
15124
|
+
let b = all.length;
|
|
15125
|
+
while (a < b && isComma(all[a])) a++;
|
|
15126
|
+
while (b > a && isComma(all[b - 1])) b--;
|
|
15127
|
+
const trimmed = all.slice(a, b);
|
|
15128
|
+
if (trimmed.length < all.length && isClauseChars(trimmed)) chars = trimmed;
|
|
15129
|
+
}
|
|
15130
|
+
pushTok();
|
|
15131
|
+
};
|
|
15132
|
+
const pushTok = () => {
|
|
14947
15133
|
if (chars.length === 0) return;
|
|
14948
15134
|
const neg = chars.length > 1 && chars[0].ch === "-" && !chars[0].q && chars[1].ch === "(" && !chars[1].q;
|
|
14949
15135
|
const start = neg ? 1 : 0;
|
|
@@ -14979,6 +15165,11 @@ function tokenize(input2) {
|
|
|
14979
15165
|
flush();
|
|
14980
15166
|
return out;
|
|
14981
15167
|
}
|
|
15168
|
+
function isClauseChars(chars) {
|
|
15169
|
+
const text = chars.map((c) => c.ch).join("").replace(/^-?\(+/, "").replace(/\)+$/, "");
|
|
15170
|
+
if (!text) return false;
|
|
15171
|
+
return parseToken(text).kind !== "text";
|
|
15172
|
+
}
|
|
14982
15173
|
function parseToken(token) {
|
|
14983
15174
|
const lower = token.toLowerCase();
|
|
14984
15175
|
const rx = /^-?([a-z]+):\//.exec(lower);
|
|
@@ -16173,10 +16364,10 @@ function buildBuySlugIndex(cards) {
|
|
|
16173
16364
|
if (hit) return hit;
|
|
16174
16365
|
const bySlug = /* @__PURE__ */ new Map();
|
|
16175
16366
|
for (const card of cards.byOracleId.values()) {
|
|
16176
|
-
const
|
|
16177
|
-
if (!bySlug.has(
|
|
16367
|
+
const front2 = toEdhrecSlug(card.name);
|
|
16368
|
+
if (!bySlug.has(front2)) bySlug.set(front2, card);
|
|
16178
16369
|
const joined = toEdhrecSlug(card.name, { joined: true });
|
|
16179
|
-
if (joined !==
|
|
16370
|
+
if (joined !== front2 && !bySlug.has(joined)) bySlug.set(joined, card);
|
|
16180
16371
|
}
|
|
16181
16372
|
slugIndexByCatalog.set(cards, bySlug);
|
|
16182
16373
|
return bySlug;
|
|
@@ -16251,11 +16442,11 @@ function applyPriceOverlay(index, prices = overlay) {
|
|
|
16251
16442
|
for (const [oid, t] of prices) {
|
|
16252
16443
|
const card = index.byOracleId.get(oid);
|
|
16253
16444
|
if (!card) continue;
|
|
16254
|
-
const
|
|
16445
|
+
const usd2 = t[0];
|
|
16255
16446
|
const eur = t[1];
|
|
16256
16447
|
let hit = false;
|
|
16257
|
-
if (
|
|
16258
|
-
card.priceUsd =
|
|
16448
|
+
if (usd2 != null && card.priceUsd !== usd2) {
|
|
16449
|
+
card.priceUsd = usd2;
|
|
16259
16450
|
hit = true;
|
|
16260
16451
|
}
|
|
16261
16452
|
if (eur != null && card.priceEur !== eur) {
|
|
@@ -16350,6 +16541,7 @@ function expand(r) {
|
|
|
16350
16541
|
...r.van === 1 ? { vanilla: true } : {},
|
|
16351
16542
|
...r.an && r.an.length > 0 ? { altNames: r.an } : {},
|
|
16352
16543
|
...r.ai && r.ai.length > 0 ? { altImages: r.ai.map((s) => expandImageUrl(s)) } : {},
|
|
16544
|
+
...r.al && r.an && r.al.length === r.an.length ? { altLangs: r.al } : {},
|
|
16353
16545
|
...r.et && ENTER_TAPPED_CHAR_TO_NAME[r.et] ? { enterTapped: ENTER_TAPPED_CHAR_TO_NAME[r.et] } : {},
|
|
16354
16546
|
...r.tc && TAP_CONDITION_CHAR_TO_NAME[r.tc] ? { tapCondition: TAP_CONDITION_CHAR_TO_NAME[r.tc] } : {},
|
|
16355
16547
|
...r.mc ? { manaCost: r.mc } : {},
|
|
@@ -16384,27 +16576,45 @@ function newIndexMaps() {
|
|
|
16384
16576
|
}
|
|
16385
16577
|
function indexPass1Card(card, m) {
|
|
16386
16578
|
card.searchNameNorm = normalizeForSearch(card.searchName);
|
|
16387
|
-
m.byName.set(card.searchName, card);
|
|
16579
|
+
if (lastWins(m.byName.get(card.searchName), card)) m.byName.set(card.searchName, card);
|
|
16388
16580
|
m.byOracleId.set(card.oracleId, card);
|
|
16389
16581
|
const norm = normalizeName(card.searchName);
|
|
16390
|
-
if (
|
|
16582
|
+
if (firstWins(m.byNormalizedName.get(norm), card)) m.byNormalizedName.set(norm, card);
|
|
16391
16583
|
if (card.faceName) {
|
|
16392
|
-
m.byFaceName.
|
|
16584
|
+
if (lastWins(m.byFaceName.get(card.faceName), card)) {
|
|
16585
|
+
m.byFaceName.set(card.faceName, card);
|
|
16586
|
+
}
|
|
16393
16587
|
const faceNorm = normalizeName(card.faceName);
|
|
16394
|
-
if (
|
|
16588
|
+
if (firstWins(m.byNormalizedFaceName.get(faceNorm), card)) {
|
|
16395
16589
|
m.byNormalizedFaceName.set(faceNorm, card);
|
|
16396
16590
|
}
|
|
16397
16591
|
}
|
|
16398
16592
|
}
|
|
16593
|
+
function isRealCard(card) {
|
|
16594
|
+
return card.commanderLegal || card.banned === true;
|
|
16595
|
+
}
|
|
16596
|
+
function lastWins(existing, incoming) {
|
|
16597
|
+
if (!existing) return true;
|
|
16598
|
+
return isRealCard(incoming) || !isRealCard(existing);
|
|
16599
|
+
}
|
|
16600
|
+
function firstWins(existing, incoming) {
|
|
16601
|
+
if (!existing) return true;
|
|
16602
|
+
return isRealCard(incoming) && !isRealCard(existing);
|
|
16603
|
+
}
|
|
16399
16604
|
function indexPass2aCard(card) {
|
|
16400
16605
|
if (!card.altNames || card.altNames.length === 0) return;
|
|
16401
16606
|
const keep = card.altNames.map(hasRenderableChar);
|
|
16402
16607
|
if (!keep.every(Boolean)) {
|
|
16403
16608
|
card.altNames = card.altNames.filter((_, i) => keep[i]);
|
|
16404
16609
|
if (card.altImages) card.altImages = card.altImages.filter((_, i) => keep[i]);
|
|
16610
|
+
if (card.altLangs) {
|
|
16611
|
+
const tags = card.altLangs;
|
|
16612
|
+
card.altLangs = [...tags].filter((_, i) => keep[i]).join("");
|
|
16613
|
+
}
|
|
16405
16614
|
if (card.altNames.length === 0) {
|
|
16406
16615
|
delete card.altNames;
|
|
16407
16616
|
delete card.altImages;
|
|
16617
|
+
delete card.altLangs;
|
|
16408
16618
|
delete card.searchAltNames;
|
|
16409
16619
|
delete card.searchAltNamesNorm;
|
|
16410
16620
|
return;
|
|
@@ -16715,11 +16925,13 @@ import { dirname, join as join4 } from "node:path";
|
|
|
16715
16925
|
var DATA_PATH = /^(?:commanders\/)?[a-z0-9_.-]+\.json$/i;
|
|
16716
16926
|
async function ensureFile(opts, name) {
|
|
16717
16927
|
if (!DATA_PATH.test(name) || name.includes("..")) throw new Error(`Not a data file name: ${name}`);
|
|
16928
|
+
return ensureRemote(opts, `/data/${name}`, join4("files", name));
|
|
16929
|
+
}
|
|
16930
|
+
async function ensureRemote(opts, urlPath, cacheRel) {
|
|
16931
|
+
if (cacheRel.includes("..") || !urlPath.startsWith("/")) throw new Error(`Not a site path: ${urlPath}`);
|
|
16718
16932
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
16719
16933
|
const origin = opts.origin ?? "https://edhvault.com";
|
|
16720
|
-
const
|
|
16721
|
-
mkdirSync2(dir, { recursive: true });
|
|
16722
|
-
const path = join4(dir, name);
|
|
16934
|
+
const path = join4(opts.dir, cacheRel);
|
|
16723
16935
|
mkdirSync2(dirname(path), { recursive: true });
|
|
16724
16936
|
const metaPath = `${path}.meta.json`;
|
|
16725
16937
|
const cached2 = existsSync2(path) && existsSync2(metaPath) ? JSON.parse(readFileSync4(metaPath, "utf8")) : null;
|
|
@@ -16728,7 +16940,7 @@ async function ensureFile(opts, name) {
|
|
|
16728
16940
|
if (cached2?.lastModified) headers["If-Modified-Since"] = cached2.lastModified;
|
|
16729
16941
|
let res;
|
|
16730
16942
|
try {
|
|
16731
|
-
res = await fetchImpl(`${origin}
|
|
16943
|
+
res = await fetchImpl(`${origin}${urlPath}`, { headers, signal: AbortSignal.timeout(opts.timeoutMs ?? 12e4) });
|
|
16732
16944
|
} catch (e) {
|
|
16733
16945
|
if (cached2) return { path, stale: true };
|
|
16734
16946
|
throw e;
|
|
@@ -16736,7 +16948,7 @@ async function ensureFile(opts, name) {
|
|
|
16736
16948
|
if (res.status === 304 && cached2) return { path, stale: false };
|
|
16737
16949
|
if (!res.ok) {
|
|
16738
16950
|
if (cached2) return { path, stale: true };
|
|
16739
|
-
throw new Error(`${
|
|
16951
|
+
throw new Error(`${urlPath.replace(/^\/data\//, "")}: ${res.status}`);
|
|
16740
16952
|
}
|
|
16741
16953
|
let body;
|
|
16742
16954
|
try {
|
|
@@ -16847,9 +17059,161 @@ function extrasLoader(opts) {
|
|
|
16847
17059
|
};
|
|
16848
17060
|
}
|
|
16849
17061
|
|
|
17062
|
+
// src/priceHistory.ts
|
|
17063
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync6, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
17064
|
+
import { dirname as dirname2, join as join6 } from "node:path";
|
|
17065
|
+
|
|
17066
|
+
// ../src/lib/priceHistory/format.ts
|
|
17067
|
+
var HISTORY_VERSION = 1;
|
|
17068
|
+
var FINISHES = ["n", "f", "e"];
|
|
17069
|
+
var HISTORY_SOURCE = "TCGplayer market prices via MTGJSON";
|
|
17070
|
+
var DAY_MS = 864e5;
|
|
17071
|
+
function epochDay(date5) {
|
|
17072
|
+
const t = Date.parse(`${date5.slice(0, 10)}T00:00:00Z`);
|
|
17073
|
+
return Number.isFinite(t) ? Math.round(t / DAY_MS) : NaN;
|
|
17074
|
+
}
|
|
17075
|
+
function dayToDate(day2) {
|
|
17076
|
+
return new Date(day2 * DAY_MS).toISOString().slice(0, 10);
|
|
17077
|
+
}
|
|
17078
|
+
function monthOf(day2) {
|
|
17079
|
+
return dayToDate(day2).slice(0, 7);
|
|
17080
|
+
}
|
|
17081
|
+
function decodeSeries(record2, length) {
|
|
17082
|
+
const out = new Array(length).fill(null);
|
|
17083
|
+
for (let i = 0; i < record2.length; i += 2) {
|
|
17084
|
+
const from = record2[i];
|
|
17085
|
+
const to = i + 2 < record2.length ? record2[i + 2] : length;
|
|
17086
|
+
const v = record2[i + 1] ?? null;
|
|
17087
|
+
for (let d = Math.max(0, from); d < Math.min(to, length); d++) out[d] = v;
|
|
17088
|
+
}
|
|
17089
|
+
return out;
|
|
17090
|
+
}
|
|
17091
|
+
var HISTORY_BASE = "/api/price-history";
|
|
17092
|
+
var manifestPath = () => "manifest.json";
|
|
17093
|
+
var monthIndexPath = (month, hash2) => `m/${month}.${hash2}.json`;
|
|
17094
|
+
var setMonthPath = (month, set3, hash2) => `s/${month}/${set3}.${hash2}.json`;
|
|
17095
|
+
var HISTORY_KEY_RE = /^(?:manifest\.json|m\/\d{4}-\d{2}\.[0-9a-f]{12}\.json|s\/\d{4}-\d{2}\/[a-z0-9]{2,8}\.[0-9a-f]{12}\.json|vendors\/[a-z0-9]{2,8}\.json)$/;
|
|
17096
|
+
|
|
17097
|
+
// ../src/lib/priceHistory/load.ts
|
|
17098
|
+
init_build();
|
|
17099
|
+
init_fetchWithTimeout();
|
|
17100
|
+
var BUNDLE_MAX = 100;
|
|
17101
|
+
|
|
17102
|
+
// ../src/lib/priceHistory/vendors.ts
|
|
17103
|
+
var VENDOR_PRICES_VERSION = 1;
|
|
17104
|
+
var VENDOR_PRICES_SOURCE = "MTGJSON";
|
|
17105
|
+
var VENDOR_SET_RE = /^[a-z0-9]{2,8}$/;
|
|
17106
|
+
var vendorSetPath = (set3) => `vendors/${set3}.json`;
|
|
17107
|
+
|
|
17108
|
+
// src/priceHistory.ts
|
|
17109
|
+
var MANIFEST_FRESH_MS = 5 * 6e4;
|
|
17110
|
+
var VENDOR_FRESH_MS = 60 * 6e4;
|
|
17111
|
+
function priceHistoryLoader(opts, now = Date.now) {
|
|
17112
|
+
const root = "price-history";
|
|
17113
|
+
const dir = join6(opts.dir, root);
|
|
17114
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
17115
|
+
const origin = opts.origin ?? "https://edhvault.com";
|
|
17116
|
+
const staleSet = /* @__PURE__ */ new Set();
|
|
17117
|
+
const fresh = /* @__PURE__ */ new Map();
|
|
17118
|
+
const mutable = (key2, freshMs, read) => {
|
|
17119
|
+
const hit = fresh.get(key2);
|
|
17120
|
+
if (hit && now() - hit.at < freshMs) return hit.value;
|
|
17121
|
+
const value = (async () => {
|
|
17122
|
+
const got = await ensureRemote(opts, `${HISTORY_BASE}/${key2}`, join6(root, key2));
|
|
17123
|
+
if (got.stale) staleSet.add(key2);
|
|
17124
|
+
else staleSet.delete(key2);
|
|
17125
|
+
return read(JSON.parse(readFileSync6(got.path, "utf8")));
|
|
17126
|
+
})();
|
|
17127
|
+
fresh.set(key2, { at: now(), value });
|
|
17128
|
+
value.catch(() => fresh.delete(key2));
|
|
17129
|
+
return value;
|
|
17130
|
+
};
|
|
17131
|
+
const readKept = (key2) => {
|
|
17132
|
+
const path = join6(dir, key2);
|
|
17133
|
+
return existsSync4(path) ? JSON.parse(readFileSync6(path, "utf8")) : void 0;
|
|
17134
|
+
};
|
|
17135
|
+
const keep = (key2, value) => {
|
|
17136
|
+
const path = join6(dir, key2);
|
|
17137
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
17138
|
+
writeFileSync3(`${path}.incoming`, JSON.stringify(value));
|
|
17139
|
+
renameSync3(`${path}.incoming`, path);
|
|
17140
|
+
};
|
|
17141
|
+
const getJson = async (path) => {
|
|
17142
|
+
const res = await fetchImpl(`${origin}${HISTORY_BASE}/${path}`, { signal: AbortSignal.timeout(opts.timeoutMs ?? 12e4) });
|
|
17143
|
+
if (!res.ok) throw new Error(`price history ${path}: ${res.status}`);
|
|
17144
|
+
return await res.json();
|
|
17145
|
+
};
|
|
17146
|
+
const immutable = async (key2) => {
|
|
17147
|
+
if (!HISTORY_KEY_RE.test(key2)) throw new Error(`Not a price history file: ${key2}`);
|
|
17148
|
+
const hit = readKept(key2);
|
|
17149
|
+
if (hit !== void 0) return hit;
|
|
17150
|
+
const value = await getJson(key2);
|
|
17151
|
+
keep(key2, value);
|
|
17152
|
+
return value;
|
|
17153
|
+
};
|
|
17154
|
+
const manifest = () => mutable(manifestPath(), MANIFEST_FRESH_MS, (raw) => {
|
|
17155
|
+
const m = raw;
|
|
17156
|
+
if (m?.v !== HISTORY_VERSION || typeof m.months !== "object") throw new Error("The price history is from a newer version of EDHVault.");
|
|
17157
|
+
return m;
|
|
17158
|
+
});
|
|
17159
|
+
const prune = (live, months) => {
|
|
17160
|
+
for (const month of months) {
|
|
17161
|
+
const d = join6(dir, "s", month);
|
|
17162
|
+
if (!existsSync4(d)) continue;
|
|
17163
|
+
for (const f of readdirSync(d)) if (!f.endsWith(".incoming") && !live.has(`s/${month}/${f}`)) rmSync2(join6(d, f), { force: true });
|
|
17164
|
+
}
|
|
17165
|
+
};
|
|
17166
|
+
return {
|
|
17167
|
+
manifest,
|
|
17168
|
+
async setFiles(sets, fromMonth) {
|
|
17169
|
+
const m = await manifest();
|
|
17170
|
+
const months = Object.keys(m.months).filter((mo) => !fromMonth || mo >= fromMonth).sort();
|
|
17171
|
+
const wanted = new Set(sets.map((s) => s.toLowerCase()));
|
|
17172
|
+
const paths = [];
|
|
17173
|
+
for (const month of months) {
|
|
17174
|
+
const index = await immutable(monthIndexPath(month, m.months[month]));
|
|
17175
|
+
for (const [set3, hash2] of Object.entries(index.sets)) if (wanted.has(set3)) paths.push(setMonthPath(month, set3, hash2));
|
|
17176
|
+
}
|
|
17177
|
+
const files = [];
|
|
17178
|
+
const missing = [];
|
|
17179
|
+
for (const p of paths) {
|
|
17180
|
+
const hit = readKept(p);
|
|
17181
|
+
if (hit) files.push(hit);
|
|
17182
|
+
else missing.push(p);
|
|
17183
|
+
}
|
|
17184
|
+
for (let i = 0; i < missing.length; i += BUNDLE_MAX) {
|
|
17185
|
+
const keys = missing.slice(i, i + BUNDLE_MAX);
|
|
17186
|
+
const got = await getJson(`bundle?f=${keys.join(",")}`);
|
|
17187
|
+
for (const k of keys) {
|
|
17188
|
+
const f = got[k];
|
|
17189
|
+
if (!f) throw new Error(`price history bundle: ${k} missing`);
|
|
17190
|
+
keep(k, f);
|
|
17191
|
+
files.push(f);
|
|
17192
|
+
}
|
|
17193
|
+
}
|
|
17194
|
+
prune(new Set(paths), months.slice(-1));
|
|
17195
|
+
return files;
|
|
17196
|
+
},
|
|
17197
|
+
async vendorSet(set3) {
|
|
17198
|
+
const key2 = set3.toLowerCase();
|
|
17199
|
+
if (!VENDOR_SET_RE.test(key2)) return null;
|
|
17200
|
+
try {
|
|
17201
|
+
return await mutable(vendorSetPath(key2), VENDOR_FRESH_MS, (raw) => {
|
|
17202
|
+
const f = raw;
|
|
17203
|
+
return f?.v === VENDOR_PRICES_VERSION && f.p ? f : null;
|
|
17204
|
+
});
|
|
17205
|
+
} catch (e) {
|
|
17206
|
+
if (e instanceof Error && /: 404$/.test(e.message)) return null;
|
|
17207
|
+
throw e;
|
|
17208
|
+
}
|
|
17209
|
+
},
|
|
17210
|
+
stale: () => [...staleSet]
|
|
17211
|
+
};
|
|
17212
|
+
}
|
|
17213
|
+
|
|
16850
17214
|
// src/library.ts
|
|
16851
|
-
import { existsSync as
|
|
16852
|
-
import { join as
|
|
17215
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
17216
|
+
import { join as join7 } from "node:path";
|
|
16853
17217
|
|
|
16854
17218
|
// ../src/lib/sync/agentAccess.ts
|
|
16855
17219
|
init_sealedBox();
|
|
@@ -16915,6 +17279,22 @@ init_sealedBox();
|
|
|
16915
17279
|
init_syncKeys();
|
|
16916
17280
|
init_syncApi();
|
|
16917
17281
|
init_aiMarks();
|
|
17282
|
+
init_syncHistory();
|
|
17283
|
+
init_storage();
|
|
17284
|
+
function decodeViewHistory(raw) {
|
|
17285
|
+
if (!Array.isArray(raw)) return [];
|
|
17286
|
+
let revived;
|
|
17287
|
+
try {
|
|
17288
|
+
revived = JSON.parse(JSON.stringify(raw), reviver);
|
|
17289
|
+
} catch {
|
|
17290
|
+
return [];
|
|
17291
|
+
}
|
|
17292
|
+
return revived.filter((c) => {
|
|
17293
|
+
const o = c;
|
|
17294
|
+
const plan = o?.snapshot?.plan;
|
|
17295
|
+
return !!o && typeof o.id === "string" && typeof o.label === "string" && typeof o.at === "number" && (o.kind === "manual" || o.kind === "auto" || o.kind === "session") && !!plan && plan.assignments instanceof Map && plan.purchases instanceof Map && plan.basicQuantities instanceof Map;
|
|
17296
|
+
});
|
|
17297
|
+
}
|
|
16918
17298
|
var viewAad = (scope, name) => `v2:${scope}:${name}`;
|
|
16919
17299
|
var indexAad = (scope) => `v2:${scope}:index`;
|
|
16920
17300
|
function openViewObject(sealed, viewKey, scope, name) {
|
|
@@ -16927,11 +17307,13 @@ async function openViewIndex(sealed, viewKey, scope) {
|
|
|
16927
17307
|
}
|
|
16928
17308
|
return index;
|
|
16929
17309
|
}
|
|
17310
|
+
var VIEW_OBJECT_MAX_BYTES = 2 * 1024 * 1024;
|
|
16930
17311
|
var BATCH_PUTS = Math.min(250, SYNC_MAX_PUTS);
|
|
16931
17312
|
var BATCH_BYTES = 16 * 1024 * 1024;
|
|
16932
17313
|
|
|
16933
17314
|
// src/library.ts
|
|
16934
17315
|
init_storage();
|
|
17316
|
+
init_syncHistory();
|
|
16935
17317
|
init_syncApi();
|
|
16936
17318
|
var FRESH_MS = 2 * 6e4;
|
|
16937
17319
|
var GET_BATCH = 50;
|
|
@@ -16966,14 +17348,15 @@ function entries(index) {
|
|
|
16966
17348
|
return [
|
|
16967
17349
|
...Object.values(index.decks),
|
|
16968
17350
|
...index.lib ? [index.lib] : [],
|
|
16969
|
-
...Object.values(index.coll?.chunks ?? {})
|
|
17351
|
+
...Object.values(index.coll?.chunks ?? {}),
|
|
17352
|
+
...Object.values(index.hist ?? {}).filter((e) => e.obj)
|
|
16970
17353
|
];
|
|
16971
17354
|
}
|
|
16972
17355
|
var Library = class {
|
|
16973
17356
|
constructor(opts) {
|
|
16974
17357
|
this.opts = opts;
|
|
16975
|
-
this.cache =
|
|
16976
|
-
|
|
17358
|
+
this.cache = join7(opts.dir, "view2");
|
|
17359
|
+
rmSync3(join7(opts.dir, "view"), { recursive: true, force: true });
|
|
16977
17360
|
this.now = opts.now ?? Date.now;
|
|
16978
17361
|
this.freshMs = opts.freshMs ?? FRESH_MS;
|
|
16979
17362
|
}
|
|
@@ -16989,8 +17372,8 @@ var Library = class {
|
|
|
16989
17372
|
now;
|
|
16990
17373
|
freshMs;
|
|
16991
17374
|
forget() {
|
|
16992
|
-
|
|
16993
|
-
|
|
17375
|
+
rmSync3(this.cache, { recursive: true, force: true });
|
|
17376
|
+
rmSync3(join7(this.opts.dir, "requests"), { recursive: true, force: true });
|
|
16994
17377
|
this.parts.clear();
|
|
16995
17378
|
this.token = null;
|
|
16996
17379
|
this.keys = null;
|
|
@@ -17099,24 +17482,24 @@ var Library = class {
|
|
|
17099
17482
|
return part2.index;
|
|
17100
17483
|
}
|
|
17101
17484
|
dirOf(scope) {
|
|
17102
|
-
return
|
|
17485
|
+
return join7(this.cache, scope);
|
|
17103
17486
|
}
|
|
17104
17487
|
prune(scope, index) {
|
|
17105
17488
|
const dir = this.dirOf(scope);
|
|
17106
|
-
if (!
|
|
17489
|
+
if (!existsSync5(dir)) return;
|
|
17107
17490
|
const live = new Set(entries(index).map((e) => e.obj));
|
|
17108
|
-
for (const f of
|
|
17491
|
+
for (const f of readdirSync2(dir)) if (!live.has(f)) rmSync3(join7(dir, f), { force: true });
|
|
17109
17492
|
}
|
|
17110
17493
|
/** Object texts of one part by name, from the disk cache or batched reads. */
|
|
17111
17494
|
async read(scope, list) {
|
|
17112
17495
|
const { token, key: key2 } = await this.key(scope);
|
|
17113
17496
|
const dir = this.dirOf(scope);
|
|
17114
|
-
|
|
17497
|
+
mkdirSync4(dir, { recursive: true });
|
|
17115
17498
|
const sealed = /* @__PURE__ */ new Map();
|
|
17116
17499
|
const missing = [];
|
|
17117
17500
|
for (const e of list) {
|
|
17118
|
-
const file4 =
|
|
17119
|
-
if (
|
|
17501
|
+
const file4 = join7(dir, e.obj);
|
|
17502
|
+
if (existsSync5(file4)) sealed.set(e.obj, new Uint8Array(readFileSync7(file4)));
|
|
17120
17503
|
else missing.push(e.obj);
|
|
17121
17504
|
}
|
|
17122
17505
|
for (let i = 0; i < missing.length; i += GET_BATCH) {
|
|
@@ -17129,7 +17512,7 @@ var Library = class {
|
|
|
17129
17512
|
for (const [name, bytes] of got) {
|
|
17130
17513
|
if (!bytes) continue;
|
|
17131
17514
|
sealed.set(name, bytes);
|
|
17132
|
-
|
|
17515
|
+
writeFileSync4(join7(dir, name), bytes);
|
|
17133
17516
|
}
|
|
17134
17517
|
}
|
|
17135
17518
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -17161,6 +17544,23 @@ var Library = class {
|
|
|
17161
17544
|
const text = (await this.read("notes", [e])).get(e.obj);
|
|
17162
17545
|
return text ? JSON.parse(text, reviver) : null;
|
|
17163
17546
|
}
|
|
17547
|
+
/** One deck's History: its saved checkpoints (manual, auto and "as you left
|
|
17548
|
+
* it"), newest first, each with the cards it held. `null`: the read copy has
|
|
17549
|
+
* none for this deck (no History yet, or a copy an older EDHVault wrote). */
|
|
17550
|
+
async historyOf(id, refresh = false) {
|
|
17551
|
+
const index = await this.view("decks", refresh);
|
|
17552
|
+
const e = index.hist?.[id];
|
|
17553
|
+
if (!e) return null;
|
|
17554
|
+
if (!e.obj) throw new LibraryError("no-copy", "This deck's History is too big for the read copy (over 2 MB), so it can't be read here. It's all still in EDHVault.");
|
|
17555
|
+
const text = (await this.read("decks", [e])).get(e.obj);
|
|
17556
|
+
const doc = text ? await unpackHistory(text) : null;
|
|
17557
|
+
return doc ? decodeViewHistory(doc.list).sort((a, b) => b.at - a.at) : null;
|
|
17558
|
+
}
|
|
17559
|
+
/** Whether the read copy carries History at all (written by a build that
|
|
17560
|
+
* copies it), so "no History" can be told from "not copied yet". */
|
|
17561
|
+
async historyCopied(refresh = false) {
|
|
17562
|
+
return (await this.view("decks", refresh)).hist !== void 0;
|
|
17563
|
+
}
|
|
17164
17564
|
/** Every collection stack. */
|
|
17165
17565
|
async collection(refresh = false) {
|
|
17166
17566
|
const index = await this.view("collection", refresh);
|
|
@@ -17203,7 +17603,7 @@ var Library = class {
|
|
|
17203
17603
|
return autoFromLetters(this.writes);
|
|
17204
17604
|
}
|
|
17205
17605
|
requestDir() {
|
|
17206
|
-
return
|
|
17606
|
+
return join7(this.opts.dir, "requests");
|
|
17207
17607
|
}
|
|
17208
17608
|
/** File a change request. The text is sealed here, under a key only this
|
|
17209
17609
|
* code and the user's own devices hold; a copy stays on disk, sealed, so
|
|
@@ -17225,8 +17625,8 @@ var Library = class {
|
|
|
17225
17625
|
this.fail(e);
|
|
17226
17626
|
}
|
|
17227
17627
|
if (r.status === "ok") {
|
|
17228
|
-
|
|
17229
|
-
|
|
17628
|
+
mkdirSync4(this.requestDir(), { recursive: true });
|
|
17629
|
+
writeFileSync4(join7(this.requestDir(), r.id), sealed);
|
|
17230
17630
|
}
|
|
17231
17631
|
return r;
|
|
17232
17632
|
}
|
|
@@ -17243,14 +17643,14 @@ var Library = class {
|
|
|
17243
17643
|
const agent = await deriveAgentKeys(this.secret);
|
|
17244
17644
|
const dir = this.requestDir();
|
|
17245
17645
|
const known = new Set(list.map((r) => r.id));
|
|
17246
|
-
if (
|
|
17247
|
-
for (const f of
|
|
17646
|
+
if (existsSync5(dir)) {
|
|
17647
|
+
for (const f of readdirSync2(dir)) if (!known.has(f)) rmSync3(join7(dir, f), { force: true });
|
|
17248
17648
|
}
|
|
17249
17649
|
return Promise.all(
|
|
17250
17650
|
list.map(async (r) => {
|
|
17251
|
-
const file4 =
|
|
17252
|
-
if (!keys.requests || !
|
|
17253
|
-
const text = await openAgentRequest(new Uint8Array(
|
|
17651
|
+
const file4 = join7(dir, r.id);
|
|
17652
|
+
if (!keys.requests || !existsSync5(file4)) return r;
|
|
17653
|
+
const text = await openAgentRequest(new Uint8Array(readFileSync7(file4)), keys.requests, agent.ah).catch(() => void 0);
|
|
17254
17654
|
return text ? { ...r, text } : r;
|
|
17255
17655
|
})
|
|
17256
17656
|
);
|
|
@@ -17258,14 +17658,14 @@ var Library = class {
|
|
|
17258
17658
|
};
|
|
17259
17659
|
|
|
17260
17660
|
// src/log.ts
|
|
17261
|
-
import { appendFileSync, mkdirSync as
|
|
17262
|
-
import { dirname as
|
|
17661
|
+
import { appendFileSync, mkdirSync as mkdirSync5 } from "node:fs";
|
|
17662
|
+
import { dirname as dirname3 } from "node:path";
|
|
17263
17663
|
var file = null;
|
|
17264
17664
|
var debugOn = false;
|
|
17265
17665
|
function configureLog(opts) {
|
|
17266
17666
|
file = opts.file ?? null;
|
|
17267
17667
|
debugOn = !!opts.debug;
|
|
17268
|
-
if (file)
|
|
17668
|
+
if (file) mkdirSync5(dirname3(file), { recursive: true });
|
|
17269
17669
|
}
|
|
17270
17670
|
function write(level, message) {
|
|
17271
17671
|
const line = `${(/* @__PURE__ */ new Date()).toISOString()} ${level} ${message}
|
|
@@ -17333,9 +17733,9 @@ async function redeemPairCode(text, t = {}, purpose = "sync") {
|
|
|
17333
17733
|
// src/secretStore.ts
|
|
17334
17734
|
init_syncKeys();
|
|
17335
17735
|
import { execFileSync } from "node:child_process";
|
|
17336
|
-
import { chmodSync, existsSync as
|
|
17736
|
+
import { chmodSync, existsSync as existsSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync8, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
17337
17737
|
import { userInfo } from "node:os";
|
|
17338
|
-
import { dirname as
|
|
17738
|
+
import { dirname as dirname4, join as join8 } from "node:path";
|
|
17339
17739
|
var SERVICE = "edhvault-mcp";
|
|
17340
17740
|
var ACCOUNT = "access-code";
|
|
17341
17741
|
async function osKeychain() {
|
|
@@ -17360,27 +17760,27 @@ function lockToOwner(file4) {
|
|
|
17360
17760
|
}
|
|
17361
17761
|
const windir = process.env.SystemRoot ?? "C:\\Windows";
|
|
17362
17762
|
execFileSync(
|
|
17363
|
-
|
|
17763
|
+
join8(windir, "System32", "icacls.exe"),
|
|
17364
17764
|
[file4, "/inheritance:r", "/grant:r", `${userInfo().username}:F`],
|
|
17365
17765
|
{ stdio: "ignore", windowsHide: true }
|
|
17366
17766
|
);
|
|
17367
17767
|
}
|
|
17368
17768
|
function fileKeychain(dir) {
|
|
17369
|
-
const file4 =
|
|
17769
|
+
const file4 = join8(dir, ACCOUNT);
|
|
17370
17770
|
return {
|
|
17371
|
-
get: () =>
|
|
17771
|
+
get: () => existsSync6(file4) ? readFileSync8(file4, "utf8").trim() : null,
|
|
17372
17772
|
set: (value) => {
|
|
17373
|
-
|
|
17374
|
-
|
|
17773
|
+
mkdirSync6(dirname4(file4), { recursive: true, mode: 448 });
|
|
17774
|
+
writeFileSync5(file4, "", { mode: 384 });
|
|
17375
17775
|
try {
|
|
17376
17776
|
lockToOwner(file4);
|
|
17377
17777
|
} catch (e) {
|
|
17378
|
-
|
|
17778
|
+
rmSync4(file4, { force: true });
|
|
17379
17779
|
throw new Error(`Couldn't make ${file4} private, so the code wasn't saved: ${e instanceof Error ? e.message : e}`);
|
|
17380
17780
|
}
|
|
17381
|
-
|
|
17781
|
+
writeFileSync5(file4, value);
|
|
17382
17782
|
},
|
|
17383
|
-
remove: () =>
|
|
17783
|
+
remove: () => rmSync4(file4, { force: true })
|
|
17384
17784
|
};
|
|
17385
17785
|
}
|
|
17386
17786
|
function saveSecret(store2, secret) {
|
|
@@ -17424,13 +17824,13 @@ async function login(code, store2, t) {
|
|
|
17424
17824
|
|
|
17425
17825
|
// src/paths.ts
|
|
17426
17826
|
import { homedir } from "node:os";
|
|
17427
|
-
import { join as
|
|
17827
|
+
import { join as join9 } from "node:path";
|
|
17428
17828
|
var ORIGIN = process.env.EDHVAULT_ORIGIN ?? "https://edhvault.com";
|
|
17429
17829
|
function configDir(env = process.env, platform = process.platform) {
|
|
17430
17830
|
if (env.EDHVAULT_MCP_HOME) return env.EDHVAULT_MCP_HOME;
|
|
17431
|
-
if (platform === "win32") return
|
|
17432
|
-
if (platform === "darwin") return
|
|
17433
|
-
return
|
|
17831
|
+
if (platform === "win32") return join9(env.APPDATA ?? join9(homedir(), "AppData", "Roaming"), "edhvault-mcp");
|
|
17832
|
+
if (platform === "darwin") return join9(homedir(), "Library", "Application Support", "edhvault-mcp");
|
|
17833
|
+
return join9(env.XDG_CONFIG_HOME ?? join9(homedir(), ".config"), "edhvault-mcp");
|
|
17434
17834
|
}
|
|
17435
17835
|
|
|
17436
17836
|
// ../../commander/node_modules/zod/v3/helpers/util.js
|
|
@@ -38617,7 +39017,7 @@ __export(external_exports, {
|
|
|
38617
39017
|
parse: () => parse3,
|
|
38618
39018
|
parseAsync: () => parseAsync2,
|
|
38619
39019
|
partialRecord: () => partialRecord,
|
|
38620
|
-
pipe: () =>
|
|
39020
|
+
pipe: () => pipe2,
|
|
38621
39021
|
positive: () => _positive,
|
|
38622
39022
|
prefault: () => prefault,
|
|
38623
39023
|
preprocess: () => preprocess,
|
|
@@ -38826,7 +39226,7 @@ __export(schemas_exports2, {
|
|
|
38826
39226
|
object: () => object2,
|
|
38827
39227
|
optional: () => optional,
|
|
38828
39228
|
partialRecord: () => partialRecord,
|
|
38829
|
-
pipe: () =>
|
|
39229
|
+
pipe: () => pipe2,
|
|
38830
39230
|
prefault: () => prefault,
|
|
38831
39231
|
preprocess: () => preprocess,
|
|
38832
39232
|
promise: () => promise,
|
|
@@ -39027,7 +39427,7 @@ var ZodType2 = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
39027
39427
|
return intersection(this, arg);
|
|
39028
39428
|
},
|
|
39029
39429
|
transform(tx) {
|
|
39030
|
-
return
|
|
39430
|
+
return pipe2(this, transform(tx));
|
|
39031
39431
|
},
|
|
39032
39432
|
default(d) {
|
|
39033
39433
|
return _default2(this, d);
|
|
@@ -39039,7 +39439,7 @@ var ZodType2 = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
39039
39439
|
return _catch2(this, params);
|
|
39040
39440
|
},
|
|
39041
39441
|
pipe(target) {
|
|
39042
|
-
return
|
|
39442
|
+
return pipe2(this, target);
|
|
39043
39443
|
},
|
|
39044
39444
|
readonly() {
|
|
39045
39445
|
return readonly(this);
|
|
@@ -40253,7 +40653,7 @@ var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
|
40253
40653
|
inst.in = def.in;
|
|
40254
40654
|
inst.out = def.out;
|
|
40255
40655
|
});
|
|
40256
|
-
function
|
|
40656
|
+
function pipe2(in_, out) {
|
|
40257
40657
|
return new ZodPipe({
|
|
40258
40658
|
type: "pipe",
|
|
40259
40659
|
in: in_,
|
|
@@ -46869,6 +47269,19 @@ var FIELD_ALIASES = {
|
|
|
46869
47269
|
condition: ["condition"],
|
|
46870
47270
|
language: ["language", "lang"]
|
|
46871
47271
|
};
|
|
47272
|
+
var ACQUIRED_ALIASES = {
|
|
47273
|
+
price: ["purchase price", "price paid", "purchased price", "acquired price"],
|
|
47274
|
+
currency: ["purchase price currency", "purchase currency", "currency"],
|
|
47275
|
+
date: ["added", "date added", "added at", "added on", "acquired", "acquired date", "purchase date", "date purchased"]
|
|
47276
|
+
};
|
|
47277
|
+
function pickExact(headers, aliases) {
|
|
47278
|
+
const lower = headers.map((h) => h.toLowerCase().trim());
|
|
47279
|
+
for (const alias of aliases) {
|
|
47280
|
+
const i = lower.indexOf(alias);
|
|
47281
|
+
if (i !== -1) return headers[i];
|
|
47282
|
+
}
|
|
47283
|
+
return null;
|
|
47284
|
+
}
|
|
46872
47285
|
function pickBinderTypeHeader(headers) {
|
|
46873
47286
|
const i = headers.findIndex((h) => h.toLowerCase().trim() === "binder type");
|
|
46874
47287
|
return i !== -1 ? headers[i] : null;
|
|
@@ -46908,7 +47321,7 @@ function detectCsvFormat(headers) {
|
|
|
46908
47321
|
}
|
|
46909
47322
|
return "unknown";
|
|
46910
47323
|
}
|
|
46911
|
-
function buildEntry(row, headerMap) {
|
|
47324
|
+
function buildEntry(row, headerMap, acq = { price: null, currency: null, date: null }) {
|
|
46912
47325
|
const nameHeader = headerMap.name;
|
|
46913
47326
|
if (!nameHeader) return null;
|
|
46914
47327
|
const rawName = row[nameHeader];
|
|
@@ -46922,6 +47335,9 @@ function buildEntry(row, headerMap) {
|
|
|
46922
47335
|
const foilRaw = headerMap.foil ? row[headerMap.foil] : void 0;
|
|
46923
47336
|
const conditionRaw = headerMap.condition ? row[headerMap.condition] : void 0;
|
|
46924
47337
|
const languageRaw = headerMap.language ? row[headerMap.language] : void 0;
|
|
47338
|
+
const price = acq.price ? parsePurchasePrice(row[acq.price]) : void 0;
|
|
47339
|
+
const date5 = acq.date ? parseAddedDate(row[acq.date]) : void 0;
|
|
47340
|
+
const currency = price !== void 0 && acq.currency ? row[acq.currency]?.trim().toUpperCase() : void 0;
|
|
46925
47341
|
return {
|
|
46926
47342
|
name,
|
|
46927
47343
|
quantity,
|
|
@@ -46929,7 +47345,11 @@ function buildEntry(row, headerMap) {
|
|
|
46929
47345
|
...collectorRaw ? { collectorNumber: collectorRaw.trim() } : {},
|
|
46930
47346
|
...foilRaw && isFoilLike(foilRaw) ? { foil: true } : {},
|
|
46931
47347
|
...conditionRaw ? { condition: conditionRaw.trim() } : {},
|
|
46932
|
-
...languageRaw ? { language: languageRaw.trim() } : {}
|
|
47348
|
+
...languageRaw ? { language: languageRaw.trim() } : {},
|
|
47349
|
+
...price !== void 0 || date5 ? {
|
|
47350
|
+
acquired: [{ quantity, ...price !== void 0 ? { price } : {}, ...date5 ? { date: date5 } : {} }],
|
|
47351
|
+
...currency && /^[A-Z]{3}$/.test(currency) ? { purchaseCurrency: currency } : {}
|
|
47352
|
+
} : {}
|
|
46933
47353
|
};
|
|
46934
47354
|
}
|
|
46935
47355
|
function looksLikePrice(value) {
|
|
@@ -46995,6 +47415,11 @@ async function parseCsv(input2) {
|
|
|
46995
47415
|
for (const field of Object.keys(FIELD_ALIASES)) {
|
|
46996
47416
|
headerMap[field] = pickHeader(headers, FIELD_ALIASES[field]);
|
|
46997
47417
|
}
|
|
47418
|
+
const acquiredHeaders = {
|
|
47419
|
+
price: pickExact(headers, ACQUIRED_ALIASES.price),
|
|
47420
|
+
currency: pickExact(headers, ACQUIRED_ALIASES.currency),
|
|
47421
|
+
date: pickExact(headers, ACQUIRED_ALIASES.date)
|
|
47422
|
+
};
|
|
46998
47423
|
const nameHeader = headerMap.name;
|
|
46999
47424
|
if (nameHeader) {
|
|
47000
47425
|
let repairedCount = 0;
|
|
@@ -47027,7 +47452,7 @@ async function parseCsv(input2) {
|
|
|
47027
47452
|
}
|
|
47028
47453
|
const entries2 = [];
|
|
47029
47454
|
for (const row of dataRows) {
|
|
47030
|
-
const entry = buildEntry(row, headerMap);
|
|
47455
|
+
const entry = buildEntry(row, headerMap, acquiredHeaders);
|
|
47031
47456
|
if (entry) entries2.push(entry);
|
|
47032
47457
|
}
|
|
47033
47458
|
return { entries: entries2, format, warnings };
|
|
@@ -47365,10 +47790,10 @@ var idbPrintingsCache = {
|
|
|
47365
47790
|
// ../src/lib/scryfall/resolvePrintings.ts
|
|
47366
47791
|
init_printings();
|
|
47367
47792
|
function createPrintingsResolver(source, cache2) {
|
|
47368
|
-
const
|
|
47793
|
+
const inflight2 = /* @__PURE__ */ new Map();
|
|
47369
47794
|
return function resolve(oracleId) {
|
|
47370
47795
|
if (!oracleId) return Promise.resolve({ status: "unavailable" });
|
|
47371
|
-
const pending =
|
|
47796
|
+
const pending = inflight2.get(oracleId);
|
|
47372
47797
|
if (pending) return pending;
|
|
47373
47798
|
const work = (async () => {
|
|
47374
47799
|
const cached2 = await cache2.get(oracleId);
|
|
@@ -47378,9 +47803,9 @@ function createPrintingsResolver(source, cache2) {
|
|
|
47378
47803
|
await cache2.put({ oracleId, printings: fetched, fetchedAt: Date.now() });
|
|
47379
47804
|
return { status: "ok", printings: fetched };
|
|
47380
47805
|
})();
|
|
47381
|
-
|
|
47806
|
+
inflight2.set(oracleId, work);
|
|
47382
47807
|
void work.finally(() => {
|
|
47383
|
-
if (
|
|
47808
|
+
if (inflight2.get(oracleId) === work) inflight2.delete(oracleId);
|
|
47384
47809
|
});
|
|
47385
47810
|
return work;
|
|
47386
47811
|
};
|
|
@@ -48586,6 +49011,7 @@ init_storage();
|
|
|
48586
49011
|
// ../src/lib/savedDecks/crud.ts
|
|
48587
49012
|
init_storageKey();
|
|
48588
49013
|
init_storage();
|
|
49014
|
+
init_checkpointStore();
|
|
48589
49015
|
init_deckText();
|
|
48590
49016
|
init_emptyDeck();
|
|
48591
49017
|
|
|
@@ -48669,6 +49095,7 @@ init_storage2();
|
|
|
48669
49095
|
init_storage3();
|
|
48670
49096
|
init_manaOverrides();
|
|
48671
49097
|
init_oddsPlans();
|
|
49098
|
+
init_checkpointStore();
|
|
48672
49099
|
|
|
48673
49100
|
// ../src/lib/savedDecks/format.ts
|
|
48674
49101
|
var VERBOSE_DATE = new Intl.DateTimeFormat("en-US", {
|
|
@@ -48677,7 +49104,7 @@ var VERBOSE_DATE = new Intl.DateTimeFormat("en-US", {
|
|
|
48677
49104
|
month: "long",
|
|
48678
49105
|
day: "numeric"
|
|
48679
49106
|
});
|
|
48680
|
-
var
|
|
49107
|
+
var DAY_MS3 = 24 * 60 * 60 * 1e3;
|
|
48681
49108
|
|
|
48682
49109
|
// ../src/lib/savedDecks/crossDeck.ts
|
|
48683
49110
|
init_utils();
|
|
@@ -48752,6 +49179,38 @@ var createImpl = (createState) => {
|
|
|
48752
49179
|
};
|
|
48753
49180
|
var create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
48754
49181
|
|
|
49182
|
+
// ../src/lib/scryfall/identityArt.ts
|
|
49183
|
+
async function deriveIdentityArt(wanted) {
|
|
49184
|
+
const out = /* @__PURE__ */ new Map();
|
|
49185
|
+
if (wanted.length === 0) return out;
|
|
49186
|
+
const ids = (ws) => ws.map((w) => ({ set: w.set, collectorNumber: w.collectorNumber }));
|
|
49187
|
+
let baked = /* @__PURE__ */ new Map();
|
|
49188
|
+
try {
|
|
49189
|
+
baked = await getBakedIdentityArt(ids(wanted));
|
|
49190
|
+
} catch {
|
|
49191
|
+
}
|
|
49192
|
+
const misses = wanted.filter(
|
|
49193
|
+
(w) => !baked.has(printingKey(w.set, w.collectorNumber))
|
|
49194
|
+
);
|
|
49195
|
+
let live = /* @__PURE__ */ new Map();
|
|
49196
|
+
if (misses.length > 0) {
|
|
49197
|
+
try {
|
|
49198
|
+
live = await resolvePrintingsByIdentity(ids(misses));
|
|
49199
|
+
} catch {
|
|
49200
|
+
}
|
|
49201
|
+
}
|
|
49202
|
+
for (const w of wanted) {
|
|
49203
|
+
const key2 = printingKey(w.set, w.collectorNumber);
|
|
49204
|
+
const rec = baked.get(key2) ?? live.get(key2);
|
|
49205
|
+
if (!rec || rec.oracleId !== w.oracleId || !rec.image) continue;
|
|
49206
|
+
out.set(key2, {
|
|
49207
|
+
image: rec.image,
|
|
49208
|
+
...rec.backImage ? { backImage: rec.backImage } : {}
|
|
49209
|
+
});
|
|
49210
|
+
}
|
|
49211
|
+
return out;
|
|
49212
|
+
}
|
|
49213
|
+
|
|
48755
49214
|
// ../src/state/deckPrintingOverrides.ts
|
|
48756
49215
|
var useDeckPrintingOverrides = create(
|
|
48757
49216
|
(set3, get) => ({
|
|
@@ -48785,35 +49244,9 @@ async function resolveMissingArt(overrides, set3, get) {
|
|
|
48785
49244
|
wanted.push({ oracleId, set: ov.set, collectorNumber: ov.collectorNumber });
|
|
48786
49245
|
}
|
|
48787
49246
|
if (wanted.length === 0) return;
|
|
48788
|
-
const
|
|
48789
|
-
|
|
48790
|
-
);
|
|
48791
|
-
const misses = wanted.filter(
|
|
48792
|
-
(w) => !baked.has(printingKey(w.set, w.collectorNumber))
|
|
48793
|
-
);
|
|
48794
|
-
let live = /* @__PURE__ */ new Map();
|
|
48795
|
-
if (misses.length > 0) {
|
|
48796
|
-
try {
|
|
48797
|
-
live = await resolvePrintingsByIdentity(
|
|
48798
|
-
misses.map((w) => ({ set: w.set, collectorNumber: w.collectorNumber }))
|
|
48799
|
-
);
|
|
48800
|
-
} catch {
|
|
48801
|
-
}
|
|
48802
|
-
}
|
|
48803
|
-
const next = new Map(get().resolvedArt);
|
|
48804
|
-
let added = 0;
|
|
48805
|
-
for (const w of wanted) {
|
|
48806
|
-
const key2 = printingKey(w.set, w.collectorNumber);
|
|
48807
|
-
const rec = baked.get(key2) ?? live.get(key2);
|
|
48808
|
-
if (!rec || rec.oracleId !== w.oracleId || !rec.image) continue;
|
|
48809
|
-
next.set(key2, {
|
|
48810
|
-
image: rec.image,
|
|
48811
|
-
...rec.backImage ? { backImage: rec.backImage } : {}
|
|
48812
|
-
});
|
|
48813
|
-
added++;
|
|
48814
|
-
}
|
|
48815
|
-
if (added === 0) return;
|
|
48816
|
-
set3({ resolvedArt: next });
|
|
49247
|
+
const derived2 = await deriveIdentityArt(wanted);
|
|
49248
|
+
if (derived2.size === 0) return;
|
|
49249
|
+
set3({ resolvedArt: new Map([...get().resolvedArt, ...derived2]) });
|
|
48817
49250
|
}
|
|
48818
49251
|
|
|
48819
49252
|
// ../src/components/deckBuilderV2/v2CategoryOps.ts
|
|
@@ -50850,6 +51283,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
50850
51283
|
// Hour of Victory
|
|
50851
51284
|
"d95d0b24-2e6f-4f61-8668-26effeaaf2fb": { "r": "finds a card by name" },
|
|
50852
51285
|
// Howling Wolf
|
|
51286
|
+
"f129e01f-cb3b-439d-b1eb-5e253557e814": { "a": [{ "types": [["basic", "land"]] }] },
|
|
51287
|
+
// Huatli, Inventor's Inspiration
|
|
50853
51288
|
"2e6ed3e6-d2b8-4b75-b7e1-0773da4987a1": { "a": [{ "types": [["basic", "land"]] }, { "types": [["dinosaur"]] }] },
|
|
50854
51289
|
// Huatli, Poet of Unity // Roar of the Fifth People
|
|
50855
51290
|
"a7285536-6cc1-448e-839a-606d585fbd9d": { "a": [{ "types": [["basic", "land"]] }] },
|
|
@@ -50958,6 +51393,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
50958
51393
|
// Keys to the House
|
|
50959
51394
|
"be6155de-c5b2-415c-ad83-142f9926462a": { "a": [{ "types": [["basic", "land"]] }] },
|
|
50960
51395
|
// Khalni Heart Expedition
|
|
51396
|
+
"025ceb73-5b00-4ac8-a20b-1126505fab68": { "a": [{ "types": [["basic", "land"]] }] },
|
|
51397
|
+
// King Tiro of Meletis
|
|
50961
51398
|
"a3d68848-e8cc-497c-951b-e7111f6d5142": { "a": [{ "types": [["kithkin"]] }] },
|
|
50962
51399
|
// Kithkin Harbinger
|
|
50963
51400
|
"393e5331-4456-4ba3-b410-bb630bb053db": { "a": [{ "types": [["land"]] }] },
|
|
@@ -51448,6 +51885,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
51448
51885
|
// Roamer's Routine
|
|
51449
51886
|
"41c765a4-a9c9-4169-a9f1-74ededeb793c": { "a": [{ "types": [["creature"]] }] },
|
|
51450
51887
|
// Rocco, Cabaretti Caterer
|
|
51888
|
+
"d3e182c0-54d1-4d06-a9f3-b6671a084a15": { "a": [{ "types": [["creature"]] }] },
|
|
51889
|
+
// Rocco, Snack Supplier
|
|
51451
51890
|
"f9330a7b-8a65-4e04-a777-bf6512332850": { "a": [{ "types": [["forest"]] }] },
|
|
51452
51891
|
// Rocksteady, Crash Courser
|
|
51453
51892
|
"8709b5b1-ef9e-45b2-bf4f-ef4c4d613dcd": { "a": [{ "types": [["swamp"], ["mountain"]] }] },
|
|
@@ -51566,6 +52005,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
51566
52005
|
// Shadow-Rite Priest
|
|
51567
52006
|
"595a15f0-77f3-4544-8acc-10630e12cc14": { "a": [{ "types": [["demon", "creature"]] }] },
|
|
51568
52007
|
// Shadowborn Apostle
|
|
52008
|
+
"155ee70b-898c-472f-a5e7-71f14da94894": { "a": [{ "types": [["basic", "land"]] }, { "types": [["desert"]] }] },
|
|
52009
|
+
// Shai-Hulud
|
|
51569
52010
|
"c51fc4f2-76a6-4337-ab8f-1b3e84f82019": { "a": [{ "types": [["plains"]] }, { "types": [["island"]] }, { "types": [["swamp"]] }, { "types": [["mountain"]] }] },
|
|
51570
52011
|
// Shard Convergence
|
|
51571
52012
|
"823afa57-faac-4a43-a403-c1bb0446d594": { "a": [{ "types": [["basic", "land"]] }] },
|
|
@@ -51710,8 +52151,6 @@ var TUTOR_TEXT_REACH = {
|
|
|
51710
52151
|
// Stoneforge Mystic
|
|
51711
52152
|
"b3d99ea0-d61f-4394-8913-b4057c38ff3e": { "a": [{ "types": [["equipment"]] }] },
|
|
51712
52153
|
// Stonehewer Giant
|
|
51713
|
-
"a500b724-bf28-47a3-b434-6efdebbcc04c": { "a": [{ "types": [["land"]] }] },
|
|
51714
|
-
// Strata Scythe
|
|
51715
52154
|
"36ab41b7-bcfb-4618-bbfb-70d608dba15a": { "a": [{ "types": [["basic", "land"]] }] },
|
|
51716
52155
|
// Stratosoarer
|
|
51717
52156
|
"e286a191-39d4-4073-b844-11d2aba911b4": { "a": [{ "types": [["basic", "land"]] }] },
|
|
@@ -52326,9 +52765,9 @@ var UNCHECKABLE_SUBTAGS = /* @__PURE__ */ new Set([
|
|
|
52326
52765
|
"praetor"
|
|
52327
52766
|
]);
|
|
52328
52767
|
function parseTarget(target) {
|
|
52329
|
-
const
|
|
52768
|
+
const front2 = (target.typeLine.split(" // ")[0] ?? target.typeLine).toLowerCase();
|
|
52330
52769
|
return {
|
|
52331
|
-
words: new Set(
|
|
52770
|
+
words: new Set(front2.split(/[\s—]+/).filter(Boolean)),
|
|
52332
52771
|
cmc: target.cmc,
|
|
52333
52772
|
colors: target.colors,
|
|
52334
52773
|
keywords: target.keywords,
|
|
@@ -53819,6 +54258,243 @@ function decodeCardText(entry) {
|
|
|
53819
54258
|
};
|
|
53820
54259
|
}
|
|
53821
54260
|
|
|
54261
|
+
// ../src/lib/priceHistory/value.ts
|
|
54262
|
+
function seriesFor(p, foil) {
|
|
54263
|
+
if (!p) return null;
|
|
54264
|
+
const order = foil ? ["f", "e", "n"] : ["n", "f", "e"];
|
|
54265
|
+
for (const f of order) {
|
|
54266
|
+
const r = p[f];
|
|
54267
|
+
if (r && r.length > 0) return { finish: f, record: r };
|
|
54268
|
+
}
|
|
54269
|
+
return null;
|
|
54270
|
+
}
|
|
54271
|
+
function groupOwned(owned) {
|
|
54272
|
+
const by = /* @__PURE__ */ new Map();
|
|
54273
|
+
for (const o of owned) {
|
|
54274
|
+
if (!o.set || !o.collectorNumber || !(o.quantity > 0)) continue;
|
|
54275
|
+
const key2 = `${o.set.toLowerCase()}|${o.collectorNumber}|${o.foil ? 1 : 0}`;
|
|
54276
|
+
const prev = by.get(key2);
|
|
54277
|
+
if (prev) {
|
|
54278
|
+
prev.quantity += o.quantity;
|
|
54279
|
+
if (o.lots) prev.lots = [...prev.lots ?? [], ...o.lots];
|
|
54280
|
+
} else by.set(key2, { ...o, set: o.set.toLowerCase() });
|
|
54281
|
+
}
|
|
54282
|
+
return [...by.values()];
|
|
54283
|
+
}
|
|
54284
|
+
function computeValueHistory(owned, files, from, to) {
|
|
54285
|
+
const days = to - from + 1;
|
|
54286
|
+
const totals = new Float64Array(Math.max(0, days));
|
|
54287
|
+
const grouped = groupOwned(owned);
|
|
54288
|
+
const bySet = /* @__PURE__ */ new Map();
|
|
54289
|
+
for (const f of files) {
|
|
54290
|
+
if (f.end < from || f.start > to) continue;
|
|
54291
|
+
const list = bySet.get(f.set) ?? [];
|
|
54292
|
+
list.push(f);
|
|
54293
|
+
bySet.set(f.set, list);
|
|
54294
|
+
}
|
|
54295
|
+
for (const list of bySet.values()) list.sort((a, b) => a.start - b.start);
|
|
54296
|
+
let pricedCopies = 0;
|
|
54297
|
+
let unpricedCopies = 0;
|
|
54298
|
+
let specialFoilCopies = 0;
|
|
54299
|
+
const moves = [];
|
|
54300
|
+
const daily = new Int32Array(Math.max(0, days));
|
|
54301
|
+
const then = new Float64Array(Math.max(0, days));
|
|
54302
|
+
let anyDated = false;
|
|
54303
|
+
const purchase = { copies: 0, paidCents: 0, nowCents: 0 };
|
|
54304
|
+
for (const o of grouped) {
|
|
54305
|
+
const list = bySet.get(o.set);
|
|
54306
|
+
daily.fill(-1);
|
|
54307
|
+
let finish = null;
|
|
54308
|
+
let special = false;
|
|
54309
|
+
if (list) {
|
|
54310
|
+
for (const file4 of list) {
|
|
54311
|
+
const s = seriesFor(file4.p[o.collectorNumber], o.foil);
|
|
54312
|
+
if (!s) continue;
|
|
54313
|
+
finish ??= s.finish;
|
|
54314
|
+
const record2 = s.finish === finish ? s.record : file4.p[o.collectorNumber]?.[finish];
|
|
54315
|
+
if (!record2) continue;
|
|
54316
|
+
if (o.foil && file4.af?.includes(o.collectorNumber)) special = true;
|
|
54317
|
+
for (let i = 0; i < record2.length; i += 2) {
|
|
54318
|
+
const startDay = file4.start + record2[i];
|
|
54319
|
+
const endDay = i + 2 < record2.length ? file4.start + record2[i + 2] - 1 : file4.end;
|
|
54320
|
+
const v = record2[i + 1];
|
|
54321
|
+
if (v == null) continue;
|
|
54322
|
+
for (let d = Math.max(startDay, from); d <= Math.min(endDay, to); d++) daily[d - from] = v;
|
|
54323
|
+
}
|
|
54324
|
+
}
|
|
54325
|
+
}
|
|
54326
|
+
let last = -1;
|
|
54327
|
+
let first = -1;
|
|
54328
|
+
for (let i = 0; i < days; i++) {
|
|
54329
|
+
if (daily[i] >= 0) {
|
|
54330
|
+
last = daily[i];
|
|
54331
|
+
if (first < 0) first = last;
|
|
54332
|
+
} else if (last >= 0) daily[i] = last;
|
|
54333
|
+
if (daily[i] >= 0) totals[i] += daily[i] * o.quantity;
|
|
54334
|
+
}
|
|
54335
|
+
if (last < 0 || finish === null) {
|
|
54336
|
+
unpricedCopies += o.quantity;
|
|
54337
|
+
continue;
|
|
54338
|
+
}
|
|
54339
|
+
pricedCopies += o.quantity;
|
|
54340
|
+
if (special) specialFoilCopies += o.quantity;
|
|
54341
|
+
for (const lot of o.lots ?? []) {
|
|
54342
|
+
if (lot.date) {
|
|
54343
|
+
anyDated = true;
|
|
54344
|
+
const start = Math.max(0, epochDay(lot.date) - from);
|
|
54345
|
+
for (let i = start; i < days; i++) if (daily[i] >= 0) then[i] += daily[i] * lot.quantity;
|
|
54346
|
+
}
|
|
54347
|
+
if (lot.priceUsd !== void 0) {
|
|
54348
|
+
purchase.copies += lot.quantity;
|
|
54349
|
+
purchase.paidCents += Math.round(lot.priceUsd * 100) * lot.quantity;
|
|
54350
|
+
purchase.nowCents += last * lot.quantity;
|
|
54351
|
+
}
|
|
54352
|
+
}
|
|
54353
|
+
if (FINISHES.includes(finish) && first >= 0) {
|
|
54354
|
+
moves.push({ printing: o, finish, fromCents: first, toCents: last, deltaCents: (last - first) * o.quantity });
|
|
54355
|
+
}
|
|
54356
|
+
}
|
|
54357
|
+
const points = [];
|
|
54358
|
+
for (let i = 0; i < days; i++) points.push({ day: from + i, cents: Math.round(totals[i]) });
|
|
54359
|
+
moves.sort((a, b) => b.deltaCents - a.deltaCents);
|
|
54360
|
+
const addedByThen = anyDated ? points.map((p, i) => ({ day: p.day, cents: Math.round(then[i]) })) : null;
|
|
54361
|
+
return { points, pricedCopies, unpricedCopies, specialFoilCopies, moves, addedByThen, purchase };
|
|
54362
|
+
}
|
|
54363
|
+
function ownedSets(owned) {
|
|
54364
|
+
return [...new Set(owned.filter((o) => o.set && o.collectorNumber).map((o) => o.set.toLowerCase()))].sort();
|
|
54365
|
+
}
|
|
54366
|
+
|
|
54367
|
+
// ../src/lib/affiliate.ts
|
|
54368
|
+
init_slug();
|
|
54369
|
+
var TCGPLAYER_AFFILIATE_LINK = "https://partner.tcgplayer.com/c/7357471/1780961/21018";
|
|
54370
|
+
var CARDMARKET_PARTNER = "";
|
|
54371
|
+
var front = (cardName) => cardName.split(" // ")[0];
|
|
54372
|
+
function buildTcgPlayerSearchUrl(cardName) {
|
|
54373
|
+
const q = encodeURIComponent(front(cardName));
|
|
54374
|
+
const destination2 = `https://www.tcgplayer.com/search/magic/product?productLineName=magic&q=${q}`;
|
|
54375
|
+
return `${TCGPLAYER_AFFILIATE_LINK}?u=${encodeURIComponent(destination2)}`;
|
|
54376
|
+
}
|
|
54377
|
+
function buildTcgPlayerMassEntryUrl(cards) {
|
|
54378
|
+
const list = cards.map((c) => {
|
|
54379
|
+
const base = `${c.qty ?? 1} ${front(c.name)}`;
|
|
54380
|
+
return c.set && c.collectorNumber ? `${base} [${c.set.toUpperCase()}] ${c.collectorNumber}` : base;
|
|
54381
|
+
}).join("||");
|
|
54382
|
+
const destination2 = `https://www.tcgplayer.com/massentry?productline=Magic&c=${encodeURIComponent(list)}`;
|
|
54383
|
+
return `${TCGPLAYER_AFFILIATE_LINK}?u=${encodeURIComponent(destination2)}`;
|
|
54384
|
+
}
|
|
54385
|
+
function buildCardmarketSearchUrl(cardName) {
|
|
54386
|
+
const q = encodeURIComponent(front(cardName));
|
|
54387
|
+
const partner = CARDMARKET_PARTNER ? `&utm_source=${encodeURIComponent(CARDMARKET_PARTNER)}&utm_medium=affiliate` : "";
|
|
54388
|
+
return `https://www.cardmarket.com/en/Magic/Products/Search?searchString=${q}${partner}`;
|
|
54389
|
+
}
|
|
54390
|
+
function buildCardKingdomSearchUrl(cardName) {
|
|
54391
|
+
const q = encodeURIComponent(front(cardName));
|
|
54392
|
+
return `https://www.cardkingdom.com/catalog/search?search=header&filter%5Bname%5D=${q}`;
|
|
54393
|
+
}
|
|
54394
|
+
function buildCardKingdomBuilderUrl(cards) {
|
|
54395
|
+
const list = cards.map((c) => `${c.qty ?? 1} ${front(c.name)}`).join("\n");
|
|
54396
|
+
return `https://www.cardkingdom.com/builder?c=${encodeURIComponent(list)}`;
|
|
54397
|
+
}
|
|
54398
|
+
function buildManaPoolCardUrl(cardName) {
|
|
54399
|
+
return `https://manapool.com/card/${toEdhrecSlug(cardName)}`;
|
|
54400
|
+
}
|
|
54401
|
+
var VENDORS = [
|
|
54402
|
+
{
|
|
54403
|
+
id: "cardkingdom",
|
|
54404
|
+
name: "Card Kingdom",
|
|
54405
|
+
cardUrl: buildCardKingdomSearchUrl,
|
|
54406
|
+
deckUrl: buildCardKingdomBuilderUrl,
|
|
54407
|
+
affiliate: false
|
|
54408
|
+
},
|
|
54409
|
+
{
|
|
54410
|
+
id: "cardmarket",
|
|
54411
|
+
name: "Cardmarket",
|
|
54412
|
+
cardUrl: buildCardmarketSearchUrl,
|
|
54413
|
+
deckUrl: null,
|
|
54414
|
+
affiliate: false
|
|
54415
|
+
},
|
|
54416
|
+
{
|
|
54417
|
+
id: "manapool",
|
|
54418
|
+
name: "Mana Pool",
|
|
54419
|
+
cardUrl: buildManaPoolCardUrl,
|
|
54420
|
+
deckUrl: null,
|
|
54421
|
+
affiliate: false
|
|
54422
|
+
},
|
|
54423
|
+
{
|
|
54424
|
+
id: "tcgplayer",
|
|
54425
|
+
name: "TCGplayer",
|
|
54426
|
+
cardUrl: buildTcgPlayerSearchUrl,
|
|
54427
|
+
deckUrl: buildTcgPlayerMassEntryUrl,
|
|
54428
|
+
affiliate: true
|
|
54429
|
+
}
|
|
54430
|
+
];
|
|
54431
|
+
var HAS_AFFILIATE_VENDOR = VENDORS.some((v) => v.affiliate);
|
|
54432
|
+
|
|
54433
|
+
// ../src/lib/deckPlan/historyPreview.ts
|
|
54434
|
+
function deslugify(slug) {
|
|
54435
|
+
return slug.split("-").map((w) => w ? w[0].toUpperCase() + w.slice(1) : w).join(" ").trim();
|
|
54436
|
+
}
|
|
54437
|
+
var byName2 = (a, b) => a.name.localeCompare(b.name);
|
|
54438
|
+
function versionCards(plan, r = {}) {
|
|
54439
|
+
const nameOf = (oracleId, slug) => oracleId && r.resolveName?.(oracleId) || (slug ? deslugify(slug) : "Unknown card");
|
|
54440
|
+
const deck = /* @__PURE__ */ new Map();
|
|
54441
|
+
const add = (key2, oracleId, name, qty) => {
|
|
54442
|
+
const prev = deck.get(key2);
|
|
54443
|
+
if (prev) prev.qty += qty;
|
|
54444
|
+
else deck.set(key2, { key: key2, ...oracleId ? { oracleId } : {}, name, qty, zone: "deck" });
|
|
54445
|
+
};
|
|
54446
|
+
for (const oid of plan.assignments.keys()) {
|
|
54447
|
+
add(oid, oid, nameOf(oid), Math.max(1, plan.basicQuantities.get(oid) ?? 1));
|
|
54448
|
+
}
|
|
54449
|
+
for (const slug of plan.purchases.keys()) {
|
|
54450
|
+
const oid = r.resolveSlug?.(slug);
|
|
54451
|
+
add(oid ?? `slug:${slug}`, oid, nameOf(oid, slug), Math.max(1, plan.purchaseQuantities?.get(slug) ?? 1));
|
|
54452
|
+
}
|
|
54453
|
+
const zone = (ids, z2) => [...ids ?? []].filter((oid) => !deck.has(oid)).map((oid) => ({ key: oid, oracleId: oid, name: nameOf(oid), qty: 1, zone: z2 })).sort(byName2);
|
|
54454
|
+
return [
|
|
54455
|
+
...[...deck.values()].sort(byName2),
|
|
54456
|
+
...zone(plan.considering, "considering"),
|
|
54457
|
+
...zone(plan.sideboard, "sideboard")
|
|
54458
|
+
];
|
|
54459
|
+
}
|
|
54460
|
+
function diffVersions(then, now, r = {}) {
|
|
54461
|
+
const a = new Map(versionCards(then, r).map((c) => [c.key, c]));
|
|
54462
|
+
const b = new Map(versionCards(now, r).map((c) => [c.key, c]));
|
|
54463
|
+
const out = {
|
|
54464
|
+
addedSince: [],
|
|
54465
|
+
removedSince: [],
|
|
54466
|
+
countChanged: [],
|
|
54467
|
+
moved: [],
|
|
54468
|
+
commandersThen: then.commanders.map((c) => c.name),
|
|
54469
|
+
commandersNow: now.commanders.map((c) => c.name),
|
|
54470
|
+
commanderChanged: false
|
|
54471
|
+
};
|
|
54472
|
+
for (const [key2, was] of a) {
|
|
54473
|
+
const is = b.get(key2);
|
|
54474
|
+
if (!is) out.removedSince.push(was);
|
|
54475
|
+
else if (is.zone !== was.zone) out.moved.push({ card: is, then: was.zone, now: is.zone });
|
|
54476
|
+
else if (is.qty !== was.qty) out.countChanged.push({ card: is, then: was.qty, now: is.qty });
|
|
54477
|
+
}
|
|
54478
|
+
for (const [key2, is] of b) if (!a.has(key2)) out.addedSince.push(is);
|
|
54479
|
+
out.commanderChanged = then.commanders.map((c) => c.oracleId).join("|") !== now.commanders.map((c) => c.oracleId).join("|") || then.soloHalf !== now.soloHalf;
|
|
54480
|
+
return out;
|
|
54481
|
+
}
|
|
54482
|
+
function isSameVersion(d) {
|
|
54483
|
+
return !d.commanderChanged && !d.addedSince.length && !d.removedSince.length && !d.countChanged.length && !d.moved.length;
|
|
54484
|
+
}
|
|
54485
|
+
function summarizeVersionDiff(d, textFields = []) {
|
|
54486
|
+
const parts = [];
|
|
54487
|
+
if (d.commanderChanged) parts.push("commander changed");
|
|
54488
|
+
if (d.addedSince.length) parts.push(`${d.addedSince.length} added`);
|
|
54489
|
+
if (d.removedSince.length) parts.push(`${d.removedSince.length} removed`);
|
|
54490
|
+
if (d.moved.length) parts.push(`${d.moved.length} moved`);
|
|
54491
|
+
if (d.countChanged.length) parts.push(`${d.countChanged.length} ${d.countChanged.length === 1 ? "count" : "counts"} changed`);
|
|
54492
|
+
if (textFields.length) parts.push(`${textFields.join(", ")} edited`);
|
|
54493
|
+
if (!parts.length) return "Tags or printings changed";
|
|
54494
|
+
const s = parts.join(", ");
|
|
54495
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
54496
|
+
}
|
|
54497
|
+
|
|
53822
54498
|
// ../src/lib/edhrec/bracket-signals.ts
|
|
53823
54499
|
init_slug();
|
|
53824
54500
|
var MLD_NAMES = [
|
|
@@ -54078,8 +54754,8 @@ function viewDeck(id, d, catalog, comboIndex) {
|
|
|
54078
54754
|
}
|
|
54079
54755
|
var TYPE_ORDER = ["Creature", "Planeswalker", "Battle", "Instant", "Sorcery", "Artifact", "Enchantment", "Land"];
|
|
54080
54756
|
function primaryType(card) {
|
|
54081
|
-
const
|
|
54082
|
-
return TYPE_ORDER.find((t) =>
|
|
54757
|
+
const front2 = card.typeLine.split(" // ")[0] ?? card.typeLine;
|
|
54758
|
+
return TYPE_ORDER.find((t) => front2.includes(t)) ?? "Other";
|
|
54083
54759
|
}
|
|
54084
54760
|
function isLand3(card) {
|
|
54085
54761
|
return (card.typeLine.split(" // ")[0] ?? card.typeLine).includes("Land");
|
|
@@ -54137,7 +54813,13 @@ var REDUCER = new Set(REDUCER_FIELDS);
|
|
|
54137
54813
|
|
|
54138
54814
|
// ../src/lib/agentRequests/deckOps.ts
|
|
54139
54815
|
init_utils();
|
|
54816
|
+
init_deckText();
|
|
54140
54817
|
var DECK_BOARDS = ["deck", "considering", "sideboard"];
|
|
54818
|
+
var DECK_TEXT_FIELDS = ["name", "description", "notes"];
|
|
54819
|
+
var TEXT_OID = "deck-text";
|
|
54820
|
+
var isTextOp = (op) => op.op === "text";
|
|
54821
|
+
var MAX_CARD_TAGS = 12;
|
|
54822
|
+
var MAX_TAG_NAME = 40;
|
|
54141
54823
|
var MAX_CARDS_PER_EDIT = 30;
|
|
54142
54824
|
var MAX_COPIES = 99;
|
|
54143
54825
|
function slugsOf(card) {
|
|
@@ -54161,8 +54843,81 @@ function entryProblem(card, qty, identity2) {
|
|
|
54161
54843
|
if (qty > 1 && !allowsMultipleCopies(card.typeLine, card.name)) return "only one copy is allowed";
|
|
54162
54844
|
return null;
|
|
54163
54845
|
}
|
|
54846
|
+
var sideOf = (stored) => ({
|
|
54847
|
+
cats: stored.v2Categories,
|
|
54848
|
+
prints: stored.printingOverrides,
|
|
54849
|
+
text: { name: stored.name ?? "", description: stored.description ?? "", notes: stored.notes ?? "" }
|
|
54850
|
+
});
|
|
54851
|
+
function cleanDeckText(field, value) {
|
|
54852
|
+
if (field === "name") return clampDeckName(value);
|
|
54853
|
+
return value.trim().slice(0, field === "description" ? MAX_DESCRIPTION_LENGTH : MAX_NOTES_LENGTH);
|
|
54854
|
+
}
|
|
54855
|
+
var TEXT_LABEL = { name: "the deck's name", description: "the description", notes: "the notes" };
|
|
54856
|
+
function textProblem(side, op) {
|
|
54857
|
+
if (op.from !== void 0 && side.text[op.field] !== op.from) return "changed since";
|
|
54858
|
+
return side.text[op.field] === cleanDeckText(op.field, op.value) ? "already says that" : null;
|
|
54859
|
+
}
|
|
54860
|
+
function tagsOf(cats, oid) {
|
|
54861
|
+
if (!cats) return [];
|
|
54862
|
+
const name = (id) => cats.categories.find((c) => c.id === id)?.name;
|
|
54863
|
+
const primary = cats.assignments[oid];
|
|
54864
|
+
return [primary, ...cats.secondary?.[oid] ?? []].flatMap((id) => id ? [name(id)].filter((n) => !!n) : []);
|
|
54865
|
+
}
|
|
54866
|
+
function withTags(cats, oid, tags) {
|
|
54867
|
+
const base = cats ?? { groupMode: "type", categories: [], assignments: {} };
|
|
54868
|
+
const categories = [...base.categories];
|
|
54869
|
+
const ids = [];
|
|
54870
|
+
for (const raw of tags) {
|
|
54871
|
+
const name = raw.trim();
|
|
54872
|
+
if (!name) continue;
|
|
54873
|
+
let cat = categories.find((c) => c.name.toLowerCase() === name.toLowerCase());
|
|
54874
|
+
if (!cat) {
|
|
54875
|
+
let n = categories.length;
|
|
54876
|
+
while (categories.some((c) => c.id === `cat_link_${n}`)) n++;
|
|
54877
|
+
cat = { id: `cat_link_${n}`, name };
|
|
54878
|
+
categories.push(cat);
|
|
54879
|
+
}
|
|
54880
|
+
if (!ids.includes(cat.id)) ids.push(cat.id);
|
|
54881
|
+
}
|
|
54882
|
+
const assignments = { ...base.assignments };
|
|
54883
|
+
const secondary = { ...base.secondary ?? {} };
|
|
54884
|
+
delete assignments[oid];
|
|
54885
|
+
delete secondary[oid];
|
|
54886
|
+
if (ids[0]) assignments[oid] = ids[0];
|
|
54887
|
+
if (ids.length > 1) secondary[oid] = ids.slice(1);
|
|
54888
|
+
const next = { ...base, categories, assignments };
|
|
54889
|
+
if (Object.keys(secondary).length) next.secondary = secondary;
|
|
54890
|
+
else delete next.secondary;
|
|
54891
|
+
return next;
|
|
54892
|
+
}
|
|
54893
|
+
var printOf = (prints, oid) => {
|
|
54894
|
+
const p = prints?.[oid];
|
|
54895
|
+
return p ? { set: p.set, cn: p.collectorNumber } : null;
|
|
54896
|
+
};
|
|
54897
|
+
var samePrint = (a, b) => (a?.set ?? "") === (b?.set ?? "") && (a?.cn ?? "") === (b?.cn ?? "");
|
|
54898
|
+
function sideProblem(s, side, op, card) {
|
|
54899
|
+
if (!placeOf(s, card) && !s.commanders.some((c) => c.oracleId === card.oracleId)) return "not in the deck";
|
|
54900
|
+
if (op.op === "tags") {
|
|
54901
|
+
if (op.tags.length > MAX_CARD_TAGS || op.tags.some((t) => !t.trim() || t.length > MAX_TAG_NAME)) return "asks for tags it can't have";
|
|
54902
|
+
const now = tagsOf(side.cats, card.oracleId);
|
|
54903
|
+
return now.length === op.tags.length && now.every((t, i) => t.toLowerCase() === op.tags[i].trim().toLowerCase()) ? "already tagged that way" : null;
|
|
54904
|
+
}
|
|
54905
|
+
return samePrint(printOf(side.prints, card.oracleId), op.print) ? "already that printing" : null;
|
|
54906
|
+
}
|
|
54907
|
+
function runSide(side, op) {
|
|
54908
|
+
const id = op.oracleId;
|
|
54909
|
+
if (op.op === "tags") {
|
|
54910
|
+
return { side: { ...side, cats: withTags(side.cats, id, op.tags) }, inverse: { op: "tags", oracleId: id, tags: tagsOf(side.cats, id) } };
|
|
54911
|
+
}
|
|
54912
|
+
const prints = { ...side.prints ?? {} };
|
|
54913
|
+
const before = printOf(side.prints, id);
|
|
54914
|
+
if (op.print) prints[id] = { set: op.print.set, collectorNumber: op.print.cn };
|
|
54915
|
+
else delete prints[id];
|
|
54916
|
+
return { side: { ...side, prints }, inverse: { op: "print", oracleId: id, print: before } };
|
|
54917
|
+
}
|
|
54918
|
+
var isSideOp = (op) => op.op === "tags" || op.op === "print";
|
|
54164
54919
|
function cardsChanged(ops) {
|
|
54165
|
-
return new Set(ops.map((o) => o.oracleId)).size;
|
|
54920
|
+
return new Set(ops.filter((o) => !isTextOp(o)).map((o) => o.oracleId)).size;
|
|
54166
54921
|
}
|
|
54167
54922
|
function checkDeckOps(stored, ops, ctx, maxCards = MAX_CARDS_PER_EDIT) {
|
|
54168
54923
|
const issues = [];
|
|
@@ -54170,14 +54925,22 @@ function checkDeckOps(stored, ops, ctx, maxCards = MAX_CARDS_PER_EDIT) {
|
|
|
54170
54925
|
issues.push({ index: -1, card: "", reason: `changes ${cardsChanged(ops)} cards; at most ${maxCards} per request` });
|
|
54171
54926
|
}
|
|
54172
54927
|
let s = fromStored(stored);
|
|
54928
|
+
let side = sideOf(stored);
|
|
54173
54929
|
ops.forEach((op, index) => {
|
|
54930
|
+
if (isTextOp(op)) {
|
|
54931
|
+
const problem2 = textProblem(side, op);
|
|
54932
|
+
if (problem2) issues.push({ index, card: TEXT_LABEL[op.field], reason: problem2 });
|
|
54933
|
+
else side = { ...side, text: { ...side.text, [op.field]: cleanDeckText(op.field, op.value) } };
|
|
54934
|
+
return;
|
|
54935
|
+
}
|
|
54174
54936
|
const card = ctx.card(op.oracleId);
|
|
54175
54937
|
if (!card) {
|
|
54176
54938
|
issues.push({ index, card: op.oracleId, reason: "not a card EDHVault knows" });
|
|
54177
54939
|
return;
|
|
54178
54940
|
}
|
|
54179
|
-
const problem = opProblem(s, op, card, ctx);
|
|
54941
|
+
const problem = isSideOp(op) ? sideProblem(s, side, op, card) : opProblem(s, op, card, ctx);
|
|
54180
54942
|
if (problem) issues.push({ index, card: card.name, reason: problem });
|
|
54943
|
+
else if (isSideOp(op)) side = runSide(side, op).side;
|
|
54181
54944
|
else s = run(s, op, card, ctx).state;
|
|
54182
54945
|
});
|
|
54183
54946
|
return issues;
|
|
@@ -54206,6 +54969,12 @@ function opProblem(s, op, card, ctx) {
|
|
|
54206
54969
|
if (at.board === op.to) return `already in ${boardName(op.to)}`;
|
|
54207
54970
|
return op.to === "deck" ? entryProblem(card, 1, ctx.identity) : null;
|
|
54208
54971
|
}
|
|
54972
|
+
case "commanders": {
|
|
54973
|
+
if (op.ids.length < 1 || op.ids.length > 2 || op.ids[0] !== op.oracleId) return "asks for a command zone it can't have";
|
|
54974
|
+
if (op.ids.some((id) => !ctx.card(id))) return "not a card EDHVault knows";
|
|
54975
|
+
const now = s.commanders.map((c) => c.oracleId);
|
|
54976
|
+
return now.length === op.ids.length && now.every((id, i) => id === op.ids[i]) ? "already the commander" : null;
|
|
54977
|
+
}
|
|
54209
54978
|
}
|
|
54210
54979
|
}
|
|
54211
54980
|
function run(s, op, card, ctx) {
|
|
@@ -54254,6 +55023,15 @@ function run(s, op, card, ctx) {
|
|
|
54254
55023
|
enter(op.to, from.board === "deck" ? from.qty : 1);
|
|
54255
55024
|
return { state: s, inverse: { op: "move", oracleId: id, to: from.board } };
|
|
54256
55025
|
}
|
|
55026
|
+
case "commanders": {
|
|
55027
|
+
const before = s.commanders.map((c) => c.oracleId);
|
|
55028
|
+
const refs2 = op.ids.map((oid) => {
|
|
55029
|
+
const c = ctx.card(oid);
|
|
55030
|
+
return { oracleId: oid, name: c.name, colors: c.colors ?? [] };
|
|
55031
|
+
});
|
|
55032
|
+
dispatch({ type: "setCommanders", commanders: refs2 });
|
|
55033
|
+
return { state: s, inverse: before.length ? { op: "commanders", oracleId: before[0], ids: before } : { op: "commanders", oracleId: id, ids: op.ids } };
|
|
55034
|
+
}
|
|
54257
55035
|
}
|
|
54258
55036
|
}
|
|
54259
55037
|
function summarizeDeckOps(ops) {
|
|
@@ -54261,11 +55039,19 @@ function summarizeDeckOps(ops) {
|
|
|
54261
55039
|
const cut = ops.filter((o) => o.op === "remove").length;
|
|
54262
55040
|
const moved = ops.filter((o) => o.op === "move").length;
|
|
54263
55041
|
const counts = ops.filter((o) => o.op === "setQty").length;
|
|
55042
|
+
const tagged = ops.filter((o) => o.op === "tags").length;
|
|
55043
|
+
const printed = ops.filter((o) => o.op === "print").length;
|
|
55044
|
+
const commander = ops.some((o) => o.op === "commanders");
|
|
55045
|
+
const texts = DECK_TEXT_FIELDS.filter((f) => ops.some((o) => o.op === "text" && o.field === f));
|
|
54264
55046
|
return [
|
|
54265
55047
|
add ? `+${add}` : "",
|
|
54266
55048
|
cut ? `\u2212${cut}` : "",
|
|
54267
55049
|
moved ? `${moved} moved` : "",
|
|
54268
|
-
counts ? `${counts} recounted` : ""
|
|
55050
|
+
counts ? `${counts} recounted` : "",
|
|
55051
|
+
tagged ? `${tagged} retagged` : "",
|
|
55052
|
+
printed ? `${printed} new ${printed === 1 ? "printing" : "printings"}` : "",
|
|
55053
|
+
commander ? "new commander" : "",
|
|
55054
|
+
texts.length ? `new ${texts.join(" and ")}` : ""
|
|
54269
55055
|
].filter(Boolean).join(" ") || "no change";
|
|
54270
55056
|
}
|
|
54271
55057
|
|
|
@@ -54288,6 +55074,7 @@ var MAX_NOTE_CHARS = 500;
|
|
|
54288
55074
|
var MAX_CARDS_PER_NEW_DECK = 120;
|
|
54289
55075
|
var MAX_DECKS_PER_MOVE = 50;
|
|
54290
55076
|
var MAX_FOLDER_NAME = 60;
|
|
55077
|
+
var MAX_FROM_NAME = 40;
|
|
54291
55078
|
var NOTE_FIELDS = ["name", "description", "notes", "primer", "tags"];
|
|
54292
55079
|
var NOTES_PART_FIELDS = ["description", "notes", "primer"];
|
|
54293
55080
|
var MAX_LIBRARY_OPS = 100;
|
|
@@ -54329,9 +55116,16 @@ function parseLibraryOps(x, withQty) {
|
|
|
54329
55116
|
}
|
|
54330
55117
|
var SEEN_RE = /^[0-9a-f]{8}$/;
|
|
54331
55118
|
var DECK_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
54332
|
-
function
|
|
55119
|
+
function parseDeckOp(x, live = false) {
|
|
54333
55120
|
if (!x || typeof x !== "object") return null;
|
|
54334
55121
|
const o = x;
|
|
55122
|
+
if (o.op === "text") {
|
|
55123
|
+
if (!live || o.oracleId !== TEXT_OID || typeof o.value !== "string") return null;
|
|
55124
|
+
const field = o.field;
|
|
55125
|
+
if (!DECK_TEXT_FIELDS.includes(field)) return null;
|
|
55126
|
+
const cap2 = field === "notes" ? MAX_NOTES_LENGTH : field === "description" ? MAX_DESCRIPTION_LENGTH : MAX_DECK_NAME_LENGTH;
|
|
55127
|
+
return o.value.length <= cap2 ? { op: "text", oracleId: TEXT_OID, field, value: o.value } : null;
|
|
55128
|
+
}
|
|
54335
55129
|
if (typeof o.oracleId !== "string" || !OID_RE.test(o.oracleId)) return null;
|
|
54336
55130
|
const board = (b) => typeof b === "string" && DECK_BOARDS.includes(b);
|
|
54337
55131
|
const count2 = (n) => Number.isInteger(n) && n >= 1 && n <= MAX_COPIES;
|
|
@@ -54346,13 +55140,30 @@ function parseOp(x) {
|
|
|
54346
55140
|
return count2(o.qty) ? { op: "setQty", oracleId: o.oracleId, qty: o.qty } : null;
|
|
54347
55141
|
case "move":
|
|
54348
55142
|
return board(o.to) ? { op: "move", oracleId: o.oracleId, to: o.to } : null;
|
|
55143
|
+
case "tags": {
|
|
55144
|
+
if (!live || !Array.isArray(o.tags) || o.tags.length > MAX_CARD_TAGS) return null;
|
|
55145
|
+
if (!o.tags.every((t) => typeof t === "string" && t.trim().length > 0 && t.length <= MAX_TAG_NAME)) return null;
|
|
55146
|
+
return { op: "tags", oracleId: o.oracleId, tags: o.tags };
|
|
55147
|
+
}
|
|
55148
|
+
case "print": {
|
|
55149
|
+
if (!live) return null;
|
|
55150
|
+
if (o.print === null) return { op: "print", oracleId: o.oracleId, print: null };
|
|
55151
|
+
const p = o.print;
|
|
55152
|
+
const part2 = (v) => typeof v === "string" && /^[A-Za-z0-9★_-]{1,12}$/.test(v);
|
|
55153
|
+
return p && part2(p.set) && part2(p.cn) ? { op: "print", oracleId: o.oracleId, print: { set: p.set, cn: p.cn } } : null;
|
|
55154
|
+
}
|
|
55155
|
+
case "commanders": {
|
|
55156
|
+
if (!live || !Array.isArray(o.ids) || o.ids.length < 1 || o.ids.length > 2) return null;
|
|
55157
|
+
if (!o.ids.every((id) => typeof id === "string" && OID_RE.test(id)) || o.ids[0] !== o.oracleId) return null;
|
|
55158
|
+
return { op: "commanders", oracleId: o.oracleId, ids: o.ids };
|
|
55159
|
+
}
|
|
54349
55160
|
default:
|
|
54350
55161
|
return null;
|
|
54351
55162
|
}
|
|
54352
55163
|
}
|
|
54353
55164
|
function parseOps(x, max) {
|
|
54354
55165
|
if (!Array.isArray(x) || x.length === 0 || x.length > max * 2) return null;
|
|
54355
|
-
const ops = x.map(
|
|
55166
|
+
const ops = x.map((o) => parseDeckOp(o));
|
|
54356
55167
|
return ops.some((o) => o === null) ? null : ops;
|
|
54357
55168
|
}
|
|
54358
55169
|
var utf8Bytes = (s) => new TextEncoder().encode(s).length;
|
|
@@ -54418,10 +55229,19 @@ function parseRequest(text) {
|
|
|
54418
55229
|
const r = x;
|
|
54419
55230
|
if (r.v !== 1 || !Number.isFinite(r.madeAt)) return null;
|
|
54420
55231
|
if (r.note !== void 0 && (typeof r.note !== "string" || r.note.length > MAX_NOTE_CHARS)) return null;
|
|
55232
|
+
if (r.via !== void 0 && r.via !== "link") return null;
|
|
55233
|
+
let from;
|
|
55234
|
+
if (r.from !== void 0) {
|
|
55235
|
+
const f = r.from;
|
|
55236
|
+
if (!f || typeof f !== "object" || Object.keys(f).some((k) => k !== "name") || typeof f.name !== "string" || f.name.trim().length > MAX_FROM_NAME) return null;
|
|
55237
|
+
if (f.name.trim()) from = { name: f.name.trim() };
|
|
55238
|
+
}
|
|
54421
55239
|
const base = {
|
|
54422
55240
|
v: 1,
|
|
54423
55241
|
...typeof r.note === "string" && r.note.trim() ? { note: r.note.trim() } : {},
|
|
54424
|
-
madeAt: r.madeAt
|
|
55242
|
+
madeAt: r.madeAt,
|
|
55243
|
+
...from ? { from } : {},
|
|
55244
|
+
...r.via === "link" ? { via: "link" } : {}
|
|
54425
55245
|
};
|
|
54426
55246
|
const deck = () => typeof r.deckId === "string" && DECK_ID_RE.test(r.deckId) && Number.isFinite(r.basedOn) && (r.seen === void 0 || typeof r.seen === "string" && SEEN_RE.test(r.seen));
|
|
54427
55247
|
const seen = typeof r.seen === "string" ? { seen: r.seen } : {};
|
|
@@ -55326,6 +56146,19 @@ function addedUnits(clause) {
|
|
|
55326
56146
|
if (/\ban amount of mana\b/.test(clause)) return [ANY];
|
|
55327
56147
|
return [];
|
|
55328
56148
|
}
|
|
56149
|
+
function loyaltyMana(self2) {
|
|
56150
|
+
for (const l of self2.split("\n")) {
|
|
56151
|
+
const m = l.match(/^(?:\+\d+|0): add ([^.]*)(?:\.|$)(.*)$/);
|
|
56152
|
+
if (!m) continue;
|
|
56153
|
+
const [, clause, rest] = m;
|
|
56154
|
+
const symbols = /^(?:\{[wubrgc]\})+$/.test(clause);
|
|
56155
|
+
const wider = /^\{[wubrgc]\}(?:(?:, | or |, or )\{[wubrgc]\})+$/.test(clause) || /^(?:one|two|three) mana (?:of any color|in any combination of colors)$/.test(clause);
|
|
56156
|
+
if (!symbols && !(wider && !/spend this mana only/.test(rest))) continue;
|
|
56157
|
+
const u = addedUnits(clause);
|
|
56158
|
+
if (u.length) return u;
|
|
56159
|
+
}
|
|
56160
|
+
return null;
|
|
56161
|
+
}
|
|
55329
56162
|
function tapAddUnits(text) {
|
|
55330
56163
|
let best = [];
|
|
55331
56164
|
for (const line of text.split("\n")) {
|
|
@@ -55351,19 +56184,19 @@ function manaProfile(card, oracleText) {
|
|
|
55351
56184
|
const costs = (card.manaCost ?? "").split(" // ");
|
|
55352
56185
|
if (costs.length > 1 && (card.layout === "adventure" || card.layout === "split" || card.layout === "prepare")) {
|
|
55353
56186
|
const first = parseCost(costs[0]);
|
|
55354
|
-
const
|
|
56187
|
+
const front2 = { ...card, manaCost: costs[0], cmc: first.generic + pipValue(first.pips) + (first.phyrexian ?? 0) };
|
|
55355
56188
|
if (card.layout === "adventure") {
|
|
55356
56189
|
const faces3 = preparedFaces(card.name, oracleText ?? "");
|
|
55357
56190
|
const types2 = card.typeLine.split("//");
|
|
55358
|
-
if (!faces3.spell || types2.length < 2) return readProfile(
|
|
56191
|
+
if (!faces3.spell || types2.length < 2) return readProfile(front2, oracleText);
|
|
55359
56192
|
const second2 = parseCost(costs[1]);
|
|
55360
56193
|
const spell2 = readProfile(
|
|
55361
56194
|
{ ...card, typeLine: types2[1].trim(), manaCost: costs[1], cmc: second2.generic + pipValue(second2.pips) + (second2.phyrexian ?? 0), layout: void 0 },
|
|
55362
56195
|
faces3.spell
|
|
55363
56196
|
);
|
|
55364
|
-
return { ...readProfile({ ...
|
|
56197
|
+
return { ...readProfile({ ...front2, typeLine: types2[0].trim() }, faces3.creature), spellSide: spell2 };
|
|
55365
56198
|
}
|
|
55366
|
-
if (card.layout !== "prepare") return readProfile(
|
|
56199
|
+
if (card.layout !== "prepare") return readProfile(front2, oracleText);
|
|
55367
56200
|
const faces2 = preparedFaces(card.name, oracleText ?? "");
|
|
55368
56201
|
const types = card.typeLine.split("//");
|
|
55369
56202
|
const second = parseCost(costs[1]);
|
|
@@ -55371,7 +56204,7 @@ function manaProfile(card, oracleText) {
|
|
|
55371
56204
|
{ ...card, typeLine: (types[1] ?? "").trim(), manaCost: costs[1], cmc: second.generic + pipValue(second.pips) + (second.phyrexian ?? 0), layout: void 0 },
|
|
55372
56205
|
faces2.spell
|
|
55373
56206
|
);
|
|
55374
|
-
const creature = readProfile({ ...
|
|
56207
|
+
const creature = readProfile({ ...front2, typeLine: types[0].trim() }, faces2.creature);
|
|
55375
56208
|
return { ...creature, spellSide: spell, prepared: /\benters prepared\b/.test(faces2.creature.toLowerCase()) ? "enters" : "condition" };
|
|
55376
56209
|
}
|
|
55377
56210
|
const p = withNonPlain(withConvert(readProfile(card, oracleText), oracleText ?? ""), oracleText ?? "");
|
|
@@ -55603,7 +56436,7 @@ function readPaidDraw(self2, planeswalker = false) {
|
|
|
55603
56436
|
for (const raw of self2.split("\n")) {
|
|
55604
56437
|
const l = raw.trim().replace(/^[a-z][a-z' -]* — /, "");
|
|
55605
56438
|
const loyalty = planeswalker && /^\+?\d+: /.test(l);
|
|
55606
|
-
if (loyalty &&
|
|
56439
|
+
if (loyalty && loyaltyMana(self2)) continue;
|
|
55607
56440
|
if (!ACTIVATED.test(l) && !loyalty) continue;
|
|
55608
56441
|
const at = l.indexOf(": ");
|
|
55609
56442
|
if (at < 0) continue;
|
|
@@ -56545,8 +57378,8 @@ function readProfile(card, oracleText) {
|
|
|
56545
57378
|
const on = text.match(/(?:^|\n)enchant (land|forest|island|swamp|mountain|plains)\b/);
|
|
56546
57379
|
return done({ ...base, makes: u.length ? u : [ANY], ...on ? { enchantLand: on[1] === "land" ? "land" : on[1][0].toUpperCase() + on[1].slice(1) } : {} });
|
|
56547
57380
|
}
|
|
56548
|
-
const
|
|
56549
|
-
const own2 = creature && /\bcreatures? you control\b[^"\n]*\bha(?:s|ve) "/.test(
|
|
57381
|
+
const front2 = flips ? text.split(/\n\(transforms from [^)]*\)/)[0] : text;
|
|
57382
|
+
const own2 = creature && /\bcreatures? you control\b[^"\n]*\bha(?:s|ve) "/.test(front2) ? front2 : front2.replace(/"[^"]*"/g, "");
|
|
56550
57383
|
const sure = tapAddUnits(own2.split("\n").filter((l) => !/activate only if/.test(l)).join("\n"));
|
|
56551
57384
|
const units = sure.length ? sure : tapAddUnits(own2);
|
|
56552
57385
|
const limited = units.length ? null : readLimitedMana(own2, card, creature);
|
|
@@ -56575,11 +57408,8 @@ function readProfile(card, oracleText) {
|
|
|
56575
57408
|
if (once.length) return done({ ...base, ritualMakes: once, discardsHand: true });
|
|
56576
57409
|
}
|
|
56577
57410
|
const tapOther = units.length ? null : own2.match(/(?:^|\n)(?:tap an untapped [^:{}\n]* you control|\{0\}): add ([^.]*)/);
|
|
56578
|
-
const loyalMana = units.length || !/\bplaneswalker\b/.test(type) ? null : own2
|
|
56579
|
-
if (loyalMana) {
|
|
56580
|
-
const u = addedUnits(loyalMana[1]);
|
|
56581
|
-
if (u.length) return done({ ...base, makes: u, summoningSick: false });
|
|
56582
|
-
}
|
|
57411
|
+
const loyalMana = units.length || !/\bplaneswalker\b/.test(type) ? null : loyaltyMana(own2);
|
|
57412
|
+
if (loyalMana) return done({ ...base, makes: loyalMana, summoningSick: false });
|
|
56583
57413
|
if (tapOther) {
|
|
56584
57414
|
const u0 = addedUnits(tapOther[1]);
|
|
56585
57415
|
const floor = manaFloor(card, own2);
|
|
@@ -56600,7 +57430,7 @@ function readProfile(card, oracleText) {
|
|
|
56600
57430
|
/^[^:]*\bsacrifice a food\b[^:]*:[^\n]*\badd\b/.test(l) || /\{t\}[^:]*:[^\n]*\btarget\b[^\n]*\badd\b/.test(l)
|
|
56601
57431
|
)
|
|
56602
57432
|
);
|
|
56603
|
-
const floor = varies ? manaFloor(card,
|
|
57433
|
+
const floor = varies ? manaFloor(card, front2) : null;
|
|
56604
57434
|
const sure2 = floor === null ? units : floor === 0 ? [] : Array.from({ length: floor }, () => units[0]);
|
|
56605
57435
|
return done({ ...base, makes: sure2, summoningSick: creature && !base.haste || /enters tapped/.test(text), ...varies ? { manaVaries: true } : {} });
|
|
56606
57436
|
}
|
|
@@ -57268,11 +58098,11 @@ function chosenFinds(finds, deck) {
|
|
|
57268
58098
|
const count2 = /* @__PURE__ */ new Map();
|
|
57269
58099
|
const add = (k) => count2.set(k, (count2.get(k) ?? 0) + 1);
|
|
57270
58100
|
for (const c of deck) {
|
|
57271
|
-
const
|
|
57272
|
-
if (/\bland\b/.test(
|
|
58101
|
+
const front2 = c.typeLine.split(" // ")[0].toLowerCase();
|
|
58102
|
+
if (/\bland\b/.test(front2)) continue;
|
|
57273
58103
|
if (/@subtype\b/.test(f)) {
|
|
57274
|
-
if (/\bcreature\b/.test(
|
|
57275
|
-
} else for (const t of CHOSEN_TYPES) if (new RegExp(`\\b${t}\\b`).test(
|
|
58104
|
+
if (/\bcreature\b/.test(front2)) for (const t of typesOf(c).types ?? []) add(t);
|
|
58105
|
+
} else for (const t of CHOSEN_TYPES) if (new RegExp(`\\b${t}\\b`).test(front2)) add(t);
|
|
57276
58106
|
}
|
|
57277
58107
|
const top = [...count2].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
57278
58108
|
return f.replace(/@(?:sub)?type\b/, top ? `t:${top}` : "t:none-chosen").trim();
|
|
@@ -62410,7 +63240,7 @@ var ASSUMPTION_LABEL = {
|
|
|
62410
63240
|
},
|
|
62411
63241
|
exilesFirst: {
|
|
62412
63242
|
title: "Tutors that exile your top cards first, counted with the risk",
|
|
62413
|
-
hint: "Demonic Bargain exiles your top 13 before it searches, Demonic Consultation your top 6: the card you want can be among them. We play it as the card says: then it finds another of the
|
|
63243
|
+
hint: "Demonic Bargain exiles your top 13 before it searches, Demonic Consultation your top 6: the card you want can be among them. We play it as the card says: then it finds another of the step's cards, or nothing."
|
|
62414
63244
|
},
|
|
62415
63245
|
reanimate: {
|
|
62416
63246
|
title: "Reanimation we don't read, not counted",
|
|
@@ -62531,7 +63361,7 @@ function planAssumptions(args) {
|
|
|
62531
63361
|
const t = raw.replace(/\([^)]*\)/g, "");
|
|
62532
63362
|
const unread = (p2.castTriggers ? withoutCastTriggers(t) : t).split("\n").filter((l) => !(p2.diesDraw && diesDrawsOf(selfRef(c.name, l))) && !(p2.sacDraw && SAC_DRAW.test(selfRef(c.name, l).trim())) && !(p2.enterDraw && enterDrawOf(l)) && !(p2.paidDraw?.sacSelf && LEAVES_DRAW.test(selfRef(c.name, l).trim())) && !(p2.paidDraw?.sacCreature && /^\s*whenever equipped creature dies, (?:you )?draw\b/.test(l))).join("\n");
|
|
62533
63363
|
const sides = raw.split(/\n\(transforms from [^)]*\)/);
|
|
62534
|
-
const
|
|
63364
|
+
const front2 = sides[0].replace(/\([^)]*\)/g, "");
|
|
62535
63365
|
const backTreasure = sides.length > 1 && TREASURE2.test(sides.slice(1).join("\n"));
|
|
62536
63366
|
const abilityDraw = t.replace(/\n(?=\s*(?:[•·]|\+ ))/g, " ").split("\n").flatMap((l) => [l, ...(l.match(/"[^"]*"/g) ?? []).map((q) => q.slice(1, -1))]).some((l) => ACTIVATED.test(l) && /:[^\n]*(?:\bdraws? (?:a|one|two|three|four|five|six|seven|\d+|x|that many) cards?|\bdraws? cards equal to\b|\btop card of your library\b[^\n]*\binto your hand|\bput (?:one|two|a card) of (?:them|those cards) into your hand|\bconnives?\b)/.test(l.replace(/"[^"]*"/g, "")) || // A Class's level is bought (Wizard Class: "when this class becomes level 2, draw two").
|
|
62537
63367
|
/^\s*when this class becomes level \d+, [^\n]*\bdraws?\b/.test(l));
|
|
@@ -62580,7 +63410,7 @@ function planAssumptions(args) {
|
|
|
62580
63410
|
!p2.paidTreasure && !p2.diesTreasures && // (A death watcher's Treasure: Pitiless Plunderer.)
|
|
62581
63411
|
!p2.diesDraw?.some((d) => d.treasures) && // (Academy Manufactor's "a clue, food, or treasure token": read.)
|
|
62582
63412
|
!p2.tokenTriple && // (A cast trigger's Treasure: Storm-Kiln Artist's magecraft.)
|
|
62583
|
-
!p2.castTriggers?.some((x) => x.treasures) && TREASURE2.test(
|
|
63413
|
+
!p2.castTriggers?.some((x) => x.treasures) && TREASURE2.test(front2) || // A land token (Overlord of the Hauntwoods' "Everywhere") taps for mana.
|
|
62584
63414
|
/\bcreates? [^.\n]*\bland tokens?\b/.test(t) || // Its own entry is read, the rest is a trigger (Ganax: "or another dragon ... enters").
|
|
62585
63415
|
!!p2.treasures && /\bor another\b[^,\n]*\benters, create\b[^.\n]*\btreasure\b/.test(t))
|
|
62586
63416
|
add("manaTokens");
|
|
@@ -62907,18 +63737,18 @@ function savedPlanGame(saved) {
|
|
|
62907
63737
|
};
|
|
62908
63738
|
}
|
|
62909
63739
|
var MISS_LABEL = {
|
|
62910
|
-
notDrawn: { text: "
|
|
63740
|
+
notDrawn: { text: "never found it", hint: "You never had enough of these cards, and no tutor for them." },
|
|
62911
63741
|
tutorUnpaid: {
|
|
62912
|
-
text: "
|
|
63742
|
+
text: "had a tutor, not the mana",
|
|
62913
63743
|
hint: "You held a tutor that could get one, but couldn't pay for it (and the card) in time."
|
|
62914
63744
|
},
|
|
62915
63745
|
tutorUnusable: {
|
|
62916
|
-
text: "
|
|
62917
|
-
hint: `You held a tutor that could get one, but its search is a trigger
|
|
63746
|
+
text: "had a tutor these games can't use",
|
|
63747
|
+
hint: `You held a tutor that could get one, but its search is a trigger these games don't play from your hand (a "whenever you cast" search, a land's trigger), so it was never used.`
|
|
62918
63748
|
},
|
|
62919
|
-
noColor: { text: "
|
|
63749
|
+
noColor: { text: "wrong colors", hint: "You had the cards and the mana, not of the colors they need." },
|
|
62920
63750
|
landDrop: { text: "missed a land drop", hint: "You had the cards, not enough mana, and missed a land drop." },
|
|
62921
|
-
noMana: { text: "
|
|
63751
|
+
noMana: { text: "not enough mana", hint: "You had the cards and made every land drop, still not enough mana." },
|
|
62922
63752
|
countShort: { text: "fell short", hint: "The count never reached your number by that turn." }
|
|
62923
63753
|
};
|
|
62924
63754
|
function tutorReadQuery(a) {
|
|
@@ -63116,7 +63946,7 @@ function oddsPct(p) {
|
|
|
63116
63946
|
|
|
63117
63947
|
// ../src/lib/deckPlan/oddsFormat.ts
|
|
63118
63948
|
function levelMeaning(games) {
|
|
63119
|
-
return `
|
|
63949
|
+
return `Out of ${games.toLocaleString("en-US")} practice games played alone with simple choices. Good for comparing two builds. A careful player can do better.`;
|
|
63120
63950
|
}
|
|
63121
63951
|
function headlinePct(p, games) {
|
|
63122
63952
|
const { lead, value, tail } = headlineParts(p, games);
|
|
@@ -63774,9 +64604,9 @@ function neverUsedLabel(reason, lastTurn) {
|
|
|
63774
64604
|
case "ignored":
|
|
63775
64605
|
return { title: "Set not to count", hint: "You set these not to count." };
|
|
63776
64606
|
case "tableGuess":
|
|
63777
|
-
return { title: "
|
|
64607
|
+
return { title: "Waits on other players, set a guess", hint: "What they give comes from the other players, and your guess for that is 0 a round. Set your guess in the card." };
|
|
63778
64608
|
case "planAsks":
|
|
63779
|
-
return { title: "
|
|
64609
|
+
return { title: "No step asks for it", hint: "A tutor: a game casts one to find a card a step asks for, and no step asks for one it can find." };
|
|
63780
64610
|
case "bonus":
|
|
63781
64611
|
return { title: "Interaction with a bonus", hint: "Its draw or mana isn't counted, because goldfish games have nothing to target." };
|
|
63782
64612
|
case "notModeled":
|
|
@@ -64570,7 +65400,7 @@ var planOdds = {
|
|
|
64570
65400
|
mulligans: external_exports.number().int().min(0).max(3).optional().describe("Mulligans you'd take for this plan."),
|
|
64571
65401
|
countTutors: external_exports.boolean().optional().describe("Let tutors fetch missing pieces (default yes)."),
|
|
64572
65402
|
opponents: external_exports.number().int().min(1).max(9).optional().describe("Opponents at the table."),
|
|
64573
|
-
keepLands: external_exports.
|
|
65403
|
+
keepLands: external_exports.array(external_exports.number().int().min(0).max(7)).length(2).optional().describe("Keep a 7 with this many lands, [min, max] (default [2, 5])."),
|
|
64574
65404
|
need: external_exports.number().int().min(1).optional().describe("How many rows must come together in the same game (default: all of them)."),
|
|
64575
65405
|
table: external_exports.record(external_exports.string(), external_exports.record(external_exports.string(), external_exports.unknown())).optional().describe("What the other players give you, by card name, for this run: drawsPerRound / treasuresPerRound, each [{ from: turn, cards: n }] (Rhystic Study, Smothering Tithe). Replaces the plan's saved table guesses."),
|
|
64576
65406
|
careful: external_exports.boolean().optional().describe("The Odds tab's careful play: tries several lines each turn (land drop, what to cast first) on reshuffles of the cards not yet seen, instead of plain play. Uses our card reads. 300 games here, so it gives a range; far slower (tens of seconds)."),
|
|
@@ -64624,9 +65454,9 @@ function changes(windows) {
|
|
|
64624
65454
|
}
|
|
64625
65455
|
return out;
|
|
64626
65456
|
}
|
|
64627
|
-
function printingChanges(file4, set3, number4,
|
|
65457
|
+
function printingChanges(file4, set3, number4, usd2, foil) {
|
|
64628
65458
|
const out = {};
|
|
64629
|
-
for (const [isFoil, now] of [[false,
|
|
65459
|
+
for (const [isFoil, now] of [[false, usd2], [true, foil]]) {
|
|
64630
65460
|
const w = printingTrendWindows(file4, set3, number4, isFoil, now ?? void 0);
|
|
64631
65461
|
for (const k of TREND_WINDOWS) {
|
|
64632
65462
|
const d = w[k]?.delta;
|
|
@@ -64651,9 +65481,11 @@ async function part(missing, what, load) {
|
|
|
64651
65481
|
}
|
|
64652
65482
|
var cardTool = {
|
|
64653
65483
|
name: "get_card",
|
|
64654
|
-
description: "Everything EDHVault knows about one card: printed rules text (every face), legality in every format, EDHREC rank, Game Changer, roles and every Scryfall tag, today's price and its 1/7/30-day change, every printing with its prices, its land cycle, the combos it's in, and (with an access code) what the user owns of it and which decks use it. `comboSteps` adds how each combo works (the first time, a ~57 MB download). Needs no access code.",
|
|
65484
|
+
description: "Everything EDHVault knows about one card: printed rules text (every face), legality in every format, EDHREC rank, Game Changer, roles and every Scryfall tag, today's price and its 1/7/30-day change, every printing with its prices, each shop's own price (Card Kingdom, Cardmarket, Mana Pool, TCGplayer) for one printing, its land cycle, the combos it's in, and (with an access code) what the user owns of it and which decks use it. `comboSteps` adds how each combo works (the first time, a ~57 MB download). `priceHistory` adds the printing's daily TCGplayer price since July 2026. Shop prices and the history are for `printing`, else the cheapest listed one. Needs no access code.",
|
|
64655
65485
|
input: {
|
|
64656
65486
|
name: external_exports.string().min(1).describe("The card's name."),
|
|
65487
|
+
printing: external_exports.string().optional().describe('The printing for shop prices and the price history: set code and collector number, like "fdc 286". Default: the cheapest listed.'),
|
|
65488
|
+
priceHistory: external_exports.boolean().optional().describe("Add the printing's price history: each day it changed, the low and the high."),
|
|
64657
65489
|
detail: detailInput,
|
|
64658
65490
|
comboSteps: external_exports.boolean().optional().describe("Add each combo's steps, mana needed and notes."),
|
|
64659
65491
|
refresh: refreshInput
|
|
@@ -64684,11 +65516,11 @@ var cardTool = {
|
|
|
64684
65516
|
const stepsWereOnDisk = x?.comboStepsOnDisk() ?? false;
|
|
64685
65517
|
const steps = args.comboSteps === true && combos ? await part(missing, "combo steps", x?.comboDetail) : null;
|
|
64686
65518
|
const printed = cardText ? decodeCardText(cardText.text[c.oracleId]) : null;
|
|
64687
|
-
const
|
|
65519
|
+
const front2 = {
|
|
64688
65520
|
...c.power != null ? { power: c.power, toughness: c.toughness } : {},
|
|
64689
65521
|
...c.loyalty != null ? { loyalty: c.loyalty } : {}
|
|
64690
65522
|
};
|
|
64691
|
-
const wording = cardText ? printed && "faces" in printed ? printed : { ...printed ? { text: printed.text } : {}, ...
|
|
65523
|
+
const wording = cardText ? printed && "faces" in printed ? printed : { ...printed ? { text: printed.text } : {}, ...front2 } : { text: catalog.oracle(c.oracleId), textNote: "EDHVault's search copy of the rules text: lowercase, reminder text inline.", ...front2 };
|
|
64692
65524
|
const code = cardText?.legal[c.oracleId];
|
|
64693
65525
|
let formats;
|
|
64694
65526
|
if (cardText && code) {
|
|
@@ -64720,6 +65552,12 @@ var cardTool = {
|
|
|
64720
65552
|
const priced = all.filter((p) => p.priceUsd != null).sort((a, b) => a.priceUsd - b.priceUsd);
|
|
64721
65553
|
const cheapest = priced[0];
|
|
64722
65554
|
const cycle = cycles?.find((cy) => cy.members.some((m) => m.oracleId === c.oracleId));
|
|
65555
|
+
const ph = ctx.priceHistory;
|
|
65556
|
+
const pick2 = pickPrinting(all, args.printing);
|
|
65557
|
+
const [shops, history] = await Promise.all([
|
|
65558
|
+
ph && pick2 ? part(missing, "shop prices", () => shopPrices(ph, pick2)) : null,
|
|
65559
|
+
ph && pick2 && args.priceHistory === true ? part(missing, "the price history", () => printingHistory(ph, pick2, detail)) : null
|
|
65560
|
+
]);
|
|
64723
65561
|
let comboList = null;
|
|
64724
65562
|
if (combos) {
|
|
64725
65563
|
const r = buildCardComboResults(combos.index, c.oracleId, /* @__PURE__ */ new Set(), (oid) => catalog.index.byOracleId.get(oid), steps ?? void 0);
|
|
@@ -64775,6 +65613,8 @@ var cardTool = {
|
|
|
64775
65613
|
...all.length > printingRows.length ? { more: all.length - printingRows.length } : {}
|
|
64776
65614
|
}
|
|
64777
65615
|
} : {},
|
|
65616
|
+
...shops ? { shops } : {},
|
|
65617
|
+
...history ? { priceHistory: history } : {},
|
|
64778
65618
|
...cycle ? {
|
|
64779
65619
|
landCycle: {
|
|
64780
65620
|
name: cycle.displayName,
|
|
@@ -65797,7 +66637,7 @@ var editDeckTool = {
|
|
|
65797
66637
|
deck: viewDeck(id, stored, null).name,
|
|
65798
66638
|
summary: summarizeDeckOps(ops),
|
|
65799
66639
|
changes: ops.map(
|
|
65800
|
-
(o) => o.op === "add" ? `+ ${name(o.oracleId)}${o.qty && o.qty > 1 ? ` x${o.qty}` : ""}${o.to && o.to !== "deck" ? ` (to ${o.to})` : ""}` : o.op === "remove" ? `- ${name(o.oracleId)}` : o.op === "setQty" ? `${name(o.oracleId)}: ${o.qty} copies` : `${name(o.oracleId)} to ${o.to}`
|
|
66640
|
+
(o) => o.op === "add" ? `+ ${name(o.oracleId)}${o.qty && o.qty > 1 ? ` x${o.qty}` : ""}${o.to && o.to !== "deck" ? ` (to ${o.to})` : ""}` : o.op === "remove" ? `- ${name(o.oracleId)}` : o.op === "setQty" ? `${name(o.oracleId)}: ${o.qty} copies` : o.op === "move" ? `${name(o.oracleId)} to ${o.to}` : o.op === "tags" ? `${name(o.oracleId)}: tags ${o.tags.join(", ") || "none"}` : o.op === "print" ? `${name(o.oracleId)}: ${o.print ? `printing ${o.print.set.toUpperCase()} ${o.print.cn}` : "default printing"}` : o.op === "commanders" ? `commander: ${o.ids.map(name).join(" + ")}` : `${o.field}: ${o.value}`
|
|
65801
66641
|
),
|
|
65802
66642
|
expires: new Date(r.expiresAt).toISOString().slice(0, 10),
|
|
65803
66643
|
about: PENDING_ABOUT
|
|
@@ -66156,10 +66996,235 @@ var getRequestsTool = {
|
|
|
66156
66996
|
});
|
|
66157
66997
|
}
|
|
66158
66998
|
};
|
|
66159
|
-
var
|
|
66999
|
+
var PRICE_HISTORY_CREDIT = `Price history: ${HISTORY_SOURCE}, as EDHVault keeps it.`;
|
|
67000
|
+
var FINISH_WORD = { n: "regular", f: "foil", e: "etched" };
|
|
67001
|
+
var usd = (cents2) => Math.round(cents2) / 100;
|
|
67002
|
+
function shopAmount(cents2, cur) {
|
|
67003
|
+
const n = (cents2 / 100).toFixed(2);
|
|
67004
|
+
if (!cur || cur === "USD") return `$${n}`;
|
|
67005
|
+
if (cur === "EUR") return `\u20AC${n}`;
|
|
67006
|
+
return `${n} ${cur}`;
|
|
67007
|
+
}
|
|
67008
|
+
function pickPrinting(all, asked) {
|
|
67009
|
+
const label = (p2) => `${p2.setName ? `${p2.setName} ` : ""}(${p2.set} ${p2.collectorNumber})`;
|
|
67010
|
+
if (typeof asked === "string" && asked.trim()) {
|
|
67011
|
+
const m = asked.trim().toLowerCase().match(/^([a-z0-9]{2,8})[\s#:/-]+([^\s]+)$/);
|
|
67012
|
+
if (!m) throw new ToolProblem(`printing is a set code and collector number, like "fdc 286". Got "${asked}".`);
|
|
67013
|
+
const hit = all.find((p2) => p2.set.toLowerCase() === m[1] && p2.collectorNumber.toLowerCase() === m[2]);
|
|
67014
|
+
return hit ? { set: hit.set.toLowerCase(), number: hit.collectorNumber, label: label(hit) } : { set: m[1], number: m[2], label: `(${m[1]} ${m[2]})` };
|
|
67015
|
+
}
|
|
67016
|
+
const priced = all.filter((p2) => p2.priceUsd != null).sort((a, b) => a.priceUsd - b.priceUsd);
|
|
67017
|
+
const p = priced[0] ?? all[0];
|
|
67018
|
+
return p ? { set: p.set.toLowerCase(), number: p.collectorNumber, label: label(p) } : null;
|
|
67019
|
+
}
|
|
67020
|
+
async function shopPrices(ph, p) {
|
|
67021
|
+
const file4 = await ph.vendorSet(p.set);
|
|
67022
|
+
const row = file4?.p[p.number];
|
|
67023
|
+
if (!file4 || !row) return { printing: p.label, none: "No shop prices for this printing (MTGJSON lists none for it, or its set)." };
|
|
67024
|
+
const prices = {};
|
|
67025
|
+
for (const v of VENDORS) {
|
|
67026
|
+
const by = row[v.id];
|
|
67027
|
+
if (!by) continue;
|
|
67028
|
+
const out = {};
|
|
67029
|
+
for (const f of FINISHES) if (by[f] != null) out[FINISH_WORD[f]] = shopAmount(by[f], file4.cur[v.id]);
|
|
67030
|
+
if (Object.keys(out).length) prices[v.name] = out;
|
|
67031
|
+
}
|
|
67032
|
+
return { printing: p.label, asOf: file4.day, prices, credit: `Shop prices from ${VENDOR_PRICES_SOURCE}, ${file4.day}.` };
|
|
67033
|
+
}
|
|
67034
|
+
async function printingHistory(ph, p, detail) {
|
|
67035
|
+
const manifest = await ph.manifest();
|
|
67036
|
+
const files = (await ph.setFiles([p.set])).sort((a, b) => a.start - b.start);
|
|
67037
|
+
const finishes = {};
|
|
67038
|
+
for (const f of FINISHES) {
|
|
67039
|
+
const changes2 = [];
|
|
67040
|
+
let last;
|
|
67041
|
+
for (const file4 of files) {
|
|
67042
|
+
const rec = file4.p[p.number]?.[f];
|
|
67043
|
+
if (!rec) continue;
|
|
67044
|
+
const daily = decodeSeries(rec, file4.end - file4.start + 1);
|
|
67045
|
+
daily.forEach((cents2, i) => {
|
|
67046
|
+
if (cents2 === last) return;
|
|
67047
|
+
last = cents2;
|
|
67048
|
+
changes2.push([dayToDate(file4.start + i), cents2 == null ? null : usd(cents2)]);
|
|
67049
|
+
});
|
|
67050
|
+
}
|
|
67051
|
+
const priced = changes2.filter((c) => c[1] != null);
|
|
67052
|
+
if (!priced.length) continue;
|
|
67053
|
+
const lo = priced.reduce((a, b) => b[1] < a[1] ? b : a);
|
|
67054
|
+
const hi = priced.reduce((a, b) => b[1] > a[1] ? b : a);
|
|
67055
|
+
const cap2 = { summary: 40, standard: 120, full: Infinity }[detail];
|
|
67056
|
+
finishes[FINISH_WORD[f]] = {
|
|
67057
|
+
first: { date: priced[0][0], usd: priced[0][1] },
|
|
67058
|
+
// The newest price, and the day it last changed to it.
|
|
67059
|
+
current: { usd: priced[priced.length - 1][1], since: priced[priced.length - 1][0] },
|
|
67060
|
+
low: { date: lo[0], usd: lo[1] },
|
|
67061
|
+
high: { date: hi[0], usd: hi[1] },
|
|
67062
|
+
// Each day the price changed, and what to; a null is a day with no price.
|
|
67063
|
+
changes: changes2.slice(-cap2),
|
|
67064
|
+
...changes2.length > cap2 ? { earlierChanges: changes2.length - cap2, more: "Ask with detail: full for every change." } : {}
|
|
67065
|
+
};
|
|
67066
|
+
}
|
|
67067
|
+
if (!Object.keys(finishes).length) return { printing: p.label, none: "This printing isn't in the price history." };
|
|
67068
|
+
const special = files.some((f) => f.af?.includes(p.number));
|
|
67069
|
+
return {
|
|
67070
|
+
printing: p.label,
|
|
67071
|
+
from: manifest.from,
|
|
67072
|
+
asOf: manifest.asOf,
|
|
67073
|
+
...finishes,
|
|
67074
|
+
...special ? { foilNote: "TCGplayer also sells a special foil of this printing; the foil line here is its regular foil." } : {},
|
|
67075
|
+
credit: PRICE_HISTORY_CREDIT
|
|
67076
|
+
};
|
|
67077
|
+
}
|
|
67078
|
+
var VALUE_RANGES = ["30", "90", "all"];
|
|
67079
|
+
var collectionValueTool = {
|
|
67080
|
+
name: "collection_value",
|
|
67081
|
+
description: "The collection's value over time, as the Collection page's value section shows it: the value of the cards the user owns NOW on each past day, at that day's TCGplayer market price (via MTGJSON). Gives the change over the range, the high and low, the biggest gainers and losers, and how many copies the history prices. Our reading: it isn't a record of what the user owned then. Needs an access code that can read the collection.",
|
|
67082
|
+
input: {
|
|
67083
|
+
range: external_exports.enum(VALUE_RANGES).optional().describe("30 or 90 days, or all the history (default 90)."),
|
|
67084
|
+
movers: external_exports.number().int().min(0).max(50).optional().describe("Gainers and losers to list (default 10)."),
|
|
67085
|
+
detail: external_exports.enum(DETAILS).optional().describe("summary (default: a value per week), standard (every 3 days), or full (every day)."),
|
|
67086
|
+
refresh: refreshInput
|
|
67087
|
+
},
|
|
67088
|
+
async run(args, ctx) {
|
|
67089
|
+
const ph = ctx.priceHistory;
|
|
67090
|
+
if (!ph) throw new ToolProblem("The price history isn't available in this setup.");
|
|
67091
|
+
const stacks = await ctx.library.collection(args.refresh === true);
|
|
67092
|
+
const owned = stacks.filter((s) => s.set && s.collectorNumber && s.quantity > 0).map((s) => ({ set: s.set.toLowerCase(), collectorNumber: s.collectorNumber, foil: !!s.foil, quantity: s.quantity, name: s.name }));
|
|
67093
|
+
const noPrinting = stacks.filter((s) => !(s.set && s.collectorNumber)).reduce((n2, s) => n2 + s.quantity, 0);
|
|
67094
|
+
if (!owned.length) {
|
|
67095
|
+
return json2({ copies: 0, note: noPrinting ? "None of the collection's cards name a printing (set and number), and the history prices printings." : "The collection is empty." });
|
|
67096
|
+
}
|
|
67097
|
+
const manifest = await ph.manifest();
|
|
67098
|
+
const to = epochDay(manifest.asOf);
|
|
67099
|
+
const first = epochDay(manifest.from);
|
|
67100
|
+
const range = VALUE_RANGES.includes(args.range) ? args.range : "90";
|
|
67101
|
+
const from = range === "all" ? first : Math.max(first, to - Number(range) + 1);
|
|
67102
|
+
const files = await ph.setFiles(ownedSets(owned), monthOf(from));
|
|
67103
|
+
const h = computeValueHistory(owned, files, from, to);
|
|
67104
|
+
const points = h.points;
|
|
67105
|
+
const start = points.find((p) => p.cents > 0) ?? points[0];
|
|
67106
|
+
const end = points[points.length - 1];
|
|
67107
|
+
let hi = points[0];
|
|
67108
|
+
let lo = points[0];
|
|
67109
|
+
for (const p of points) {
|
|
67110
|
+
if (p.cents > hi.cents) hi = p;
|
|
67111
|
+
if (p.cents > 0 && (lo.cents === 0 || p.cents < lo.cents)) lo = p;
|
|
67112
|
+
}
|
|
67113
|
+
const n = typeof args.movers === "number" ? args.movers : 10;
|
|
67114
|
+
const move = (m) => ({
|
|
67115
|
+
card: m.printing.name,
|
|
67116
|
+
printing: `${m.printing.set} ${m.printing.collectorNumber}${m.finish !== "n" ? ` ${FINISH_WORD[m.finish]}` : ""}`,
|
|
67117
|
+
copies: m.printing.quantity,
|
|
67118
|
+
each: `$${usd(m.fromCents)} \u2192 $${usd(m.toCents)}`,
|
|
67119
|
+
change: usd(m.deltaCents)
|
|
67120
|
+
});
|
|
67121
|
+
const detail = detailOf(args);
|
|
67122
|
+
const step = { summary: 7, standard: 3, full: 1 }[detail];
|
|
67123
|
+
const series = points.filter((_, i) => (points.length - 1 - i) % step === 0).map((p) => [dayToDate(p.day), usd(p.cents)]);
|
|
67124
|
+
const standIns = manifest.fallbackDays.filter((d) => epochDay(d) >= from && epochDay(d) <= to);
|
|
67125
|
+
const delta = end.cents - start.cents;
|
|
67126
|
+
return json2({
|
|
67127
|
+
range: { from: dayToDate(from), to: manifest.asOf, days: to - from + 1 },
|
|
67128
|
+
valueNow: usd(end.cents),
|
|
67129
|
+
valueAtStart: { date: dayToDate(start.day), usd: usd(start.cents) },
|
|
67130
|
+
change: { usd: usd(delta), pct: start.cents > 0 ? Math.round(delta / start.cents * 1e3) / 10 : null },
|
|
67131
|
+
high: { date: dayToDate(hi.day), usd: usd(hi.cents) },
|
|
67132
|
+
low: { date: dayToDate(lo.day), usd: usd(lo.cents) },
|
|
67133
|
+
gainers: h.moves.filter((m) => m.deltaCents > 0).slice(0, n).map(move),
|
|
67134
|
+
losers: h.moves.filter((m) => m.deltaCents < 0).sort((a, b) => a.deltaCents - b.deltaCents).slice(0, n).map(move),
|
|
67135
|
+
copies: {
|
|
67136
|
+
priced: h.pricedCopies,
|
|
67137
|
+
notInHistory: h.unpricedCopies,
|
|
67138
|
+
...noPrinting ? { noPrinting } : {},
|
|
67139
|
+
...h.specialFoilCopies ? { specialFoils: h.specialFoilCopies, specialFoilNote: "Foils TCGplayer also sells as a special foil are valued at its regular foil price." } : {}
|
|
67140
|
+
},
|
|
67141
|
+
[`every${step === 1 ? "Day" : `${step}Days`}`]: series,
|
|
67142
|
+
about: "EDHVault's reading: what the cards owned now were worth on each day, at that day's price. Not a record of what was owned then. A day with no price carries the last one forward.",
|
|
67143
|
+
...standIns.length ? { standInDays: standIns, standInNote: "On these days MTGJSON had no prices, so Scryfall's stand in." } : {},
|
|
67144
|
+
...ph.stale().length ? { olderCopy: ph.stale() } : {},
|
|
67145
|
+
credit: PRICE_HISTORY_CREDIT
|
|
67146
|
+
});
|
|
67147
|
+
}
|
|
67148
|
+
};
|
|
67149
|
+
var KIND_WORD = { manual: "saved by you", auto: "saved automatically", session: "as you left it" };
|
|
67150
|
+
var deckHistoryTool = {
|
|
67151
|
+
name: "deck_history",
|
|
67152
|
+
description: "A deck's History, as its History panel keeps it: the versions saved by the user, saved automatically before big changes, and \"as you left it\" after each editing session, newest first. Each says when, its label, and what changed between it and the deck now (added since, removed since, moved, copies, commander). Give `version` (an id from the list) for that version's full comparison, or its whole card list with detail: full. Read-only: to go back, edit_deck can ask to undo the changes. Needs an access code that can read decks.",
|
|
67153
|
+
input: {
|
|
67154
|
+
deck: external_exports.string().min(1).describe("A saved deck's name or id."),
|
|
67155
|
+
version: external_exports.string().optional().describe("One version's id, from the list, for everything that changed since."),
|
|
67156
|
+
limit: external_exports.number().int().min(1).max(100).optional().describe("Versions to list (default 20)."),
|
|
67157
|
+
detail: detailInput,
|
|
67158
|
+
refresh: refreshInput
|
|
67159
|
+
},
|
|
67160
|
+
async run(args, ctx) {
|
|
67161
|
+
const [id, raw] = findDeck(String(args.deck), await ctx.library.decks(args.refresh === true));
|
|
67162
|
+
const catalog = await tryCatalog(ctx);
|
|
67163
|
+
const name = viewDeck(id, asDeck(raw), null).name;
|
|
67164
|
+
const list = await ctx.library.historyOf(id, args.refresh === true);
|
|
67165
|
+
if (!list?.length) {
|
|
67166
|
+
const copied = await ctx.library.historyCopied();
|
|
67167
|
+
return json2({
|
|
67168
|
+
deck: name,
|
|
67169
|
+
versions: 0,
|
|
67170
|
+
note: copied ? "This deck has no saved History yet." : "The read copy doesn't carry History yet: it's added by the newest EDHVault. Open EDHVault on a synced device, then ask again."
|
|
67171
|
+
});
|
|
67172
|
+
}
|
|
67173
|
+
const r = catalog ? { resolveName: (oid) => catalog.index.byOracleId.get(oid)?.name, resolveSlug: (slug) => catalog.bySlug.get(slug)?.oracleId } : {};
|
|
67174
|
+
const stored = asDeck(raw);
|
|
67175
|
+
const now = {
|
|
67176
|
+
...stored,
|
|
67177
|
+
considering: stored.considering ?? /* @__PURE__ */ new Set(),
|
|
67178
|
+
sideboard: stored.sideboard ?? /* @__PURE__ */ new Set(),
|
|
67179
|
+
purchaseQuantities: stored.purchaseQuantities ?? /* @__PURE__ */ new Map(),
|
|
67180
|
+
soloHalf: stored.soloHalf ?? null
|
|
67181
|
+
};
|
|
67182
|
+
const detail = detailOf(args);
|
|
67183
|
+
const when = (at) => new Date(at).toISOString().replace(/\.\d+Z$/, "Z");
|
|
67184
|
+
const deckCount = (plan) => versionCards(plan, r).filter((c) => c.zone === "deck").reduce((s, c) => s + c.qty, 0);
|
|
67185
|
+
if (typeof args.version === "string" && args.version.trim()) {
|
|
67186
|
+
const cp = list.find((c) => c.id === args.version);
|
|
67187
|
+
if (!cp) throw new ToolProblem(`No version "${args.version}" in ${name}'s History. deck_history without version lists them.`);
|
|
67188
|
+
const d = diffVersions(cp.snapshot.plan, now, r);
|
|
67189
|
+
const cap2 = { summary: 60, standard: 150, full: Infinity }[detail];
|
|
67190
|
+
const nm = (c) => c.qty > 1 ? `${c.qty} ${c.name}` : c.name;
|
|
67191
|
+
return json2({
|
|
67192
|
+
deck: name,
|
|
67193
|
+
version: { id: cp.id, when: when(cp.at), kind: KIND_WORD[cp.kind], label: cp.label, ...cp.snapshot.text?.name && cp.snapshot.text.name !== name ? { deckNameThen: cp.snapshot.text.name } : {} },
|
|
67194
|
+
sinceThen: isSameVersion(d) ? "No card changes since this version." : summarizeVersionDiff(d),
|
|
67195
|
+
addedSince: d.addedSince.slice(0, cap2).map((c) => `${nm(c)}${c.zone !== "deck" ? ` (${c.zone})` : ""}`),
|
|
67196
|
+
removedSince: d.removedSince.slice(0, cap2).map((c) => `${nm(c)}${c.zone !== "deck" ? ` (${c.zone})` : ""}`),
|
|
67197
|
+
...d.moved.length ? { moved: d.moved.map((m) => `${m.card.name}: ${m.then} \u2192 ${m.now}`) } : {},
|
|
67198
|
+
...d.countChanged.length ? { copies: d.countChanged.map((c) => `${c.card.name}: ${c.then} \u2192 ${c.now}`) } : {},
|
|
67199
|
+
...d.commanderChanged ? { commander: { then: d.commandersThen, now: d.commandersNow } } : {},
|
|
67200
|
+
...detail === "full" ? { cardsThen: versionCards(cp.snapshot.plan, r).map((c) => `${nm(c)}${c.zone !== "deck" ? ` (${c.zone})` : ""}`) } : {},
|
|
67201
|
+
toGoBack: "edit_deck can ask to add back what was removed and cut what was added; the user approves it. EDHVault's History panel restores a version in one click."
|
|
67202
|
+
});
|
|
67203
|
+
}
|
|
67204
|
+
const limit = typeof args.limit === "number" ? args.limit : 20;
|
|
67205
|
+
return json2({
|
|
67206
|
+
deck: name,
|
|
67207
|
+
versions: list.length,
|
|
67208
|
+
newestFirst: list.slice(0, limit).map((cp) => {
|
|
67209
|
+
const d = diffVersions(cp.snapshot.plan, now, r);
|
|
67210
|
+
return {
|
|
67211
|
+
id: cp.id,
|
|
67212
|
+
when: when(cp.at),
|
|
67213
|
+
kind: KIND_WORD[cp.kind],
|
|
67214
|
+
label: cp.label,
|
|
67215
|
+
cards: deckCount(cp.snapshot.plan),
|
|
67216
|
+
sinceThen: isSameVersion(d) ? "same cards as now" : summarizeVersionDiff(d)
|
|
67217
|
+
};
|
|
67218
|
+
}),
|
|
67219
|
+
...list.length > limit ? { more: list.length - limit } : {},
|
|
67220
|
+
note: "Each version's notes, description and primer aren't in what an access code reads; its cards, commander, name and label are."
|
|
67221
|
+
});
|
|
67222
|
+
}
|
|
67223
|
+
};
|
|
67224
|
+
var TOOLS = [listDecks, getDeck, collectionLookup, cardSearch, cardTool, tutorTool, swapsTool, commanderTool, deckCombos2, comboSearch, collectionCombos, statsTool, budgetTool, pullListTool, compareTool, overlapTool, manabaseTool, planOdds, editDeckTool, setDeckNotesTool, moveToFolderTool, createDeckTool, collectionTool("collection_add"), collectionTool("collection_remove"), wishlistEditTool, binderEditTool, setCardReadTool, getRequestsTool, collectionValueTool, deckHistoryTool];
|
|
66160
67225
|
|
|
66161
67226
|
// src/server.ts
|
|
66162
|
-
|
|
67227
|
+
function buildServer(version2, ctx) {
|
|
66163
67228
|
const server = new McpServer({ name: "edhvault", version: version2 });
|
|
66164
67229
|
for (const tool of TOOLS) {
|
|
66165
67230
|
server.registerTool(
|
|
@@ -66175,7 +67240,10 @@ async function serve(version2, ctx) {
|
|
|
66175
67240
|
}
|
|
66176
67241
|
);
|
|
66177
67242
|
}
|
|
66178
|
-
|
|
67243
|
+
return server;
|
|
67244
|
+
}
|
|
67245
|
+
async function serve(version2, ctx) {
|
|
67246
|
+
await buildServer(version2, ctx).connect(new StdioServerTransport());
|
|
66179
67247
|
log.info(`edhvault-mcp ${version2} serving ${TOOLS.length} tools`);
|
|
66180
67248
|
}
|
|
66181
67249
|
|
|
@@ -66185,7 +67253,7 @@ var say = (m) => process.stderr.write(`${m}
|
|
|
66185
67253
|
var transport = {
|
|
66186
67254
|
fetchImpl: ((url2, init) => fetch(`${ORIGIN}${url2}`, {
|
|
66187
67255
|
...init,
|
|
66188
|
-
headers: { ...Object.fromEntries(new Headers(init?.headers)), "user-agent": `edhvault-mcp/${"0.2.
|
|
67256
|
+
headers: { ...Object.fromEntries(new Headers(init?.headers)), "user-agent": `edhvault-mcp/${"0.2.24"}` }
|
|
66189
67257
|
}))
|
|
66190
67258
|
};
|
|
66191
67259
|
async function store(dir) {
|
|
@@ -66201,11 +67269,11 @@ async function secretFromEnv() {
|
|
|
66201
67269
|
async function main() {
|
|
66202
67270
|
const args = process.argv.slice(2);
|
|
66203
67271
|
if (args.includes("--version")) {
|
|
66204
|
-
say("0.2.
|
|
67272
|
+
say("0.2.24");
|
|
66205
67273
|
return;
|
|
66206
67274
|
}
|
|
66207
67275
|
const dir = configDir();
|
|
66208
|
-
configureLog({ file:
|
|
67276
|
+
configureLog({ file: join10(dir, "edhvault-mcp.log"), debug: args.includes("--debug") });
|
|
66209
67277
|
const secrets = await store(dir);
|
|
66210
67278
|
if (args[0] === "login") {
|
|
66211
67279
|
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
@@ -66218,19 +67286,20 @@ async function main() {
|
|
|
66218
67286
|
}
|
|
66219
67287
|
if (args[0] === "logout") {
|
|
66220
67288
|
secrets.remove();
|
|
66221
|
-
|
|
67289
|
+
rmSync5(join10(dir, "view"), { recursive: true, force: true });
|
|
66222
67290
|
say("Forgotten on this machine. To block the code everywhere, remove it in Settings.");
|
|
66223
67291
|
return;
|
|
66224
67292
|
}
|
|
66225
67293
|
const extras = extrasLoader({ dir, origin: ORIGIN });
|
|
66226
67294
|
const fromEnv = await secretFromEnv();
|
|
66227
|
-
await serve("0.2.
|
|
67295
|
+
await serve("0.2.24", {
|
|
66228
67296
|
// The saved login is read again when not connected and on refresh, so
|
|
66229
67297
|
// `login` in another terminal works without restarting the AI tool.
|
|
66230
67298
|
library: new Library({ secret: () => fromEnv ?? loadSecret(secrets), dir, transport }),
|
|
66231
67299
|
catalog: catalogLoader({ dir, origin: ORIGIN, prices: extras.prices }),
|
|
66232
67300
|
combos: comboLoader({ dir, origin: ORIGIN }),
|
|
66233
67301
|
extras,
|
|
67302
|
+
priceHistory: priceHistoryLoader({ dir, origin: ORIGIN }),
|
|
66234
67303
|
// A Moxfield or Archidekt link is read by edhvault.com's own import route.
|
|
66235
67304
|
siteFetch: transport.fetchImpl
|
|
66236
67305
|
});
|