this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rename handler types for clarity

futur f826961a 824dfd7d

+40 -21
+20 -17
src/LabelerServer.ts
··· 1 - import { 1 + import type { 2 2 ComAtprotoLabelDefs, 3 3 ToolsOzoneModerationDefs, 4 4 ToolsOzoneModerationEmitEvent, 5 5 } from "@atproto/api"; 6 - import { Keypair, Secp256k1Keypair } from "@atproto/crypto"; 6 + import { type Keypair, Secp256k1Keypair } from "@atproto/crypto"; 7 7 import { IdResolver } from "@atproto/identity"; 8 8 import { 9 9 AuthRequiredError, ··· 20 20 import { fromString as ui8FromString } from "uint8arrays"; 21 21 import type { WebSocket } from "ws"; 22 22 import { formatLabel, labelIsSigned, signLabel } from "./util/labels.js"; 23 - import { GetMethod, SavedLabel, WebSocketMethod } from "./util/types.js"; 23 + import type { 24 + ProcedureHandler, 25 + QueryHandler, 26 + SavedLabel, 27 + SubscriptionHandler, 28 + } from "./util/types.js"; 24 29 25 30 /** 26 31 * Options for the {@link LabelerServer} class. ··· 229 234 /** 230 235 * Handler for com.atproto.label.queryLabels. 231 236 */ 232 - queryLabelsHandler: GetMethod< 233 - { 234 - Querystring: { 235 - uriPatterns?: Array<string>; 236 - sources?: Array<string>; 237 - limit?: string; 238 - cursor?: string; 239 - }; 240 - } 237 + queryLabelsHandler: QueryHandler< 238 + { uriPatterns?: Array<string>; sources?: Array<string>; limit?: string; cursor?: string } 241 239 > = async (req, res) => { 242 240 try { 243 241 const { ··· 304 302 /** 305 303 * Handler for com.atproto.label.subscribeLabels. 306 304 */ 307 - subscribeLabelsHandler: WebSocketMethod<{ Querystring: { cursor?: string } }> = (ws, req) => { 305 + subscribeLabelsHandler: SubscriptionHandler<{ Querystring: { cursor?: string } }> = ( 306 + ws, 307 + req, 308 + ) => { 308 309 const cursor = parseInt(req.query.cursor ?? "NaN", 10); 309 310 310 311 if (!Number.isNaN(cursor)) { ··· 355 356 /** 356 357 * Handler for tools.ozone.moderation.emitEvent. 357 358 */ 358 - emitEventHandler: GetMethod = async (req, res) => { 359 + emitEventHandler: ProcedureHandler<ToolsOzoneModerationEmitEvent.InputSchema> = async ( 360 + req, 361 + res, 362 + ) => { 359 363 try { 360 364 const actorDid = await this.parseAuthHeaderDid(req); 361 365 const authed = await this.auth(actorDid); ··· 363 367 throw new AuthRequiredError("Unauthorized"); 364 368 } 365 369 366 - const { event, subject, subjectBlobCids = [], createdBy } = req 367 - .body as ToolsOzoneModerationEmitEvent.InputSchema; 370 + const { event, subject, subjectBlobCids = [], createdBy } = req.body; 368 371 if (!event || !subject || !createdBy) { 369 372 throw new InvalidRequestError("Missing required field(s)"); 370 373 } ··· 423 426 /** 424 427 * Catch-all handler for unknown XRPC methods. 425 428 */ 426 - unknownMethodHandler: GetMethod = async (_req, res) => 429 + unknownMethodHandler: QueryHandler = async (_req, res) => 427 430 res.send({ error: "MethodNotImplemented", message: "Method Not Implemented" }); 428 431 429 432 /**
+7 -1
src/index.ts
··· 1 1 export { type LabelerOptions, LabelerServer } from "./LabelerServer.js"; 2 2 export { formatLabel, labelIsSigned, signLabel } from "./util/labels.js"; 3 - export type { GetMethod, SavedLabel, SignedLabel, WebSocketMethod } from "./util/types.js"; 3 + export type { 4 + ProcedureHandler, 5 + QueryHandler, 6 + SavedLabel, 7 + SignedLabel, 8 + SubscriptionHandler, 9 + } from "./util/types.js";
+13 -3
src/util/types.ts
··· 16 16 export type SignedLabel = ComAtprotoLabelDefs.Label & { sig: Uint8Array }; 17 17 export type SavedLabel = SignedLabel & { id: number }; 18 18 19 - export type GetMethod<T extends RouteGenericInterface = RouteGenericInterface> = RouteHandlerMethod< 19 + export type QueryHandler< 20 + T extends RouteGenericInterface["Querystring"] = RouteGenericInterface["Querystring"], 21 + > = RouteHandlerMethod< 20 22 RawServerDefault, 21 23 RawRequestDefaultExpression, 22 24 RawReplyDefaultExpression, 23 - T 25 + { Querystring: T } 24 26 >; 25 - export type WebSocketMethod<T extends RequestGenericInterface = RequestGenericInterface> = 27 + export type ProcedureHandler< 28 + T extends RouteGenericInterface["Body"] = RouteGenericInterface["Body"], 29 + > = RouteHandlerMethod< 30 + RawServerDefault, 31 + RawRequestDefaultExpression, 32 + RawReplyDefaultExpression, 33 + { Body: T } 34 + >; 35 + export type SubscriptionHandler<T extends RequestGenericInterface = RequestGenericInterface> = 26 36 WebsocketHandler<RawServerDefault, RawRequestDefaultExpression, T>;