bbdata-cli 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/bbdata.js +109 -6
- package/dist/bin/bbdata.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.js +103 -2
- package/dist/src/index.js.map +1 -1
- package/dist/templates/queries/hitter-batted-ball.ts +66 -0
- package/dist/templates/queries/hitter-hot-cold-zones.ts +81 -0
- package/dist/templates/queries/hitter-vs-pitch-type.ts +78 -0
- package/dist/templates/queries/index.ts +24 -0
- package/dist/templates/queries/leaderboard-comparison.ts +72 -0
- package/dist/templates/queries/leaderboard-custom.ts +90 -0
- package/dist/templates/queries/matchup-pitcher-vs-hitter.ts +81 -0
- package/dist/templates/queries/matchup-situational.ts +68 -0
- package/dist/templates/queries/pitcher-arsenal.ts +89 -0
- package/dist/templates/queries/pitcher-handedness-splits.ts +81 -0
- package/dist/templates/queries/pitcher-velocity-trend.ts +73 -0
- package/dist/templates/queries/registry.ts +73 -0
- package/dist/templates/queries/trend-rolling-average.ts +86 -0
- package/dist/templates/queries/trend-year-over-year.ts +73 -0
- package/dist/templates/reports/advance-lineup.hbs +29 -0
- package/dist/templates/reports/advance-sp.hbs +60 -0
- package/dist/templates/reports/college-hitter-draft.hbs +49 -0
- package/dist/templates/reports/college-pitcher-draft.hbs +48 -0
- package/dist/templates/reports/dev-progress.hbs +29 -0
- package/dist/templates/reports/draft-board-card.hbs +35 -0
- package/dist/templates/reports/hs-prospect.hbs +48 -0
- package/dist/templates/reports/partials/footer.hbs +7 -0
- package/dist/templates/reports/partials/header.hbs +12 -0
- package/dist/templates/reports/post-promotion.hbs +25 -0
- package/dist/templates/reports/pro-hitter-eval.hbs +65 -0
- package/dist/templates/reports/pro-pitcher-eval.hbs +69 -0
- package/dist/templates/reports/registry.ts +215 -0
- package/dist/templates/reports/relief-pitcher-quick.hbs +29 -0
- package/dist/templates/reports/trade-target-onepager.hbs +45 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ interface QueryOptions {
|
|
|
17
17
|
format?: OutputFormat;
|
|
18
18
|
source?: string;
|
|
19
19
|
cache?: boolean;
|
|
20
|
+
stdin?: boolean;
|
|
20
21
|
}
|
|
21
22
|
interface QueryResult {
|
|
22
23
|
data: Record<string, unknown>[];
|
|
@@ -44,6 +45,7 @@ interface ReportOptions {
|
|
|
44
45
|
audience?: Audience;
|
|
45
46
|
format?: 'markdown' | 'json';
|
|
46
47
|
validate?: boolean;
|
|
48
|
+
stdin?: boolean;
|
|
47
49
|
}
|
|
48
50
|
interface ReportResult {
|
|
49
51
|
content: string;
|
|
@@ -207,7 +209,7 @@ type BbdataConfig = z.infer<typeof ConfigSchema>;
|
|
|
207
209
|
declare function getConfig(): BbdataConfig;
|
|
208
210
|
declare function setConfig(updates: Partial<BbdataConfig>): BbdataConfig;
|
|
209
211
|
|
|
210
|
-
type DataSource = 'savant' | 'fangraphs' | 'mlb-stats-api' | 'baseball-reference';
|
|
212
|
+
type DataSource = 'savant' | 'fangraphs' | 'mlb-stats-api' | 'baseball-reference' | 'stdin';
|
|
211
213
|
declare const PitchDataSchema: z.ZodObject<{
|
|
212
214
|
pitcher_id: z.ZodString;
|
|
213
215
|
pitcher_name: z.ZodString;
|
package/dist/src/index.js
CHANGED
|
@@ -398,13 +398,88 @@ var BaseballReferenceAdapter = class {
|
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
400
|
|
|
401
|
+
// src/adapters/stdin.ts
|
|
402
|
+
var StdinAdapter = class {
|
|
403
|
+
source = "stdin";
|
|
404
|
+
description = "Local data from stdin (for sandboxed environments)";
|
|
405
|
+
data = [];
|
|
406
|
+
player = null;
|
|
407
|
+
loaded = false;
|
|
408
|
+
/**
|
|
409
|
+
* Load data from a pre-read stdin string.
|
|
410
|
+
* Called by the CLI before the adapter is used.
|
|
411
|
+
*/
|
|
412
|
+
load(raw) {
|
|
413
|
+
try {
|
|
414
|
+
const parsed = JSON.parse(raw);
|
|
415
|
+
if (Array.isArray(parsed)) {
|
|
416
|
+
this.data = parsed;
|
|
417
|
+
} else if (parsed.data && Array.isArray(parsed.data)) {
|
|
418
|
+
this.data = parsed.data;
|
|
419
|
+
if (parsed.player) {
|
|
420
|
+
this.player = parsed.player;
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
423
|
+
throw new Error('Expected JSON array or { "data": [...] } object');
|
|
424
|
+
}
|
|
425
|
+
this.loaded = true;
|
|
426
|
+
log.info(`Stdin adapter loaded ${this.data.length} records`);
|
|
427
|
+
} catch (error) {
|
|
428
|
+
throw new Error(
|
|
429
|
+
`Failed to parse stdin data: ${error instanceof Error ? error.message : String(error)}`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
supports(_query) {
|
|
434
|
+
return this.loaded && this.data.length > 0;
|
|
435
|
+
}
|
|
436
|
+
async fetch(query2) {
|
|
437
|
+
if (!this.loaded) {
|
|
438
|
+
throw new Error("Stdin adapter has no data \u2014 pipe JSON via stdin with --stdin flag");
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
data: this.data,
|
|
442
|
+
source: "stdin",
|
|
443
|
+
cached: false,
|
|
444
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
445
|
+
meta: {
|
|
446
|
+
rowCount: this.data.length,
|
|
447
|
+
season: query2.season,
|
|
448
|
+
query: query2
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
async resolvePlayer(name) {
|
|
453
|
+
if (this.player && this.player.name.toLowerCase() === name.toLowerCase()) {
|
|
454
|
+
return this.player;
|
|
455
|
+
}
|
|
456
|
+
const firstRecord = this.data[0];
|
|
457
|
+
if (firstRecord) {
|
|
458
|
+
const id = firstRecord.pitcher_id ?? firstRecord.player_id ?? "";
|
|
459
|
+
const recordName = firstRecord.pitcher_name ?? firstRecord.player_name ?? name;
|
|
460
|
+
if (id) {
|
|
461
|
+
return {
|
|
462
|
+
mlbam_id: id,
|
|
463
|
+
name: recordName
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
401
471
|
// src/adapters/index.ts
|
|
472
|
+
var stdinAdapter = new StdinAdapter();
|
|
402
473
|
var adapters = {
|
|
403
474
|
"mlb-stats-api": new MlbStatsApiAdapter(),
|
|
404
475
|
"savant": new SavantAdapter(),
|
|
405
476
|
"fangraphs": new FanGraphsAdapter(),
|
|
406
|
-
"baseball-reference": new BaseballReferenceAdapter()
|
|
477
|
+
"baseball-reference": new BaseballReferenceAdapter(),
|
|
478
|
+
"stdin": stdinAdapter
|
|
407
479
|
};
|
|
480
|
+
function getStdinAdapter() {
|
|
481
|
+
return stdinAdapter;
|
|
482
|
+
}
|
|
408
483
|
function resolveAdapters(preferred) {
|
|
409
484
|
return preferred.map((source) => adapters[source]).filter(Boolean);
|
|
410
485
|
}
|
|
@@ -583,6 +658,20 @@ function getTemplatesDir() {
|
|
|
583
658
|
return dir;
|
|
584
659
|
}
|
|
585
660
|
|
|
661
|
+
// src/utils/stdin.ts
|
|
662
|
+
function readStdin() {
|
|
663
|
+
return new Promise((resolve, reject) => {
|
|
664
|
+
if (process.stdin.isTTY) {
|
|
665
|
+
reject(new Error(`--stdin flag requires piped input. Usage: echo '{"data":[...]}' | bbdata query ... --stdin`));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
const chunks = [];
|
|
669
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
670
|
+
process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
|
|
671
|
+
process.stdin.on("error", reject);
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
586
675
|
// src/templates/queries/registry.ts
|
|
587
676
|
var templates = /* @__PURE__ */ new Map();
|
|
588
677
|
function registerTemplate(template13) {
|
|
@@ -1434,6 +1523,12 @@ registerTemplate(template12);
|
|
|
1434
1523
|
|
|
1435
1524
|
// src/commands/query.ts
|
|
1436
1525
|
async function query(options) {
|
|
1526
|
+
if (options.stdin) {
|
|
1527
|
+
const raw = await readStdin();
|
|
1528
|
+
const adapter = getStdinAdapter();
|
|
1529
|
+
adapter.load(raw);
|
|
1530
|
+
options.source = "stdin";
|
|
1531
|
+
}
|
|
1437
1532
|
const config = getConfig();
|
|
1438
1533
|
const outputFormat = options.format ?? config.defaultFormat;
|
|
1439
1534
|
const template13 = getTemplate(options.template);
|
|
@@ -1772,6 +1867,11 @@ ${sections}
|
|
|
1772
1867
|
`;
|
|
1773
1868
|
}
|
|
1774
1869
|
async function report(options) {
|
|
1870
|
+
if (options.stdin) {
|
|
1871
|
+
const raw = await readStdin();
|
|
1872
|
+
const adapter = getStdinAdapter();
|
|
1873
|
+
adapter.load(raw);
|
|
1874
|
+
}
|
|
1775
1875
|
const config = getConfig();
|
|
1776
1876
|
const audience = options.audience ?? config.defaultAudience;
|
|
1777
1877
|
const template13 = getReportTemplate(options.template);
|
|
@@ -1791,7 +1891,8 @@ ${available}`);
|
|
|
1791
1891
|
player: options.player,
|
|
1792
1892
|
team: options.team,
|
|
1793
1893
|
season,
|
|
1794
|
-
format: "json"
|
|
1894
|
+
format: "json",
|
|
1895
|
+
...options.stdin ? { source: "stdin" } : {}
|
|
1795
1896
|
});
|
|
1796
1897
|
dataResults[req.queryTemplate] = result.data;
|
|
1797
1898
|
if (!dataSources.includes(result.meta.source)) {
|