@madewithremy/admin 0.1.63 → 0.1.65

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/prod.js CHANGED
@@ -78,7 +78,7 @@ var Args = class {
78
78
  positionals;
79
79
  flags;
80
80
  /** A required positional. Presence was validated at parse time. */
81
- req(name) {
81
+ required(name) {
82
82
  const value = this.positionals[this.indexOf(name)];
83
83
  if (value === void 0) {
84
84
  throw new UsageError(
@@ -89,7 +89,7 @@ var Args = class {
89
89
  return value;
90
90
  }
91
91
  /** An optional positional. */
92
- opt(name) {
92
+ optional(name) {
93
93
  return this.positionals[this.indexOf(name)];
94
94
  }
95
95
  /** The variadic tail. */
@@ -270,7 +270,7 @@ function isTransientError(err) {
270
270
  return err instanceof TypeError;
271
271
  }
272
272
  var REPORT_TIMEOUT_MS = 6e4;
273
- function seg(value) {
273
+ function encodePathSegment(value) {
274
274
  return encodeURIComponent(String(value));
275
275
  }
276
276
  function qs(params) {
@@ -361,7 +361,7 @@ function get(ctx, requestId) {
361
361
  return call(
362
362
  ctx,
363
363
  "GET",
364
- `/_internal/v2/apps/${ctx.appId}/requests/${seg(requestId)}`
364
+ `/_internal/v2/apps/${ctx.appId}/requests/${encodePathSegment(requestId)}`
365
365
  );
366
366
  }
367
367
  function statsSummary(ctx, params = {}) {
@@ -375,7 +375,7 @@ function statsForMethod(ctx, methodId, params = {}) {
375
375
  return call(
376
376
  ctx,
377
377
  "GET",
378
- `/_internal/v2/apps/${ctx.appId}/metrics/methods/${seg(methodId)}${qs(params)}`
378
+ `/_internal/v2/apps/${ctx.appId}/metrics/methods/${encodePathSegment(methodId)}${qs(params)}`
379
379
  );
380
380
  }
381
381
 
@@ -431,13 +431,13 @@ async function pollUntil(read, isSettled, options) {
431
431
  function elapsedSeconds(start2) {
432
432
  return Math.round((Date.now() - start2) / 1e3);
433
433
  }
434
- function timedOut(timeoutMs, still) {
434
+ function timeoutMessage(timeoutMs, still) {
435
435
  return `Timed out after ${Math.round(timeoutMs / 1e3)}s ${still}`;
436
436
  }
437
437
 
438
438
  // src/output.ts
439
439
  var PRETTY = process.stdout.isTTY === true;
440
- function out(data) {
440
+ function printJson(data) {
441
441
  process.stdout.write(`${JSON.stringify(data, null, PRETTY ? 2 : 0)}
442
442
  `);
443
443
  }
@@ -496,7 +496,7 @@ var requestsSpecs = {
496
496
  }
497
497
  };
498
498
  async function requestsList(ctx, a) {
499
- out(
499
+ printJson(
500
500
  await list(ctx, {
501
501
  methodId: a.str("method"),
502
502
  status: a.str("status"),
@@ -506,15 +506,15 @@ async function requestsList(ctx, a) {
506
506
  );
507
507
  }
508
508
  async function requestsGet(ctx, a) {
509
- out(await get(ctx, a.req("requestId")));
509
+ printJson(await get(ctx, a.required("requestId")));
510
510
  }
511
511
  async function requestsStats(ctx, a) {
512
512
  const window = { start: a.str("start"), end: a.str("end") };
513
513
  const method = a.str("method");
514
514
  if (method) {
515
- out(await statsForMethod(ctx, method, window));
515
+ printJson(await statsForMethod(ctx, method, window));
516
516
  } else {
517
- out(await statsSummary(ctx, window));
517
+ printJson(await statsSummary(ctx, window));
518
518
  }
519
519
  }
520
520
  var requestsHandlers = {
@@ -559,14 +559,14 @@ function occurrences(ctx, fingerprint, params = {}) {
559
559
  return call(
560
560
  ctx,
561
561
  "GET",
562
- `/_internal/v2/apps/${ctx.appId}/frontend-errors/${seg(fingerprint)}/events${qs(params)}`
562
+ `/_internal/v2/apps/${ctx.appId}/frontend-errors/${encodePathSegment(fingerprint)}/events${qs(params)}`
563
563
  );
564
564
  }
565
565
  function get2(ctx, eventId) {
566
566
  return call(
567
567
  ctx,
568
568
  "GET",
569
- `/_internal/v2/apps/${ctx.appId}/frontend-errors/events/${seg(eventId)}`
569
+ `/_internal/v2/apps/${ctx.appId}/frontend-errors/events/${encodePathSegment(eventId)}`
570
570
  );
571
571
  }
572
572
  function stats(ctx, params = {}) {
@@ -612,7 +612,7 @@ var crashesSpecs = {
612
612
  }
613
613
  };
614
614
  async function crashesList(ctx, a) {
615
- out(
615
+ printJson(
616
616
  await list2(ctx, {
617
617
  releaseId: a.str("release"),
618
618
  sort: a.str("sort"),
@@ -623,8 +623,8 @@ async function crashesList(ctx, a) {
623
623
  );
624
624
  }
625
625
  async function crashesOccurrences(ctx, a) {
626
- out(
627
- await occurrences(ctx, a.req("fingerprint"), {
626
+ printJson(
627
+ await occurrences(ctx, a.required("fingerprint"), {
628
628
  releaseId: a.str("release"),
629
629
  cursor: a.str("cursor"),
630
630
  limit: a.num("limit"),
@@ -634,10 +634,10 @@ async function crashesOccurrences(ctx, a) {
634
634
  );
635
635
  }
636
636
  async function crashesGet(ctx, a) {
637
- out(await get2(ctx, a.req("eventId")));
637
+ printJson(await get2(ctx, a.required("eventId")));
638
638
  }
639
639
  async function crashesStats(ctx, a) {
640
- out(
640
+ printJson(
641
641
  await stats(ctx, {
642
642
  releaseId: a.str("release"),
643
643
  start: a.str("start"),
@@ -747,7 +747,7 @@ function crawlers(ctx, params) {
747
747
  return call(
748
748
  ctx,
749
749
  "GET",
750
- `/_internal/v2/apps/${ctx.appId}/insights/crawlers/${seg(kind)}${qs(rest)}`
750
+ `/_internal/v2/apps/${ctx.appId}/insights/crawlers/${encodePathSegment(kind)}${qs(rest)}`
751
751
  );
752
752
  }
753
753
 
@@ -835,7 +835,7 @@ var analyticsSpecs = {
835
835
  }
836
836
  };
837
837
  async function analyticsQuery(ctx, a) {
838
- const raw = a.req("body");
838
+ const raw = a.required("body");
839
839
  let body;
840
840
  try {
841
841
  body = JSON.parse(raw);
@@ -845,10 +845,10 @@ async function analyticsQuery(ctx, a) {
845
845
  analyticsSpecs["analytics query"].usage
846
846
  );
847
847
  }
848
- out(await query(ctx, body));
848
+ printJson(await query(ctx, body));
849
849
  }
850
850
  async function analyticsBatch(ctx, a) {
851
- const raw = a.req("body");
851
+ const raw = a.required("body");
852
852
  let body;
853
853
  try {
854
854
  body = JSON.parse(raw);
@@ -859,9 +859,9 @@ async function analyticsBatch(ctx, a) {
859
859
  );
860
860
  }
861
861
  const queries = Array.isArray(body) ? body : body?.queries;
862
- out(await batch(ctx, queries));
862
+ printJson(await batch(ctx, queries));
863
863
  }
864
- function visitReadBody(raw, command) {
864
+ function readFunnelOrPathsBody(raw, command) {
865
865
  if (raw === void 0) {
866
866
  return {};
867
867
  }
@@ -877,20 +877,23 @@ function visitReadBody(raw, command) {
877
877
  return body;
878
878
  }
879
879
  async function analyticsFunnel(ctx, a) {
880
- out(
880
+ printJson(
881
881
  await funnel(
882
882
  ctx,
883
- visitReadBody(a.req("body"), "analytics funnel")
883
+ readFunnelOrPathsBody(a.required("body"), "analytics funnel")
884
884
  )
885
885
  );
886
886
  }
887
887
  async function analyticsPaths(ctx, a) {
888
- out(
889
- await paths(ctx, visitReadBody(a.str("body"), "analytics paths"))
888
+ printJson(
889
+ await paths(
890
+ ctx,
891
+ readFunnelOrPathsBody(a.str("body"), "analytics paths")
892
+ )
890
893
  );
891
894
  }
892
895
  async function analyticsSources(ctx, a) {
893
- out(
896
+ printJson(
894
897
  await sources(ctx, {
895
898
  releaseId: a.str("release"),
896
899
  start: a.str("start"),
@@ -912,7 +915,7 @@ async function analyticsSources(ctx, a) {
912
915
  );
913
916
  }
914
917
  async function analyticsMap(ctx, a) {
915
- out(
918
+ printJson(
916
919
  await map(ctx, {
917
920
  releaseId: a.str("release"),
918
921
  start: a.str("start"),
@@ -934,10 +937,10 @@ async function analyticsMap(ctx, a) {
934
937
  );
935
938
  }
936
939
  async function analyticsLive(ctx) {
937
- out(await live(ctx));
940
+ printJson(await live(ctx));
938
941
  }
939
942
  async function analyticsAiSources(ctx, a) {
940
- out(
943
+ printJson(
941
944
  await aiSources(ctx, {
942
945
  releaseId: a.str("release"),
943
946
  start: a.str("start"),
@@ -947,9 +950,9 @@ async function analyticsAiSources(ctx, a) {
947
950
  );
948
951
  }
949
952
  async function analyticsCrawlers(ctx, a) {
950
- out(
953
+ printJson(
951
954
  await crawlers(ctx, {
952
- kind: a.req("sub"),
955
+ kind: a.required("sub"),
953
956
  releaseId: a.str("release"),
954
957
  start: a.str("start"),
955
958
  end: a.str("end"),
@@ -1113,14 +1116,14 @@ function get3(ctx, releaseId) {
1113
1116
  return call(
1114
1117
  ctx,
1115
1118
  "GET",
1116
- `/_internal/v2/apps/${ctx.appId}/releases/${seg(releaseId)}`
1119
+ `/_internal/v2/apps/${ctx.appId}/releases/${encodePathSegment(releaseId)}`
1117
1120
  );
1118
1121
  }
1119
- function byCommit(ctx, commitSha) {
1122
+ function getByCommit(ctx, commitSha) {
1120
1123
  return tryCall(
1121
1124
  ctx,
1122
1125
  "GET",
1123
- `/_internal/v2/apps/${ctx.appId}/releases/by-commit/${seg(commitSha)}`
1126
+ `/_internal/v2/apps/${ctx.appId}/releases/by-commit/${encodePathSegment(commitSha)}`
1124
1127
  );
1125
1128
  }
1126
1129
  async function dashboardLive(ctx) {
@@ -1177,7 +1180,7 @@ async function waitForCommit(ctx, params) {
1177
1180
  const start2 = Date.now();
1178
1181
  let release;
1179
1182
  while (true) {
1180
- const r = await byCommit(ctx, commitSha);
1183
+ const r = await getByCommit(ctx, commitSha);
1181
1184
  if (r.ok) {
1182
1185
  release = r.body;
1183
1186
  break;
@@ -1227,7 +1230,7 @@ async function waitForCommit(ctx, params) {
1227
1230
  `${release.status}\u2026 (${Math.round((Date.now() - start2) / 1e3)}s)`
1228
1231
  );
1229
1232
  await sleep(POLL_MS);
1230
- const r = await byCommit(ctx, commitSha);
1233
+ const r = await getByCommit(ctx, commitSha);
1231
1234
  if (r.ok) {
1232
1235
  release = r.body;
1233
1236
  }
@@ -1283,26 +1286,26 @@ function expandCommitSha(sha) {
1283
1286
  return sha;
1284
1287
  }
1285
1288
  }
1286
- function finishWait(data, code) {
1287
- out(data);
1289
+ function printWaitResult(data, code) {
1290
+ printJson(data);
1288
1291
  process.exitCode = code;
1289
1292
  }
1290
1293
  async function releasesList(ctx, a) {
1291
1294
  const result = await list3(ctx, { limit: a.num("limit") });
1292
- out(result.releases ?? []);
1295
+ printJson(result.releases ?? []);
1293
1296
  }
1294
1297
  async function releasesGet(ctx, a) {
1295
- out(await get3(ctx, a.req("releaseId")));
1298
+ printJson(await get3(ctx, a.required("releaseId")));
1296
1299
  }
1297
1300
  async function releasesCurrent(ctx) {
1298
1301
  const live2 = await dashboardLive(ctx);
1299
1302
  if (!live2) {
1300
1303
  fatal("No live release \u2014 publish first.");
1301
1304
  }
1302
- out(live2);
1305
+ printJson(live2);
1303
1306
  }
1304
1307
  async function releasesStatus(ctx, a) {
1305
- const releaseId = a.req("releaseId");
1308
+ const releaseId = a.required("releaseId");
1306
1309
  const wait = a.bool("wait");
1307
1310
  const timeout = (a.num("timeout") ?? 120) * 1e3;
1308
1311
  const startTime = Date.now();
@@ -1314,13 +1317,13 @@ async function releasesStatus(ctx, a) {
1314
1317
  "superseded"
1315
1318
  ]);
1316
1319
  if (!wait) {
1317
- out(await get3(ctx, releaseId));
1320
+ printJson(await get3(ctx, releaseId));
1318
1321
  return;
1319
1322
  }
1320
1323
  while (true) {
1321
1324
  const release = await get3(ctx, releaseId);
1322
1325
  if (TERMINAL.has(release.status)) {
1323
- out(release);
1326
+ printJson(release);
1324
1327
  return;
1325
1328
  }
1326
1329
  if (Date.now() - startTime > timeout) {
@@ -1350,7 +1353,7 @@ async function releasesWait(ctx, a) {
1350
1353
  });
1351
1354
  switch (result.outcome) {
1352
1355
  case "not_found":
1353
- finishWait(
1356
+ printWaitResult(
1354
1357
  {
1355
1358
  status: "not_found",
1356
1359
  commitSha: commit,
@@ -1360,7 +1363,7 @@ async function releasesWait(ctx, a) {
1360
1363
  );
1361
1364
  return;
1362
1365
  case "timeout":
1363
- finishWait(
1366
+ printWaitResult(
1364
1367
  {
1365
1368
  ...result.summary,
1366
1369
  error: result.error
@@ -1370,13 +1373,13 @@ async function releasesWait(ctx, a) {
1370
1373
  return;
1371
1374
  case "live":
1372
1375
  case "preview":
1373
- finishWait(result.summary, EXIT.ok);
1376
+ printWaitResult(result.summary, EXIT.ok);
1374
1377
  return;
1375
1378
  case "failed":
1376
- finishWait(result.summary, EXIT.buildFailed);
1379
+ printWaitResult(result.summary, EXIT.buildFailed);
1377
1380
  return;
1378
1381
  case "superseded":
1379
- finishWait(result.summary, EXIT.superseded);
1382
+ printWaitResult(result.summary, EXIT.superseded);
1380
1383
  return;
1381
1384
  }
1382
1385
  }
@@ -1449,7 +1452,7 @@ function revoke(ctx, shareId) {
1449
1452
  return call(
1450
1453
  ctx,
1451
1454
  "POST",
1452
- `/_internal/v2/apps/${ctx.appId}/preview/shares/${seg(shareId)}/revoke`
1455
+ `/_internal/v2/apps/${ctx.appId}/preview/shares/${encodePathSegment(shareId)}/revoke`
1453
1456
  );
1454
1457
  }
1455
1458
 
@@ -1473,19 +1476,19 @@ var previewsSpecs = {
1473
1476
  }
1474
1477
  };
1475
1478
  async function previewsShare(ctx, a) {
1476
- out(
1479
+ printJson(
1477
1480
  await share(ctx, {
1478
- branch: a.req("branch"),
1481
+ branch: a.required("branch"),
1479
1482
  days: a.num("days"),
1480
1483
  label: a.str("label")
1481
1484
  })
1482
1485
  );
1483
1486
  }
1484
1487
  async function previewsList(ctx, a) {
1485
- out(await list4(ctx, a.req("branch")));
1488
+ printJson(await list4(ctx, a.required("branch")));
1486
1489
  }
1487
1490
  async function previewsRevoke(ctx, a) {
1488
- out(await revoke(ctx, a.req("shareId")));
1491
+ printJson(await revoke(ctx, a.required("shareId")));
1489
1492
  }
1490
1493
  var previewsHandlers = {
1491
1494
  "previews share": previewsShare,
@@ -1532,7 +1535,7 @@ function getRelease(ctx, releaseId) {
1532
1535
  return call(
1533
1536
  ctx,
1534
1537
  "GET",
1535
- `/_internal/v2/apps/${ctx.appId}/releases/${seg(releaseId)}`
1538
+ `/_internal/v2/apps/${ctx.appId}/releases/${encodePathSegment(releaseId)}`
1536
1539
  );
1537
1540
  }
1538
1541
  async function fetchReport(url) {
@@ -1587,28 +1590,28 @@ async function diagnosticsGet(ctx, a) {
1587
1590
  while (true) {
1588
1591
  const release2 = await getRelease(ctx, releaseId);
1589
1592
  if (release2.diagnostics) {
1590
- out(release2.diagnostics);
1593
+ printJson(release2.diagnostics);
1591
1594
  return;
1592
1595
  }
1593
1596
  if (Date.now() - start2 > timeout) {
1594
- out(DIAGNOSTICS_PENDING);
1597
+ printJson(DIAGNOSTICS_PENDING);
1595
1598
  return;
1596
1599
  }
1597
1600
  await sleep(3e3);
1598
1601
  }
1599
1602
  }
1600
1603
  const release = await getRelease(ctx, releaseId);
1601
- out(release.diagnostics ?? DIAGNOSTICS_PENDING);
1604
+ printJson(release.diagnostics ?? DIAGNOSTICS_PENDING);
1602
1605
  }
1603
1606
  async function diagnosticsReport(ctx, a) {
1604
1607
  const releaseId = await resolveReleaseId(ctx, a);
1605
1608
  const release = await getRelease(ctx, releaseId);
1606
1609
  const url = release.diagnostics?.lighthouseJsonUrl;
1607
1610
  if (!url) {
1608
- out(DIAGNOSTICS_PENDING);
1611
+ printJson(DIAGNOSTICS_PENDING);
1609
1612
  return;
1610
1613
  }
1611
- out(await fetchReport(url));
1614
+ printJson(await fetchReport(url));
1612
1615
  }
1613
1616
  var diagnosticsHandlers = {
1614
1617
  "diagnostics get": diagnosticsGet,
@@ -1709,7 +1712,7 @@ async function customRemove(ctx, hostname) {
1709
1712
  return call(
1710
1713
  ctx,
1711
1714
  "POST",
1712
- `/_internal/v2/apps/${ctx.appId}/settings/custom-domains/${seg(id)}/delete`
1715
+ `/_internal/v2/apps/${ctx.appId}/settings/custom-domains/${encodePathSegment(id)}/delete`
1713
1716
  );
1714
1717
  }
1715
1718
  async function customRetry(ctx, hostname) {
@@ -1717,7 +1720,7 @@ async function customRetry(ctx, hostname) {
1717
1720
  return call(
1718
1721
  ctx,
1719
1722
  "POST",
1720
- `/_internal/v2/apps/${ctx.appId}/settings/custom-domains/${seg(id)}/retry`
1723
+ `/_internal/v2/apps/${ctx.appId}/settings/custom-domains/${encodePathSegment(id)}/retry`
1721
1724
  );
1722
1725
  }
1723
1726
  var REGISTERED = (ctx) => `/_internal/v2/apps/${ctx.appId}/settings/registered-domains`;
@@ -1745,12 +1748,12 @@ function buy(ctx, params) {
1745
1748
  { name: params.name, expectedPrice: params.price, acceptTerms: true }
1746
1749
  );
1747
1750
  }
1748
- function owned(ctx) {
1751
+ function listOwned(ctx) {
1749
1752
  return call(ctx, "GET", REGISTERED(ctx));
1750
1753
  }
1751
1754
  async function findOwned(ctx, name) {
1752
1755
  const wanted = name.toLowerCase();
1753
- const { domains } = await owned(ctx);
1756
+ const { domains } = await listOwned(ctx);
1754
1757
  const domain = domains.find(
1755
1758
  (d) => d.name === wanted && (d.status === "active" || d.status === "expired" || d.status === "pending")
1756
1759
  );
@@ -1779,7 +1782,7 @@ async function zone(ctx, name) {
1779
1782
  return call(
1780
1783
  ctx,
1781
1784
  "GET",
1782
- `${REGISTERED(ctx)}/${seg(domain.id)}/records`
1785
+ `${REGISTERED(ctx)}/${encodePathSegment(domain.id)}/records`
1783
1786
  );
1784
1787
  }
1785
1788
  async function zoneAdd(ctx, name, record) {
@@ -1787,7 +1790,7 @@ async function zoneAdd(ctx, name, record) {
1787
1790
  return call(
1788
1791
  ctx,
1789
1792
  "POST",
1790
- `${REGISTERED(ctx)}/${seg(domain.id)}/records`,
1793
+ `${REGISTERED(ctx)}/${encodePathSegment(domain.id)}/records`,
1791
1794
  { ...record }
1792
1795
  );
1793
1796
  }
@@ -1796,7 +1799,7 @@ async function zoneUpdate(ctx, name, recordId, record) {
1796
1799
  return call(
1797
1800
  ctx,
1798
1801
  "POST",
1799
- `${REGISTERED(ctx)}/${seg(domain.id)}/records/${seg(recordId)}`,
1802
+ `${REGISTERED(ctx)}/${encodePathSegment(domain.id)}/records/${encodePathSegment(recordId)}`,
1800
1803
  { ...record }
1801
1804
  );
1802
1805
  }
@@ -1805,7 +1808,7 @@ async function zoneDelete(ctx, name, recordId) {
1805
1808
  return call(
1806
1809
  ctx,
1807
1810
  "POST",
1808
- `${REGISTERED(ctx)}/${seg(domain.id)}/records/${seg(recordId)}/delete`
1811
+ `${REGISTERED(ctx)}/${encodePathSegment(domain.id)}/records/${encodePathSegment(recordId)}/delete`
1809
1812
  );
1810
1813
  }
1811
1814
 
@@ -1941,34 +1944,34 @@ var domainsSpecs = {
1941
1944
  }
1942
1945
  };
1943
1946
  async function domainsGet(ctx) {
1944
- out(await get4(ctx));
1947
+ printJson(await get4(ctx));
1945
1948
  }
1946
1949
  async function domainsSet(ctx, a) {
1947
- out(await set(ctx, a.req("subdomain")));
1950
+ printJson(await set(ctx, a.required("subdomain")));
1948
1951
  }
1949
1952
  async function domainsCheck(ctx, a) {
1950
- out(await check(ctx, a.req("subdomain")));
1953
+ printJson(await check(ctx, a.required("subdomain")));
1951
1954
  }
1952
1955
  async function customDomainsList(ctx) {
1953
- out(await customList(ctx));
1956
+ printJson(await customList(ctx));
1954
1957
  }
1955
1958
  async function customDomainsAdd(ctx, a) {
1956
- out(await customAdd(ctx, a.req("hostname")));
1959
+ printJson(await customAdd(ctx, a.required("hostname")));
1957
1960
  }
1958
1961
  async function customDomainsCheck(ctx, a) {
1959
- out(await customCheck(ctx, a.req("hostname")));
1962
+ printJson(await customCheck(ctx, a.required("hostname")));
1960
1963
  }
1961
1964
  async function customDomainsRecords(ctx, a) {
1962
- const { entry } = await findHostname(ctx, a.req("hostname"));
1963
- out({
1965
+ const { entry } = await findHostname(ctx, a.required("hostname"));
1966
+ printJson({
1964
1967
  hostname: entry.hostname,
1965
1968
  isApex: entry.isApex,
1966
1969
  dnsInstructions: entry.dnsInstructions
1967
1970
  });
1968
1971
  }
1969
1972
  async function customDomainsStatus(ctx, a) {
1970
- const { entry } = await findHostname(ctx, a.req("hostname"));
1971
- out({
1973
+ const { entry } = await findHostname(ctx, a.required("hostname"));
1974
+ printJson({
1972
1975
  hostname: entry.hostname,
1973
1976
  uiStatus: entry.uiStatus,
1974
1977
  verificationErrors: entry.verificationErrors ?? null,
@@ -1977,33 +1980,33 @@ async function customDomainsStatus(ctx, a) {
1977
1980
  });
1978
1981
  }
1979
1982
  async function customDomainsRemove(ctx, a) {
1980
- out(await customRemove(ctx, a.req("hostname")));
1983
+ printJson(await customRemove(ctx, a.required("hostname")));
1981
1984
  }
1982
1985
  async function customDomainsRetry(ctx, a) {
1983
- out(await customRetry(ctx, a.req("hostname")));
1986
+ printJson(await customRetry(ctx, a.required("hostname")));
1984
1987
  }
1985
1988
  async function domainsSearch(ctx, a) {
1986
- out(await search(ctx, a.rest("query").join(" ")));
1989
+ printJson(await search(ctx, a.rest("query").join(" ")));
1987
1990
  }
1988
1991
  async function domainsQuote(ctx, a) {
1989
- out(await quote(ctx, a.req("name")));
1992
+ printJson(await quote(ctx, a.required("name")));
1990
1993
  }
1991
1994
  async function domainsBuy(ctx, a) {
1992
- out(
1995
+ printJson(
1993
1996
  await buy(ctx, {
1994
- name: a.req("name"),
1997
+ name: a.required("name"),
1995
1998
  price: Number(a.str("price"))
1996
1999
  })
1997
2000
  );
1998
2001
  }
1999
2002
  async function domainsOwned(ctx) {
2000
- out(await owned(ctx));
2003
+ printJson(await listOwned(ctx));
2001
2004
  }
2002
2005
  async function domainsContactGet(ctx) {
2003
- out(await contactGet(ctx));
2006
+ printJson(await contactGet(ctx));
2004
2007
  }
2005
2008
  async function domainsContactSet(ctx, a) {
2006
- out(
2009
+ printJson(
2007
2010
  await contactSet(ctx, {
2008
2011
  firstName: a.str("first-name") ?? "",
2009
2012
  lastName: a.str("last-name") ?? "",
@@ -2030,23 +2033,29 @@ function zoneRecord(a) {
2030
2033
  };
2031
2034
  }
2032
2035
  async function domainsZoneList(ctx, a) {
2033
- out(await zone(ctx, a.req("name")));
2036
+ printJson(await zone(ctx, a.required("name")));
2034
2037
  }
2035
2038
  async function domainsZoneAdd(ctx, a) {
2036
- out(await zoneAdd(ctx, a.req("name"), zoneRecord(a)));
2039
+ printJson(await zoneAdd(ctx, a.required("name"), zoneRecord(a)));
2037
2040
  }
2038
2041
  async function domainsZoneUpdate(ctx, a) {
2039
- out(
2042
+ printJson(
2040
2043
  await zoneUpdate(
2041
2044
  ctx,
2042
- a.req("name"),
2043
- Number(a.req("recordId")),
2045
+ a.required("name"),
2046
+ Number(a.required("recordId")),
2044
2047
  zoneRecord(a)
2045
2048
  )
2046
2049
  );
2047
2050
  }
2048
2051
  async function domainsZoneDelete(ctx, a) {
2049
- out(await zoneDelete(ctx, a.req("name"), Number(a.req("recordId"))));
2052
+ printJson(
2053
+ await zoneDelete(
2054
+ ctx,
2055
+ a.required("name"),
2056
+ Number(a.required("recordId"))
2057
+ )
2058
+ );
2050
2059
  }
2051
2060
  var domainsHandlers = {
2052
2061
  "domains get": domainsGet,
@@ -2168,7 +2177,7 @@ function setRole(ctx, userId, role) {
2168
2177
  return call(
2169
2178
  ctx,
2170
2179
  "POST",
2171
- `/_internal/v2/apps/${ctx.appId}/users/${seg(userId)}/roles`,
2180
+ `/_internal/v2/apps/${ctx.appId}/users/${encodePathSegment(userId)}/roles`,
2172
2181
  { roles: [role] }
2173
2182
  );
2174
2183
  }
@@ -2176,14 +2185,14 @@ function createApiKey(ctx, userId) {
2176
2185
  return call(
2177
2186
  ctx,
2178
2187
  "POST",
2179
- `/_internal/v2/apps/${ctx.appId}/users/${seg(userId)}/api-key`
2188
+ `/_internal/v2/apps/${ctx.appId}/users/${encodePathSegment(userId)}/api-key`
2180
2189
  );
2181
2190
  }
2182
2191
  function revokeApiKey(ctx, userId) {
2183
2192
  return call(
2184
2193
  ctx,
2185
2194
  "DELETE",
2186
- `/_internal/v2/apps/${ctx.appId}/users/${seg(userId)}/api-key`
2195
+ `/_internal/v2/apps/${ctx.appId}/users/${encodePathSegment(userId)}/api-key`
2187
2196
  );
2188
2197
  }
2189
2198
 
@@ -2210,7 +2219,7 @@ var usersSpecs = {
2210
2219
  }
2211
2220
  };
2212
2221
  async function usersList(ctx, a) {
2213
- out(
2222
+ printJson(
2214
2223
  await list5(ctx, {
2215
2224
  limit: a.num("limit"),
2216
2225
  offset: a.num("offset")
@@ -2218,13 +2227,13 @@ async function usersList(ctx, a) {
2218
2227
  );
2219
2228
  }
2220
2229
  async function usersSetRole(ctx, a) {
2221
- out(await setRole(ctx, a.req("userId"), a.req("role")));
2230
+ printJson(await setRole(ctx, a.required("userId"), a.required("role")));
2222
2231
  }
2223
2232
  async function usersCreateApiKey(ctx, a) {
2224
- out(await createApiKey(ctx, a.req("userId")));
2233
+ printJson(await createApiKey(ctx, a.required("userId")));
2225
2234
  }
2226
2235
  async function usersRevokeApiKey(ctx, a) {
2227
- out(await revokeApiKey(ctx, a.req("userId")));
2236
+ printJson(await revokeApiKey(ctx, a.required("userId")));
2228
2237
  }
2229
2238
  var usersHandlers = {
2230
2239
  "users list": usersList,
@@ -2334,24 +2343,28 @@ var dbSpecs = {
2334
2343
  }
2335
2344
  };
2336
2345
  async function dbQuery(ctx, a) {
2337
- out(await query2(ctx, a.req("sql")));
2346
+ printJson(await query2(ctx, a.required("sql")));
2338
2347
  }
2339
2348
  async function dbHistory(ctx, a) {
2340
- out(
2349
+ printJson(
2341
2350
  await history(ctx, { limit: a.num("limit"), cursor: a.str("cursor") })
2342
2351
  );
2343
2352
  }
2344
2353
  async function dbHistoryQuery(ctx, a) {
2345
- out(await historyQuery(ctx, a.req("releaseId"), a.req("sql")));
2354
+ printJson(
2355
+ await historyQuery(ctx, a.required("releaseId"), a.required("sql"))
2356
+ );
2346
2357
  }
2347
2358
  async function dbHistoryAttach(ctx, a) {
2348
- out(await historyAttach(ctx, a.req("releaseId"), a.req("sql")));
2359
+ printJson(
2360
+ await historyAttach(ctx, a.required("releaseId"), a.required("sql"))
2361
+ );
2349
2362
  }
2350
2363
  async function dbHistoryPurge(ctx) {
2351
- out(await historyPurge(ctx));
2364
+ printJson(await historyPurge(ctx));
2352
2365
  }
2353
2366
  async function dbTables(ctx) {
2354
- out(
2367
+ printJson(
2355
2368
  await query2(
2356
2369
  ctx,
2357
2370
  "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"
@@ -2481,7 +2494,7 @@ function set2(ctx, key, params) {
2481
2494
  return call(
2482
2495
  ctx,
2483
2496
  "PUT",
2484
- `/_internal/v2/apps/${ctx.appId}/secrets/${seg(key)}`,
2497
+ `/_internal/v2/apps/${ctx.appId}/secrets/${encodePathSegment(key)}`,
2485
2498
  body
2486
2499
  );
2487
2500
  }
@@ -2489,7 +2502,7 @@ function del(ctx, key) {
2489
2502
  return call(
2490
2503
  ctx,
2491
2504
  "DELETE",
2492
- `/_internal/v2/apps/${ctx.appId}/secrets/${seg(key)}`
2505
+ `/_internal/v2/apps/${ctx.appId}/secrets/${encodePathSegment(key)}`
2493
2506
  );
2494
2507
  }
2495
2508
 
@@ -2518,10 +2531,10 @@ var secretsSpecs = {
2518
2531
  }
2519
2532
  };
2520
2533
  async function secretsList(ctx) {
2521
- out(await list6(ctx));
2534
+ printJson(await list6(ctx));
2522
2535
  }
2523
2536
  async function secretsSet(ctx, a) {
2524
- const key = a.req("key");
2537
+ const key = a.required("key");
2525
2538
  const dev = a.str("dev");
2526
2539
  const prod = a.str("prod");
2527
2540
  const devClear = a.bool("dev-clear");
@@ -2542,10 +2555,10 @@ async function secretsSet(ctx, a) {
2542
2555
  "At least one of --dev <value>, --prod <value>, --dev-clear, or --prod-clear is required"
2543
2556
  );
2544
2557
  }
2545
- out(await set2(ctx, key, params));
2558
+ printJson(await set2(ctx, key, params));
2546
2559
  }
2547
2560
  async function secretsDelete(ctx, a) {
2548
- out(await del(ctx, a.req("key")));
2561
+ printJson(await del(ctx, a.required("key")));
2549
2562
  }
2550
2563
  var secretsHandlers = {
2551
2564
  "secrets list": secretsList,
@@ -2648,7 +2661,7 @@ async function streamToStdout(ctx, apiPath, body) {
2648
2661
  return;
2649
2662
  }
2650
2663
  try {
2651
- out(JSON.parse(line.slice(6)));
2664
+ printJson(JSON.parse(line.slice(6)));
2652
2665
  } catch {
2653
2666
  }
2654
2667
  };
@@ -2721,7 +2734,7 @@ async function tailSseToStdout(ctx, apiPath) {
2721
2734
  complete = true;
2722
2735
  return;
2723
2736
  }
2724
- out(value);
2737
+ printJson(value);
2725
2738
  } catch {
2726
2739
  }
2727
2740
  };
@@ -2773,7 +2786,7 @@ async function list7(ctx) {
2773
2786
  function invoke(ctx, params) {
2774
2787
  const { methodId, input, impersonate } = params;
2775
2788
  const useImpersonate = impersonate !== void 0 && (impersonate.roles !== void 0 || impersonate.userId !== void 0);
2776
- const apiPath = useImpersonate ? `/_internal/v2/apps/${ctx.appId}/methods/${seg(methodId)}/invoke-as` : `/_internal/v2/apps/${ctx.appId}/methods/${seg(methodId)}/invoke`;
2789
+ const apiPath = useImpersonate ? `/_internal/v2/apps/${ctx.appId}/methods/${encodePathSegment(methodId)}/invoke-as` : `/_internal/v2/apps/${ctx.appId}/methods/${encodePathSegment(methodId)}/invoke`;
2777
2790
  const body = useImpersonate ? { input, impersonate } : { input };
2778
2791
  return call(
2779
2792
  ctx,
@@ -2801,10 +2814,10 @@ var methodsSpecs = {
2801
2814
  }
2802
2815
  };
2803
2816
  async function methodsList(ctx) {
2804
- out(await list7(ctx));
2817
+ printJson(await list7(ctx));
2805
2818
  }
2806
2819
  async function methodsInvoke(ctx, a) {
2807
- const methodId = a.req("methodId");
2820
+ const methodId = a.required("methodId");
2808
2821
  const inputRaw = a.str("input");
2809
2822
  let input = {};
2810
2823
  if (inputRaw) {
@@ -2825,14 +2838,14 @@ async function methodsInvoke(ctx, a) {
2825
2838
  }
2826
2839
  const useImpersonate = impersonate.roles !== void 0 || impersonate.userId !== void 0;
2827
2840
  const stream = a.bool("stream");
2828
- const apiPath = useImpersonate ? `/_internal/v2/apps/${ctx.appId}/methods/${seg(methodId)}/invoke-as` : `/_internal/v2/apps/${ctx.appId}/methods/${seg(methodId)}/invoke`;
2841
+ const apiPath = useImpersonate ? `/_internal/v2/apps/${ctx.appId}/methods/${encodePathSegment(methodId)}/invoke-as` : `/_internal/v2/apps/${ctx.appId}/methods/${encodePathSegment(methodId)}/invoke`;
2829
2842
  const body = useImpersonate ? { input, impersonate } : { input };
2830
2843
  if (stream) {
2831
2844
  await streamToStdout(ctx, apiPath, { ...body, stream: true });
2832
2845
  return;
2833
2846
  }
2834
2847
  try {
2835
- out(
2848
+ printJson(
2836
2849
  await invoke(ctx, {
2837
2850
  methodId,
2838
2851
  input,
@@ -2930,16 +2943,16 @@ var dataSpecs = {
2930
2943
  }
2931
2944
  };
2932
2945
  async function dataLiftFromDev(ctx, a) {
2933
- const given = a.req("appId");
2946
+ const given = a.required("appId");
2934
2947
  if (given !== ctx.appId) {
2935
2948
  fatal(
2936
2949
  `appId "${given}" does not match this workspace's app \u2014 re-run with the exact appId from mindstudio.json.`
2937
2950
  );
2938
2951
  }
2939
- out(await liftFromDev(ctx, { releaseId: a.str("release-id") }));
2952
+ printJson(await liftFromDev(ctx, { releaseId: a.str("release-id") }));
2940
2953
  }
2941
2954
  async function dataLiftFromLive(ctx, a) {
2942
- out(
2955
+ printJson(
2943
2956
  await liftFromLive(ctx, {
2944
2957
  truncate: a.bool("truncate"),
2945
2958
  releaseId: a.str("release-id")
@@ -3017,7 +3030,7 @@ function list8(ctx, params = {}) {
3017
3030
  `/_internal/v2/apps/${ctx.appId}/issues${listQuery(params)}`
3018
3031
  );
3019
3032
  }
3020
- function filed(ctx, params = {}) {
3033
+ function listFiled(ctx, params = {}) {
3021
3034
  return call(
3022
3035
  ctx,
3023
3036
  "GET",
@@ -3028,7 +3041,7 @@ function get5(ctx, number) {
3028
3041
  return call(
3029
3042
  ctx,
3030
3043
  "GET",
3031
- `/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}`
3044
+ `/_internal/v2/apps/${ctx.appId}/issues/${encodePathSegment(number)}`
3032
3045
  );
3033
3046
  }
3034
3047
  function create(ctx, params) {
@@ -3057,7 +3070,7 @@ function comment(ctx, number, body) {
3057
3070
  return call(
3058
3071
  ctx,
3059
3072
  "POST",
3060
- `/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/comments`,
3073
+ `/_internal/v2/apps/${ctx.appId}/issues/${encodePathSegment(number)}/comments`,
3061
3074
  { body, authorKind: "agent", ...authorship(ctx) }
3062
3075
  );
3063
3076
  }
@@ -3073,7 +3086,7 @@ function close(ctx, number, comment2) {
3073
3086
  return call(
3074
3087
  ctx,
3075
3088
  "POST",
3076
- `/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/update`,
3089
+ `/_internal/v2/apps/${ctx.appId}/issues/${encodePathSegment(number)}/update`,
3077
3090
  requestBody
3078
3091
  );
3079
3092
  }
@@ -3081,7 +3094,7 @@ function reopen(ctx, number) {
3081
3094
  return call(
3082
3095
  ctx,
3083
3096
  "POST",
3084
- `/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/update`,
3097
+ `/_internal/v2/apps/${ctx.appId}/issues/${encodePathSegment(number)}/update`,
3085
3098
  { status: "open", authorKind: "agent", ...authorship(ctx) }
3086
3099
  );
3087
3100
  }
@@ -3105,7 +3118,7 @@ function edit(ctx, number, params) {
3105
3118
  return call(
3106
3119
  ctx,
3107
3120
  "POST",
3108
- `/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/update`,
3121
+ `/_internal/v2/apps/${ctx.appId}/issues/${encodePathSegment(number)}/update`,
3109
3122
  requestBody
3110
3123
  );
3111
3124
  }
@@ -3113,7 +3126,7 @@ function del2(ctx, number) {
3113
3126
  return call(
3114
3127
  ctx,
3115
3128
  "POST",
3116
- `/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/delete`
3129
+ `/_internal/v2/apps/${ctx.appId}/issues/${encodePathSegment(number)}/delete`
3117
3130
  );
3118
3131
  }
3119
3132
 
@@ -3215,7 +3228,7 @@ function readStateFilter(a) {
3215
3228
  return state === "all" ? void 0 : state;
3216
3229
  }
3217
3230
  async function issuesList(ctx, a) {
3218
- out(
3231
+ printJson(
3219
3232
  await list8(ctx, {
3220
3233
  status: readStateFilter(a),
3221
3234
  labels: a.list("label"),
@@ -3226,8 +3239,8 @@ async function issuesList(ctx, a) {
3226
3239
  );
3227
3240
  }
3228
3241
  async function issuesFiled(ctx, a) {
3229
- out(
3230
- await filed(ctx, {
3242
+ printJson(
3243
+ await listFiled(ctx, {
3231
3244
  status: readStateFilter(a),
3232
3245
  labels: a.list("label"),
3233
3246
  limit: a.num("limit"),
@@ -3236,32 +3249,34 @@ async function issuesFiled(ctx, a) {
3236
3249
  );
3237
3250
  }
3238
3251
  async function issuesGet(ctx, a) {
3239
- out(await get5(ctx, a.req("number")));
3252
+ printJson(await get5(ctx, a.required("number")));
3240
3253
  }
3241
3254
  async function issuesCreate(ctx, a) {
3242
3255
  const issueBody = readBodyFlag(a);
3243
- out(
3256
+ printJson(
3244
3257
  await create(ctx, {
3245
- title: a.req("title"),
3258
+ title: a.required("title"),
3246
3259
  body: issueBody,
3247
3260
  labels: a.list("label")
3248
3261
  })
3249
3262
  );
3250
3263
  }
3251
3264
  async function issuesComment(ctx, a) {
3252
- const commentBody = readBodyFlag(a) ?? a.req("body");
3253
- out(await comment(ctx, a.req("number"), commentBody));
3265
+ const commentBody = readBodyFlag(a) ?? a.required("body");
3266
+ printJson(await comment(ctx, a.required("number"), commentBody));
3254
3267
  }
3255
3268
  async function issuesClose(ctx, a) {
3256
- out(await close(ctx, a.req("number"), readStdinFlag(a, "comment")));
3269
+ printJson(
3270
+ await close(ctx, a.required("number"), readStdinFlag(a, "comment"))
3271
+ );
3257
3272
  }
3258
3273
  async function issuesReopen(ctx, a) {
3259
- out(await reopen(ctx, a.req("number")));
3274
+ printJson(await reopen(ctx, a.required("number")));
3260
3275
  }
3261
3276
  async function issuesEdit(ctx, a) {
3262
3277
  const editBody = readBodyFlag(a);
3263
- out(
3264
- await edit(ctx, a.req("number"), {
3278
+ printJson(
3279
+ await edit(ctx, a.required("number"), {
3265
3280
  title: a.str("title"),
3266
3281
  body: editBody,
3267
3282
  labels: a.list("label"),
@@ -3270,7 +3285,7 @@ async function issuesEdit(ctx, a) {
3270
3285
  );
3271
3286
  }
3272
3287
  async function issuesDelete(ctx, a) {
3273
- out(await del2(ctx, a.req("number")));
3288
+ printJson(await del2(ctx, a.required("number")));
3274
3289
  }
3275
3290
  var issuesHandlers = {
3276
3291
  "issues list": issuesList,
@@ -3372,7 +3387,7 @@ var appsSpecs = {
3372
3387
  }
3373
3388
  };
3374
3389
  async function appsList(ctx, a) {
3375
- out(
3390
+ printJson(
3376
3391
  await list9(ctx, {
3377
3392
  search: a.str("search"),
3378
3393
  status: a.str("status")
@@ -3461,14 +3476,14 @@ var prerenderSpecs = {
3461
3476
  }
3462
3477
  };
3463
3478
  async function prerenderInvalidate(ctx, a) {
3464
- out(
3479
+ printJson(
3465
3480
  await invalidate(ctx, {
3466
3481
  paths: a.bool("all") ? void 0 : a.rest("path")
3467
3482
  })
3468
3483
  );
3469
3484
  }
3470
3485
  async function prerenderGet(ctx, a) {
3471
- const rawPath = a.req("path");
3486
+ const rawPath = a.required("path");
3472
3487
  const normalized = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
3473
3488
  const host = a.str("host")?.replace(/^https?:\/\//, "").replace(/\/+$/, "");
3474
3489
  const origin = host ? `https://${host}` : new URL(await primaryUrl(ctx)).origin;
@@ -3485,16 +3500,16 @@ async function prerenderGet(ctx, a) {
3485
3500
  );
3486
3501
  const html = await res.text();
3487
3502
  const result = { url, status: res.status, html };
3488
- out(result);
3503
+ printJson(result);
3489
3504
  }
3490
3505
  async function prerenderPages(ctx, a) {
3491
- out(await pages(ctx, { cursor: a.str("cursor") }));
3506
+ printJson(await pages(ctx, { cursor: a.str("cursor") }));
3492
3507
  }
3493
3508
  async function prerenderView(ctx, a) {
3494
- const rawPath = a.req("path");
3509
+ const rawPath = a.required("path");
3495
3510
  const normalized = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
3496
3511
  const host = a.str("host")?.replace(/^https?:\/\//, "").replace(/\/+$/, "");
3497
- out(await view(ctx, { path: normalized, host }));
3512
+ printJson(await view(ctx, { path: normalized, host }));
3498
3513
  }
3499
3514
  var prerenderHandlers = {
3500
3515
  "prerender invalidate": prerenderInvalidate,
@@ -3766,7 +3781,7 @@ async function refOf(ctx, a, key) {
3766
3781
  return { store: storeOf(a), access: await readAccess(ctx, a, key), key };
3767
3782
  }
3768
3783
  async function filesPut(ctx, a) {
3769
- const file = a.req("file");
3784
+ const file = a.required("file");
3770
3785
  const abs = path2.isAbsolute(file) ? file : path2.join(WORKSPACE_DIR, file);
3771
3786
  let bytes;
3772
3787
  try {
@@ -3774,7 +3789,7 @@ async function filesPut(ctx, a) {
3774
3789
  } catch (err) {
3775
3790
  fatal(`Could not read file "${file}": ${err.message}`);
3776
3791
  }
3777
- out(
3792
+ printJson(
3778
3793
  await put(ctx, {
3779
3794
  content: bytes,
3780
3795
  store: storeOf(a),
@@ -3788,7 +3803,7 @@ async function filesPut(ctx, a) {
3788
3803
  );
3789
3804
  }
3790
3805
  async function filesGet(ctx, a) {
3791
- const key = a.req("key");
3806
+ const key = a.required("key");
3792
3807
  const ref = await refOf(ctx, a, key);
3793
3808
  const { url } = await sign(
3794
3809
  ctx,
@@ -3807,18 +3822,18 @@ async function filesGet(ctx, a) {
3807
3822
  Readable.fromWeb(res.body),
3808
3823
  fs2.createWriteStream(abs)
3809
3824
  );
3810
- out({ path: abs, size: fs2.statSync(abs).size });
3825
+ printJson({ path: abs, size: fs2.statSync(abs).size });
3811
3826
  }
3812
3827
  async function filesSign(ctx, a) {
3813
- out(
3828
+ printJson(
3814
3829
  await sign(ctx, await refOf(ctx, a, requireKeyFlag(a)), a.num("ttl"))
3815
3830
  );
3816
3831
  }
3817
3832
  async function filesStat(ctx, a) {
3818
- out(await stat(ctx, await refOf(ctx, a, requireKeyFlag(a))));
3833
+ printJson(await stat(ctx, await refOf(ctx, a, requireKeyFlag(a))));
3819
3834
  }
3820
3835
  async function filesLs(ctx, a) {
3821
- out(
3836
+ printJson(
3822
3837
  await ls(ctx, {
3823
3838
  store: storeOf(a),
3824
3839
  access: await readAccess(ctx, a),
@@ -3830,7 +3845,7 @@ async function filesLs(ctx, a) {
3830
3845
  );
3831
3846
  }
3832
3847
  async function filesList(ctx) {
3833
- out(await summary(ctx));
3848
+ printJson(await summary(ctx));
3834
3849
  }
3835
3850
  async function filesRm(ctx, a) {
3836
3851
  const store = a.str("store");
@@ -3841,7 +3856,7 @@ async function filesRm(ctx, a) {
3841
3856
  if (!key) {
3842
3857
  fatal("--key is required.");
3843
3858
  }
3844
- out(
3859
+ printJson(
3845
3860
  await remove(ctx, {
3846
3861
  store,
3847
3862
  access: await readAccess(ctx, a, key),
@@ -4012,7 +4027,7 @@ async function waitForIngest(ctx, params) {
4012
4027
  return {
4013
4028
  status: "timeout",
4014
4029
  documents: tracked.map(summarize),
4015
- error: timedOut(
4030
+ error: timeoutMessage(
4016
4031
  timeoutMs,
4017
4032
  `with ${pendingOf(tracked).length} document(s) still processing`
4018
4033
  )
@@ -4056,7 +4071,7 @@ async function waitForCandidate(ctx, params) {
4056
4071
  status: "timeout",
4057
4072
  counts,
4058
4073
  documents: failed,
4059
- error: timedOut(
4074
+ error: timeoutMessage(
4060
4075
  timeoutMs,
4061
4076
  `with ${counts?.processing ?? 0} document(s) still building`
4062
4077
  )
@@ -4090,7 +4105,7 @@ async function allDocuments(ctx, params) {
4090
4105
  { length: Math.ceil(params.ids.length / DOCUMENTS_IDS_MAX) },
4091
4106
  (_, i) => params.ids.slice(i * DOCUMENTS_IDS_MAX, (i + 1) * DOCUMENTS_IDS_MAX)
4092
4107
  ) : [void 0];
4093
- const out2 = [];
4108
+ const out = [];
4094
4109
  for (const ids of groups) {
4095
4110
  let cursor;
4096
4111
  do {
@@ -4104,11 +4119,11 @@ async function allDocuments(ctx, params) {
4104
4119
  status: params.status,
4105
4120
  filename: params.filename
4106
4121
  });
4107
- out2.push(...page.documents ?? []);
4122
+ out.push(...page.documents ?? []);
4108
4123
  cursor = page.nextCursor ?? void 0;
4109
4124
  } while (cursor);
4110
4125
  }
4111
- return out2;
4126
+ return out;
4112
4127
  }
4113
4128
  function list10(ctx) {
4114
4129
  return call(ctx, "GET", base(ctx.appId));
@@ -4255,7 +4270,7 @@ async function waitForMove(ctx, params) {
4255
4270
  return {
4256
4271
  status: "timeout",
4257
4272
  source,
4258
- error: timedOut(
4273
+ error: timeoutMessage(
4259
4274
  timeoutMs,
4260
4275
  `with ${migration.copied}/${migration.total} documents copied`
4261
4276
  )
@@ -4289,7 +4304,7 @@ function promote(ctx, params) {
4289
4304
  }
4290
4305
  );
4291
4306
  }
4292
- function drop(ctx, params) {
4307
+ function dropPipelineVersion(ctx, params) {
4293
4308
  return call(
4294
4309
  ctx,
4295
4310
  "POST",
@@ -4300,7 +4315,7 @@ function drop(ctx, params) {
4300
4315
  }
4301
4316
  );
4302
4317
  }
4303
- function rm(ctx, params) {
4318
+ function deleteDocument(ctx, params) {
4304
4319
  return call(
4305
4320
  ctx,
4306
4321
  "POST",
@@ -4311,7 +4326,7 @@ function rm(ctx, params) {
4311
4326
  }
4312
4327
  );
4313
4328
  }
4314
- function rmWhere(ctx, params) {
4329
+ function deleteDocumentsWhere(ctx, params) {
4315
4330
  return call(
4316
4331
  ctx,
4317
4332
  "POST",
@@ -4319,10 +4334,10 @@ function rmWhere(ctx, params) {
4319
4334
  { slug: params.slug, filter: params.filter }
4320
4335
  );
4321
4336
  }
4322
- async function rmWhereAll(ctx, params) {
4337
+ async function deleteAllDocumentsWhere(ctx, params) {
4323
4338
  let deleted = 0;
4324
4339
  while (true) {
4325
- const page = await rmWhere(ctx, params);
4340
+ const page = await deleteDocumentsWhere(ctx, params);
4326
4341
  deleted += page.deleted;
4327
4342
  if (page.remaining === 0 || page.deleted === 0) {
4328
4343
  return { deleted };
@@ -4518,7 +4533,7 @@ async function settle(ctx, params, isSettled) {
4518
4533
  return {
4519
4534
  status: "timeout",
4520
4535
  job,
4521
- error: timedOut(timeoutMs, `; job is still ${job.state}`)
4536
+ error: timeoutMessage(timeoutMs, `; job is still ${job.state}`)
4522
4537
  };
4523
4538
  }
4524
4539
  if (job.state === "failed" || job.state === "cancelled") {
@@ -4596,7 +4611,7 @@ var timeoutOf = (a) => {
4596
4611
  const seconds = a.str("timeout");
4597
4612
  return seconds ? { timeoutMs: Number(seconds) * 1e3 } : {};
4598
4613
  };
4599
- function failOnWait(result) {
4614
+ function throwIfWaitFailed(result) {
4600
4615
  if (result.status === "timeout") {
4601
4616
  throw new CliError(result.error ?? "Timed out.", EXIT.timeout);
4602
4617
  }
@@ -4613,8 +4628,8 @@ function failOnWait(result) {
4613
4628
  async function waitAndReport(ctx, a, id, mode, summary4) {
4614
4629
  const wait = mode === "plan" ? waitForPlan : waitForJob;
4615
4630
  const result = await wait(ctx, { id, ...timeoutOf(a), onProgress: progress });
4616
- out({ ...summary4, ...result });
4617
- failOnWait(result);
4631
+ printJson({ ...summary4, ...result });
4632
+ throwIfWaitFailed(result);
4618
4633
  }
4619
4634
 
4620
4635
  // src/ops/dataSourceConnectors.ts
@@ -4749,7 +4764,7 @@ async function connect2(ctx, a) {
4749
4764
  ...deletions ? { deletions } : {},
4750
4765
  ...budget !== void 0 ? { budgetDollarsPerSync: budget } : {}
4751
4766
  });
4752
- out({
4767
+ printJson({
4753
4768
  dataSource: slug,
4754
4769
  connector,
4755
4770
  note: "Connected. Run `datasources sync --source " + slug + " --wait` to load the bucket; the first sync plans first and stops for `datasources jobs approve <id>` when the plan is over the per-sync budget."
@@ -4757,7 +4772,7 @@ async function connect2(ctx, a) {
4757
4772
  }
4758
4773
  async function show(ctx, a) {
4759
4774
  const slug = sourceOf(a);
4760
- out({ dataSource: slug, ...await get7(ctx, { slug }) });
4775
+ printJson({ dataSource: slug, ...await get7(ctx, { slug }) });
4761
4776
  }
4762
4777
  async function disconnect2(ctx, a) {
4763
4778
  const slug = a.str("source");
@@ -4767,7 +4782,7 @@ async function disconnect2(ctx, a) {
4767
4782
  );
4768
4783
  }
4769
4784
  const result = await disconnect(ctx, { slug });
4770
- out({
4785
+ printJson({
4771
4786
  dataSource: slug,
4772
4787
  ...result,
4773
4788
  note: "The documents stay. Connect again to follow a bucket; unchanged files are recognised by content and cost nothing to re-sync."
@@ -4786,7 +4801,7 @@ async function sync2(ctx, a) {
4786
4801
  ...a.bool("priority") ? { priority: true } : {}
4787
4802
  });
4788
4803
  if (!a.bool("wait")) {
4789
- out({
4804
+ printJson({
4790
4805
  dataSource: slug,
4791
4806
  job,
4792
4807
  note: "Syncing. Poll `datasources jobs status <id>`, or re-run with --wait. A plan over the per-sync budget waits in `planned` for `datasources jobs approve <id>`."
@@ -4893,7 +4908,7 @@ async function waitForHydration(ctx, params) {
4893
4908
  return {
4894
4909
  status: "timeout",
4895
4910
  source,
4896
- error: timedOut(
4911
+ error: timeoutMessage(
4897
4912
  timeoutMs,
4898
4913
  `with ${hydration.copied}/${hydration.total} documents loaded`
4899
4914
  )
@@ -5030,7 +5045,7 @@ async function waitForRun(ctx, params) {
5030
5045
  return {
5031
5046
  status: "timeout",
5032
5047
  run: run3,
5033
- error: timedOut(
5048
+ error: timeoutMessage(
5034
5049
  timeoutMs,
5035
5050
  `; run is ${run3.state} (${run3.completed}/${run3.total})`
5036
5051
  )
@@ -5058,7 +5073,7 @@ async function waitForSet(ctx, params) {
5058
5073
  return {
5059
5074
  status: "timeout",
5060
5075
  set: set3,
5061
- error: timedOut(timeoutMs, `; set is still ${set3.state}`)
5076
+ error: timeoutMessage(timeoutMs, `; set is still ${set3.state}`)
5062
5077
  };
5063
5078
  }
5064
5079
  if (set3.state === "failed") {
@@ -5246,7 +5261,7 @@ async function hydrate2(ctx, a) {
5246
5261
  const slug = a.str("source") || DEFAULT_SOURCE;
5247
5262
  const started = await hydrate(ctx, { slug });
5248
5263
  if (started.resident || !a.bool("wait")) {
5249
- out({
5264
+ printJson({
5250
5265
  dataSource: slug,
5251
5266
  ...started,
5252
5267
  ...started.resident ? { note: "The index is already loaded." } : {
@@ -5260,14 +5275,14 @@ async function hydrate2(ctx, a) {
5260
5275
  ...timeoutOf(a),
5261
5276
  onProgress: progress
5262
5277
  });
5263
- out({ dataSource: slug, action: "hydrate", ...result });
5264
- failOnWait(result);
5278
+ printJson({ dataSource: slug, action: "hydrate", ...result });
5279
+ throwIfWaitFailed(result);
5265
5280
  }
5266
5281
  async function reindex2(ctx, a) {
5267
5282
  const slug = a.str("source") || DEFAULT_SOURCE;
5268
5283
  const started = await reindex(ctx, { slug });
5269
5284
  if (!a.bool("wait")) {
5270
- out({
5285
+ printJson({
5271
5286
  dataSource: slug,
5272
5287
  ...started,
5273
5288
  note: "The collection was recreated and is refilling from stored vectors in the background. `datasources list` shows progress; re-run with --wait to block."
@@ -5279,8 +5294,8 @@ async function reindex2(ctx, a) {
5279
5294
  ...timeoutOf(a),
5280
5295
  onProgress: progress
5281
5296
  });
5282
- out({ dataSource: slug, action: "reindex", ...result });
5283
- failOnWait(result);
5297
+ printJson({ dataSource: slug, action: "reindex", ...result });
5298
+ throwIfWaitFailed(result);
5284
5299
  }
5285
5300
  async function sampleCmd(ctx, a) {
5286
5301
  const slug = a.str("source");
@@ -5298,7 +5313,7 @@ async function sampleCmd(ctx, a) {
5298
5313
  ...placement !== void 0 ? { placement } : {}
5299
5314
  });
5300
5315
  if (!a.bool("wait")) {
5301
- out({
5316
+ printJson({
5302
5317
  ...result,
5303
5318
  note: `Sampling into "${result.dataSource.slug}". Poll \`datasources jobs status ${result.job.id}\` or re-run with --wait.`
5304
5319
  });
@@ -5329,7 +5344,7 @@ async function evalCreate(ctx, a) {
5329
5344
  });
5330
5345
  const generating = set3.state === "queued" || set3.state === "generating";
5331
5346
  if (!generating || !a.bool("wait")) {
5332
- out({
5347
+ printJson({
5333
5348
  dataSource: slug,
5334
5349
  set: set3,
5335
5350
  note: generating ? "Generating in the background. `datasources eval get <id>` shows the state; re-run with --wait to block." : "Empty set. Add queries with `datasources eval add` or `eval import`."
@@ -5341,23 +5356,23 @@ async function evalCreate(ctx, a) {
5341
5356
  ...timeoutOf(a),
5342
5357
  onProgress: progress
5343
5358
  });
5344
- out({ dataSource: slug, action: "create", ...result });
5345
- failOnWait(result);
5359
+ printJson({ dataSource: slug, action: "create", ...result });
5360
+ throwIfWaitFailed(result);
5346
5361
  }
5347
5362
  async function evalList(ctx, a) {
5348
5363
  const slug = a.str("source");
5349
- out(await listSets(ctx, slug ? { slug } : void 0));
5364
+ printJson(await listSets(ctx, slug ? { slug } : void 0));
5350
5365
  }
5351
5366
  async function evalGet(ctx, a) {
5352
- out(
5367
+ printJson(
5353
5368
  await getSet(ctx, {
5354
- id: a.req("id"),
5369
+ id: a.required("id"),
5355
5370
  ...a.bool("queries") ? { queries: true } : {}
5356
5371
  })
5357
5372
  );
5358
5373
  }
5359
5374
  async function evalDelete(ctx, a) {
5360
- out(await deleteSet(ctx, { id: a.req("id") }));
5375
+ printJson(await deleteSet(ctx, { id: a.required("id") }));
5361
5376
  }
5362
5377
  function expectFromFlags(a) {
5363
5378
  const expect = {};
@@ -5395,11 +5410,11 @@ async function evalAdd(ctx, a) {
5395
5410
  }
5396
5411
  ]
5397
5412
  });
5398
- out({ set: id, ...result });
5413
+ printJson({ set: id, ...result });
5399
5414
  }
5400
5415
  async function evalImport(ctx, a) {
5401
5416
  const id = requireSet(a);
5402
- const file = a.req("file");
5417
+ const file = a.required("file");
5403
5418
  const abs = path3.isAbsolute(file) ? file : path3.join(WORKSPACE_DIR, file);
5404
5419
  let content;
5405
5420
  try {
@@ -5440,16 +5455,16 @@ async function evalImport(ctx, a) {
5440
5455
  added += result.added;
5441
5456
  queryCount = result.queryCount;
5442
5457
  }
5443
- out({ set: id, added, queryCount });
5458
+ printJson({ set: id, added, queryCount });
5444
5459
  }
5445
5460
  async function evalQueries(ctx, a) {
5446
- out(await listQueries(ctx, { id: requireSet(a) }));
5461
+ printJson(await listQueries(ctx, { id: requireSet(a) }));
5447
5462
  }
5448
5463
  async function evalRm(ctx, a) {
5449
- out(
5464
+ printJson(
5450
5465
  await deleteQuery(ctx, {
5451
5466
  id: requireSet(a),
5452
- queryId: a.req("queryId")
5467
+ queryId: a.required("queryId")
5453
5468
  })
5454
5469
  );
5455
5470
  }
@@ -5483,7 +5498,7 @@ async function evalRun(ctx, a) {
5483
5498
  retrieval
5484
5499
  });
5485
5500
  if (!a.bool("wait")) {
5486
- out({
5501
+ printJson({
5487
5502
  run: run3,
5488
5503
  note: "Running in the background. `datasources eval result <id>` shows the numbers when it is done; re-run with --wait to block."
5489
5504
  });
@@ -5494,13 +5509,13 @@ async function evalRun(ctx, a) {
5494
5509
  ...timeoutOf(a),
5495
5510
  onProgress: progress
5496
5511
  });
5497
- out({ action: "run", ...result });
5498
- failOnWait(result);
5512
+ printJson({ action: "run", ...result });
5513
+ throwIfWaitFailed(result);
5499
5514
  }
5500
5515
  async function evalRuns(ctx, a) {
5501
5516
  const setId = a.str("set");
5502
5517
  const slug = a.str("source");
5503
- out(
5518
+ printJson(
5504
5519
  await listRuns(ctx, {
5505
5520
  ...setId ? { setId } : {},
5506
5521
  ...slug ? { slug } : {}
@@ -5509,16 +5524,18 @@ async function evalRuns(ctx, a) {
5509
5524
  }
5510
5525
  async function evalResult(ctx, a) {
5511
5526
  const worst = a.num("worst");
5512
- out(
5527
+ printJson(
5513
5528
  await getRun(ctx, {
5514
- id: a.req("id"),
5529
+ id: a.required("id"),
5515
5530
  ...a.bool("queries") ? { queries: true } : {},
5516
5531
  ...worst !== void 0 ? { worst } : {}
5517
5532
  })
5518
5533
  );
5519
5534
  }
5520
5535
  async function evalCompare(ctx, a) {
5521
- out(await compare(ctx, { a: a.req("a"), b: a.req("b") }));
5536
+ printJson(
5537
+ await compare(ctx, { a: a.required("a"), b: a.required("b") })
5538
+ );
5522
5539
  }
5523
5540
  var dataSourceEvalsHandlers = {
5524
5541
  "datasources hydrate": hydrate2,
@@ -5664,9 +5681,9 @@ function readEntries(file) {
5664
5681
  return entries;
5665
5682
  }
5666
5683
  async function dictionaryPush(ctx, a) {
5667
- const entries = readEntries(a.req("file"));
5684
+ const entries = readEntries(a.required("file"));
5668
5685
  const linkerVersion = a.num("linker-version");
5669
- out(
5686
+ printJson(
5670
5687
  await pushDictionary(ctx, {
5671
5688
  slug: sourceOf(a),
5672
5689
  entries,
@@ -5676,10 +5693,15 @@ async function dictionaryPush(ctx, a) {
5676
5693
  );
5677
5694
  }
5678
5695
  async function dictionaryStatus(ctx, a) {
5679
- out(await dictionary(ctx, { slug: sourceOf(a) }));
5696
+ printJson(await dictionary(ctx, { slug: sourceOf(a) }));
5680
5697
  }
5681
5698
  async function link2(ctx, a) {
5682
- out(await link(ctx, { slug: sourceOf(a), text: a.req("text") }));
5699
+ printJson(
5700
+ await link(ctx, {
5701
+ slug: sourceOf(a),
5702
+ text: a.required("text")
5703
+ })
5704
+ );
5683
5705
  }
5684
5706
  var dataSourceDictionaryHandlers = {
5685
5707
  "datasources dictionary push": dictionaryPush,
@@ -5831,7 +5853,7 @@ async function jobsStart(ctx, a) {
5831
5853
  ...limit !== void 0 ? { limit } : {}
5832
5854
  });
5833
5855
  if (!a.bool("wait")) {
5834
- out({
5856
+ printJson({
5835
5857
  dataSource: slug,
5836
5858
  job,
5837
5859
  note: job.autoApprove ? "Planning, then running once the plan passes the gates. Poll `datasources jobs status <id>` or re-run with --wait." : "Planning. When the plan is ready, review it with `datasources jobs status <id>` and run `datasources jobs approve <id>`."
@@ -5846,18 +5868,18 @@ async function jobsStart(ctx, a) {
5846
5868
  }
5847
5869
  async function jobsList(ctx, a) {
5848
5870
  const slug = a.str("source");
5849
- out(await list11(ctx, slug ? { slug } : void 0));
5871
+ printJson(await list11(ctx, slug ? { slug } : void 0));
5850
5872
  }
5851
5873
  async function jobsStatus(ctx, a) {
5852
- const id = a.req("id");
5874
+ const id = a.required("id");
5853
5875
  if (!a.bool("wait")) {
5854
- out(await get6(ctx, { id }));
5876
+ printJson(await get6(ctx, { id }));
5855
5877
  return;
5856
5878
  }
5857
5879
  await waitAndReport(ctx, a, id, "job", { action: "status" });
5858
5880
  }
5859
5881
  async function jobsApprove(ctx, a) {
5860
- const id = a.req("id");
5882
+ const id = a.required("id");
5861
5883
  const concurrency = a.num("concurrency");
5862
5884
  const { job } = await approve(ctx, {
5863
5885
  id,
@@ -5865,7 +5887,7 @@ async function jobsApprove(ctx, a) {
5865
5887
  ...a.bool("priority") ? { priority: true } : {}
5866
5888
  });
5867
5889
  if (!a.bool("wait")) {
5868
- out({
5890
+ printJson({
5869
5891
  job,
5870
5892
  note: "Running. Poll `datasources jobs status <id>` or re-run with --wait."
5871
5893
  });
@@ -5874,10 +5896,10 @@ async function jobsApprove(ctx, a) {
5874
5896
  await waitAndReport(ctx, a, id, "job", { action: "approve" });
5875
5897
  }
5876
5898
  async function jobsPause(ctx, a) {
5877
- out(await pause(ctx, { id: a.req("id") }));
5899
+ printJson(await pause(ctx, { id: a.required("id") }));
5878
5900
  }
5879
5901
  async function jobsResume(ctx, a) {
5880
- const id = a.req("id");
5902
+ const id = a.required("id");
5881
5903
  const concurrency = a.num("concurrency");
5882
5904
  const { job } = await resume(ctx, {
5883
5905
  id,
@@ -5885,22 +5907,22 @@ async function jobsResume(ctx, a) {
5885
5907
  ...a.bool("priority") ? { priority: true } : {}
5886
5908
  });
5887
5909
  if (!a.bool("wait")) {
5888
- out({ job });
5910
+ printJson({ job });
5889
5911
  return;
5890
5912
  }
5891
5913
  await waitAndReport(ctx, a, id, "job", { action: "resume" });
5892
5914
  }
5893
5915
  async function jobsRetry(ctx, a) {
5894
- const id = a.req("id");
5916
+ const id = a.required("id");
5895
5917
  const { job } = await retry(ctx, { id });
5896
5918
  if (!a.bool("wait")) {
5897
- out({ job });
5919
+ printJson({ job });
5898
5920
  return;
5899
5921
  }
5900
5922
  await waitAndReport(ctx, a, id, "job", { action: "retry" });
5901
5923
  }
5902
5924
  async function jobsCancel(ctx, a) {
5903
- out(await cancel(ctx, { id: a.req("id") }));
5925
+ printJson(await cancel(ctx, { id: a.required("id") }));
5904
5926
  }
5905
5927
  var dataSourceJobsHandlers = {
5906
5928
  "datasources jobs start": jobsStart,
@@ -6184,7 +6206,7 @@ async function inspect2(ctx, a) {
6184
6206
  ...keysOf(a) ? { keys: keysOf(a) } : {},
6185
6207
  ...limit !== void 0 ? { limit } : {}
6186
6208
  });
6187
- out({
6209
+ printJson({
6188
6210
  ...slug ? { dataSource: slug } : {},
6189
6211
  ...result,
6190
6212
  note: result.report.truncated ? `Listed the first ${result.report.objects.toLocaleString()} objects; raise --limit to see more of the shape.` : `Listed every object (${result.report.objects.toLocaleString()}).`
@@ -6213,7 +6235,7 @@ async function mapTest2(ctx, a) {
6213
6235
  }
6214
6236
  } : r
6215
6237
  );
6216
- out({
6238
+ printJson({
6217
6239
  dataSource: slug,
6218
6240
  ...result,
6219
6241
  results,
@@ -6235,7 +6257,7 @@ async function mapDeploy2(ctx, a) {
6235
6257
  });
6236
6258
  const { mapper } = result;
6237
6259
  const from = `${mapper.branch ?? "release"} @ ${(mapper.commitSha ?? "").slice(0, 7)}`;
6238
- out({
6260
+ printJson({
6239
6261
  dataSource: slug,
6240
6262
  mapper,
6241
6263
  changed: result.changed,
@@ -6252,7 +6274,7 @@ async function remap2(ctx, a) {
6252
6274
  ...limit !== void 0 ? { limit } : {}
6253
6275
  });
6254
6276
  if (!a.bool("wait")) {
6255
- out({
6277
+ printJson({
6256
6278
  dataSource: slug,
6257
6279
  job,
6258
6280
  mapper,
@@ -6267,7 +6289,7 @@ async function remap2(ctx, a) {
6267
6289
  });
6268
6290
  }
6269
6291
  async function quarantine2(ctx, a) {
6270
- const id = a.req("id");
6292
+ const id = a.required("id");
6271
6293
  const limit = a.num("limit");
6272
6294
  const kind = kindOf(a);
6273
6295
  const stage = a.str("stage");
@@ -6293,20 +6315,20 @@ async function quarantine2(ctx, a) {
6293
6315
  `Reading: fix the reader and publish, then \`datasources reader retry --source ${result.dataSource.slug} --job ${id}\` reads these again.`
6294
6316
  ] : []
6295
6317
  ];
6296
- out({
6318
+ printJson({
6297
6319
  ...result,
6298
6320
  note: notes.length === 0 ? "Nothing quarantined: the mapper produced documents (or deletions) for every object, and the reader read every document." : notes.join(" ")
6299
6321
  });
6300
6322
  }
6301
6323
  async function replay2(ctx, a) {
6302
- const id = a.req("id");
6324
+ const id = a.required("id");
6303
6325
  const kind = kindOf(a);
6304
6326
  const { job, mapper, dataSource } = await replay(ctx, {
6305
6327
  id,
6306
6328
  ...kind ? { kind } : {}
6307
6329
  });
6308
6330
  if (!a.bool("wait")) {
6309
- out({
6331
+ printJson({
6310
6332
  dataSource: dataSource.slug,
6311
6333
  fromJob: id,
6312
6334
  job,
@@ -6496,7 +6518,7 @@ async function readerTest2(ctx, a) {
6496
6518
  ...limit !== void 0 ? { limit } : {},
6497
6519
  ...a.str("release") ? { releaseId: a.str("release") } : {}
6498
6520
  });
6499
- out({
6521
+ printJson({
6500
6522
  dataSource: slug,
6501
6523
  ...result,
6502
6524
  note: "Ran the LOCAL reader through the dev session, writing into the dev session's database. Query its tables to check what it wrote; publish to make it the live reader, then `datasources reread --unread` reads what it has not."
@@ -6512,7 +6534,7 @@ async function readerStatus2(ctx, a) {
6512
6534
  const slug = sourceOf(a);
6513
6535
  const result = await readerStatus(ctx, { slug });
6514
6536
  const { reader, deliveries, documents: documents2 } = result;
6515
- out({
6537
+ printJson({
6516
6538
  dataSource: slug,
6517
6539
  ...result,
6518
6540
  note: !reader ? `The live release declares no reader for "${slug}". Declare one in mindstudio.json's dataSources and publish.` : deliveries.parked > 0 ? `${deliveries.parked} delivery(ies) failed six times and parked. Fix the reader and publish, then \`datasources reader retry\`.` : documents2.unread > 0 ? `${documents2.unread.toLocaleString()} live document(s) not read yet. \`datasources reread --unread\` plans reading them.` : "Every live document has been read."
@@ -6525,7 +6547,7 @@ async function readerRetry2(ctx, a) {
6525
6547
  slug,
6526
6548
  ...jobId ? { jobId } : {}
6527
6549
  });
6528
- out({
6550
+ printJson({
6529
6551
  dataSource: slug,
6530
6552
  ...jobId ? { job: jobId } : {},
6531
6553
  ...result,
@@ -6545,7 +6567,7 @@ async function reread2(ctx, a) {
6545
6567
  ...limit !== void 0 ? { limit } : {}
6546
6568
  });
6547
6569
  if (!a.bool("wait")) {
6548
- out({
6570
+ printJson({
6549
6571
  dataSource: slug,
6550
6572
  job,
6551
6573
  note: `Planning: the reread prices reading from the reader's history, or reads a first slice for real to measure it. \`datasources jobs status ${job.id}\` shows the plan; \`datasources jobs approve ${job.id}\` runs it.`
@@ -6841,7 +6863,7 @@ async function dataSourcesAdd(ctx, a) {
6841
6863
  timeoutMs,
6842
6864
  onProgress: progress
6843
6865
  });
6844
- out({
6866
+ printJson({
6845
6867
  dataSource: slug,
6846
6868
  status: result.status,
6847
6869
  ...result.error ? { error: result.error } : {},
@@ -6856,14 +6878,14 @@ async function dataSourcesAdd(ctx, a) {
6856
6878
  }
6857
6879
  return;
6858
6880
  }
6859
- out({
6881
+ printJson({
6860
6882
  dataSource: slug,
6861
6883
  documents: results.map(({ job, ...r }) => r),
6862
6884
  ...jobs.length > 0 ? { jobs } : {}
6863
6885
  });
6864
6886
  }
6865
6887
  async function dataSourcesList(ctx) {
6866
- out(await list10(ctx));
6888
+ printJson(await list10(ctx));
6867
6889
  }
6868
6890
  async function dataSourcesStatus(ctx, a) {
6869
6891
  const slug = sourceOf(a);
@@ -6876,7 +6898,7 @@ async function dataSourcesStatus(ctx, a) {
6876
6898
  slug,
6877
6899
  ...status2 ? { status: "error" } : {}
6878
6900
  });
6879
- out({
6901
+ printJson({
6880
6902
  dataSource: slug,
6881
6903
  documents: documents2.map(summarize)
6882
6904
  });
@@ -6885,7 +6907,7 @@ async function dataSourcesStatus(ctx, a) {
6885
6907
  const { dataSources: sources2 } = await list10(ctx);
6886
6908
  const source = sources2.find((s) => s.slug === slug);
6887
6909
  if (!source) {
6888
- out({ dataSource: slug, exists: false });
6910
+ printJson({ dataSource: slug, exists: false });
6889
6911
  return;
6890
6912
  }
6891
6913
  const failures = status2 === "error" || source.counts.error > 0 ? await documents(ctx, {
@@ -6893,7 +6915,7 @@ async function dataSourcesStatus(ctx, a) {
6893
6915
  status: "error",
6894
6916
  limit: FAILURES_PAGE
6895
6917
  }) : null;
6896
- out({
6918
+ printJson({
6897
6919
  dataSource: slug,
6898
6920
  counts: source.counts,
6899
6921
  chunkCount: source.chunkCount,
@@ -6913,18 +6935,18 @@ async function dataSourcesRm(ctx, a) {
6913
6935
  fatal("Give --document or --filter, not both.");
6914
6936
  }
6915
6937
  if (documentId) {
6916
- await rm(ctx, { slug: sourceOf(a), documentId });
6917
- out({ deleted: documentId });
6938
+ await deleteDocument(ctx, { slug: sourceOf(a), documentId });
6939
+ printJson({ deleted: documentId });
6918
6940
  return;
6919
6941
  }
6920
6942
  const filter = documentSelectorOf(rawFilter);
6921
6943
  const slug = sourceOf(a);
6922
- const result = await rmWhereAll(ctx, {
6944
+ const result = await deleteAllDocumentsWhere(ctx, {
6923
6945
  slug,
6924
6946
  filter,
6925
6947
  onProgress: progress
6926
6948
  });
6927
- out({ dataSource: slug, filter, ...result });
6949
+ printJson({ dataSource: slug, filter, ...result });
6928
6950
  }
6929
6951
  async function dataSourcesDelete(ctx, a) {
6930
6952
  const slug = a.str("source");
@@ -6934,7 +6956,7 @@ async function dataSourcesDelete(ctx, a) {
6934
6956
  );
6935
6957
  }
6936
6958
  const result = await deleteSource(ctx, slug);
6937
- out({ dataSource: slug, ...result });
6959
+ printJson({ dataSource: slug, ...result });
6938
6960
  }
6939
6961
  async function dataSourcesSearch(ctx, a) {
6940
6962
  const topK = a.num("top-k");
@@ -6948,10 +6970,10 @@ async function dataSourcesSearch(ctx, a) {
6948
6970
  }
6949
6971
  const filter = filterFromFlags(a);
6950
6972
  const maxPerDocument = a.num("max-per-document");
6951
- out(
6973
+ printJson(
6952
6974
  await search2(ctx, {
6953
6975
  slug: sourceOf(a),
6954
- query: a.req("query"),
6976
+ query: a.required("query"),
6955
6977
  ...topK ? { topK } : {},
6956
6978
  ...mode ? { mode } : {},
6957
6979
  ...filter ? { filter } : {},
@@ -6964,7 +6986,7 @@ async function dataSourcesSearch(ctx, a) {
6964
6986
  }
6965
6987
  async function dataSourcesCount(ctx, a) {
6966
6988
  const filter = filterFromFlags(a);
6967
- out(
6989
+ printJson(
6968
6990
  await count(ctx, {
6969
6991
  slug: sourceOf(a),
6970
6992
  ...filter ? { filter } : {},
@@ -6975,7 +6997,7 @@ async function dataSourcesCount(ctx, a) {
6975
6997
  async function dataSourcesEntities(ctx, a) {
6976
6998
  const filter = filterFromFlags(a);
6977
6999
  const limit = a.num("limit");
6978
- out(
7000
+ printJson(
6979
7001
  await entities(ctx, {
6980
7002
  slug: sourceOf(a),
6981
7003
  ...filter ? { filter } : {},
@@ -6995,7 +7017,7 @@ async function dataSourcesPassages(ctx, a) {
6995
7017
  ...limit !== void 0 ? { limit } : {},
6996
7018
  ...a.bool("candidate") ? { candidate: true } : {}
6997
7019
  });
6998
- out({
7020
+ printJson({
6999
7021
  ...result,
7000
7022
  ...result.nextCursor ? { note: `More: pass --cursor ${result.nextCursor} for the next page.` } : {}
7001
7023
  });
@@ -7135,7 +7157,7 @@ async function dataSourcesCreate(ctx, a) {
7135
7157
  ...ingest ? { ingest } : {},
7136
7158
  ...placement !== void 0 ? { placement } : {}
7137
7159
  });
7138
- out(
7160
+ printJson(
7139
7161
  result.migration && !result.migration.error ? { ...result, note: MOVE_NOTE } : result
7140
7162
  );
7141
7163
  }
@@ -7144,7 +7166,7 @@ async function dataSourcesConfig(ctx, a) {
7144
7166
  const { ingest, retrieval } = configFromFlags(a);
7145
7167
  const placement = placementOf(a);
7146
7168
  if (!ingest && !retrieval && placement === void 0) {
7147
- out(await configGet(ctx, slug));
7169
+ printJson(await configGet(ctx, slug));
7148
7170
  return;
7149
7171
  }
7150
7172
  const result = await configSet(ctx, {
@@ -7153,14 +7175,14 @@ async function dataSourcesConfig(ctx, a) {
7153
7175
  ...retrieval ? { retrieval } : {},
7154
7176
  ...placement !== void 0 ? { placement } : {}
7155
7177
  });
7156
- out(
7178
+ printJson(
7157
7179
  result.placementChanged && result.migration && !result.migration.error ? { ...result, note: MOVE_NOTE } : result
7158
7180
  );
7159
7181
  }
7160
7182
  async function dataSourcesMove(ctx, a) {
7161
7183
  const slug = sourceOf(a);
7162
7184
  if (a.bool("stop")) {
7163
- out({
7185
+ printJson({
7164
7186
  dataSource: slug,
7165
7187
  ...await stopMove(ctx, { slug }),
7166
7188
  note: "Stopped; the chains halt at their next checkpoint. Re-run `datasources move --to <same target>` to resume from where they were."
@@ -7177,7 +7199,7 @@ async function dataSourcesMove(ctx, a) {
7177
7199
  ...chains !== void 0 ? { chains } : {}
7178
7200
  });
7179
7201
  if (!started.migration || !a.bool("wait")) {
7180
- out({
7202
+ printJson({
7181
7203
  dataSource: slug,
7182
7204
  ...started,
7183
7205
  ...started.migration ? { note: MOVE_NOTE } : {}
@@ -7190,7 +7212,7 @@ async function dataSourcesMove(ctx, a) {
7190
7212
  ...timeoutSec ? { timeoutMs: timeoutSec * 1e3 } : {},
7191
7213
  onProgress: progress
7192
7214
  });
7193
- out({
7215
+ printJson({
7194
7216
  dataSource: slug,
7195
7217
  status: result.status,
7196
7218
  placement: result.source.placement,
@@ -7212,7 +7234,11 @@ async function dataSourcesRevectorize(ctx, a) {
7212
7234
  ...ingest ? { ingest } : {}
7213
7235
  });
7214
7236
  if (!a.bool("wait")) {
7215
- out({ dataSource: slug, ...started, note: "Run `promote` when ready." });
7237
+ printJson({
7238
+ dataSource: slug,
7239
+ ...started,
7240
+ note: "Run `promote` when ready."
7241
+ });
7216
7242
  return;
7217
7243
  }
7218
7244
  const timeoutSec = a.num("timeout");
@@ -7222,10 +7248,10 @@ async function dataSourcesRevectorize(ctx, a) {
7222
7248
  onProgress: progress
7223
7249
  });
7224
7250
  if (result.status === "timeout") {
7225
- out({ dataSource: slug, status: "timeout", error: result.error });
7251
+ printJson({ dataSource: slug, status: "timeout", error: result.error });
7226
7252
  throw new CliError(result.error ?? "Timed out.", EXIT.timeout);
7227
7253
  }
7228
- out({
7254
+ printJson({
7229
7255
  dataSource: slug,
7230
7256
  candidateVersion: started.candidateVersion,
7231
7257
  status: result.status,
@@ -7238,7 +7264,7 @@ async function dataSourcesRevectorize(ctx, a) {
7238
7264
  }
7239
7265
  }
7240
7266
  async function dataSourcesPromote(ctx, a) {
7241
- out(
7267
+ printJson(
7242
7268
  await promote(ctx, {
7243
7269
  slug: sourceOf(a),
7244
7270
  ...a.bool("force") ? { force: true } : {}
@@ -7247,8 +7273,8 @@ async function dataSourcesPromote(ctx, a) {
7247
7273
  }
7248
7274
  async function dataSourcesDrop(ctx, a) {
7249
7275
  const version = a.str("version");
7250
- out(
7251
- await drop(ctx, {
7276
+ printJson(
7277
+ await dropPipelineVersion(ctx, {
7252
7278
  slug: sourceOf(a),
7253
7279
  ...version ? { version: Number(version) } : {}
7254
7280
  })
@@ -7573,7 +7599,7 @@ async function numbersRelease(ctx, e164) {
7573
7599
  return call(
7574
7600
  ctx,
7575
7601
  "POST",
7576
- `/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/${seg(id)}/release`
7602
+ `/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/${encodePathSegment(id)}/release`
7577
7603
  );
7578
7604
  }
7579
7605
  async function numbersSetName(ctx, e164, displayName) {
@@ -7581,7 +7607,7 @@ async function numbersSetName(ctx, e164, displayName) {
7581
7607
  return call(
7582
7608
  ctx,
7583
7609
  "POST",
7584
- `/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/${seg(id)}/display-name`,
7610
+ `/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/${encodePathSegment(id)}/display-name`,
7585
7611
  { displayName }
7586
7612
  );
7587
7613
  }
@@ -7596,7 +7622,7 @@ function sessionsGet(ctx, sessionId) {
7596
7622
  return call(
7597
7623
  ctx,
7598
7624
  "GET",
7599
- `/_internal/v2/apps/${ctx.appId}/voice-sessions/${seg(sessionId)}`
7625
+ `/_internal/v2/apps/${ctx.appId}/voice-sessions/${encodePathSegment(sessionId)}`
7600
7626
  );
7601
7627
  }
7602
7628
  function settingsGet(ctx) {
@@ -7694,10 +7720,10 @@ var voiceSpecs = {
7694
7720
  }
7695
7721
  };
7696
7722
  async function numbersList2(ctx) {
7697
- out(await numbersList(ctx));
7723
+ printJson(await numbersList(ctx));
7698
7724
  }
7699
7725
  async function numbersSearch2(ctx, a) {
7700
- out(
7726
+ printJson(
7701
7727
  await numbersSearch(ctx, {
7702
7728
  areaCode: a.str("area-code"),
7703
7729
  locality: a.str("locality"),
@@ -7707,9 +7733,9 @@ async function numbersSearch2(ctx, a) {
7707
7733
  );
7708
7734
  }
7709
7735
  async function numbersBuy2(ctx, a) {
7710
- out(
7736
+ printJson(
7711
7737
  await numbersBuy(ctx, {
7712
- phoneNumber: a.req("e164"),
7738
+ phoneNumber: a.required("e164"),
7713
7739
  locality: a.str("locality"),
7714
7740
  administrativeArea: a.str("state"),
7715
7741
  monthlyCost: a.str("monthly-cost")
@@ -7717,14 +7743,14 @@ async function numbersBuy2(ctx, a) {
7717
7743
  );
7718
7744
  }
7719
7745
  async function numbersRelease2(ctx, a) {
7720
- out(await numbersRelease(ctx, a.req("e164")));
7746
+ printJson(await numbersRelease(ctx, a.required("e164")));
7721
7747
  }
7722
7748
  async function numbersSetName2(ctx, a) {
7723
7749
  const displayName = a.bool("clear") ? "" : a.str("name") ?? "";
7724
- out(await numbersSetName(ctx, a.req("e164"), displayName));
7750
+ printJson(await numbersSetName(ctx, a.required("e164"), displayName));
7725
7751
  }
7726
7752
  async function sessionsList2(ctx, a) {
7727
- out(
7753
+ printJson(
7728
7754
  await sessionsList(ctx, {
7729
7755
  limit: a.num("limit"),
7730
7756
  cursor: a.str("cursor")
@@ -7732,13 +7758,13 @@ async function sessionsList2(ctx, a) {
7732
7758
  );
7733
7759
  }
7734
7760
  async function sessionsGet2(ctx, a) {
7735
- out(await sessionsGet(ctx, a.req("sessionId")));
7761
+ printJson(await sessionsGet(ctx, a.required("sessionId")));
7736
7762
  }
7737
7763
  async function settingsGet2(ctx) {
7738
- out(await settingsGet(ctx));
7764
+ printJson(await settingsGet(ctx));
7739
7765
  }
7740
7766
  async function settingsSet2(ctx, a) {
7741
- out(
7767
+ printJson(
7742
7768
  await settingsSet(ctx, {
7743
7769
  maxConcurrentSessions: a.num("max-concurrent-sessions"),
7744
7770
  maxConcurrentSessionsPerVisitor: a.num("max-per-visitor"),
@@ -7810,7 +7836,7 @@ function threadsGet(ctx, threadId) {
7810
7836
  return call(
7811
7837
  ctx,
7812
7838
  "GET",
7813
- `/_internal/v2/apps/${ctx.appId}/agent-threads/${seg(threadId)}`
7839
+ `/_internal/v2/apps/${ctx.appId}/agent-threads/${encodePathSegment(threadId)}`
7814
7840
  );
7815
7841
  }
7816
7842
 
@@ -7829,7 +7855,7 @@ var agentSpecs = {
7829
7855
  }
7830
7856
  };
7831
7857
  async function threadsList2(ctx, a) {
7832
- out(
7858
+ printJson(
7833
7859
  await threadsList(ctx, {
7834
7860
  limit: a.num("limit"),
7835
7861
  cursor: a.str("cursor")
@@ -7837,7 +7863,7 @@ async function threadsList2(ctx, a) {
7837
7863
  );
7838
7864
  }
7839
7865
  async function threadsGet2(ctx, a) {
7840
- out(await threadsGet(ctx, a.req("threadId")));
7866
+ printJson(await threadsGet(ctx, a.required("threadId")));
7841
7867
  }
7842
7868
  var agentHandlers = {
7843
7869
  "agent threads list": threadsList2,
@@ -7887,7 +7913,7 @@ function get8(ctx, traceId) {
7887
7913
  return call(
7888
7914
  ctx,
7889
7915
  "GET",
7890
- `/_internal/v2/apps/${ctx.appId}/task-traces/${seg(traceId)}`
7916
+ `/_internal/v2/apps/${ctx.appId}/task-traces/${encodePathSegment(traceId)}`
7891
7917
  );
7892
7918
  }
7893
7919
 
@@ -7906,7 +7932,7 @@ var tasksSpecs = {
7906
7932
  }
7907
7933
  };
7908
7934
  async function list13(ctx, a) {
7909
- out(
7935
+ printJson(
7910
7936
  await list12(ctx, {
7911
7937
  limit: a.num("limit"),
7912
7938
  cursor: a.str("cursor")
@@ -7914,7 +7940,7 @@ async function list13(ctx, a) {
7914
7940
  );
7915
7941
  }
7916
7942
  async function get9(ctx, a) {
7917
- out(await get8(ctx, a.req("traceId")));
7943
+ printJson(await get8(ctx, a.required("traceId")));
7918
7944
  }
7919
7945
  var tasksHandlers = {
7920
7946
  "tasks list": list13,
@@ -7984,7 +8010,7 @@ var usageSpecs = {
7984
8010
  async function summary3(ctx, a) {
7985
8011
  const end = a.str("end") ?? (/* @__PURE__ */ new Date()).toISOString();
7986
8012
  const start2 = a.str("start") ?? new Date(new Date(end).getTime() - DEFAULT_WINDOW_MS).toISOString();
7987
- out(
8013
+ printJson(
7988
8014
  await summary2(ctx, {
7989
8015
  startTime: start2,
7990
8016
  endTime: end,
@@ -8089,23 +8115,23 @@ async function eventsTail(ctx, a) {
8089
8115
  );
8090
8116
  }
8091
8117
  async function eventsPublish(ctx, a) {
8092
- const raw = a.req("json");
8118
+ const raw = a.required("json");
8093
8119
  let data;
8094
8120
  try {
8095
8121
  data = JSON.parse(raw);
8096
8122
  } catch {
8097
8123
  fatal(`Invalid JSON payload: ${raw}`);
8098
8124
  }
8099
- out(
8125
+ printJson(
8100
8126
  await publish(ctx, {
8101
- channels: a.req("channel"),
8127
+ channels: a.required("channel"),
8102
8128
  data,
8103
8129
  scope: a.str("scope")
8104
8130
  })
8105
8131
  );
8106
8132
  }
8107
8133
  async function eventsChannelsList(ctx, a) {
8108
- out(await channelsList(ctx, { scope: a.str("scope") }));
8134
+ printJson(await channelsList(ctx, { scope: a.str("scope") }));
8109
8135
  }
8110
8136
  var eventsHandlers = {
8111
8137
  "events tail": eventsTail,
@@ -8182,7 +8208,7 @@ function pair(ctx, pairId) {
8182
8208
  return call(
8183
8209
  ctx,
8184
8210
  "GET",
8185
- `/_internal/v2/apps/${ctx.appId}/jewels/pairs/${seg(pairId)}`
8211
+ `/_internal/v2/apps/${ctx.appId}/jewels/pairs/${encodePathSegment(pairId)}`
8186
8212
  );
8187
8213
  }
8188
8214
  function queue(ctx, params = {}) {
@@ -8212,7 +8238,7 @@ function dryrun(ctx, params) {
8212
8238
  return call(
8213
8239
  ctx,
8214
8240
  "POST",
8215
- `/_internal/v2/apps/${ctx.appId}/jewels/${seg(params.methodId)}/dryrun`,
8241
+ `/_internal/v2/apps/${ctx.appId}/jewels/${encodePathSegment(params.methodId)}/dryrun`,
8216
8242
  { subject: params.subject },
8217
8243
  JEWEL_RUN_TIMEOUT_MS
8218
8244
  );
@@ -8246,14 +8272,14 @@ function getRun2(ctx, runId) {
8246
8272
  return call(
8247
8273
  ctx,
8248
8274
  "GET",
8249
- `/_internal/v2/apps/${ctx.appId}/jewels/training-runs/${seg(runId)}`
8275
+ `/_internal/v2/apps/${ctx.appId}/jewels/training-runs/${encodePathSegment(runId)}`
8250
8276
  );
8251
8277
  }
8252
8278
  function grade(ctx, runId) {
8253
8279
  return call(
8254
8280
  ctx,
8255
8281
  "POST",
8256
- `/_internal/v2/apps/${ctx.appId}/jewels/training-runs/${seg(runId)}/grade`,
8282
+ `/_internal/v2/apps/${ctx.appId}/jewels/training-runs/${encodePathSegment(runId)}/grade`,
8257
8283
  void 0,
8258
8284
  JEWEL_RUN_TIMEOUT_MS
8259
8285
  );
@@ -8360,7 +8386,7 @@ function parseJsonFlag(a, flag) {
8360
8386
  return value;
8361
8387
  }
8362
8388
  async function jewelsOverview(ctx, a) {
8363
- out(
8389
+ printJson(
8364
8390
  await overview(ctx, {
8365
8391
  start: a.str("start"),
8366
8392
  end: a.str("end")
@@ -8368,7 +8394,7 @@ async function jewelsOverview(ctx, a) {
8368
8394
  );
8369
8395
  }
8370
8396
  async function jewelsPairs(ctx, a) {
8371
- out(
8397
+ printJson(
8372
8398
  await pairs(ctx, {
8373
8399
  methodId: a.str("method-id"),
8374
8400
  verdict: a.str("verdict"),
@@ -8381,10 +8407,10 @@ async function jewelsPairs(ctx, a) {
8381
8407
  );
8382
8408
  }
8383
8409
  async function jewelsPair(ctx, a) {
8384
- out(await pair(ctx, a.req("pairId")));
8410
+ printJson(await pair(ctx, a.required("pairId")));
8385
8411
  }
8386
8412
  async function jewelsQueue(ctx, a) {
8387
- out(
8413
+ printJson(
8388
8414
  await queue(ctx, {
8389
8415
  methodId: a.str("method-id"),
8390
8416
  limit: a.num("limit")
@@ -8392,7 +8418,7 @@ async function jewelsQueue(ctx, a) {
8392
8418
  );
8393
8419
  }
8394
8420
  async function jewelsTimeseries(ctx, a) {
8395
- out(
8421
+ printJson(
8396
8422
  await timeseries(ctx, {
8397
8423
  methodId: a.str("method-id"),
8398
8424
  start: a.str("start"),
@@ -8411,37 +8437,37 @@ async function jewelsResolve(ctx, a) {
8411
8437
  fatal("--input only applies to --approve.");
8412
8438
  }
8413
8439
  const params = {
8414
- itemId: a.req("itemId"),
8440
+ itemId: a.required("itemId"),
8415
8441
  action: approve2 ? "approve" : "dismiss"
8416
8442
  };
8417
8443
  if (a.str("input") !== void 0) {
8418
8444
  params.input = parseJsonFlag(a, "input");
8419
8445
  }
8420
- out(await resolve(ctx, params));
8446
+ printJson(await resolve(ctx, params));
8421
8447
  }
8422
8448
  async function jewelsExport(ctx, a) {
8423
8449
  const apiPath = `/_internal/v2/apps/${ctx.appId}/jewels/export${qs({
8424
8450
  file: a.str("file"),
8425
8451
  start: a.str("start"),
8426
8452
  end: a.str("end"),
8427
- methodId: a.req("methodId")
8453
+ methodId: a.required("methodId")
8428
8454
  })}`;
8429
8455
  if (a.str("file")) {
8430
8456
  await rawToStdout(ctx, "GET", apiPath, JEWEL_RUN_TIMEOUT_MS);
8431
8457
  return;
8432
8458
  }
8433
- out(
8459
+ printJson(
8434
8460
  await exportSummary(ctx, {
8435
- methodId: a.req("methodId"),
8461
+ methodId: a.required("methodId"),
8436
8462
  start: a.str("start"),
8437
8463
  end: a.str("end")
8438
8464
  })
8439
8465
  );
8440
8466
  }
8441
8467
  async function jewelsDryrun(ctx, a) {
8442
- out(
8468
+ printJson(
8443
8469
  await dryrun(ctx, {
8444
- methodId: a.req("methodId"),
8470
+ methodId: a.required("methodId"),
8445
8471
  subject: parseJsonFlag(a, "subject")
8446
8472
  })
8447
8473
  );
@@ -8449,12 +8475,12 @@ async function jewelsDryrun(ctx, a) {
8449
8475
  var TRAIN_POLL_MS = 15e3;
8450
8476
  var TRAIN_WAIT_LIMIT_MS = 45 * 6e4;
8451
8477
  async function jewelsTrain(ctx, a) {
8452
- const started = await train(ctx, { methodId: a.req("methodId") });
8478
+ const started = await train(ctx, { methodId: a.required("methodId") });
8453
8479
  if (!a.bool("wait")) {
8454
- out(started);
8480
+ printJson(started);
8455
8481
  return;
8456
8482
  }
8457
- out({ runId: started.run?.id, summary: started.summary });
8483
+ printJson({ runId: started.run?.id, summary: started.summary });
8458
8484
  const runId = started.run?.id;
8459
8485
  const deadline = Date.now() + TRAIN_WAIT_LIMIT_MS;
8460
8486
  let lastLogLen = 0;
@@ -8467,20 +8493,20 @@ async function jewelsTrain(ctx, a) {
8467
8493
  const isStatus = (x) => x?.kind === "status";
8468
8494
  const isLoss = (x) => x?.kind === "loss";
8469
8495
  for (const e of fresh.filter(isStatus)) {
8470
- out({ status: run3.status, at: e.ts, message: e.message });
8496
+ printJson({ status: run3.status, at: e.ts, message: e.message });
8471
8497
  }
8472
8498
  const losses = fresh.filter(isLoss);
8473
8499
  if (losses.length) {
8474
8500
  const last = losses[losses.length - 1];
8475
8501
  const p = run3.progress;
8476
- out({
8502
+ printJson({
8477
8503
  status: run3.status,
8478
8504
  step: `${last.step}/${p?.totalSteps ?? "?"}`,
8479
8505
  loss: last.loss
8480
8506
  });
8481
8507
  }
8482
8508
  if (run3.status === "complete" || run3.status === "failed") {
8483
- out(compactRunLog(run3));
8509
+ printJson(compactRunLog(run3));
8484
8510
  if (run3.status === "failed") {
8485
8511
  process.exitCode = 1;
8486
8512
  }
@@ -8492,15 +8518,15 @@ async function jewelsTrain(ctx, a) {
8492
8518
  );
8493
8519
  }
8494
8520
  function compactRunLog(run3) {
8495
- let out2 = { ...run3 };
8521
+ let out = { ...run3 };
8496
8522
  if (Array.isArray(run3.log)) {
8497
8523
  const statusEntries = run3.log.filter((e) => e?.kind === "status");
8498
8524
  const lossPoints = run3.log.length - statusEntries.length;
8499
- out2 = { ...out2, log: { statusEntries, lossPoints } };
8525
+ out = { ...out, log: { statusEntries, lossPoints } };
8500
8526
  }
8501
8527
  if (Array.isArray(run3.report?.candidates)) {
8502
- out2 = {
8503
- ...out2,
8528
+ out = {
8529
+ ...out,
8504
8530
  report: {
8505
8531
  ...run3.report,
8506
8532
  candidates: run3.report.candidates.map(
@@ -8509,10 +8535,10 @@ function compactRunLog(run3) {
8509
8535
  }
8510
8536
  };
8511
8537
  }
8512
- return out2;
8538
+ return out;
8513
8539
  }
8514
8540
  async function jewelsRuns(ctx, a) {
8515
- out(
8541
+ printJson(
8516
8542
  await runs(ctx, {
8517
8543
  methodId: a.str("method-id"),
8518
8544
  limit: a.num("limit")
@@ -8520,11 +8546,11 @@ async function jewelsRuns(ctx, a) {
8520
8546
  );
8521
8547
  }
8522
8548
  async function jewelsRunGet(ctx, a) {
8523
- const { run: run3 } = await getRun2(ctx, a.req("runId"));
8524
- out({ run: compactRunLog(run3) });
8549
+ const { run: run3 } = await getRun2(ctx, a.required("runId"));
8550
+ printJson({ run: compactRunLog(run3) });
8525
8551
  }
8526
8552
  async function jewelsGrade(ctx, a) {
8527
- out(await grade(ctx, a.req("runId")));
8553
+ printJson(await grade(ctx, a.required("runId")));
8528
8554
  }
8529
8555
  var jewelsHandlers = {
8530
8556
  "jewels overview": jewelsOverview,
@@ -8715,18 +8741,20 @@ function normalizeOrigin(raw) {
8715
8741
  return trimmed.includes("://") ? trimmed : `https://${trimmed}`;
8716
8742
  }
8717
8743
  async function settingsGet3(ctx) {
8718
- out({ settings: await getSettings(ctx) });
8744
+ printJson({ settings: await getSettings(ctx) });
8719
8745
  }
8720
8746
  async function settingsSet3(ctx, a) {
8721
- const key = a.req("key");
8722
- const raw = a.req("value");
8747
+ const key = a.required("key");
8748
+ const raw = a.required("value");
8723
8749
  let value;
8724
8750
  try {
8725
8751
  value = JSON.parse(raw);
8726
8752
  } catch {
8727
8753
  value = raw;
8728
8754
  }
8729
- out({ settings: await updateSettings(ctx, { [key]: value }) });
8755
+ printJson({
8756
+ settings: await updateSettings(ctx, { [key]: value })
8757
+ });
8730
8758
  }
8731
8759
  function allowlistView(s) {
8732
8760
  return {
@@ -8735,7 +8763,7 @@ function allowlistView(s) {
8735
8763
  };
8736
8764
  }
8737
8765
  async function allowlistList(ctx) {
8738
- out(allowlistView(await getSettings(ctx)));
8766
+ printJson(allowlistView(await getSettings(ctx)));
8739
8767
  }
8740
8768
  async function allowlistEnable(ctx) {
8741
8769
  const updated = await updateSettings(ctx, {
@@ -8745,17 +8773,17 @@ async function allowlistEnable(ctx) {
8745
8773
  if (view2.entries.length === 0) {
8746
8774
  view2.note = "The allowlist is enabled but empty \u2014 an empty list allows everyone. Add entries to enforce it.";
8747
8775
  }
8748
- out(view2);
8776
+ printJson(view2);
8749
8777
  }
8750
8778
  async function allowlistDisable(ctx) {
8751
- out(
8779
+ printJson(
8752
8780
  allowlistView(
8753
8781
  await updateSettings(ctx, { signupAllowlistEnabled: false })
8754
8782
  )
8755
8783
  );
8756
8784
  }
8757
8785
  async function allowlistAdd(ctx, a) {
8758
- const entry = a.req("entry").trim().toLowerCase();
8786
+ const entry = a.required("entry").trim().toLowerCase();
8759
8787
  const current = await getSettings(ctx);
8760
8788
  const entries = current.signupAllowlist ?? [];
8761
8789
  const next = entries.includes(entry) ? entries : [...entries, entry];
@@ -8766,10 +8794,10 @@ async function allowlistAdd(ctx, a) {
8766
8794
  if (!view2.enabled) {
8767
8795
  view2.note = "signupAllowlistEnabled is off, so this list is not being enforced. Enable it with: remy-admin settings allowlist enable";
8768
8796
  }
8769
- out(view2);
8797
+ printJson(view2);
8770
8798
  }
8771
8799
  async function allowlistRemove(ctx, a) {
8772
- const entry = a.req("entry").trim().toLowerCase();
8800
+ const entry = a.required("entry").trim().toLowerCase();
8773
8801
  const current = await getSettings(ctx);
8774
8802
  const entries = current.signupAllowlist ?? [];
8775
8803
  if (!entries.includes(entry)) {
@@ -8783,7 +8811,7 @@ async function allowlistRemove(ctx, a) {
8783
8811
  if (view2.enabled && view2.entries.length === 0) {
8784
8812
  view2.note = "The allowlist is now empty while enabled \u2014 an empty list allows everyone.";
8785
8813
  }
8786
- out(view2);
8814
+ printJson(view2);
8787
8815
  }
8788
8816
  function testAccountsView(s) {
8789
8817
  return {
@@ -8792,25 +8820,25 @@ function testAccountsView(s) {
8792
8820
  };
8793
8821
  }
8794
8822
  async function testAccountsList(ctx) {
8795
- out(testAccountsView(await getSettings(ctx)));
8823
+ printJson(testAccountsView(await getSettings(ctx)));
8796
8824
  }
8797
8825
  async function testAccountsEnable(ctx) {
8798
- out(
8826
+ printJson(
8799
8827
  testAccountsView(
8800
8828
  await updateSettings(ctx, { testAccountsEnabled: true })
8801
8829
  )
8802
8830
  );
8803
8831
  }
8804
8832
  async function testAccountsDisable(ctx) {
8805
- out(
8833
+ printJson(
8806
8834
  testAccountsView(
8807
8835
  await updateSettings(ctx, { testAccountsEnabled: false })
8808
8836
  )
8809
8837
  );
8810
8838
  }
8811
8839
  async function testAccountsAdd(ctx, a) {
8812
- const identifier = normalizeIdentifier(a.req("identifier"));
8813
- const code = a.req("code").trim();
8840
+ const identifier = normalizeIdentifier(a.required("identifier"));
8841
+ const code = a.required("code").trim();
8814
8842
  const current = await getSettings(ctx);
8815
8843
  const accounts = current.testAccounts ?? [];
8816
8844
  const next = [
@@ -8822,17 +8850,17 @@ async function testAccountsAdd(ctx, a) {
8822
8850
  if (!view2.enabled) {
8823
8851
  view2.note = "testAccountsEnabled is off, so fixed-code login is not active. Enable it with: remy-admin settings test-accounts enable";
8824
8852
  }
8825
- out(view2);
8853
+ printJson(view2);
8826
8854
  }
8827
8855
  async function testAccountsRemove(ctx, a) {
8828
- const identifier = normalizeIdentifier(a.req("identifier"));
8856
+ const identifier = normalizeIdentifier(a.required("identifier"));
8829
8857
  const current = await getSettings(ctx);
8830
8858
  const accounts = current.testAccounts ?? [];
8831
8859
  if (!accounts.some((t) => t.identifier === identifier)) {
8832
8860
  fatal(`"${identifier}" is not a configured test account`);
8833
8861
  }
8834
8862
  const next = accounts.filter((t) => t.identifier !== identifier);
8835
- out(
8863
+ printJson(
8836
8864
  testAccountsView(
8837
8865
  await updateSettings(ctx, { testAccounts: next })
8838
8866
  )
@@ -8840,20 +8868,20 @@ async function testAccountsRemove(ctx, a) {
8840
8868
  }
8841
8869
  async function frameAncestorsList(ctx) {
8842
8870
  const s = await getSettings(ctx);
8843
- out({ origins: s.additionalFrameAncestors ?? [] });
8871
+ printJson({ origins: s.additionalFrameAncestors ?? [] });
8844
8872
  }
8845
8873
  async function frameAncestorsAdd(ctx, a) {
8846
- const origin = normalizeOrigin(a.req("origin"));
8874
+ const origin = normalizeOrigin(a.required("origin"));
8847
8875
  const current = await getSettings(ctx);
8848
8876
  const origins = current.additionalFrameAncestors ?? [];
8849
8877
  const next = origins.includes(origin) ? origins : [...origins, origin];
8850
8878
  const updated = await updateSettings(ctx, {
8851
8879
  additionalFrameAncestors: next
8852
8880
  });
8853
- out({ origins: updated.additionalFrameAncestors ?? [] });
8881
+ printJson({ origins: updated.additionalFrameAncestors ?? [] });
8854
8882
  }
8855
8883
  async function frameAncestorsRemove(ctx, a) {
8856
- const origin = normalizeOrigin(a.req("origin"));
8884
+ const origin = normalizeOrigin(a.required("origin"));
8857
8885
  const current = await getSettings(ctx);
8858
8886
  const origins = current.additionalFrameAncestors ?? [];
8859
8887
  if (!origins.includes(origin)) {
@@ -8863,7 +8891,7 @@ async function frameAncestorsRemove(ctx, a) {
8863
8891
  const updated = await updateSettings(ctx, {
8864
8892
  additionalFrameAncestors: next
8865
8893
  });
8866
- out({ origins: updated.additionalFrameAncestors ?? [] });
8894
+ printJson({ origins: updated.additionalFrameAncestors ?? [] });
8867
8895
  }
8868
8896
  var settingsHandlers = {
8869
8897
  "settings get": settingsGet3,
@@ -8979,7 +9007,7 @@ function get10(ctx, messageId) {
8979
9007
  return call(
8980
9008
  ctx,
8981
9009
  "GET",
8982
- `/_internal/v2/apps/${ctx.appId}/outbound-email/messages/${seg(messageId)}`
9010
+ `/_internal/v2/apps/${ctx.appId}/outbound-email/messages/${encodePathSegment(messageId)}`
8983
9011
  );
8984
9012
  }
8985
9013
  function stats2(ctx, params = {}) {
@@ -9007,7 +9035,7 @@ function batch2(ctx, batchId) {
9007
9035
  return call(
9008
9036
  ctx,
9009
9037
  "GET",
9010
- `/_internal/v2/apps/${ctx.appId}/outbound-email/batches/${seg(batchId)}`
9038
+ `/_internal/v2/apps/${ctx.appId}/outbound-email/batches/${encodePathSegment(batchId)}`
9011
9039
  );
9012
9040
  }
9013
9041
  function suppressions(ctx, params = {}) {
@@ -9058,7 +9086,7 @@ async function verifyDomain(ctx, direction, domain) {
9058
9086
  return call(
9059
9087
  ctx,
9060
9088
  "POST",
9061
- `${domainsPath(ctx, direction)}/${seg(id)}/retry`
9089
+ `${domainsPath(ctx, direction)}/${encodePathSegment(id)}/retry`
9062
9090
  );
9063
9091
  }
9064
9092
  async function removeDomain(ctx, direction, domain) {
@@ -9066,7 +9094,7 @@ async function removeDomain(ctx, direction, domain) {
9066
9094
  return call(
9067
9095
  ctx,
9068
9096
  "POST",
9069
- `${domainsPath(ctx, direction)}/${seg(id)}/delete`
9097
+ `${domainsPath(ctx, direction)}/${encodePathSegment(id)}/delete`
9070
9098
  );
9071
9099
  }
9072
9100
 
@@ -9166,7 +9194,7 @@ var emailSpecs = {
9166
9194
  }
9167
9195
  };
9168
9196
  async function emailList(ctx, a) {
9169
- out(
9197
+ printJson(
9170
9198
  await list14(ctx, {
9171
9199
  status: a.str("status"),
9172
9200
  kind: a.str("kind"),
@@ -9181,16 +9209,18 @@ async function emailList(ctx, a) {
9181
9209
  );
9182
9210
  }
9183
9211
  async function emailGet(ctx, a) {
9184
- out(await get10(ctx, a.req("messageId")));
9212
+ printJson(await get10(ctx, a.required("messageId")));
9185
9213
  }
9186
9214
  async function emailStats(ctx, a) {
9187
- out(await stats2(ctx, { start: a.str("start"), end: a.str("end") }));
9215
+ printJson(
9216
+ await stats2(ctx, { start: a.str("start"), end: a.str("end") })
9217
+ );
9188
9218
  }
9189
9219
  async function emailStatus(ctx) {
9190
- out(await status(ctx));
9220
+ printJson(await status(ctx));
9191
9221
  }
9192
9222
  async function emailBatches(ctx, a) {
9193
- out(
9223
+ printJson(
9194
9224
  await batches(ctx, {
9195
9225
  start: a.str("start"),
9196
9226
  end: a.str("end"),
@@ -9200,10 +9230,10 @@ async function emailBatches(ctx, a) {
9200
9230
  );
9201
9231
  }
9202
9232
  async function emailBatch(ctx, a) {
9203
- out(await batch2(ctx, a.req("batchId")));
9233
+ printJson(await batch2(ctx, a.required("batchId")));
9204
9234
  }
9205
9235
  async function emailSuppressions(ctx, a) {
9206
- out(
9236
+ printJson(
9207
9237
  await suppressions(ctx, {
9208
9238
  limit: a.num("limit"),
9209
9239
  offset: a.num("offset")
@@ -9211,7 +9241,7 @@ async function emailSuppressions(ctx, a) {
9211
9241
  );
9212
9242
  }
9213
9243
  async function emailSuppress(ctx, a) {
9214
- out(await suppress(ctx, a.req("email")));
9244
+ printJson(await suppress(ctx, a.required("email")));
9215
9245
  }
9216
9246
  async function emailUnsuppress(ctx, a) {
9217
9247
  if (!a.bool("confirm")) {
@@ -9219,23 +9249,23 @@ async function emailUnsuppress(ctx, a) {
9219
9249
  "Refusing without --confirm: resubscribing sends mail to someone who opted out."
9220
9250
  );
9221
9251
  }
9222
- const result = await unsuppress(ctx, a.req("email"));
9223
- out(result);
9252
+ const result = await unsuppress(ctx, a.required("email"));
9253
+ printJson(result);
9224
9254
  if (result?.platformSuppression) {
9225
9255
  const { reason, at } = result.platformSuppression;
9226
9256
  console.error(
9227
9257
  `
9228
- Note: removed from this app's list, but ${a.req("email")} is still on the ACCOUNT-wide suppression list (${reason}${at ? ` since ${at}` : ""}). Mail to it will still be blocked \u2014 that list is shared by every app and is not cleared.`
9258
+ Note: removed from this app's list, but ${a.required("email")} is still on the ACCOUNT-wide suppression list (${reason}${at ? ` since ${at}` : ""}). Mail to it will still be blocked \u2014 that list is shared by every app and is not cleared.`
9229
9259
  );
9230
9260
  } else if (result?.tenantEntryRemoved) {
9231
9261
  console.error(
9232
9262
  `
9233
- Note: also cleared this app's provider-side bounce/complaint record for ${a.req("email")}. Mail will be attempted again \u2014 another hard bounce re-suppresses it automatically.`
9263
+ Note: also cleared this app's provider-side bounce/complaint record for ${a.required("email")}. Mail will be attempted again \u2014 another hard bounce re-suppresses it automatically.`
9234
9264
  );
9235
9265
  }
9236
9266
  }
9237
9267
  async function emailInbox(ctx, a) {
9238
- out(
9268
+ printJson(
9239
9269
  await inbox(ctx, {
9240
9270
  status: a.str("status"),
9241
9271
  search: a.str("search"),
@@ -9248,19 +9278,19 @@ async function emailInbox(ctx, a) {
9248
9278
  }
9249
9279
  var domainCommands = (direction) => ({
9250
9280
  list: async (ctx) => {
9251
- out(await listDomains(ctx, direction));
9281
+ printJson(await listDomains(ctx, direction));
9252
9282
  },
9253
9283
  check: async (ctx, a) => {
9254
- out(await checkDomain(ctx, direction, a.req("domain")));
9284
+ printJson(await checkDomain(ctx, direction, a.required("domain")));
9255
9285
  },
9256
9286
  add: async (ctx, a) => {
9257
- out(await addDomain(ctx, direction, a.req("domain")));
9287
+ printJson(await addDomain(ctx, direction, a.required("domain")));
9258
9288
  },
9259
9289
  verify: async (ctx, a) => {
9260
- out(await verifyDomain(ctx, direction, a.req("domain")));
9290
+ printJson(await verifyDomain(ctx, direction, a.required("domain")));
9261
9291
  },
9262
9292
  remove: async (ctx, a) => {
9263
- out(await removeDomain(ctx, direction, a.req("domain")));
9293
+ printJson(await removeDomain(ctx, direction, a.required("domain")));
9264
9294
  }
9265
9295
  });
9266
9296
  var sendingDomains = domainCommands("sending");
@@ -9381,7 +9411,7 @@ function run2(ctx, route) {
9381
9411
  return call(
9382
9412
  ctx,
9383
9413
  "POST",
9384
- `/_internal/v2/apps/${ctx.appId}/cron/${seg(route)}/run`
9414
+ `/_internal/v2/apps/${ctx.appId}/cron/${encodePathSegment(route)}/run`
9385
9415
  );
9386
9416
  }
9387
9417
 
@@ -9399,10 +9429,10 @@ var cronSpecs = {
9399
9429
  }
9400
9430
  };
9401
9431
  async function cronList(ctx, a) {
9402
- out(await list15(ctx, { runs: a.num("runs") }));
9432
+ printJson(await list15(ctx, { runs: a.num("runs") }));
9403
9433
  }
9404
9434
  async function cronRun(ctx, a) {
9405
- out(await run2(ctx, a.req("route")));
9435
+ printJson(await run2(ctx, a.required("route")));
9406
9436
  }
9407
9437
  var cronHandlers = {
9408
9438
  "cron list": cronList,
@@ -9460,8 +9490,8 @@ var feedbackSpecs = {
9460
9490
  };
9461
9491
  async function feedbackDraft(ctx, a) {
9462
9492
  const flag = a.str("message");
9463
- const message = flag === "-" ? fs7.readFileSync(0, "utf-8") : flag ?? a.req("message");
9464
- out(await draft(ctx, message));
9493
+ const message = flag === "-" ? fs7.readFileSync(0, "utf-8") : flag ?? a.required("message");
9494
+ printJson(await draft(ctx, message));
9465
9495
  }
9466
9496
  var feedbackHandlers = {
9467
9497
  "feedback draft": feedbackDraft
@@ -9598,7 +9628,7 @@ async function waitForPhase(ctx, params) {
9598
9628
  return {
9599
9629
  status: "timeout",
9600
9630
  resource,
9601
- error: timedOut(timeoutMs, `; resource is still ${resource.phase}`)
9631
+ error: timeoutMessage(timeoutMs, `; resource is still ${resource.phase}`)
9602
9632
  };
9603
9633
  }
9604
9634
  if (arrived(resource)) {
@@ -9683,27 +9713,28 @@ async function waitAndReport2(ctx, a, id, phases, summary4, until) {
9683
9713
  ...timeoutSec ? { timeoutMs: Number(timeoutSec) * 1e3 } : {},
9684
9714
  onProgress: progress
9685
9715
  });
9686
- out({ ...summary4, ...result });
9716
+ printJson({ ...summary4, ...result });
9687
9717
  if (result.status === "failed") {
9688
- throw new CliError(result.error, EXIT.buildFailed);
9689
- }
9690
- if (result.status === "timeout") {
9691
- throw new CliError(result.error, EXIT.timeout);
9718
+ process.exitCode = EXIT.buildFailed;
9719
+ } else if (result.status === "timeout") {
9720
+ process.exitCode = EXIT.timeout;
9692
9721
  }
9693
9722
  }
9694
9723
  async function infraList(ctx, a) {
9695
- out(await list16(ctx, { includeDestroyed: a.bool("include-destroyed") }));
9724
+ printJson(
9725
+ await list16(ctx, { includeDestroyed: a.bool("include-destroyed") })
9726
+ );
9696
9727
  }
9697
9728
  async function infraGet(ctx, a) {
9698
- out(await get11(ctx, { id: a.req("id") }));
9729
+ printJson(await get11(ctx, { id: a.required("id") }));
9699
9730
  }
9700
9731
  var FOLLOW_POLL_MS = 4e3;
9701
9732
  async function infraLogs(ctx, a) {
9702
- const id = a.req("id");
9733
+ const id = a.required("id");
9703
9734
  const limitRaw = a.str("limit");
9704
9735
  const limit = limitRaw ? Number(limitRaw) : void 0;
9705
9736
  let { logs: logs2 } = await logs(ctx, { id, ...limit ? { limit } : {} });
9706
- out({ logs: logs2 });
9737
+ printJson({ logs: logs2 });
9707
9738
  if (!a.bool("follow")) {
9708
9739
  return;
9709
9740
  }
@@ -9716,7 +9747,7 @@ async function infraLogs(ctx, a) {
9716
9747
  limit: 500
9717
9748
  }));
9718
9749
  if (logs2.length > 0) {
9719
- out({ logs: logs2 });
9750
+ printJson({ logs: logs2 });
9720
9751
  after = logs2[logs2.length - 1].id;
9721
9752
  }
9722
9753
  }
@@ -9742,7 +9773,7 @@ async function infraProvision(ctx, a) {
9742
9773
  });
9743
9774
  const pricing = pricingOf(resource);
9744
9775
  if (!a.bool("wait")) {
9745
- out({
9776
+ printJson({
9746
9777
  resource,
9747
9778
  pricing,
9748
9779
  note: "Provisioning; poll `infra get <id>` or re-run with --wait."
@@ -9755,42 +9786,42 @@ async function infraProvision(ctx, a) {
9755
9786
  });
9756
9787
  }
9757
9788
  async function infraHibernate(ctx, a) {
9758
- const id = a.req("id");
9789
+ const id = a.required("id");
9759
9790
  const { resource } = await hibernate(ctx, { id });
9760
9791
  if (!a.bool("wait")) {
9761
- out({ resource });
9792
+ printJson({ resource });
9762
9793
  return;
9763
9794
  }
9764
9795
  await waitAndReport2(ctx, a, id, ["hibernated"], { action: "hibernate" });
9765
9796
  }
9766
9797
  async function infraResume(ctx, a) {
9767
- const id = a.req("id");
9798
+ const id = a.required("id");
9768
9799
  const { resource } = await resume2(ctx, { id });
9769
9800
  if (!a.bool("wait")) {
9770
- out({ resource });
9801
+ printJson({ resource });
9771
9802
  return;
9772
9803
  }
9773
9804
  await waitAndReport2(ctx, a, id, ["active"], { action: "resume" });
9774
9805
  }
9775
9806
  async function infraDestroy(ctx, a) {
9776
- const id = a.req("id");
9807
+ const id = a.required("id");
9777
9808
  const { resource } = await destroy(ctx, { id });
9778
9809
  if (!a.bool("wait")) {
9779
- out({ resource });
9810
+ printJson({ resource });
9780
9811
  return;
9781
9812
  }
9782
9813
  await waitAndReport2(ctx, a, id, ["destroyed"], { action: "destroy" });
9783
9814
  }
9784
9815
  async function infraRename(ctx, a) {
9785
- out(
9816
+ printJson(
9786
9817
  await rename(ctx, {
9787
- id: a.req("id"),
9818
+ id: a.required("id"),
9788
9819
  name: a.str("name")
9789
9820
  })
9790
9821
  );
9791
9822
  }
9792
9823
  async function infraResize(ctx, a) {
9793
- const id = a.req("id");
9824
+ const id = a.required("id");
9794
9825
  const { resource } = await resize(ctx, {
9795
9826
  id,
9796
9827
  offeringId: a.str("offering")
@@ -9800,10 +9831,10 @@ async function infraResize(ctx, a) {
9800
9831
  offering: resource.resizingTo ?? resource.offering
9801
9832
  });
9802
9833
  if (!a.bool("wait")) {
9803
- out({
9834
+ printJson({
9804
9835
  resource,
9805
9836
  pricing,
9806
- note: "Resizing; searches on its sources pause while it is parked and restored. Poll `infra get <id>` or re-run with --wait."
9837
+ note: `Resizing; ${resource.kind === "database" ? "the app's queries pause" : "searches on its sources pause"} while it is parked and restored. Poll \`infra get <id>\` or re-run with --wait.`
9807
9838
  });
9808
9839
  return;
9809
9840
  }
@@ -9829,9 +9860,11 @@ var infraHandlers = {
9829
9860
  };
9830
9861
  var infraHelp = `remy-admin infra \u2014 Dedicated infrastructure your app leases from the platform.
9831
9862
 
9832
- Today the one kind is dedicated retrieval: the app's own vector-store capacity
9833
- for data sources, isolated from the shared pool. Sizes and prices come from the
9834
- platform catalog (\`infra list\` prints them); nothing is priced client-side.
9863
+ Two kinds, each isolated from the shared pool: \`retrieval\`, the app's own
9864
+ vector-store capacity for data sources, and \`database\`, a database server of
9865
+ the app's own for databases past the shared pool's limit. Sizes and prices come
9866
+ from the platform catalog (\`infra list\` prints them, by kind); nothing is
9867
+ priced client-side.
9835
9868
 
9836
9869
  A resource bills by the clock hour at the active rate for every hour it is
9837
9870
  active in, including the hour a resume lands in, and costs nothing while
@@ -9843,13 +9876,15 @@ audited.
9843
9876
 
9844
9877
  Subcommands:
9845
9878
  list Resources on this app, plus the offerings you can provision
9846
- get One resource: billing to date, state timeline, recent log, attached sources
9879
+ get One resource: billing to date, state timeline, recent log, what it holds
9847
9880
  logs The platform's log for a resource (--follow to keep reading)
9848
- provision Lease a new resource (needs a month's credits; prints the price)
9849
- hibernate Park it: data kept, searches paused, compute charge stops
9881
+ provision Lease a new resource (needs a month's credits; prints the price;
9882
+ one database server an app)
9883
+ hibernate Park it: data kept, its searches or queries paused, the charge stops
9850
9884
  resume Bring a hibernated resource back (needs a month's credits)
9851
9885
  resize Change its size, data intact (passes through hibernated)
9852
- destroy Delete it (refused while data sources are placed on it)
9886
+ destroy Delete it (retrieval: refused while data sources are placed on it;
9887
+ database: while a database is too large for the shared pool)
9853
9888
  rename Change the display name
9854
9889
 
9855
9890
  Usage:
@@ -9884,8 +9919,36 @@ Placing a data source on a resource:
9884
9919
  progress. The messages are written for the app's end user; the stable code
9885
9920
  is what to act on.
9886
9921
 
9922
+ Dedicated databases:
9923
+ A database server takes the app's live databases as it first becomes active,
9924
+ each one let go by the shared pool and served there from then on, under the
9925
+ size's own limit (\`maxDatabaseGiB\` on the offering) in place of the shared
9926
+ pool's. A release the app deploys keeps its databases there. Nothing in the
9927
+ app changes: the same queries, routed to it by the platform. An app has one:
9928
+ a second is refused with database_server_exists (422); resize the one it has.
9929
+
9930
+ Its databases live on the server's own disk and are backed up hourly when
9931
+ they've changed, so \`databases\` on \`infra get\` shows each one's size against
9932
+ its limit, whether it has writes its backup hasn't had (dirty) and when it
9933
+ was last backed up. Sizes read from elsewhere (the dashboard, metering) can
9934
+ run up to an hour behind it; an export or a database download backs up
9935
+ first.
9936
+
9937
+ Parking backs up every database and drops the server's disk, so a parked
9938
+ server costs nothing; queries answer database_lease_parked (503) until it
9939
+ resumes, and a resume downloads each database again. Destroying hands the
9940
+ databases back to the shared pool, so it's refused with
9941
+ resource_holds_large_databases while any is too large for the pool to take
9942
+ back. The check reads each database's file, which deleting rows doesn't
9943
+ shrink, and its backup: delete rows, compact with \`db query\` (VACUUM),
9944
+ then destroy after its next hourly backup, or keep the server.
9945
+
9887
9946
  Resizing:
9888
- A resize keeps the documents: the resource is parked, its spec is swapped,
9947
+ A database server's resize parks it, every database backed up, and resumes it
9948
+ at the new size; shrinking is refused below its largest database's file
9949
+ (resize_too_small), which deleting rows doesn't shrink.
9950
+
9951
+ A retrieval resize keeps the documents: the resource is parked, its spec is swapped,
9889
9952
  and it comes back up with its sources' indexes rebuilt from durable storage
9890
9953
  in the background (nothing is re-embedded). Searches on those sources answer
9891
9954
  index_warming until the rebuild lands. A hibernated resource swaps in place
@@ -9897,8 +9960,9 @@ Phases and timing:
9897
9960
  requested \u2192 provisioning \u2192 active \u21C4 hibernated \u2192 destroyed, with hibernating /
9898
9961
  resuming / decommissioning in between and failed when a change cannot complete
9899
9962
  (retried automatically; resume or hibernate to retry by hand). A transition
9900
- takes a minute or two; the rebuild that follows a resume runs under its own
9901
- progress with a measured ETA. --wait gives up only after --timeout (default
9963
+ takes a minute or two, but a database server's park backs up every database
9964
+ first, which for a large one takes minutes; the rebuild that follows a
9965
+ retrieval resume runs under its own progress with a measured ETA. --wait gives up only after --timeout (default
9902
9966
  600s) WITHOUT movement, so a long rebuild is waited out while it moves.
9903
9967
 
9904
9968
  Billing and the log:
@@ -10091,7 +10155,7 @@ var qaRecordingsSpecs = {
10091
10155
  }
10092
10156
  };
10093
10157
  async function qaRecordingsLs(ctx, a) {
10094
- out(
10158
+ printJson(
10095
10159
  await ls2(ctx, {
10096
10160
  sessionId: a.str("session"),
10097
10161
  cursor: a.str("cursor"),
@@ -10122,7 +10186,7 @@ async function qaRecordingsExport(ctx, a) {
10122
10186
  if (result.status !== "completed") {
10123
10187
  fatal(result.error ?? `Export ${result.status}.`);
10124
10188
  }
10125
- out(result);
10189
+ printJson(result);
10126
10190
  }
10127
10191
  var qaRecordingsHandlers = {
10128
10192
  "qa-recordings ls": qaRecordingsLs,
@@ -10282,7 +10346,7 @@ import path7 from "node:path";
10282
10346
 
10283
10347
  // src/parseJsonConfig.ts
10284
10348
  import JSON5 from "json5";
10285
- function msg(err) {
10349
+ function errorMessage(err) {
10286
10350
  return err instanceof Error ? err.message : String(err);
10287
10351
  }
10288
10352
  function parseJsonConfig(raw) {
@@ -10290,7 +10354,7 @@ function parseJsonConfig(raw) {
10290
10354
  try {
10291
10355
  return { ok: true, value: JSON.parse(raw), repaired: false };
10292
10356
  } catch (err) {
10293
- strictError = msg(err);
10357
+ strictError = errorMessage(err);
10294
10358
  }
10295
10359
  try {
10296
10360
  return {
@@ -10300,7 +10364,7 @@ function parseJsonConfig(raw) {
10300
10364
  error: strictError
10301
10365
  };
10302
10366
  } catch (err) {
10303
- return { ok: false, error: msg(err), notFound: false };
10367
+ return { ok: false, error: errorMessage(err), notFound: false };
10304
10368
  }
10305
10369
  }
10306
10370
 
@@ -10360,7 +10424,7 @@ Commands:
10360
10424
  email Email \u2014 delivery log, blast stats, unsubscribes, inbox, custom domains
10361
10425
  cron Scheduled jobs \u2014 schedules, run history, manual trigger
10362
10426
  feedback Tell the Remy team about a problem or gap in Remy, for the user to review and send
10363
- infra Dedicated infrastructure \u2014 provision, hibernate, resize + destroy retrieval capacity
10427
+ infra Dedicated infrastructure \u2014 provision, hibernate, resize + destroy retrieval and database servers
10364
10428
  qa-recordings Browser-QA session replays \u2014 list them, render one as an mp4
10365
10429
 
10366
10430
  Run 'remy-admin <command> --help' for details on each command.
@@ -10379,7 +10443,8 @@ allow. analytics.view, usage.view, requests.view (requests, crashes),
10379
10443
  agent.view, tasks.view, voice.view|manage, users.view|manage (live runs only),
10380
10444
  settings.manage, email.view|manage, domains.manage (custom domains, the
10381
10445
  subdomain), issues.view|manage, datasources.manage, cron.view|manage,
10382
- releases.view. A .manage includes its .view. A call the method doesn't hold is
10446
+ releases.view, infra.view (infra list, get, logs). A .manage includes its
10447
+ .view. A call the method doesn't hold is
10383
10448
  admin_permission_required:<name>; another app is app_credential_wrong_app and
10384
10449
  needs a key. The full list and rules are createAdminClient's docs.`;
10385
10450
  var GROUPS = [
@@ -10547,6 +10612,6 @@ async function main() {
10547
10612
  return HANDLERS[route.key](ctx, a);
10548
10613
  }
10549
10614
  main().catch((err) => {
10550
- out({ error: err?.message ?? String(err) });
10615
+ printJson({ error: err?.message ?? String(err) });
10551
10616
  process.exitCode = err instanceof CliError ? err.code : EXIT.generic;
10552
10617
  });