@fedify/cli 2.1.1 → 2.1.2

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/lookup.js CHANGED
@@ -1,24 +1,21 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { configContext } from "./config.js";
5
- import { getContextLoader, getDocumentLoader } from "./docloader.js";
3
+ import { getContextLoader, getDocumentLoader as getDocumentLoader$1 } from "./docloader.js";
6
4
  import { configureLogging } from "./log.js";
7
5
  import { createTunnelServiceOption, userAgentOption } from "./options.js";
8
6
  import { spawnTemporaryServer } from "./tempserver.js";
9
7
  import { colorEnabled, colors, formatObject } from "./utils.js";
10
8
  import { renderImages } from "./imagerenderer.js";
11
- import process from "node:process";
12
9
  import { argument, choice, command, constant, flag, float, integer, map, merge, message, multiple, object, option, optionNames, optional, or, string, withDefault } from "@optique/core";
13
10
  import { path, printError } from "@optique/run";
14
11
  import { createWriteStream } from "node:fs";
12
+ import process from "node:process";
15
13
  import { bindConfig } from "@optique/config";
16
14
  import { generateCryptoKeyPair, getAuthenticatedDocumentLoader, respondWithObject } from "@fedify/fedify";
17
15
  import { Application, Collection, CryptographicKey, Object as Object$1, lookupObject, traverseCollection } from "@fedify/vocab";
18
16
  import { getLogger } from "@logtape/logtape";
19
17
  import ora from "ora";
20
18
  import { UrlError } from "@fedify/vocab-runtime";
21
-
22
19
  //#region src/lookup.ts
23
20
  const logger = getLogger([
24
21
  "fedify",
@@ -130,8 +127,8 @@ The arguments can be either URLs or actor handles (e.g., ${"@username@domain"}),
130
127
  });
131
128
  var TimeoutError = class extends Error {
132
129
  name = "TimeoutError";
133
- constructor(message$1) {
134
- super(message$1);
130
+ constructor(message) {
131
+ super(message);
135
132
  this.name = "TimeoutError";
136
133
  }
137
134
  };
@@ -192,36 +189,34 @@ async function findAllImages(obj) {
192
189
  if (image && image.url instanceof URL) result.push(image.url);
193
190
  return result;
194
191
  }
195
- async function writeObjectToStream(object$1, outputPath, format, contextLoader, stream) {
192
+ async function writeObjectToStream(object, outputPath, format, contextLoader, stream) {
196
193
  const localStream = stream ?? (outputPath ? createWriteStream(outputPath) : process.stdout);
197
194
  const localFileStream = stream == null && outputPath != null ? localStream : void 0;
198
195
  let content;
199
196
  let json = true;
200
197
  let imageUrls = [];
201
- if (format) if (format === "raw") content = await object$1.toJsonLd({ contextLoader });
202
- else if (format === "compact") content = await object$1.toJsonLd({
198
+ if (format) if (format === "raw") content = await object.toJsonLd({ contextLoader });
199
+ else if (format === "compact") content = await object.toJsonLd({
203
200
  format: "compact",
204
201
  contextLoader
205
202
  });
206
- else if (format === "expand") content = await object$1.toJsonLd({
203
+ else if (format === "expand") content = await object.toJsonLd({
207
204
  format: "expand",
208
205
  contextLoader
209
206
  });
210
207
  else {
211
- content = object$1;
208
+ content = object;
212
209
  json = false;
213
210
  }
214
211
  else {
215
- content = object$1;
212
+ content = object;
216
213
  json = false;
217
214
  }
218
215
  const enableColors = colorEnabled && localStream === process.stdout;
219
216
  content = formatObject(content, enableColors, json);
220
- const encoder = new TextEncoder();
221
- const bytes = encoder.encode(content + "\n");
222
- await writeToStream(localStream, bytes);
217
+ await writeToStream(localStream, new TextEncoder().encode(content + "\n"));
223
218
  if (localFileStream != null) await endWritableStream(localFileStream);
224
- if (object$1 instanceof Object$1) imageUrls = await findAllImages(object$1);
219
+ if (object instanceof Object$1) imageUrls = await findAllImages(object);
225
220
  if (localStream === process.stdout && imageUrls.length > 0) await renderImages(imageUrls);
226
221
  }
227
222
  async function closeWriteStream(stream) {
@@ -281,8 +276,7 @@ function handleTimeoutError(spinner, timeoutSeconds, url) {
281
276
  printError(message`Try increasing the timeout with -T/--timeout option or check network connectivity.`);
282
277
  }
283
278
  function isPrivateAddressError(error) {
284
- const errorMessage = error instanceof Error ? error.message : String(error);
285
- const lowerMessage = errorMessage.toLowerCase();
279
+ const lowerMessage = (error instanceof Error ? error.message : String(error)).toLowerCase();
286
280
  if (error instanceof UrlError) return lowerMessage.includes("invalid or private address") || lowerMessage.includes("localhost is not allowed");
287
281
  return lowerMessage.includes("private address") || lowerMessage.includes("private ip") || lowerMessage.includes("localhost") || lowerMessage.includes("loopback");
288
282
  }
@@ -314,15 +308,15 @@ function printLookupFailureHint(authLoader, error, options = {}) {
314
308
  /**
315
309
  * Gets the next recursion target URL from an ActivityPub object.
316
310
  */
317
- function getRecursiveTargetId(object$1, recurseProperty) {
311
+ function getRecursiveTargetId(object, recurseProperty) {
318
312
  switch (recurseProperty) {
319
313
  case "replyTarget":
320
- case IN_REPLY_TO_IRI: return object$1.replyTargetId;
314
+ case IN_REPLY_TO_IRI: return object.replyTargetId;
321
315
  case "quoteUrl":
322
316
  case QUOTE_URL_IRI:
323
317
  case MISSKEY_QUOTE_IRI:
324
318
  case FEDIBIRD_QUOTE_IRI: {
325
- const quoteUrl = object$1.quoteUrl;
319
+ const quoteUrl = object.quoteUrl;
326
320
  return quoteUrl instanceof URL ? quoteUrl : null;
327
321
  }
328
322
  default: return null;
@@ -368,41 +362,39 @@ async function collectRecursiveObjects(initialObject, recurseProperty, recurseDe
368
362
  }
369
363
  return results;
370
364
  }
371
- async function runLookup(command$1, deps = {}) {
365
+ async function runLookup(command, deps = {}) {
372
366
  const effectiveDeps = {
373
367
  lookupObject,
374
368
  traverseCollection,
375
369
  exit: (code) => process.exit(code),
376
370
  ...deps
377
371
  };
378
- if (command$1.urls.length < 1) {
372
+ if (command.urls.length < 1) {
379
373
  printError(message`At least one URL or actor handle must be provided.`);
380
374
  effectiveDeps.exit(1);
381
375
  }
382
- if (command$1.debug) await configureLogging();
376
+ if (command.debug) await configureLogging();
383
377
  const spinner = ora({
384
- text: `Looking up the ${command$1.recurse != null ? "object chain" : command$1.traverse ? "collection" : command$1.urls.length > 1 ? "objects" : "object"}...`,
378
+ text: `Looking up the ${command.recurse != null ? "object chain" : command.traverse ? "collection" : command.urls.length > 1 ? "objects" : "object"}...`,
385
379
  discardStdin: false
386
380
  }).start();
387
381
  let server = void 0;
388
- const baseDocumentLoader = await getDocumentLoader({
389
- userAgent: command$1.userAgent,
390
- allowPrivateAddress: command$1.allowPrivateAddress
391
- });
392
- const documentLoader = wrapDocumentLoaderWithTimeout(baseDocumentLoader, command$1.timeout);
393
- const baseContextLoader = await getContextLoader({
394
- userAgent: command$1.userAgent,
395
- allowPrivateAddress: command$1.allowPrivateAddress
396
- });
397
- const contextLoader = wrapDocumentLoaderWithTimeout(baseContextLoader, command$1.timeout);
382
+ const documentLoader = wrapDocumentLoaderWithTimeout(await getDocumentLoader$1({
383
+ userAgent: command.userAgent,
384
+ allowPrivateAddress: command.allowPrivateAddress
385
+ }), command.timeout);
386
+ const contextLoader = wrapDocumentLoaderWithTimeout(await getContextLoader({
387
+ userAgent: command.userAgent,
388
+ allowPrivateAddress: command.allowPrivateAddress
389
+ }), command.timeout);
398
390
  let authLoader = void 0;
399
391
  let authIdentity = void 0;
400
392
  let outputStream;
401
393
  let outputStreamError;
402
394
  const getOutputStream = () => {
403
- if (command$1.output == null) return void 0;
395
+ if (command.output == null) return void 0;
404
396
  if (outputStream == null) {
405
- outputStream = createWriteStream(command$1.output);
397
+ outputStream = createWriteStream(command.output);
406
398
  outputStream.once("error", (error) => {
407
399
  outputStreamError = error;
408
400
  });
@@ -426,7 +418,7 @@ async function runLookup(command$1, deps = {}) {
426
418
  }
427
419
  effectiveDeps.exit(cleanupFailed && code === 0 ? 1 : code);
428
420
  };
429
- if (command$1.authorizedFetch) {
421
+ if (command.authorizedFetch) {
430
422
  spinner.text = "Generating a one-time key pair...";
431
423
  const key = await generateCryptoKeyPair();
432
424
  spinner.text = "Spinning up a temporary ActivityPub server...";
@@ -456,62 +448,59 @@ async function runLookup(command$1, deps = {}) {
456
448
  inbox: new URL("/inbox", serverUrl),
457
449
  outbox: new URL("/outbox", serverUrl)
458
450
  }), { contextLoader });
459
- }, { service: command$1.tunnelService });
451
+ }, { service: command.tunnelService });
460
452
  authIdentity = {
461
453
  keyId: new URL("#main-key", server.url),
462
454
  privateKey: key.privateKey
463
455
  };
464
- const baseAuthLoader = getAuthenticatedDocumentLoader(authIdentity, {
465
- allowPrivateAddress: command$1.allowPrivateAddress,
466
- userAgent: command$1.userAgent,
456
+ authLoader = wrapDocumentLoaderWithTimeout(getAuthenticatedDocumentLoader(authIdentity, {
457
+ allowPrivateAddress: command.allowPrivateAddress,
458
+ userAgent: command.userAgent,
467
459
  specDeterminer: {
468
460
  determineSpec() {
469
- return command$1.firstKnock;
461
+ return command.firstKnock;
470
462
  },
471
463
  rememberSpec() {}
472
464
  }
473
- });
474
- authLoader = wrapDocumentLoaderWithTimeout(baseAuthLoader, command$1.timeout);
465
+ }), command.timeout);
475
466
  }
476
- spinner.text = `Looking up the ${command$1.recurse != null ? "object chain" : command$1.traverse ? "collection" : command$1.urls.length > 1 ? "objects" : "object"}...`;
477
- if (command$1.recurse != null) {
478
- const recursiveBaseDocumentLoader = await getDocumentLoader({
479
- userAgent: command$1.userAgent,
467
+ spinner.text = `Looking up the ${command.recurse != null ? "object chain" : command.traverse ? "collection" : command.urls.length > 1 ? "objects" : "object"}...`;
468
+ if (command.recurse != null) {
469
+ const recursiveDocumentLoader = wrapDocumentLoaderWithTimeout(await getDocumentLoader$1({
470
+ userAgent: command.userAgent,
480
471
  allowPrivateAddress: false
481
- });
482
- const recursiveDocumentLoader = wrapDocumentLoaderWithTimeout(recursiveBaseDocumentLoader, command$1.timeout);
483
- const recursiveBaseContextLoader = await getContextLoader({
484
- userAgent: command$1.userAgent,
472
+ }), command.timeout);
473
+ const recursiveContextLoader = wrapDocumentLoaderWithTimeout(await getContextLoader({
474
+ userAgent: command.userAgent,
485
475
  allowPrivateAddress: false
486
- });
487
- const recursiveContextLoader = wrapDocumentLoaderWithTimeout(recursiveBaseContextLoader, command$1.timeout);
488
- const recursiveAuthLoader = command$1.authorizedFetch && authIdentity != null ? wrapDocumentLoaderWithTimeout(getAuthenticatedDocumentLoader(authIdentity, {
476
+ }), command.timeout);
477
+ const recursiveAuthLoader = command.authorizedFetch && authIdentity != null ? wrapDocumentLoaderWithTimeout(getAuthenticatedDocumentLoader(authIdentity, {
489
478
  allowPrivateAddress: false,
490
- userAgent: command$1.userAgent,
479
+ userAgent: command.userAgent,
491
480
  specDeterminer: {
492
481
  determineSpec() {
493
- return command$1.firstKnock;
482
+ return command.firstKnock;
494
483
  },
495
484
  rememberSpec() {}
496
485
  }
497
- }), command$1.timeout) : void 0;
486
+ }), command.timeout) : void 0;
498
487
  const initialLookupDocumentLoader = authLoader ?? documentLoader;
499
488
  const recursiveLookupDocumentLoader = recursiveAuthLoader ?? recursiveDocumentLoader;
500
489
  let totalObjects = 0;
501
- const recurseDepth = command$1.recurseDepth;
502
- for (let urlIndex = 0; urlIndex < command$1.urls.length; urlIndex++) {
490
+ const recurseDepth = command.recurseDepth;
491
+ for (let urlIndex = 0; urlIndex < command.urls.length; urlIndex++) {
503
492
  const visited = /* @__PURE__ */ new Set();
504
- const url = command$1.urls[urlIndex];
505
- if (urlIndex > 0) spinner.text = `Looking up object chain ${urlIndex + 1}/${command$1.urls.length}...`;
493
+ const url = command.urls[urlIndex];
494
+ if (urlIndex > 0) spinner.text = `Looking up object chain ${urlIndex + 1}/${command.urls.length}...`;
506
495
  let current = null;
507
496
  try {
508
497
  current = await effectiveDeps.lookupObject(url, {
509
498
  documentLoader: initialLookupDocumentLoader,
510
499
  contextLoader,
511
- userAgent: command$1.userAgent
500
+ userAgent: command.userAgent
512
501
  });
513
502
  } catch (error) {
514
- if (error instanceof TimeoutError) handleTimeoutError(spinner, command$1.timeout, url);
503
+ if (error instanceof TimeoutError) handleTimeoutError(spinner, command.timeout, url);
515
504
  else {
516
505
  spinner.fail(`Failed to fetch object: ${colors.red(url)}.`);
517
506
  printLookupFailureHint(authLoader, error);
@@ -527,9 +516,9 @@ async function runLookup(command$1, deps = {}) {
527
516
  }
528
517
  visited.add(url);
529
518
  if (current.id != null) visited.add(current.id.href);
530
- if (!command$1.reverse) try {
531
- if (totalObjects > 0) await writeSeparator(command$1.separator, getOutputStream());
532
- await writeObjectToStream(current, command$1.output, command$1.format, contextLoader, getOutputStream());
519
+ if (!command.reverse) try {
520
+ if (totalObjects > 0) await writeSeparator(command.separator, getOutputStream());
521
+ await writeObjectToStream(current, command.output, command.format, contextLoader, getOutputStream());
533
522
  totalObjects++;
534
523
  } catch (error) {
535
524
  logger.error("Failed to write lookup output: {error}", { error });
@@ -539,18 +528,18 @@ async function runLookup(command$1, deps = {}) {
539
528
  }
540
529
  let chain = [];
541
530
  try {
542
- chain = await collectRecursiveObjects(current, command$1.recurse, recurseDepth, (target) => effectiveDeps.lookupObject(target, {
531
+ chain = await collectRecursiveObjects(current, command.recurse, recurseDepth, (target) => effectiveDeps.lookupObject(target, {
543
532
  documentLoader: recursiveLookupDocumentLoader,
544
533
  contextLoader: recursiveContextLoader,
545
- userAgent: command$1.userAgent
534
+ userAgent: command.userAgent
546
535
  }), {
547
- suppressErrors: command$1.suppressErrors,
536
+ suppressErrors: command.suppressErrors,
548
537
  visited
549
538
  });
550
539
  } catch (error) {
551
- if (command$1.reverse) try {
552
- if (totalObjects > 0) await writeSeparator(command$1.separator, getOutputStream());
553
- await writeObjectToStream(current, command$1.output, command$1.format, contextLoader, getOutputStream());
540
+ if (command.reverse) try {
541
+ if (totalObjects > 0) await writeSeparator(command.separator, getOutputStream());
542
+ await writeObjectToStream(current, command.output, command.format, contextLoader, getOutputStream());
554
543
  totalObjects++;
555
544
  } catch (writeError) {
556
545
  logger.error("Failed to write lookup output: {error}", { error: writeError });
@@ -559,7 +548,7 @@ async function runLookup(command$1, deps = {}) {
559
548
  return;
560
549
  }
561
550
  logger.error("Failed to recursively fetch an object in chain: {error}", { error });
562
- if (error instanceof TimeoutError) handleTimeoutError(spinner, command$1.timeout);
551
+ if (error instanceof TimeoutError) handleTimeoutError(spinner, command.timeout);
563
552
  else if (error instanceof RecursiveLookupError) {
564
553
  spinner.fail(`Failed to recursively fetch object: ${colors.red(error.target)}.`);
565
554
  if (authLoader == null) printError(message`It may be a private object. Try with -a/--authorized-fetch.`);
@@ -572,7 +561,7 @@ async function runLookup(command$1, deps = {}) {
572
561
  await finalizeAndExit(1);
573
562
  return;
574
563
  }
575
- if (command$1.reverse) {
564
+ if (command.reverse) {
576
565
  const chainEntries = [{
577
566
  object: current,
578
567
  objectContextLoader: contextLoader
@@ -583,8 +572,8 @@ async function runLookup(command$1, deps = {}) {
583
572
  for (let chainIndex = chainEntries.length - 1; chainIndex >= 0; chainIndex--) {
584
573
  const entry = chainEntries[chainIndex];
585
574
  try {
586
- if (totalObjects > 0 || chainIndex < chainEntries.length - 1) await writeSeparator(command$1.separator, getOutputStream());
587
- await writeObjectToStream(entry.object, command$1.output, command$1.format, entry.objectContextLoader, getOutputStream());
575
+ if (totalObjects > 0 || chainIndex < chainEntries.length - 1) await writeSeparator(command.separator, getOutputStream());
576
+ await writeObjectToStream(entry.object, command.output, command.format, entry.objectContextLoader, getOutputStream());
588
577
  totalObjects++;
589
578
  } catch (error) {
590
579
  logger.error("Failed to write lookup output: {error}", { error });
@@ -601,8 +590,8 @@ async function runLookup(command$1, deps = {}) {
601
590
  for (let chainIndex = 0; chainIndex < chainEntries.length; chainIndex++) {
602
591
  const entry = chainEntries[chainIndex];
603
592
  try {
604
- if (totalObjects > 0 || chainIndex > 0) await writeSeparator(command$1.separator, getOutputStream());
605
- await writeObjectToStream(entry.object, command$1.output, command$1.format, entry.objectContextLoader, getOutputStream());
593
+ if (totalObjects > 0 || chainIndex > 0) await writeSeparator(command.separator, getOutputStream());
594
+ await writeObjectToStream(entry.object, command.output, command.format, entry.objectContextLoader, getOutputStream());
606
595
  totalObjects++;
607
596
  } catch (error) {
608
597
  logger.error("Failed to write lookup output: {error}", { error });
@@ -617,20 +606,20 @@ async function runLookup(command$1, deps = {}) {
617
606
  await finalizeAndExit(0);
618
607
  return;
619
608
  }
620
- if (command$1.traverse) {
609
+ if (command.traverse) {
621
610
  let totalItems = 0;
622
- for (let urlIndex = 0; urlIndex < command$1.urls.length; urlIndex++) {
623
- const url = command$1.urls[urlIndex];
624
- if (urlIndex > 0) spinner.text = `Looking up collection ${urlIndex + 1}/${command$1.urls.length}...`;
611
+ for (let urlIndex = 0; urlIndex < command.urls.length; urlIndex++) {
612
+ const url = command.urls[urlIndex];
613
+ if (urlIndex > 0) spinner.text = `Looking up collection ${urlIndex + 1}/${command.urls.length}...`;
625
614
  let collection = null;
626
615
  try {
627
616
  collection = await effectiveDeps.lookupObject(url, {
628
617
  documentLoader: authLoader ?? documentLoader,
629
618
  contextLoader,
630
- userAgent: command$1.userAgent
619
+ userAgent: command.userAgent
631
620
  });
632
621
  } catch (error) {
633
- if (error instanceof TimeoutError) handleTimeoutError(spinner, command$1.timeout, url);
622
+ if (error instanceof TimeoutError) handleTimeoutError(spinner, command.timeout, url);
634
623
  else {
635
624
  spinner.fail(`Failed to fetch object: ${colors.red(url)}.`);
636
625
  printLookupFailureHint(authLoader, error);
@@ -651,17 +640,17 @@ async function runLookup(command$1, deps = {}) {
651
640
  }
652
641
  spinner.succeed(`Fetched collection: ${colors.green(url)}.`);
653
642
  try {
654
- if (command$1.reverse) {
643
+ if (command.reverse) {
655
644
  const { items: traversedItems, error: traversalError } = await collectAsyncItems(effectiveDeps.traverseCollection(collection, {
656
645
  documentLoader: authLoader ?? documentLoader,
657
646
  contextLoader,
658
- suppressError: command$1.suppressErrors
647
+ suppressError: command.suppressErrors
659
648
  }));
660
649
  for (let index = traversedItems.length - 1; index >= 0; index--) {
661
650
  const item = traversedItems[index];
662
651
  try {
663
- if (totalItems > 0) await writeSeparator(command$1.separator, getOutputStream());
664
- await writeObjectToStream(item, command$1.output, command$1.format, contextLoader, getOutputStream());
652
+ if (totalItems > 0) await writeSeparator(command.separator, getOutputStream());
653
+ await writeObjectToStream(item, command.output, command.format, contextLoader, getOutputStream());
665
654
  } catch (error) {
666
655
  logger.error("Failed to write output for {url}: {error}", {
667
656
  url,
@@ -677,11 +666,11 @@ async function runLookup(command$1, deps = {}) {
677
666
  } else for await (const item of effectiveDeps.traverseCollection(collection, {
678
667
  documentLoader: authLoader ?? documentLoader,
679
668
  contextLoader,
680
- suppressError: command$1.suppressErrors
669
+ suppressError: command.suppressErrors
681
670
  })) {
682
671
  try {
683
- if (totalItems > 0) await writeSeparator(command$1.separator, getOutputStream());
684
- await writeObjectToStream(item, command$1.output, command$1.format, contextLoader, getOutputStream());
672
+ if (totalItems > 0) await writeSeparator(command.separator, getOutputStream());
673
+ await writeObjectToStream(item, command.output, command.format, contextLoader, getOutputStream());
685
674
  } catch (error) {
686
675
  logger.error("Failed to write output for {url}: {error}", {
687
676
  url,
@@ -698,7 +687,7 @@ async function runLookup(command$1, deps = {}) {
698
687
  url,
699
688
  error
700
689
  });
701
- if (error instanceof TimeoutError) handleTimeoutError(spinner, command$1.timeout, url);
690
+ if (error instanceof TimeoutError) handleTimeoutError(spinner, command.timeout, url);
702
691
  else {
703
692
  spinner.fail(`Failed to complete the traversal for: ${colors.red(url)}.`);
704
693
  const hint = getLookupFailureHint(error);
@@ -714,12 +703,12 @@ async function runLookup(command$1, deps = {}) {
714
703
  return;
715
704
  }
716
705
  const promises = [];
717
- for (const url of command$1.urls) promises.push(effectiveDeps.lookupObject(url, {
706
+ for (const url of command.urls) promises.push(effectiveDeps.lookupObject(url, {
718
707
  documentLoader: authLoader ?? documentLoader,
719
708
  contextLoader,
720
- userAgent: command$1.userAgent
709
+ userAgent: command.userAgent
721
710
  }).catch((error) => {
722
- if (error instanceof TimeoutError) handleTimeoutError(spinner, command$1.timeout, url);
711
+ if (error instanceof TimeoutError) handleTimeoutError(spinner, command.timeout, url);
723
712
  throw error;
724
713
  }));
725
714
  let objects = [];
@@ -734,7 +723,7 @@ async function runLookup(command$1, deps = {}) {
734
723
  let printedCount = 0;
735
724
  const successfulObjects = [];
736
725
  for (const [i, obj] of objects.entries()) {
737
- const url = command$1.urls[i];
726
+ const url = command.urls[i];
738
727
  if (obj == null) {
739
728
  spinner.fail(`Failed to fetch ${colors.red(url)}`);
740
729
  if (authLoader == null) printError(message`It may be a private object. Try with -a/--authorized-fetch.`);
@@ -744,10 +733,10 @@ async function runLookup(command$1, deps = {}) {
744
733
  successfulObjects.push(obj);
745
734
  }
746
735
  }
747
- for (const obj of toPresentationOrder(successfulObjects, command$1.reverse)) {
736
+ for (const obj of toPresentationOrder(successfulObjects, command.reverse)) {
748
737
  try {
749
- if (printedCount > 0) await writeSeparator(command$1.separator, getOutputStream());
750
- await writeObjectToStream(obj, command$1.output, command$1.format, contextLoader, getOutputStream());
738
+ if (printedCount > 0) await writeSeparator(command.separator, getOutputStream());
739
+ await writeObjectToStream(obj, command.output, command.format, contextLoader, getOutputStream());
751
740
  } catch (error) {
752
741
  logger.error("Failed to write lookup output: {error}", { error });
753
742
  spinner.fail("Failed to write output.");
@@ -756,7 +745,7 @@ async function runLookup(command$1, deps = {}) {
756
745
  }
757
746
  printedCount++;
758
747
  }
759
- if (success) spinner.succeed(command$1.urls.length > 1 ? "Successfully fetched all objects." : "Successfully fetched the object.");
748
+ if (success) spinner.succeed(command.urls.length > 1 ? "Successfully fetched all objects." : "Successfully fetched the object.");
760
749
  if (!success) {
761
750
  await finalizeAndExit(1);
762
751
  return;
@@ -770,8 +759,7 @@ async function runLookup(command$1, deps = {}) {
770
759
  await finalizeAndExit(1);
771
760
  return;
772
761
  }
773
- if (success && command$1.output) spinner.succeed(`Successfully wrote output to ${colors.green(command$1.output)}.`);
762
+ if (success && command.output) spinner.succeed(`Successfully wrote output to ${colors.green(command.output)}.`);
774
763
  }
775
-
776
764
  //#endregion
777
- export { lookupCommand, runLookup };
765
+ export { lookupCommand, runLookup };
package/dist/mod.js CHANGED
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env -S node --disable-warning=ExperimentalWarning
2
-
3
- import { Temporal } from "@js-temporal/polyfill";
4
-
2
+ import "@js-temporal/polyfill";
5
3
  import { configContext, tryLoadToml } from "./config.js";
6
- import { runGenerateVocab } from "./generate-vocab/action.js";
7
- import command_default from "./generate-vocab/command.js";
4
+ import runGenerateVocab from "./generate-vocab/action.js";
5
+ import generateVocabCommand from "./generate-vocab/command.js";
8
6
  import "./generate-vocab/mod.js";
9
- import deno_default from "./deno.js";
7
+ import { version } from "./deno.js";
10
8
  import { globalOptions } from "./options.js";
11
9
  import { inboxCommand, runInbox } from "./inbox.js";
12
10
  import { initCommand, runInit } from "./init/mod.js";
@@ -14,19 +12,18 @@ import { nodeInfoCommand, runNodeInfo } from "./nodeinfo.js";
14
12
  import { lookupCommand, runLookup } from "./lookup.js";
15
13
  import { relayCommand, runRelay } from "./relay.js";
16
14
  import { runTunnel, tunnelCommand } from "./tunnel.js";
17
- import { runWebFinger } from "./webfinger/action.js";
15
+ import runWebFinger from "./webfinger/action.js";
18
16
  import { webFingerCommand } from "./webfinger/command.js";
19
17
  import "./webfinger/mod.js";
20
- import { join } from "node:path";
21
- import { homedir } from "node:os";
22
- import process from "node:process";
23
18
  import { runWithConfig } from "@optique/config/run";
24
19
  import { group, merge, message, or } from "@optique/core";
25
20
  import { printError } from "@optique/run";
26
21
  import { merge as merge$1 } from "es-toolkit";
27
22
  import { readFileSync } from "node:fs";
23
+ import { homedir } from "node:os";
24
+ import { join } from "node:path";
25
+ import process from "node:process";
28
26
  import { parse } from "smol-toml";
29
-
30
27
  //#region src/mod.ts
31
28
  /**
32
29
  * Returns the system-wide configuration file paths.
@@ -34,10 +31,7 @@ import { parse } from "smol-toml";
34
31
  * - Windows: Uses `%ProgramData%` (default: C:\ProgramData)
35
32
  */
36
33
  function getSystemConfigPaths() {
37
- if (process.platform === "win32") {
38
- const programData = process.env.ProgramData || "C:\\ProgramData";
39
- return [join(programData, "fedify", "config.toml")];
40
- }
34
+ if (process.platform === "win32") return [join(process.env.ProgramData || "C:\\ProgramData", "fedify", "config.toml")];
41
35
  return (process.env.XDG_CONFIG_DIRS || "/etc/xdg").split(":").map((dir) => join(dir, "fedify", "config.toml"));
42
36
  }
43
37
  /**
@@ -46,21 +40,16 @@ function getSystemConfigPaths() {
46
40
  * - Windows: `%APPDATA%\fedify\config.toml`
47
41
  */
48
42
  function getUserConfigPath() {
49
- if (process.platform === "win32") {
50
- const appData = process.env.APPDATA || join(homedir(), "AppData", "Roaming");
51
- return join(appData, "fedify", "config.toml");
52
- }
53
- const xdgConfigHome = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
54
- return join(xdgConfigHome, "fedify", "config.toml");
43
+ if (process.platform === "win32") return join(process.env.APPDATA || join(homedir(), "AppData", "Roaming"), "fedify", "config.toml");
44
+ return join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "fedify", "config.toml");
55
45
  }
56
- const command$1 = merge(or(group("Generating code", or(initCommand, command_default)), group("ActivityPub tools", or(webFingerCommand, lookupCommand, inboxCommand, nodeInfoCommand, relayCommand)), group("Network tools", tunnelCommand)), globalOptions);
46
+ const command$1 = merge(or(group("Generating code", or(initCommand, generateVocabCommand)), group("ActivityPub tools", or(webFingerCommand, lookupCommand, inboxCommand, nodeInfoCommand, relayCommand)), group("Network tools", tunnelCommand)), globalOptions);
57
47
  async function main() {
58
48
  const result = await runWithConfig(command$1, configContext, {
59
49
  programName: "fedify",
60
50
  load: (parsed) => {
61
51
  if (parsed.ignoreConfig) return {};
62
- const systemConfigs = getSystemConfigPaths().map(tryLoadToml);
63
- const system = systemConfigs.reduce((acc, config) => merge$1(acc, config), {});
52
+ const system = getSystemConfigPaths().map(tryLoadToml).reduce((acc, config) => merge$1(acc, config), {});
64
53
  const user = tryLoadToml(getUserConfigPath());
65
54
  const project = tryLoadToml(join(process.cwd(), ".fedify.toml"));
66
55
  let custom = {};
@@ -85,7 +74,7 @@ async function main() {
85
74
  },
86
75
  version: {
87
76
  mode: "both",
88
- value: deno_default.version,
77
+ value: version,
89
78
  group: "Meta commands"
90
79
  },
91
80
  completion: {
@@ -108,10 +97,7 @@ async function main() {
108
97
  else if (result.command === "tunnel") await runTunnel(result);
109
98
  else if (result.command === "generate-vocab") await runGenerateVocab(result);
110
99
  else if (result.command === "relay") await runRelay(result);
111
- else {
112
- const _exhaustiveCheck = result;
113
- }
114
100
  }
115
101
  await main();
116
-
117
- //#endregion
102
+ //#endregion
103
+ export {};