@fedify/fedify
Version:
An ActivityPub server framework
757 lines (753 loc) • 1.7 MB
JavaScript
import { Temporal } from "@js-temporal/polyfill";
import { URLPattern } from "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { __export } from "./chunk-HsBuZ-b2.js";
import { getDocumentLoader } from "./docloader-C8mmLN-Y.js";
import { decode, encode } from "./multibase-DeCHcK8L.js";
import { LanguageString } from "./langstr-DbWheeIS.js";
import { getLogger } from "@logtape/logtape";
import { SpanStatusCode, trace } from "@opentelemetry/api";
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
import { decodeHex } from "byte-encodings/hex";
import jsonld from "jsonld";
import { LanguageTag, parseLanguageTag } from "@phensley/language-tag";
import { Integer, Sequence } from "asn1js";
import { decodeBase64Url } from "byte-encodings/base64url";
import { addPrefix, getCodeFromData, rmPrefix } from "multicodec";
import { createPublicKey } from "node:crypto";
import { PublicKeyInfo } from "pkijs";
//#region runtime/key.ts
const algorithms = {
"1.2.840.113549.1.1.1": {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256"
},
"1.3.101.112": "Ed25519"
};
/**
* Imports a PEM-SPKI formatted public key.
* @param pem The PEM-SPKI formatted public key.
* @returns The imported public key.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 0.5.0
*/
async function importSpki(pem) {
pem = pem.replace(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "");
let spki;
try {
spki = decodeBase64(pem);
} catch (_) {
throw new TypeError("Invalid PEM-SPKI format.");
}
const pki = PublicKeyInfo.fromBER(spki);
const oid = pki.algorithm.algorithmId;
const algorithm = algorithms[oid];
if (algorithm == null) throw new TypeError("Unsupported algorithm: " + oid);
return await crypto.subtle.importKey("spki", spki, algorithm, true, ["verify"]);
}
/**
* Exports a public key in PEM-SPKI format.
* @param key The public key to export.
* @returns The exported public key in PEM-SPKI format.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 0.5.0
*/
async function exportSpki(key) {
const { validateCryptoKey } = await import("./key-y9w9Y2OM.js");
validateCryptoKey(key);
const spki = await crypto.subtle.exportKey("spki", key);
let pem = encodeBase64(spki);
pem = (pem.match(/.{1,64}/g) || []).join("\n");
return `-----BEGIN PUBLIC KEY-----\n${pem}\n-----END PUBLIC KEY-----\n`;
}
/**
* Imports a PEM-PKCS#1 formatted public key.
* @param pem The PEM-PKCS#1 formatted public key.
* @returns The imported public key.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 1.5.0
*/
function importPkcs1(pem) {
const key = createPublicKey({
key: pem,
format: "pem",
type: "pkcs1"
});
const spki = key.export({
type: "spki",
format: "pem"
});
return importSpki(spki);
}
const PKCS1_HEADER = /^\s*-----BEGIN\s+RSA\s+PUBLIC\s+KEY-----\s*\n/;
/**
* Imports a PEM formatted public key (SPKI or PKCS#1).
* @param pem The PEM formatted public key to import (SPKI or PKCS#1).
* @returns The imported public key.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 1.5.0
*/
function importPem(pem) {
return PKCS1_HEADER.test(pem) ? importPkcs1(pem) : importSpki(pem);
}
/**
* Imports a [Multibase]-encoded public key.
*
* [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
* @param key The Multibase-encoded public key.
* @returns The imported public key.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 0.10.0
*/
async function importMultibaseKey(key) {
const decoded = decode(key);
const code = getCodeFromData(decoded);
const content = rmPrefix(decoded);
if (code === 4613) {
const keyObject = createPublicKey({
key: content,
format: "der",
type: "pkcs1"
});
const spki = keyObject.export({
type: "spki",
format: "der"
}).buffer;
return await crypto.subtle.importKey("spki", new Uint8Array(spki), {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256"
}, true, ["verify"]);
} else if (code === 237) return await crypto.subtle.importKey("raw", content, "Ed25519", true, ["verify"]);
else throw new TypeError("Unsupported key type: 0x" + code.toString(16));
}
/**
* Exports a public key in [Multibase] format.
*
* [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
* @param key The public key to export.
* @returns The exported public key in Multibase format.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 0.10.0
*/
async function exportMultibaseKey(key) {
let content;
let code;
if (key.algorithm.name === "Ed25519") {
content = await crypto.subtle.exportKey("raw", key);
code = 237;
} else if (key.algorithm.name === "RSASSA-PKCS1-v1_5" && key.algorithm.hash.name === "SHA-256") {
const jwk = await crypto.subtle.exportKey("jwk", key);
const decodedN = decodeBase64Url(jwk.n);
const n = new Uint8Array(decodedN.length + 1);
n.set(decodedN, 1);
const sequence = new Sequence({ value: [new Integer({
isHexOnly: true,
valueHex: n
}), new Integer({
isHexOnly: true,
valueHex: decodeBase64Url(jwk.e)
})] });
content = sequence.toBER(false);
code = 4613;
} else throw new TypeError("Unsupported key type: " + JSON.stringify(key.algorithm));
const codeHex = code.toString(16);
const codeBytes = decodeHex(codeHex.length % 2 < 1 ? codeHex : "0" + codeHex);
const prefixed = addPrefix(codeBytes, new Uint8Array(content));
const encoded = encode("base58btc", prefixed);
return new TextDecoder().decode(encoded);
}
//#endregion
//#region vocab/vocab.ts
var vocab_exports = {};
__export(vocab_exports, {
Accept: () => Accept,
Activity: () => Activity,
Add: () => Add,
Announce: () => Announce,
Application: () => Application,
Arrive: () => Arrive,
Article: () => Article,
Audio: () => Audio,
Block: () => Block,
ChatMessage: () => ChatMessage,
Collection: () => Collection,
CollectionPage: () => CollectionPage,
Create: () => Create,
CryptographicKey: () => CryptographicKey,
DataIntegrityProof: () => DataIntegrityProof,
Delete: () => Delete,
DidService: () => DidService,
Dislike: () => Dislike,
Document: () => Document,
Emoji: () => Emoji,
EmojiReact: () => EmojiReact,
Endpoints: () => Endpoints,
Event: () => Event,
Export: () => Export,
Flag: () => Flag,
Follow: () => Follow,
Group: () => Group,
Hashtag: () => Hashtag,
Ignore: () => Ignore,
Image: () => Image,
IntransitiveActivity: () => IntransitiveActivity,
Invite: () => Invite,
Join: () => Join,
Leave: () => Leave,
Like: () => Like,
Link: () => Link,
Listen: () => Listen,
Mention: () => Mention,
Move: () => Move,
Multikey: () => Multikey,
Note: () => Note,
Object: () => Object$1,
Offer: () => Offer,
OrderedCollection: () => OrderedCollection,
OrderedCollectionPage: () => OrderedCollectionPage,
Organization: () => Organization,
Page: () => Page,
Person: () => Person,
Place: () => Place,
Profile: () => Profile,
PropertyValue: () => PropertyValue,
Question: () => Question,
Read: () => Read,
Reject: () => Reject,
Relationship: () => Relationship,
Remove: () => Remove,
Service: () => Service,
Source: () => Source,
TentativeAccept: () => TentativeAccept,
TentativeReject: () => TentativeReject,
Tombstone: () => Tombstone,
Travel: () => Travel,
Undo: () => Undo,
Update: () => Update,
Video: () => Video,
View: () => View
});
/** Describes an object of any kind. The Object type serves as the base type for
* most of the other kinds of objects defined in the Activity Vocabulary,
* including other Core types such as {@link Activity},
* {@link IntransitiveActivity}, {@link Collection} and
* {@link OrderedCollection}.
*/
var Object$1 = class Object$1 {
#documentLoader;
#contextLoader;
#tracerProvider;
#warning;
#cachedJsonLd;
id;
get _documentLoader() {
return this.#documentLoader;
}
get _contextLoader() {
return this.#contextLoader;
}
get _tracerProvider() {
return this.#tracerProvider;
}
get _warning() {
return this.#warning;
}
get _cachedJsonLd() {
return this.#cachedJsonLd;
}
set _cachedJsonLd(value) {
this.#cachedJsonLd = value;
}
/**
* The type URI of {@link Object}: `https://www.w3.org/ns/activitystreams#Object`.
*/
static get typeId() {
return new URL("https://www.w3.org/ns/activitystreams#Object");
}
#_49BipA5dq9eoH8LX8xdsVumveTca_attachment = [];
#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo = [];
#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience = [];
#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content = [];
#_3mhZzGXSpQ431mBSz2kvych22v4e_context = [];
#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name = [];
#_219RwDanjScTv5tYCjwGZVCM7KZ9_endTime = [];
#_86xFhmgBapoMvYqjbjRuDPayTrS_generator = [];
#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon = [];
#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image = [];
#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo = [];
#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location = [];
#_gCVTegXxWWCw6wWRxa1QF65zusg_preview = [];
#_5e258TDXtuhaFRPZiGoDfEpjdMr_published = [];
#_7UpwM3JWcXhADcscukEehBorf6k_replies = [];
#_3kAfck9PcEYt2L7xug5y99YPbANs_shares = [];
#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes = [];
#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions = [];
#_2w3Jmue4up8iVDUA51WZqomEF438_startTime = [];
#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary = [];
#_5chuqj6s95p5gg2sk1HntGfarRf_tag = [];
#_385aB7ySixcf5Un6z3VsWmThgCzQ_updated = [];
#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url = [];
#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to = [];
#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto = [];
#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc = [];
#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc = [];
#_3BLrzmscsjHCw8TF5BHRW9WkPnX8_mediaType = [];
#_3bNvLMBN1bCJETiTihM3wvi1B2JX_duration = [];
#_u8gdcDTtChQ4tbSQMXc4cYWyum7_sensitive = [];
#_2ZwCFoS787v8y8bXKjMoE6MAbrEB_source = [];
#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof = [];
/**
* Constructs a new instance of Object with the given values.
* @param values The values to initialize the instance with.
* @param options The options to use for initialization.
*/
constructor(values, options = {}) {
this.#documentLoader = options.documentLoader;
this.#contextLoader = options.contextLoader;
this.#tracerProvider = options.tracerProvider;
if ("$warning" in options) this.#warning = options.$warning;
if (values.id == null || values.id instanceof URL) this.id = values.id ?? null;
else throw new TypeError("The id must be a URL.");
if ("attachments" in values && values.attachments != null) if (Array.isArray(values.attachments) && values.attachments.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof PropertyValue || v instanceof URL)) this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment = values.attachments;
else throw new TypeError("The attachments must be an array of type Object | Link | PropertyValue | URL.");
if ("attribution" in values && values.attribution != null) if (values.attribution instanceof Application || values.attribution instanceof Group || values.attribution instanceof Organization || values.attribution instanceof Person || values.attribution instanceof Service || values.attribution instanceof URL) this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo = [values.attribution];
else throw new TypeError("The attribution must be of type Application | Group | Organization | Person | Service | URL.");
if ("attributions" in values && values.attributions != null) {
if ("attribution" in values && values.attribution != null) throw new TypeError("Cannot initialize both attribution and attributions at the same time.");
if (Array.isArray(values.attributions) && values.attributions.every((v) => v instanceof Application || v instanceof Group || v instanceof Organization || v instanceof Person || v instanceof Service || v instanceof URL)) this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo = values.attributions;
else throw new TypeError("The attributions must be an array of type Application | Group | Organization | Person | Service | URL.");
}
if ("audience" in values && values.audience != null) if (values.audience instanceof Object$1 || values.audience instanceof URL) this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience = [values.audience];
else throw new TypeError("The audience must be of type Object | URL.");
if ("audiences" in values && values.audiences != null) {
if ("audience" in values && values.audience != null) throw new TypeError("Cannot initialize both audience and audiences at the same time.");
if (Array.isArray(values.audiences) && values.audiences.every((v) => v instanceof Object$1 || v instanceof URL)) this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience = values.audiences;
else throw new TypeError("The audiences must be an array of type Object | URL.");
}
if ("content" in values && values.content != null) if (typeof values.content === "string" || values.content instanceof LanguageString) this.#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content = [values.content];
else throw new TypeError("The content must be of type string | LanguageString.");
if ("contents" in values && values.contents != null) {
if ("content" in values && values.content != null) throw new TypeError("Cannot initialize both content and contents at the same time.");
if (Array.isArray(values.contents) && values.contents.every((v) => typeof v === "string" || v instanceof LanguageString)) this.#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content = values.contents;
else throw new TypeError("The contents must be an array of type string | LanguageString.");
}
if ("contexts" in values && values.contexts != null) if (Array.isArray(values.contexts) && values.contexts.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context = values.contexts;
else throw new TypeError("The contexts must be an array of type Object | Link | URL.");
if ("name" in values && values.name != null) if (typeof values.name === "string" || values.name instanceof LanguageString) this.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name = [values.name];
else throw new TypeError("The name must be of type string | LanguageString.");
if ("names" in values && values.names != null) {
if ("name" in values && values.name != null) throw new TypeError("Cannot initialize both name and names at the same time.");
if (Array.isArray(values.names) && values.names.every((v) => typeof v === "string" || v instanceof LanguageString)) this.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name = values.names;
else throw new TypeError("The names must be an array of type string | LanguageString.");
}
if ("endTime" in values && values.endTime != null) if (values.endTime instanceof Temporal.Instant) this.#_219RwDanjScTv5tYCjwGZVCM7KZ9_endTime = [values.endTime];
else throw new TypeError("The endTime must be of type Temporal.Instant.");
if ("generators" in values && values.generators != null) if (Array.isArray(values.generators) && values.generators.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator = values.generators;
else throw new TypeError("The generators must be an array of type Object | Link | URL.");
if ("icon" in values && values.icon != null) if (values.icon instanceof Image || values.icon instanceof URL) this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon = [values.icon];
else throw new TypeError("The icon must be of type Image | URL.");
if ("icons" in values && values.icons != null) {
if ("icon" in values && values.icon != null) throw new TypeError("Cannot initialize both icon and icons at the same time.");
if (Array.isArray(values.icons) && values.icons.every((v) => v instanceof Image || v instanceof URL)) this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon = values.icons;
else throw new TypeError("The icons must be an array of type Image | URL.");
}
if ("image" in values && values.image != null) if (values.image instanceof Image || values.image instanceof URL) this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image = [values.image];
else throw new TypeError("The image must be of type Image | URL.");
if ("images" in values && values.images != null) {
if ("image" in values && values.image != null) throw new TypeError("Cannot initialize both image and images at the same time.");
if (Array.isArray(values.images) && values.images.every((v) => v instanceof Image || v instanceof URL)) this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image = values.images;
else throw new TypeError("The images must be an array of type Image | URL.");
}
if ("replyTarget" in values && values.replyTarget != null) if (values.replyTarget instanceof Object$1 || values.replyTarget instanceof Link || values.replyTarget instanceof URL) this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo = [values.replyTarget];
else throw new TypeError("The replyTarget must be of type Object | Link | URL.");
if ("replyTargets" in values && values.replyTargets != null) {
if ("replyTarget" in values && values.replyTarget != null) throw new TypeError("Cannot initialize both replyTarget and replyTargets at the same time.");
if (Array.isArray(values.replyTargets) && values.replyTargets.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo = values.replyTargets;
else throw new TypeError("The replyTargets must be an array of type Object | Link | URL.");
}
if ("location" in values && values.location != null) if (values.location instanceof Object$1 || values.location instanceof Link || values.location instanceof URL) this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location = [values.location];
else throw new TypeError("The location must be of type Object | Link | URL.");
if ("locations" in values && values.locations != null) {
if ("location" in values && values.location != null) throw new TypeError("Cannot initialize both location and locations at the same time.");
if (Array.isArray(values.locations) && values.locations.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location = values.locations;
else throw new TypeError("The locations must be an array of type Object | Link | URL.");
}
if ("preview" in values && values.preview != null) if (values.preview instanceof Link || values.preview instanceof Object$1 || values.preview instanceof URL) this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview = [values.preview];
else throw new TypeError("The preview must be of type Link | Object | URL.");
if ("previews" in values && values.previews != null) {
if ("preview" in values && values.preview != null) throw new TypeError("Cannot initialize both preview and previews at the same time.");
if (Array.isArray(values.previews) && values.previews.every((v) => v instanceof Link || v instanceof Object$1 || v instanceof URL)) this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview = values.previews;
else throw new TypeError("The previews must be an array of type Link | Object | URL.");
}
if ("published" in values && values.published != null) if (values.published instanceof Temporal.Instant) this.#_5e258TDXtuhaFRPZiGoDfEpjdMr_published = [values.published];
else throw new TypeError("The published must be of type Temporal.Instant.");
if ("replies" in values && values.replies != null) if (values.replies instanceof Collection || values.replies instanceof URL) this.#_7UpwM3JWcXhADcscukEehBorf6k_replies = [values.replies];
else throw new TypeError("The replies must be of type Collection | URL.");
if ("shares" in values && values.shares != null) if (values.shares instanceof Collection || values.shares instanceof URL) this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares = [values.shares];
else throw new TypeError("The shares must be of type Collection | URL.");
if ("likes" in values && values.likes != null) if (values.likes instanceof Collection || values.likes instanceof URL) this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes = [values.likes];
else throw new TypeError("The likes must be of type Collection | URL.");
if ("emojiReactions" in values && values.emojiReactions != null) if (values.emojiReactions instanceof Collection || values.emojiReactions instanceof URL) this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions = [values.emojiReactions];
else throw new TypeError("The emojiReactions must be of type Collection | URL.");
if ("startTime" in values && values.startTime != null) if (values.startTime instanceof Temporal.Instant) this.#_2w3Jmue4up8iVDUA51WZqomEF438_startTime = [values.startTime];
else throw new TypeError("The startTime must be of type Temporal.Instant.");
if ("summary" in values && values.summary != null) if (typeof values.summary === "string" || values.summary instanceof LanguageString) this.#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary = [values.summary];
else throw new TypeError("The summary must be of type string | LanguageString.");
if ("summaries" in values && values.summaries != null) {
if ("summary" in values && values.summary != null) throw new TypeError("Cannot initialize both summary and summaries at the same time.");
if (Array.isArray(values.summaries) && values.summaries.every((v) => typeof v === "string" || v instanceof LanguageString)) this.#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary = values.summaries;
else throw new TypeError("The summaries must be an array of type string | LanguageString.");
}
if ("tags" in values && values.tags != null) if (Array.isArray(values.tags) && values.tags.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag = values.tags;
else throw new TypeError("The tags must be an array of type Object | Link | URL.");
if ("updated" in values && values.updated != null) if (values.updated instanceof Temporal.Instant) this.#_385aB7ySixcf5Un6z3VsWmThgCzQ_updated = [values.updated];
else throw new TypeError("The updated must be of type Temporal.Instant.");
if ("url" in values && values.url != null) if (values.url instanceof URL || values.url instanceof Link) this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url = [values.url];
else throw new TypeError("The url must be of type URL | Link.");
if ("urls" in values && values.urls != null) {
if ("url" in values && values.url != null) throw new TypeError("Cannot initialize both url and urls at the same time.");
if (Array.isArray(values.urls) && values.urls.every((v) => v instanceof URL || v instanceof Link)) this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url = values.urls;
else throw new TypeError("The urls must be an array of type URL | Link.");
}
if ("to" in values && values.to != null) if (values.to instanceof Object$1 || values.to instanceof URL) this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to = [values.to];
else throw new TypeError("The to must be of type Object | URL.");
if ("tos" in values && values.tos != null) {
if ("to" in values && values.to != null) throw new TypeError("Cannot initialize both to and tos at the same time.");
if (Array.isArray(values.tos) && values.tos.every((v) => v instanceof Object$1 || v instanceof URL)) this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to = values.tos;
else throw new TypeError("The tos must be an array of type Object | URL.");
}
if ("bto" in values && values.bto != null) if (values.bto instanceof Object$1 || values.bto instanceof URL) this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto = [values.bto];
else throw new TypeError("The bto must be of type Object | URL.");
if ("btos" in values && values.btos != null) {
if ("bto" in values && values.bto != null) throw new TypeError("Cannot initialize both bto and btos at the same time.");
if (Array.isArray(values.btos) && values.btos.every((v) => v instanceof Object$1 || v instanceof URL)) this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto = values.btos;
else throw new TypeError("The btos must be an array of type Object | URL.");
}
if ("cc" in values && values.cc != null) if (values.cc instanceof Object$1 || values.cc instanceof URL) this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc = [values.cc];
else throw new TypeError("The cc must be of type Object | URL.");
if ("ccs" in values && values.ccs != null) {
if ("cc" in values && values.cc != null) throw new TypeError("Cannot initialize both cc and ccs at the same time.");
if (Array.isArray(values.ccs) && values.ccs.every((v) => v instanceof Object$1 || v instanceof URL)) this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc = values.ccs;
else throw new TypeError("The ccs must be an array of type Object | URL.");
}
if ("bcc" in values && values.bcc != null) if (values.bcc instanceof Object$1 || values.bcc instanceof URL) this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc = [values.bcc];
else throw new TypeError("The bcc must be of type Object | URL.");
if ("bccs" in values && values.bccs != null) {
if ("bcc" in values && values.bcc != null) throw new TypeError("Cannot initialize both bcc and bccs at the same time.");
if (Array.isArray(values.bccs) && values.bccs.every((v) => v instanceof Object$1 || v instanceof URL)) this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc = values.bccs;
else throw new TypeError("The bccs must be an array of type Object | URL.");
}
if ("mediaType" in values && values.mediaType != null) if (typeof values.mediaType === "string") this.#_3BLrzmscsjHCw8TF5BHRW9WkPnX8_mediaType = [values.mediaType];
else throw new TypeError("The mediaType must be of type string.");
if ("duration" in values && values.duration != null) if (values.duration instanceof Temporal.Duration) this.#_3bNvLMBN1bCJETiTihM3wvi1B2JX_duration = [values.duration];
else throw new TypeError("The duration must be of type Temporal.Duration.");
if ("sensitive" in values && values.sensitive != null) if (typeof values.sensitive === "boolean") this.#_u8gdcDTtChQ4tbSQMXc4cYWyum7_sensitive = [values.sensitive];
else throw new TypeError("The sensitive must be of type boolean.");
if ("source" in values && values.source != null) if (values.source instanceof Source) this.#_2ZwCFoS787v8y8bXKjMoE6MAbrEB_source = [values.source];
else throw new TypeError("The source must be of type Source.");
if ("proof" in values && values.proof != null) if (values.proof instanceof DataIntegrityProof || values.proof instanceof URL) this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof = [values.proof];
else throw new TypeError("The proof must be of type DataIntegrityProof | URL.");
if ("proofs" in values && values.proofs != null) {
if ("proof" in values && values.proof != null) throw new TypeError("Cannot initialize both proof and proofs at the same time.");
if (Array.isArray(values.proofs) && values.proofs.every((v) => v instanceof DataIntegrityProof || v instanceof URL)) this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof = values.proofs;
else throw new TypeError("The proofs must be an array of type DataIntegrityProof | URL.");
}
}
/**
* Clones this instance, optionally updating it with the given values.
* @param values The values to update the clone with.
* @options The options to use for cloning.
* @returns The cloned instance.
*/
clone(values = {}, options = {}) {
if (this._warning != null) {
getLogger(this._warning.category).warn(this._warning.message, this._warning.values);
options = {
...options,
$warning: this._warning
};
}
const clone = new this.constructor({ id: values.id ?? this.id }, options);
clone.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment = this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment;
if ("attachments" in values && values.attachments != null) if (Array.isArray(values.attachments) && values.attachments.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof PropertyValue || v instanceof URL)) clone.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment = values.attachments;
else throw new TypeError("The attachments must be an array of type Object | Link | PropertyValue | URL.");
clone.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo;
if ("attribution" in values && values.attribution != null) if (values.attribution instanceof Application || values.attribution instanceof Group || values.attribution instanceof Organization || values.attribution instanceof Person || values.attribution instanceof Service || values.attribution instanceof URL) clone.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo = [values.attribution];
else throw new TypeError("The attribution must be of type Application | Group | Organization | Person | Service | URL.");
if ("attributions" in values && values.attributions != null) {
if ("attribution" in values && values.attribution != null) throw new TypeError("Cannot update both attribution and attributions at the same time.");
if (Array.isArray(values.attributions) && values.attributions.every((v) => v instanceof Application || v instanceof Group || v instanceof Organization || v instanceof Person || v instanceof Service || v instanceof URL)) clone.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo = values.attributions;
else throw new TypeError("The attributions must be an array of type Application | Group | Organization | Person | Service | URL.");
}
clone.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience;
if ("audience" in values && values.audience != null) if (values.audience instanceof Object$1 || values.audience instanceof URL) clone.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience = [values.audience];
else throw new TypeError("The audience must be of type Object | URL.");
if ("audiences" in values && values.audiences != null) {
if ("audience" in values && values.audience != null) throw new TypeError("Cannot update both audience and audiences at the same time.");
if (Array.isArray(values.audiences) && values.audiences.every((v) => v instanceof Object$1 || v instanceof URL)) clone.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience = values.audiences;
else throw new TypeError("The audiences must be an array of type Object | URL.");
}
clone.#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content = this.#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content;
if ("content" in values && values.content != null) if (typeof values.content === "string" || values.content instanceof LanguageString) clone.#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content = [values.content];
else throw new TypeError("The content must be of type string | LanguageString.");
if ("contents" in values && values.contents != null) {
if ("content" in values && values.content != null) throw new TypeError("Cannot update both content and contents at the same time.");
if (Array.isArray(values.contents) && values.contents.every((v) => typeof v === "string" || v instanceof LanguageString)) clone.#_4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content = values.contents;
else throw new TypeError("The contents must be an array of type string | LanguageString.");
}
clone.#_3mhZzGXSpQ431mBSz2kvych22v4e_context = this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context;
if ("contexts" in values && values.contexts != null) if (Array.isArray(values.contexts) && values.contexts.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) clone.#_3mhZzGXSpQ431mBSz2kvych22v4e_context = values.contexts;
else throw new TypeError("The contexts must be an array of type Object | Link | URL.");
clone.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name = this.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name;
if ("name" in values && values.name != null) if (typeof values.name === "string" || values.name instanceof LanguageString) clone.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name = [values.name];
else throw new TypeError("The name must be of type string | LanguageString.");
if ("names" in values && values.names != null) {
if ("name" in values && values.name != null) throw new TypeError("Cannot update both name and names at the same time.");
if (Array.isArray(values.names) && values.names.every((v) => typeof v === "string" || v instanceof LanguageString)) clone.#_4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name = values.names;
else throw new TypeError("The names must be an array of type string | LanguageString.");
}
clone.#_219RwDanjScTv5tYCjwGZVCM7KZ9_endTime = this.#_219RwDanjScTv5tYCjwGZVCM7KZ9_endTime;
if ("endTime" in values && values.endTime != null) if (values.endTime instanceof Temporal.Instant) clone.#_219RwDanjScTv5tYCjwGZVCM7KZ9_endTime = [values.endTime];
else throw new TypeError("The endTime must be of type Temporal.Instant.");
clone.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator = this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator;
if ("generators" in values && values.generators != null) if (Array.isArray(values.generators) && values.generators.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) clone.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator = values.generators;
else throw new TypeError("The generators must be an array of type Object | Link | URL.");
clone.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon;
if ("icon" in values && values.icon != null) if (values.icon instanceof Image || values.icon instanceof URL) clone.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon = [values.icon];
else throw new TypeError("The icon must be of type Image | URL.");
if ("icons" in values && values.icons != null) {
if ("icon" in values && values.icon != null) throw new TypeError("Cannot update both icon and icons at the same time.");
if (Array.isArray(values.icons) && values.icons.every((v) => v instanceof Image || v instanceof URL)) clone.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon = values.icons;
else throw new TypeError("The icons must be an array of type Image | URL.");
}
clone.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image;
if ("image" in values && values.image != null) if (values.image instanceof Image || values.image instanceof URL) clone.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image = [values.image];
else throw new TypeError("The image must be of type Image | URL.");
if ("images" in values && values.images != null) {
if ("image" in values && values.image != null) throw new TypeError("Cannot update both image and images at the same time.");
if (Array.isArray(values.images) && values.images.every((v) => v instanceof Image || v instanceof URL)) clone.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image = values.images;
else throw new TypeError("The images must be an array of type Image | URL.");
}
clone.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo;
if ("replyTarget" in values && values.replyTarget != null) if (values.replyTarget instanceof Object$1 || values.replyTarget instanceof Link || values.replyTarget instanceof URL) clone.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo = [values.replyTarget];
else throw new TypeError("The replyTarget must be of type Object | Link | URL.");
if ("replyTargets" in values && values.replyTargets != null) {
if ("replyTarget" in values && values.replyTarget != null) throw new TypeError("Cannot update both replyTarget and replyTargets at the same time.");
if (Array.isArray(values.replyTargets) && values.replyTargets.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) clone.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo = values.replyTargets;
else throw new TypeError("The replyTargets must be an array of type Object | Link | URL.");
}
clone.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location;
if ("location" in values && values.location != null) if (values.location instanceof Object$1 || values.location instanceof Link || values.location instanceof URL) clone.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location = [values.location];
else throw new TypeError("The location must be of type Object | Link | URL.");
if ("locations" in values && values.locations != null) {
if ("location" in values && values.location != null) throw new TypeError("Cannot update both location and locations at the same time.");
if (Array.isArray(values.locations) && values.locations.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) clone.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location = values.locations;
else throw new TypeError("The locations must be an array of type Object | Link | URL.");
}
clone.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview;
if ("preview" in values && values.preview != null) if (values.preview instanceof Link || values.preview instanceof Object$1 || values.preview instanceof URL) clone.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview = [values.preview];
else throw new TypeError("The preview must be of type Link | Object | URL.");
if ("previews" in values && values.previews != null) {
if ("preview" in values && values.preview != null) throw new TypeError("Cannot update both preview and previews at the same time.");
if (Array.isArray(values.previews) && values.previews.every((v) => v instanceof Link || v instanceof Object$1 || v instanceof URL)) clone.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview = values.previews;
else throw new TypeError("The previews must be an array of type Link | Object | URL.");
}
clone.#_5e258TDXtuhaFRPZiGoDfEpjdMr_published = this.#_5e258TDXtuhaFRPZiGoDfEpjdMr_published;
if ("published" in values && values.published != null) if (values.published instanceof Temporal.Instant) clone.#_5e258TDXtuhaFRPZiGoDfEpjdMr_published = [values.published];
else throw new TypeError("The published must be of type Temporal.Instant.");
clone.#_7UpwM3JWcXhADcscukEehBorf6k_replies = this.#_7UpwM3JWcXhADcscukEehBorf6k_replies;
if ("replies" in values && values.replies != null) if (values.replies instanceof Collection || values.replies instanceof URL) clone.#_7UpwM3JWcXhADcscukEehBorf6k_replies = [values.replies];
else throw new TypeError("The replies must be of type Collection | URL.");
clone.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares = this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares;
if ("shares" in values && values.shares != null) if (values.shares instanceof Collection || values.shares instanceof URL) clone.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares = [values.shares];
else throw new TypeError("The shares must be of type Collection | URL.");
clone.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes = this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes;
if ("likes" in values && values.likes != null) if (values.likes instanceof Collection || values.likes instanceof URL) clone.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes = [values.likes];
else throw new TypeError("The likes must be of type Collection | URL.");
clone.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions = this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions;
if ("emojiReactions" in values && values.emojiReactions != null) if (values.emojiReactions instanceof Collection || values.emojiReactions instanceof URL) clone.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions = [values.emojiReactions];
else throw new TypeError("The emojiReactions must be of type Collection | URL.");
clone.#_2w3Jmue4up8iVDUA51WZqomEF438_startTime = this.#_2w3Jmue4up8iVDUA51WZqomEF438_startTime;
if ("startTime" in values && values.startTime != null) if (values.startTime instanceof Temporal.Instant) clone.#_2w3Jmue4up8iVDUA51WZqomEF438_startTime = [values.startTime];
else throw new TypeError("The startTime must be of type Temporal.Instant.");
clone.#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary = this.#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary;
if ("summary" in values && values.summary != null) if (typeof values.summary === "string" || values.summary instanceof LanguageString) clone.#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary = [values.summary];
else throw new TypeError("The summary must be of type string | LanguageString.");
if ("summaries" in values && values.summaries != null) {
if ("summary" in values && values.summary != null) throw new TypeError("Cannot update both summary and summaries at the same time.");
if (Array.isArray(values.summaries) && values.summaries.every((v) => typeof v === "string" || v instanceof LanguageString)) clone.#_4LqirZspQbFWWQEbFcXAxm7tTDN1_summary = values.summaries;
else throw new TypeError("The summaries must be an array of type string | LanguageString.");
}
clone.#_5chuqj6s95p5gg2sk1HntGfarRf_tag = this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag;
if ("tags" in values && values.tags != null) if (Array.isArray(values.tags) && values.tags.every((v) => v instanceof Object$1 || v instanceof Link || v instanceof URL)) clone.#_5chuqj6s95p5gg2sk1HntGfarRf_tag = values.tags;
else throw new TypeError("The tags must be an array of type Object | Link | URL.");
clone.#_385aB7ySixcf5Un6z3VsWmThgCzQ_updated = this.#_385aB7ySixcf5Un6z3VsWmThgCzQ_updated;
if ("updated" in values && values.updated != null) if (values.updated instanceof Temporal.Instant) clone.#_385aB7ySixcf5Un6z3VsWmThgCzQ_updated = [values.updated];
else throw new TypeError("The updated must be of type Temporal.Instant.");
clone.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url = this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url;
if ("url" in values && values.url != null) if (values.url instanceof URL || values.url instanceof Link) clone.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url = [values.url];
else throw new TypeError("The url must be of type URL | Link.");
if ("urls" in values && values.urls != null) {
if ("url" in values && values.url != null) throw new TypeError("Cannot update both url and urls at the same time.");
if (Array.isArray(values.urls) && values.urls.every((v) => v instanceof URL || v instanceof Link)) clone.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url = values.urls;
else throw new TypeError("The urls must be an array of type URL | Link.");
}
clone.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to;
if ("to" in values && values.to != null) if (values.to instanceof Object$1 || values.to instanceof URL) clone.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to = [values.to];
else throw new TypeError("The to must be of type Object | URL.");
if ("tos" in values && values.tos != null) {
if ("to" in values && values.to != null) throw new TypeError("Cannot update both to and tos at the same time.");
if (Array.isArray(values.tos) && values.tos.every((v) => v instanceof Object$1 || v instanceof URL)) clone.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to = values.tos;
else throw new TypeError("The tos must be an array of type Object | URL.");
}
clone.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto;
if ("bto" in values && values.bto != null) if (values.bto instanceof Object$1 || values.bto instanceof URL) clone.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto = [values.bto];
else throw new TypeError("The bto must be of type Object | URL.");
if ("btos" in values && values.btos != null) {
if ("bto" in values && values.bto != null) throw new TypeError("Cannot update both bto and btos at the same time.");
if (Array.isArray(values.btos) && values.btos.every((v) => v instanceof Object$1 || v instanceof URL)) clone.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto = values.btos;
else throw new TypeError("The btos must be an array of type Object | URL.");
}
clone.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc;
if ("cc" in values && values.cc != null) if (values.cc instanceof Object$1 || values.cc instanceof URL) clone.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc = [values.cc];
else throw new TypeError("The cc must be of type Object | URL.");
if ("ccs" in values && values.ccs != null) {
if ("cc" in values && values.cc != null) throw new TypeError("Cannot update both cc and ccs at the same time.");
if (Array.isArray(values.ccs) && values.ccs.every((v) => v instanceof Object$1 || v instanceof URL)) clone.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc = values.ccs;
else throw new TypeError("The ccs must be an array of type Object | URL.");
}
clone.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc;
if ("bcc" in values && values.bcc != null) if (values.bcc instanceof Object$1 || values.bcc instanceof URL) clone.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc = [values.bcc];
else throw new TypeError("The bcc must be of type Object | URL.");
if ("bccs" in values && values.bccs != null) {
if ("bcc" in values && values.bcc != null) throw new TypeError("Cannot update both bcc and bccs at the same time.");
if (Array.isArray(values.bccs) && values.bccs.every((v) => v instanceof Object$1 || v instanceof URL)) clone.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc = values.bccs;
else throw new TypeError("The bccs must be an array of type Object | URL.");
}
clone.#_3BLrzmscsjHCw8TF5BHRW9WkPnX8_mediaType = this.#_3BLrzmscsjHCw8TF5BHRW9WkPnX8_mediaType;
if ("mediaType" in values && values.mediaType != null) if (typeof values.mediaType === "string") clone.#_3BLrzmscsjHCw8TF5BHRW9WkPnX8_mediaType = [values.mediaType];
else throw new TypeError("The mediaType must be of type string.");
clone.#_3bNvLMBN1bCJETiTihM3wvi1B2JX_duration = this.#_3bNvLMBN1bCJETiTihM3wvi1B2JX_duration;
if ("duration" in values && values.duration != null) if (values.duration instanceof Temporal.Duration) clone.#_3bNvLMBN1bCJETiTihM3wvi1B2JX_duration = [values.duration];
else throw new TypeError("The duration must be of type Temporal.Duration.");
clone.#_u8gdcDTtChQ4tbSQMXc4cYWyum7_sensitive = this.#_u8gdcDTtChQ4tbSQMXc4cYWyum7_sensitive;
if ("sensitive" in values && values.sensitive != null) if (typeof values.sensitive === "boolean") clone.#_u8gdcDTtChQ4tbSQMXc4cYWyum7_sensitive = [values.sensitive];
else throw new TypeError("The sensitive must be of type boolean.");
clone.#_2ZwCFoS787v8y8bXKjMoE6MAbrEB_source = this.#_2ZwCFoS787v8y8bXKjMoE6MAbrEB_source;
if ("source" in values && values.source != null) if (values.source instanceof Source) clone.#_2ZwCFoS787v8y8bXKjMoE6MAbrEB_source = [values.source];
else throw new TypeError("The source must be of type Source.");
clone.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof;
if ("proof" in values && values.proof != null) if (values.proof instanceof DataIntegrityProof || values.proof instanceof URL) clone.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof = [values.proof];
else throw new TypeError("The proof must be of type DataIntegrityProof | URL.");
if ("proofs" in values && values.proofs != null) {
if ("proof" in values && values.proof != null) throw new TypeError("Cannot update both proof and proofs at the same time.");
if (Array.isArray(values.proofs) && values.proofs.every((v) => v instanceof DataIntegrityProof || v instanceof URL)) clone.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof = values.proofs;
else throw new TypeError("The proofs must be an array of type DataIntegrityProof | URL.");
}
return clone;
}
async #fetchAttachment(url, options = {}) {
const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader();
const contextLoader = options.contextLoader ?? this._contextLoader ?? getDocumentLoader();
const tracerProvider = options.tracerProvider ?? this._tracerProvider ?? trace.getTracerProvider();
const tracer = tracerProvider.getTracer("@fedify/fedify", "1.7.8");
return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => {
let fetchResult;
try {
fetchResult = await documentLoader(url.href);
} catch (error) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: String(error)
});
span.end();
if (options.suppressError) {
getLogger(["fedify", "vocab"]).error("Failed to fetch {url}: {error}", {
error,
url: url.href
});
return null;
}
throw error;
}
const { document } = fetchResult;
try {
const obj = await this.#attachment_fromJsonLd(document, {
documentLoader,
contextLoader,
tracerProvider
});
span.setAttribute("activitypub.object.id", (obj.id ?? url).href);
span.setAttribute("activitypub.object.type", obj.constructor.typeId.href);
return obj;
} catch (e) {
if (options.suppressError) {
getLogger(["fedify", "vocab"]).error("Failed to parse {url}: {error}", {
error: e,
url: url.href
});
return null;
}
span.setStatus({
code: SpanStatusCode.ERROR,
message: String(e)
});
throw e;
} finally {
span.end();
}
});
}
async #attachment_fromJsonLd(jsonLd, options) {
const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader();
const contextLoader = options.contextLoader ?? this._contextLoader ?? getDocumentLoader();
const tracerProvider = options.tracerProvider ?? this._tracerProvider ?? trace.getTracerProvider();
try {
return await Object$1.fromJsonLd(jsonLd, {
documentLoader,
contextLoader,
tracerProvider
});
} catch (e) {
if (!(e instanceof TypeError)) throw e;
}
try {
return await Link.fromJsonLd(jsonLd, {
documentLoader,
contextLoader,
tracerProvider
});
} catch (e) {
if (!(e instanceof TypeError)) throw e;
}
try {
return await PropertyValue.fromJsonLd(jsonLd, {
documentLoader,
contextLoader,
tracerProvider
});
} catch (e) {
if (!(e instanceof TypeError)) throw e;
}
throw new TypeError("Expected an object of any type of: " + [
"https://www.w3.org/ns/activitystreams#Object",
"https://www.w3.org/ns/activitystreams#Link",
"http://schema.org#PropertyValue"
].join(", "));
}
/**
* Similar to
* {@link Object.getAttachments},
* but returns their `@id`s instead of the objects themselves.
*/
get attachmentIds() {
if (this._warning != null) getLogger(this._warning.category).warn(this._warning.message, this._warning.values);
return this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment.map((v) => v instanceof URL ? v : v.id).filter((id) => id !== null);
}
/** Identifies a resource attached or related to an object that potentially
* requires special handling. The intent is to provide a model that is at
* least semantically similar to attachments in email.
*/
async *getAttachments(options = {}) {
if (this._warning != null) getLogger(this._warning.category).warn(this._warning.message, this._warning.values);
const vs = this.#_49BipA5dq9eoH8LX8x