Skip to content

Commit 3d1ca85

Browse files
authored
Merge pull request #677 from dahlia/chore/optique-1.0.0-cli
Update @fedify/cli for Optique 1.0.0
2 parents fe50936 + 86a1f54 commit 3d1ca85

18 files changed

Lines changed: 721 additions & 488 deletions

File tree

deno.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
"@opentelemetry/core": "npm:@opentelemetry/core@^2.5.0",
4949
"@opentelemetry/sdk-trace-base": "npm:@opentelemetry/sdk-trace-base@^2.5.0",
5050
"@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.39.0",
51-
"@optique/config": "jsr:@optique/config@^0.10.7",
52-
"@optique/core": "jsr:@optique/core@^0.10.7",
53-
"@optique/run": "jsr:@optique/run@^0.10.7",
51+
"@optique/config": "jsr:@optique/config@^1.0.0",
52+
"@optique/core": "jsr:@optique/core@^1.0.0",
53+
"@optique/run": "jsr:@optique/run@^1.0.0",
5454
"@std/assert": "jsr:@std/assert@^1.0.13",
5555
"@std/async": "jsr:@std/async@^1.0.13",
5656
"@std/encoding": "jsr:@std/encoding@^1.0.10",

deno.lock

Lines changed: 48 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/inbox.tsx

Lines changed: 7 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,18 @@ import {
2323
type Recipient,
2424
} from "@fedify/vocab";
2525
import { getLogger } from "@logtape/logtape";
26-
import { bindConfig } from "@optique/config";
27-
import {
28-
command,
29-
constant,
30-
group,
31-
type InferValue,
32-
merge,
33-
message,
34-
multiple,
35-
object,
36-
option,
37-
string,
38-
} from "@optique/core";
26+
import type { InferValue } from "@optique/core";
3927
import Table from "cli-table3";
4028
import { type Context as HonoContext, Hono } from "hono";
4129
import type { BlankEnv, BlankInput } from "hono/types";
4230
import process from "node:process";
4331
import ora from "ora";
4432
import metadata from "../deno.json" with { type: "json" };
45-
import { configContext } from "./config.ts";
4633
import { getDocumentLoader } from "./docloader.ts";
4734
import type { ActivityEntry } from "./inbox/entry.ts";
4835
import { ActivityEntryPage, ActivityListPage } from "./inbox/view.tsx";
4936
import { configureLogging, recordingSink } from "./log.ts";
50-
import { createTunnelOption, type GlobalOptions } from "./options.ts";
37+
import type { GlobalOptions } from "./options.ts";
5138
import { tableStyle } from "./table.ts";
5239
import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts";
5340
import { colors, matchesActor } from "./utils.ts";
@@ -66,92 +53,18 @@ interface ContextData {
6653

6754
const logger = getLogger(["fedify", "cli", "inbox"]);
6855

69-
export const inboxCommand = command(
70-
"inbox",
71-
merge(
72-
object("Inbox options", {
73-
command: constant("inbox"),
74-
follow: bindConfig(
75-
multiple(
76-
option("-f", "--follow", string({ metavar: "URI" }), {
77-
description:
78-
message`Follow the given actor. The argument can be either an actor URI or a handle. Can be specified multiple times.`,
79-
}),
80-
),
81-
{
82-
context: configContext,
83-
key: (config) => config.inbox?.follow ?? [],
84-
default: [],
85-
},
86-
),
87-
acceptFollow: bindConfig(
88-
multiple(
89-
option("-a", "--accept-follow", string({ metavar: "URI" }), {
90-
description:
91-
message`Accept follow requests from the given actor. The argument can be either an actor URI or a handle, or a wildcard (${"*"}). Can be specified multiple times. If a wildcard is specified, all follow requests will be accepted.`,
92-
}),
93-
),
94-
{
95-
context: configContext,
96-
key: (config) => config.inbox?.acceptFollow ?? [],
97-
default: [],
98-
},
99-
),
100-
actorName: bindConfig(
101-
option("--actor-name", string({ metavar: "NAME" }), {
102-
description: message`Customize the actor display name.`,
103-
}),
104-
{
105-
context: configContext,
106-
key: (config) => config.inbox?.actorName ?? "Fedify Ephemeral Inbox",
107-
default: "Fedify Ephemeral Inbox",
108-
},
109-
),
110-
actorSummary: bindConfig(
111-
option("--actor-summary", string({ metavar: "SUMMARY" }), {
112-
description: message`Customize the actor description.`,
113-
}),
114-
{
115-
context: configContext,
116-
key: (config) =>
117-
config.inbox?.actorSummary ??
118-
"An ephemeral ActivityPub inbox for testing purposes.",
119-
default: "An ephemeral ActivityPub inbox for testing purposes.",
120-
},
121-
),
122-
authorizedFetch: bindConfig(
123-
option(
124-
"-A",
125-
"--authorized-fetch",
126-
{
127-
description:
128-
message`Enable authorized fetch mode. Incoming requests without valid HTTP signatures will be rejected with 401 Unauthorized.`,
129-
},
130-
),
131-
{
132-
context: configContext,
133-
key: (config) => config.inbox?.authorizedFetch ?? false,
134-
default: false,
135-
},
136-
),
137-
}),
138-
group("Tunnel options", createTunnelOption("inbox")),
139-
),
140-
{
141-
brief: message`Run an ephemeral ActivityPub inbox server.`,
142-
description:
143-
message`Spins up an ephemeral server that serves the ActivityPub inbox with an one-time actor, through a short-lived public DNS with HTTPS. You can monitor the incoming activities in real-time.`,
144-
},
145-
);
146-
14756
// Module-level state
14857
const activities: ActivityEntry[] = [];
14958
const acceptFollows: string[] = [];
15059
const peers: Record<string, Actor> = {};
15160
const followers: Record<string, Actor> = {};
15261

62+
type InboxCommand =
63+
& InferValue<typeof import("./inbox/command.ts").inboxCommand>
64+
& GlobalOptions;
65+
15366
export async function runInbox(
154-
command: InferValue<typeof inboxCommand> & GlobalOptions,
67+
command: InboxCommand,
15568
) {
15669
// Reset module-level state for a clean run
15770
activities.length = 0;

packages/cli/src/inbox/command.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { bindConfig } from "@optique/config";
2+
import {
3+
command,
4+
constant,
5+
group,
6+
merge,
7+
message,
8+
multiple,
9+
object,
10+
option,
11+
string,
12+
} from "@optique/core";
13+
import { configContext } from "../config.ts";
14+
import { createTunnelOption } from "../options.ts";
15+
16+
const DEFAULT_EPHEMERAL_INBOX_NAME = "Fedify Ephemeral Inbox";
17+
const DEFAULT_EPHEMERAL_INBOX_SUMMARY =
18+
"An ephemeral ActivityPub inbox for testing purposes.";
19+
20+
export const inboxCommand = command(
21+
"inbox",
22+
merge(
23+
object("Inbox options", {
24+
command: constant("inbox"),
25+
follow: bindConfig(
26+
multiple(
27+
option("-f", "--follow", string({ metavar: "URI" }), {
28+
description:
29+
message`Follow the given actor. The argument can be either an actor URI or a handle. Can be specified multiple times.`,
30+
}),
31+
),
32+
{
33+
context: configContext,
34+
key: (config) => config.inbox?.follow ?? [],
35+
default: [],
36+
},
37+
),
38+
acceptFollow: bindConfig(
39+
multiple(
40+
option("-a", "--accept-follow", string({ metavar: "URI" }), {
41+
description:
42+
message`Accept follow requests from the given actor. The argument can be either an actor URI or a handle, or a wildcard (${"*"}). Can be specified multiple times. If a wildcard is specified, all follow requests will be accepted.`,
43+
}),
44+
),
45+
{
46+
context: configContext,
47+
key: (config) => config.inbox?.acceptFollow ?? [],
48+
default: [],
49+
},
50+
),
51+
actorName: bindConfig(
52+
option("--actor-name", string({ metavar: "NAME" }), {
53+
description: message`Customize the actor display name.`,
54+
}),
55+
{
56+
context: configContext,
57+
key: (config) =>
58+
config.inbox?.actorName ?? DEFAULT_EPHEMERAL_INBOX_NAME,
59+
default: DEFAULT_EPHEMERAL_INBOX_NAME,
60+
},
61+
),
62+
actorSummary: bindConfig(
63+
option("--actor-summary", string({ metavar: "SUMMARY" }), {
64+
description: message`Customize the actor description.`,
65+
}),
66+
{
67+
context: configContext,
68+
key: (config) =>
69+
config.inbox?.actorSummary ??
70+
DEFAULT_EPHEMERAL_INBOX_SUMMARY,
71+
default: DEFAULT_EPHEMERAL_INBOX_SUMMARY,
72+
},
73+
),
74+
authorizedFetch: bindConfig(
75+
option(
76+
"-A",
77+
"--authorized-fetch",
78+
{
79+
description:
80+
message`Enable authorized fetch mode. Incoming requests without valid HTTP signatures will be rejected with 401 Unauthorized.`,
81+
},
82+
),
83+
{
84+
context: configContext,
85+
key: (config) => config.inbox?.authorizedFetch ?? false,
86+
default: false,
87+
},
88+
),
89+
}),
90+
group("Tunnel options", createTunnelOption("inbox")),
91+
),
92+
{
93+
brief: message`Run an ephemeral ActivityPub inbox server.`,
94+
description:
95+
message`Spins up an ephemeral server that serves the ActivityPub inbox with a one-time actor, through a short-lived public DNS with HTTPS. You can monitor the incoming activities in real-time.`,
96+
},
97+
);

0 commit comments

Comments
 (0)