edhvault-mcp 0.2.22 → 0.2.25
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 +9 -4
- package/dist/cli.js +2689 -250
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -458,6 +458,35 @@ var init_build = __esm({
|
|
|
458
458
|
}
|
|
459
459
|
});
|
|
460
460
|
|
|
461
|
+
// ../src/lib/deckPlan/deckSchema.ts
|
|
462
|
+
function minEditorOfRaw(raw) {
|
|
463
|
+
if (!raw) return 0;
|
|
464
|
+
const m = MIN_EDITOR_PREFIX.exec(raw);
|
|
465
|
+
return m ? Number(m[1]) : 0;
|
|
466
|
+
}
|
|
467
|
+
function minEditorOf(record2) {
|
|
468
|
+
if (!record2 || typeof record2 !== "object") return 0;
|
|
469
|
+
const v = record2[MIN_EDITOR_FIELD];
|
|
470
|
+
return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : 0;
|
|
471
|
+
}
|
|
472
|
+
function canEditDeck(record2) {
|
|
473
|
+
return minEditorOf(record2) <= DECK_SCHEMA;
|
|
474
|
+
}
|
|
475
|
+
function isDeckRecordKey(key2) {
|
|
476
|
+
return DECK_RECORD_KEY.test(key2);
|
|
477
|
+
}
|
|
478
|
+
var DECK_SCHEMA, MIN_EDITOR_FIELD, MIN_EDITOR_PREFIX, DECK_RECORD_KEY, NEWER_DECK_MESSAGE;
|
|
479
|
+
var init_deckSchema = __esm({
|
|
480
|
+
"../src/lib/deckPlan/deckSchema.ts"() {
|
|
481
|
+
"use strict";
|
|
482
|
+
DECK_SCHEMA = 3;
|
|
483
|
+
MIN_EDITOR_FIELD = "minEditor";
|
|
484
|
+
MIN_EDITOR_PREFIX = /^\{"minEditor":(\d{1,6})[,}]/;
|
|
485
|
+
DECK_RECORD_KEY = /^deck-[123]-/;
|
|
486
|
+
NEWER_DECK_MESSAGE = "This deck was saved by a newer version of EDHVault. Reload to update before editing it.";
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
461
490
|
// ../src/lib/storage.ts
|
|
462
491
|
function replacer(_key, value) {
|
|
463
492
|
if (value instanceof Map) {
|
|
@@ -532,7 +561,26 @@ function noteWrite(key2) {
|
|
|
532
561
|
}
|
|
533
562
|
}
|
|
534
563
|
}
|
|
564
|
+
function refusesOlderDeckWrite(key2, incomingMinEditor) {
|
|
565
|
+
if (!isDeckRecordKey(key2)) return false;
|
|
566
|
+
let existing;
|
|
567
|
+
try {
|
|
568
|
+
existing = localStorage.getItem(PREFIX + key2);
|
|
569
|
+
} catch {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
const need = minEditorOfRaw(existing);
|
|
573
|
+
if (need <= DECK_SCHEMA || incomingMinEditor >= need) return false;
|
|
574
|
+
for (const l of newerDeckListeners) {
|
|
575
|
+
try {
|
|
576
|
+
l(key2);
|
|
577
|
+
} catch {
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
535
582
|
function saveJSON(key2, value) {
|
|
583
|
+
if (refusesOlderDeckWrite(key2, minEditorOf(value))) return false;
|
|
536
584
|
try {
|
|
537
585
|
localStorage.setItem(PREFIX + key2, JSON.stringify(value, replacer));
|
|
538
586
|
noteStorageSuccess();
|
|
@@ -543,10 +591,11 @@ function saveJSON(key2, value) {
|
|
|
543
591
|
return false;
|
|
544
592
|
}
|
|
545
593
|
}
|
|
546
|
-
var VERSION, PREFIX, quotaFailure, quotaListeners, quotaFailureObserved, blockedStorage, blockedListeners, writeListeners, writeNoticesMuted;
|
|
594
|
+
var VERSION, PREFIX, quotaFailure, quotaListeners, quotaFailureObserved, blockedStorage, blockedListeners, writeListeners, writeNoticesMuted, newerDeckListeners;
|
|
547
595
|
var init_storage = __esm({
|
|
548
596
|
"../src/lib/storage.ts"() {
|
|
549
597
|
"use strict";
|
|
598
|
+
init_deckSchema();
|
|
550
599
|
VERSION = "v1";
|
|
551
600
|
PREFIX = "ce-" + VERSION + "-";
|
|
552
601
|
quotaFailure = null;
|
|
@@ -556,6 +605,7 @@ var init_storage = __esm({
|
|
|
556
605
|
blockedListeners = /* @__PURE__ */ new Set();
|
|
557
606
|
writeListeners = /* @__PURE__ */ new Set();
|
|
558
607
|
writeNoticesMuted = 0;
|
|
608
|
+
newerDeckListeners = /* @__PURE__ */ new Set();
|
|
559
609
|
}
|
|
560
610
|
});
|
|
561
611
|
|
|
@@ -820,6 +870,15 @@ async function call(t, url2, init, timeoutMs = FETCH_TIMEOUTS.sync.timeoutMs) {
|
|
|
820
870
|
if (why === "scope") {
|
|
821
871
|
throw new SyncHttpError("no-scope", "This access code can't read that part of your library.");
|
|
822
872
|
}
|
|
873
|
+
if (why === "off") {
|
|
874
|
+
throw new SyncHttpError("off", "This link was turned off or has expired. Ask whoever sent it for a new one.");
|
|
875
|
+
}
|
|
876
|
+
if (why === "too many links") {
|
|
877
|
+
throw new SyncHttpError("forbidden", "You already have the most suggest links you can (50). Turn one off first.");
|
|
878
|
+
}
|
|
879
|
+
if (why === "too many for deck") {
|
|
880
|
+
throw new SyncHttpError("forbidden", "This deck already has the most suggest links it can (10). Turn one off first.");
|
|
881
|
+
}
|
|
823
882
|
if (why === "too many codes") {
|
|
824
883
|
throw new SyncHttpError("forbidden", "You already have the most access codes you can (10). Remove one first.");
|
|
825
884
|
}
|
|
@@ -1691,6 +1750,51 @@ var init_aiMarks = __esm({
|
|
|
1691
1750
|
}
|
|
1692
1751
|
});
|
|
1693
1752
|
|
|
1753
|
+
// ../src/lib/deckPlan/checkpointStore.ts
|
|
1754
|
+
var init_checkpointStore = __esm({
|
|
1755
|
+
"../src/lib/deckPlan/checkpointStore.ts"() {
|
|
1756
|
+
"use strict";
|
|
1757
|
+
init_build();
|
|
1758
|
+
init_storage();
|
|
1759
|
+
init_storageKey();
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
|
|
1763
|
+
// ../src/lib/sync/syncHistory.ts
|
|
1764
|
+
async function pipe(bytes, stream) {
|
|
1765
|
+
const out = new Response(new Blob([bytes]).stream().pipeThrough(stream));
|
|
1766
|
+
return new Uint8Array(await out.arrayBuffer());
|
|
1767
|
+
}
|
|
1768
|
+
async function unpackHistory(text) {
|
|
1769
|
+
try {
|
|
1770
|
+
let json3 = text;
|
|
1771
|
+
if (text.startsWith(GZ)) {
|
|
1772
|
+
if (typeof DecompressionStream === "undefined") return null;
|
|
1773
|
+
const z2 = base64UrlToBytes(text.slice(GZ.length));
|
|
1774
|
+
if (!z2) return null;
|
|
1775
|
+
json3 = new TextDecoder().decode(await pipe(z2, new DecompressionStream("gzip")));
|
|
1776
|
+
}
|
|
1777
|
+
const doc = JSON.parse(json3);
|
|
1778
|
+
if (!doc || doc.v !== 1 || !Array.isArray(doc.list)) return null;
|
|
1779
|
+
return doc;
|
|
1780
|
+
} catch {
|
|
1781
|
+
return null;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
var SYNC_HISTORY_MAX_BYTES, DAY_MS2, GZ;
|
|
1785
|
+
var init_syncHistory = __esm({
|
|
1786
|
+
"../src/lib/sync/syncHistory.ts"() {
|
|
1787
|
+
"use strict";
|
|
1788
|
+
init_checkpointStore();
|
|
1789
|
+
init_sealedBox();
|
|
1790
|
+
init_syncKeys();
|
|
1791
|
+
init_syncApi();
|
|
1792
|
+
SYNC_HISTORY_MAX_BYTES = 4 * 1024 * 1024;
|
|
1793
|
+
DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
1794
|
+
GZ = "gz1:";
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
|
|
1694
1798
|
// ../../commander/node_modules/ajv/dist/compile/codegen/code.js
|
|
1695
1799
|
var require_code = __commonJS({
|
|
1696
1800
|
"../../commander/node_modules/ajv/dist/compile/codegen/code.js"(exports) {
|
|
@@ -8591,11 +8695,12 @@ function mergeDuplicates(entries2) {
|
|
|
8591
8695
|
const existing = merged.get(key2);
|
|
8592
8696
|
if (existing) {
|
|
8593
8697
|
existing.quantity += entry.quantity;
|
|
8698
|
+
if (entry.acquired) mergeAcquired(existing, entry);
|
|
8594
8699
|
if (entry.tags && entry.tags.length > 0) {
|
|
8595
8700
|
existing.tags = unionTags(existing.tags, entry.tags);
|
|
8596
8701
|
}
|
|
8597
8702
|
} else {
|
|
8598
|
-
merged.set(key2, { ...entry });
|
|
8703
|
+
merged.set(key2, entry.acquired ? { ...entry, acquired: entry.acquired.map((l) => ({ ...l })) } : { ...entry });
|
|
8599
8704
|
}
|
|
8600
8705
|
}
|
|
8601
8706
|
return Array.from(merged.values());
|
|
@@ -8612,6 +8717,44 @@ function unionTags(a, b) {
|
|
|
8612
8717
|
}
|
|
8613
8718
|
return out;
|
|
8614
8719
|
}
|
|
8720
|
+
function mergeAcquired(into, from) {
|
|
8721
|
+
const lots = into.acquired ??= [];
|
|
8722
|
+
const currency = into.purchaseCurrency ?? from.purchaseCurrency;
|
|
8723
|
+
const clash = !!from.purchaseCurrency && !!into.purchaseCurrency && from.purchaseCurrency !== into.purchaseCurrency;
|
|
8724
|
+
for (const lot of from.acquired ?? []) {
|
|
8725
|
+
if (clash && lot.price !== void 0) {
|
|
8726
|
+
const { price: _dropped, ...rest } = lot;
|
|
8727
|
+
lots.push(rest);
|
|
8728
|
+
} else lots.push({ ...lot });
|
|
8729
|
+
}
|
|
8730
|
+
if (currency && !into.purchaseCurrency && lots.some((l) => l.price !== void 0)) into.purchaseCurrency = currency;
|
|
8731
|
+
}
|
|
8732
|
+
function parsePurchasePrice(raw) {
|
|
8733
|
+
if (!raw) return void 0;
|
|
8734
|
+
let t = raw.replace(/[^\d.,-]/g, "");
|
|
8735
|
+
if (!t) return void 0;
|
|
8736
|
+
if (t.includes(",") && !t.includes(".") && /,\d{1,2}$/.test(t)) t = t.replace(",", ".");
|
|
8737
|
+
else t = t.replace(/,/g, "");
|
|
8738
|
+
const n = Number(t);
|
|
8739
|
+
return Number.isFinite(n) && n > 0 && n < 1e6 ? Math.round(n * 100) / 100 : void 0;
|
|
8740
|
+
}
|
|
8741
|
+
function parseAddedDate(raw) {
|
|
8742
|
+
const t = raw?.trim();
|
|
8743
|
+
if (!t) return void 0;
|
|
8744
|
+
const iso = /^(\d{4})-(\d{2})-(\d{2})/.exec(t);
|
|
8745
|
+
let ms;
|
|
8746
|
+
if (iso && t.length === 10) ms = Date.UTC(+iso[1], +iso[2] - 1, +iso[3]);
|
|
8747
|
+
else if (iso) ms = Date.parse(t);
|
|
8748
|
+
else {
|
|
8749
|
+
const us = /^(\d{1,2})\/(\d{1,2})\/(\d{4})/.exec(t);
|
|
8750
|
+
if (!us) return void 0;
|
|
8751
|
+
ms = Date.UTC(+us[3], +us[1] - 1, +us[2]);
|
|
8752
|
+
}
|
|
8753
|
+
if (!Number.isFinite(ms)) return void 0;
|
|
8754
|
+
const day2 = new Date(ms).toISOString().slice(0, 10);
|
|
8755
|
+
const year = +day2.slice(0, 4);
|
|
8756
|
+
return year >= 1993 && year <= 2100 ? day2 : void 0;
|
|
8757
|
+
}
|
|
8615
8758
|
var init_normalize = __esm({
|
|
8616
8759
|
"../src/lib/parser/normalize.ts"() {
|
|
8617
8760
|
"use strict";
|
|
@@ -9954,95 +10097,144 @@ function parsePrice(raw) {
|
|
|
9954
10097
|
const n = Number.parseFloat(raw);
|
|
9955
10098
|
return Number.isFinite(n) ? n : null;
|
|
9956
10099
|
}
|
|
10100
|
+
function printingsFetchPaused(now = Date.now()) {
|
|
10101
|
+
return now < trippedUntil;
|
|
10102
|
+
}
|
|
10103
|
+
function takeSlot() {
|
|
10104
|
+
const turn = gate.then(async () => {
|
|
10105
|
+
if (printingsFetchPaused()) return false;
|
|
10106
|
+
const wait = Math.max(nextSlotAt, pausedUntil) - Date.now();
|
|
10107
|
+
if (wait > 0) await sleep(wait);
|
|
10108
|
+
if (printingsFetchPaused()) return false;
|
|
10109
|
+
nextSlotAt = Date.now() + MIN_GAP_MS;
|
|
10110
|
+
return true;
|
|
10111
|
+
});
|
|
10112
|
+
gate = turn.catch(() => void 0);
|
|
10113
|
+
return turn;
|
|
10114
|
+
}
|
|
10115
|
+
function noteFailure() {
|
|
10116
|
+
consecutiveFailures++;
|
|
10117
|
+
if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
|
|
10118
|
+
trips++;
|
|
10119
|
+
trippedUntil = Date.now() + TRIP_MS * 2 ** Math.min(trips - 1, 4);
|
|
10120
|
+
consecutiveFailures = 0;
|
|
10121
|
+
if (false) {
|
|
10122
|
+
console.warn("printings: Scryfall keeps failing; pausing /cards/collection");
|
|
10123
|
+
}
|
|
10124
|
+
return;
|
|
10125
|
+
}
|
|
10126
|
+
pausedUntil = Date.now() + FAILURE_PAUSE_MS;
|
|
10127
|
+
}
|
|
10128
|
+
async function requestBatch(batch) {
|
|
10129
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
10130
|
+
if (!await takeSlot()) return null;
|
|
10131
|
+
try {
|
|
10132
|
+
const res = await fetchWithTimeout(COLLECTION_URL, {
|
|
10133
|
+
...FETCH_TIMEOUTS.scryfall,
|
|
10134
|
+
method: "POST",
|
|
10135
|
+
headers: {
|
|
10136
|
+
"Content-Type": "application/json",
|
|
10137
|
+
Accept: "application/json"
|
|
10138
|
+
},
|
|
10139
|
+
body: JSON.stringify({ identifiers: batch })
|
|
10140
|
+
});
|
|
10141
|
+
if (res.ok) {
|
|
10142
|
+
consecutiveFailures = 0;
|
|
10143
|
+
return await res.json();
|
|
10144
|
+
}
|
|
10145
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 429) return null;
|
|
10146
|
+
noteFailure();
|
|
10147
|
+
} catch (e) {
|
|
10148
|
+
if (false) console.warn("printings: batch fetch failed:", e);
|
|
10149
|
+
noteFailure();
|
|
10150
|
+
}
|
|
10151
|
+
}
|
|
10152
|
+
return null;
|
|
10153
|
+
}
|
|
9957
10154
|
async function fetchPrintings(identifiers, onProgress) {
|
|
9958
10155
|
const result = /* @__PURE__ */ new Map();
|
|
10156
|
+
const shared = [];
|
|
9959
10157
|
const toFetch = [];
|
|
10158
|
+
const settle2 = /* @__PURE__ */ new Map();
|
|
9960
10159
|
for (const id of identifiers) {
|
|
9961
10160
|
const key2 = printingKey(id.set, id.collector_number);
|
|
9962
10161
|
const cached2 = cache.get(key2);
|
|
9963
10162
|
if (cached2) {
|
|
9964
10163
|
result.set(key2, cached2);
|
|
9965
|
-
|
|
9966
|
-
toFetch.push(id);
|
|
10164
|
+
continue;
|
|
9967
10165
|
}
|
|
10166
|
+
if (notFound.has(key2) || settle2.has(key2)) continue;
|
|
10167
|
+
const running = inflight.get(key2);
|
|
10168
|
+
if (running) {
|
|
10169
|
+
shared.push(running.then((rec) => void (rec && result.set(key2, rec))));
|
|
10170
|
+
continue;
|
|
10171
|
+
}
|
|
10172
|
+
const mine = new Promise((resolve) => {
|
|
10173
|
+
settle2.set(key2, (rec) => {
|
|
10174
|
+
settle2.delete(key2);
|
|
10175
|
+
inflight.delete(key2);
|
|
10176
|
+
resolve(rec);
|
|
10177
|
+
});
|
|
10178
|
+
});
|
|
10179
|
+
inflight.set(key2, mine);
|
|
10180
|
+
toFetch.push(id);
|
|
9968
10181
|
}
|
|
9969
10182
|
const total = toFetch.length;
|
|
9970
10183
|
if (total === 0) {
|
|
10184
|
+
await Promise.all(shared);
|
|
9971
10185
|
onProgress?.(0, 0);
|
|
9972
10186
|
return result;
|
|
9973
10187
|
}
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
9979
|
-
|
|
9980
|
-
|
|
9981
|
-
|
|
9982
|
-
|
|
9983
|
-
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
|
|
9991
|
-
|
|
9992
|
-
|
|
9993
|
-
|
|
9994
|
-
|
|
9995
|
-
|
|
9996
|
-
|
|
9997
|
-
|
|
10188
|
+
try {
|
|
10189
|
+
for (let i = 0; i < toFetch.length; i += BATCH) {
|
|
10190
|
+
if (printingsFetchPaused()) break;
|
|
10191
|
+
const batch = toFetch.slice(i, i + BATCH);
|
|
10192
|
+
const json3 = await requestBatch(batch);
|
|
10193
|
+
if (json3) {
|
|
10194
|
+
try {
|
|
10195
|
+
const missing = new Set(
|
|
10196
|
+
(json3.not_found ?? []).map((n) => printingKey(n.set, n.collector_number))
|
|
10197
|
+
);
|
|
10198
|
+
let dataIdx = 0;
|
|
10199
|
+
for (const reqId of batch) {
|
|
10200
|
+
const key2 = printingKey(reqId.set, reqId.collector_number);
|
|
10201
|
+
if (missing.has(key2)) {
|
|
10202
|
+
notFound.add(key2);
|
|
10203
|
+
settle2.get(key2)?.(null);
|
|
10204
|
+
continue;
|
|
10205
|
+
}
|
|
10206
|
+
const card = json3.data[dataIdx++];
|
|
10207
|
+
if (!card?.oracle_id) continue;
|
|
10208
|
+
const image = pickImage(card);
|
|
10209
|
+
if (!image) continue;
|
|
10210
|
+
const backImage = card.card_faces?.[1]?.image_uris?.normal;
|
|
10211
|
+
const record2 = {
|
|
10212
|
+
oracleId: card.oracle_id,
|
|
10213
|
+
image,
|
|
10214
|
+
...backImage ? { backImage } : {},
|
|
10215
|
+
priceUsd: parsePrice(card.prices?.usd),
|
|
10216
|
+
priceUsdFoil: parsePrice(card.prices?.usd_foil)
|
|
10217
|
+
};
|
|
10218
|
+
result.set(key2, record2);
|
|
10219
|
+
cache.set(key2, record2);
|
|
10220
|
+
settle2.get(key2)?.(record2);
|
|
10221
|
+
}
|
|
10222
|
+
} catch (e) {
|
|
10223
|
+
if (false) console.warn("printings: batch parse failed:", e);
|
|
9998
10224
|
}
|
|
9999
10225
|
}
|
|
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
10226
|
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);
|
|
10227
|
+
settle2.get(printingKey(reqId.set, reqId.collector_number))?.(null);
|
|
10036
10228
|
}
|
|
10229
|
+
onProgress?.(Math.min(i + BATCH, total), total);
|
|
10037
10230
|
}
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
await new Promise((r) => setTimeout(r, REQUEST_GAP_MS));
|
|
10041
|
-
}
|
|
10231
|
+
} finally {
|
|
10232
|
+
for (const done of [...settle2.values()]) done(null);
|
|
10042
10233
|
}
|
|
10234
|
+
await Promise.all(shared);
|
|
10043
10235
|
return result;
|
|
10044
10236
|
}
|
|
10045
|
-
var COLLECTION_URL, BATCH,
|
|
10237
|
+
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
10238
|
var init_printings = __esm({
|
|
10047
10239
|
"../src/lib/scryfall/printings.ts"() {
|
|
10048
10240
|
"use strict";
|
|
@@ -10050,8 +10242,20 @@ var init_printings = __esm({
|
|
|
10050
10242
|
init_fetchWithTimeout();
|
|
10051
10243
|
COLLECTION_URL = "https://api.scryfall.com/cards/collection";
|
|
10052
10244
|
BATCH = 75;
|
|
10053
|
-
|
|
10245
|
+
MIN_GAP_MS = 550;
|
|
10246
|
+
FAILURE_PAUSE_MS = 3e4;
|
|
10247
|
+
MAX_CONSECUTIVE_FAILURES = 3;
|
|
10248
|
+
TRIP_MS = 10 * 6e4;
|
|
10054
10249
|
cache = /* @__PURE__ */ new Map();
|
|
10250
|
+
gate = Promise.resolve();
|
|
10251
|
+
nextSlotAt = 0;
|
|
10252
|
+
pausedUntil = 0;
|
|
10253
|
+
trippedUntil = 0;
|
|
10254
|
+
consecutiveFailures = 0;
|
|
10255
|
+
trips = 0;
|
|
10256
|
+
notFound = /* @__PURE__ */ new Set();
|
|
10257
|
+
inflight = /* @__PURE__ */ new Map();
|
|
10258
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
10055
10259
|
}
|
|
10056
10260
|
});
|
|
10057
10261
|
|
|
@@ -11001,7 +11205,7 @@ var init_countRows = __esm({
|
|
|
11001
11205
|
what: "treasures",
|
|
11002
11206
|
label: "Treasure",
|
|
11003
11207
|
of: (n) => `${n} Treasure`,
|
|
11004
|
-
when: "Treasure you still hold as the turn ends. While this
|
|
11208
|
+
when: "Treasure you still hold as the turn ends. While this step is short, Treasure is only spent on what another step needs.",
|
|
11005
11209
|
start: 3,
|
|
11006
11210
|
max: 30
|
|
11007
11211
|
},
|
|
@@ -12599,7 +12803,7 @@ var require_react_development = __commonJS({
|
|
|
12599
12803
|
var dispatcher = resolveDispatcher();
|
|
12600
12804
|
return dispatcher.useLayoutEffect(create2, deps);
|
|
12601
12805
|
}
|
|
12602
|
-
function
|
|
12806
|
+
function useCallback2(callback, deps) {
|
|
12603
12807
|
var dispatcher = resolveDispatcher();
|
|
12604
12808
|
return dispatcher.useCallback(callback, deps);
|
|
12605
12809
|
}
|
|
@@ -13366,7 +13570,7 @@ var require_react_development = __commonJS({
|
|
|
13366
13570
|
exports.memo = memo2;
|
|
13367
13571
|
exports.startTransition = startTransition;
|
|
13368
13572
|
exports.unstable_act = act;
|
|
13369
|
-
exports.useCallback =
|
|
13573
|
+
exports.useCallback = useCallback2;
|
|
13370
13574
|
exports.useContext = useContext;
|
|
13371
13575
|
exports.useDebugValue = useDebugValue2;
|
|
13372
13576
|
exports.useDeferredValue = useDeferredValue;
|
|
@@ -13696,8 +13900,8 @@ var init_syncCollection = __esm({
|
|
|
13696
13900
|
});
|
|
13697
13901
|
|
|
13698
13902
|
// src/cli.ts
|
|
13699
|
-
import { rmSync as
|
|
13700
|
-
import { join as
|
|
13903
|
+
import { rmSync as rmSync5 } from "node:fs";
|
|
13904
|
+
import { join as join10 } from "node:path";
|
|
13701
13905
|
import { createInterface } from "node:readline/promises";
|
|
13702
13906
|
|
|
13703
13907
|
// src/catalog.ts
|
|
@@ -13724,6 +13928,12 @@ function cardTrendWindows(tuple2, asOf) {
|
|
|
13724
13928
|
}
|
|
13725
13929
|
return out;
|
|
13726
13930
|
}
|
|
13931
|
+
function compareChange(a, b, dir) {
|
|
13932
|
+
if (a == null && b == null) return 0;
|
|
13933
|
+
if (a == null) return 1;
|
|
13934
|
+
if (b == null) return -1;
|
|
13935
|
+
return dir === "desc" ? b - a : a - b;
|
|
13936
|
+
}
|
|
13727
13937
|
|
|
13728
13938
|
// ../src/lib/cardInsights.ts
|
|
13729
13939
|
init_slug();
|
|
@@ -13962,6 +14172,45 @@ var ARCHETYPE_TAGS = [
|
|
|
13962
14172
|
// targeted discard (Thoughtseize)
|
|
13963
14173
|
];
|
|
13964
14174
|
|
|
14175
|
+
// ../src/lib/formats.ts
|
|
14176
|
+
var FORMATS = [
|
|
14177
|
+
// Commander and its family first: this is a Commander site.
|
|
14178
|
+
{ key: "commander", label: "Commander", group: "commander", aliases: ["edh"] },
|
|
14179
|
+
{ key: "oathbreaker", label: "Oathbreaker", group: "commander" },
|
|
14180
|
+
{ key: "paupercommander", label: "Pauper Commander", group: "commander", aliases: ["pdh", "pauperedh"] },
|
|
14181
|
+
{ key: "duel", label: "Duel Commander", group: "commander", aliases: ["duelcommander", "dc"] },
|
|
14182
|
+
{ key: "predh", label: "PreDH", group: "commander" },
|
|
14183
|
+
{ key: "brawl", label: "Brawl", group: "commander", aliases: ["historicbrawl"] },
|
|
14184
|
+
{ key: "standardbrawl", label: "Standard Brawl", group: "commander" },
|
|
14185
|
+
// Paper constructed.
|
|
14186
|
+
{ key: "standard", label: "Standard", group: "constructed", aliases: ["std"] },
|
|
14187
|
+
{ key: "pioneer", label: "Pioneer", group: "constructed" },
|
|
14188
|
+
{ key: "modern", label: "Modern", group: "constructed" },
|
|
14189
|
+
{ key: "legacy", label: "Legacy", group: "constructed" },
|
|
14190
|
+
{ key: "vintage", label: "Vintage", group: "constructed" },
|
|
14191
|
+
{ key: "pauper", label: "Pauper", group: "constructed" },
|
|
14192
|
+
{ key: "premodern", label: "Premodern", group: "constructed" },
|
|
14193
|
+
{ key: "oldschool", label: "Old School", group: "constructed" },
|
|
14194
|
+
{ key: "penny", label: "Penny Dreadful", group: "constructed", aliases: ["pennydreadful"] },
|
|
14195
|
+
// MTG Arena only.
|
|
14196
|
+
{ key: "alchemy", label: "Alchemy", group: "arena" },
|
|
14197
|
+
{ key: "historic", label: "Historic", group: "arena" },
|
|
14198
|
+
{ key: "timeless", label: "Timeless", group: "arena" },
|
|
14199
|
+
{ key: "gladiator", label: "Gladiator", group: "arena" },
|
|
14200
|
+
{ key: "competitivebrawl", label: "Competitive Brawl", group: "arena" }
|
|
14201
|
+
];
|
|
14202
|
+
var BY_KEY = new Map(FORMATS.map((f) => [f.key, f]));
|
|
14203
|
+
var BY_SPELLING = /* @__PURE__ */ new Map();
|
|
14204
|
+
for (const f of FORMATS) {
|
|
14205
|
+
BY_SPELLING.set(f.key, f.key);
|
|
14206
|
+
for (const a of f.aliases ?? []) BY_SPELLING.set(a, f.key);
|
|
14207
|
+
}
|
|
14208
|
+
var UNLABELED_KEYS = /* @__PURE__ */ new Set(["future", "tlr"]);
|
|
14209
|
+
function resolveFormat(input2) {
|
|
14210
|
+
const k = input2.toLowerCase().replace(/[\s_-]+/g, "");
|
|
14211
|
+
return BY_SPELLING.get(k) ?? (UNLABELED_KEYS.has(k) ? k : null);
|
|
14212
|
+
}
|
|
14213
|
+
|
|
13965
14214
|
// ../src/lib/edhrec/game-changers.ts
|
|
13966
14215
|
init_slug();
|
|
13967
14216
|
var GAME_CHANGER_NAMES = [
|
|
@@ -14207,7 +14456,6 @@ var UNAVAILABLE_OPS = {
|
|
|
14207
14456
|
"Cube search": ["cube"],
|
|
14208
14457
|
"Game-availability search": ["game"],
|
|
14209
14458
|
"Printing-count search": ["prints", "sets", "paperprints", "papersets"],
|
|
14210
|
-
"Format-legality search": ["f", "format", "banned", "restricted"],
|
|
14211
14459
|
"EUR / TIX price search": ["eur", "tix", "cheapest"],
|
|
14212
14460
|
"Art-tag search": ["art", "atag", "arttag"],
|
|
14213
14461
|
"Printing-history search": ["in", "new"],
|
|
@@ -14459,6 +14707,11 @@ var SUPPORTED_OP_PREFIXES = /* @__PURE__ */ new Set([
|
|
|
14459
14707
|
"produce",
|
|
14460
14708
|
"mv",
|
|
14461
14709
|
"cmc",
|
|
14710
|
+
"f",
|
|
14711
|
+
"format",
|
|
14712
|
+
"legal",
|
|
14713
|
+
"banned",
|
|
14714
|
+
"restricted",
|
|
14462
14715
|
"owned",
|
|
14463
14716
|
"name",
|
|
14464
14717
|
"is",
|
|
@@ -14738,6 +14991,7 @@ function parseScryfallQuery(input2) {
|
|
|
14738
14991
|
sets: [],
|
|
14739
14992
|
finishes: [],
|
|
14740
14993
|
treatments: [],
|
|
14994
|
+
legality: [],
|
|
14741
14995
|
routes: [],
|
|
14742
14996
|
keywords: [],
|
|
14743
14997
|
isDerived: [],
|
|
@@ -14843,6 +15097,11 @@ function parseScryfallQuery(input2) {
|
|
|
14843
15097
|
for (const c of parsed.value) if (!out.sets.includes(c)) out.sets.push(c);
|
|
14844
15098
|
continue;
|
|
14845
15099
|
}
|
|
15100
|
+
if (parsed.kind === "legality") {
|
|
15101
|
+
const v = parsed.value;
|
|
15102
|
+
if (!out.legality.some((l) => l.format === v.format && l.status === v.status)) out.legality.push(v);
|
|
15103
|
+
continue;
|
|
15104
|
+
}
|
|
14846
15105
|
if (parsed.kind === "finish") {
|
|
14847
15106
|
if (!out.finishes.includes(parsed.value)) out.finishes.push(parsed.value);
|
|
14848
15107
|
continue;
|
|
@@ -14917,7 +15176,7 @@ function parseScryfallQuery(input2) {
|
|
|
14917
15176
|
}
|
|
14918
15177
|
function hasRunnableClause(q) {
|
|
14919
15178
|
if (q.tree !== null) return true;
|
|
14920
|
-
return q.text !== "" || q.exactName !== null || q.negated.length > 0 || q.color !== null || q.identity !== null || q.types.length > 0 || q.mv.length > 0 || q.mvParity !== null || q.year.length > 0 || q.edhrecRank.length > 0 || q.oracle.length > 0 || q.otags.length > 0 || q.otagsBroad.length > 0 || q.roles.length > 0 || q.sets.length > 0 || q.finishes.length > 0 || q.treatments.length > 0 || q.keywords.length > 0 || q.isDerived.length > 0 || q.rarities.length > 0 || q.rarityCmp.length > 0 || q.pow.length > 0 || q.tou.length > 0 || q.loy.length > 0 || q.produces !== null || q.price.length > 0 || q.ownership !== null || q.ub !== "include" || q.banned !== null || q.reserved !== null || q.commander !== null;
|
|
15179
|
+
return q.text !== "" || q.exactName !== null || q.negated.length > 0 || q.color !== null || q.identity !== null || q.types.length > 0 || q.mv.length > 0 || q.mvParity !== null || q.year.length > 0 || q.edhrecRank.length > 0 || q.oracle.length > 0 || q.otags.length > 0 || q.otagsBroad.length > 0 || q.roles.length > 0 || q.sets.length > 0 || q.finishes.length > 0 || q.treatments.length > 0 || q.legality.length > 0 || q.keywords.length > 0 || q.isDerived.length > 0 || q.rarities.length > 0 || q.rarityCmp.length > 0 || q.pow.length > 0 || q.tou.length > 0 || q.loy.length > 0 || q.produces !== null || q.price.length > 0 || q.ownership !== null || q.ub !== "include" || q.banned !== null || q.reserved !== null || q.commander !== null;
|
|
14921
15180
|
}
|
|
14922
15181
|
function negatedBroadSlugs(q) {
|
|
14923
15182
|
const out = [];
|
|
@@ -14944,6 +15203,38 @@ function tokenize(input2) {
|
|
|
14944
15203
|
let chars = [];
|
|
14945
15204
|
let inQuote = false;
|
|
14946
15205
|
const flush = () => {
|
|
15206
|
+
if (chars.length === 0) return;
|
|
15207
|
+
const isComma = (c) => c.ch === "," && !c.q;
|
|
15208
|
+
const segs = [[]];
|
|
15209
|
+
for (const c of chars) {
|
|
15210
|
+
if (isComma(c)) segs.push([]);
|
|
15211
|
+
else segs[segs.length - 1].push(c);
|
|
15212
|
+
}
|
|
15213
|
+
if (segs.length > 1) {
|
|
15214
|
+
const parts = segs.filter((g) => g.length > 0);
|
|
15215
|
+
const all = chars;
|
|
15216
|
+
if (parts.length === 0) {
|
|
15217
|
+
chars = [];
|
|
15218
|
+
return;
|
|
15219
|
+
}
|
|
15220
|
+
if (parts.every(isClauseChars)) {
|
|
15221
|
+
for (const g of parts) {
|
|
15222
|
+
chars = g;
|
|
15223
|
+
pushTok();
|
|
15224
|
+
}
|
|
15225
|
+
chars = [];
|
|
15226
|
+
return;
|
|
15227
|
+
}
|
|
15228
|
+
let a = 0;
|
|
15229
|
+
let b = all.length;
|
|
15230
|
+
while (a < b && isComma(all[a])) a++;
|
|
15231
|
+
while (b > a && isComma(all[b - 1])) b--;
|
|
15232
|
+
const trimmed = all.slice(a, b);
|
|
15233
|
+
if (trimmed.length < all.length && isClauseChars(trimmed)) chars = trimmed;
|
|
15234
|
+
}
|
|
15235
|
+
pushTok();
|
|
15236
|
+
};
|
|
15237
|
+
const pushTok = () => {
|
|
14947
15238
|
if (chars.length === 0) return;
|
|
14948
15239
|
const neg = chars.length > 1 && chars[0].ch === "-" && !chars[0].q && chars[1].ch === "(" && !chars[1].q;
|
|
14949
15240
|
const start = neg ? 1 : 0;
|
|
@@ -14979,6 +15270,11 @@ function tokenize(input2) {
|
|
|
14979
15270
|
flush();
|
|
14980
15271
|
return out;
|
|
14981
15272
|
}
|
|
15273
|
+
function isClauseChars(chars) {
|
|
15274
|
+
const text = chars.map((c) => c.ch).join("").replace(/^-?\(+/, "").replace(/\)+$/, "");
|
|
15275
|
+
if (!text) return false;
|
|
15276
|
+
return parseToken(text).kind !== "text";
|
|
15277
|
+
}
|
|
14982
15278
|
function parseToken(token) {
|
|
14983
15279
|
const lower = token.toLowerCase();
|
|
14984
15280
|
const rx = /^-?([a-z]+):\//.exec(lower);
|
|
@@ -15093,6 +15389,20 @@ function parseToken(token) {
|
|
|
15093
15389
|
}
|
|
15094
15390
|
return { kind: "set", value: parts };
|
|
15095
15391
|
}
|
|
15392
|
+
for (const [p, status] of [
|
|
15393
|
+
["format:", "legal"],
|
|
15394
|
+
["legal:", "legal"],
|
|
15395
|
+
["f:", "legal"],
|
|
15396
|
+
["banned:", "banned"],
|
|
15397
|
+
["restricted:", "restricted"]
|
|
15398
|
+
]) {
|
|
15399
|
+
if (!lower.startsWith(p)) continue;
|
|
15400
|
+
const rhs = lower.slice(p.length);
|
|
15401
|
+
if (!rhs) return { kind: "warn", value: `empty format filter` };
|
|
15402
|
+
const format = resolveFormat(rhs);
|
|
15403
|
+
if (!format) return { kind: "warn", value: `unknown format: "${token}"` };
|
|
15404
|
+
return { kind: "legality", value: { format, status } };
|
|
15405
|
+
}
|
|
15096
15406
|
const numToken = tryParseNumeric(lower);
|
|
15097
15407
|
if (numToken) return numToken;
|
|
15098
15408
|
for (const p of ["produces", "produce"]) {
|
|
@@ -15548,6 +15858,218 @@ function rawSlots(c) {
|
|
|
15548
15858
|
// ../src/lib/edhrec/salt.ts
|
|
15549
15859
|
init_slug();
|
|
15550
15860
|
|
|
15861
|
+
// ../src/lib/edhrec/salt.generated.ts
|
|
15862
|
+
var SALT_BY_NAME = /* @__PURE__ */ new Map([
|
|
15863
|
+
["stasis", 3.053],
|
|
15864
|
+
["armageddon", 2.982],
|
|
15865
|
+
["winter orb", 2.927],
|
|
15866
|
+
["the tabernacle at pendrell vale", 2.83],
|
|
15867
|
+
["rhystic study", 2.817],
|
|
15868
|
+
["tergrid, god of fright", 2.813],
|
|
15869
|
+
["grand arbiter augustin iv", 2.759],
|
|
15870
|
+
["vivi ornitier", 2.71],
|
|
15871
|
+
["static orb", 2.706],
|
|
15872
|
+
["ravages of war", 2.633],
|
|
15873
|
+
["smothering tithe", 2.624],
|
|
15874
|
+
["jokulhaups", 2.592],
|
|
15875
|
+
["obliterate", 2.584],
|
|
15876
|
+
["vorinclex, voice of hunger", 2.555],
|
|
15877
|
+
["sunder", 2.517],
|
|
15878
|
+
["thassa's oracle", 2.504],
|
|
15879
|
+
["jin-gitaxias, core augur", 2.503],
|
|
15880
|
+
["humility", 2.48],
|
|
15881
|
+
["drannith magistrate", 2.474],
|
|
15882
|
+
["the one ring", 2.446],
|
|
15883
|
+
["devastation", 2.44],
|
|
15884
|
+
["decree of annihilation", 2.389],
|
|
15885
|
+
["opposition agent", 2.388],
|
|
15886
|
+
["worldfire", 2.378],
|
|
15887
|
+
["cyclonic rift", 2.353],
|
|
15888
|
+
["toxrill, the corrosive", 2.325],
|
|
15889
|
+
["winter moon", 2.325],
|
|
15890
|
+
["farewell", 2.324],
|
|
15891
|
+
["hokori, dust drinker", 2.319],
|
|
15892
|
+
["rising waters", 2.311],
|
|
15893
|
+
["fierce guardianship", 2.289],
|
|
15894
|
+
["apocalypse", 2.286],
|
|
15895
|
+
["sheoldred, the apocalypse", 2.28],
|
|
15896
|
+
["blood moon", 2.238],
|
|
15897
|
+
["gaea's cradle", 2.234],
|
|
15898
|
+
["urza, lord high artificer", 2.231],
|
|
15899
|
+
["smokestack", 2.219],
|
|
15900
|
+
["expropriate", 2.215],
|
|
15901
|
+
["jin-gitaxias, progress tyrant", 2.209],
|
|
15902
|
+
["nether void", 2.182],
|
|
15903
|
+
["tectonic break", 2.171],
|
|
15904
|
+
["back to basics", 2.162],
|
|
15905
|
+
["force of will", 2.153],
|
|
15906
|
+
["braids, cabal minion", 2.148],
|
|
15907
|
+
["notion thief", 2.137],
|
|
15908
|
+
["edgar markov", 2.113],
|
|
15909
|
+
["global ruin", 2.112],
|
|
15910
|
+
["ruination", 2.111],
|
|
15911
|
+
["mana breach", 2.108],
|
|
15912
|
+
["yuriko, the tiger's shadow", 2.102],
|
|
15913
|
+
["the legend of yangchen", 2.092],
|
|
15914
|
+
["orcish bowmasters", 2.09],
|
|
15915
|
+
["sen triplets", 2.076],
|
|
15916
|
+
["deadpool, trading card", 2.061],
|
|
15917
|
+
["narset, parter of veils", 2.057],
|
|
15918
|
+
["glacial chasm", 2.039],
|
|
15919
|
+
["aura shards", 2.038],
|
|
15920
|
+
["mana drain", 2.025],
|
|
15921
|
+
["kinnan, bonder prodigy", 2.024],
|
|
15922
|
+
["mindslaver", 2.016],
|
|
15923
|
+
["wake of destruction", 2.011],
|
|
15924
|
+
["grave pact", 2.009],
|
|
15925
|
+
["hullbreaker horror", 2.004],
|
|
15926
|
+
["tsunami", 2.004],
|
|
15927
|
+
["epicenter", 2.002],
|
|
15928
|
+
["catastrophe", 1.996],
|
|
15929
|
+
["the ur-dragon", 1.991],
|
|
15930
|
+
["acid rain", 1.984],
|
|
15931
|
+
["emrakul, the promised end", 1.978],
|
|
15932
|
+
["overwhelming splendor", 1.972],
|
|
15933
|
+
["blightsteel colossus", 1.971],
|
|
15934
|
+
["void winnower", 1.968],
|
|
15935
|
+
["prismari, the inspiration", 1.966],
|
|
15936
|
+
["teferi's protection", 1.959],
|
|
15937
|
+
["flashfires", 1.949],
|
|
15938
|
+
["force of negation", 1.948],
|
|
15939
|
+
["magus of the moon", 1.934],
|
|
15940
|
+
["thieves' auction", 1.924],
|
|
15941
|
+
["scrambleverse", 1.923],
|
|
15942
|
+
["mana vortex", 1.922],
|
|
15943
|
+
["impending disaster", 1.918],
|
|
15944
|
+
["elesh norn, mother of machines", 1.917],
|
|
15945
|
+
["boiling seas", 1.917],
|
|
15946
|
+
["dictate of erebos", 1.912],
|
|
15947
|
+
["thoughts of ruin", 1.909],
|
|
15948
|
+
["ulamog, the defiler", 1.905],
|
|
15949
|
+
["warp world", 1.902],
|
|
15950
|
+
["time stretch", 1.898],
|
|
15951
|
+
["boil", 1.887],
|
|
15952
|
+
["demonic consultation", 1.88],
|
|
15953
|
+
["torpor orb", 1.878],
|
|
15954
|
+
["jodah, the unifier", 1.861],
|
|
15955
|
+
["esper sentinel", 1.858],
|
|
15956
|
+
["etali, primal conqueror", 1.852],
|
|
15957
|
+
["improvisation capstone", 1.836],
|
|
15958
|
+
["maha, its feathers night", 1.827],
|
|
15959
|
+
["ad nauseam", 1.825],
|
|
15960
|
+
["possessed portal", 1.824],
|
|
15961
|
+
["consecrated sphinx", 1.821],
|
|
15962
|
+
["rule of law", 1.815]
|
|
15963
|
+
]);
|
|
15964
|
+
var SALT_BY_SLUG = /* @__PURE__ */ new Map([
|
|
15965
|
+
["stasis", 3.053],
|
|
15966
|
+
["armageddon", 2.982],
|
|
15967
|
+
["winter-orb", 2.927],
|
|
15968
|
+
["the-tabernacle-at-pendrell-vale", 2.83],
|
|
15969
|
+
["rhystic-study", 2.817],
|
|
15970
|
+
["tergrid-god-of-fright", 2.813],
|
|
15971
|
+
["grand-arbiter-augustin-iv", 2.759],
|
|
15972
|
+
["vivi-ornitier", 2.71],
|
|
15973
|
+
["static-orb", 2.706],
|
|
15974
|
+
["ravages-of-war", 2.633],
|
|
15975
|
+
["smothering-tithe", 2.624],
|
|
15976
|
+
["jokulhaups", 2.592],
|
|
15977
|
+
["obliterate", 2.584],
|
|
15978
|
+
["vorinclex-voice-of-hunger", 2.555],
|
|
15979
|
+
["sunder", 2.517],
|
|
15980
|
+
["thassas-oracle", 2.504],
|
|
15981
|
+
["jin-gitaxias-core-augur", 2.503],
|
|
15982
|
+
["humility", 2.48],
|
|
15983
|
+
["drannith-magistrate", 2.474],
|
|
15984
|
+
["the-one-ring", 2.446],
|
|
15985
|
+
["devastation", 2.44],
|
|
15986
|
+
["decree-of-annihilation", 2.389],
|
|
15987
|
+
["opposition-agent", 2.388],
|
|
15988
|
+
["worldfire", 2.378],
|
|
15989
|
+
["cyclonic-rift", 2.353],
|
|
15990
|
+
["toxrill-the-corrosive", 2.325],
|
|
15991
|
+
["winter-moon", 2.325],
|
|
15992
|
+
["farewell", 2.324],
|
|
15993
|
+
["hokori-dust-drinker", 2.319],
|
|
15994
|
+
["rising-waters", 2.311],
|
|
15995
|
+
["fierce-guardianship", 2.289],
|
|
15996
|
+
["apocalypse", 2.286],
|
|
15997
|
+
["sheoldred-the-apocalypse", 2.28],
|
|
15998
|
+
["blood-moon", 2.238],
|
|
15999
|
+
["gaeas-cradle", 2.234],
|
|
16000
|
+
["urza-lord-high-artificer", 2.231],
|
|
16001
|
+
["smokestack", 2.219],
|
|
16002
|
+
["expropriate", 2.215],
|
|
16003
|
+
["jin-gitaxias-progress-tyrant", 2.209],
|
|
16004
|
+
["nether-void", 2.182],
|
|
16005
|
+
["tectonic-break", 2.171],
|
|
16006
|
+
["back-to-basics", 2.162],
|
|
16007
|
+
["force-of-will", 2.153],
|
|
16008
|
+
["braids-cabal-minion", 2.148],
|
|
16009
|
+
["notion-thief", 2.137],
|
|
16010
|
+
["edgar-markov", 2.113],
|
|
16011
|
+
["global-ruin", 2.112],
|
|
16012
|
+
["ruination", 2.111],
|
|
16013
|
+
["mana-breach", 2.108],
|
|
16014
|
+
["yuriko-the-tigers-shadow", 2.102],
|
|
16015
|
+
["the-legend-of-yangchen", 2.092],
|
|
16016
|
+
["orcish-bowmasters", 2.09],
|
|
16017
|
+
["sen-triplets", 2.076],
|
|
16018
|
+
["deadpool-trading-card", 2.061],
|
|
16019
|
+
["narset-parter-of-veils", 2.057],
|
|
16020
|
+
["glacial-chasm", 2.039],
|
|
16021
|
+
["aura-shards", 2.038],
|
|
16022
|
+
["mana-drain", 2.025],
|
|
16023
|
+
["kinnan-bonder-prodigy", 2.024],
|
|
16024
|
+
["mindslaver", 2.016],
|
|
16025
|
+
["wake-of-destruction", 2.011],
|
|
16026
|
+
["grave-pact", 2.009],
|
|
16027
|
+
["hullbreaker-horror", 2.004],
|
|
16028
|
+
["tsunami", 2.004],
|
|
16029
|
+
["epicenter", 2.002],
|
|
16030
|
+
["catastrophe", 1.996],
|
|
16031
|
+
["the-ur-dragon", 1.991],
|
|
16032
|
+
["acid-rain", 1.984],
|
|
16033
|
+
["emrakul-the-promised-end", 1.978],
|
|
16034
|
+
["overwhelming-splendor", 1.972],
|
|
16035
|
+
["blightsteel-colossus", 1.971],
|
|
16036
|
+
["void-winnower", 1.968],
|
|
16037
|
+
["prismari-the-inspiration", 1.966],
|
|
16038
|
+
["teferis-protection", 1.959],
|
|
16039
|
+
["flashfires", 1.949],
|
|
16040
|
+
["force-of-negation", 1.948],
|
|
16041
|
+
["magus-of-the-moon", 1.934],
|
|
16042
|
+
["thieves-auction", 1.924],
|
|
16043
|
+
["scrambleverse", 1.923],
|
|
16044
|
+
["mana-vortex", 1.922],
|
|
16045
|
+
["impending-disaster", 1.918],
|
|
16046
|
+
["elesh-norn-mother-of-machines", 1.917],
|
|
16047
|
+
["boiling-seas", 1.917],
|
|
16048
|
+
["dictate-of-erebos", 1.912],
|
|
16049
|
+
["thoughts-of-ruin", 1.909],
|
|
16050
|
+
["ulamog-the-defiler", 1.905],
|
|
16051
|
+
["warp-world", 1.902],
|
|
16052
|
+
["time-stretch", 1.898],
|
|
16053
|
+
["boil", 1.887],
|
|
16054
|
+
["demonic-consultation", 1.88],
|
|
16055
|
+
["torpor-orb", 1.878],
|
|
16056
|
+
["jodah-the-unifier", 1.861],
|
|
16057
|
+
["esper-sentinel", 1.858],
|
|
16058
|
+
["etali-primal-conqueror", 1.852],
|
|
16059
|
+
["improvisation-capstone", 1.836],
|
|
16060
|
+
["maha-its-feathers-night", 1.827],
|
|
16061
|
+
["ad-nauseam", 1.825],
|
|
16062
|
+
["possessed-portal", 1.824],
|
|
16063
|
+
["consecrated-sphinx", 1.821],
|
|
16064
|
+
["rule-of-law", 1.815]
|
|
16065
|
+
]);
|
|
16066
|
+
|
|
16067
|
+
// ../src/lib/edhrec/salt.ts
|
|
16068
|
+
function saltScoreForName(name) {
|
|
16069
|
+
if (!name) return void 0;
|
|
16070
|
+
return SALT_BY_NAME.get(name.toLowerCase()) ?? SALT_BY_SLUG.get(toEdhrecSlug(name));
|
|
16071
|
+
}
|
|
16072
|
+
|
|
15551
16073
|
// ../src/lib/cardCatalog/applyCatalogFilters.ts
|
|
15552
16074
|
function compileClauses(parsed, broadMatch, resolvers) {
|
|
15553
16075
|
return {
|
|
@@ -15558,7 +16080,8 @@ function compileClauses(parsed, broadMatch, resolvers) {
|
|
|
15558
16080
|
setMatch: resolvers.setMatch,
|
|
15559
16081
|
finishMatch: resolvers.finishMatch,
|
|
15560
16082
|
treatmentMatch: resolvers.treatmentMatch,
|
|
15561
|
-
|
|
16083
|
+
legalityMatch: resolvers.legalityMatch,
|
|
16084
|
+
unresolvable: parsed.otagsBroad.length > 0 && !broadMatch || parsed.oracle.length > 0 && !resolvers.oracleText || parsed.sets.length > 0 && !resolvers.setMatch || parsed.finishes.length > 0 && !resolvers.finishMatch || parsed.treatments.length > 0 && !resolvers.treatmentMatch || parsed.legality.length > 0 && !resolvers.legalityMatch,
|
|
15562
16085
|
negated: parsed.negated.map((n) => compileSub(n, resolvers))
|
|
15563
16086
|
};
|
|
15564
16087
|
}
|
|
@@ -15633,6 +16156,9 @@ function matchClauses(card, c) {
|
|
|
15633
16156
|
if (parsed.treatments.length > 0) {
|
|
15634
16157
|
if (!c.treatmentMatch || !c.treatmentMatch(card.oracleId, parsed.treatments)) return { pass: false };
|
|
15635
16158
|
}
|
|
16159
|
+
if (parsed.legality.length > 0) {
|
|
16160
|
+
if (!c.legalityMatch || !c.legalityMatch(card.oracleId, parsed.legality)) return { pass: false };
|
|
16161
|
+
}
|
|
15636
16162
|
if (parsed.keywords.length > 0) {
|
|
15637
16163
|
const kws = card.keywords?.map((k) => k.toLowerCase());
|
|
15638
16164
|
if (!kws || !parsed.keywords.every((k) => kws.includes(k))) return { pass: false };
|
|
@@ -15750,6 +16276,7 @@ function buildCatalogPredicate(filters) {
|
|
|
15750
16276
|
setMatch,
|
|
15751
16277
|
finishMatch,
|
|
15752
16278
|
treatmentMatch,
|
|
16279
|
+
legalityMatch,
|
|
15753
16280
|
alwaysIncludeBasics
|
|
15754
16281
|
} = filters;
|
|
15755
16282
|
const parsed = filters.parsedOverride ?? parseScryfallQuery(query);
|
|
@@ -15759,7 +16286,8 @@ function buildCatalogPredicate(filters) {
|
|
|
15759
16286
|
oracleText: oracleText ?? null,
|
|
15760
16287
|
setMatch: setMatch ?? null,
|
|
15761
16288
|
finishMatch: finishMatch ?? null,
|
|
15762
|
-
treatmentMatch: treatmentMatch ?? null
|
|
16289
|
+
treatmentMatch: treatmentMatch ?? null,
|
|
16290
|
+
legalityMatch: legalityMatch ?? null
|
|
15763
16291
|
};
|
|
15764
16292
|
const positive = compileClauses(parsed, otagBroadMatch ?? null, resolvers);
|
|
15765
16293
|
const tree = parsed.tree ? compileTree(parsed.tree, resolvers) : null;
|
|
@@ -16173,10 +16701,10 @@ function buildBuySlugIndex(cards) {
|
|
|
16173
16701
|
if (hit) return hit;
|
|
16174
16702
|
const bySlug = /* @__PURE__ */ new Map();
|
|
16175
16703
|
for (const card of cards.byOracleId.values()) {
|
|
16176
|
-
const
|
|
16177
|
-
if (!bySlug.has(
|
|
16704
|
+
const front2 = toEdhrecSlug(card.name);
|
|
16705
|
+
if (!bySlug.has(front2)) bySlug.set(front2, card);
|
|
16178
16706
|
const joined = toEdhrecSlug(card.name, { joined: true });
|
|
16179
|
-
if (joined !==
|
|
16707
|
+
if (joined !== front2 && !bySlug.has(joined)) bySlug.set(joined, card);
|
|
16180
16708
|
}
|
|
16181
16709
|
slugIndexByCatalog.set(cards, bySlug);
|
|
16182
16710
|
return bySlug;
|
|
@@ -16251,11 +16779,11 @@ function applyPriceOverlay(index, prices = overlay) {
|
|
|
16251
16779
|
for (const [oid, t] of prices) {
|
|
16252
16780
|
const card = index.byOracleId.get(oid);
|
|
16253
16781
|
if (!card) continue;
|
|
16254
|
-
const
|
|
16782
|
+
const usd2 = t[0];
|
|
16255
16783
|
const eur = t[1];
|
|
16256
16784
|
let hit = false;
|
|
16257
|
-
if (
|
|
16258
|
-
card.priceUsd =
|
|
16785
|
+
if (usd2 != null && card.priceUsd !== usd2) {
|
|
16786
|
+
card.priceUsd = usd2;
|
|
16259
16787
|
hit = true;
|
|
16260
16788
|
}
|
|
16261
16789
|
if (eur != null && card.priceEur !== eur) {
|
|
@@ -16350,6 +16878,7 @@ function expand(r) {
|
|
|
16350
16878
|
...r.van === 1 ? { vanilla: true } : {},
|
|
16351
16879
|
...r.an && r.an.length > 0 ? { altNames: r.an } : {},
|
|
16352
16880
|
...r.ai && r.ai.length > 0 ? { altImages: r.ai.map((s) => expandImageUrl(s)) } : {},
|
|
16881
|
+
...r.al && r.an && r.al.length === r.an.length ? { altLangs: r.al } : {},
|
|
16353
16882
|
...r.et && ENTER_TAPPED_CHAR_TO_NAME[r.et] ? { enterTapped: ENTER_TAPPED_CHAR_TO_NAME[r.et] } : {},
|
|
16354
16883
|
...r.tc && TAP_CONDITION_CHAR_TO_NAME[r.tc] ? { tapCondition: TAP_CONDITION_CHAR_TO_NAME[r.tc] } : {},
|
|
16355
16884
|
...r.mc ? { manaCost: r.mc } : {},
|
|
@@ -16384,27 +16913,45 @@ function newIndexMaps() {
|
|
|
16384
16913
|
}
|
|
16385
16914
|
function indexPass1Card(card, m) {
|
|
16386
16915
|
card.searchNameNorm = normalizeForSearch(card.searchName);
|
|
16387
|
-
m.byName.set(card.searchName, card);
|
|
16916
|
+
if (lastWins(m.byName.get(card.searchName), card)) m.byName.set(card.searchName, card);
|
|
16388
16917
|
m.byOracleId.set(card.oracleId, card);
|
|
16389
16918
|
const norm = normalizeName(card.searchName);
|
|
16390
|
-
if (
|
|
16919
|
+
if (firstWins(m.byNormalizedName.get(norm), card)) m.byNormalizedName.set(norm, card);
|
|
16391
16920
|
if (card.faceName) {
|
|
16392
|
-
m.byFaceName.
|
|
16921
|
+
if (lastWins(m.byFaceName.get(card.faceName), card)) {
|
|
16922
|
+
m.byFaceName.set(card.faceName, card);
|
|
16923
|
+
}
|
|
16393
16924
|
const faceNorm = normalizeName(card.faceName);
|
|
16394
|
-
if (
|
|
16925
|
+
if (firstWins(m.byNormalizedFaceName.get(faceNorm), card)) {
|
|
16395
16926
|
m.byNormalizedFaceName.set(faceNorm, card);
|
|
16396
16927
|
}
|
|
16397
16928
|
}
|
|
16398
16929
|
}
|
|
16930
|
+
function isRealCard(card) {
|
|
16931
|
+
return card.commanderLegal || card.banned === true;
|
|
16932
|
+
}
|
|
16933
|
+
function lastWins(existing, incoming) {
|
|
16934
|
+
if (!existing) return true;
|
|
16935
|
+
return isRealCard(incoming) || !isRealCard(existing);
|
|
16936
|
+
}
|
|
16937
|
+
function firstWins(existing, incoming) {
|
|
16938
|
+
if (!existing) return true;
|
|
16939
|
+
return isRealCard(incoming) && !isRealCard(existing);
|
|
16940
|
+
}
|
|
16399
16941
|
function indexPass2aCard(card) {
|
|
16400
16942
|
if (!card.altNames || card.altNames.length === 0) return;
|
|
16401
16943
|
const keep = card.altNames.map(hasRenderableChar);
|
|
16402
16944
|
if (!keep.every(Boolean)) {
|
|
16403
16945
|
card.altNames = card.altNames.filter((_, i) => keep[i]);
|
|
16404
16946
|
if (card.altImages) card.altImages = card.altImages.filter((_, i) => keep[i]);
|
|
16947
|
+
if (card.altLangs) {
|
|
16948
|
+
const tags = card.altLangs;
|
|
16949
|
+
card.altLangs = [...tags].filter((_, i) => keep[i]).join("");
|
|
16950
|
+
}
|
|
16405
16951
|
if (card.altNames.length === 0) {
|
|
16406
16952
|
delete card.altNames;
|
|
16407
16953
|
delete card.altImages;
|
|
16954
|
+
delete card.altLangs;
|
|
16408
16955
|
delete card.searchAltNames;
|
|
16409
16956
|
delete card.searchAltNamesNorm;
|
|
16410
16957
|
return;
|
|
@@ -16715,11 +17262,13 @@ import { dirname, join as join4 } from "node:path";
|
|
|
16715
17262
|
var DATA_PATH = /^(?:commanders\/)?[a-z0-9_.-]+\.json$/i;
|
|
16716
17263
|
async function ensureFile(opts, name) {
|
|
16717
17264
|
if (!DATA_PATH.test(name) || name.includes("..")) throw new Error(`Not a data file name: ${name}`);
|
|
17265
|
+
return ensureRemote(opts, `/data/${name}`, join4("files", name));
|
|
17266
|
+
}
|
|
17267
|
+
async function ensureRemote(opts, urlPath, cacheRel) {
|
|
17268
|
+
if (cacheRel.includes("..") || !urlPath.startsWith("/")) throw new Error(`Not a site path: ${urlPath}`);
|
|
16718
17269
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
16719
17270
|
const origin = opts.origin ?? "https://edhvault.com";
|
|
16720
|
-
const
|
|
16721
|
-
mkdirSync2(dir, { recursive: true });
|
|
16722
|
-
const path = join4(dir, name);
|
|
17271
|
+
const path = join4(opts.dir, cacheRel);
|
|
16723
17272
|
mkdirSync2(dirname(path), { recursive: true });
|
|
16724
17273
|
const metaPath = `${path}.meta.json`;
|
|
16725
17274
|
const cached2 = existsSync2(path) && existsSync2(metaPath) ? JSON.parse(readFileSync4(metaPath, "utf8")) : null;
|
|
@@ -16728,7 +17277,7 @@ async function ensureFile(opts, name) {
|
|
|
16728
17277
|
if (cached2?.lastModified) headers["If-Modified-Since"] = cached2.lastModified;
|
|
16729
17278
|
let res;
|
|
16730
17279
|
try {
|
|
16731
|
-
res = await fetchImpl(`${origin}
|
|
17280
|
+
res = await fetchImpl(`${origin}${urlPath}`, { headers, signal: AbortSignal.timeout(opts.timeoutMs ?? 12e4) });
|
|
16732
17281
|
} catch (e) {
|
|
16733
17282
|
if (cached2) return { path, stale: true };
|
|
16734
17283
|
throw e;
|
|
@@ -16736,7 +17285,7 @@ async function ensureFile(opts, name) {
|
|
|
16736
17285
|
if (res.status === 304 && cached2) return { path, stale: false };
|
|
16737
17286
|
if (!res.ok) {
|
|
16738
17287
|
if (cached2) return { path, stale: true };
|
|
16739
|
-
throw new Error(`${
|
|
17288
|
+
throw new Error(`${urlPath.replace(/^\/data\//, "")}: ${res.status}`);
|
|
16740
17289
|
}
|
|
16741
17290
|
let body;
|
|
16742
17291
|
try {
|
|
@@ -16847,9 +17396,161 @@ function extrasLoader(opts) {
|
|
|
16847
17396
|
};
|
|
16848
17397
|
}
|
|
16849
17398
|
|
|
17399
|
+
// src/priceHistory.ts
|
|
17400
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync6, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
17401
|
+
import { dirname as dirname2, join as join6 } from "node:path";
|
|
17402
|
+
|
|
17403
|
+
// ../src/lib/priceHistory/format.ts
|
|
17404
|
+
var HISTORY_VERSION = 1;
|
|
17405
|
+
var FINISHES = ["n", "f", "e"];
|
|
17406
|
+
var HISTORY_SOURCE = "TCGplayer market prices via MTGJSON";
|
|
17407
|
+
var DAY_MS = 864e5;
|
|
17408
|
+
function epochDay(date5) {
|
|
17409
|
+
const t = Date.parse(`${date5.slice(0, 10)}T00:00:00Z`);
|
|
17410
|
+
return Number.isFinite(t) ? Math.round(t / DAY_MS) : NaN;
|
|
17411
|
+
}
|
|
17412
|
+
function dayToDate(day2) {
|
|
17413
|
+
return new Date(day2 * DAY_MS).toISOString().slice(0, 10);
|
|
17414
|
+
}
|
|
17415
|
+
function monthOf(day2) {
|
|
17416
|
+
return dayToDate(day2).slice(0, 7);
|
|
17417
|
+
}
|
|
17418
|
+
function decodeSeries(record2, length) {
|
|
17419
|
+
const out = new Array(length).fill(null);
|
|
17420
|
+
for (let i = 0; i < record2.length; i += 2) {
|
|
17421
|
+
const from = record2[i];
|
|
17422
|
+
const to = i + 2 < record2.length ? record2[i + 2] : length;
|
|
17423
|
+
const v = record2[i + 1] ?? null;
|
|
17424
|
+
for (let d = Math.max(0, from); d < Math.min(to, length); d++) out[d] = v;
|
|
17425
|
+
}
|
|
17426
|
+
return out;
|
|
17427
|
+
}
|
|
17428
|
+
var HISTORY_BASE = "/api/price-history";
|
|
17429
|
+
var manifestPath = () => "manifest.json";
|
|
17430
|
+
var monthIndexPath = (month, hash2) => `m/${month}.${hash2}.json`;
|
|
17431
|
+
var setMonthPath = (month, set3, hash2) => `s/${month}/${set3}.${hash2}.json`;
|
|
17432
|
+
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)$/;
|
|
17433
|
+
|
|
17434
|
+
// ../src/lib/priceHistory/load.ts
|
|
17435
|
+
init_build();
|
|
17436
|
+
init_fetchWithTimeout();
|
|
17437
|
+
var BUNDLE_MAX = 100;
|
|
17438
|
+
|
|
17439
|
+
// ../src/lib/priceHistory/vendors.ts
|
|
17440
|
+
var VENDOR_PRICES_VERSION = 1;
|
|
17441
|
+
var VENDOR_PRICES_SOURCE = "MTGJSON";
|
|
17442
|
+
var VENDOR_SET_RE = /^[a-z0-9]{2,8}$/;
|
|
17443
|
+
var vendorSetPath = (set3) => `vendors/${set3}.json`;
|
|
17444
|
+
|
|
17445
|
+
// src/priceHistory.ts
|
|
17446
|
+
var MANIFEST_FRESH_MS = 5 * 6e4;
|
|
17447
|
+
var VENDOR_FRESH_MS = 60 * 6e4;
|
|
17448
|
+
function priceHistoryLoader(opts, now = Date.now) {
|
|
17449
|
+
const root = "price-history";
|
|
17450
|
+
const dir = join6(opts.dir, root);
|
|
17451
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
17452
|
+
const origin = opts.origin ?? "https://edhvault.com";
|
|
17453
|
+
const staleSet = /* @__PURE__ */ new Set();
|
|
17454
|
+
const fresh = /* @__PURE__ */ new Map();
|
|
17455
|
+
const mutable = (key2, freshMs, read) => {
|
|
17456
|
+
const hit = fresh.get(key2);
|
|
17457
|
+
if (hit && now() - hit.at < freshMs) return hit.value;
|
|
17458
|
+
const value = (async () => {
|
|
17459
|
+
const got = await ensureRemote(opts, `${HISTORY_BASE}/${key2}`, join6(root, key2));
|
|
17460
|
+
if (got.stale) staleSet.add(key2);
|
|
17461
|
+
else staleSet.delete(key2);
|
|
17462
|
+
return read(JSON.parse(readFileSync6(got.path, "utf8")));
|
|
17463
|
+
})();
|
|
17464
|
+
fresh.set(key2, { at: now(), value });
|
|
17465
|
+
value.catch(() => fresh.delete(key2));
|
|
17466
|
+
return value;
|
|
17467
|
+
};
|
|
17468
|
+
const readKept = (key2) => {
|
|
17469
|
+
const path = join6(dir, key2);
|
|
17470
|
+
return existsSync4(path) ? JSON.parse(readFileSync6(path, "utf8")) : void 0;
|
|
17471
|
+
};
|
|
17472
|
+
const keep = (key2, value) => {
|
|
17473
|
+
const path = join6(dir, key2);
|
|
17474
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
17475
|
+
writeFileSync3(`${path}.incoming`, JSON.stringify(value));
|
|
17476
|
+
renameSync3(`${path}.incoming`, path);
|
|
17477
|
+
};
|
|
17478
|
+
const getJson = async (path) => {
|
|
17479
|
+
const res = await fetchImpl(`${origin}${HISTORY_BASE}/${path}`, { signal: AbortSignal.timeout(opts.timeoutMs ?? 12e4) });
|
|
17480
|
+
if (!res.ok) throw new Error(`price history ${path}: ${res.status}`);
|
|
17481
|
+
return await res.json();
|
|
17482
|
+
};
|
|
17483
|
+
const immutable = async (key2) => {
|
|
17484
|
+
if (!HISTORY_KEY_RE.test(key2)) throw new Error(`Not a price history file: ${key2}`);
|
|
17485
|
+
const hit = readKept(key2);
|
|
17486
|
+
if (hit !== void 0) return hit;
|
|
17487
|
+
const value = await getJson(key2);
|
|
17488
|
+
keep(key2, value);
|
|
17489
|
+
return value;
|
|
17490
|
+
};
|
|
17491
|
+
const manifest = () => mutable(manifestPath(), MANIFEST_FRESH_MS, (raw) => {
|
|
17492
|
+
const m = raw;
|
|
17493
|
+
if (m?.v !== HISTORY_VERSION || typeof m.months !== "object") throw new Error("The price history is from a newer version of EDHVault.");
|
|
17494
|
+
return m;
|
|
17495
|
+
});
|
|
17496
|
+
const prune = (live, months) => {
|
|
17497
|
+
for (const month of months) {
|
|
17498
|
+
const d = join6(dir, "s", month);
|
|
17499
|
+
if (!existsSync4(d)) continue;
|
|
17500
|
+
for (const f of readdirSync(d)) if (!f.endsWith(".incoming") && !live.has(`s/${month}/${f}`)) rmSync2(join6(d, f), { force: true });
|
|
17501
|
+
}
|
|
17502
|
+
};
|
|
17503
|
+
return {
|
|
17504
|
+
manifest,
|
|
17505
|
+
async setFiles(sets, fromMonth) {
|
|
17506
|
+
const m = await manifest();
|
|
17507
|
+
const months = Object.keys(m.months).filter((mo) => !fromMonth || mo >= fromMonth).sort();
|
|
17508
|
+
const wanted = new Set(sets.map((s) => s.toLowerCase()));
|
|
17509
|
+
const paths = [];
|
|
17510
|
+
for (const month of months) {
|
|
17511
|
+
const index = await immutable(monthIndexPath(month, m.months[month]));
|
|
17512
|
+
for (const [set3, hash2] of Object.entries(index.sets)) if (wanted.has(set3)) paths.push(setMonthPath(month, set3, hash2));
|
|
17513
|
+
}
|
|
17514
|
+
const files = [];
|
|
17515
|
+
const missing = [];
|
|
17516
|
+
for (const p of paths) {
|
|
17517
|
+
const hit = readKept(p);
|
|
17518
|
+
if (hit) files.push(hit);
|
|
17519
|
+
else missing.push(p);
|
|
17520
|
+
}
|
|
17521
|
+
for (let i = 0; i < missing.length; i += BUNDLE_MAX) {
|
|
17522
|
+
const keys = missing.slice(i, i + BUNDLE_MAX);
|
|
17523
|
+
const got = await getJson(`bundle?f=${keys.join(",")}`);
|
|
17524
|
+
for (const k of keys) {
|
|
17525
|
+
const f = got[k];
|
|
17526
|
+
if (!f) throw new Error(`price history bundle: ${k} missing`);
|
|
17527
|
+
keep(k, f);
|
|
17528
|
+
files.push(f);
|
|
17529
|
+
}
|
|
17530
|
+
}
|
|
17531
|
+
prune(new Set(paths), months.slice(-1));
|
|
17532
|
+
return files;
|
|
17533
|
+
},
|
|
17534
|
+
async vendorSet(set3) {
|
|
17535
|
+
const key2 = set3.toLowerCase();
|
|
17536
|
+
if (!VENDOR_SET_RE.test(key2)) return null;
|
|
17537
|
+
try {
|
|
17538
|
+
return await mutable(vendorSetPath(key2), VENDOR_FRESH_MS, (raw) => {
|
|
17539
|
+
const f = raw;
|
|
17540
|
+
return f?.v === VENDOR_PRICES_VERSION && f.p ? f : null;
|
|
17541
|
+
});
|
|
17542
|
+
} catch (e) {
|
|
17543
|
+
if (e instanceof Error && /: 404$/.test(e.message)) return null;
|
|
17544
|
+
throw e;
|
|
17545
|
+
}
|
|
17546
|
+
},
|
|
17547
|
+
stale: () => [...staleSet]
|
|
17548
|
+
};
|
|
17549
|
+
}
|
|
17550
|
+
|
|
16850
17551
|
// src/library.ts
|
|
16851
|
-
import { existsSync as
|
|
16852
|
-
import { join as
|
|
17552
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
17553
|
+
import { join as join7 } from "node:path";
|
|
16853
17554
|
|
|
16854
17555
|
// ../src/lib/sync/agentAccess.ts
|
|
16855
17556
|
init_sealedBox();
|
|
@@ -16915,6 +17616,23 @@ init_sealedBox();
|
|
|
16915
17616
|
init_syncKeys();
|
|
16916
17617
|
init_syncApi();
|
|
16917
17618
|
init_aiMarks();
|
|
17619
|
+
init_syncHistory();
|
|
17620
|
+
init_storage();
|
|
17621
|
+
var PUBLIC_FLAG = "isPublic";
|
|
17622
|
+
function decodeViewHistory(raw) {
|
|
17623
|
+
if (!Array.isArray(raw)) return [];
|
|
17624
|
+
let revived;
|
|
17625
|
+
try {
|
|
17626
|
+
revived = JSON.parse(JSON.stringify(raw), reviver);
|
|
17627
|
+
} catch {
|
|
17628
|
+
return [];
|
|
17629
|
+
}
|
|
17630
|
+
return revived.filter((c) => {
|
|
17631
|
+
const o = c;
|
|
17632
|
+
const plan = o?.snapshot?.plan;
|
|
17633
|
+
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;
|
|
17634
|
+
});
|
|
17635
|
+
}
|
|
16918
17636
|
var viewAad = (scope, name) => `v2:${scope}:${name}`;
|
|
16919
17637
|
var indexAad = (scope) => `v2:${scope}:index`;
|
|
16920
17638
|
function openViewObject(sealed, viewKey, scope, name) {
|
|
@@ -16927,11 +17645,13 @@ async function openViewIndex(sealed, viewKey, scope) {
|
|
|
16927
17645
|
}
|
|
16928
17646
|
return index;
|
|
16929
17647
|
}
|
|
17648
|
+
var VIEW_OBJECT_MAX_BYTES = 2 * 1024 * 1024;
|
|
16930
17649
|
var BATCH_PUTS = Math.min(250, SYNC_MAX_PUTS);
|
|
16931
17650
|
var BATCH_BYTES = 16 * 1024 * 1024;
|
|
16932
17651
|
|
|
16933
17652
|
// src/library.ts
|
|
16934
17653
|
init_storage();
|
|
17654
|
+
init_syncHistory();
|
|
16935
17655
|
init_syncApi();
|
|
16936
17656
|
var FRESH_MS = 2 * 6e4;
|
|
16937
17657
|
var GET_BATCH = 50;
|
|
@@ -16966,14 +17686,15 @@ function entries(index) {
|
|
|
16966
17686
|
return [
|
|
16967
17687
|
...Object.values(index.decks),
|
|
16968
17688
|
...index.lib ? [index.lib] : [],
|
|
16969
|
-
...Object.values(index.coll?.chunks ?? {})
|
|
17689
|
+
...Object.values(index.coll?.chunks ?? {}),
|
|
17690
|
+
...Object.values(index.hist ?? {}).filter((e) => e.obj)
|
|
16970
17691
|
];
|
|
16971
17692
|
}
|
|
16972
17693
|
var Library = class {
|
|
16973
17694
|
constructor(opts) {
|
|
16974
17695
|
this.opts = opts;
|
|
16975
|
-
this.cache =
|
|
16976
|
-
|
|
17696
|
+
this.cache = join7(opts.dir, "view2");
|
|
17697
|
+
rmSync3(join7(opts.dir, "view"), { recursive: true, force: true });
|
|
16977
17698
|
this.now = opts.now ?? Date.now;
|
|
16978
17699
|
this.freshMs = opts.freshMs ?? FRESH_MS;
|
|
16979
17700
|
}
|
|
@@ -16989,8 +17710,8 @@ var Library = class {
|
|
|
16989
17710
|
now;
|
|
16990
17711
|
freshMs;
|
|
16991
17712
|
forget() {
|
|
16992
|
-
|
|
16993
|
-
|
|
17713
|
+
rmSync3(this.cache, { recursive: true, force: true });
|
|
17714
|
+
rmSync3(join7(this.opts.dir, "requests"), { recursive: true, force: true });
|
|
16994
17715
|
this.parts.clear();
|
|
16995
17716
|
this.token = null;
|
|
16996
17717
|
this.keys = null;
|
|
@@ -17099,24 +17820,24 @@ var Library = class {
|
|
|
17099
17820
|
return part2.index;
|
|
17100
17821
|
}
|
|
17101
17822
|
dirOf(scope) {
|
|
17102
|
-
return
|
|
17823
|
+
return join7(this.cache, scope);
|
|
17103
17824
|
}
|
|
17104
17825
|
prune(scope, index) {
|
|
17105
17826
|
const dir = this.dirOf(scope);
|
|
17106
|
-
if (!
|
|
17827
|
+
if (!existsSync5(dir)) return;
|
|
17107
17828
|
const live = new Set(entries(index).map((e) => e.obj));
|
|
17108
|
-
for (const f of
|
|
17829
|
+
for (const f of readdirSync2(dir)) if (!live.has(f)) rmSync3(join7(dir, f), { force: true });
|
|
17109
17830
|
}
|
|
17110
17831
|
/** Object texts of one part by name, from the disk cache or batched reads. */
|
|
17111
17832
|
async read(scope, list) {
|
|
17112
17833
|
const { token, key: key2 } = await this.key(scope);
|
|
17113
17834
|
const dir = this.dirOf(scope);
|
|
17114
|
-
|
|
17835
|
+
mkdirSync4(dir, { recursive: true });
|
|
17115
17836
|
const sealed = /* @__PURE__ */ new Map();
|
|
17116
17837
|
const missing = [];
|
|
17117
17838
|
for (const e of list) {
|
|
17118
|
-
const file4 =
|
|
17119
|
-
if (
|
|
17839
|
+
const file4 = join7(dir, e.obj);
|
|
17840
|
+
if (existsSync5(file4)) sealed.set(e.obj, new Uint8Array(readFileSync7(file4)));
|
|
17120
17841
|
else missing.push(e.obj);
|
|
17121
17842
|
}
|
|
17122
17843
|
for (let i = 0; i < missing.length; i += GET_BATCH) {
|
|
@@ -17129,7 +17850,7 @@ var Library = class {
|
|
|
17129
17850
|
for (const [name, bytes] of got) {
|
|
17130
17851
|
if (!bytes) continue;
|
|
17131
17852
|
sealed.set(name, bytes);
|
|
17132
|
-
|
|
17853
|
+
writeFileSync4(join7(dir, name), bytes);
|
|
17133
17854
|
}
|
|
17134
17855
|
}
|
|
17135
17856
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -17161,6 +17882,23 @@ var Library = class {
|
|
|
17161
17882
|
const text = (await this.read("notes", [e])).get(e.obj);
|
|
17162
17883
|
return text ? JSON.parse(text, reviver) : null;
|
|
17163
17884
|
}
|
|
17885
|
+
/** One deck's History: its saved checkpoints (manual, auto and "as you left
|
|
17886
|
+
* it"), newest first, each with the cards it held. `null`: the read copy has
|
|
17887
|
+
* none for this deck (no History yet, or a copy an older EDHVault wrote). */
|
|
17888
|
+
async historyOf(id, refresh = false) {
|
|
17889
|
+
const index = await this.view("decks", refresh);
|
|
17890
|
+
const e = index.hist?.[id];
|
|
17891
|
+
if (!e) return null;
|
|
17892
|
+
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.");
|
|
17893
|
+
const text = (await this.read("decks", [e])).get(e.obj);
|
|
17894
|
+
const doc = text ? await unpackHistory(text) : null;
|
|
17895
|
+
return doc ? decodeViewHistory(doc.list).sort((a, b) => b.at - a.at) : null;
|
|
17896
|
+
}
|
|
17897
|
+
/** Whether the read copy carries History at all (written by a build that
|
|
17898
|
+
* copies it), so "no History" can be told from "not copied yet". */
|
|
17899
|
+
async historyCopied(refresh = false) {
|
|
17900
|
+
return (await this.view("decks", refresh)).hist !== void 0;
|
|
17901
|
+
}
|
|
17164
17902
|
/** Every collection stack. */
|
|
17165
17903
|
async collection(refresh = false) {
|
|
17166
17904
|
const index = await this.view("collection", refresh);
|
|
@@ -17203,7 +17941,7 @@ var Library = class {
|
|
|
17203
17941
|
return autoFromLetters(this.writes);
|
|
17204
17942
|
}
|
|
17205
17943
|
requestDir() {
|
|
17206
|
-
return
|
|
17944
|
+
return join7(this.opts.dir, "requests");
|
|
17207
17945
|
}
|
|
17208
17946
|
/** File a change request. The text is sealed here, under a key only this
|
|
17209
17947
|
* code and the user's own devices hold; a copy stays on disk, sealed, so
|
|
@@ -17225,8 +17963,8 @@ var Library = class {
|
|
|
17225
17963
|
this.fail(e);
|
|
17226
17964
|
}
|
|
17227
17965
|
if (r.status === "ok") {
|
|
17228
|
-
|
|
17229
|
-
|
|
17966
|
+
mkdirSync4(this.requestDir(), { recursive: true });
|
|
17967
|
+
writeFileSync4(join7(this.requestDir(), r.id), sealed);
|
|
17230
17968
|
}
|
|
17231
17969
|
return r;
|
|
17232
17970
|
}
|
|
@@ -17243,14 +17981,14 @@ var Library = class {
|
|
|
17243
17981
|
const agent = await deriveAgentKeys(this.secret);
|
|
17244
17982
|
const dir = this.requestDir();
|
|
17245
17983
|
const known = new Set(list.map((r) => r.id));
|
|
17246
|
-
if (
|
|
17247
|
-
for (const f of
|
|
17984
|
+
if (existsSync5(dir)) {
|
|
17985
|
+
for (const f of readdirSync2(dir)) if (!known.has(f)) rmSync3(join7(dir, f), { force: true });
|
|
17248
17986
|
}
|
|
17249
17987
|
return Promise.all(
|
|
17250
17988
|
list.map(async (r) => {
|
|
17251
|
-
const file4 =
|
|
17252
|
-
if (!keys.requests || !
|
|
17253
|
-
const text = await openAgentRequest(new Uint8Array(
|
|
17989
|
+
const file4 = join7(dir, r.id);
|
|
17990
|
+
if (!keys.requests || !existsSync5(file4)) return r;
|
|
17991
|
+
const text = await openAgentRequest(new Uint8Array(readFileSync7(file4)), keys.requests, agent.ah).catch(() => void 0);
|
|
17254
17992
|
return text ? { ...r, text } : r;
|
|
17255
17993
|
})
|
|
17256
17994
|
);
|
|
@@ -17258,14 +17996,14 @@ var Library = class {
|
|
|
17258
17996
|
};
|
|
17259
17997
|
|
|
17260
17998
|
// src/log.ts
|
|
17261
|
-
import { appendFileSync, mkdirSync as
|
|
17262
|
-
import { dirname as
|
|
17999
|
+
import { appendFileSync, mkdirSync as mkdirSync5 } from "node:fs";
|
|
18000
|
+
import { dirname as dirname3 } from "node:path";
|
|
17263
18001
|
var file = null;
|
|
17264
18002
|
var debugOn = false;
|
|
17265
18003
|
function configureLog(opts) {
|
|
17266
18004
|
file = opts.file ?? null;
|
|
17267
18005
|
debugOn = !!opts.debug;
|
|
17268
|
-
if (file)
|
|
18006
|
+
if (file) mkdirSync5(dirname3(file), { recursive: true });
|
|
17269
18007
|
}
|
|
17270
18008
|
function write(level, message) {
|
|
17271
18009
|
const line = `${(/* @__PURE__ */ new Date()).toISOString()} ${level} ${message}
|
|
@@ -17333,9 +18071,9 @@ async function redeemPairCode(text, t = {}, purpose = "sync") {
|
|
|
17333
18071
|
// src/secretStore.ts
|
|
17334
18072
|
init_syncKeys();
|
|
17335
18073
|
import { execFileSync } from "node:child_process";
|
|
17336
|
-
import { chmodSync, existsSync as
|
|
18074
|
+
import { chmodSync, existsSync as existsSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync8, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
17337
18075
|
import { userInfo } from "node:os";
|
|
17338
|
-
import { dirname as
|
|
18076
|
+
import { dirname as dirname4, join as join8 } from "node:path";
|
|
17339
18077
|
var SERVICE = "edhvault-mcp";
|
|
17340
18078
|
var ACCOUNT = "access-code";
|
|
17341
18079
|
async function osKeychain() {
|
|
@@ -17360,27 +18098,27 @@ function lockToOwner(file4) {
|
|
|
17360
18098
|
}
|
|
17361
18099
|
const windir = process.env.SystemRoot ?? "C:\\Windows";
|
|
17362
18100
|
execFileSync(
|
|
17363
|
-
|
|
18101
|
+
join8(windir, "System32", "icacls.exe"),
|
|
17364
18102
|
[file4, "/inheritance:r", "/grant:r", `${userInfo().username}:F`],
|
|
17365
18103
|
{ stdio: "ignore", windowsHide: true }
|
|
17366
18104
|
);
|
|
17367
18105
|
}
|
|
17368
18106
|
function fileKeychain(dir) {
|
|
17369
|
-
const file4 =
|
|
18107
|
+
const file4 = join8(dir, ACCOUNT);
|
|
17370
18108
|
return {
|
|
17371
|
-
get: () =>
|
|
18109
|
+
get: () => existsSync6(file4) ? readFileSync8(file4, "utf8").trim() : null,
|
|
17372
18110
|
set: (value) => {
|
|
17373
|
-
|
|
17374
|
-
|
|
18111
|
+
mkdirSync6(dirname4(file4), { recursive: true, mode: 448 });
|
|
18112
|
+
writeFileSync5(file4, "", { mode: 384 });
|
|
17375
18113
|
try {
|
|
17376
18114
|
lockToOwner(file4);
|
|
17377
18115
|
} catch (e) {
|
|
17378
|
-
|
|
18116
|
+
rmSync4(file4, { force: true });
|
|
17379
18117
|
throw new Error(`Couldn't make ${file4} private, so the code wasn't saved: ${e instanceof Error ? e.message : e}`);
|
|
17380
18118
|
}
|
|
17381
|
-
|
|
18119
|
+
writeFileSync5(file4, value);
|
|
17382
18120
|
},
|
|
17383
|
-
remove: () =>
|
|
18121
|
+
remove: () => rmSync4(file4, { force: true })
|
|
17384
18122
|
};
|
|
17385
18123
|
}
|
|
17386
18124
|
function saveSecret(store2, secret) {
|
|
@@ -17424,13 +18162,13 @@ async function login(code, store2, t) {
|
|
|
17424
18162
|
|
|
17425
18163
|
// src/paths.ts
|
|
17426
18164
|
import { homedir } from "node:os";
|
|
17427
|
-
import { join as
|
|
18165
|
+
import { join as join9 } from "node:path";
|
|
17428
18166
|
var ORIGIN = process.env.EDHVAULT_ORIGIN ?? "https://edhvault.com";
|
|
17429
18167
|
function configDir(env = process.env, platform = process.platform) {
|
|
17430
18168
|
if (env.EDHVAULT_MCP_HOME) return env.EDHVAULT_MCP_HOME;
|
|
17431
|
-
if (platform === "win32") return
|
|
17432
|
-
if (platform === "darwin") return
|
|
17433
|
-
return
|
|
18169
|
+
if (platform === "win32") return join9(env.APPDATA ?? join9(homedir(), "AppData", "Roaming"), "edhvault-mcp");
|
|
18170
|
+
if (platform === "darwin") return join9(homedir(), "Library", "Application Support", "edhvault-mcp");
|
|
18171
|
+
return join9(env.XDG_CONFIG_HOME ?? join9(homedir(), ".config"), "edhvault-mcp");
|
|
17434
18172
|
}
|
|
17435
18173
|
|
|
17436
18174
|
// ../../commander/node_modules/zod/v3/helpers/util.js
|
|
@@ -38617,7 +39355,7 @@ __export(external_exports, {
|
|
|
38617
39355
|
parse: () => parse3,
|
|
38618
39356
|
parseAsync: () => parseAsync2,
|
|
38619
39357
|
partialRecord: () => partialRecord,
|
|
38620
|
-
pipe: () =>
|
|
39358
|
+
pipe: () => pipe2,
|
|
38621
39359
|
positive: () => _positive,
|
|
38622
39360
|
prefault: () => prefault,
|
|
38623
39361
|
preprocess: () => preprocess,
|
|
@@ -38826,7 +39564,7 @@ __export(schemas_exports2, {
|
|
|
38826
39564
|
object: () => object2,
|
|
38827
39565
|
optional: () => optional,
|
|
38828
39566
|
partialRecord: () => partialRecord,
|
|
38829
|
-
pipe: () =>
|
|
39567
|
+
pipe: () => pipe2,
|
|
38830
39568
|
prefault: () => prefault,
|
|
38831
39569
|
preprocess: () => preprocess,
|
|
38832
39570
|
promise: () => promise,
|
|
@@ -39027,7 +39765,7 @@ var ZodType2 = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
39027
39765
|
return intersection(this, arg);
|
|
39028
39766
|
},
|
|
39029
39767
|
transform(tx) {
|
|
39030
|
-
return
|
|
39768
|
+
return pipe2(this, transform(tx));
|
|
39031
39769
|
},
|
|
39032
39770
|
default(d) {
|
|
39033
39771
|
return _default2(this, d);
|
|
@@ -39039,7 +39777,7 @@ var ZodType2 = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
39039
39777
|
return _catch2(this, params);
|
|
39040
39778
|
},
|
|
39041
39779
|
pipe(target) {
|
|
39042
|
-
return
|
|
39780
|
+
return pipe2(this, target);
|
|
39043
39781
|
},
|
|
39044
39782
|
readonly() {
|
|
39045
39783
|
return readonly(this);
|
|
@@ -40253,7 +40991,7 @@ var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
|
40253
40991
|
inst.in = def.in;
|
|
40254
40992
|
inst.out = def.out;
|
|
40255
40993
|
});
|
|
40256
|
-
function
|
|
40994
|
+
function pipe2(in_, out) {
|
|
40257
40995
|
return new ZodPipe({
|
|
40258
40996
|
type: "pipe",
|
|
40259
40997
|
in: in_,
|
|
@@ -46869,6 +47607,19 @@ var FIELD_ALIASES = {
|
|
|
46869
47607
|
condition: ["condition"],
|
|
46870
47608
|
language: ["language", "lang"]
|
|
46871
47609
|
};
|
|
47610
|
+
var ACQUIRED_ALIASES = {
|
|
47611
|
+
price: ["purchase price", "price paid", "purchased price", "acquired price"],
|
|
47612
|
+
currency: ["purchase price currency", "purchase currency", "currency"],
|
|
47613
|
+
date: ["added", "date added", "added at", "added on", "acquired", "acquired date", "purchase date", "date purchased"]
|
|
47614
|
+
};
|
|
47615
|
+
function pickExact(headers, aliases) {
|
|
47616
|
+
const lower = headers.map((h) => h.toLowerCase().trim());
|
|
47617
|
+
for (const alias of aliases) {
|
|
47618
|
+
const i = lower.indexOf(alias);
|
|
47619
|
+
if (i !== -1) return headers[i];
|
|
47620
|
+
}
|
|
47621
|
+
return null;
|
|
47622
|
+
}
|
|
46872
47623
|
function pickBinderTypeHeader(headers) {
|
|
46873
47624
|
const i = headers.findIndex((h) => h.toLowerCase().trim() === "binder type");
|
|
46874
47625
|
return i !== -1 ? headers[i] : null;
|
|
@@ -46908,7 +47659,7 @@ function detectCsvFormat(headers) {
|
|
|
46908
47659
|
}
|
|
46909
47660
|
return "unknown";
|
|
46910
47661
|
}
|
|
46911
|
-
function buildEntry(row, headerMap) {
|
|
47662
|
+
function buildEntry(row, headerMap, acq = { price: null, currency: null, date: null }) {
|
|
46912
47663
|
const nameHeader = headerMap.name;
|
|
46913
47664
|
if (!nameHeader) return null;
|
|
46914
47665
|
const rawName = row[nameHeader];
|
|
@@ -46922,6 +47673,9 @@ function buildEntry(row, headerMap) {
|
|
|
46922
47673
|
const foilRaw = headerMap.foil ? row[headerMap.foil] : void 0;
|
|
46923
47674
|
const conditionRaw = headerMap.condition ? row[headerMap.condition] : void 0;
|
|
46924
47675
|
const languageRaw = headerMap.language ? row[headerMap.language] : void 0;
|
|
47676
|
+
const price = acq.price ? parsePurchasePrice(row[acq.price]) : void 0;
|
|
47677
|
+
const date5 = acq.date ? parseAddedDate(row[acq.date]) : void 0;
|
|
47678
|
+
const currency = price !== void 0 && acq.currency ? row[acq.currency]?.trim().toUpperCase() : void 0;
|
|
46925
47679
|
return {
|
|
46926
47680
|
name,
|
|
46927
47681
|
quantity,
|
|
@@ -46929,7 +47683,11 @@ function buildEntry(row, headerMap) {
|
|
|
46929
47683
|
...collectorRaw ? { collectorNumber: collectorRaw.trim() } : {},
|
|
46930
47684
|
...foilRaw && isFoilLike(foilRaw) ? { foil: true } : {},
|
|
46931
47685
|
...conditionRaw ? { condition: conditionRaw.trim() } : {},
|
|
46932
|
-
...languageRaw ? { language: languageRaw.trim() } : {}
|
|
47686
|
+
...languageRaw ? { language: languageRaw.trim() } : {},
|
|
47687
|
+
...price !== void 0 || date5 ? {
|
|
47688
|
+
acquired: [{ quantity, ...price !== void 0 ? { price } : {}, ...date5 ? { date: date5 } : {} }],
|
|
47689
|
+
...currency && /^[A-Z]{3}$/.test(currency) ? { purchaseCurrency: currency } : {}
|
|
47690
|
+
} : {}
|
|
46933
47691
|
};
|
|
46934
47692
|
}
|
|
46935
47693
|
function looksLikePrice(value) {
|
|
@@ -46995,6 +47753,11 @@ async function parseCsv(input2) {
|
|
|
46995
47753
|
for (const field of Object.keys(FIELD_ALIASES)) {
|
|
46996
47754
|
headerMap[field] = pickHeader(headers, FIELD_ALIASES[field]);
|
|
46997
47755
|
}
|
|
47756
|
+
const acquiredHeaders = {
|
|
47757
|
+
price: pickExact(headers, ACQUIRED_ALIASES.price),
|
|
47758
|
+
currency: pickExact(headers, ACQUIRED_ALIASES.currency),
|
|
47759
|
+
date: pickExact(headers, ACQUIRED_ALIASES.date)
|
|
47760
|
+
};
|
|
46998
47761
|
const nameHeader = headerMap.name;
|
|
46999
47762
|
if (nameHeader) {
|
|
47000
47763
|
let repairedCount = 0;
|
|
@@ -47027,7 +47790,7 @@ async function parseCsv(input2) {
|
|
|
47027
47790
|
}
|
|
47028
47791
|
const entries2 = [];
|
|
47029
47792
|
for (const row of dataRows) {
|
|
47030
|
-
const entry = buildEntry(row, headerMap);
|
|
47793
|
+
const entry = buildEntry(row, headerMap, acquiredHeaders);
|
|
47031
47794
|
if (entry) entries2.push(entry);
|
|
47032
47795
|
}
|
|
47033
47796
|
return { entries: entries2, format, warnings };
|
|
@@ -47365,10 +48128,10 @@ var idbPrintingsCache = {
|
|
|
47365
48128
|
// ../src/lib/scryfall/resolvePrintings.ts
|
|
47366
48129
|
init_printings();
|
|
47367
48130
|
function createPrintingsResolver(source, cache2) {
|
|
47368
|
-
const
|
|
48131
|
+
const inflight2 = /* @__PURE__ */ new Map();
|
|
47369
48132
|
return function resolve(oracleId) {
|
|
47370
48133
|
if (!oracleId) return Promise.resolve({ status: "unavailable" });
|
|
47371
|
-
const pending =
|
|
48134
|
+
const pending = inflight2.get(oracleId);
|
|
47372
48135
|
if (pending) return pending;
|
|
47373
48136
|
const work = (async () => {
|
|
47374
48137
|
const cached2 = await cache2.get(oracleId);
|
|
@@ -47378,9 +48141,9 @@ function createPrintingsResolver(source, cache2) {
|
|
|
47378
48141
|
await cache2.put({ oracleId, printings: fetched, fetchedAt: Date.now() });
|
|
47379
48142
|
return { status: "ok", printings: fetched };
|
|
47380
48143
|
})();
|
|
47381
|
-
|
|
48144
|
+
inflight2.set(oracleId, work);
|
|
47382
48145
|
void work.finally(() => {
|
|
47383
|
-
if (
|
|
48146
|
+
if (inflight2.get(oracleId) === work) inflight2.delete(oracleId);
|
|
47384
48147
|
});
|
|
47385
48148
|
return work;
|
|
47386
48149
|
};
|
|
@@ -47521,6 +48284,190 @@ function colorsFit(card, allowed) {
|
|
|
47521
48284
|
return true;
|
|
47522
48285
|
}
|
|
47523
48286
|
|
|
48287
|
+
// ../src/lib/ranking/rankCommanders.ts
|
|
48288
|
+
var SYNERGY_DENOM_FLOOR = 30;
|
|
48289
|
+
function buildOwnedSlugs(ownedOracleIds, cards) {
|
|
48290
|
+
const slugs = /* @__PURE__ */ new Set();
|
|
48291
|
+
for (const oid of ownedOracleIds) addOwnedSlugs(slugs, oid, cards);
|
|
48292
|
+
return slugs;
|
|
48293
|
+
}
|
|
48294
|
+
function addOwnedSlugs(slugs, oid, cards) {
|
|
48295
|
+
const card = cards.byOracleId.get(oid);
|
|
48296
|
+
if (!card) return;
|
|
48297
|
+
slugs.add(toEdhrecSlug(card.name));
|
|
48298
|
+
if (card.name.includes(" // ")) {
|
|
48299
|
+
slugs.add(toEdhrecSlug(card.name, { joined: true }));
|
|
48300
|
+
}
|
|
48301
|
+
}
|
|
48302
|
+
var scoreCaches = /* @__PURE__ */ new WeakMap();
|
|
48303
|
+
function scoreCacheFor(ownedOracleIds, cards) {
|
|
48304
|
+
const hit = scoreCaches.get(ownedOracleIds);
|
|
48305
|
+
if (hit && hit.cards === cards) return hit;
|
|
48306
|
+
const fresh = {
|
|
48307
|
+
cards,
|
|
48308
|
+
ownedSlugs: buildOwnedSlugs(ownedOracleIds, cards),
|
|
48309
|
+
bySummary: /* @__PURE__ */ new WeakMap()
|
|
48310
|
+
};
|
|
48311
|
+
scoreCaches.set(ownedOracleIds, fresh);
|
|
48312
|
+
return fresh;
|
|
48313
|
+
}
|
|
48314
|
+
function scoredRow(cache2, summary) {
|
|
48315
|
+
let row = cache2.bySummary.get(summary);
|
|
48316
|
+
if (!row) {
|
|
48317
|
+
row = scoreCommander(summary, cache2.ownedSlugs, cache2.cards);
|
|
48318
|
+
cache2.bySummary.set(summary, row);
|
|
48319
|
+
}
|
|
48320
|
+
return row;
|
|
48321
|
+
}
|
|
48322
|
+
function scoreCommander(summary, ownedSlugs, cards) {
|
|
48323
|
+
let synergyOwned = 0;
|
|
48324
|
+
for (const slug of summary.pool) {
|
|
48325
|
+
if (ownedSlugs.has(slug)) synergyOwned++;
|
|
48326
|
+
}
|
|
48327
|
+
const directCard = findCardByName(cards, summary.name);
|
|
48328
|
+
const looksLikePartner = !directCard && summary.name.includes(" // ");
|
|
48329
|
+
let commanderOwned = false;
|
|
48330
|
+
let partiallyOwned = false;
|
|
48331
|
+
const ownedParts = [];
|
|
48332
|
+
const missingParts = [];
|
|
48333
|
+
let primarySlim;
|
|
48334
|
+
let partnerSlim;
|
|
48335
|
+
if (looksLikePartner) {
|
|
48336
|
+
const parts = summary.name.split(" // ").map((s) => s.trim());
|
|
48337
|
+
parts.forEach((part2, idx) => {
|
|
48338
|
+
const partCard = findCardByName(cards, part2);
|
|
48339
|
+
if (idx === 0) primarySlim = partCard;
|
|
48340
|
+
else if (idx === 1) partnerSlim = partCard;
|
|
48341
|
+
const isOwned = partCard ? ownedSlugs.has(toEdhrecSlug(partCard.name)) : ownedSlugs.has(toEdhrecSlug(part2));
|
|
48342
|
+
if (isOwned) ownedParts.push(part2);
|
|
48343
|
+
else missingParts.push(part2);
|
|
48344
|
+
});
|
|
48345
|
+
commanderOwned = missingParts.length === 0 && ownedParts.length > 0;
|
|
48346
|
+
partiallyOwned = ownedParts.length > 0 && missingParts.length > 0;
|
|
48347
|
+
} else {
|
|
48348
|
+
commanderOwned = directCard ? ownedSlugs.has(toEdhrecSlug(directCard.name)) : ownedSlugs.has(summary.slug);
|
|
48349
|
+
primarySlim = directCard;
|
|
48350
|
+
}
|
|
48351
|
+
const poolSize = summary.pool.length;
|
|
48352
|
+
const denom = Math.max(poolSize, SYNERGY_DENOM_FLOOR);
|
|
48353
|
+
const synergyRatio = denom > 0 ? synergyOwned / denom : 0;
|
|
48354
|
+
return {
|
|
48355
|
+
commander: summary,
|
|
48356
|
+
synergyOwned,
|
|
48357
|
+
poolSize,
|
|
48358
|
+
synergyRatio,
|
|
48359
|
+
commanderOwned,
|
|
48360
|
+
partiallyOwned,
|
|
48361
|
+
ownedParts,
|
|
48362
|
+
missingParts,
|
|
48363
|
+
...primarySlim ? { primarySlim } : {},
|
|
48364
|
+
...partnerSlim ? { partnerSlim } : {},
|
|
48365
|
+
...looksLikePartner ? { isPartnerPair: true } : {}
|
|
48366
|
+
};
|
|
48367
|
+
}
|
|
48368
|
+
function compareWeek(a, b) {
|
|
48369
|
+
const wa = a.commander.week;
|
|
48370
|
+
const wb = b.commander.week;
|
|
48371
|
+
if (wa && wb) return wb.decks - wa.decks || wa.rank - wb.rank;
|
|
48372
|
+
if (wa) return -1;
|
|
48373
|
+
if (wb) return 1;
|
|
48374
|
+
return b.commander.deckCount - a.commander.deckCount || b.synergyOwned - a.synergyOwned;
|
|
48375
|
+
}
|
|
48376
|
+
function commanderMatchesNameQuery(r, q) {
|
|
48377
|
+
if (normalizeForSearch(r.commander.name).includes(q)) return true;
|
|
48378
|
+
return [r.primarySlim, r.partnerSlim].some(
|
|
48379
|
+
(c) => c?.searchAltNamesNorm?.some((a) => a.includes(q)) === true
|
|
48380
|
+
);
|
|
48381
|
+
}
|
|
48382
|
+
function rankCommanders(summaries, ownedOracleIds, cards, opts = { sortBy: "synergy" }) {
|
|
48383
|
+
const cache2 = scoreCacheFor(ownedOracleIds, cards);
|
|
48384
|
+
let ranked = summaries.map((s) => scoredRow(cache2, s));
|
|
48385
|
+
if (opts.colors && opts.colors.length > 0) {
|
|
48386
|
+
const filter = new Set(opts.colors);
|
|
48387
|
+
const mode = opts.colorMode ?? "includes";
|
|
48388
|
+
ranked = ranked.filter(
|
|
48389
|
+
(r) => identityMatchesPips(r.commander.colors, filter, mode)
|
|
48390
|
+
);
|
|
48391
|
+
}
|
|
48392
|
+
if (opts.query) {
|
|
48393
|
+
const q = normalizeForSearch(opts.query);
|
|
48394
|
+
if (q) {
|
|
48395
|
+
ranked = ranked.filter((r) => commanderMatchesNameQuery(r, q));
|
|
48396
|
+
}
|
|
48397
|
+
}
|
|
48398
|
+
if (opts.brackets && opts.brackets.length > 0) {
|
|
48399
|
+
const allowed = new Set(opts.brackets);
|
|
48400
|
+
ranked = ranked.filter(
|
|
48401
|
+
(r) => r.commander.bracket !== void 0 && allowed.has(r.commander.bracket)
|
|
48402
|
+
);
|
|
48403
|
+
}
|
|
48404
|
+
if (opts.mvMin !== void 0 || opts.mvMax !== void 0) {
|
|
48405
|
+
const min = opts.mvMin ?? 0;
|
|
48406
|
+
const max = opts.mvMax ?? Number.POSITIVE_INFINITY;
|
|
48407
|
+
ranked = ranked.filter((r) => {
|
|
48408
|
+
const lookupName = r.commander.name.split(" // ")[0].toLowerCase();
|
|
48409
|
+
const card = cards.byName.get(lookupName) ?? cards.byFaceName.get(lookupName);
|
|
48410
|
+
if (!card) return true;
|
|
48411
|
+
return card.cmc >= min && card.cmc <= max;
|
|
48412
|
+
});
|
|
48413
|
+
}
|
|
48414
|
+
if (opts.saltMax !== void 0) {
|
|
48415
|
+
const max = opts.saltMax;
|
|
48416
|
+
ranked = ranked.filter((r) => {
|
|
48417
|
+
const lookupName = r.commander.name.split(" // ")[0];
|
|
48418
|
+
const score = saltScoreForName(lookupName);
|
|
48419
|
+
return score === void 0 || score <= max;
|
|
48420
|
+
});
|
|
48421
|
+
}
|
|
48422
|
+
const changeMemo = /* @__PURE__ */ new Map();
|
|
48423
|
+
const changeOfCommander = (r) => {
|
|
48424
|
+
if (!opts.changeOf) return void 0;
|
|
48425
|
+
const name = r.commander.name.split(" // ")[0];
|
|
48426
|
+
if (changeMemo.has(name)) return changeMemo.get(name);
|
|
48427
|
+
const card = resolveCardName(cards, name);
|
|
48428
|
+
const v = card ? opts.changeOf(card.oracleId) : void 0;
|
|
48429
|
+
changeMemo.set(name, v);
|
|
48430
|
+
return v;
|
|
48431
|
+
};
|
|
48432
|
+
const dir = opts.sortDir ?? "desc";
|
|
48433
|
+
const flip = (n) => dir === "desc" ? n : -n;
|
|
48434
|
+
const byPopularity2 = (a, b) => b.commander.deckCount - a.commander.deckCount || b.synergyOwned - a.synergyOwned;
|
|
48435
|
+
const byKnown = (va, vb, a, b) => {
|
|
48436
|
+
if (va !== void 0 && vb !== void 0) return flip(vb - va) || byPopularity2(a, b);
|
|
48437
|
+
if (va !== void 0) return -1;
|
|
48438
|
+
if (vb !== void 0) return 1;
|
|
48439
|
+
return byPopularity2(a, b);
|
|
48440
|
+
};
|
|
48441
|
+
ranked.sort((a, b) => {
|
|
48442
|
+
switch (opts.sortBy) {
|
|
48443
|
+
case "synergy":
|
|
48444
|
+
return flip(
|
|
48445
|
+
b.synergyRatio - a.synergyRatio || b.synergyOwned - a.synergyOwned || Number(b.commanderOwned) - Number(a.commanderOwned) || b.commander.deckCount - a.commander.deckCount
|
|
48446
|
+
);
|
|
48447
|
+
case "popularity":
|
|
48448
|
+
return flip(byPopularity2(a, b));
|
|
48449
|
+
case "salt":
|
|
48450
|
+
return byKnown(
|
|
48451
|
+
saltScoreForName(a.commander.name.split(" // ")[0]),
|
|
48452
|
+
saltScoreForName(b.commander.name.split(" // ")[0]),
|
|
48453
|
+
a,
|
|
48454
|
+
b
|
|
48455
|
+
);
|
|
48456
|
+
case "week": {
|
|
48457
|
+
const wa = a.commander.week;
|
|
48458
|
+
const wb = b.commander.week;
|
|
48459
|
+
if (wa && wb) return flip(wb.decks - wa.decks || wa.rank - wb.rank);
|
|
48460
|
+
return compareWeek(a, b);
|
|
48461
|
+
}
|
|
48462
|
+
case "change":
|
|
48463
|
+
return compareChange(changeOfCommander(a), changeOfCommander(b), dir) || byPopularity2(a, b);
|
|
48464
|
+
case "trending":
|
|
48465
|
+
return byKnown(a.commander.trend ?? void 0, b.commander.trend ?? void 0, a, b);
|
|
48466
|
+
}
|
|
48467
|
+
});
|
|
48468
|
+
return ranked;
|
|
48469
|
+
}
|
|
48470
|
+
|
|
47524
48471
|
// ../src/lib/commanders/inclusionDenominator.ts
|
|
47525
48472
|
function commanderInclusionDenominator(detail) {
|
|
47526
48473
|
let denom = detail.deckCount ?? 0;
|
|
@@ -47777,6 +48724,10 @@ function buildDeckSlots(detail, ownedOracleIds, cards, opts = {}) {
|
|
|
47777
48724
|
var CURVE_BUCKETS = ["0", "1", "2", "3", "4", "5", "6", "7+"];
|
|
47778
48725
|
var CURVE_BUCKET_COUNT = CURVE_BUCKETS.length;
|
|
47779
48726
|
var CURVE_TOP_BUCKET = CURVE_BUCKET_COUNT - 1;
|
|
48727
|
+
function bucketIndex(cmc) {
|
|
48728
|
+
const v = Math.max(0, Math.floor(cmc));
|
|
48729
|
+
return v >= CURVE_TOP_BUCKET ? CURVE_TOP_BUCKET : v;
|
|
48730
|
+
}
|
|
47780
48731
|
|
|
47781
48732
|
// ../src/lib/ranking/curveTarget.ts
|
|
47782
48733
|
var UNIVERSAL_COUNTS = [1, 6, 13, 13, 10, 8, 6, 6];
|
|
@@ -47791,6 +48742,22 @@ function normalizeToFractions(weights) {
|
|
|
47791
48742
|
}
|
|
47792
48743
|
return weights.map((w) => w / total);
|
|
47793
48744
|
}
|
|
48745
|
+
function targetCounts(curve, total) {
|
|
48746
|
+
const n = curve.fractions.length;
|
|
48747
|
+
if (total <= 0) return new Array(n).fill(0);
|
|
48748
|
+
const exact = curve.fractions.map((f) => f * total);
|
|
48749
|
+
const floors = exact.map((x) => Math.floor(x));
|
|
48750
|
+
let used = floors.reduce((s, x) => s + x, 0);
|
|
48751
|
+
let remaining = total - used;
|
|
48752
|
+
const order = exact.map((x, i) => ({ i, frac: x - Math.floor(x) })).sort((a, b) => b.frac - a.frac);
|
|
48753
|
+
const counts = floors.slice();
|
|
48754
|
+
for (const { i } of order) {
|
|
48755
|
+
if (remaining <= 0) break;
|
|
48756
|
+
counts[i] += 1;
|
|
48757
|
+
remaining -= 1;
|
|
48758
|
+
}
|
|
48759
|
+
return counts;
|
|
48760
|
+
}
|
|
47794
48761
|
|
|
47795
48762
|
// ../src/lib/deckPlan/importDeck.ts
|
|
47796
48763
|
init_utils();
|
|
@@ -48179,7 +49146,7 @@ function buildImportNotices(stats, format, hasCommander, commanderKnown = false)
|
|
|
48179
49146
|
function messageForKind(kind) {
|
|
48180
49147
|
switch (kind) {
|
|
48181
49148
|
case "not-found":
|
|
48182
|
-
return "We couldn't find that deck. It may not exist, or it may be private
|
|
49149
|
+
return "We couldn't find that deck. It may not exist, or it may be private: Archidekt doesn't tell us which. If it's private, make it public on Archidekt, or paste the decklist text here instead.";
|
|
48183
49150
|
case "unreachable":
|
|
48184
49151
|
return "Couldn't reach Archidekt just now. Try again in a moment, or paste the decklist text instead.";
|
|
48185
49152
|
case "empty":
|
|
@@ -48586,6 +49553,7 @@ init_storage();
|
|
|
48586
49553
|
// ../src/lib/savedDecks/crud.ts
|
|
48587
49554
|
init_storageKey();
|
|
48588
49555
|
init_storage();
|
|
49556
|
+
init_checkpointStore();
|
|
48589
49557
|
init_deckText();
|
|
48590
49558
|
init_emptyDeck();
|
|
48591
49559
|
|
|
@@ -48669,6 +49637,7 @@ init_storage2();
|
|
|
48669
49637
|
init_storage3();
|
|
48670
49638
|
init_manaOverrides();
|
|
48671
49639
|
init_oddsPlans();
|
|
49640
|
+
init_checkpointStore();
|
|
48672
49641
|
|
|
48673
49642
|
// ../src/lib/savedDecks/format.ts
|
|
48674
49643
|
var VERBOSE_DATE = new Intl.DateTimeFormat("en-US", {
|
|
@@ -48677,7 +49646,7 @@ var VERBOSE_DATE = new Intl.DateTimeFormat("en-US", {
|
|
|
48677
49646
|
month: "long",
|
|
48678
49647
|
day: "numeric"
|
|
48679
49648
|
});
|
|
48680
|
-
var
|
|
49649
|
+
var DAY_MS3 = 24 * 60 * 60 * 1e3;
|
|
48681
49650
|
|
|
48682
49651
|
// ../src/lib/savedDecks/crossDeck.ts
|
|
48683
49652
|
init_utils();
|
|
@@ -48752,6 +49721,38 @@ var createImpl = (createState) => {
|
|
|
48752
49721
|
};
|
|
48753
49722
|
var create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
48754
49723
|
|
|
49724
|
+
// ../src/lib/scryfall/identityArt.ts
|
|
49725
|
+
async function deriveIdentityArt(wanted) {
|
|
49726
|
+
const out = /* @__PURE__ */ new Map();
|
|
49727
|
+
if (wanted.length === 0) return out;
|
|
49728
|
+
const ids = (ws) => ws.map((w) => ({ set: w.set, collectorNumber: w.collectorNumber }));
|
|
49729
|
+
let baked = /* @__PURE__ */ new Map();
|
|
49730
|
+
try {
|
|
49731
|
+
baked = await getBakedIdentityArt(ids(wanted));
|
|
49732
|
+
} catch {
|
|
49733
|
+
}
|
|
49734
|
+
const misses = wanted.filter(
|
|
49735
|
+
(w) => !baked.has(printingKey(w.set, w.collectorNumber))
|
|
49736
|
+
);
|
|
49737
|
+
let live = /* @__PURE__ */ new Map();
|
|
49738
|
+
if (misses.length > 0) {
|
|
49739
|
+
try {
|
|
49740
|
+
live = await resolvePrintingsByIdentity(ids(misses));
|
|
49741
|
+
} catch {
|
|
49742
|
+
}
|
|
49743
|
+
}
|
|
49744
|
+
for (const w of wanted) {
|
|
49745
|
+
const key2 = printingKey(w.set, w.collectorNumber);
|
|
49746
|
+
const rec = baked.get(key2) ?? live.get(key2);
|
|
49747
|
+
if (!rec || rec.oracleId !== w.oracleId || !rec.image) continue;
|
|
49748
|
+
out.set(key2, {
|
|
49749
|
+
image: rec.image,
|
|
49750
|
+
...rec.backImage ? { backImage: rec.backImage } : {}
|
|
49751
|
+
});
|
|
49752
|
+
}
|
|
49753
|
+
return out;
|
|
49754
|
+
}
|
|
49755
|
+
|
|
48755
49756
|
// ../src/state/deckPrintingOverrides.ts
|
|
48756
49757
|
var useDeckPrintingOverrides = create(
|
|
48757
49758
|
(set3, get) => ({
|
|
@@ -48785,35 +49786,9 @@ async function resolveMissingArt(overrides, set3, get) {
|
|
|
48785
49786
|
wanted.push({ oracleId, set: ov.set, collectorNumber: ov.collectorNumber });
|
|
48786
49787
|
}
|
|
48787
49788
|
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 });
|
|
49789
|
+
const derived2 = await deriveIdentityArt(wanted);
|
|
49790
|
+
if (derived2.size === 0) return;
|
|
49791
|
+
set3({ resolvedArt: new Map([...get().resolvedArt, ...derived2]) });
|
|
48817
49792
|
}
|
|
48818
49793
|
|
|
48819
49794
|
// ../src/components/deckBuilderV2/v2CategoryOps.ts
|
|
@@ -49027,15 +50002,25 @@ function isTwoCardInfiniteCombo(v) {
|
|
|
49027
50002
|
function comboKey(v) {
|
|
49028
50003
|
return (v.uses ?? []).map((u) => u.card?.name?.trim().toLowerCase() ?? "").filter(Boolean).sort().join("|");
|
|
49029
50004
|
}
|
|
49030
|
-
function
|
|
50005
|
+
function listTwoCardInfiniteCombos(included) {
|
|
49031
50006
|
const seen = /* @__PURE__ */ new Set();
|
|
50007
|
+
const out = [];
|
|
49032
50008
|
for (const v of included) {
|
|
49033
50009
|
if (!isTwoCardInfiniteCombo(v)) continue;
|
|
49034
50010
|
const key2 = comboKey(v);
|
|
49035
50011
|
if (!key2 || seen.has(key2)) continue;
|
|
49036
50012
|
seen.add(key2);
|
|
50013
|
+
out.push({
|
|
50014
|
+
key: key2,
|
|
50015
|
+
cards: (v.uses ?? []).map((u) => u.card?.name ?? "").filter(Boolean),
|
|
50016
|
+
produces: (v.produces ?? []).map((p) => p.feature?.name ?? "").filter(Boolean),
|
|
50017
|
+
...v.bracketTag ? { bracketTag: v.bracketTag } : {}
|
|
50018
|
+
});
|
|
49037
50019
|
}
|
|
49038
|
-
return
|
|
50020
|
+
return out;
|
|
50021
|
+
}
|
|
50022
|
+
function countTwoCardInfiniteCombos(included) {
|
|
50023
|
+
return listTwoCardInfiniteCombos(included).length;
|
|
49039
50024
|
}
|
|
49040
50025
|
|
|
49041
50026
|
// ../src/lib/combos/deckCards.ts
|
|
@@ -50850,6 +51835,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
50850
51835
|
// Hour of Victory
|
|
50851
51836
|
"d95d0b24-2e6f-4f61-8668-26effeaaf2fb": { "r": "finds a card by name" },
|
|
50852
51837
|
// Howling Wolf
|
|
51838
|
+
"f129e01f-cb3b-439d-b1eb-5e253557e814": { "a": [{ "types": [["basic", "land"]] }] },
|
|
51839
|
+
// Huatli, Inventor's Inspiration
|
|
50853
51840
|
"2e6ed3e6-d2b8-4b75-b7e1-0773da4987a1": { "a": [{ "types": [["basic", "land"]] }, { "types": [["dinosaur"]] }] },
|
|
50854
51841
|
// Huatli, Poet of Unity // Roar of the Fifth People
|
|
50855
51842
|
"a7285536-6cc1-448e-839a-606d585fbd9d": { "a": [{ "types": [["basic", "land"]] }] },
|
|
@@ -50958,6 +51945,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
50958
51945
|
// Keys to the House
|
|
50959
51946
|
"be6155de-c5b2-415c-ad83-142f9926462a": { "a": [{ "types": [["basic", "land"]] }] },
|
|
50960
51947
|
// Khalni Heart Expedition
|
|
51948
|
+
"025ceb73-5b00-4ac8-a20b-1126505fab68": { "a": [{ "types": [["basic", "land"]] }] },
|
|
51949
|
+
// King Tiro of Meletis
|
|
50961
51950
|
"a3d68848-e8cc-497c-951b-e7111f6d5142": { "a": [{ "types": [["kithkin"]] }] },
|
|
50962
51951
|
// Kithkin Harbinger
|
|
50963
51952
|
"393e5331-4456-4ba3-b410-bb630bb053db": { "a": [{ "types": [["land"]] }] },
|
|
@@ -51448,6 +52437,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
51448
52437
|
// Roamer's Routine
|
|
51449
52438
|
"41c765a4-a9c9-4169-a9f1-74ededeb793c": { "a": [{ "types": [["creature"]] }] },
|
|
51450
52439
|
// Rocco, Cabaretti Caterer
|
|
52440
|
+
"d3e182c0-54d1-4d06-a9f3-b6671a084a15": { "a": [{ "types": [["creature"]] }] },
|
|
52441
|
+
// Rocco, Snack Supplier
|
|
51451
52442
|
"f9330a7b-8a65-4e04-a777-bf6512332850": { "a": [{ "types": [["forest"]] }] },
|
|
51452
52443
|
// Rocksteady, Crash Courser
|
|
51453
52444
|
"8709b5b1-ef9e-45b2-bf4f-ef4c4d613dcd": { "a": [{ "types": [["swamp"], ["mountain"]] }] },
|
|
@@ -51566,6 +52557,8 @@ var TUTOR_TEXT_REACH = {
|
|
|
51566
52557
|
// Shadow-Rite Priest
|
|
51567
52558
|
"595a15f0-77f3-4544-8acc-10630e12cc14": { "a": [{ "types": [["demon", "creature"]] }] },
|
|
51568
52559
|
// Shadowborn Apostle
|
|
52560
|
+
"155ee70b-898c-472f-a5e7-71f14da94894": { "a": [{ "types": [["basic", "land"]] }, { "types": [["desert"]] }] },
|
|
52561
|
+
// Shai-Hulud
|
|
51569
52562
|
"c51fc4f2-76a6-4337-ab8f-1b3e84f82019": { "a": [{ "types": [["plains"]] }, { "types": [["island"]] }, { "types": [["swamp"]] }, { "types": [["mountain"]] }] },
|
|
51570
52563
|
// Shard Convergence
|
|
51571
52564
|
"823afa57-faac-4a43-a403-c1bb0446d594": { "a": [{ "types": [["basic", "land"]] }] },
|
|
@@ -51710,8 +52703,6 @@ var TUTOR_TEXT_REACH = {
|
|
|
51710
52703
|
// Stoneforge Mystic
|
|
51711
52704
|
"b3d99ea0-d61f-4394-8913-b4057c38ff3e": { "a": [{ "types": [["equipment"]] }] },
|
|
51712
52705
|
// Stonehewer Giant
|
|
51713
|
-
"a500b724-bf28-47a3-b434-6efdebbcc04c": { "a": [{ "types": [["land"]] }] },
|
|
51714
|
-
// Strata Scythe
|
|
51715
52706
|
"36ab41b7-bcfb-4618-bbfb-70d608dba15a": { "a": [{ "types": [["basic", "land"]] }] },
|
|
51716
52707
|
// Stratosoarer
|
|
51717
52708
|
"e286a191-39d4-4073-b844-11d2aba911b4": { "a": [{ "types": [["basic", "land"]] }] },
|
|
@@ -52326,9 +53317,9 @@ var UNCHECKABLE_SUBTAGS = /* @__PURE__ */ new Set([
|
|
|
52326
53317
|
"praetor"
|
|
52327
53318
|
]);
|
|
52328
53319
|
function parseTarget(target) {
|
|
52329
|
-
const
|
|
53320
|
+
const front2 = (target.typeLine.split(" // ")[0] ?? target.typeLine).toLowerCase();
|
|
52330
53321
|
return {
|
|
52331
|
-
words: new Set(
|
|
53322
|
+
words: new Set(front2.split(/[\s—]+/).filter(Boolean)),
|
|
52332
53323
|
cmc: target.cmc,
|
|
52333
53324
|
colors: target.colors,
|
|
52334
53325
|
keywords: target.keywords,
|
|
@@ -53040,6 +54031,10 @@ function budgetStatus(spent, budget) {
|
|
|
53040
54031
|
return { over: spent > budget, delta: spent - budget };
|
|
53041
54032
|
}
|
|
53042
54033
|
|
|
54034
|
+
// ../src/lib/deckPlan/hooks/useDeckActions.ts
|
|
54035
|
+
var import_react2 = __toESM(require_react(), 1);
|
|
54036
|
+
init_utils();
|
|
54037
|
+
|
|
53043
54038
|
// ../src/lib/deckPlan/karstenTable.generated.ts
|
|
53044
54039
|
var KARSTEN_2022 = {
|
|
53045
54040
|
landsFrom: 28,
|
|
@@ -53210,6 +54205,12 @@ function distributeBasics(pips, identity2, slotCount) {
|
|
|
53210
54205
|
}
|
|
53211
54206
|
return out;
|
|
53212
54207
|
}
|
|
54208
|
+
var COLORLESS_BASICS_FLOOR = 7;
|
|
54209
|
+
function minBasics(colorCount) {
|
|
54210
|
+
if (colorCount === 0) return COLORLESS_BASICS_FLOOR;
|
|
54211
|
+
if (colorCount === 1) return 0;
|
|
54212
|
+
return Math.min(Math.max(2 * colorCount, 4), 6);
|
|
54213
|
+
}
|
|
53213
54214
|
var BASIC_NAME = {
|
|
53214
54215
|
W: "Plains",
|
|
53215
54216
|
U: "Island",
|
|
@@ -53217,6 +54218,7 @@ var BASIC_NAME = {
|
|
|
53217
54218
|
R: "Mountain",
|
|
53218
54219
|
G: "Forest"
|
|
53219
54220
|
};
|
|
54221
|
+
var WASTES_NAME = "Wastes";
|
|
53220
54222
|
var KARSTEN_LANDS_RANGE = { min: KARSTEN_2022.landsFrom, max: KARSTEN_2022.landsTo };
|
|
53221
54223
|
function karstenTarget(pips, mv, lands) {
|
|
53222
54224
|
if (pips <= 0) return 0;
|
|
@@ -53283,6 +54285,17 @@ function cardTarget(card, color, lands) {
|
|
|
53283
54285
|
const colours = WUBRG_ORDER.filter((c) => (p?.[c] ?? 0) > 0).length;
|
|
53284
54286
|
return karstenTarget(pips, card.cmc, lands) + (colours >= 2 ? 1 : 0);
|
|
53285
54287
|
}
|
|
54288
|
+
function karstenTargetsByColor(cards, lands) {
|
|
54289
|
+
const out = { W: 0, U: 0, B: 0, R: 0, G: 0 };
|
|
54290
|
+
for (const c of cards) {
|
|
54291
|
+
if (!c.colorPips) continue;
|
|
54292
|
+
for (const color of WUBRG_ORDER) {
|
|
54293
|
+
const t = cardTarget(c, color, lands);
|
|
54294
|
+
if (t > out[color]) out[color] = t;
|
|
54295
|
+
}
|
|
54296
|
+
}
|
|
54297
|
+
return out;
|
|
54298
|
+
}
|
|
53286
54299
|
function fetchableColors(fetch2, lands) {
|
|
53287
54300
|
const out = /* @__PURE__ */ new Set();
|
|
53288
54301
|
const f = fetch2.fetches;
|
|
@@ -53298,6 +54311,511 @@ function fetchableColors(fetch2, lands) {
|
|
|
53298
54311
|
}
|
|
53299
54312
|
return out;
|
|
53300
54313
|
}
|
|
54314
|
+
function sourcesByColor(lands) {
|
|
54315
|
+
const out = { W: 0, U: 0, B: 0, R: 0, G: 0 };
|
|
54316
|
+
for (const c of lands) {
|
|
54317
|
+
const pm = c.producedMana;
|
|
54318
|
+
if (!pm) continue;
|
|
54319
|
+
for (const color of WUBRG_ORDER) if (pm.includes(color)) out[color] += 1;
|
|
54320
|
+
}
|
|
54321
|
+
return out;
|
|
54322
|
+
}
|
|
54323
|
+
function nonBasicAllowance(colorCount) {
|
|
54324
|
+
switch (colorCount) {
|
|
54325
|
+
case 0:
|
|
54326
|
+
return 99;
|
|
54327
|
+
// colorless: no colored basics to reserve; Wastes floor is separate
|
|
54328
|
+
case 1:
|
|
54329
|
+
return 12;
|
|
54330
|
+
case 2:
|
|
54331
|
+
return 20;
|
|
54332
|
+
case 3:
|
|
54333
|
+
return 26;
|
|
54334
|
+
case 4:
|
|
54335
|
+
return 30;
|
|
54336
|
+
default:
|
|
54337
|
+
return 33;
|
|
54338
|
+
}
|
|
54339
|
+
}
|
|
54340
|
+
function distributeBasicsBySources(targets, supply, identity2, seats) {
|
|
54341
|
+
const out = { W: 0, U: 0, B: 0, R: 0, G: 0 };
|
|
54342
|
+
if (seats <= 0) return out;
|
|
54343
|
+
const allowed = WUBRG_ORDER.filter((c) => identity2.includes(c));
|
|
54344
|
+
if (allowed.length === 0) return out;
|
|
54345
|
+
const demanded = allowed.filter((c) => targets[c] > 0);
|
|
54346
|
+
if (demanded.length === 0) {
|
|
54347
|
+
return distributeBasics({ W: 0, U: 0, B: 0, R: 0, G: 0 }, identity2, seats);
|
|
54348
|
+
}
|
|
54349
|
+
const running = { ...supply };
|
|
54350
|
+
let placed = 0;
|
|
54351
|
+
for (const c of demanded) {
|
|
54352
|
+
if (placed >= seats) break;
|
|
54353
|
+
if (running[c] <= 0) {
|
|
54354
|
+
out[c] += 1;
|
|
54355
|
+
running[c] += 1;
|
|
54356
|
+
placed += 1;
|
|
54357
|
+
}
|
|
54358
|
+
}
|
|
54359
|
+
for (; placed < seats; placed++) {
|
|
54360
|
+
let best = demanded[0];
|
|
54361
|
+
let bestDeficit = targets[best] - running[best];
|
|
54362
|
+
for (const c of demanded) {
|
|
54363
|
+
const deficit = targets[c] - running[c];
|
|
54364
|
+
if (deficit > bestDeficit) {
|
|
54365
|
+
bestDeficit = deficit;
|
|
54366
|
+
best = c;
|
|
54367
|
+
}
|
|
54368
|
+
}
|
|
54369
|
+
out[best] += 1;
|
|
54370
|
+
running[best] += 1;
|
|
54371
|
+
}
|
|
54372
|
+
return out;
|
|
54373
|
+
}
|
|
54374
|
+
|
|
54375
|
+
// ../src/lib/deckPlan/applySeeds.ts
|
|
54376
|
+
init_slug();
|
|
54377
|
+
|
|
54378
|
+
// ../src/lib/deckPlan/hooks/useDeckActions.ts
|
|
54379
|
+
var RANK_SYNERGY_WEIGHT = 1;
|
|
54380
|
+
var CURVE_PENALTY_WEIGHT = 0.15;
|
|
54381
|
+
var CURVE_7PLUS_CEILING_SLACK = 2;
|
|
54382
|
+
function rankScore(item, mode) {
|
|
54383
|
+
if (mode === "popularity") return item.inclusion;
|
|
54384
|
+
return item.inclusionPct + RANK_SYNERGY_WEIGHT * Math.max(0, item.synergy);
|
|
54385
|
+
}
|
|
54386
|
+
function gcAllowanceForBracket(bracket) {
|
|
54387
|
+
if (bracket === void 0) return Infinity;
|
|
54388
|
+
if (bracket <= 2) return 0;
|
|
54389
|
+
if (bracket === 3) return 3;
|
|
54390
|
+
return Infinity;
|
|
54391
|
+
}
|
|
54392
|
+
function withinPriceCap(priceUsd, cap2) {
|
|
54393
|
+
if (cap2 == null) return true;
|
|
54394
|
+
return priceUsd === void 0 || priceUsd <= cap2;
|
|
54395
|
+
}
|
|
54396
|
+
function fillLands(landsSlot, ownedTaken, newAssignments, newBasicQty, nonLandsCommitted, ownedQtyForCard, effectiveDetail, opts) {
|
|
54397
|
+
let filled = 0;
|
|
54398
|
+
const need = landsSlot.target;
|
|
54399
|
+
const identity2 = effectiveDetail?.colors ?? [];
|
|
54400
|
+
const colorCount = identity2.length;
|
|
54401
|
+
const floor = colorCount === 0 ? Math.min(minBasics(0), need) : Math.max(0, need - Math.min(need, nonBasicAllowance(colorCount)));
|
|
54402
|
+
const nonBasicCap = need - floor;
|
|
54403
|
+
const placedNonBasics = [];
|
|
54404
|
+
const sortedOwned = [...landsSlot.owned].sort(
|
|
54405
|
+
(a, b) => b.inclusion - a.inclusion
|
|
54406
|
+
);
|
|
54407
|
+
const ownedBasicByColor = {};
|
|
54408
|
+
let ownedWastes;
|
|
54409
|
+
const heldNonBasics = [];
|
|
54410
|
+
for (const item of sortedOwned) {
|
|
54411
|
+
const isBasic = isBasicLandType(item.card.typeLine);
|
|
54412
|
+
if (isBasic) {
|
|
54413
|
+
for (const c of item.card.colors) {
|
|
54414
|
+
ownedBasicByColor[c] ??= item.card;
|
|
54415
|
+
}
|
|
54416
|
+
if (item.card.colors.length === 0) ownedWastes ??= item.card;
|
|
54417
|
+
continue;
|
|
54418
|
+
}
|
|
54419
|
+
if (ownedTaken.has(item.card.oracleId)) continue;
|
|
54420
|
+
if (filled >= nonBasicCap) {
|
|
54421
|
+
heldNonBasics.push(item.card);
|
|
54422
|
+
continue;
|
|
54423
|
+
}
|
|
54424
|
+
newAssignments.set(item.card.oracleId, landsSlot.slot);
|
|
54425
|
+
ownedTaken.add(item.card.oracleId);
|
|
54426
|
+
placedNonBasics.push(item.card);
|
|
54427
|
+
filled++;
|
|
54428
|
+
}
|
|
54429
|
+
if (opts && filled < nonBasicCap) {
|
|
54430
|
+
const sortedSuggestions = [...landsSlot.suggestions].filter((s) => withinPriceCap(s.card?.priceUsd, opts.priceCap)).sort((a, b) => b.inclusion - a.inclusion);
|
|
54431
|
+
for (const sug of sortedSuggestions) {
|
|
54432
|
+
if (filled >= nonBasicCap) break;
|
|
54433
|
+
if (opts.purchasedTaken.has(sug.slug)) continue;
|
|
54434
|
+
opts.purchases.set(sug.slug, landsSlot.slot);
|
|
54435
|
+
opts.purchasedTaken.add(sug.slug);
|
|
54436
|
+
if (sug.card) placedNonBasics.push(sug.card);
|
|
54437
|
+
filled++;
|
|
54438
|
+
}
|
|
54439
|
+
}
|
|
54440
|
+
const remaining = Math.max(0, need - filled);
|
|
54441
|
+
if (remaining > 0 && identity2.length === 0) {
|
|
54442
|
+
let wastes = ownedWastes;
|
|
54443
|
+
if (!wastes && opts?.cards) {
|
|
54444
|
+
wastes = findCardByName(opts.cards, WASTES_NAME);
|
|
54445
|
+
}
|
|
54446
|
+
if (wastes) {
|
|
54447
|
+
const planned = opts ? remaining : Math.min(remaining, ownedQtyForCard(wastes.oracleId));
|
|
54448
|
+
if (planned > 0) {
|
|
54449
|
+
if (!ownedTaken.has(wastes.oracleId)) {
|
|
54450
|
+
newAssignments.set(wastes.oracleId, landsSlot.slot);
|
|
54451
|
+
ownedTaken.add(wastes.oracleId);
|
|
54452
|
+
}
|
|
54453
|
+
if (planned > 1) newBasicQty.set(wastes.oracleId, planned);
|
|
54454
|
+
filled += planned;
|
|
54455
|
+
}
|
|
54456
|
+
}
|
|
54457
|
+
} else if (remaining > 0) {
|
|
54458
|
+
const targets = karstenTargetsByColor(nonLandsCommitted, need);
|
|
54459
|
+
const supply = sourcesByColor(placedNonBasics);
|
|
54460
|
+
const want = distributeBasicsBySources(targets, supply, identity2, remaining);
|
|
54461
|
+
for (const color of WUBRG_ORDER) {
|
|
54462
|
+
const targetCount = want[color];
|
|
54463
|
+
if (targetCount === 0) continue;
|
|
54464
|
+
let basicCard = ownedBasicByColor[color];
|
|
54465
|
+
if (!basicCard && opts?.cards) {
|
|
54466
|
+
basicCard = findCardByName(opts.cards, BASIC_NAME[color]);
|
|
54467
|
+
}
|
|
54468
|
+
if (!basicCard) continue;
|
|
54469
|
+
const planned = opts ? targetCount : Math.min(targetCount, ownedQtyForCard(basicCard.oracleId));
|
|
54470
|
+
if (planned <= 0) continue;
|
|
54471
|
+
if (!ownedTaken.has(basicCard.oracleId)) {
|
|
54472
|
+
newAssignments.set(basicCard.oracleId, landsSlot.slot);
|
|
54473
|
+
ownedTaken.add(basicCard.oracleId);
|
|
54474
|
+
}
|
|
54475
|
+
if (planned > 1) newBasicQty.set(basicCard.oracleId, planned);
|
|
54476
|
+
filled += planned;
|
|
54477
|
+
}
|
|
54478
|
+
}
|
|
54479
|
+
if (filled < need && heldNonBasics.length > 0) {
|
|
54480
|
+
for (const card of heldNonBasics) {
|
|
54481
|
+
if (filled >= need) break;
|
|
54482
|
+
if (ownedTaken.has(card.oracleId)) continue;
|
|
54483
|
+
newAssignments.set(card.oracleId, landsSlot.slot);
|
|
54484
|
+
ownedTaken.add(card.oracleId);
|
|
54485
|
+
filled++;
|
|
54486
|
+
}
|
|
54487
|
+
}
|
|
54488
|
+
}
|
|
54489
|
+
function computeBestBuildPlan(slots, ownedQtyForCard, effectiveDetail, useQualityFloor = true, rankMode = "popularity", targetCurve = void 0, targetBracket = void 0, cards = null, priceCap = null, ownedOnly = false) {
|
|
54490
|
+
const newAssignments = /* @__PURE__ */ new Map();
|
|
54491
|
+
const newPurchases = /* @__PURE__ */ new Map();
|
|
54492
|
+
const newBasicQty = /* @__PURE__ */ new Map();
|
|
54493
|
+
const ownedTaken = /* @__PURE__ */ new Set();
|
|
54494
|
+
const purchasedTaken = /* @__PURE__ */ new Set();
|
|
54495
|
+
const nonLandsCommitted = [];
|
|
54496
|
+
const floorStats = [];
|
|
54497
|
+
const bracketGcAllowance = gcAllowanceForBracket(
|
|
54498
|
+
targetBracket ?? effectiveDetail?.bracket
|
|
54499
|
+
);
|
|
54500
|
+
let gcUsed = 0;
|
|
54501
|
+
const sampleDecks = effectiveDetail?.deckCount ?? 0;
|
|
54502
|
+
const lowSample = sampleDecks > 0 && sampleDecks < LOW_SAMPLE_THRESHOLD;
|
|
54503
|
+
const effectiveRankMode = rankMode === "synergy" && lowSample ? "popularity" : rankMode;
|
|
54504
|
+
const hasEdhrecData = (effectiveDetail?.categories?.length ?? 0) > 0;
|
|
54505
|
+
const rankTiebreak = (card) => hasEdhrecData ? 0 : card?.edhrecRank ?? Number.POSITIVE_INFINITY;
|
|
54506
|
+
const byRank2 = (a, b) => {
|
|
54507
|
+
const diff = rankScore(b, effectiveRankMode) - rankScore(a, effectiveRankMode);
|
|
54508
|
+
if (diff !== 0) return diff;
|
|
54509
|
+
const incDiff = b.inclusion - a.inclusion;
|
|
54510
|
+
if (incDiff !== 0) return incDiff;
|
|
54511
|
+
return rankTiebreak(a.card) - rankTiebreak(b.card);
|
|
54512
|
+
};
|
|
54513
|
+
const assignOwned = (items, slotName, need, filled) => {
|
|
54514
|
+
for (const item of items) {
|
|
54515
|
+
if (filled >= need) break;
|
|
54516
|
+
if (ownedTaken.has(item.card.oracleId)) continue;
|
|
54517
|
+
if (gcUsed >= bracketGcAllowance && isGameChangerName(item.card.name)) {
|
|
54518
|
+
continue;
|
|
54519
|
+
}
|
|
54520
|
+
newAssignments.set(item.card.oracleId, slotName);
|
|
54521
|
+
ownedTaken.add(item.card.oracleId);
|
|
54522
|
+
nonLandsCommitted.push(item.card);
|
|
54523
|
+
if (isGameChangerName(item.card.name)) gcUsed++;
|
|
54524
|
+
filled++;
|
|
54525
|
+
}
|
|
54526
|
+
return filled;
|
|
54527
|
+
};
|
|
54528
|
+
const nonLandTarget = slots.reduce(
|
|
54529
|
+
(sum, s) => s.slot === "lands" ? sum : sum + s.target,
|
|
54530
|
+
0
|
|
54531
|
+
);
|
|
54532
|
+
const targetBuckets = targetCurve ? targetCounts(targetCurve, nonLandTarget) : null;
|
|
54533
|
+
const ceiling7plus = targetBuckets ? targetBuckets[CURVE_TOP_BUCKET] + CURVE_7PLUS_CEILING_SLACK : Infinity;
|
|
54534
|
+
const curve = new Array(CURVE_BUCKET_COUNT).fill(0);
|
|
54535
|
+
const scoreSpread = (items) => {
|
|
54536
|
+
let min = Infinity;
|
|
54537
|
+
let max = -Infinity;
|
|
54538
|
+
for (const it of items) {
|
|
54539
|
+
const s = rankScore(it, effectiveRankMode);
|
|
54540
|
+
if (s < min) min = s;
|
|
54541
|
+
if (s > max) max = s;
|
|
54542
|
+
}
|
|
54543
|
+
if (max === -Infinity) return 1;
|
|
54544
|
+
const spread = max - min;
|
|
54545
|
+
return spread > 0 ? spread : 1;
|
|
54546
|
+
};
|
|
54547
|
+
const pickCurveAware = (pool, isTaken, isGcBlocked, scoreOf, bucketOf, inclusionOf, keyOf, scale, rankOf) => {
|
|
54548
|
+
let bestIdx = -1;
|
|
54549
|
+
let bestUnder = false;
|
|
54550
|
+
let bestEff = -Infinity;
|
|
54551
|
+
let bestInc = -Infinity;
|
|
54552
|
+
let bestRank = Infinity;
|
|
54553
|
+
let bestKey = "";
|
|
54554
|
+
for (let i = 0; i < pool.length; i++) {
|
|
54555
|
+
const t = pool[i];
|
|
54556
|
+
if (isTaken(t) || isGcBlocked(t)) continue;
|
|
54557
|
+
const b = bucketOf(t);
|
|
54558
|
+
const over = b !== null && targetBuckets ? Math.max(0, curve[b] + 1 - targetBuckets[b]) : 0;
|
|
54559
|
+
const under = !(b === CURVE_TOP_BUCKET && curve[CURVE_TOP_BUCKET] >= ceiling7plus);
|
|
54560
|
+
const eff = scoreOf(t) - CURVE_PENALTY_WEIGHT * scale * over;
|
|
54561
|
+
const inc = inclusionOf(t);
|
|
54562
|
+
const rank = rankOf(t);
|
|
54563
|
+
const key2 = keyOf(t);
|
|
54564
|
+
const better = bestIdx === -1 || under && !bestUnder || under === bestUnder && (eff > bestEff || eff === bestEff && (inc > bestInc || inc === bestInc && (rank < bestRank || rank === bestRank && key2 < bestKey)));
|
|
54565
|
+
if (better) {
|
|
54566
|
+
bestIdx = i;
|
|
54567
|
+
bestUnder = under;
|
|
54568
|
+
bestEff = eff;
|
|
54569
|
+
bestInc = inc;
|
|
54570
|
+
bestRank = rank;
|
|
54571
|
+
bestKey = key2;
|
|
54572
|
+
}
|
|
54573
|
+
}
|
|
54574
|
+
return bestIdx;
|
|
54575
|
+
};
|
|
54576
|
+
const assignOwnedCurveAware = (items, slotName, need, filled) => {
|
|
54577
|
+
const scale = scoreSpread(items);
|
|
54578
|
+
while (filled < need) {
|
|
54579
|
+
const idx = pickCurveAware(
|
|
54580
|
+
items,
|
|
54581
|
+
(it) => ownedTaken.has(it.card.oracleId),
|
|
54582
|
+
(it) => gcUsed >= bracketGcAllowance && isGameChangerName(it.card.name),
|
|
54583
|
+
(it) => rankScore(it, effectiveRankMode),
|
|
54584
|
+
(it) => bucketIndex(it.card.cmc),
|
|
54585
|
+
(it) => it.inclusion,
|
|
54586
|
+
(it) => it.card.oracleId,
|
|
54587
|
+
scale,
|
|
54588
|
+
(it) => rankTiebreak(it.card)
|
|
54589
|
+
);
|
|
54590
|
+
if (idx === -1) break;
|
|
54591
|
+
const item = items[idx];
|
|
54592
|
+
newAssignments.set(item.card.oracleId, slotName);
|
|
54593
|
+
ownedTaken.add(item.card.oracleId);
|
|
54594
|
+
nonLandsCommitted.push(item.card);
|
|
54595
|
+
curve[bucketIndex(item.card.cmc)]++;
|
|
54596
|
+
if (isGameChangerName(item.card.name)) gcUsed++;
|
|
54597
|
+
filled++;
|
|
54598
|
+
}
|
|
54599
|
+
return filled;
|
|
54600
|
+
};
|
|
54601
|
+
const buyCurveAware = (sugs, slotName, need, filled) => {
|
|
54602
|
+
const scale = scoreSpread(sugs);
|
|
54603
|
+
let placed = 0;
|
|
54604
|
+
while (filled < need) {
|
|
54605
|
+
const idx = pickCurveAware(
|
|
54606
|
+
sugs,
|
|
54607
|
+
(s) => purchasedTaken.has(s.slug),
|
|
54608
|
+
(s) => gcUsed >= bracketGcAllowance && isGameChangerName(s.card?.name ?? s.name ?? ""),
|
|
54609
|
+
(s) => rankScore(s, effectiveRankMode),
|
|
54610
|
+
(s) => s.card ? bucketIndex(s.card.cmc) : null,
|
|
54611
|
+
(s) => s.inclusion,
|
|
54612
|
+
(s) => s.slug,
|
|
54613
|
+
scale,
|
|
54614
|
+
(s) => rankTiebreak(s.card)
|
|
54615
|
+
);
|
|
54616
|
+
if (idx === -1) break;
|
|
54617
|
+
const sug = sugs[idx];
|
|
54618
|
+
const sugName = sug.card?.name ?? sug.name ?? "";
|
|
54619
|
+
newPurchases.set(sug.slug, slotName);
|
|
54620
|
+
purchasedTaken.add(sug.slug);
|
|
54621
|
+
if (sug.card) {
|
|
54622
|
+
nonLandsCommitted.push(sug.card);
|
|
54623
|
+
curve[bucketIndex(sug.card.cmc)]++;
|
|
54624
|
+
}
|
|
54625
|
+
if (isGameChangerName(sugName)) gcUsed++;
|
|
54626
|
+
filled++;
|
|
54627
|
+
placed++;
|
|
54628
|
+
}
|
|
54629
|
+
return { filled, placed };
|
|
54630
|
+
};
|
|
54631
|
+
for (const slot of slots) {
|
|
54632
|
+
if (slot.slot === "lands") continue;
|
|
54633
|
+
let filled = 0;
|
|
54634
|
+
const need = slot.target;
|
|
54635
|
+
const ownedAboveFloor = [];
|
|
54636
|
+
const ownedBelowFloor = [];
|
|
54637
|
+
for (const item of slot.owned) {
|
|
54638
|
+
if (!useQualityFloor || item.inclusionPct >= INCLUSION_FLOOR_PCT) {
|
|
54639
|
+
ownedAboveFloor.push(item);
|
|
54640
|
+
} else {
|
|
54641
|
+
ownedBelowFloor.push(item);
|
|
54642
|
+
}
|
|
54643
|
+
}
|
|
54644
|
+
ownedAboveFloor.sort(byRank2);
|
|
54645
|
+
ownedBelowFloor.sort(byRank2);
|
|
54646
|
+
filled = targetBuckets ? assignOwnedCurveAware(ownedAboveFloor, slot.slot, need, filled) : assignOwned(ownedAboveFloor, slot.slot, need, filled);
|
|
54647
|
+
let buysThisSlot = 0;
|
|
54648
|
+
if (!ownedOnly && filled < need) {
|
|
54649
|
+
const sugAboveFloor = [...slot.suggestions].filter(
|
|
54650
|
+
(s) => s.inclusionPct >= INCLUSION_FLOOR_PCT && withinPriceCap(s.card?.priceUsd, priceCap)
|
|
54651
|
+
).sort(byRank2);
|
|
54652
|
+
if (targetBuckets) {
|
|
54653
|
+
const r = buyCurveAware(sugAboveFloor, slot.slot, need, filled);
|
|
54654
|
+
filled = r.filled;
|
|
54655
|
+
buysThisSlot = r.placed;
|
|
54656
|
+
} else {
|
|
54657
|
+
for (const sug of sugAboveFloor) {
|
|
54658
|
+
if (filled >= need) break;
|
|
54659
|
+
if (purchasedTaken.has(sug.slug)) continue;
|
|
54660
|
+
const sugName = sug.card?.name ?? sug.name ?? "";
|
|
54661
|
+
if (gcUsed >= bracketGcAllowance && isGameChangerName(sugName)) {
|
|
54662
|
+
continue;
|
|
54663
|
+
}
|
|
54664
|
+
newPurchases.set(sug.slug, slot.slot);
|
|
54665
|
+
purchasedTaken.add(sug.slug);
|
|
54666
|
+
if (sug.card) nonLandsCommitted.push(sug.card);
|
|
54667
|
+
if (isGameChangerName(sugName)) gcUsed++;
|
|
54668
|
+
filled++;
|
|
54669
|
+
buysThisSlot++;
|
|
54670
|
+
}
|
|
54671
|
+
}
|
|
54672
|
+
}
|
|
54673
|
+
if (filled < need) {
|
|
54674
|
+
filled = targetBuckets ? assignOwnedCurveAware(ownedBelowFloor, slot.slot, need, filled) : assignOwned(ownedBelowFloor, slot.slot, need, filled);
|
|
54675
|
+
}
|
|
54676
|
+
floorStats.push({ buys: buysThisSlot, belowFloor: ownedBelowFloor.map((o) => o.card) });
|
|
54677
|
+
}
|
|
54678
|
+
const landsSlot = slots.find((s) => s.slot === "lands");
|
|
54679
|
+
if (landsSlot) {
|
|
54680
|
+
fillLands(
|
|
54681
|
+
landsSlot,
|
|
54682
|
+
ownedTaken,
|
|
54683
|
+
newAssignments,
|
|
54684
|
+
newBasicQty,
|
|
54685
|
+
nonLandsCommitted,
|
|
54686
|
+
ownedQtyForCard,
|
|
54687
|
+
effectiveDetail,
|
|
54688
|
+
ownedOnly ? void 0 : { purchases: newPurchases, purchasedTaken, cards, priceCap }
|
|
54689
|
+
);
|
|
54690
|
+
}
|
|
54691
|
+
let skippedLowSignalOwned = 0;
|
|
54692
|
+
for (const { buys, belowFloor } of floorStats) {
|
|
54693
|
+
if (buys === 0) continue;
|
|
54694
|
+
const benched = belowFloor.filter((c) => !ownedTaken.has(c.oracleId)).length;
|
|
54695
|
+
skippedLowSignalOwned += Math.min(buys, benched);
|
|
54696
|
+
}
|
|
54697
|
+
const lowSignalPlacedBySlot = [];
|
|
54698
|
+
for (const slot of slots) {
|
|
54699
|
+
if (slot.slot === "lands") continue;
|
|
54700
|
+
const hadAboveFloorCandidate = slot.owned.some((o) => o.inclusionPct >= INCLUSION_FLOOR_PCT) || slot.suggestions.some((s) => s.inclusionPct >= INCLUSION_FLOOR_PCT);
|
|
54701
|
+
if (!hadAboveFloorCandidate) continue;
|
|
54702
|
+
let count2 = 0;
|
|
54703
|
+
for (const item of slot.owned) {
|
|
54704
|
+
if (item.inclusionPct >= INCLUSION_FLOOR_PCT) continue;
|
|
54705
|
+
if (newAssignments.get(item.card.oracleId) === slot.slot) count2++;
|
|
54706
|
+
}
|
|
54707
|
+
if (count2 > 0) {
|
|
54708
|
+
lowSignalPlacedBySlot.push({
|
|
54709
|
+
slot: slot.slot,
|
|
54710
|
+
label: slot.label,
|
|
54711
|
+
count: count2
|
|
54712
|
+
});
|
|
54713
|
+
}
|
|
54714
|
+
}
|
|
54715
|
+
return {
|
|
54716
|
+
assignments: newAssignments,
|
|
54717
|
+
purchases: newPurchases,
|
|
54718
|
+
basicQuantities: newBasicQty,
|
|
54719
|
+
ownedCount: newAssignments.size,
|
|
54720
|
+
buyCount: newPurchases.size,
|
|
54721
|
+
skippedLowSignalOwned,
|
|
54722
|
+
lowSignalPlacedBySlot
|
|
54723
|
+
};
|
|
54724
|
+
}
|
|
54725
|
+
var LAND_FIT_MAX_PASSES = 3;
|
|
54726
|
+
function retargetLands(slots, landTarget) {
|
|
54727
|
+
const lands = slots.find((s) => s.slot === "lands");
|
|
54728
|
+
if (!lands || lands.target === landTarget) return slots;
|
|
54729
|
+
const delta = lands.target - landTarget;
|
|
54730
|
+
return slots.map(
|
|
54731
|
+
(s) => s.slot === "lands" ? { ...s, target: landTarget } : s.slot === "creatures" ? { ...s, target: Math.max(0, s.target + delta) } : s
|
|
54732
|
+
);
|
|
54733
|
+
}
|
|
54734
|
+
function planNonLandCards(plan, slots, cards) {
|
|
54735
|
+
const out = [];
|
|
54736
|
+
for (const [oracleId, slot] of plan.assignments) {
|
|
54737
|
+
if (slot === "lands") continue;
|
|
54738
|
+
const c = cards.byOracleId.get(oracleId);
|
|
54739
|
+
if (c) out.push(c);
|
|
54740
|
+
}
|
|
54741
|
+
const bySlug = /* @__PURE__ */ new Map();
|
|
54742
|
+
for (const s of slots) {
|
|
54743
|
+
if (s.slot === "lands") continue;
|
|
54744
|
+
for (const sug of s.suggestions) if (sug.card) bySlug.set(sug.slug, sug.card);
|
|
54745
|
+
}
|
|
54746
|
+
for (const [slug, slot] of plan.purchases) {
|
|
54747
|
+
if (slot === "lands") continue;
|
|
54748
|
+
const c = bySlug.get(slug);
|
|
54749
|
+
if (c) out.push(c);
|
|
54750
|
+
}
|
|
54751
|
+
return out;
|
|
54752
|
+
}
|
|
54753
|
+
function buildWithRecommendedLands(build, slots, cards, lens) {
|
|
54754
|
+
let cur = slots;
|
|
54755
|
+
let plan = build(cur);
|
|
54756
|
+
if (!cards || !cur.some((s) => s.slot === "lands")) return { plan, slots: cur };
|
|
54757
|
+
const tried = /* @__PURE__ */ new Set();
|
|
54758
|
+
for (let pass = 0; pass < LAND_FIT_MAX_PASSES; pass++) {
|
|
54759
|
+
const landTarget = cur.find((s) => s.slot === "lands").target;
|
|
54760
|
+
tried.add(landTarget);
|
|
54761
|
+
const inputs = landCountInputs(
|
|
54762
|
+
planNonLandCards(plan, cur, cards).map((card) => ({ card })),
|
|
54763
|
+
lens
|
|
54764
|
+
);
|
|
54765
|
+
if (inputs.spellCount === 0) break;
|
|
54766
|
+
const rec = recommendedLandCount(inputs);
|
|
54767
|
+
if (rec === landTarget || tried.has(rec)) break;
|
|
54768
|
+
cur = retargetLands(cur, rec);
|
|
54769
|
+
plan = build(cur);
|
|
54770
|
+
}
|
|
54771
|
+
return { plan, slots: cur };
|
|
54772
|
+
}
|
|
54773
|
+
|
|
54774
|
+
// ../src/lib/commandersBySeeds.ts
|
|
54775
|
+
function rankCommandersBySeeds(seeds, commandersIndex) {
|
|
54776
|
+
if (seeds.length === 0) return [];
|
|
54777
|
+
const seedColors = /* @__PURE__ */ new Set();
|
|
54778
|
+
for (const s of seeds) {
|
|
54779
|
+
for (const c of s.colors) seedColors.add(c);
|
|
54780
|
+
}
|
|
54781
|
+
const out = [];
|
|
54782
|
+
for (const c of commandersIndex.commanders) {
|
|
54783
|
+
const pool = new Set(c.pool);
|
|
54784
|
+
const hitSlugs = [];
|
|
54785
|
+
const missingSlugs = [];
|
|
54786
|
+
for (const seed of seeds) {
|
|
54787
|
+
if (pool.has(seed.slug)) hitSlugs.push(seed.slug);
|
|
54788
|
+
else missingSlugs.push(seed.slug);
|
|
54789
|
+
}
|
|
54790
|
+
if (hitSlugs.length === 0) continue;
|
|
54791
|
+
let colorLegal = true;
|
|
54792
|
+
if (seedColors.size > 0) {
|
|
54793
|
+
const commanderColors = new Set(c.colors);
|
|
54794
|
+
for (const col of seedColors) {
|
|
54795
|
+
if (!commanderColors.has(col)) {
|
|
54796
|
+
colorLegal = false;
|
|
54797
|
+
break;
|
|
54798
|
+
}
|
|
54799
|
+
}
|
|
54800
|
+
}
|
|
54801
|
+
out.push({
|
|
54802
|
+
commander: c,
|
|
54803
|
+
hits: hitSlugs.length,
|
|
54804
|
+
hitSlugs,
|
|
54805
|
+
missingSlugs,
|
|
54806
|
+
colorLegal
|
|
54807
|
+
});
|
|
54808
|
+
}
|
|
54809
|
+
out.sort((a, b) => {
|
|
54810
|
+
if (a.hits !== b.hits) return b.hits - a.hits;
|
|
54811
|
+
if (a.colorLegal !== b.colorLegal) return a.colorLegal ? -1 : 1;
|
|
54812
|
+
return b.commander.deckCount - a.commander.deckCount;
|
|
54813
|
+
});
|
|
54814
|
+
return out;
|
|
54815
|
+
}
|
|
54816
|
+
function legalCommandersOnly(rankings) {
|
|
54817
|
+
return rankings.filter((r) => r.colorLegal);
|
|
54818
|
+
}
|
|
53301
54819
|
|
|
53302
54820
|
// ../src/lib/deckPlan/deckHealth.ts
|
|
53303
54821
|
function comb(n, k) {
|
|
@@ -53819,6 +55337,243 @@ function decodeCardText(entry) {
|
|
|
53819
55337
|
};
|
|
53820
55338
|
}
|
|
53821
55339
|
|
|
55340
|
+
// ../src/lib/priceHistory/value.ts
|
|
55341
|
+
function seriesFor(p, foil) {
|
|
55342
|
+
if (!p) return null;
|
|
55343
|
+
const order = foil ? ["f", "e", "n"] : ["n", "f", "e"];
|
|
55344
|
+
for (const f of order) {
|
|
55345
|
+
const r = p[f];
|
|
55346
|
+
if (r && r.length > 0) return { finish: f, record: r };
|
|
55347
|
+
}
|
|
55348
|
+
return null;
|
|
55349
|
+
}
|
|
55350
|
+
function groupOwned(owned) {
|
|
55351
|
+
const by = /* @__PURE__ */ new Map();
|
|
55352
|
+
for (const o of owned) {
|
|
55353
|
+
if (!o.set || !o.collectorNumber || !(o.quantity > 0)) continue;
|
|
55354
|
+
const key2 = `${o.set.toLowerCase()}|${o.collectorNumber}|${o.foil ? 1 : 0}`;
|
|
55355
|
+
const prev = by.get(key2);
|
|
55356
|
+
if (prev) {
|
|
55357
|
+
prev.quantity += o.quantity;
|
|
55358
|
+
if (o.lots) prev.lots = [...prev.lots ?? [], ...o.lots];
|
|
55359
|
+
} else by.set(key2, { ...o, set: o.set.toLowerCase() });
|
|
55360
|
+
}
|
|
55361
|
+
return [...by.values()];
|
|
55362
|
+
}
|
|
55363
|
+
function computeValueHistory(owned, files, from, to) {
|
|
55364
|
+
const days = to - from + 1;
|
|
55365
|
+
const totals = new Float64Array(Math.max(0, days));
|
|
55366
|
+
const grouped = groupOwned(owned);
|
|
55367
|
+
const bySet = /* @__PURE__ */ new Map();
|
|
55368
|
+
for (const f of files) {
|
|
55369
|
+
if (f.end < from || f.start > to) continue;
|
|
55370
|
+
const list = bySet.get(f.set) ?? [];
|
|
55371
|
+
list.push(f);
|
|
55372
|
+
bySet.set(f.set, list);
|
|
55373
|
+
}
|
|
55374
|
+
for (const list of bySet.values()) list.sort((a, b) => a.start - b.start);
|
|
55375
|
+
let pricedCopies = 0;
|
|
55376
|
+
let unpricedCopies = 0;
|
|
55377
|
+
let specialFoilCopies = 0;
|
|
55378
|
+
const moves = [];
|
|
55379
|
+
const daily = new Int32Array(Math.max(0, days));
|
|
55380
|
+
const then = new Float64Array(Math.max(0, days));
|
|
55381
|
+
let anyDated = false;
|
|
55382
|
+
const purchase = { copies: 0, paidCents: 0, nowCents: 0 };
|
|
55383
|
+
for (const o of grouped) {
|
|
55384
|
+
const list = bySet.get(o.set);
|
|
55385
|
+
daily.fill(-1);
|
|
55386
|
+
let finish = null;
|
|
55387
|
+
let special = false;
|
|
55388
|
+
if (list) {
|
|
55389
|
+
for (const file4 of list) {
|
|
55390
|
+
const s = seriesFor(file4.p[o.collectorNumber], o.foil);
|
|
55391
|
+
if (!s) continue;
|
|
55392
|
+
finish ??= s.finish;
|
|
55393
|
+
const record2 = s.finish === finish ? s.record : file4.p[o.collectorNumber]?.[finish];
|
|
55394
|
+
if (!record2) continue;
|
|
55395
|
+
if (o.foil && file4.af?.includes(o.collectorNumber)) special = true;
|
|
55396
|
+
for (let i = 0; i < record2.length; i += 2) {
|
|
55397
|
+
const startDay = file4.start + record2[i];
|
|
55398
|
+
const endDay = i + 2 < record2.length ? file4.start + record2[i + 2] - 1 : file4.end;
|
|
55399
|
+
const v = record2[i + 1];
|
|
55400
|
+
if (v == null) continue;
|
|
55401
|
+
for (let d = Math.max(startDay, from); d <= Math.min(endDay, to); d++) daily[d - from] = v;
|
|
55402
|
+
}
|
|
55403
|
+
}
|
|
55404
|
+
}
|
|
55405
|
+
let last = -1;
|
|
55406
|
+
let first = -1;
|
|
55407
|
+
for (let i = 0; i < days; i++) {
|
|
55408
|
+
if (daily[i] >= 0) {
|
|
55409
|
+
last = daily[i];
|
|
55410
|
+
if (first < 0) first = last;
|
|
55411
|
+
} else if (last >= 0) daily[i] = last;
|
|
55412
|
+
if (daily[i] >= 0) totals[i] += daily[i] * o.quantity;
|
|
55413
|
+
}
|
|
55414
|
+
if (last < 0 || finish === null) {
|
|
55415
|
+
unpricedCopies += o.quantity;
|
|
55416
|
+
continue;
|
|
55417
|
+
}
|
|
55418
|
+
pricedCopies += o.quantity;
|
|
55419
|
+
if (special) specialFoilCopies += o.quantity;
|
|
55420
|
+
for (const lot of o.lots ?? []) {
|
|
55421
|
+
if (lot.date) {
|
|
55422
|
+
anyDated = true;
|
|
55423
|
+
const start = Math.max(0, epochDay(lot.date) - from);
|
|
55424
|
+
for (let i = start; i < days; i++) if (daily[i] >= 0) then[i] += daily[i] * lot.quantity;
|
|
55425
|
+
}
|
|
55426
|
+
if (lot.priceUsd !== void 0) {
|
|
55427
|
+
purchase.copies += lot.quantity;
|
|
55428
|
+
purchase.paidCents += Math.round(lot.priceUsd * 100) * lot.quantity;
|
|
55429
|
+
purchase.nowCents += last * lot.quantity;
|
|
55430
|
+
}
|
|
55431
|
+
}
|
|
55432
|
+
if (FINISHES.includes(finish) && first >= 0) {
|
|
55433
|
+
moves.push({ printing: o, finish, fromCents: first, toCents: last, deltaCents: (last - first) * o.quantity });
|
|
55434
|
+
}
|
|
55435
|
+
}
|
|
55436
|
+
const points = [];
|
|
55437
|
+
for (let i = 0; i < days; i++) points.push({ day: from + i, cents: Math.round(totals[i]) });
|
|
55438
|
+
moves.sort((a, b) => b.deltaCents - a.deltaCents);
|
|
55439
|
+
const addedByThen = anyDated ? points.map((p, i) => ({ day: p.day, cents: Math.round(then[i]) })) : null;
|
|
55440
|
+
return { points, pricedCopies, unpricedCopies, specialFoilCopies, moves, addedByThen, purchase };
|
|
55441
|
+
}
|
|
55442
|
+
function ownedSets(owned) {
|
|
55443
|
+
return [...new Set(owned.filter((o) => o.set && o.collectorNumber).map((o) => o.set.toLowerCase()))].sort();
|
|
55444
|
+
}
|
|
55445
|
+
|
|
55446
|
+
// ../src/lib/affiliate.ts
|
|
55447
|
+
init_slug();
|
|
55448
|
+
var TCGPLAYER_AFFILIATE_LINK = "https://partner.tcgplayer.com/c/7357471/1780961/21018";
|
|
55449
|
+
var CARDMARKET_PARTNER = "";
|
|
55450
|
+
var front = (cardName) => cardName.split(" // ")[0];
|
|
55451
|
+
function buildTcgPlayerSearchUrl(cardName) {
|
|
55452
|
+
const q = encodeURIComponent(front(cardName));
|
|
55453
|
+
const destination2 = `https://www.tcgplayer.com/search/magic/product?productLineName=magic&q=${q}`;
|
|
55454
|
+
return `${TCGPLAYER_AFFILIATE_LINK}?u=${encodeURIComponent(destination2)}`;
|
|
55455
|
+
}
|
|
55456
|
+
function buildTcgPlayerMassEntryUrl(cards) {
|
|
55457
|
+
const list = cards.map((c) => {
|
|
55458
|
+
const base = `${c.qty ?? 1} ${front(c.name)}`;
|
|
55459
|
+
return c.set && c.collectorNumber ? `${base} [${c.set.toUpperCase()}] ${c.collectorNumber}` : base;
|
|
55460
|
+
}).join("||");
|
|
55461
|
+
const destination2 = `https://www.tcgplayer.com/massentry?productline=Magic&c=${encodeURIComponent(list)}`;
|
|
55462
|
+
return `${TCGPLAYER_AFFILIATE_LINK}?u=${encodeURIComponent(destination2)}`;
|
|
55463
|
+
}
|
|
55464
|
+
function buildCardmarketSearchUrl(cardName) {
|
|
55465
|
+
const q = encodeURIComponent(front(cardName));
|
|
55466
|
+
const partner = CARDMARKET_PARTNER ? `&utm_source=${encodeURIComponent(CARDMARKET_PARTNER)}&utm_medium=affiliate` : "";
|
|
55467
|
+
return `https://www.cardmarket.com/en/Magic/Products/Search?searchString=${q}${partner}`;
|
|
55468
|
+
}
|
|
55469
|
+
function buildCardKingdomSearchUrl(cardName) {
|
|
55470
|
+
const q = encodeURIComponent(front(cardName));
|
|
55471
|
+
return `https://www.cardkingdom.com/catalog/search?search=header&filter%5Bname%5D=${q}`;
|
|
55472
|
+
}
|
|
55473
|
+
function buildCardKingdomBuilderUrl(cards) {
|
|
55474
|
+
const list = cards.map((c) => `${c.qty ?? 1} ${front(c.name)}`).join("\n");
|
|
55475
|
+
return `https://www.cardkingdom.com/builder?c=${encodeURIComponent(list)}`;
|
|
55476
|
+
}
|
|
55477
|
+
function buildManaPoolCardUrl(cardName) {
|
|
55478
|
+
return `https://manapool.com/card/${toEdhrecSlug(cardName)}`;
|
|
55479
|
+
}
|
|
55480
|
+
var VENDORS = [
|
|
55481
|
+
{
|
|
55482
|
+
id: "cardkingdom",
|
|
55483
|
+
name: "Card Kingdom",
|
|
55484
|
+
cardUrl: buildCardKingdomSearchUrl,
|
|
55485
|
+
deckUrl: buildCardKingdomBuilderUrl,
|
|
55486
|
+
affiliate: false
|
|
55487
|
+
},
|
|
55488
|
+
{
|
|
55489
|
+
id: "cardmarket",
|
|
55490
|
+
name: "Cardmarket",
|
|
55491
|
+
cardUrl: buildCardmarketSearchUrl,
|
|
55492
|
+
deckUrl: null,
|
|
55493
|
+
affiliate: false
|
|
55494
|
+
},
|
|
55495
|
+
{
|
|
55496
|
+
id: "manapool",
|
|
55497
|
+
name: "Mana Pool",
|
|
55498
|
+
cardUrl: buildManaPoolCardUrl,
|
|
55499
|
+
deckUrl: null,
|
|
55500
|
+
affiliate: false
|
|
55501
|
+
},
|
|
55502
|
+
{
|
|
55503
|
+
id: "tcgplayer",
|
|
55504
|
+
name: "TCGplayer",
|
|
55505
|
+
cardUrl: buildTcgPlayerSearchUrl,
|
|
55506
|
+
deckUrl: buildTcgPlayerMassEntryUrl,
|
|
55507
|
+
affiliate: true
|
|
55508
|
+
}
|
|
55509
|
+
];
|
|
55510
|
+
var HAS_AFFILIATE_VENDOR = VENDORS.some((v) => v.affiliate);
|
|
55511
|
+
|
|
55512
|
+
// ../src/lib/deckPlan/historyPreview.ts
|
|
55513
|
+
function deslugify(slug) {
|
|
55514
|
+
return slug.split("-").map((w) => w ? w[0].toUpperCase() + w.slice(1) : w).join(" ").trim();
|
|
55515
|
+
}
|
|
55516
|
+
var byName2 = (a, b) => a.name.localeCompare(b.name);
|
|
55517
|
+
function versionCards(plan, r = {}) {
|
|
55518
|
+
const nameOf = (oracleId, slug) => oracleId && r.resolveName?.(oracleId) || (slug ? deslugify(slug) : "Unknown card");
|
|
55519
|
+
const deck = /* @__PURE__ */ new Map();
|
|
55520
|
+
const add = (key2, oracleId, name, qty) => {
|
|
55521
|
+
const prev = deck.get(key2);
|
|
55522
|
+
if (prev) prev.qty += qty;
|
|
55523
|
+
else deck.set(key2, { key: key2, ...oracleId ? { oracleId } : {}, name, qty, zone: "deck" });
|
|
55524
|
+
};
|
|
55525
|
+
for (const oid of plan.assignments.keys()) {
|
|
55526
|
+
add(oid, oid, nameOf(oid), Math.max(1, plan.basicQuantities.get(oid) ?? 1));
|
|
55527
|
+
}
|
|
55528
|
+
for (const slug of plan.purchases.keys()) {
|
|
55529
|
+
const oid = r.resolveSlug?.(slug);
|
|
55530
|
+
add(oid ?? `slug:${slug}`, oid, nameOf(oid, slug), Math.max(1, plan.purchaseQuantities?.get(slug) ?? 1));
|
|
55531
|
+
}
|
|
55532
|
+
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);
|
|
55533
|
+
return [
|
|
55534
|
+
...[...deck.values()].sort(byName2),
|
|
55535
|
+
...zone(plan.considering, "considering"),
|
|
55536
|
+
...zone(plan.sideboard, "sideboard")
|
|
55537
|
+
];
|
|
55538
|
+
}
|
|
55539
|
+
function diffVersions(then, now, r = {}) {
|
|
55540
|
+
const a = new Map(versionCards(then, r).map((c) => [c.key, c]));
|
|
55541
|
+
const b = new Map(versionCards(now, r).map((c) => [c.key, c]));
|
|
55542
|
+
const out = {
|
|
55543
|
+
addedSince: [],
|
|
55544
|
+
removedSince: [],
|
|
55545
|
+
countChanged: [],
|
|
55546
|
+
moved: [],
|
|
55547
|
+
commandersThen: then.commanders.map((c) => c.name),
|
|
55548
|
+
commandersNow: now.commanders.map((c) => c.name),
|
|
55549
|
+
commanderChanged: false
|
|
55550
|
+
};
|
|
55551
|
+
for (const [key2, was] of a) {
|
|
55552
|
+
const is = b.get(key2);
|
|
55553
|
+
if (!is) out.removedSince.push(was);
|
|
55554
|
+
else if (is.zone !== was.zone) out.moved.push({ card: is, then: was.zone, now: is.zone });
|
|
55555
|
+
else if (is.qty !== was.qty) out.countChanged.push({ card: is, then: was.qty, now: is.qty });
|
|
55556
|
+
}
|
|
55557
|
+
for (const [key2, is] of b) if (!a.has(key2)) out.addedSince.push(is);
|
|
55558
|
+
out.commanderChanged = then.commanders.map((c) => c.oracleId).join("|") !== now.commanders.map((c) => c.oracleId).join("|") || then.soloHalf !== now.soloHalf;
|
|
55559
|
+
return out;
|
|
55560
|
+
}
|
|
55561
|
+
function isSameVersion(d) {
|
|
55562
|
+
return !d.commanderChanged && !d.addedSince.length && !d.removedSince.length && !d.countChanged.length && !d.moved.length;
|
|
55563
|
+
}
|
|
55564
|
+
function summarizeVersionDiff(d, textFields = []) {
|
|
55565
|
+
const parts = [];
|
|
55566
|
+
if (d.commanderChanged) parts.push("commander changed");
|
|
55567
|
+
if (d.addedSince.length) parts.push(`${d.addedSince.length} added`);
|
|
55568
|
+
if (d.removedSince.length) parts.push(`${d.removedSince.length} removed`);
|
|
55569
|
+
if (d.moved.length) parts.push(`${d.moved.length} moved`);
|
|
55570
|
+
if (d.countChanged.length) parts.push(`${d.countChanged.length} ${d.countChanged.length === 1 ? "count" : "counts"} changed`);
|
|
55571
|
+
if (textFields.length) parts.push(`${textFields.join(", ")} edited`);
|
|
55572
|
+
if (!parts.length) return "Tags or printings changed";
|
|
55573
|
+
const s = parts.join(", ");
|
|
55574
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
55575
|
+
}
|
|
55576
|
+
|
|
53822
55577
|
// ../src/lib/edhrec/bracket-signals.ts
|
|
53823
55578
|
init_slug();
|
|
53824
55579
|
var MLD_NAMES = [
|
|
@@ -53943,21 +55698,25 @@ function isFastManaName(name) {
|
|
|
53943
55698
|
// ../src/components/deckBuilderV2/bracketInference.ts
|
|
53944
55699
|
var BRACKET_MIN_COMMITTED = 30;
|
|
53945
55700
|
var EXTRA_TURN_SIGNAL = "extra-turn";
|
|
53946
|
-
function
|
|
53947
|
-
|
|
53948
|
-
|
|
53949
|
-
let fastMana = 0;
|
|
55701
|
+
function bracketSignalCards(cards) {
|
|
55702
|
+
const mld = [];
|
|
55703
|
+
const extraTurns = [];
|
|
53950
55704
|
for (const c of cards) {
|
|
53951
|
-
if (isMassLandDestructionName(c.name)) mld
|
|
55705
|
+
if (isMassLandDestructionName(c.name)) mld.push(c.name);
|
|
53952
55706
|
if (c.signals?.includes(EXTRA_TURN_SIGNAL) || isExtraTurnName(c.name))
|
|
53953
|
-
extraTurns
|
|
53954
|
-
if (isFastManaName(c.name)) fastMana++;
|
|
55707
|
+
extraTurns.push(c.name);
|
|
53955
55708
|
}
|
|
55709
|
+
return { mld, extraTurns };
|
|
55710
|
+
}
|
|
55711
|
+
function countSignals(cards, gameChangerCount, comboCount) {
|
|
55712
|
+
const named = bracketSignalCards(cards);
|
|
55713
|
+
let fastMana = 0;
|
|
55714
|
+
for (const c of cards) if (isFastManaName(c.name)) fastMana++;
|
|
53956
55715
|
return {
|
|
53957
55716
|
gameChangers: gameChangerCount,
|
|
53958
55717
|
combos: comboCount,
|
|
53959
|
-
mld,
|
|
53960
|
-
extraTurns,
|
|
55718
|
+
mld: named.mld.length,
|
|
55719
|
+
extraTurns: named.extraTurns.length,
|
|
53961
55720
|
fastMana
|
|
53962
55721
|
};
|
|
53963
55722
|
}
|
|
@@ -54078,8 +55837,8 @@ function viewDeck(id, d, catalog, comboIndex) {
|
|
|
54078
55837
|
}
|
|
54079
55838
|
var TYPE_ORDER = ["Creature", "Planeswalker", "Battle", "Instant", "Sorcery", "Artifact", "Enchantment", "Land"];
|
|
54080
55839
|
function primaryType(card) {
|
|
54081
|
-
const
|
|
54082
|
-
return TYPE_ORDER.find((t) =>
|
|
55840
|
+
const front2 = card.typeLine.split(" // ")[0] ?? card.typeLine;
|
|
55841
|
+
return TYPE_ORDER.find((t) => front2.includes(t)) ?? "Other";
|
|
54083
55842
|
}
|
|
54084
55843
|
function isLand3(card) {
|
|
54085
55844
|
return (card.typeLine.split(" // ")[0] ?? card.typeLine).includes("Land");
|
|
@@ -54133,11 +55892,19 @@ var REDUCER_FIELDS = [
|
|
|
54133
55892
|
"fillActionAt",
|
|
54134
55893
|
"editedSinceFill"
|
|
54135
55894
|
];
|
|
54136
|
-
var
|
|
55895
|
+
var NEVER_CARRIED = ["minEditor"];
|
|
55896
|
+
var REDUCER = /* @__PURE__ */ new Set([...REDUCER_FIELDS, ...NEVER_CARRIED]);
|
|
54137
55897
|
|
|
54138
55898
|
// ../src/lib/agentRequests/deckOps.ts
|
|
55899
|
+
init_deckSchema();
|
|
54139
55900
|
init_utils();
|
|
55901
|
+
init_deckText();
|
|
54140
55902
|
var DECK_BOARDS = ["deck", "considering", "sideboard"];
|
|
55903
|
+
var DECK_TEXT_FIELDS = ["name", "description", "notes"];
|
|
55904
|
+
var TEXT_OID = "deck-text";
|
|
55905
|
+
var isTextOp = (op) => op.op === "text";
|
|
55906
|
+
var MAX_CARD_TAGS = 12;
|
|
55907
|
+
var MAX_TAG_NAME = 40;
|
|
54141
55908
|
var MAX_CARDS_PER_EDIT = 30;
|
|
54142
55909
|
var MAX_COPIES = 99;
|
|
54143
55910
|
function slugsOf(card) {
|
|
@@ -54161,23 +55928,112 @@ function entryProblem(card, qty, identity2) {
|
|
|
54161
55928
|
if (qty > 1 && !allowsMultipleCopies(card.typeLine, card.name)) return "only one copy is allowed";
|
|
54162
55929
|
return null;
|
|
54163
55930
|
}
|
|
55931
|
+
var sideOf = (stored) => ({
|
|
55932
|
+
cats: stored.v2Categories,
|
|
55933
|
+
prints: stored.printingOverrides,
|
|
55934
|
+
text: { name: stored.name ?? "", description: stored.description ?? "", notes: stored.notes ?? "" }
|
|
55935
|
+
});
|
|
55936
|
+
function cleanDeckText(field, value) {
|
|
55937
|
+
if (field === "name") return clampDeckName(value);
|
|
55938
|
+
return value.trim().slice(0, field === "description" ? MAX_DESCRIPTION_LENGTH : MAX_NOTES_LENGTH);
|
|
55939
|
+
}
|
|
55940
|
+
var TEXT_LABEL = { name: "the deck's name", description: "the description", notes: "the notes" };
|
|
55941
|
+
function textProblem(side, op) {
|
|
55942
|
+
if (op.from !== void 0 && side.text[op.field] !== op.from) return "changed since";
|
|
55943
|
+
return side.text[op.field] === cleanDeckText(op.field, op.value) ? "already says that" : null;
|
|
55944
|
+
}
|
|
55945
|
+
function tagsOf(cats, oid) {
|
|
55946
|
+
if (!cats) return [];
|
|
55947
|
+
const name = (id) => cats.categories.find((c) => c.id === id)?.name;
|
|
55948
|
+
const primary = cats.assignments[oid];
|
|
55949
|
+
return [primary, ...cats.secondary?.[oid] ?? []].flatMap((id) => id ? [name(id)].filter((n) => !!n) : []);
|
|
55950
|
+
}
|
|
55951
|
+
function withTags(cats, oid, tags) {
|
|
55952
|
+
const base = cats ?? { groupMode: "type", categories: [], assignments: {} };
|
|
55953
|
+
const categories = [...base.categories];
|
|
55954
|
+
const ids = [];
|
|
55955
|
+
for (const raw of tags) {
|
|
55956
|
+
const name = raw.trim();
|
|
55957
|
+
if (!name) continue;
|
|
55958
|
+
let cat = categories.find((c) => c.name.toLowerCase() === name.toLowerCase());
|
|
55959
|
+
if (!cat) {
|
|
55960
|
+
let n = categories.length;
|
|
55961
|
+
while (categories.some((c) => c.id === `cat_link_${n}`)) n++;
|
|
55962
|
+
cat = { id: `cat_link_${n}`, name };
|
|
55963
|
+
categories.push(cat);
|
|
55964
|
+
}
|
|
55965
|
+
if (!ids.includes(cat.id)) ids.push(cat.id);
|
|
55966
|
+
}
|
|
55967
|
+
const assignments = { ...base.assignments };
|
|
55968
|
+
const secondary = { ...base.secondary ?? {} };
|
|
55969
|
+
delete assignments[oid];
|
|
55970
|
+
delete secondary[oid];
|
|
55971
|
+
if (ids[0]) assignments[oid] = ids[0];
|
|
55972
|
+
if (ids.length > 1) secondary[oid] = ids.slice(1);
|
|
55973
|
+
const next = { ...base, categories, assignments };
|
|
55974
|
+
if (Object.keys(secondary).length) next.secondary = secondary;
|
|
55975
|
+
else delete next.secondary;
|
|
55976
|
+
return next;
|
|
55977
|
+
}
|
|
55978
|
+
var printOf = (prints, oid) => {
|
|
55979
|
+
const p = prints?.[oid];
|
|
55980
|
+
return p ? { set: p.set, cn: p.collectorNumber } : null;
|
|
55981
|
+
};
|
|
55982
|
+
var samePrint = (a, b) => (a?.set ?? "") === (b?.set ?? "") && (a?.cn ?? "") === (b?.cn ?? "");
|
|
55983
|
+
function sideProblem(s, side, op, card) {
|
|
55984
|
+
if (!placeOf(s, card) && !s.commanders.some((c) => c.oracleId === card.oracleId)) return "not in the deck";
|
|
55985
|
+
if (op.op === "tags") {
|
|
55986
|
+
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";
|
|
55987
|
+
const now = tagsOf(side.cats, card.oracleId);
|
|
55988
|
+
return now.length === op.tags.length && now.every((t, i) => t.toLowerCase() === op.tags[i].trim().toLowerCase()) ? "already tagged that way" : null;
|
|
55989
|
+
}
|
|
55990
|
+
return samePrint(printOf(side.prints, card.oracleId), op.print) ? "already that printing" : null;
|
|
55991
|
+
}
|
|
55992
|
+
function runSide(side, op) {
|
|
55993
|
+
const id = op.oracleId;
|
|
55994
|
+
if (op.op === "tags") {
|
|
55995
|
+
return { side: { ...side, cats: withTags(side.cats, id, op.tags) }, inverse: { op: "tags", oracleId: id, tags: tagsOf(side.cats, id) } };
|
|
55996
|
+
}
|
|
55997
|
+
const prints = { ...side.prints ?? {} };
|
|
55998
|
+
const before = printOf(side.prints, id);
|
|
55999
|
+
if (op.print) prints[id] = { set: op.print.set, collectorNumber: op.print.cn };
|
|
56000
|
+
else delete prints[id];
|
|
56001
|
+
return { side: { ...side, prints }, inverse: { op: "print", oracleId: id, print: before } };
|
|
56002
|
+
}
|
|
56003
|
+
var isSideOp = (op) => op.op === "tags" || op.op === "print";
|
|
54164
56004
|
function cardsChanged(ops) {
|
|
54165
|
-
return new Set(ops.map((o) => o.oracleId)).size;
|
|
56005
|
+
return new Set(ops.filter((o) => !isTextOp(o)).map((o) => o.oracleId)).size;
|
|
56006
|
+
}
|
|
56007
|
+
function newerDeckIssues(ops, ctx) {
|
|
56008
|
+
return ops.map((op, index) => ({
|
|
56009
|
+
index,
|
|
56010
|
+
card: isTextOp(op) ? TEXT_LABEL[op.field] : ctx.card(op.oracleId)?.name ?? op.oracleId,
|
|
56011
|
+
reason: NEWER_DECK_MESSAGE
|
|
56012
|
+
}));
|
|
54166
56013
|
}
|
|
54167
56014
|
function checkDeckOps(stored, ops, ctx, maxCards = MAX_CARDS_PER_EDIT) {
|
|
56015
|
+
if (!canEditDeck(stored)) return newerDeckIssues(ops, ctx);
|
|
54168
56016
|
const issues = [];
|
|
54169
56017
|
if (cardsChanged(ops) > maxCards) {
|
|
54170
56018
|
issues.push({ index: -1, card: "", reason: `changes ${cardsChanged(ops)} cards; at most ${maxCards} per request` });
|
|
54171
56019
|
}
|
|
54172
56020
|
let s = fromStored(stored);
|
|
56021
|
+
let side = sideOf(stored);
|
|
54173
56022
|
ops.forEach((op, index) => {
|
|
56023
|
+
if (isTextOp(op)) {
|
|
56024
|
+
const problem2 = textProblem(side, op);
|
|
56025
|
+
if (problem2) issues.push({ index, card: TEXT_LABEL[op.field], reason: problem2 });
|
|
56026
|
+
else side = { ...side, text: { ...side.text, [op.field]: cleanDeckText(op.field, op.value) } };
|
|
56027
|
+
return;
|
|
56028
|
+
}
|
|
54174
56029
|
const card = ctx.card(op.oracleId);
|
|
54175
56030
|
if (!card) {
|
|
54176
56031
|
issues.push({ index, card: op.oracleId, reason: "not a card EDHVault knows" });
|
|
54177
56032
|
return;
|
|
54178
56033
|
}
|
|
54179
|
-
const problem = opProblem(s, op, card, ctx);
|
|
56034
|
+
const problem = isSideOp(op) ? sideProblem(s, side, op, card) : opProblem(s, op, card, ctx);
|
|
54180
56035
|
if (problem) issues.push({ index, card: card.name, reason: problem });
|
|
56036
|
+
else if (isSideOp(op)) side = runSide(side, op).side;
|
|
54181
56037
|
else s = run(s, op, card, ctx).state;
|
|
54182
56038
|
});
|
|
54183
56039
|
return issues;
|
|
@@ -54206,6 +56062,12 @@ function opProblem(s, op, card, ctx) {
|
|
|
54206
56062
|
if (at.board === op.to) return `already in ${boardName(op.to)}`;
|
|
54207
56063
|
return op.to === "deck" ? entryProblem(card, 1, ctx.identity) : null;
|
|
54208
56064
|
}
|
|
56065
|
+
case "commanders": {
|
|
56066
|
+
if (op.ids.length < 1 || op.ids.length > 2 || op.ids[0] !== op.oracleId) return "asks for a command zone it can't have";
|
|
56067
|
+
if (op.ids.some((id) => !ctx.card(id))) return "not a card EDHVault knows";
|
|
56068
|
+
const now = s.commanders.map((c) => c.oracleId);
|
|
56069
|
+
return now.length === op.ids.length && now.every((id, i) => id === op.ids[i]) ? "already the commander" : null;
|
|
56070
|
+
}
|
|
54209
56071
|
}
|
|
54210
56072
|
}
|
|
54211
56073
|
function run(s, op, card, ctx) {
|
|
@@ -54254,6 +56116,15 @@ function run(s, op, card, ctx) {
|
|
|
54254
56116
|
enter(op.to, from.board === "deck" ? from.qty : 1);
|
|
54255
56117
|
return { state: s, inverse: { op: "move", oracleId: id, to: from.board } };
|
|
54256
56118
|
}
|
|
56119
|
+
case "commanders": {
|
|
56120
|
+
const before = s.commanders.map((c) => c.oracleId);
|
|
56121
|
+
const refs2 = op.ids.map((oid) => {
|
|
56122
|
+
const c = ctx.card(oid);
|
|
56123
|
+
return { oracleId: oid, name: c.name, colors: c.colors ?? [] };
|
|
56124
|
+
});
|
|
56125
|
+
dispatch({ type: "setCommanders", commanders: refs2 });
|
|
56126
|
+
return { state: s, inverse: before.length ? { op: "commanders", oracleId: before[0], ids: before } : { op: "commanders", oracleId: id, ids: op.ids } };
|
|
56127
|
+
}
|
|
54257
56128
|
}
|
|
54258
56129
|
}
|
|
54259
56130
|
function summarizeDeckOps(ops) {
|
|
@@ -54261,11 +56132,19 @@ function summarizeDeckOps(ops) {
|
|
|
54261
56132
|
const cut = ops.filter((o) => o.op === "remove").length;
|
|
54262
56133
|
const moved = ops.filter((o) => o.op === "move").length;
|
|
54263
56134
|
const counts = ops.filter((o) => o.op === "setQty").length;
|
|
56135
|
+
const tagged = ops.filter((o) => o.op === "tags").length;
|
|
56136
|
+
const printed = ops.filter((o) => o.op === "print").length;
|
|
56137
|
+
const commander = ops.some((o) => o.op === "commanders");
|
|
56138
|
+
const texts = DECK_TEXT_FIELDS.filter((f) => ops.some((o) => o.op === "text" && o.field === f));
|
|
54264
56139
|
return [
|
|
54265
56140
|
add ? `+${add}` : "",
|
|
54266
56141
|
cut ? `\u2212${cut}` : "",
|
|
54267
56142
|
moved ? `${moved} moved` : "",
|
|
54268
|
-
counts ? `${counts} recounted` : ""
|
|
56143
|
+
counts ? `${counts} recounted` : "",
|
|
56144
|
+
tagged ? `${tagged} retagged` : "",
|
|
56145
|
+
printed ? `${printed} new ${printed === 1 ? "printing" : "printings"}` : "",
|
|
56146
|
+
commander ? "new commander" : "",
|
|
56147
|
+
texts.length ? `new ${texts.join(" and ")}` : ""
|
|
54269
56148
|
].filter(Boolean).join(" ") || "no change";
|
|
54270
56149
|
}
|
|
54271
56150
|
|
|
@@ -54288,6 +56167,7 @@ var MAX_NOTE_CHARS = 500;
|
|
|
54288
56167
|
var MAX_CARDS_PER_NEW_DECK = 120;
|
|
54289
56168
|
var MAX_DECKS_PER_MOVE = 50;
|
|
54290
56169
|
var MAX_FOLDER_NAME = 60;
|
|
56170
|
+
var MAX_FROM_NAME = 40;
|
|
54291
56171
|
var NOTE_FIELDS = ["name", "description", "notes", "primer", "tags"];
|
|
54292
56172
|
var NOTES_PART_FIELDS = ["description", "notes", "primer"];
|
|
54293
56173
|
var MAX_LIBRARY_OPS = 100;
|
|
@@ -54329,9 +56209,16 @@ function parseLibraryOps(x, withQty) {
|
|
|
54329
56209
|
}
|
|
54330
56210
|
var SEEN_RE = /^[0-9a-f]{8}$/;
|
|
54331
56211
|
var DECK_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
54332
|
-
function
|
|
56212
|
+
function parseDeckOp(x, live = false) {
|
|
54333
56213
|
if (!x || typeof x !== "object") return null;
|
|
54334
56214
|
const o = x;
|
|
56215
|
+
if (o.op === "text") {
|
|
56216
|
+
if (!live || o.oracleId !== TEXT_OID || typeof o.value !== "string") return null;
|
|
56217
|
+
const field = o.field;
|
|
56218
|
+
if (!DECK_TEXT_FIELDS.includes(field)) return null;
|
|
56219
|
+
const cap2 = field === "notes" ? MAX_NOTES_LENGTH : field === "description" ? MAX_DESCRIPTION_LENGTH : MAX_DECK_NAME_LENGTH;
|
|
56220
|
+
return o.value.length <= cap2 ? { op: "text", oracleId: TEXT_OID, field, value: o.value } : null;
|
|
56221
|
+
}
|
|
54335
56222
|
if (typeof o.oracleId !== "string" || !OID_RE.test(o.oracleId)) return null;
|
|
54336
56223
|
const board = (b) => typeof b === "string" && DECK_BOARDS.includes(b);
|
|
54337
56224
|
const count2 = (n) => Number.isInteger(n) && n >= 1 && n <= MAX_COPIES;
|
|
@@ -54346,13 +56233,29 @@ function parseOp(x) {
|
|
|
54346
56233
|
return count2(o.qty) ? { op: "setQty", oracleId: o.oracleId, qty: o.qty } : null;
|
|
54347
56234
|
case "move":
|
|
54348
56235
|
return board(o.to) ? { op: "move", oracleId: o.oracleId, to: o.to } : null;
|
|
56236
|
+
case "tags": {
|
|
56237
|
+
if (!Array.isArray(o.tags) || o.tags.length > MAX_CARD_TAGS) return null;
|
|
56238
|
+
if (!o.tags.every((t) => typeof t === "string" && t.trim().length > 0 && t.length <= MAX_TAG_NAME)) return null;
|
|
56239
|
+
return { op: "tags", oracleId: o.oracleId, tags: o.tags };
|
|
56240
|
+
}
|
|
56241
|
+
case "print": {
|
|
56242
|
+
if (o.print === null) return { op: "print", oracleId: o.oracleId, print: null };
|
|
56243
|
+
const p = o.print;
|
|
56244
|
+
const part2 = (v) => typeof v === "string" && /^[A-Za-z0-9★_-]{1,12}$/.test(v);
|
|
56245
|
+
return p && part2(p.set) && part2(p.cn) ? { op: "print", oracleId: o.oracleId, print: { set: p.set, cn: p.cn } } : null;
|
|
56246
|
+
}
|
|
56247
|
+
case "commanders": {
|
|
56248
|
+
if (!Array.isArray(o.ids) || o.ids.length < 1 || o.ids.length > 2) return null;
|
|
56249
|
+
if (!o.ids.every((id) => typeof id === "string" && OID_RE.test(id)) || o.ids[0] !== o.oracleId) return null;
|
|
56250
|
+
return { op: "commanders", oracleId: o.oracleId, ids: o.ids };
|
|
56251
|
+
}
|
|
54349
56252
|
default:
|
|
54350
56253
|
return null;
|
|
54351
56254
|
}
|
|
54352
56255
|
}
|
|
54353
56256
|
function parseOps(x, max) {
|
|
54354
56257
|
if (!Array.isArray(x) || x.length === 0 || x.length > max * 2) return null;
|
|
54355
|
-
const ops = x.map(
|
|
56258
|
+
const ops = x.map((o) => parseDeckOp(o));
|
|
54356
56259
|
return ops.some((o) => o === null) ? null : ops;
|
|
54357
56260
|
}
|
|
54358
56261
|
var utf8Bytes = (s) => new TextEncoder().encode(s).length;
|
|
@@ -54418,10 +56321,19 @@ function parseRequest(text) {
|
|
|
54418
56321
|
const r = x;
|
|
54419
56322
|
if (r.v !== 1 || !Number.isFinite(r.madeAt)) return null;
|
|
54420
56323
|
if (r.note !== void 0 && (typeof r.note !== "string" || r.note.length > MAX_NOTE_CHARS)) return null;
|
|
56324
|
+
if (r.via !== void 0 && r.via !== "link") return null;
|
|
56325
|
+
let from;
|
|
56326
|
+
if (r.from !== void 0) {
|
|
56327
|
+
const f = r.from;
|
|
56328
|
+
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;
|
|
56329
|
+
if (f.name.trim()) from = { name: f.name.trim() };
|
|
56330
|
+
}
|
|
54421
56331
|
const base = {
|
|
54422
56332
|
v: 1,
|
|
54423
56333
|
...typeof r.note === "string" && r.note.trim() ? { note: r.note.trim() } : {},
|
|
54424
|
-
madeAt: r.madeAt
|
|
56334
|
+
madeAt: r.madeAt,
|
|
56335
|
+
...from ? { from } : {},
|
|
56336
|
+
...r.via === "link" ? { via: "link" } : {}
|
|
54425
56337
|
};
|
|
54426
56338
|
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
56339
|
const seen = typeof r.seen === "string" ? { seen: r.seen } : {};
|
|
@@ -55326,6 +57238,19 @@ function addedUnits(clause) {
|
|
|
55326
57238
|
if (/\ban amount of mana\b/.test(clause)) return [ANY];
|
|
55327
57239
|
return [];
|
|
55328
57240
|
}
|
|
57241
|
+
function loyaltyMana(self2) {
|
|
57242
|
+
for (const l of self2.split("\n")) {
|
|
57243
|
+
const m = l.match(/^(?:\+\d+|0): add ([^.]*)(?:\.|$)(.*)$/);
|
|
57244
|
+
if (!m) continue;
|
|
57245
|
+
const [, clause, rest] = m;
|
|
57246
|
+
const symbols = /^(?:\{[wubrgc]\})+$/.test(clause);
|
|
57247
|
+
const wider = /^\{[wubrgc]\}(?:(?:, | or |, or )\{[wubrgc]\})+$/.test(clause) || /^(?:one|two|three) mana (?:of any color|in any combination of colors)$/.test(clause);
|
|
57248
|
+
if (!symbols && !(wider && !/spend this mana only/.test(rest))) continue;
|
|
57249
|
+
const u = addedUnits(clause);
|
|
57250
|
+
if (u.length) return u;
|
|
57251
|
+
}
|
|
57252
|
+
return null;
|
|
57253
|
+
}
|
|
55329
57254
|
function tapAddUnits(text) {
|
|
55330
57255
|
let best = [];
|
|
55331
57256
|
for (const line of text.split("\n")) {
|
|
@@ -55351,19 +57276,19 @@ function manaProfile(card, oracleText) {
|
|
|
55351
57276
|
const costs = (card.manaCost ?? "").split(" // ");
|
|
55352
57277
|
if (costs.length > 1 && (card.layout === "adventure" || card.layout === "split" || card.layout === "prepare")) {
|
|
55353
57278
|
const first = parseCost(costs[0]);
|
|
55354
|
-
const
|
|
57279
|
+
const front2 = { ...card, manaCost: costs[0], cmc: first.generic + pipValue(first.pips) + (first.phyrexian ?? 0) };
|
|
55355
57280
|
if (card.layout === "adventure") {
|
|
55356
57281
|
const faces3 = preparedFaces(card.name, oracleText ?? "");
|
|
55357
57282
|
const types2 = card.typeLine.split("//");
|
|
55358
|
-
if (!faces3.spell || types2.length < 2) return readProfile(
|
|
57283
|
+
if (!faces3.spell || types2.length < 2) return readProfile(front2, oracleText);
|
|
55359
57284
|
const second2 = parseCost(costs[1]);
|
|
55360
57285
|
const spell2 = readProfile(
|
|
55361
57286
|
{ ...card, typeLine: types2[1].trim(), manaCost: costs[1], cmc: second2.generic + pipValue(second2.pips) + (second2.phyrexian ?? 0), layout: void 0 },
|
|
55362
57287
|
faces3.spell
|
|
55363
57288
|
);
|
|
55364
|
-
return { ...readProfile({ ...
|
|
57289
|
+
return { ...readProfile({ ...front2, typeLine: types2[0].trim() }, faces3.creature), spellSide: spell2 };
|
|
55365
57290
|
}
|
|
55366
|
-
if (card.layout !== "prepare") return readProfile(
|
|
57291
|
+
if (card.layout !== "prepare") return readProfile(front2, oracleText);
|
|
55367
57292
|
const faces2 = preparedFaces(card.name, oracleText ?? "");
|
|
55368
57293
|
const types = card.typeLine.split("//");
|
|
55369
57294
|
const second = parseCost(costs[1]);
|
|
@@ -55371,7 +57296,7 @@ function manaProfile(card, oracleText) {
|
|
|
55371
57296
|
{ ...card, typeLine: (types[1] ?? "").trim(), manaCost: costs[1], cmc: second.generic + pipValue(second.pips) + (second.phyrexian ?? 0), layout: void 0 },
|
|
55372
57297
|
faces2.spell
|
|
55373
57298
|
);
|
|
55374
|
-
const creature = readProfile({ ...
|
|
57299
|
+
const creature = readProfile({ ...front2, typeLine: types[0].trim() }, faces2.creature);
|
|
55375
57300
|
return { ...creature, spellSide: spell, prepared: /\benters prepared\b/.test(faces2.creature.toLowerCase()) ? "enters" : "condition" };
|
|
55376
57301
|
}
|
|
55377
57302
|
const p = withNonPlain(withConvert(readProfile(card, oracleText), oracleText ?? ""), oracleText ?? "");
|
|
@@ -55603,7 +57528,7 @@ function readPaidDraw(self2, planeswalker = false) {
|
|
|
55603
57528
|
for (const raw of self2.split("\n")) {
|
|
55604
57529
|
const l = raw.trim().replace(/^[a-z][a-z' -]* — /, "");
|
|
55605
57530
|
const loyalty = planeswalker && /^\+?\d+: /.test(l);
|
|
55606
|
-
if (loyalty &&
|
|
57531
|
+
if (loyalty && loyaltyMana(self2)) continue;
|
|
55607
57532
|
if (!ACTIVATED.test(l) && !loyalty) continue;
|
|
55608
57533
|
const at = l.indexOf(": ");
|
|
55609
57534
|
if (at < 0) continue;
|
|
@@ -56545,8 +58470,8 @@ function readProfile(card, oracleText) {
|
|
|
56545
58470
|
const on = text.match(/(?:^|\n)enchant (land|forest|island|swamp|mountain|plains)\b/);
|
|
56546
58471
|
return done({ ...base, makes: u.length ? u : [ANY], ...on ? { enchantLand: on[1] === "land" ? "land" : on[1][0].toUpperCase() + on[1].slice(1) } : {} });
|
|
56547
58472
|
}
|
|
56548
|
-
const
|
|
56549
|
-
const own2 = creature && /\bcreatures? you control\b[^"\n]*\bha(?:s|ve) "/.test(
|
|
58473
|
+
const front2 = flips ? text.split(/\n\(transforms from [^)]*\)/)[0] : text;
|
|
58474
|
+
const own2 = creature && /\bcreatures? you control\b[^"\n]*\bha(?:s|ve) "/.test(front2) ? front2 : front2.replace(/"[^"]*"/g, "");
|
|
56550
58475
|
const sure = tapAddUnits(own2.split("\n").filter((l) => !/activate only if/.test(l)).join("\n"));
|
|
56551
58476
|
const units = sure.length ? sure : tapAddUnits(own2);
|
|
56552
58477
|
const limited = units.length ? null : readLimitedMana(own2, card, creature);
|
|
@@ -56575,11 +58500,8 @@ function readProfile(card, oracleText) {
|
|
|
56575
58500
|
if (once.length) return done({ ...base, ritualMakes: once, discardsHand: true });
|
|
56576
58501
|
}
|
|
56577
58502
|
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
|
-
}
|
|
58503
|
+
const loyalMana = units.length || !/\bplaneswalker\b/.test(type) ? null : loyaltyMana(own2);
|
|
58504
|
+
if (loyalMana) return done({ ...base, makes: loyalMana, summoningSick: false });
|
|
56583
58505
|
if (tapOther) {
|
|
56584
58506
|
const u0 = addedUnits(tapOther[1]);
|
|
56585
58507
|
const floor = manaFloor(card, own2);
|
|
@@ -56600,7 +58522,7 @@ function readProfile(card, oracleText) {
|
|
|
56600
58522
|
/^[^:]*\bsacrifice a food\b[^:]*:[^\n]*\badd\b/.test(l) || /\{t\}[^:]*:[^\n]*\btarget\b[^\n]*\badd\b/.test(l)
|
|
56601
58523
|
)
|
|
56602
58524
|
);
|
|
56603
|
-
const floor = varies ? manaFloor(card,
|
|
58525
|
+
const floor = varies ? manaFloor(card, front2) : null;
|
|
56604
58526
|
const sure2 = floor === null ? units : floor === 0 ? [] : Array.from({ length: floor }, () => units[0]);
|
|
56605
58527
|
return done({ ...base, makes: sure2, summoningSick: creature && !base.haste || /enters tapped/.test(text), ...varies ? { manaVaries: true } : {} });
|
|
56606
58528
|
}
|
|
@@ -57268,11 +59190,11 @@ function chosenFinds(finds, deck) {
|
|
|
57268
59190
|
const count2 = /* @__PURE__ */ new Map();
|
|
57269
59191
|
const add = (k) => count2.set(k, (count2.get(k) ?? 0) + 1);
|
|
57270
59192
|
for (const c of deck) {
|
|
57271
|
-
const
|
|
57272
|
-
if (/\bland\b/.test(
|
|
59193
|
+
const front2 = c.typeLine.split(" // ")[0].toLowerCase();
|
|
59194
|
+
if (/\bland\b/.test(front2)) continue;
|
|
57273
59195
|
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(
|
|
59196
|
+
if (/\bcreature\b/.test(front2)) for (const t of typesOf(c).types ?? []) add(t);
|
|
59197
|
+
} else for (const t of CHOSEN_TYPES) if (new RegExp(`\\b${t}\\b`).test(front2)) add(t);
|
|
57276
59198
|
}
|
|
57277
59199
|
const top = [...count2].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
57278
59200
|
return f.replace(/@(?:sub)?type\b/, top ? `t:${top}` : "t:none-chosen").trim();
|
|
@@ -62410,7 +64332,7 @@ var ASSUMPTION_LABEL = {
|
|
|
62410
64332
|
},
|
|
62411
64333
|
exilesFirst: {
|
|
62412
64334
|
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
|
|
64335
|
+
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
64336
|
},
|
|
62415
64337
|
reanimate: {
|
|
62416
64338
|
title: "Reanimation we don't read, not counted",
|
|
@@ -62531,7 +64453,7 @@ function planAssumptions(args) {
|
|
|
62531
64453
|
const t = raw.replace(/\([^)]*\)/g, "");
|
|
62532
64454
|
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
64455
|
const sides = raw.split(/\n\(transforms from [^)]*\)/);
|
|
62534
|
-
const
|
|
64456
|
+
const front2 = sides[0].replace(/\([^)]*\)/g, "");
|
|
62535
64457
|
const backTreasure = sides.length > 1 && TREASURE2.test(sides.slice(1).join("\n"));
|
|
62536
64458
|
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
64459
|
/^\s*when this class becomes level \d+, [^\n]*\bdraws?\b/.test(l));
|
|
@@ -62580,7 +64502,7 @@ function planAssumptions(args) {
|
|
|
62580
64502
|
!p2.paidTreasure && !p2.diesTreasures && // (A death watcher's Treasure: Pitiless Plunderer.)
|
|
62581
64503
|
!p2.diesDraw?.some((d) => d.treasures) && // (Academy Manufactor's "a clue, food, or treasure token": read.)
|
|
62582
64504
|
!p2.tokenTriple && // (A cast trigger's Treasure: Storm-Kiln Artist's magecraft.)
|
|
62583
|
-
!p2.castTriggers?.some((x) => x.treasures) && TREASURE2.test(
|
|
64505
|
+
!p2.castTriggers?.some((x) => x.treasures) && TREASURE2.test(front2) || // A land token (Overlord of the Hauntwoods' "Everywhere") taps for mana.
|
|
62584
64506
|
/\bcreates? [^.\n]*\bland tokens?\b/.test(t) || // Its own entry is read, the rest is a trigger (Ganax: "or another dragon ... enters").
|
|
62585
64507
|
!!p2.treasures && /\bor another\b[^,\n]*\benters, create\b[^.\n]*\btreasure\b/.test(t))
|
|
62586
64508
|
add("manaTokens");
|
|
@@ -62907,18 +64829,18 @@ function savedPlanGame(saved) {
|
|
|
62907
64829
|
};
|
|
62908
64830
|
}
|
|
62909
64831
|
var MISS_LABEL = {
|
|
62910
|
-
notDrawn: { text: "
|
|
64832
|
+
notDrawn: { text: "never found it", hint: "You never had enough of these cards, and no tutor for them." },
|
|
62911
64833
|
tutorUnpaid: {
|
|
62912
|
-
text: "
|
|
64834
|
+
text: "had a tutor, not the mana",
|
|
62913
64835
|
hint: "You held a tutor that could get one, but couldn't pay for it (and the card) in time."
|
|
62914
64836
|
},
|
|
62915
64837
|
tutorUnusable: {
|
|
62916
|
-
text: "
|
|
62917
|
-
hint: `You held a tutor that could get one, but its search is a trigger
|
|
64838
|
+
text: "had a tutor these games can't use",
|
|
64839
|
+
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
64840
|
},
|
|
62919
|
-
noColor: { text: "
|
|
64841
|
+
noColor: { text: "wrong colors", hint: "You had the cards and the mana, not of the colors they need." },
|
|
62920
64842
|
landDrop: { text: "missed a land drop", hint: "You had the cards, not enough mana, and missed a land drop." },
|
|
62921
|
-
noMana: { text: "
|
|
64843
|
+
noMana: { text: "not enough mana", hint: "You had the cards and made every land drop, still not enough mana." },
|
|
62922
64844
|
countShort: { text: "fell short", hint: "The count never reached your number by that turn." }
|
|
62923
64845
|
};
|
|
62924
64846
|
function tutorReadQuery(a) {
|
|
@@ -63116,7 +65038,7 @@ function oddsPct(p) {
|
|
|
63116
65038
|
|
|
63117
65039
|
// ../src/lib/deckPlan/oddsFormat.ts
|
|
63118
65040
|
function levelMeaning(games) {
|
|
63119
|
-
return `
|
|
65041
|
+
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
65042
|
}
|
|
63121
65043
|
function headlinePct(p, games) {
|
|
63122
65044
|
const { lead, value, tail } = headlineParts(p, games);
|
|
@@ -63774,9 +65696,9 @@ function neverUsedLabel(reason, lastTurn) {
|
|
|
63774
65696
|
case "ignored":
|
|
63775
65697
|
return { title: "Set not to count", hint: "You set these not to count." };
|
|
63776
65698
|
case "tableGuess":
|
|
63777
|
-
return { title: "
|
|
65699
|
+
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
65700
|
case "planAsks":
|
|
63779
|
-
return { title: "
|
|
65701
|
+
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
65702
|
case "bonus":
|
|
63781
65703
|
return { title: "Interaction with a bonus", hint: "Its draw or mana isn't counted, because goldfish games have nothing to target." };
|
|
63782
65704
|
case "notModeled":
|
|
@@ -64105,7 +66027,7 @@ var comboNotes = (combos) => combos ? combos.stale ? { comboNote: "Combo data co
|
|
|
64105
66027
|
var asDeck = (d) => d;
|
|
64106
66028
|
var listDecks = {
|
|
64107
66029
|
name: "list_decks",
|
|
64108
|
-
description: "List the user's saved decks: name, commanders, card count, legality, bracket floor, folder, last edit.",
|
|
66030
|
+
description: "List the user's saved decks: name, commanders, card count, legality, bracket floor, public or private, folder, last edit.",
|
|
64109
66031
|
input: {
|
|
64110
66032
|
query: external_exports.string().optional().describe("Filter by deck or commander name."),
|
|
64111
66033
|
folder: external_exports.string().optional().describe("Only decks in this folder."),
|
|
@@ -64136,6 +66058,7 @@ var listDecks = {
|
|
|
64136
66058
|
cards: `${v.cards}/${v.target}`,
|
|
64137
66059
|
status: v.status,
|
|
64138
66060
|
bracketFloor: v.bracketFloor,
|
|
66061
|
+
...visibilityOf(decks.get(v.id)),
|
|
64139
66062
|
folder: f,
|
|
64140
66063
|
updated: savedAt ? new Date(savedAt).toISOString().slice(0, 10) : void 0
|
|
64141
66064
|
})),
|
|
@@ -64262,6 +66185,10 @@ function matchesOnly(l, only, stored) {
|
|
|
64262
66185
|
const id = cats?.categories.find((c) => c.name.toLowerCase() === o)?.id;
|
|
64263
66186
|
return !!id && cats?.assignments[l.card.oracleId] === id;
|
|
64264
66187
|
}
|
|
66188
|
+
function visibilityOf(raw) {
|
|
66189
|
+
const flag = raw && typeof raw === "object" ? raw[PUBLIC_FLAG] : void 0;
|
|
66190
|
+
return typeof flag === "boolean" ? { visibility: flag ? "public" : "private" } : {};
|
|
66191
|
+
}
|
|
64265
66192
|
function deckAnswer(v, stored, detail, only) {
|
|
64266
66193
|
const main2 = v.lines.filter((l) => l.board === "main" || l.board === "buy");
|
|
64267
66194
|
const byType = {};
|
|
@@ -64281,6 +66208,7 @@ function deckAnswer(v, stored, detail, only) {
|
|
|
64281
66208
|
considering: v.lines.filter((l) => l.board === "considering").length,
|
|
64282
66209
|
sideboard: v.lines.filter((l) => l.board === "sideboard").length,
|
|
64283
66210
|
...v.unknownCards ? { unknownCards: v.unknownCards } : {},
|
|
66211
|
+
...visibilityOf(stored),
|
|
64284
66212
|
...stored.tags?.length ? { tags: stored.tags } : {},
|
|
64285
66213
|
...stored.description ? { description: stored.description } : {}
|
|
64286
66214
|
};
|
|
@@ -64570,7 +66498,7 @@ var planOdds = {
|
|
|
64570
66498
|
mulligans: external_exports.number().int().min(0).max(3).optional().describe("Mulligans you'd take for this plan."),
|
|
64571
66499
|
countTutors: external_exports.boolean().optional().describe("Let tutors fetch missing pieces (default yes)."),
|
|
64572
66500
|
opponents: external_exports.number().int().min(1).max(9).optional().describe("Opponents at the table."),
|
|
64573
|
-
keepLands: external_exports.
|
|
66501
|
+
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
66502
|
need: external_exports.number().int().min(1).optional().describe("How many rows must come together in the same game (default: all of them)."),
|
|
64575
66503
|
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
66504
|
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 +66552,9 @@ function changes(windows) {
|
|
|
64624
66552
|
}
|
|
64625
66553
|
return out;
|
|
64626
66554
|
}
|
|
64627
|
-
function printingChanges(file4, set3, number4,
|
|
66555
|
+
function printingChanges(file4, set3, number4, usd2, foil) {
|
|
64628
66556
|
const out = {};
|
|
64629
|
-
for (const [isFoil, now] of [[false,
|
|
66557
|
+
for (const [isFoil, now] of [[false, usd2], [true, foil]]) {
|
|
64630
66558
|
const w = printingTrendWindows(file4, set3, number4, isFoil, now ?? void 0);
|
|
64631
66559
|
for (const k of TREND_WINDOWS) {
|
|
64632
66560
|
const d = w[k]?.delta;
|
|
@@ -64651,9 +66579,11 @@ async function part(missing, what, load) {
|
|
|
64651
66579
|
}
|
|
64652
66580
|
var cardTool = {
|
|
64653
66581
|
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.",
|
|
66582
|
+
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
66583
|
input: {
|
|
64656
66584
|
name: external_exports.string().min(1).describe("The card's name."),
|
|
66585
|
+
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.'),
|
|
66586
|
+
priceHistory: external_exports.boolean().optional().describe("Add the printing's price history: each day it changed, the low and the high."),
|
|
64657
66587
|
detail: detailInput,
|
|
64658
66588
|
comboSteps: external_exports.boolean().optional().describe("Add each combo's steps, mana needed and notes."),
|
|
64659
66589
|
refresh: refreshInput
|
|
@@ -64684,11 +66614,11 @@ var cardTool = {
|
|
|
64684
66614
|
const stepsWereOnDisk = x?.comboStepsOnDisk() ?? false;
|
|
64685
66615
|
const steps = args.comboSteps === true && combos ? await part(missing, "combo steps", x?.comboDetail) : null;
|
|
64686
66616
|
const printed = cardText ? decodeCardText(cardText.text[c.oracleId]) : null;
|
|
64687
|
-
const
|
|
66617
|
+
const front2 = {
|
|
64688
66618
|
...c.power != null ? { power: c.power, toughness: c.toughness } : {},
|
|
64689
66619
|
...c.loyalty != null ? { loyalty: c.loyalty } : {}
|
|
64690
66620
|
};
|
|
64691
|
-
const wording = cardText ? printed && "faces" in printed ? printed : { ...printed ? { text: printed.text } : {}, ...
|
|
66621
|
+
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
66622
|
const code = cardText?.legal[c.oracleId];
|
|
64693
66623
|
let formats;
|
|
64694
66624
|
if (cardText && code) {
|
|
@@ -64720,6 +66650,12 @@ var cardTool = {
|
|
|
64720
66650
|
const priced = all.filter((p) => p.priceUsd != null).sort((a, b) => a.priceUsd - b.priceUsd);
|
|
64721
66651
|
const cheapest = priced[0];
|
|
64722
66652
|
const cycle = cycles?.find((cy) => cy.members.some((m) => m.oracleId === c.oracleId));
|
|
66653
|
+
const ph = ctx.priceHistory;
|
|
66654
|
+
const pick2 = pickPrinting(all, args.printing);
|
|
66655
|
+
const [shops, history] = await Promise.all([
|
|
66656
|
+
ph && pick2 ? part(missing, "shop prices", () => shopPrices(ph, pick2)) : null,
|
|
66657
|
+
ph && pick2 && args.priceHistory === true ? part(missing, "the price history", () => printingHistory(ph, pick2, detail)) : null
|
|
66658
|
+
]);
|
|
64723
66659
|
let comboList = null;
|
|
64724
66660
|
if (combos) {
|
|
64725
66661
|
const r = buildCardComboResults(combos.index, c.oracleId, /* @__PURE__ */ new Set(), (oid) => catalog.index.byOracleId.get(oid), steps ?? void 0);
|
|
@@ -64775,6 +66711,8 @@ var cardTool = {
|
|
|
64775
66711
|
...all.length > printingRows.length ? { more: all.length - printingRows.length } : {}
|
|
64776
66712
|
}
|
|
64777
66713
|
} : {},
|
|
66714
|
+
...shops ? { shops } : {},
|
|
66715
|
+
...history ? { priceHistory: history } : {},
|
|
64778
66716
|
...cycle ? {
|
|
64779
66717
|
landCycle: {
|
|
64780
66718
|
name: cycle.displayName,
|
|
@@ -65750,13 +67688,17 @@ var PENDING_ABOUT = "Nothing has changed yet. The user approves or declines it i
|
|
|
65750
67688
|
var editDeckTool = {
|
|
65751
67689
|
name: "edit_deck",
|
|
65752
67690
|
write: true,
|
|
65753
|
-
description: "Ask to change one of the user's saved decks: add cards, cut cards, set a card's copies,
|
|
67691
|
+
description: "Ask to change one of the user's saved decks: add cards, cut cards, set a card's copies, move cards between the deck, considering and the sideboard, set a card's tags or printing, or change the commander. This files a REQUEST: nothing changes until the user approves it in EDHVault (Settings, AI tools), and it expires after 7 days. Owned cards go in the deck, others on its buy list, as the deck builder does. At most 30 cards per request. It's checked first against the deck as you see it (already in, not in it, outside the commander's colors, banned, one copy only) and refused with the reasons if it wouldn't apply. Give `note` to say why, in a sentence: the user sees it. Needs an access code allowed to ask to change decks.",
|
|
65754
67692
|
input: {
|
|
65755
67693
|
deck: external_exports.string().describe("The deck: its name or id (list_decks)."),
|
|
65756
67694
|
add: external_exports.array(external_exports.object({ name: external_exports.string(), qty: external_exports.number().int().min(1).max(99).optional(), to: BOARD_INPUT.optional() })).max(30).optional().describe("Cards to add: name, copies (basics and any-number cards only), and where (default: deck)."),
|
|
65757
67695
|
remove: external_exports.array(external_exports.string()).max(30).optional().describe("Cards to cut, wherever they are in the deck."),
|
|
65758
67696
|
setQuantity: external_exports.array(external_exports.object({ name: external_exports.string(), qty: external_exports.number().int().min(1).max(99) })).max(30).optional().describe("Copies of a card already in the deck."),
|
|
65759
67697
|
move: external_exports.array(external_exports.object({ name: external_exports.string(), to: BOARD_INPUT })).max(30).optional().describe("Cards to move to the deck, considering or the sideboard."),
|
|
67698
|
+
tags: external_exports.array(external_exports.object({ name: external_exports.string(), tags: external_exports.array(external_exports.string().min(1).max(MAX_TAG_NAME)).max(MAX_CARD_TAGS) })).max(30).optional().describe("A card's tags (the builder's categories), its main tag first; [] untags it. This replaces the card's tags: get_deck shows them."),
|
|
67699
|
+
printing: external_exports.array(external_exports.object({ name: external_exports.string(), printing: external_exports.string().nullable() })).max(30).optional().describe(`A card's printing: set code and collector number, like "fdc 286" (get_card lists them), or null for the default.`),
|
|
67700
|
+
commander: external_exports.string().optional().describe("A new commander. Cards outside its colors are named in the answer, not cut: cut them in the same request."),
|
|
67701
|
+
partner: external_exports.string().optional().describe("With commander: a second commander (partner, background, and the like)."),
|
|
65760
67702
|
note: external_exports.string().max(MAX_NOTE_CHARS).optional().describe("Why, in a sentence. Shown to the user beside the request.")
|
|
65761
67703
|
},
|
|
65762
67704
|
async run(args, ctx) {
|
|
@@ -65769,18 +67711,36 @@ var editDeckTool = {
|
|
|
65769
67711
|
if (!c) throw new ToolProblem(`No card named "${name2}".`);
|
|
65770
67712
|
return c;
|
|
65771
67713
|
};
|
|
67714
|
+
if (args.partner !== void 0 && args.commander === void 0) throw new ToolProblem("partner goes with commander: give both.");
|
|
67715
|
+
const newCommanders = typeof args.commander === "string" && args.commander.trim() ? [card(args.commander), ...typeof args.partner === "string" && args.partner.trim() ? [card(args.partner)] : []] : null;
|
|
67716
|
+
if (newCommanders) {
|
|
67717
|
+
for (const c of newCommanders) if (!c.canBeCommander) throw new ToolProblem(`${c.name} can't be a commander.`);
|
|
67718
|
+
if (newCommanders.length === 2) {
|
|
67719
|
+
const pair = isPairLegal(newCommanders[0], newCommanders[1]);
|
|
67720
|
+
if (!pair.legal) throw new ToolProblem(`${newCommanders[0].name} and ${newCommanders[1].name} can't be commanders together: ${pair.reason}`);
|
|
67721
|
+
}
|
|
67722
|
+
}
|
|
67723
|
+
const printingOf2 = args.printing?.length ? await printingPicker(ctx) : () => ({ set: "", cn: "" });
|
|
65772
67724
|
const ops = [
|
|
67725
|
+
// The command zone first: what's checked after it is checked against it.
|
|
67726
|
+
...newCommanders ? [{ op: "commanders", oracleId: newCommanders[0].oracleId, ids: newCommanders.map((c) => c.oracleId) }] : [],
|
|
65773
67727
|
...(args.remove ?? []).map((n) => ({ op: "remove", oracleId: card(n).oracleId })),
|
|
65774
67728
|
...(args.move ?? []).map((m) => ({ op: "move", oracleId: card(m.name).oracleId, to: m.to })),
|
|
65775
67729
|
...(args.setQuantity ?? []).map((m) => ({ op: "setQty", oracleId: card(m.name).oracleId, qty: m.qty })),
|
|
65776
|
-
...(args.add ?? []).map((a) => ({ op: "add", oracleId: card(a.name).oracleId, ...a.qty ? { qty: a.qty } : {}, ...a.to ? { to: a.to } : {} }))
|
|
67730
|
+
...(args.add ?? []).map((a) => ({ op: "add", oracleId: card(a.name).oracleId, ...a.qty ? { qty: a.qty } : {}, ...a.to ? { to: a.to } : {} })),
|
|
67731
|
+
...(args.tags ?? []).map((t) => ({ op: "tags", oracleId: card(t.name).oracleId, tags: t.tags.map((x) => x.trim()) })),
|
|
67732
|
+
...(args.printing ?? []).map((p) => {
|
|
67733
|
+
const c = card(p.name);
|
|
67734
|
+
return { op: "print", oracleId: c.oracleId, print: p.printing === null ? null : printingOf2(c, p.printing) };
|
|
67735
|
+
})
|
|
65777
67736
|
];
|
|
65778
|
-
if (ops.length === 0) throw new ToolProblem("Nothing to change: give add, remove, setQuantity or
|
|
67737
|
+
if (ops.length === 0) throw new ToolProblem("Nothing to change: give add, remove, setQuantity, move, tags, printing or commander.");
|
|
65779
67738
|
const owned = await ownedIdsOf(ctx, catalog, false);
|
|
65780
|
-
const commanders = viewDeck(id, stored, catalog, null).commanderCards;
|
|
67739
|
+
const commanders = newCommanders ?? viewDeck(id, stored, catalog, null).commanderCards;
|
|
67740
|
+
const identity2 = [...new Set(commanders.flatMap((c) => c.colors ?? []))];
|
|
65781
67741
|
const opCtx = {
|
|
65782
67742
|
card: (oid) => catalog.index.byOracleId.get(oid),
|
|
65783
|
-
identity:
|
|
67743
|
+
identity: identity2,
|
|
65784
67744
|
owned: (oid) => owned.ids.has(oid)
|
|
65785
67745
|
};
|
|
65786
67746
|
const issues = checkDeckOps(stored, ops, opCtx);
|
|
@@ -65797,13 +67757,41 @@ var editDeckTool = {
|
|
|
65797
67757
|
deck: viewDeck(id, stored, null).name,
|
|
65798
67758
|
summary: summarizeDeckOps(ops),
|
|
65799
67759
|
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}`
|
|
67760
|
+
(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
67761
|
),
|
|
67762
|
+
...newCommanders ? offColor(stored, ops, identity2, catalog) : {},
|
|
65802
67763
|
expires: new Date(r.expiresAt).toISOString().slice(0, 10),
|
|
65803
67764
|
about: PENDING_ABOUT
|
|
65804
67765
|
});
|
|
65805
67766
|
}
|
|
65806
67767
|
};
|
|
67768
|
+
function offColor(stored, ops, identity2, catalog) {
|
|
67769
|
+
const gone = new Set(ops.filter((o) => o.op === "remove" || o.op === "move" && o.to !== "deck").map((o) => o.oracleId));
|
|
67770
|
+
const inCommand = new Set(ops.flatMap((o) => o.op === "commanders" ? o.ids : []));
|
|
67771
|
+
const out = [];
|
|
67772
|
+
const allowed = new Set(identity2);
|
|
67773
|
+
for (const oid of [...stored.assignments?.keys() ?? [], ...[...stored.purchases?.keys() ?? []].map((slug) => catalog.bySlug.get(slug)?.oracleId ?? "")]) {
|
|
67774
|
+
if (!oid || gone.has(oid) || inCommand.has(oid)) continue;
|
|
67775
|
+
const c = catalog.index.byOracleId.get(oid);
|
|
67776
|
+
if (c && !withinColorIdentity(c.colors ?? [], allowed)) out.push(c.name);
|
|
67777
|
+
}
|
|
67778
|
+
return out.length ? { outsideColors: { cards: out.sort(), about: "In the deck but outside the new commander's colors: the deck builder flags them until they're cut. A later edit_deck can cut them." } } : {};
|
|
67779
|
+
}
|
|
67780
|
+
async function printingPicker(ctx) {
|
|
67781
|
+
const file4 = ctx.extras ? await ctx.extras.printings().catch(() => null) : null;
|
|
67782
|
+
return (card, asked) => {
|
|
67783
|
+
const m = asked.trim().toLowerCase().match(/^([a-z0-9]{2,8})[\s#:/-]+([^\s]+)$/);
|
|
67784
|
+
if (!m) throw new ToolProblem(`printing is a set code and collector number, like "fdc 286". Got "${asked}".`);
|
|
67785
|
+
if (!file4) throw new ToolProblem("The printings list didn't load, so a printing can't be checked. Try again in a moment.");
|
|
67786
|
+
const all = hydrateOraclePrintings(file4.p[card.oracleId] ?? [], file4.pr[card.oracleId]);
|
|
67787
|
+
const hit = all.find((p) => p.set.toLowerCase() === m[1] && p.collectorNumber.toLowerCase() === m[2]);
|
|
67788
|
+
if (!hit) {
|
|
67789
|
+
const some = all.slice(0, 8).map((p) => `${p.set} ${p.collectorNumber}`);
|
|
67790
|
+
throw new ToolProblem(`${card.name} has no printing "${asked}".${some.length ? ` Some it has: ${some.join(", ")}.` : ""}`);
|
|
67791
|
+
}
|
|
67792
|
+
return { set: hit.set.toLowerCase(), cn: hit.collectorNumber };
|
|
67793
|
+
};
|
|
67794
|
+
}
|
|
65807
67795
|
var noteOf = (args) => typeof args.note === "string" && args.note.trim() ? args.note.trim() : void 0;
|
|
65808
67796
|
var noteInput = external_exports.string().max(MAX_NOTE_CHARS).optional().describe("Why, in a sentence. Shown to the user beside the request.");
|
|
65809
67797
|
var utf8Bytes2 = (t) => new TextEncoder().encode(t).length;
|
|
@@ -66156,10 +68144,457 @@ var getRequestsTool = {
|
|
|
66156
68144
|
});
|
|
66157
68145
|
}
|
|
66158
68146
|
};
|
|
66159
|
-
var
|
|
68147
|
+
var PRICE_HISTORY_CREDIT = `Price history: ${HISTORY_SOURCE}, as EDHVault keeps it.`;
|
|
68148
|
+
var FINISH_WORD = { n: "regular", f: "foil", e: "etched" };
|
|
68149
|
+
var usd = (cents2) => Math.round(cents2) / 100;
|
|
68150
|
+
function shopAmount(cents2, cur) {
|
|
68151
|
+
const n = (cents2 / 100).toFixed(2);
|
|
68152
|
+
if (!cur || cur === "USD") return `$${n}`;
|
|
68153
|
+
if (cur === "EUR") return `\u20AC${n}`;
|
|
68154
|
+
return `${n} ${cur}`;
|
|
68155
|
+
}
|
|
68156
|
+
function pickPrinting(all, asked) {
|
|
68157
|
+
const label = (p2) => `${p2.setName ? `${p2.setName} ` : ""}(${p2.set} ${p2.collectorNumber})`;
|
|
68158
|
+
if (typeof asked === "string" && asked.trim()) {
|
|
68159
|
+
const m = asked.trim().toLowerCase().match(/^([a-z0-9]{2,8})[\s#:/-]+([^\s]+)$/);
|
|
68160
|
+
if (!m) throw new ToolProblem(`printing is a set code and collector number, like "fdc 286". Got "${asked}".`);
|
|
68161
|
+
const hit = all.find((p2) => p2.set.toLowerCase() === m[1] && p2.collectorNumber.toLowerCase() === m[2]);
|
|
68162
|
+
return hit ? { set: hit.set.toLowerCase(), number: hit.collectorNumber, label: label(hit) } : { set: m[1], number: m[2], label: `(${m[1]} ${m[2]})` };
|
|
68163
|
+
}
|
|
68164
|
+
const priced = all.filter((p2) => p2.priceUsd != null).sort((a, b) => a.priceUsd - b.priceUsd);
|
|
68165
|
+
const p = priced[0] ?? all[0];
|
|
68166
|
+
return p ? { set: p.set.toLowerCase(), number: p.collectorNumber, label: label(p) } : null;
|
|
68167
|
+
}
|
|
68168
|
+
async function shopPrices(ph, p) {
|
|
68169
|
+
const file4 = await ph.vendorSet(p.set);
|
|
68170
|
+
const row = file4?.p[p.number];
|
|
68171
|
+
if (!file4 || !row) return { printing: p.label, none: "No shop prices for this printing (MTGJSON lists none for it, or its set)." };
|
|
68172
|
+
const prices = {};
|
|
68173
|
+
for (const v of VENDORS) {
|
|
68174
|
+
const by = row[v.id];
|
|
68175
|
+
if (!by) continue;
|
|
68176
|
+
const out = {};
|
|
68177
|
+
for (const f of FINISHES) if (by[f] != null) out[FINISH_WORD[f]] = shopAmount(by[f], file4.cur[v.id]);
|
|
68178
|
+
if (Object.keys(out).length) prices[v.name] = out;
|
|
68179
|
+
}
|
|
68180
|
+
return { printing: p.label, asOf: file4.day, prices, credit: `Shop prices from ${VENDOR_PRICES_SOURCE}, ${file4.day}.` };
|
|
68181
|
+
}
|
|
68182
|
+
async function printingHistory(ph, p, detail) {
|
|
68183
|
+
const manifest = await ph.manifest();
|
|
68184
|
+
const files = (await ph.setFiles([p.set])).sort((a, b) => a.start - b.start);
|
|
68185
|
+
const finishes = {};
|
|
68186
|
+
for (const f of FINISHES) {
|
|
68187
|
+
const changes2 = [];
|
|
68188
|
+
let last;
|
|
68189
|
+
for (const file4 of files) {
|
|
68190
|
+
const rec = file4.p[p.number]?.[f];
|
|
68191
|
+
if (!rec) continue;
|
|
68192
|
+
const daily = decodeSeries(rec, file4.end - file4.start + 1);
|
|
68193
|
+
daily.forEach((cents2, i) => {
|
|
68194
|
+
if (cents2 === last) return;
|
|
68195
|
+
last = cents2;
|
|
68196
|
+
changes2.push([dayToDate(file4.start + i), cents2 == null ? null : usd(cents2)]);
|
|
68197
|
+
});
|
|
68198
|
+
}
|
|
68199
|
+
const priced = changes2.filter((c) => c[1] != null);
|
|
68200
|
+
if (!priced.length) continue;
|
|
68201
|
+
const lo = priced.reduce((a, b) => b[1] < a[1] ? b : a);
|
|
68202
|
+
const hi = priced.reduce((a, b) => b[1] > a[1] ? b : a);
|
|
68203
|
+
const cap2 = { summary: 40, standard: 120, full: Infinity }[detail];
|
|
68204
|
+
finishes[FINISH_WORD[f]] = {
|
|
68205
|
+
first: { date: priced[0][0], usd: priced[0][1] },
|
|
68206
|
+
// The newest price, and the day it last changed to it.
|
|
68207
|
+
current: { usd: priced[priced.length - 1][1], since: priced[priced.length - 1][0] },
|
|
68208
|
+
low: { date: lo[0], usd: lo[1] },
|
|
68209
|
+
high: { date: hi[0], usd: hi[1] },
|
|
68210
|
+
// Each day the price changed, and what to; a null is a day with no price.
|
|
68211
|
+
changes: changes2.slice(-cap2),
|
|
68212
|
+
...changes2.length > cap2 ? { earlierChanges: changes2.length - cap2, more: "Ask with detail: full for every change." } : {}
|
|
68213
|
+
};
|
|
68214
|
+
}
|
|
68215
|
+
if (!Object.keys(finishes).length) return { printing: p.label, none: "This printing isn't in the price history." };
|
|
68216
|
+
const special = files.some((f) => f.af?.includes(p.number));
|
|
68217
|
+
return {
|
|
68218
|
+
printing: p.label,
|
|
68219
|
+
from: manifest.from,
|
|
68220
|
+
asOf: manifest.asOf,
|
|
68221
|
+
...finishes,
|
|
68222
|
+
...special ? { foilNote: "TCGplayer also sells a special foil of this printing; the foil line here is its regular foil." } : {},
|
|
68223
|
+
credit: PRICE_HISTORY_CREDIT
|
|
68224
|
+
};
|
|
68225
|
+
}
|
|
68226
|
+
var VALUE_RANGES = ["30", "90", "all"];
|
|
68227
|
+
var collectionValueTool = {
|
|
68228
|
+
name: "collection_value",
|
|
68229
|
+
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.",
|
|
68230
|
+
input: {
|
|
68231
|
+
range: external_exports.enum(VALUE_RANGES).optional().describe("30 or 90 days, or all the history (default 90)."),
|
|
68232
|
+
movers: external_exports.number().int().min(0).max(50).optional().describe("Gainers and losers to list (default 10)."),
|
|
68233
|
+
detail: external_exports.enum(DETAILS).optional().describe("summary (default: a value per week), standard (every 3 days), or full (every day)."),
|
|
68234
|
+
refresh: refreshInput
|
|
68235
|
+
},
|
|
68236
|
+
async run(args, ctx) {
|
|
68237
|
+
const ph = ctx.priceHistory;
|
|
68238
|
+
if (!ph) throw new ToolProblem("The price history isn't available in this setup.");
|
|
68239
|
+
const stacks = await ctx.library.collection(args.refresh === true);
|
|
68240
|
+
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 }));
|
|
68241
|
+
const noPrinting = stacks.filter((s) => !(s.set && s.collectorNumber)).reduce((n2, s) => n2 + s.quantity, 0);
|
|
68242
|
+
if (!owned.length) {
|
|
68243
|
+
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." });
|
|
68244
|
+
}
|
|
68245
|
+
const manifest = await ph.manifest();
|
|
68246
|
+
const to = epochDay(manifest.asOf);
|
|
68247
|
+
const first = epochDay(manifest.from);
|
|
68248
|
+
const range = VALUE_RANGES.includes(args.range) ? args.range : "90";
|
|
68249
|
+
const from = range === "all" ? first : Math.max(first, to - Number(range) + 1);
|
|
68250
|
+
const files = await ph.setFiles(ownedSets(owned), monthOf(from));
|
|
68251
|
+
const h = computeValueHistory(owned, files, from, to);
|
|
68252
|
+
const points = h.points;
|
|
68253
|
+
const start = points.find((p) => p.cents > 0) ?? points[0];
|
|
68254
|
+
const end = points[points.length - 1];
|
|
68255
|
+
let hi = points[0];
|
|
68256
|
+
let lo = points[0];
|
|
68257
|
+
for (const p of points) {
|
|
68258
|
+
if (p.cents > hi.cents) hi = p;
|
|
68259
|
+
if (p.cents > 0 && (lo.cents === 0 || p.cents < lo.cents)) lo = p;
|
|
68260
|
+
}
|
|
68261
|
+
const n = typeof args.movers === "number" ? args.movers : 10;
|
|
68262
|
+
const move = (m) => ({
|
|
68263
|
+
card: m.printing.name,
|
|
68264
|
+
printing: `${m.printing.set} ${m.printing.collectorNumber}${m.finish !== "n" ? ` ${FINISH_WORD[m.finish]}` : ""}`,
|
|
68265
|
+
copies: m.printing.quantity,
|
|
68266
|
+
each: `$${usd(m.fromCents)} \u2192 $${usd(m.toCents)}`,
|
|
68267
|
+
change: usd(m.deltaCents)
|
|
68268
|
+
});
|
|
68269
|
+
const detail = detailOf(args);
|
|
68270
|
+
const step = { summary: 7, standard: 3, full: 1 }[detail];
|
|
68271
|
+
const series = points.filter((_, i) => (points.length - 1 - i) % step === 0).map((p) => [dayToDate(p.day), usd(p.cents)]);
|
|
68272
|
+
const standIns = manifest.fallbackDays.filter((d) => epochDay(d) >= from && epochDay(d) <= to);
|
|
68273
|
+
const delta = end.cents - start.cents;
|
|
68274
|
+
return json2({
|
|
68275
|
+
range: { from: dayToDate(from), to: manifest.asOf, days: to - from + 1 },
|
|
68276
|
+
valueNow: usd(end.cents),
|
|
68277
|
+
valueAtStart: { date: dayToDate(start.day), usd: usd(start.cents) },
|
|
68278
|
+
change: { usd: usd(delta), pct: start.cents > 0 ? Math.round(delta / start.cents * 1e3) / 10 : null },
|
|
68279
|
+
high: { date: dayToDate(hi.day), usd: usd(hi.cents) },
|
|
68280
|
+
low: { date: dayToDate(lo.day), usd: usd(lo.cents) },
|
|
68281
|
+
gainers: h.moves.filter((m) => m.deltaCents > 0).slice(0, n).map(move),
|
|
68282
|
+
losers: h.moves.filter((m) => m.deltaCents < 0).sort((a, b) => a.deltaCents - b.deltaCents).slice(0, n).map(move),
|
|
68283
|
+
copies: {
|
|
68284
|
+
priced: h.pricedCopies,
|
|
68285
|
+
notInHistory: h.unpricedCopies,
|
|
68286
|
+
...noPrinting ? { noPrinting } : {},
|
|
68287
|
+
...h.specialFoilCopies ? { specialFoils: h.specialFoilCopies, specialFoilNote: "Foils TCGplayer also sells as a special foil are valued at its regular foil price." } : {}
|
|
68288
|
+
},
|
|
68289
|
+
[`every${step === 1 ? "Day" : `${step}Days`}`]: series,
|
|
68290
|
+
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.",
|
|
68291
|
+
...standIns.length ? { standInDays: standIns, standInNote: "On these days MTGJSON had no prices, so Scryfall's stand in." } : {},
|
|
68292
|
+
...ph.stale().length ? { olderCopy: ph.stale() } : {},
|
|
68293
|
+
credit: PRICE_HISTORY_CREDIT
|
|
68294
|
+
});
|
|
68295
|
+
}
|
|
68296
|
+
};
|
|
68297
|
+
var KIND_WORD = { manual: "saved by you", auto: "saved automatically", session: "as you left it" };
|
|
68298
|
+
var deckHistoryTool = {
|
|
68299
|
+
name: "deck_history",
|
|
68300
|
+
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.",
|
|
68301
|
+
input: {
|
|
68302
|
+
deck: external_exports.string().min(1).describe("A saved deck's name or id."),
|
|
68303
|
+
version: external_exports.string().optional().describe("One version's id, from the list, for everything that changed since."),
|
|
68304
|
+
limit: external_exports.number().int().min(1).max(100).optional().describe("Versions to list (default 20)."),
|
|
68305
|
+
detail: detailInput,
|
|
68306
|
+
refresh: refreshInput
|
|
68307
|
+
},
|
|
68308
|
+
async run(args, ctx) {
|
|
68309
|
+
const [id, raw] = findDeck(String(args.deck), await ctx.library.decks(args.refresh === true));
|
|
68310
|
+
const catalog = await tryCatalog(ctx);
|
|
68311
|
+
const name = viewDeck(id, asDeck(raw), null).name;
|
|
68312
|
+
const list = await ctx.library.historyOf(id, args.refresh === true);
|
|
68313
|
+
if (!list?.length) {
|
|
68314
|
+
const copied = await ctx.library.historyCopied();
|
|
68315
|
+
return json2({
|
|
68316
|
+
deck: name,
|
|
68317
|
+
versions: 0,
|
|
68318
|
+
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."
|
|
68319
|
+
});
|
|
68320
|
+
}
|
|
68321
|
+
const r = catalog ? { resolveName: (oid) => catalog.index.byOracleId.get(oid)?.name, resolveSlug: (slug) => catalog.bySlug.get(slug)?.oracleId } : {};
|
|
68322
|
+
const stored = asDeck(raw);
|
|
68323
|
+
const now = {
|
|
68324
|
+
...stored,
|
|
68325
|
+
considering: stored.considering ?? /* @__PURE__ */ new Set(),
|
|
68326
|
+
sideboard: stored.sideboard ?? /* @__PURE__ */ new Set(),
|
|
68327
|
+
purchaseQuantities: stored.purchaseQuantities ?? /* @__PURE__ */ new Map(),
|
|
68328
|
+
soloHalf: stored.soloHalf ?? null
|
|
68329
|
+
};
|
|
68330
|
+
const detail = detailOf(args);
|
|
68331
|
+
const when = (at) => new Date(at).toISOString().replace(/\.\d+Z$/, "Z");
|
|
68332
|
+
const deckCount = (plan) => versionCards(plan, r).filter((c) => c.zone === "deck").reduce((s, c) => s + c.qty, 0);
|
|
68333
|
+
if (typeof args.version === "string" && args.version.trim()) {
|
|
68334
|
+
const cp = list.find((c) => c.id === args.version);
|
|
68335
|
+
if (!cp) throw new ToolProblem(`No version "${args.version}" in ${name}'s History. deck_history without version lists them.`);
|
|
68336
|
+
const d = diffVersions(cp.snapshot.plan, now, r);
|
|
68337
|
+
const cap2 = { summary: 60, standard: 150, full: Infinity }[detail];
|
|
68338
|
+
const nm = (c) => c.qty > 1 ? `${c.qty} ${c.name}` : c.name;
|
|
68339
|
+
return json2({
|
|
68340
|
+
deck: name,
|
|
68341
|
+
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 } : {} },
|
|
68342
|
+
sinceThen: isSameVersion(d) ? "No card changes since this version." : summarizeVersionDiff(d),
|
|
68343
|
+
addedSince: d.addedSince.slice(0, cap2).map((c) => `${nm(c)}${c.zone !== "deck" ? ` (${c.zone})` : ""}`),
|
|
68344
|
+
removedSince: d.removedSince.slice(0, cap2).map((c) => `${nm(c)}${c.zone !== "deck" ? ` (${c.zone})` : ""}`),
|
|
68345
|
+
...d.moved.length ? { moved: d.moved.map((m) => `${m.card.name}: ${m.then} \u2192 ${m.now}`) } : {},
|
|
68346
|
+
...d.countChanged.length ? { copies: d.countChanged.map((c) => `${c.card.name}: ${c.then} \u2192 ${c.now}`) } : {},
|
|
68347
|
+
...d.commanderChanged ? { commander: { then: d.commandersThen, now: d.commandersNow } } : {},
|
|
68348
|
+
...detail === "full" ? { cardsThen: versionCards(cp.snapshot.plan, r).map((c) => `${nm(c)}${c.zone !== "deck" ? ` (${c.zone})` : ""}`) } : {},
|
|
68349
|
+
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."
|
|
68350
|
+
});
|
|
68351
|
+
}
|
|
68352
|
+
const limit = typeof args.limit === "number" ? args.limit : 20;
|
|
68353
|
+
return json2({
|
|
68354
|
+
deck: name,
|
|
68355
|
+
versions: list.length,
|
|
68356
|
+
newestFirst: list.slice(0, limit).map((cp) => {
|
|
68357
|
+
const d = diffVersions(cp.snapshot.plan, now, r);
|
|
68358
|
+
return {
|
|
68359
|
+
id: cp.id,
|
|
68360
|
+
when: when(cp.at),
|
|
68361
|
+
kind: KIND_WORD[cp.kind],
|
|
68362
|
+
label: cp.label,
|
|
68363
|
+
cards: deckCount(cp.snapshot.plan),
|
|
68364
|
+
sinceThen: isSameVersion(d) ? "same cards as now" : summarizeVersionDiff(d)
|
|
68365
|
+
};
|
|
68366
|
+
}),
|
|
68367
|
+
...list.length > limit ? { more: list.length - limit } : {},
|
|
68368
|
+
note: "Each version's notes, description and primer aren't in what an access code reads; its cards, commander, name and label are."
|
|
68369
|
+
});
|
|
68370
|
+
}
|
|
68371
|
+
};
|
|
68372
|
+
var LISTS = ["wishlist", "binders", "seeds"];
|
|
68373
|
+
var listsTool = {
|
|
68374
|
+
name: "get_lists",
|
|
68375
|
+
description: 'The user\'s wishlist (cards they want, the printing when they named one, and the named lists each is on, like "For Krenko"), binders (named groups of collection cards) and seeds (cards they want to build around), with what they own of each. Seeds also list the commanders whose EDHREC pool holds the most of them, in their colors, as the Seeds page ranks them. `binder` names one binder to list its cards. Needs an access code that can read the wishlist, binders and seeds.',
|
|
68376
|
+
input: {
|
|
68377
|
+
list: external_exports.enum(LISTS).optional().describe("One list. Default: all three (a binder's cards only with `binder`)."),
|
|
68378
|
+
binder: external_exports.string().optional().describe("A binder's name: lists its cards."),
|
|
68379
|
+
refresh: refreshInput
|
|
68380
|
+
},
|
|
68381
|
+
async run(args, ctx) {
|
|
68382
|
+
if (!await ctx.library.has("lists")) throw new ToolProblem(noScopeMessage("lists"));
|
|
68383
|
+
const catalog = await ctx.catalog();
|
|
68384
|
+
const refresh = args.refresh === true;
|
|
68385
|
+
const lib = await ctx.library.library(refresh) ?? {};
|
|
68386
|
+
let ownedQty = null;
|
|
68387
|
+
try {
|
|
68388
|
+
const own2 = await ownership(ctx, catalog, refresh);
|
|
68389
|
+
ownedQty = (oid) => own2.owned.get(oid)?.stacks.reduce((n, s) => n + s.quantity, 0) ?? 0;
|
|
68390
|
+
} catch (e) {
|
|
68391
|
+
if (!isUnread(e)) throw e;
|
|
68392
|
+
}
|
|
68393
|
+
const day2 = (t) => typeof t === "number" && t > 0 ? new Date(t).toISOString().slice(0, 10) : void 0;
|
|
68394
|
+
const oidOf = (name, oracleId) => oracleId && catalog.index.byOracleId.has(oracleId) ? oracleId : resolveCardName(catalog.index, name)?.oracleId;
|
|
68395
|
+
const owns = (oid) => ownedQty && oid ? { owned: ownedQty(oid) } : {};
|
|
68396
|
+
const want = args.list ?? (typeof args.binder === "string" ? "binders" : void 0);
|
|
68397
|
+
const out = {};
|
|
68398
|
+
if (!want || want === "wishlist") {
|
|
68399
|
+
out.wishlist = (lib.wishlist ?? []).map((w) => ({
|
|
68400
|
+
name: w.name,
|
|
68401
|
+
...w.printing ? { printing: `${w.printing.set} ${w.printing.collectorNumber}${w.printing.foil ? " foil" : ""}` } : {},
|
|
68402
|
+
...w.lists?.length ? { lists: w.lists } : {},
|
|
68403
|
+
...day2(w.addedAt) ? { added: day2(w.addedAt) } : {},
|
|
68404
|
+
...owns(oidOf(w.name, w.oracleId))
|
|
68405
|
+
}));
|
|
68406
|
+
}
|
|
68407
|
+
if (!want || want === "binders") {
|
|
68408
|
+
const b = lib.binders ?? { v: 1, binders: [], membership: {} };
|
|
68409
|
+
const sorted2 = [...b.binders].sort((x, y) => x.order - y.order);
|
|
68410
|
+
const cardsOf = (id) => (b.membership[id] ?? []).map((key2) => {
|
|
68411
|
+
const [oid, print, finish] = key2.split("::");
|
|
68412
|
+
const card = catalog.index.byOracleId.get(oid);
|
|
68413
|
+
return { name: card?.name ?? "an unknown card", ...print ? { printing: `${print.replace("/", " ")}${finish === "f" ? " foil" : ""}` } : {}, ...owns(oid) };
|
|
68414
|
+
});
|
|
68415
|
+
if (typeof args.binder === "string" && args.binder.trim()) {
|
|
68416
|
+
const asked = args.binder.trim().toLowerCase();
|
|
68417
|
+
const hit = sorted2.find((x) => x.name.trim().toLowerCase() === asked);
|
|
68418
|
+
if (!hit) throw new ToolProblem(`No binder named "${args.binder}".${sorted2.length ? ` Binders: ${sorted2.map((x) => x.name).join(", ")}.` : " There are no binders."}`);
|
|
68419
|
+
out.binder = { name: hit.name, cards: cardsOf(hit.id) };
|
|
68420
|
+
} else {
|
|
68421
|
+
out.binders = sorted2.map((x) => ({ name: x.name, cards: (b.membership[x.id] ?? []).length }));
|
|
68422
|
+
}
|
|
68423
|
+
}
|
|
68424
|
+
if (!want || want === "seeds") {
|
|
68425
|
+
const seeds = lib.seeds ?? [];
|
|
68426
|
+
out.seeds = seeds.map((s) => ({ name: s.name, colors: s.colors.join("") || "C", ...day2(s.addedAt) ? { added: day2(s.addedAt) } : {}, ...owns(oidOf(s.name)) }));
|
|
68427
|
+
if (seeds.length && ctx.extras) {
|
|
68428
|
+
const index = await ctx.extras.commandersIndex().catch(() => null);
|
|
68429
|
+
if (index) {
|
|
68430
|
+
const nameOf = new Map(seeds.map((s) => [s.slug, s.name]));
|
|
68431
|
+
out.commandersForSeeds = {
|
|
68432
|
+
commanders: legalCommandersOnly(rankCommandersBySeeds(seeds, index)).slice(0, 10).map((r) => ({
|
|
68433
|
+
commander: r.commander.name,
|
|
68434
|
+
colors: r.commander.colors.join("") || "C",
|
|
68435
|
+
seedsInPool: `${r.hits} of ${seeds.length}`,
|
|
68436
|
+
...r.missingSlugs.length ? { notInPool: r.missingSlugs.map((x) => nameOf.get(x) ?? x) } : {},
|
|
68437
|
+
decks: r.commander.deckCount
|
|
68438
|
+
})),
|
|
68439
|
+
about: "Commanders in the seeds' colors whose EDHREC top cards include the most seeds, then the most decks: the Seeds page's ranking.",
|
|
68440
|
+
credit: EDHREC_CREDIT
|
|
68441
|
+
};
|
|
68442
|
+
}
|
|
68443
|
+
}
|
|
68444
|
+
}
|
|
68445
|
+
if (!ownedQty) out.ownedLeftOut = noScopeMessage("collection");
|
|
68446
|
+
return json2(out);
|
|
68447
|
+
}
|
|
68448
|
+
};
|
|
68449
|
+
var COLOR_MODES = { fits: "atMost", has: "includes", is: "exact" };
|
|
68450
|
+
var commandersToBuildTool = {
|
|
68451
|
+
name: "list_commanders",
|
|
68452
|
+
description: "Commanders ranked by how much of their EDHREC pool (each commander's ~120 most-played cards) the user already owns, as the Commanders page ranks them, or by how many decks EDHREC counts (`sortBy: popularity`). Filter by colors and bracket, or to commanders they own. The share owned is EDHVault's reading of EDHREC's lists. Needs an access code that can read the collection.",
|
|
68453
|
+
input: {
|
|
68454
|
+
colors: external_exports.string().regex(/^[WUBRGCwubrgc]{1,6}$/).optional().describe('Colors as letters, like "UB" or "C" for colorless.'),
|
|
68455
|
+
colorMode: external_exports.enum(["fits", "has", "is"]).optional().describe("fits (default): within those colors; has: includes them; is: exactly them."),
|
|
68456
|
+
bracket: external_exports.array(external_exports.number().int().min(1).max(5)).max(5).optional().describe("Only these EDHREC bracket estimates (1-5)."),
|
|
68457
|
+
ownedOnly: external_exports.boolean().optional().describe("Only commanders the user owns (both halves for a pair)."),
|
|
68458
|
+
sortBy: external_exports.enum(["synergy", "popularity"]).optional().describe("synergy (default): share of the pool owned; popularity: EDHREC's deck count."),
|
|
68459
|
+
limit: external_exports.number().int().min(1).max(100).optional().describe("How many (default 20)."),
|
|
68460
|
+
refresh: refreshInput
|
|
68461
|
+
},
|
|
68462
|
+
async run(args, ctx) {
|
|
68463
|
+
if (!ctx.extras) throw new ToolProblem("The commander data isn't available in this setup.");
|
|
68464
|
+
if (!await ctx.library.has("collection")) throw new ToolProblem(noScopeMessage("collection"));
|
|
68465
|
+
const catalog = await ctx.catalog();
|
|
68466
|
+
const owned = await ownedIdsOf(ctx, catalog, args.refresh === true);
|
|
68467
|
+
const index = await ctx.extras.commandersIndex();
|
|
68468
|
+
const colors = typeof args.colors === "string" ? [...new Set(args.colors.toUpperCase().split(""))] : void 0;
|
|
68469
|
+
let ranked = rankCommanders(index.commanders, owned.ids, catalog.index, {
|
|
68470
|
+
sortBy: args.sortBy === "popularity" ? "popularity" : "synergy",
|
|
68471
|
+
...colors ? { colors, colorMode: COLOR_MODES[args.colorMode ?? "fits"] } : {},
|
|
68472
|
+
...Array.isArray(args.bracket) && args.bracket.length ? { brackets: args.bracket } : {}
|
|
68473
|
+
});
|
|
68474
|
+
if (args.ownedOnly === true) ranked = ranked.filter((r) => r.commanderOwned);
|
|
68475
|
+
const limit = typeof args.limit === "number" ? args.limit : 20;
|
|
68476
|
+
return json2({
|
|
68477
|
+
found: ranked.length,
|
|
68478
|
+
commanders: ranked.slice(0, limit).map((r) => ({
|
|
68479
|
+
commander: r.commander.name,
|
|
68480
|
+
colors: r.commander.colors.join("") || "C",
|
|
68481
|
+
poolOwned: `${r.synergyOwned} of ${r.poolSize}`,
|
|
68482
|
+
share: `${Math.round(r.synergyRatio * 100)}%`,
|
|
68483
|
+
...r.commanderOwned ? { commanderOwned: true } : r.partiallyOwned ? { missingHalves: r.missingParts } : {},
|
|
68484
|
+
decks: r.commander.deckCount,
|
|
68485
|
+
...r.commander.bracket ? { bracket: r.commander.bracket } : {}
|
|
68486
|
+
})),
|
|
68487
|
+
about: "share: how much of EDHREC's top cards for the commander the user owns (EDHVault's reading; small pools count as at least 30 cards). get_rough_draft builds a deck for one.",
|
|
68488
|
+
dataAsOf: index.builtAt,
|
|
68489
|
+
credit: EDHREC_CREDIT
|
|
68490
|
+
});
|
|
68491
|
+
}
|
|
68492
|
+
};
|
|
68493
|
+
var roughDraftTool = {
|
|
68494
|
+
name: "get_rough_draft",
|
|
68495
|
+
description: "The deck builder's Rough draft for a commander: a full deck from EDHREC's cards for it, the user's owned cards first, then the most-played cards to buy (or owned cards only), shaped to the builder's slot targets, curve and land count. A suggestion only: nothing is saved. create_deck asks to make it. Uses the collection when the access code can read it; without one, everything is a card to buy.",
|
|
68496
|
+
input: {
|
|
68497
|
+
commander: external_exports.string().min(1).describe("The commander's name."),
|
|
68498
|
+
partner: external_exports.string().optional().describe("A second commander (partner, background, and the like)."),
|
|
68499
|
+
ownedOnly: external_exports.boolean().optional().describe("Only cards the user owns, no buys (needs the collection)."),
|
|
68500
|
+
bracket: external_exports.number().int().min(1).max(5).optional().describe("Target bracket: caps Game Changers as the builder does. Default: the commander's own estimate."),
|
|
68501
|
+
priceCap: external_exports.number().positive().optional().describe("Leave out cards to buy over this price (USD)."),
|
|
68502
|
+
refresh: refreshInput
|
|
68503
|
+
},
|
|
68504
|
+
async run(args, ctx) {
|
|
68505
|
+
const x = ctx.extras;
|
|
68506
|
+
if (!x) throw new ToolProblem("The commander data isn't available in this setup.");
|
|
68507
|
+
const catalog = await ctx.catalog();
|
|
68508
|
+
const card = (name) => {
|
|
68509
|
+
const c = resolveCardName(catalog.index, name);
|
|
68510
|
+
if (!c) throw new ToolProblem(`No card named "${name}".`);
|
|
68511
|
+
return c;
|
|
68512
|
+
};
|
|
68513
|
+
const commanders = [card(String(args.commander)), ...typeof args.partner === "string" && args.partner.trim() ? [card(args.partner)] : []];
|
|
68514
|
+
for (const c of commanders) if (!c.canBeCommander) throw new ToolProblem(`${c.name} can't be a commander.`);
|
|
68515
|
+
if (commanders.length === 2) {
|
|
68516
|
+
const pair = isPairLegal(commanders[0], commanders[1]);
|
|
68517
|
+
if (!pair.legal) throw new ToolProblem(`${commanders[0].name} and ${commanders[1].name} can't be commanders together: ${pair.reason}`);
|
|
68518
|
+
}
|
|
68519
|
+
const names = commanders.map((c) => c.name);
|
|
68520
|
+
const index = await x.commandersIndex();
|
|
68521
|
+
const slugs = candidateSlugs(names);
|
|
68522
|
+
const summary = index.commanders.find((c) => slugs.includes(c.slug));
|
|
68523
|
+
if (!summary) throw new ToolProblem(`EDHREC has no page for ${names.join(" + ")}, so there's nothing to draft from.`);
|
|
68524
|
+
const detail = await x.commanderDetail(summary.slug);
|
|
68525
|
+
let qty = /* @__PURE__ */ new Map();
|
|
68526
|
+
let connected = false;
|
|
68527
|
+
try {
|
|
68528
|
+
const own2 = await ownership(ctx, catalog, args.refresh === true);
|
|
68529
|
+
qty = new Map([...own2.owned].map(([oid, o]) => [oid, o.stacks.reduce((n, s) => n + s.quantity, 0)]));
|
|
68530
|
+
connected = true;
|
|
68531
|
+
} catch (e) {
|
|
68532
|
+
if (!isUnread(e)) throw e;
|
|
68533
|
+
}
|
|
68534
|
+
const ownedOnly = args.ownedOnly === true;
|
|
68535
|
+
if (ownedOnly && !connected) throw new ToolProblem(`${noScopeMessage("collection")} So an owned-only draft can't be built.`);
|
|
68536
|
+
for (const c of commanders) qty.delete(c.oracleId);
|
|
68537
|
+
const tags = catalog.otags();
|
|
68538
|
+
const lens = tags ? makeCardTagLens(tags) : null;
|
|
68539
|
+
const built = buildDeckSlots(detail, new Set(qty.keys()), catalog.index, { ownedQuantities: qty, tagLens: lens });
|
|
68540
|
+
const slots = commanders.length === 2 ? built.slots.map((s) => s.slot === "other" ? { ...s, target: Math.max(0, s.target - 1) } : s) : built.slots;
|
|
68541
|
+
const { plan } = buildWithRecommendedLands(
|
|
68542
|
+
(s) => computeBestBuildPlan(
|
|
68543
|
+
s,
|
|
68544
|
+
(oid) => qty.get(oid) ?? 0,
|
|
68545
|
+
detail,
|
|
68546
|
+
true,
|
|
68547
|
+
"synergy",
|
|
68548
|
+
void 0,
|
|
68549
|
+
typeof args.bracket === "number" ? args.bracket : void 0,
|
|
68550
|
+
catalog.index,
|
|
68551
|
+
typeof args.priceCap === "number" ? args.priceCap : null,
|
|
68552
|
+
ownedOnly
|
|
68553
|
+
),
|
|
68554
|
+
slots,
|
|
68555
|
+
catalog.index,
|
|
68556
|
+
lens
|
|
68557
|
+
);
|
|
68558
|
+
const bySlot = /* @__PURE__ */ new Map();
|
|
68559
|
+
const put = (slot, line) => bySlot.set(slot, [...bySlot.get(slot) ?? [], line]);
|
|
68560
|
+
const basics = new Map(plan.basicQuantities);
|
|
68561
|
+
for (const [oid, slot] of plan.assignments) {
|
|
68562
|
+
const c = catalog.index.byOracleId.get(oid);
|
|
68563
|
+
if (!c) continue;
|
|
68564
|
+
const n = basics.get(oid);
|
|
68565
|
+
basics.delete(oid);
|
|
68566
|
+
put(slot, n && n > 1 ? `${n} ${c.name}` : c.name);
|
|
68567
|
+
}
|
|
68568
|
+
for (const [oid, n] of basics) {
|
|
68569
|
+
const c = catalog.index.byOracleId.get(oid);
|
|
68570
|
+
if (c) put("lands", `${n} ${c.name}`);
|
|
68571
|
+
}
|
|
68572
|
+
const buys = [];
|
|
68573
|
+
for (const [slug, slot] of plan.purchases) {
|
|
68574
|
+
const c = catalog.bySlug.get(slug);
|
|
68575
|
+
const name = c?.name ?? slug;
|
|
68576
|
+
buys.push(name);
|
|
68577
|
+
put(slot, `${name} (buy)`);
|
|
68578
|
+
}
|
|
68579
|
+
const total = [...plan.assignments.keys()].reduce((n, oid) => n + (plan.basicQuantities.get(oid) ?? 1), 0) + [...basics.values()].reduce((n, v) => n + v, 0) + plan.purchases.size;
|
|
68580
|
+
return json2({
|
|
68581
|
+
commander: names.join(" + "),
|
|
68582
|
+
cards: total,
|
|
68583
|
+
owned: total - plan.purchases.size,
|
|
68584
|
+
toBuy: plan.purchases.size,
|
|
68585
|
+
...plan.skippedLowSignalOwned ? { ownedSetAside: plan.skippedLowSignalOwned } : {},
|
|
68586
|
+
slots: Object.fromEntries(bySlot),
|
|
68587
|
+
...connected ? {} : { ownedLeftOut: noScopeMessage("collection") },
|
|
68588
|
+
about: "EDHVault's Rough draft: the builder's own engine, from EDHREC's cards for this commander. A suggestion only, nothing saved: create_deck asks to make it (with each card, and to: deck).",
|
|
68589
|
+
dataAsOf: index.builtAt,
|
|
68590
|
+
credit: EDHREC_CREDIT
|
|
68591
|
+
});
|
|
68592
|
+
}
|
|
68593
|
+
};
|
|
68594
|
+
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, listsTool, commandersToBuildTool, roughDraftTool];
|
|
66160
68595
|
|
|
66161
68596
|
// src/server.ts
|
|
66162
|
-
|
|
68597
|
+
function buildServer(version2, ctx) {
|
|
66163
68598
|
const server = new McpServer({ name: "edhvault", version: version2 });
|
|
66164
68599
|
for (const tool of TOOLS) {
|
|
66165
68600
|
server.registerTool(
|
|
@@ -66175,7 +68610,10 @@ async function serve(version2, ctx) {
|
|
|
66175
68610
|
}
|
|
66176
68611
|
);
|
|
66177
68612
|
}
|
|
66178
|
-
|
|
68613
|
+
return server;
|
|
68614
|
+
}
|
|
68615
|
+
async function serve(version2, ctx) {
|
|
68616
|
+
await buildServer(version2, ctx).connect(new StdioServerTransport());
|
|
66179
68617
|
log.info(`edhvault-mcp ${version2} serving ${TOOLS.length} tools`);
|
|
66180
68618
|
}
|
|
66181
68619
|
|
|
@@ -66185,7 +68623,7 @@ var say = (m) => process.stderr.write(`${m}
|
|
|
66185
68623
|
var transport = {
|
|
66186
68624
|
fetchImpl: ((url2, init) => fetch(`${ORIGIN}${url2}`, {
|
|
66187
68625
|
...init,
|
|
66188
|
-
headers: { ...Object.fromEntries(new Headers(init?.headers)), "user-agent": `edhvault-mcp/${"0.2.
|
|
68626
|
+
headers: { ...Object.fromEntries(new Headers(init?.headers)), "user-agent": `edhvault-mcp/${"0.2.25"}` }
|
|
66189
68627
|
}))
|
|
66190
68628
|
};
|
|
66191
68629
|
async function store(dir) {
|
|
@@ -66201,11 +68639,11 @@ async function secretFromEnv() {
|
|
|
66201
68639
|
async function main() {
|
|
66202
68640
|
const args = process.argv.slice(2);
|
|
66203
68641
|
if (args.includes("--version")) {
|
|
66204
|
-
say("0.2.
|
|
68642
|
+
say("0.2.25");
|
|
66205
68643
|
return;
|
|
66206
68644
|
}
|
|
66207
68645
|
const dir = configDir();
|
|
66208
|
-
configureLog({ file:
|
|
68646
|
+
configureLog({ file: join10(dir, "edhvault-mcp.log"), debug: args.includes("--debug") });
|
|
66209
68647
|
const secrets = await store(dir);
|
|
66210
68648
|
if (args[0] === "login") {
|
|
66211
68649
|
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
@@ -66218,19 +68656,20 @@ async function main() {
|
|
|
66218
68656
|
}
|
|
66219
68657
|
if (args[0] === "logout") {
|
|
66220
68658
|
secrets.remove();
|
|
66221
|
-
|
|
68659
|
+
rmSync5(join10(dir, "view"), { recursive: true, force: true });
|
|
66222
68660
|
say("Forgotten on this machine. To block the code everywhere, remove it in Settings.");
|
|
66223
68661
|
return;
|
|
66224
68662
|
}
|
|
66225
68663
|
const extras = extrasLoader({ dir, origin: ORIGIN });
|
|
66226
68664
|
const fromEnv = await secretFromEnv();
|
|
66227
|
-
await serve("0.2.
|
|
68665
|
+
await serve("0.2.25", {
|
|
66228
68666
|
// The saved login is read again when not connected and on refresh, so
|
|
66229
68667
|
// `login` in another terminal works without restarting the AI tool.
|
|
66230
68668
|
library: new Library({ secret: () => fromEnv ?? loadSecret(secrets), dir, transport }),
|
|
66231
68669
|
catalog: catalogLoader({ dir, origin: ORIGIN, prices: extras.prices }),
|
|
66232
68670
|
combos: comboLoader({ dir, origin: ORIGIN }),
|
|
66233
68671
|
extras,
|
|
68672
|
+
priceHistory: priceHistoryLoader({ dir, origin: ORIGIN }),
|
|
66234
68673
|
// A Moxfield or Archidekt link is read by edhvault.com's own import route.
|
|
66235
68674
|
siteFetch: transport.fetchImpl
|
|
66236
68675
|
});
|