UNPKG

@imigueldiaz/mongodb-labeler

Version:

A MongoDB-based labeling system for content moderation with cryptographic signing

78 lines (77 loc) 3.13 kB
import { At } from "@atcute/client/lib/lexicons"; import type { WebsocketHandler } from "@fastify/websocket"; import type { RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerDefault, RequestGenericInterface, RouteGenericInterface, RouteHandlerMethod } from "fastify"; import { Binary, ObjectId } from "mongodb"; type NullishKeys<T> = { [K in keyof T]: null extends T[K] ? K : undefined extends T[K] ? K : never; }[keyof T]; type NonNullishKeys<T> = Exclude<keyof T, NullishKeys<T>>; export type NonNullishPartial<T> = { [K in NullishKeys<T>]+?: Exclude<T[K], null | undefined>; } & { [K in NonNullishKeys<T>]-?: T[K]; }; /** * Data required to create a label. */ export interface UnsignedLabel { /** The label schema version. Current version is always 1. */ ver: 1; /** The label value. */ val: string; /** * The subject of the label. * - For labeling an account, this should be a string beginning with `did:`. CID must not be provided for DID URIs. * - For labeling specific content, this should be a string beginning with `at://`. It's recommended to provide a CID * for content-specific labels to reference a specific version. */ uri: string; /** * The CID specifying the version of the content to label. * - Only applicable for `at://` URIs * - Must not be provided for `did:` URIs * - Recommended to include for content-specific labels to reference a specific version */ cid?: string; /** Whether this label is negating a previous instance of this label applied to the same subject. */ neg?: boolean; /** The DID of the actor who created this label, if different from the labeler. Must start with 'did:'. */ src?: `did:${string}`; /** The creation date of the label. Must be in ISO 8601 format. */ cts?: string; /** The expiration date of the label, if any. Must be in ISO 8601 format. */ exp?: string; } /** * Data required to create a label. */ export type CreateLabelData = Omit<UnsignedLabel, 'ver'> & { ver?: number; }; /** * Data required to create a label. */ export type SignedLabel = UnsignedLabel & { sig: Uint8Array; }; export type FormattedLabel = UnsignedLabel & { sig?: At.Bytes; }; export type SavedLabel = UnsignedLabel & { sig: ArrayBuffer; _id: ObjectId; }; export type MongoSavedLabel = Omit<SavedLabel, "sig" | "_id"> & { id: ObjectId; sig: Binary; }; export type QueryHandler<T extends RouteGenericInterface["Querystring"] = RouteGenericInterface["Querystring"]> = RouteHandlerMethod<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, { Querystring: T; }>; export type ProcedureHandler<T extends RouteGenericInterface["Body"] = RouteGenericInterface["Body"]> = RouteHandlerMethod<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, { Body: T; }>; export type SubscriptionHandler<T extends RequestGenericInterface["Querystring"] = RequestGenericInterface["Querystring"]> = WebsocketHandler<RawServerDefault, RawRequestDefaultExpression, { Querystring: T; }>; export {};