From aac1aaf1c7f5f931d80597fc07e3346b76ab3b58 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Wed, 1 Jul 2026 11:01:23 +0900 Subject: [PATCH 1/3] Add FEP-7aa9 vocabulary support Add the FEP-7aa9 featured collection vocabulary to @fedify/vocab, including feature request, authorization, item, and collection types plus actor featuredCollections and canFeature policy support. Preload the FEP-7aa9 context and add the fixture, documentation, changelog entry, and JSON-LD round-trip coverage. Closes https://github.com/fedify-dev/fedify/issues/810 Assisted-by: Codex:gpt-5.5 --- CHANGES.md | 14 + FEDERATION.md | 10 + .../fedify/src/federation/handler.test.ts | 10 + .../src/fixtures/w3id.org/fep/7aa9.json | 24 + packages/vocab-runtime/src/contexts.ts | 2 + .../vocab-runtime/src/contexts/fep-7aa9.json | 24 + .../src/__snapshots__/class.test.ts.deno.snap | 59148 +++++++++------- .../src/__snapshots__/class.test.ts.node.snap | 59148 +++++++++------- .../src/__snapshots__/class.test.ts.snap | 59148 +++++++++------- .../src/__snapshots__/vocab.test.ts.snap | 609 + packages/vocab/src/application.yaml | 13 + packages/vocab/src/featureauthorization.yaml | 33 + packages/vocab/src/featuredcollection.yaml | 41 + packages/vocab/src/featureditem.yaml | 34 + packages/vocab/src/featurerequest.yaml | 21 + packages/vocab/src/group.yaml | 13 + packages/vocab/src/interactionpolicy.yaml | 17 +- packages/vocab/src/organization.yaml | 13 + packages/vocab/src/person.yaml | 13 + packages/vocab/src/service.yaml | 13 + packages/vocab/src/vocab.test.ts | 256 + 21 files changed, 97255 insertions(+), 81349 deletions(-) create mode 100644 packages/fixture/src/fixtures/w3id.org/fep/7aa9.json create mode 100644 packages/vocab-runtime/src/contexts/fep-7aa9.json create mode 100644 packages/vocab/src/featureauthorization.yaml create mode 100644 packages/vocab/src/featuredcollection.yaml create mode 100644 packages/vocab/src/featureditem.yaml create mode 100644 packages/vocab/src/featurerequest.yaml diff --git a/CHANGES.md b/CHANGES.md index 8bd936766..378cb96db 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,9 +16,23 @@ To be released. serialization emits canonical `ap+ef61:` values with decoded DID authorities. [[#826], [#850]] + - Added vocabulary support for [FEP-7aa9], including + `FeaturedCollection`, `FeaturedItem`, `FeatureRequest`, and + `FeatureAuthorization`, plus actor `featuredCollections` and + `InteractionPolicy.canFeature` properties. [[#810], [#914]] + [FEP-ef61]: https://w3id.org/fep/ef61 +[FEP-7aa9]: https://w3id.org/fep/7aa9 +[#810]: https://github.com/fedify-dev/fedify/issues/810 [#826]: https://github.com/fedify-dev/fedify/issues/826 [#850]: https://github.com/fedify-dev/fedify/pull/850 +[#914]: https://github.com/fedify-dev/fedify/pull/914 + +### @fedify/vocab-runtime + + - Added the [FEP-7aa9] JSON-LD context to the preloaded context registry so + FEP-7aa9 documents can be compacted and expanded without fetching the + context remotely. [[#810], [#914]] Version 2.3.1 diff --git a/FEDERATION.md b/FEDERATION.md index 71c7a68bd..ff8c9f568 100644 --- a/FEDERATION.md +++ b/FEDERATION.md @@ -37,6 +37,7 @@ Supported FEPs - [FEP-e232][]: Object Links - [FEP-5711][]: Inverse Properties for Collections - [FEP-044f][]: Consent-respecting quote posts + - [FEP-7aa9][]: Featuring recommendations using a dedicated collection - [FEP-0837][]: Federated Marketplace - [FEP-ae0c][]: Fediverse Relay Protocols: Mastodon and LitePub @@ -53,6 +54,7 @@ Supported FEPs [FEP-e232]: https://w3id.org/fep/e232 [FEP-5711]: https://w3id.org/fep/5711 [FEP-044f]: https://w3id.org/fep/044f +[FEP-7aa9]: https://w3id.org/fep/7aa9 [FEP-0837]: https://w3id.org/fep/0837 [FEP-ae0c]: https://w3id.org/fep/ae0c @@ -78,6 +80,7 @@ fediverse. - [`Delete`] - [`Dislike`] - [`EmojiReact`] + - [`FeatureRequest`] ([FEP-7aa9]) - [`Flag`] - [`Follow`] - [`Ignore`] @@ -113,6 +116,7 @@ fediverse. [`Delete`]: https://jsr.io/@fedify/vocab/doc/~/Delete [`Dislike`]: https://jsr.io/@fedify/vocab/doc/~/Dislike [`EmojiReact`]: https://jsr.io/@fedify/vocab/doc/~/EmojiReact +[`FeatureRequest`]: https://jsr.io/@fedify/vocab/doc/~/FeatureRequest [`Flag`]: https://jsr.io/@fedify/vocab/doc/~/Flag [`Follow`]: https://jsr.io/@fedify/vocab/doc/~/Follow [`Ignore`]: https://jsr.io/@fedify/vocab/doc/~/Ignore @@ -158,6 +162,8 @@ fediverse. - [`Audio`] - [`Document`] - [`Event`] + - [`FeatureAuthorization`] ([FEP-7aa9]) + - [`FeaturedItem`] ([FEP-7aa9]) - [`Image`] - [`LikeAuthorization`] (GoToSocial extension) - [`Note`] @@ -175,6 +181,8 @@ fediverse. [`Audio`]: https://jsr.io/@fedify/vocab/doc/~/Audio [`Document`]: https://jsr.io/@fedify/vocab/doc/~/Document [`Event`]: https://jsr.io/@fedify/vocab/doc/~/Event +[`FeatureAuthorization`]: https://jsr.io/@fedify/vocab/doc/~/FeatureAuthorization +[`FeaturedItem`]: https://jsr.io/@fedify/vocab/doc/~/FeaturedItem [`Image`]: https://jsr.io/@fedify/vocab/doc/~/Image [`LikeAuthorization`]: https://jsr.io/@fedify/vocab/doc/~/LikeAuthorization [`Note`]: https://jsr.io/@fedify/vocab/doc/~/Note @@ -191,11 +199,13 @@ fediverse. - [`Collection`] - [`CollectionPage`] + - [`FeaturedCollection`] ([FEP-7aa9]) - [`OrderedCollection`] - [`OrderedCollectionPage`] [`Collection`]: https://jsr.io/@fedify/vocab/doc/~/Collection [`CollectionPage`]: https://jsr.io/@fedify/vocab/doc/~/CollectionPage +[`FeaturedCollection`]: https://jsr.io/@fedify/vocab/doc/~/FeaturedCollection [`OrderedCollection`]: https://jsr.io/@fedify/vocab/doc/~/OrderedCollection [`OrderedCollectionPage`]: https://jsr.io/@fedify/vocab/doc/~/OrderedCollectionPage diff --git a/packages/fedify/src/federation/handler.test.ts b/packages/fedify/src/federation/handler.test.ts index d16ad2bb2..dfe50c38b 100644 --- a/packages/fedify/src/federation/handler.test.ts +++ b/packages/fedify/src/federation/handler.test.ts @@ -175,11 +175,16 @@ test("handleActor()", async () => { "https://www.w3.org/ns/did/v1", "https://w3id.org/security/multikey/v1", "https://gotosocial.org/ns", + "https://w3id.org/fep/7aa9", { alsoKnownAs: { "@id": "as:alsoKnownAs", "@type": "@id", }, + featuredCollections: { + "@id": "https://w3id.org/fep/7aa9#featuredCollections", + "@type": "@id", + }, manuallyApprovesFollowers: "as:manuallyApprovesFollowers", movedTo: { "@id": "as:movedTo", @@ -278,11 +283,16 @@ test("handleActor()", async () => { "https://www.w3.org/ns/did/v1", "https://w3id.org/security/multikey/v1", "https://gotosocial.org/ns", + "https://w3id.org/fep/7aa9", { alsoKnownAs: { "@id": "as:alsoKnownAs", "@type": "@id", }, + featuredCollections: { + "@id": "https://w3id.org/fep/7aa9#featuredCollections", + "@type": "@id", + }, manuallyApprovesFollowers: "as:manuallyApprovesFollowers", movedTo: { "@id": "as:movedTo", diff --git a/packages/fixture/src/fixtures/w3id.org/fep/7aa9.json b/packages/fixture/src/fixtures/w3id.org/fep/7aa9.json new file mode 100644 index 000000000..fb725ac81 --- /dev/null +++ b/packages/fixture/src/fixtures/w3id.org/fep/7aa9.json @@ -0,0 +1,24 @@ +{ + "@context": { + "FeaturedCollection": "https://w3id.org/fep/7aa9#FeaturedCollection", + "FeaturedItem": "https://w3id.org/fep/7aa9#FeaturedItem", + "FeatureRequest": "https://w3id.org/fep/7aa9#FeatureRequest", + "FeatureAuthorization": "https://w3id.org/fep/7aa9#FeatureAuthorization", + "topic": { + "@id": "https://w3id.org/fep/7aa9#topic", + "@type": "@id" + }, + "featuredObject": { + "@id": "https://w3id.org/fep/7aa9#featuredObject", + "@type": "@id" + }, + "canFeature": { + "@id": "https://w3id.org/fep/7aa9#canFeature", + "@type": "@id" + }, + "featureAuthorization": { + "@id": "https://w3id.org/fep/7aa9#featureAuthorization", + "@type": "@id" + } + } +} diff --git a/packages/vocab-runtime/src/contexts.ts b/packages/vocab-runtime/src/contexts.ts index e77a3350d..0331ef1eb 100644 --- a/packages/vocab-runtime/src/contexts.ts +++ b/packages/vocab-runtime/src/contexts.ts @@ -6,6 +6,7 @@ import activitystreams from "./contexts/activitystreams.json" with { type: "json", }; import didV1 from "./contexts/did-v1.json" with { type: "json" }; +import fep7aa9 from "./contexts/fep-7aa9.json" with { type: "json" }; import fep5711 from "./contexts/fep-5711.json" with { type: "json" }; import gotosocial from "./contexts/gotosocial.json" with { type: "json" }; import identityV1 from "./contexts/identity-v1.json" with { type: "json" }; @@ -35,6 +36,7 @@ const preloadedContexts: Record = { "http://schema.org/": schemaorg, "https://gotosocial.org/ns": gotosocial, "https://w3id.org/fep/5711": fep5711, + "https://w3id.org/fep/7aa9": fep7aa9, // Lemmy's context document is served as application/json without the JSON-LD // context Link header. The default document loader treats that as a regular diff --git a/packages/vocab-runtime/src/contexts/fep-7aa9.json b/packages/vocab-runtime/src/contexts/fep-7aa9.json new file mode 100644 index 000000000..fb725ac81 --- /dev/null +++ b/packages/vocab-runtime/src/contexts/fep-7aa9.json @@ -0,0 +1,24 @@ +{ + "@context": { + "FeaturedCollection": "https://w3id.org/fep/7aa9#FeaturedCollection", + "FeaturedItem": "https://w3id.org/fep/7aa9#FeaturedItem", + "FeatureRequest": "https://w3id.org/fep/7aa9#FeatureRequest", + "FeatureAuthorization": "https://w3id.org/fep/7aa9#FeatureAuthorization", + "topic": { + "@id": "https://w3id.org/fep/7aa9#topic", + "@type": "@id" + }, + "featuredObject": { + "@id": "https://w3id.org/fep/7aa9#featuredObject", + "@type": "@id" + }, + "canFeature": { + "@id": "https://w3id.org/fep/7aa9#canFeature", + "@type": "@id" + }, + "featureAuthorization": { + "@id": "https://w3id.org/fep/7aa9#featureAuthorization", + "@type": "@id" + } + } +} diff --git a/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap b/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap index 054901727..7240186a4 100644 --- a/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap +++ b/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap @@ -36,7 +36,7 @@ import { isTemporalInstant, } from \\"@fedify/vocab-runtime/temporal\\"; const PORTABLE_IRI_PATTERN = /^ap(?:\\\\+ef61)?:\\\\/\\\\//i; -const PORTABLE_IRI_KEYS: ReadonlySet = new Set([\\"@id\\",\\"_misskey_quote\\",\\"actor\\",\\"alsoKnownAs\\",\\"announceAuthorization\\",\\"anyOf\\",\\"approvedBy\\",\\"assertionMethod\\",\\"attachment\\",\\"attributedTo\\",\\"audience\\",\\"automaticApproval\\",\\"bcc\\",\\"bto\\",\\"cc\\",\\"context\\",\\"controller\\",\\"current\\",\\"describes\\",\\"emojiReactions\\",\\"featured\\",\\"featuredTags\\",\\"first\\",\\"followers\\",\\"followersOf\\",\\"following\\",\\"followingOf\\",\\"generator\\",\\"href\\",\\"http://fedibird.com/ns#emojiReactions\\",\\"http://fedibird.com/ns#quoteUri\\",\\"http://joinmastodon.org/ns#featured\\",\\"http://joinmastodon.org/ns#featuredTags\\",\\"http://www.w3.org/ns/ldp#inbox\\",\\"https://gotosocial.org/ns#announceAuthorization\\",\\"https://gotosocial.org/ns#approvedBy\\",\\"https://gotosocial.org/ns#automaticApproval\\",\\"https://gotosocial.org/ns#interactingObject\\",\\"https://gotosocial.org/ns#interactionTarget\\",\\"https://gotosocial.org/ns#likeAuthorization\\",\\"https://gotosocial.org/ns#manualApproval\\",\\"https://gotosocial.org/ns#replyAuthorization\\",\\"https://misskey-hub.net/ns#_misskey_quote\\",\\"https://w3id.org/fep/044f#quote\\",\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"https://w3id.org/fep/5711#followersOf\\",\\"https://w3id.org/fep/5711#followingOf\\",\\"https://w3id.org/fep/5711#inboxOf\\",\\"https://w3id.org/fep/5711#likedOf\\",\\"https://w3id.org/fep/5711#likesOf\\",\\"https://w3id.org/fep/5711#outboxOf\\",\\"https://w3id.org/fep/5711#repliesOf\\",\\"https://w3id.org/fep/5711#sharesOf\\",\\"https://w3id.org/security#assertionMethod\\",\\"https://w3id.org/security#controller\\",\\"https://w3id.org/security#owner\\",\\"https://w3id.org/security#proof\\",\\"https://w3id.org/security#publicKey\\",\\"https://w3id.org/security#verificationMethod\\",\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\",\\"https://w3id.org/valueflows/ont/vf#satisfies\\",\\"https://www.w3.org/ns/activitystreams#actor\\",\\"https://www.w3.org/ns/activitystreams#alsoKnownAs\\",\\"https://www.w3.org/ns/activitystreams#anyOf\\",\\"https://www.w3.org/ns/activitystreams#attachment\\",\\"https://www.w3.org/ns/activitystreams#attributedTo\\",\\"https://www.w3.org/ns/activitystreams#audience\\",\\"https://www.w3.org/ns/activitystreams#bcc\\",\\"https://www.w3.org/ns/activitystreams#bto\\",\\"https://www.w3.org/ns/activitystreams#cc\\",\\"https://www.w3.org/ns/activitystreams#context\\",\\"https://www.w3.org/ns/activitystreams#current\\",\\"https://www.w3.org/ns/activitystreams#describes\\",\\"https://www.w3.org/ns/activitystreams#first\\",\\"https://www.w3.org/ns/activitystreams#followers\\",\\"https://www.w3.org/ns/activitystreams#following\\",\\"https://www.w3.org/ns/activitystreams#generator\\",\\"https://www.w3.org/ns/activitystreams#href\\",\\"https://www.w3.org/ns/activitystreams#icon\\",\\"https://www.w3.org/ns/activitystreams#image\\",\\"https://www.w3.org/ns/activitystreams#inReplyTo\\",\\"https://www.w3.org/ns/activitystreams#instrument\\",\\"https://www.w3.org/ns/activitystreams#items\\",\\"https://www.w3.org/ns/activitystreams#last\\",\\"https://www.w3.org/ns/activitystreams#liked\\",\\"https://www.w3.org/ns/activitystreams#likes\\",\\"https://www.w3.org/ns/activitystreams#location\\",\\"https://www.w3.org/ns/activitystreams#movedTo\\",\\"https://www.w3.org/ns/activitystreams#next\\",\\"https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint\\",\\"https://www.w3.org/ns/activitystreams#oauthTokenEndpoint\\",\\"https://www.w3.org/ns/activitystreams#object\\",\\"https://www.w3.org/ns/activitystreams#oneOf\\",\\"https://www.w3.org/ns/activitystreams#origin\\",\\"https://www.w3.org/ns/activitystreams#outbox\\",\\"https://www.w3.org/ns/activitystreams#partOf\\",\\"https://www.w3.org/ns/activitystreams#prev\\",\\"https://www.w3.org/ns/activitystreams#preview\\",\\"https://www.w3.org/ns/activitystreams#provideClientKey\\",\\"https://www.w3.org/ns/activitystreams#proxyUrl\\",\\"https://www.w3.org/ns/activitystreams#quoteUrl\\",\\"https://www.w3.org/ns/activitystreams#relationship\\",\\"https://www.w3.org/ns/activitystreams#replies\\",\\"https://www.w3.org/ns/activitystreams#result\\",\\"https://www.w3.org/ns/activitystreams#sharedInbox\\",\\"https://www.w3.org/ns/activitystreams#shares\\",\\"https://www.w3.org/ns/activitystreams#signClientKey\\",\\"https://www.w3.org/ns/activitystreams#streams\\",\\"https://www.w3.org/ns/activitystreams#subject\\",\\"https://www.w3.org/ns/activitystreams#tag\\",\\"https://www.w3.org/ns/activitystreams#target\\",\\"https://www.w3.org/ns/activitystreams#to\\",\\"https://www.w3.org/ns/activitystreams#units\\",\\"https://www.w3.org/ns/activitystreams#url\\",\\"https://www.w3.org/ns/did#service\\",\\"https://www.w3.org/ns/did#serviceEndpoint\\",\\"icon\\",\\"id\\",\\"image\\",\\"inReplyTo\\",\\"inbox\\",\\"inboxOf\\",\\"instrument\\",\\"interactingObject\\",\\"interactionTarget\\",\\"items\\",\\"last\\",\\"likeAuthorization\\",\\"liked\\",\\"likedOf\\",\\"likes\\",\\"likesOf\\",\\"location\\",\\"manualApproval\\",\\"movedTo\\",\\"next\\",\\"oauthAuthorizationEndpoint\\",\\"oauthTokenEndpoint\\",\\"object\\",\\"oneOf\\",\\"orderedItems\\",\\"origin\\",\\"outbox\\",\\"outboxOf\\",\\"owner\\",\\"partOf\\",\\"prev\\",\\"preview\\",\\"proof\\",\\"provideClientKey\\",\\"proxyUrl\\",\\"publicKey\\",\\"quote\\",\\"quoteAuthorization\\",\\"quoteUri\\",\\"quoteUrl\\",\\"relationship\\",\\"replies\\",\\"repliesOf\\",\\"replyAuthorization\\",\\"resourceConformsTo\\",\\"result\\",\\"satisfies\\",\\"service\\",\\"sharedInbox\\",\\"shares\\",\\"sharesOf\\",\\"signClientKey\\",\\"streams\\",\\"subject\\",\\"tag\\",\\"target\\",\\"to\\",\\"units\\",\\"url\\"]); +const PORTABLE_IRI_KEYS: ReadonlySet = new Set([\\"@id\\",\\"_misskey_quote\\",\\"actor\\",\\"alsoKnownAs\\",\\"announceAuthorization\\",\\"anyOf\\",\\"approvedBy\\",\\"assertionMethod\\",\\"attachment\\",\\"attributedTo\\",\\"audience\\",\\"automaticApproval\\",\\"bcc\\",\\"bto\\",\\"cc\\",\\"context\\",\\"controller\\",\\"current\\",\\"describes\\",\\"emojiReactions\\",\\"featureAuthorization\\",\\"featured\\",\\"featuredCollections\\",\\"featuredObject\\",\\"featuredTags\\",\\"first\\",\\"followers\\",\\"followersOf\\",\\"following\\",\\"followingOf\\",\\"generator\\",\\"href\\",\\"http://fedibird.com/ns#emojiReactions\\",\\"http://fedibird.com/ns#quoteUri\\",\\"http://joinmastodon.org/ns#featured\\",\\"http://joinmastodon.org/ns#featuredTags\\",\\"http://www.w3.org/ns/ldp#inbox\\",\\"https://gotosocial.org/ns#announceAuthorization\\",\\"https://gotosocial.org/ns#approvedBy\\",\\"https://gotosocial.org/ns#automaticApproval\\",\\"https://gotosocial.org/ns#interactingObject\\",\\"https://gotosocial.org/ns#interactionTarget\\",\\"https://gotosocial.org/ns#likeAuthorization\\",\\"https://gotosocial.org/ns#manualApproval\\",\\"https://gotosocial.org/ns#replyAuthorization\\",\\"https://misskey-hub.net/ns#_misskey_quote\\",\\"https://w3id.org/fep/044f#quote\\",\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"https://w3id.org/fep/5711#followersOf\\",\\"https://w3id.org/fep/5711#followingOf\\",\\"https://w3id.org/fep/5711#inboxOf\\",\\"https://w3id.org/fep/5711#likedOf\\",\\"https://w3id.org/fep/5711#likesOf\\",\\"https://w3id.org/fep/5711#outboxOf\\",\\"https://w3id.org/fep/5711#repliesOf\\",\\"https://w3id.org/fep/5711#sharesOf\\",\\"https://w3id.org/fep/7aa9#featureAuthorization\\",\\"https://w3id.org/fep/7aa9#featuredCollections\\",\\"https://w3id.org/fep/7aa9#featuredObject\\",\\"https://w3id.org/security#assertionMethod\\",\\"https://w3id.org/security#controller\\",\\"https://w3id.org/security#owner\\",\\"https://w3id.org/security#proof\\",\\"https://w3id.org/security#publicKey\\",\\"https://w3id.org/security#verificationMethod\\",\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\",\\"https://w3id.org/valueflows/ont/vf#satisfies\\",\\"https://www.w3.org/ns/activitystreams#actor\\",\\"https://www.w3.org/ns/activitystreams#alsoKnownAs\\",\\"https://www.w3.org/ns/activitystreams#anyOf\\",\\"https://www.w3.org/ns/activitystreams#attachment\\",\\"https://www.w3.org/ns/activitystreams#attributedTo\\",\\"https://www.w3.org/ns/activitystreams#audience\\",\\"https://www.w3.org/ns/activitystreams#bcc\\",\\"https://www.w3.org/ns/activitystreams#bto\\",\\"https://www.w3.org/ns/activitystreams#cc\\",\\"https://www.w3.org/ns/activitystreams#context\\",\\"https://www.w3.org/ns/activitystreams#current\\",\\"https://www.w3.org/ns/activitystreams#describes\\",\\"https://www.w3.org/ns/activitystreams#first\\",\\"https://www.w3.org/ns/activitystreams#followers\\",\\"https://www.w3.org/ns/activitystreams#following\\",\\"https://www.w3.org/ns/activitystreams#generator\\",\\"https://www.w3.org/ns/activitystreams#href\\",\\"https://www.w3.org/ns/activitystreams#icon\\",\\"https://www.w3.org/ns/activitystreams#image\\",\\"https://www.w3.org/ns/activitystreams#inReplyTo\\",\\"https://www.w3.org/ns/activitystreams#instrument\\",\\"https://www.w3.org/ns/activitystreams#items\\",\\"https://www.w3.org/ns/activitystreams#last\\",\\"https://www.w3.org/ns/activitystreams#liked\\",\\"https://www.w3.org/ns/activitystreams#likes\\",\\"https://www.w3.org/ns/activitystreams#location\\",\\"https://www.w3.org/ns/activitystreams#movedTo\\",\\"https://www.w3.org/ns/activitystreams#next\\",\\"https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint\\",\\"https://www.w3.org/ns/activitystreams#oauthTokenEndpoint\\",\\"https://www.w3.org/ns/activitystreams#object\\",\\"https://www.w3.org/ns/activitystreams#oneOf\\",\\"https://www.w3.org/ns/activitystreams#origin\\",\\"https://www.w3.org/ns/activitystreams#outbox\\",\\"https://www.w3.org/ns/activitystreams#partOf\\",\\"https://www.w3.org/ns/activitystreams#prev\\",\\"https://www.w3.org/ns/activitystreams#preview\\",\\"https://www.w3.org/ns/activitystreams#provideClientKey\\",\\"https://www.w3.org/ns/activitystreams#proxyUrl\\",\\"https://www.w3.org/ns/activitystreams#quoteUrl\\",\\"https://www.w3.org/ns/activitystreams#relationship\\",\\"https://www.w3.org/ns/activitystreams#replies\\",\\"https://www.w3.org/ns/activitystreams#result\\",\\"https://www.w3.org/ns/activitystreams#sharedInbox\\",\\"https://www.w3.org/ns/activitystreams#shares\\",\\"https://www.w3.org/ns/activitystreams#signClientKey\\",\\"https://www.w3.org/ns/activitystreams#streams\\",\\"https://www.w3.org/ns/activitystreams#subject\\",\\"https://www.w3.org/ns/activitystreams#tag\\",\\"https://www.w3.org/ns/activitystreams#target\\",\\"https://www.w3.org/ns/activitystreams#to\\",\\"https://www.w3.org/ns/activitystreams#units\\",\\"https://www.w3.org/ns/activitystreams#url\\",\\"https://www.w3.org/ns/did#service\\",\\"https://www.w3.org/ns/did#serviceEndpoint\\",\\"icon\\",\\"id\\",\\"image\\",\\"inReplyTo\\",\\"inbox\\",\\"inboxOf\\",\\"instrument\\",\\"interactingObject\\",\\"interactionTarget\\",\\"items\\",\\"last\\",\\"likeAuthorization\\",\\"liked\\",\\"likedOf\\",\\"likes\\",\\"likesOf\\",\\"location\\",\\"manualApproval\\",\\"movedTo\\",\\"next\\",\\"oauthAuthorizationEndpoint\\",\\"oauthTokenEndpoint\\",\\"object\\",\\"oneOf\\",\\"orderedItems\\",\\"origin\\",\\"outbox\\",\\"outboxOf\\",\\"owner\\",\\"partOf\\",\\"prev\\",\\"preview\\",\\"proof\\",\\"provideClientKey\\",\\"proxyUrl\\",\\"publicKey\\",\\"quote\\",\\"quoteAuthorization\\",\\"quoteUri\\",\\"quoteUrl\\",\\"relationship\\",\\"replies\\",\\"repliesOf\\",\\"replyAuthorization\\",\\"resourceConformsTo\\",\\"result\\",\\"satisfies\\",\\"service\\",\\"sharedInbox\\",\\"shares\\",\\"sharesOf\\",\\"signClientKey\\",\\"streams\\",\\"subject\\",\\"tag\\",\\"target\\",\\"to\\",\\"units\\",\\"url\\"]); import * as _ppM0 from \\"./preprocessors.ts\\"; @@ -10682,6 +10682,14 @@ get urls(): ((URL | Link))[] { return await QuoteAuthorization.fromJsonLd(json, options); } + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\")) { + return await FeatureAuthorization.fromJsonLd(json, options); + } + + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeaturedItem\\")) { + return await FeaturedItem.fromJsonLd(json, options); + } + if (values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Agreement\\")) { return await Agreement.fromJsonLd(json, options); } @@ -10714,6 +10722,10 @@ get urls(): ((URL | Link))[] { return await QuoteRequest.fromJsonLd(json, options); } + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeatureRequest\\")) { + return await FeatureRequest.fromJsonLd(json, options); + } + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Accept\\")) { return await Accept.fromJsonLd(json, options); } @@ -10854,6 +10866,10 @@ get urls(): ((URL | Link))[] { return await OrderedCollection.fromJsonLd(json, options); } + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeaturedCollection\\")) { + return await FeaturedCollection.fromJsonLd(json, options); + } + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Document\\")) { return await Document.fromJsonLd(json, options); } @@ -10960,7 +10976,7 @@ get urls(): ((URL | Link))[] { const decoded = typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -11108,7 +11124,7 @@ get urls(): ((URL | Link))[] { const decoded = typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -11194,7 +11210,7 @@ get urls(): ((URL | Link))[] { const decoded = typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -11338,7 +11354,7 @@ get urls(): ((URL | Link))[] { const decoded = typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -11378,7 +11394,7 @@ get urls(): ((URL | Link))[] { const decoded = typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -11423,7 +11439,7 @@ get urls(): ((URL | Link))[] { v, { ...options, baseUrl: options.baseUrl } ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -11646,7 +11662,7 @@ get urls(): ((URL | Link))[] { const decoded = typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } @@ -17504,6 +17520,10 @@ instruments?: (Object | URL)[];} return await QuoteRequest.fromJsonLd(json, options); } + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeatureRequest\\")) { + return await FeatureRequest.fromJsonLd(json, options); + } + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Accept\\")) { return await Accept.fromJsonLd(json, options); } @@ -21145,7 +21165,8 @@ export class InteractionPolicy { static get typeId(): URL { return new URL(\\"https://gotosocial.org/ns#InteractionPolicy\\"); } - #_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike: (InteractionRule)[] = []; + #_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature: (InteractionRule)[] = []; +#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike: (InteractionRule)[] = []; #_2UBgLRi5p3DRGGvWyB227i4Qjhzd_canReply: (InteractionRule)[] = []; #_fu5nmoAj528fBQfnxhY9Daok3Vi_canAnnounce: (InteractionRule)[] = []; #_LE3zBTVacTZw2LSyLt4wVUkXeUy_canQuote: (InteractionRule)[] = []; @@ -21159,7 +21180,7 @@ export class InteractionPolicy { values: { id?: URL | null; -canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: InteractionRule | null;canQuote?: InteractionRule | null;} +canFeature?: InteractionRule | null;canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: InteractionRule | null;canQuote?: InteractionRule | null;} , options: { documentLoader?: DocumentLoader, @@ -21186,6 +21207,19 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: throw new TypeError(\\"The id must be a URL.\\"); } + if (\\"canFeature\\" in values && values.canFeature != null) { + if (values.canFeature instanceof InteractionRule) { + // @ts-ignore: type is checked above. + this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature = [values.canFeature]; + + } else { + throw new TypeError( + \\"The canFeature must be of type \\" + + \\"InteractionRule\\" + \\".\\", + ); + } + } + if (\\"canLike\\" in values && values.canLike != null) { if (values.canLike instanceof InteractionRule) { // @ts-ignore: type is checked above. @@ -21249,7 +21283,7 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: values: { id?: URL | null; -canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: InteractionRule | null;canQuote?: InteractionRule | null;} +canFeature?: InteractionRule | null;canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: InteractionRule | null;canQuote?: InteractionRule | null;} = {}, options: { @@ -21271,7 +21305,20 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: { id: values.id ?? this.id }, options ); - clone.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike = this.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike; + clone.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature = this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature; + if (\\"canFeature\\" in values && values.canFeature != null) { + if (values.canFeature instanceof InteractionRule) { + // @ts-ignore: type is checked above. + clone.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature = [values.canFeature]; + + } else { + throw new TypeError( + \\"The canFeature must be of type \\" + + \\"InteractionRule\\" + \\".\\", + ); + } + } + clone.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike = this.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike; if (\\"canLike\\" in values && values.canLike != null) { if (values.canLike instanceof InteractionRule) { // @ts-ignore: type is checked above. @@ -21327,6 +21374,23 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: return clone; } +/** The sub-policy specifying who can feature the actor in a + * {@link FeaturedCollection}. + * + * See [FEP-7aa9](https://w3id.org/fep/7aa9) for details. + * + */ + get canFeature(): (InteractionRule | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature.length < 1) return null; + return this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature[0]; + } + /** The sub-policy specifying who can like the post. * * When absent, implementations should assume that anyone can like the post @@ -21427,6 +21491,21 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: // deno-lint-ignore no-unused-vars prefer-const let array: unknown[]; const values: Record = {}; + array = []; + for (const v of this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/7aa9#canFeature\\"] = propValue; + + } + array = []; for (const v of this.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike) { const element = ( @@ -21496,7 +21575,7 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: ); } const docContext = options.context ?? - \\"https://gotosocial.org/ns\\"; + [\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\"]; const compacted = await jsonld.compact( values, docContext, @@ -21511,6 +21590,11 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: protected isCompactable(): boolean { + if ( + this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature != null && + this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature.length > 0 + ) return false; + if ( this.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike != null && this.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike.length > 0 @@ -21650,6 +21734,27 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: }, options, ); + const _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature: (InteractionRule)[] = []; + + let _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature__array = values[\\"https://w3id.org/fep/7aa9#canFeature\\"]; + + for ( + const v of _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature__array == null + ? [] + : _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature__array.length === 1 && \\"@list\\" in _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature__array[0] + ? _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature__array[0][\\"@list\\"] + : _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature__array + ) { + if (v == null) continue; + + const decoded = await InteractionRule.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature.push(decoded); + } + instance.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature = _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature; const _3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike: (InteractionRule)[] = []; let _3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike__array = values[\\"https://gotosocial.org/ns#canLike\\"]; @@ -21777,6 +21882,26 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: }; } + const _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature = this.#_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature.length == 1) { + proxy.canFeature = _2hdwkUHmthzVPdo1ttxKsP7AGKka_canFeature[0]; + } + const _3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike = this.#_3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike // deno-lint-ignore no-explicit-any .map((v: any) => v instanceof URL @@ -26856,68 +26981,29 @@ instruments?: (Object | URL)[];} const proxy = this._getCustomInspectProxy(); return \\"QuoteRequest \\" + inspect(proxy, options); }; - /** Means of communicating or interacting with the DID subject or associated - * entities via one or more service endpoints. Examples include discovery - * services, agent services, social networking services, file storage services, - * and verifiable credential repository services. + /** Proves that an actor consented to being included in a + * {@link FeaturedCollection}. + * + * See [FEP-7aa9](https://w3id.org/fep/7aa9) for details. * */ -export class DidService { - - readonly #documentLoader?: DocumentLoader; - readonly #contextLoader?: DocumentLoader; - readonly #tracerProvider?: TracerProvider; - readonly #warning?: { - category: string[]; - message: string; - values?: Record; - }; - #cachedJsonLd?: unknown; - readonly #_baseUrl?: URL; - readonly id: URL | null; - - protected get _documentLoader(): DocumentLoader | undefined { - return this.#documentLoader; - } - - protected get _contextLoader(): DocumentLoader | undefined { - return this.#contextLoader; - } - - protected get _tracerProvider(): TracerProvider | undefined { - return this.#tracerProvider; - } - - protected get _warning(): { - category: string[]; - message: string; - values?: Record; - } | undefined { - return this.#warning; - } - - protected get _cachedJsonLd(): unknown | undefined { - return this.#cachedJsonLd; - } - - protected set _cachedJsonLd(value: unknown | undefined) { - this.#cachedJsonLd = value; - } +export class FeatureAuthorization extends Object { - protected get _baseUrl(): URL | undefined { - return this.#_baseUrl; - } - /** - * The type URI of {@link DidService}: \`https://www.w3.org/ns/did#Service\`. + * The type URI of {@link FeatureAuthorization}: \`https://w3id.org/fep/7aa9#FeatureAuthorization\`. */ - static get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/did#Service\\"); + static override get typeId(): URL { + return new URL(\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\"); } - #_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; - + + #_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject: (Object | URL)[] = []; + #_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject: Set = new Set(); + + #_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget: (Object | URL)[] = []; + #_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget: Set = new Set(); + /** - * Constructs a new instance of DidService with the given values. + * Constructs a new instance of FeatureAuthorization with the given values. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ @@ -26925,8 +27011,23 @@ export class DidService { values: { id?: URL | null; -endpoint?: URL | null; -endpoints?: (URL)[];} +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;interactingObject?: Object | URL | null;interactionTarget?: Object | URL | null;} , options: { documentLoader?: DocumentLoader, @@ -26934,57 +27035,29 @@ endpoints?: (URL)[];} tracerProvider?: TracerProvider, } = {}, ) { - - this.#documentLoader = options.documentLoader; - this.#contextLoader = options.contextLoader; - this.#tracerProvider = options.tracerProvider; - const baseUrl = (options as { baseUrl?: URL }).baseUrl; - this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); - if (\\"\$warning\\" in options) { - this.#warning = options.\$warning as unknown as { - category: string[]; - message: string; - values?: Record; - }; - } - if (values.id == null || values.id instanceof URL) { - this.id = values.id ?? null; - } else { - throw new TypeError(\\"The id must be a URL.\\"); - } - - if (\\"endpoint\\" in values && values.endpoint != null) { - if (values.endpoint instanceof URL) { + super(values, options); + if (\\"interactingObject\\" in values && values.interactingObject != null) { + if (values.interactingObject instanceof Object || values.interactingObject instanceof URL) { // @ts-ignore: type is checked above. - this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = [values.endpoint]; - + this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = [values.interactingObject]; + this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.add(0); } else { throw new TypeError( - \\"The endpoint must be of type \\" + - \\"URL\\" + \\".\\", + \\"The interactingObject must be of type \\" + + \\"Object | URL\\" + \\".\\", ); } } - if (\\"endpoints\\" in values && values.endpoints != null) { - - if (\\"endpoint\\" in values && - values.endpoint != null) { - throw new TypeError( - \\"Cannot initialize both endpoint and \\" + - \\"endpoints at the same time.\\", - ); - } - - if (Array.isArray(values.endpoints) && - values.endpoints.every(v => v instanceof URL)) { + if (\\"interactionTarget\\" in values && values.interactionTarget != null) { + if (values.interactionTarget instanceof Object || values.interactionTarget instanceof URL) { // @ts-ignore: type is checked above. - this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = values.endpoints; - + this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = [values.interactionTarget]; + this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.add(0); } else { throw new TypeError( - \\"The endpoints must be an array of type \\" + - \\"URL\\" + \\".\\", + \\"The interactionTarget must be of type \\" + + \\"Object | URL\\" + \\".\\", ); } } @@ -26996,19 +27069,34 @@ endpoints?: (URL)[];} * @param options The options to use for cloning. * @returns The cloned instance. */ - clone( + override clone( values: { id?: URL | null; -endpoint?: URL | null; -endpoints?: (URL)[];} +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;interactingObject?: Object | URL | null;interactionTarget?: Object | URL | null;} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): DidService { + ): FeatureAuthorization { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -27017,45 +27105,29 @@ endpoints?: (URL)[];} // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - - // @ts-ignore: this.constructor is not recognized as a constructor, but it is. - const clone: DidService = new this.constructor( - { id: values.id ?? this.id }, - options - ); - clone.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; - if (\\"endpoint\\" in values && values.endpoint != null) { - if (values.endpoint instanceof URL) { + const clone = super.clone(values, options) as unknown as FeatureAuthorization;clone.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject;clone.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = new Set(this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject); + if (\\"interactingObject\\" in values && values.interactingObject != null) { + if (values.interactingObject instanceof Object || values.interactingObject instanceof URL) { // @ts-ignore: type is checked above. - clone.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = [values.endpoint]; - + clone.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = [values.interactingObject]; + clone.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = new Set([0]); } else { throw new TypeError( - \\"The endpoint must be of type \\" + - \\"URL\\" + \\".\\", + \\"The interactingObject must be of type \\" + + \\"Object | URL\\" + \\".\\", ); } } - - if (\\"endpoints\\" in values && values.endpoints != null) { - - if (\\"endpoint\\" in values && - values.endpoint != null) { - throw new TypeError( - \\"Cannot update both endpoint and \\" + - \\"endpoints at the same time.\\", - ); - } - - if (Array.isArray(values.endpoints) && - values.endpoints.every(v => v instanceof URL)) { + clone.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget;clone.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = new Set(this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget); + if (\\"interactionTarget\\" in values && values.interactionTarget != null) { + if (values.interactionTarget instanceof Object || values.interactionTarget instanceof URL) { // @ts-ignore: type is checked above. - clone.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = values.endpoints; - + clone.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = [values.interactionTarget]; + clone.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = new Set([0]); } else { throw new TypeError( - \\"The endpoints must be an array of type \\" + - \\"URL\\" + \\".\\", + \\"The interactionTarget must be of type \\" + + \\"Object | URL\\" + \\".\\", ); } } @@ -27063,972 +27135,276 @@ endpoints?: (URL)[];} return clone; } -/** A network address, such as an HTTP URL, at which services operate on behalf - * of a DID subject. - * - */ - get endpoint(): (URL | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length < 1) return null; - return this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint[0]; - } - -/** A network address, such as an HTTP URL, at which services operate on behalf - * of a DID subject. - * - */ -get endpoints(): (URL)[] { - return this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - const values: Record = {}; - array = []; - for (const v of this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint) { - const element = ( - { \\"@id\\": formatIri(v) } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/did#serviceEndpoint\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://www.w3.org/ns/did#Service\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, + async #fetchInteractingObject( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", ); - } - const docContext = options.context ?? - \\"https://www.w3.org/ns/did/v1\\"; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - } - return compacted; - } - - protected isCompactable(): boolean { - - return true; - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__DidService__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } 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: lookupUrl } + ); + return null; + } throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#interactingObject_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; } finally { span.end(); } - }, - ); - } - - protected static async __fromJsonLd__DidService__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + }); } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, - }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/9091#Export\\")) { - return await Export.fromJsonLd(json, options); - } - - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/did#Service\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - const instance = new this( - { - id - }, - options, - ); - const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; - let _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array = values[\\"https://www.w3.org/ns/did#serviceEndpoint\\"]; - - for ( - const v of _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array == null - ? [] - : _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array.length === 1 && \\"@list\\" in _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array[0] - ? _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array[0][\\"@list\\"] - : _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array - ) { - if (v == null) continue; - - const decoded = parseIri(v[\\"@id\\"], options.baseUrl); - if (typeof decoded === \\"undefined\\") continue; - _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.push(decoded); - } - instance.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; + async #interactingObject_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, + try { + return await Object.fromJsonLd( jsonLd, - options.contextLoader, + { documentLoader, contextLoader, tracerProvider, baseUrl }, ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected _getCustomInspectProxy(): Record { - - const proxy: Record = {}; - if (this.id != null) { - proxy.id = { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(this.id!.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(this.id!.href, options), - }; + + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); } + - const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length == 1) { - proxy.endpoint = _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint[0]; - } - - if (_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length > 1 - || !(\\"endpoint\\" in proxy) - && _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length > 0) { - proxy.endpoints = _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; + /** + * Similar to + * {@link FeatureAuthorization.getInteractingObject}, + * but returns its \`@id\` URL instead of the object itself. + */ + get interactingObjectId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; + const v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; + if (v instanceof URL) return v; + return v.id; } - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(DidService.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: DidService, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"DidService \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(DidService.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: DidService, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"DidService \\" + inspect(proxy, options); - }; - /** \\"Export Actor\\" service. - * +/** The featured collection for which the authorization was granted. */ -export class Export extends DidService { - - /** - * The type URI of {@link Export}: \`https://w3id.org/fep/9091#Export\`. - */ - static override get typeId(): URL { - return new URL(\\"https://w3id.org/fep/9091#Export\\"); - } - - /** - * Constructs a new instance of Export with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -endpoint?: URL | null; -endpoints?: (URL)[];} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options);} - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -endpoint?: URL | null; -endpoints?: (URL)[];} - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Export { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Export; - return clone; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; - - values[\\"@type\\"] = [\\"https://w3id.org/fep/9091#Export\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, + async getInteractingObject( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; + let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchInteractingObject(v, options); + if (fetched == null) return null; + this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0] = fetched; + this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.add(0); + this._cachedJsonLd = undefined; + return fetched; + } + + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"interactingObject\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"interactingObject\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#interactingObject_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; + } + + async #fetchInteractionTarget( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", ); - } - const docContext = options.context ?? - \\"https://www.w3.org/ns/did/v1\\"; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__Export__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, message: String(error), }); - throw error; - } finally { span.end(); - } - }, - ); - } - - protected static async __fromJsonLd__Export__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, - }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://w3id.org/fep/9091#Export\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - delete values[\\"@type\\"]; - const instance = await super.fromJsonLd(values, { - ...options, - // @ts-ignore: an internal option - _fromSubclass: true, - }); - if (!(instance instanceof Export)) { - throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); - } - - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, - ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); - } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Export.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Export, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Export \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Export.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Export, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Export \\" + inspect(proxy, options); - }; - /** A proof that can be added to any activity or object, allowing recipients to - * verify the identity of the actor and the integrity of the data. - * - */ -export class DataIntegrityProof { - - readonly #documentLoader?: DocumentLoader; - readonly #contextLoader?: DocumentLoader; - readonly #tracerProvider?: TracerProvider; - readonly #warning?: { - category: string[]; - message: string; - values?: Record; - }; - #cachedJsonLd?: unknown; - readonly #_baseUrl?: URL; - readonly id: URL | null; - - protected get _documentLoader(): DocumentLoader | undefined { - return this.#documentLoader; - } - - protected get _contextLoader(): DocumentLoader | undefined { - return this.#contextLoader; - } - - protected get _tracerProvider(): TracerProvider | undefined { - return this.#tracerProvider; - } - - protected get _warning(): { - category: string[]; - message: string; - values?: Record; - } | undefined { - return this.#warning; - } - - protected get _cachedJsonLd(): unknown | undefined { - return this.#cachedJsonLd; - } - - protected set _cachedJsonLd(value: unknown | undefined) { - this.#cachedJsonLd = value; - } - - protected get _baseUrl(): URL | undefined { - return this.#_baseUrl; - } - - /** - * The type URI of {@link DataIntegrityProof}: \`https://w3id.org/security#DataIntegrityProof\`. - */ - static get typeId(): URL { - return new URL(\\"https://w3id.org/security#DataIntegrityProof\\"); - } - #_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: (\\"eddsa-jcs-2022\\")[] = []; - - #_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: (Multikey | URL)[] = []; - #_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: Set = new Set(); - #_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose: (\\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\")[] = []; -#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue: (Uint8Array)[] = []; -#_3qzP3ukEZoUziK5FEiA1RhU4aqac: (Temporal.Instant)[] = []; - - /** - * Constructs a new instance of DataIntegrityProof with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | null;proofPurpose?: \\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\" | null;proofValue?: Uint8Array | null;created?: Temporal.Instant | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - - this.#documentLoader = options.documentLoader; - this.#contextLoader = options.contextLoader; - this.#tracerProvider = options.tracerProvider; - const baseUrl = (options as { baseUrl?: URL }).baseUrl; - this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); - if (\\"\$warning\\" in options) { - this.#warning = options.\$warning as unknown as { - category: string[]; - message: string; - values?: Record; - }; - } - if (values.id == null || values.id instanceof URL) { - this.id = values.id ?? null; - } else { - throw new TypeError(\\"The id must be a URL.\\"); - } - - if (\\"cryptosuite\\" in values && values.cryptosuite != null) { - if (values.cryptosuite == \\"eddsa-jcs-2022\\") { - // @ts-ignore: type is checked above. - this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = [values.cryptosuite]; - - } else { - throw new TypeError( - \\"The cryptosuite must be of type \\" + - \\"\\\\\\"eddsa-jcs-2022\\\\\\"\\" + \\".\\", - ); - } - } - - if (\\"verificationMethod\\" in values && values.verificationMethod != null) { - if (values.verificationMethod instanceof Multikey || values.verificationMethod instanceof URL) { - // @ts-ignore: type is checked above. - this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = [values.verificationMethod]; - this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.add(0); - } else { - throw new TypeError( - \\"The verificationMethod must be of type \\" + - \\"Multikey | URL\\" + \\".\\", - ); - } - } - - if (\\"proofPurpose\\" in values && values.proofPurpose != null) { - if (values.proofPurpose === \\"assertionMethod\\" || values.proofPurpose === \\"authentication\\" || - values.proofPurpose === \\"capabilityInvocation\\" || values.proofPurpose === \\"capabilityDelegation\\" || - values.proofPurpose === \\"keyAgreement\\") { - // @ts-ignore: type is checked above. - this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = [values.proofPurpose]; - - } else { - throw new TypeError( - \\"The proofPurpose must be of type \\" + - \\"\\\\\\"assertionMethod\\\\\\" | \\\\\\"authentication\\\\\\" | \\\\\\"capabilityInvocation\\\\\\" | \\\\\\"capabilityDelegation\\\\\\" | \\\\\\"keyAgreement\\\\\\"\\" + \\".\\", - ); - } - } - - if (\\"proofValue\\" in values && values.proofValue != null) { - if (values.proofValue instanceof Uint8Array) { - // @ts-ignore: type is checked above. - this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = [values.proofValue]; - - } else { - throw new TypeError( - \\"The proofValue must be of type \\" + - \\"Uint8Array\\" + \\".\\", - ); - } - } - - if (\\"created\\" in values && values.created != null) { - if (isTemporalInstant(values.created)) { - // @ts-ignore: type is checked above. - this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = [values.created]; - - } else { - throw new TypeError( - \\"The created must be of type \\" + - \\"Temporal.Instant\\" + \\".\\", - ); - } - } - } - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - clone( - values: - { -id?: URL | null; -cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | null;proofPurpose?: \\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\" | null;proofValue?: Uint8Array | null;created?: Temporal.Instant | null;} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): DataIntegrityProof { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - - // @ts-ignore: this.constructor is not recognized as a constructor, but it is. - const clone: DataIntegrityProof = new this.constructor( - { id: values.id ?? this.id }, - options - ); - clone.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite; - if (\\"cryptosuite\\" in values && values.cryptosuite != null) { - if (values.cryptosuite == \\"eddsa-jcs-2022\\") { - // @ts-ignore: type is checked above. - clone.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = [values.cryptosuite]; - - } else { - throw new TypeError( - \\"The cryptosuite must be of type \\" + - \\"\\\\\\"eddsa-jcs-2022\\\\\\"\\" + \\".\\", - ); - } - } - clone.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod;clone.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = new Set(this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod); - if (\\"verificationMethod\\" in values && values.verificationMethod != null) { - if (values.verificationMethod instanceof Multikey || values.verificationMethod instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = [values.verificationMethod]; - clone.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = new Set([0]); - } else { - throw new TypeError( - \\"The verificationMethod must be of type \\" + - \\"Multikey | URL\\" + \\".\\", - ); - } - } - clone.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose; - if (\\"proofPurpose\\" in values && values.proofPurpose != null) { - if (values.proofPurpose === \\"assertionMethod\\" || values.proofPurpose === \\"authentication\\" || - values.proofPurpose === \\"capabilityInvocation\\" || values.proofPurpose === \\"capabilityDelegation\\" || - values.proofPurpose === \\"keyAgreement\\") { - // @ts-ignore: type is checked above. - clone.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = [values.proofPurpose]; - - } else { - throw new TypeError( - \\"The proofPurpose must be of type \\" + - \\"\\\\\\"assertionMethod\\\\\\" | \\\\\\"authentication\\\\\\" | \\\\\\"capabilityInvocation\\\\\\" | \\\\\\"capabilityDelegation\\\\\\" | \\\\\\"keyAgreement\\\\\\"\\" + \\".\\", - ); - } - } - clone.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue; - if (\\"proofValue\\" in values && values.proofValue != null) { - if (values.proofValue instanceof Uint8Array) { - // @ts-ignore: type is checked above. - clone.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = [values.proofValue]; - - } else { - throw new TypeError( - \\"The proofValue must be of type \\" + - \\"Uint8Array\\" + \\".\\", - ); - } - } - clone.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac; - if (\\"created\\" in values && values.created != null) { - if (isTemporalInstant(values.created)) { - // @ts-ignore: type is checked above. - clone.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = [values.created]; - - } else { - throw new TypeError( - \\"The created must be of type \\" + - \\"Temporal.Instant\\" + \\".\\", - ); - } - } - - return clone; - } - -/** The cryptographic suite used to create the proof. - * - */ - get cryptosuite(): (\\"eddsa-jcs-2022\\" | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite.length < 1) return null; - return this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite[0]; - } - - async #fetchVerificationMethod( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; - try { - fetchResult = await documentLoader(lookupUrl); - } 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: lookupUrl } - ); - return null; - } - throw error; + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to fetch {url}: {error}\\", + { error, url: lookupUrl } + ); + return null; + } + throw error; } const { document, documentUrl } = fetchResult; const baseUrl = parseIri(documentUrl); try { - const obj = await this.#verificationMethod_fromJsonLd( + const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); @@ -28076,7 +27452,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | }); } - async #verificationMethod_fromJsonLd( + async #interactionTarget_fromJsonLd( jsonLd: unknown, options: { documentLoader?: DocumentLoader, @@ -28084,7 +27460,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | tracerProvider?: TracerProvider, baseUrl?: URL } - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -28094,7 +27470,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | const baseUrl = options.baseUrl; try { - return await Multikey.fromJsonLd( + return await Object.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); @@ -28103,36 +27479,32 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://w3id.org/security#Multikey\\"].join(\\", \\")); + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); } /** * Similar to - * {@link DataIntegrityProof.getVerificationMethod}, + * {@link FeatureAuthorization.getInteractionTarget}, * but returns its \`@id\` URL instead of the object itself. */ - get verificationMethodId(): URL | null { + get interactionTargetId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; - const v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; + if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; + const v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; if (v instanceof URL) return v; return v.id; } -/** A key owned by an actor according to [FEP-521a: Representing actor's public - * keys][1]. - * - * [1]: https://w3id.org/fep/521a - * +/** The actor that was authorized to be featured. */ - async getVerificationMethod( + async getInteractionTarget( options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, @@ -28140,34 +27512,59 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {} - ): Promise { + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; - let v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; + if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; + let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; if (!(v instanceof URL) && v.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { + !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } if (v instanceof URL) { const fetched = - await this.#fetchVerificationMethod(v, options); + await this.#fetchInteractionTarget(v, options); if (fetched == null) return null; - this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0] = fetched; - this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.add(0); + this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0] = fetched; + this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.add(0); this._cachedJsonLd = undefined; return fetched; } + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"interactionTarget\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"interactionTarget\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#interactionTarget_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + if (v?.id != null && this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { + !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -28190,52 +27587,6 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | return v; } -/** The reason the proof was created. - * - * - \`\\"assertionMethod\\"\` - * - \`\\"authentication\\"\` - * - \`\\"capabilityInvocation\\"\` - * - \`\\"capabilityDelegation\\"\` - * - \`\\"keyAgreement\\"\` - * - */ - get proofPurpose(): (\\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\" | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose.length < 1) return null; - return this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose[0]; - } - -/** The proof value. - */ - get proofValue(): (Uint8Array | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue.length < 1) return null; - return this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue[0]; - } - -/** The date and time the proof was created. - */ - get created(): (Temporal.Instant | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac.length < 1) return null; - return this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac[0]; - } - /** * Converts this object to a JSON-LD structure. * @param options The options to use. @@ -28246,7 +27597,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | when \`format\` is set to \`'expand'\`. * @returns The JSON-LD representation of this object. */ - async toJsonLd(options: { + override async toJsonLd(options: { format?: \\"compact\\" | \\"expand\\", contextLoader?: DocumentLoader, context?: string | Record | (string | Record)[], @@ -28265,63 +27616,80 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | contextLoader: options.contextLoader ?? getDocumentLoader(), }; - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - const values: Record = {}; - array = []; - for (const v of this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#cryptosuite\\"] = propValue; - - } - - array = []; - for (const v of this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#verificationMethod\\"] = propValue; + if (options.format == null && this.isCompactable()) { - } + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; + + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; - array = []; - for (const v of this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose) { - const element = ( - { - \\"@id\\": \\"https://w3id.org/security#\\" + v, + compactItems = []; + for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); } - ); - array.push(element);; + if (compactItems.length > 0) { + + result[\\"interactingObject\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"interactionTarget\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + result[\\"type\\"] = \\"FeatureAuthorization\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\"]; + return result; } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#proofPurpose\\"] = propValue; - } + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; array = []; - for (const v of this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue) { + for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - { - \\"@type\\": \\"https://w3id.org/security#multibase\\", - \\"@value\\": new TextDecoder().decode(encodeMultibase(\\"base58btc\\", v)), - } + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -28329,17 +27697,14 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | const propValue = ( array ); - values[\\"https://w3id.org/security#proofValue\\"] = propValue; + values[\\"https://gotosocial.org/ns#interactingObject\\"] = propValue; } array = []; - for (const v of this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac) { + for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - { - \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#dateTime\\", - \\"@value\\": v.toString(), - } + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -28347,11 +27712,11 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | const propValue = ( array ); - values[\\"http://purl.org/dc/terms/created\\"] = propValue; + values[\\"https://gotosocial.org/ns#interactionTarget\\"] = propValue; } - values[\\"@type\\"] = [\\"https://w3id.org/security#DataIntegrityProof\\"]; + values[\\"@type\\"] = [\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -28360,7 +27725,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | ); } const docContext = options.context ?? - \\"https://w3id.org/security/data-integrity/v1\\"; + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\"]; const compacted = await jsonld.compact( values, docContext, @@ -28369,13 +27734,24 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (docContext != null) { // Embed context + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; + } + } else { + compacted.proof[\\"@context\\"] = docContext; + } + } + } return compacted; } - protected isCompactable(): boolean { + protected override isCompactable(): boolean { - return true; + return super.isCompactable(); } /** @@ -28389,7 +27765,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | * @returns The object of this type. * @throws {TypeError} If the given \`json\` is invalid. */ - static async fromJsonLd( + static override async fromJsonLd( json: unknown, options: { documentLoader?: DocumentLoader, @@ -28397,7 +27773,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -28407,7 +27783,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__DataIntegrityProof__( + const object = await this.__fromJsonLd__FeatureAuthorization__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -28426,7 +27802,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | ); } - protected static async __fromJsonLd__DataIntegrityProof__( + protected static async __fromJsonLd__FeatureAuthorization__( json: unknown, span: Span, options: { @@ -28435,7 +27811,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -28472,7 +27848,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (!values[\\"@type\\"].includes(\\"https://w3id.org/security#DataIntegrityProof\\")) { + if (!values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -28488,118 +27864,75 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | cacheJsonLd = structuredClone(cacheJsonLd); } - const instance = new this( - { - id - }, - options, - ); - const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: (\\"eddsa-jcs-2022\\")[] = []; - - let _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array = values[\\"https://w3id.org/security#cryptosuite\\"]; - - for ( - const v of _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array == null - ? [] - : _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array.length === 1 && \\"@list\\" in _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array[0] - ? _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array[0][\\"@list\\"] - : _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite.push(decoded); + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof FeatureAuthorization)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } - instance.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite; - const _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: (Multikey | URL)[] = []; - const _trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: Set = new Set(); + const _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject: (Object | URL)[] = []; + const _trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject: Set = new Set(); - let _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array = values[\\"https://w3id.org/security#verificationMethod\\"]; + let _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject__array = values[\\"https://gotosocial.org/ns#interactingObject\\"]; for ( - const v of _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array == null + const v of _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject__array == null ? [] - : _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array.length === 1 && \\"@list\\" in _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array[0] - ? _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array[0][\\"@list\\"] - : _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array + : _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject__array.length === 1 && \\"@list\\" in _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject__array[0] + ? _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject__array[0][\\"@list\\"] + : _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject__array ) { if (v == null) continue; if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } - const decoded = await Multikey.fromJsonLd( + const decoded = await Object.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } ); if (typeof decoded === \\"undefined\\") continue; - _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(decoded); - } - instance.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod; - const _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose: (\\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\")[] = []; - - let _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array = values[\\"https://w3id.org/security#proofPurpose\\"]; - - for ( - const v of _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array == null - ? [] - : _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array.length === 1 && \\"@list\\" in _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array[0] - ? _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array[0][\\"@list\\"] - : _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array - ) { - if (v == null) continue; - - const decoded = v[\\"@id\\"].substring(26); - if (typeof decoded === \\"undefined\\") continue; - _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose.push(decoded); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(decoded); } - instance.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose; - const _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue: (Uint8Array)[] = []; - - let _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array = values[\\"https://w3id.org/security#proofValue\\"]; + instance.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject; - for ( - const v of _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array == null - ? [] - : _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array.length === 1 && \\"@list\\" in _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array[0] - ? _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array[0][\\"@list\\"] - : _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array - ) { - if (v == null) continue; + const _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget: (Object | URL)[] = []; + const _trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget: Set = new Set(); - const decoded = decodeMultibase(v[\\"@value\\"]); - if (typeof decoded === \\"undefined\\") continue; - _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue.push(decoded); - } - instance.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue; - const _3qzP3ukEZoUziK5FEiA1RhU4aqac: (Temporal.Instant)[] = []; - - let _3qzP3ukEZoUziK5FEiA1RhU4aqac__array = values[\\"http://purl.org/dc/terms/created\\"]; + let _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget__array = values[\\"https://gotosocial.org/ns#interactionTarget\\"]; for ( - const v of _3qzP3ukEZoUziK5FEiA1RhU4aqac__array == null + const v of _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget__array == null ? [] - : _3qzP3ukEZoUziK5FEiA1RhU4aqac__array.length === 1 && \\"@list\\" in _3qzP3ukEZoUziK5FEiA1RhU4aqac__array[0] - ? _3qzP3ukEZoUziK5FEiA1RhU4aqac__array[0][\\"@list\\"] - : _3qzP3ukEZoUziK5FEiA1RhU4aqac__array + : _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget__array.length === 1 && \\"@list\\" in _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget__array[0] + ? _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget__array[0][\\"@list\\"] + : _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget__array ) { if (v == null) continue; - const decoded = Temporal.Instant.from( - v[\\"@value\\"].substring(19).match(/[Z+-]/) - ? v[\\"@value\\"] - : v[\\"@value\\"] + \\"Z\\" - ); + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } + + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); if (typeof decoded === \\"undefined\\") continue; - _3qzP3ukEZoUziK5FEiA1RhU4aqac.push(decoded); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(decoded); } - instance.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = _3qzP3ukEZoUziK5FEiA1RhU4aqac; + instance.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { @@ -28626,84 +27959,9 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | return instance; } - protected _getCustomInspectProxy(): Record { - - const proxy: Record = {}; - if (this.id != null) { - proxy.id = { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(this.id!.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(this.id!.href, options), - }; - } - - const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite.length == 1) { - proxy.cryptosuite = _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite[0]; - } - - const _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length == 1) { - proxy.verificationMethod = _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; - } - - const _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose.length == 1) { - proxy.proofPurpose = _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose[0]; - } - - const _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + const _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject // deno-lint-ignore no-explicit-any .map((v: any) => v instanceof URL ? { @@ -28719,11 +27977,11 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } : v); - if (_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue.length == 1) { - proxy.proofValue = _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue[0]; + if (_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length == 1) { + proxy.interactingObject = _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; } - const _3qzP3ukEZoUziK5FEiA1RhU4aqac = this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac + const _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget // deno-lint-ignore no-explicit-any .map((v: any) => v instanceof URL ? { @@ -28739,8 +27997,8 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } : v); - if (_3qzP3ukEZoUziK5FEiA1RhU4aqac.length == 1) { - proxy.created = _3qzP3ukEZoUziK5FEiA1RhU4aqac[0]; + if (_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length == 1) { + proxy.interactionTarget = _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; } return proxy; @@ -28749,88 +28007,47 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | // deno-lint-ignore no-explicit-any -(DataIntegrityProof.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = +(FeatureAuthorization.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = function ( - this: DataIntegrityProof, + this: FeatureAuthorization, inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { const proxy = this._getCustomInspectProxy(); - return \\"DataIntegrityProof \\" + inspect(proxy, options); + return \\"FeatureAuthorization \\" + inspect(proxy, options); }; // deno-lint-ignore no-explicit-any -(DataIntegrityProof.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = +(FeatureAuthorization.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = function ( - this: DataIntegrityProof, + this: FeatureAuthorization, _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); - return \\"DataIntegrityProof \\" + inspect(proxy, options); + return \\"FeatureAuthorization \\" + inspect(proxy, options); }; - /** A key owned by an actor. + /** A request for consent before featuring an actor in a + * {@link FeaturedCollection}. + * + * The \`object\` property references the actor to be included, and the + * \`instrument\` property references the featured collection. + * + * See [FEP-7aa9](https://w3id.org/fep/7aa9) for details. + * */ -export class CryptographicKey { - - readonly #documentLoader?: DocumentLoader; - readonly #contextLoader?: DocumentLoader; - readonly #tracerProvider?: TracerProvider; - readonly #warning?: { - category: string[]; - message: string; - values?: Record; - }; - #cachedJsonLd?: unknown; - readonly #_baseUrl?: URL; - readonly id: URL | null; - - protected get _documentLoader(): DocumentLoader | undefined { - return this.#documentLoader; - } - - protected get _contextLoader(): DocumentLoader | undefined { - return this.#contextLoader; - } +export class FeatureRequest extends Activity { - protected get _tracerProvider(): TracerProvider | undefined { - return this.#tracerProvider; - } - - protected get _warning(): { - category: string[]; - message: string; - values?: Record; - } | undefined { - return this.#warning; - } - - protected get _cachedJsonLd(): unknown | undefined { - return this.#cachedJsonLd; - } - - protected set _cachedJsonLd(value: unknown | undefined) { - this.#cachedJsonLd = value; - } - - protected get _baseUrl(): URL | undefined { - return this.#_baseUrl; - } - /** - * The type URI of {@link CryptographicKey}: \`https://w3id.org/security#Key\`. + * The type URI of {@link FeatureRequest}: \`https://w3id.org/fep/7aa9#FeatureRequest\`. */ - static get typeId(): URL { - return new URL(\\"https://w3id.org/security#Key\\"); + static override get typeId(): URL { + return new URL(\\"https://w3id.org/fep/7aa9#FeatureRequest\\"); } - #_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: (Application | Group | Organization | Person | Service | URL)[] = []; - #_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: Set = new Set(); - #_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem: (CryptoKey)[] = []; - /** - * Constructs a new instance of CryptographicKey with the given values. + * Constructs a new instance of FeatureRequest with the given values. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ @@ -28838,7 +28055,29 @@ export class CryptographicKey { values: { id?: URL | null; -owner?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} , options: { documentLoader?: DocumentLoader, @@ -28846,54 +28085,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi tracerProvider?: TracerProvider, } = {}, ) { - - this.#documentLoader = options.documentLoader; - this.#contextLoader = options.contextLoader; - this.#tracerProvider = options.tracerProvider; - const baseUrl = (options as { baseUrl?: URL }).baseUrl; - this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); - if (\\"\$warning\\" in options) { - this.#warning = options.\$warning as unknown as { - category: string[]; - message: string; - values?: Record; - }; - } - if (values.id == null || values.id instanceof URL) { - this.id = values.id ?? null; - } else { - throw new TypeError(\\"The id must be a URL.\\"); - } - - if (\\"owner\\" in values && values.owner != null) { - if (values.owner instanceof Application || values.owner instanceof Group || values.owner instanceof Organization || values.owner instanceof Person || values.owner instanceof Service || values.owner instanceof URL) { - // @ts-ignore: type is checked above. - this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = [values.owner]; - this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.add(0); - } else { - throw new TypeError( - \\"The owner must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); - } - } - - if (\\"publicKey\\" in values && values.publicKey != null) { - if ( - // @ts-ignore: CryptoKey exists in the global scope. - values.publicKey instanceof CryptoKey - ) { - // @ts-ignore: type is checked above. - this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = [values.publicKey]; - - } else { - throw new TypeError( - \\"The publicKey must be of type \\" + - \\"CryptoKey\\" + \\".\\", - ); - } - } - } + super(values, options);} /** * Clones this instance, optionally updating it with the given values. @@ -28901,18 +28093,40 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi * @param options The options to use for cloning. * @returns The cloned instance. */ - clone( + override clone( values: { id?: URL | null; -owner?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): CryptographicKey { + ): FeatureRequest { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -28921,320 +28135,10 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - - // @ts-ignore: this.constructor is not recognized as a constructor, but it is. - const clone: CryptographicKey = new this.constructor( - { id: values.id ?? this.id }, - options - ); - clone.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner;clone.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = new Set(this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner); - if (\\"owner\\" in values && values.owner != null) { - if (values.owner instanceof Application || values.owner instanceof Group || values.owner instanceof Organization || values.owner instanceof Person || values.owner instanceof Service || values.owner instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = [values.owner]; - clone.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = new Set([0]); - } else { - throw new TypeError( - \\"The owner must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); - } - } - clone.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem; - if (\\"publicKey\\" in values && values.publicKey != null) { - if ( - // @ts-ignore: CryptoKey exists in the global scope. - values.publicKey instanceof CryptoKey - ) { - // @ts-ignore: type is checked above. - clone.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = [values.publicKey]; - - } else { - throw new TypeError( - \\"The publicKey must be of type \\" + - \\"CryptoKey\\" + \\".\\", - ); - } - } - + const clone = super.clone(values, options) as unknown as FeatureRequest; return clone; } - async #fetchOwner( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; - try { - fetchResult = await documentLoader(lookupUrl); - } 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: lookupUrl } - ); - return null; - } - throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#owner_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; - } finally { - span.end(); - } - }); - } - - async #owner_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await Application.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Group.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Organization.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Person.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Service.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Service\\"].join(\\", \\")); - } - - - /** - * Similar to - * {@link CryptographicKey.getOwner}, - * but returns its \`@id\` URL instead of the object itself. - */ - get ownerId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; - const v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; - if (v instanceof URL) return v; - return v.id; - } - -/** An actor who owns this key. - */ - - async getOwner( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; - let v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchOwner(v, options); - if (fetched == null) return null; - this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0] = fetched; - this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"owner\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"owner\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#owner_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; - } - -/** A PEM-encoded public key. - */ - get publicKey(): (CryptoKey | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem.length < 1) return null; - return this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem[0]; - } - /** * Converts this object to a JSON-LD structure. * @param options The options to use. @@ -29245,7 +28149,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi when \`format\` is set to \`'expand'\`. * @returns The JSON-LD representation of this object. */ - async toJsonLd(options: { + override async toJsonLd(options: { format?: \\"compact\\" | \\"expand\\", contextLoader?: DocumentLoader, context?: string | Record | (string | Record)[], @@ -29264,103 +28168,20 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi contextLoader: options.contextLoader ?? getDocumentLoader(), }; - if (options.format == null && this.isCompactable()) { - const result: Record = {}; - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { - const item = ( - v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Group ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Organization ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Person ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"owner\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem) { - const item = ( - await exportSpki(v) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"publicKeyPem\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"CryptographicKey\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = \\"https://w3id.org/security/v1\\"; - return result; - } - // deno-lint-ignore no-unused-vars prefer-const let array: unknown[]; - const values: Record = {}; - array = []; - for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#owner\\"] = propValue; - - } - - array = []; - for (const v of this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem) { - const element = ( - { \\"@value\\": await exportSpki(v) } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#publicKeyPem\\"] = propValue; - - } + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; - values[\\"@type\\"] = [\\"https://w3id.org/security#Key\\"]; + values[\\"@type\\"] = [\\"https://w3id.org/fep/7aa9#FeatureRequest\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -29369,7 +28190,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi ); } const docContext = options.context ?? - \\"https://w3id.org/security/v1\\"; + [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\"]; const compacted = await jsonld.compact( values, docContext, @@ -29378,13 +28199,24 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (docContext != null) { // Embed context + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; + } + } else { + compacted.proof[\\"@context\\"] = docContext; + } + } + } return compacted; } - protected isCompactable(): boolean { + protected override isCompactable(): boolean { - return true; + return super.isCompactable(); } /** @@ -29398,7 +28230,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi * @returns The object of this type. * @throws {TypeError} If the given \`json\` is invalid. */ - static async fromJsonLd( + static override async fromJsonLd( json: unknown, options: { documentLoader?: DocumentLoader, @@ -29406,7 +28238,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -29416,7 +28248,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__CryptographicKey__( + const object = await this.__fromJsonLd__FeatureRequest__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -29435,7 +28267,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi ); } - protected static async __fromJsonLd__CryptographicKey__( + protected static async __fromJsonLd__FeatureRequest__( json: unknown, span: Span, options: { @@ -29444,7 +28276,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -29481,7 +28313,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (!values[\\"@type\\"].includes(\\"https://w3id.org/security#Key\\")) { + if (!values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeatureRequest\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -29497,80 +28329,15 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi cacheJsonLd = structuredClone(cacheJsonLd); } - const instance = new this( - { - id - }, - options, - ); - - const _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: (Application | Group | Organization | Person | Service | URL)[] = []; - const _trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: Set = new Set(); - - let _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array = values[\\"https://w3id.org/security#owner\\"]; - - for ( - const v of _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array == null - ? [] - : _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array.length === 1 && \\"@list\\" in _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array[0] - ? _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array[0][\\"@list\\"] - : _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = - typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\") ? await Application.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Group\\") ? await Group.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Organization\\") ? await Organization.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Person\\") ? await Person.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Service\\") ? await Service.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(decoded); - - } - instance.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner; - const _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem: (CryptoKey)[] = []; - - let _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array = values[\\"https://w3id.org/security#publicKeyPem\\"]; - - for ( - const v of _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array == null - ? [] - : _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array.length === 1 && \\"@list\\" in _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array[0] - ? _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array[0][\\"@list\\"] - : _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array - ) { - if (v == null) continue; - - const decoded = await importPem(v[\\"@value\\"]); - if (typeof decoded === \\"undefined\\") continue; - _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem.push(decoded); - } - instance.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem; + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof FeatureRequest)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + } if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { @@ -29597,155 +28364,90 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi return instance; } - protected _getCustomInspectProxy(): Record { - - const proxy: Record = {}; - if (this.id != null) { - proxy.id = { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(this.id!.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(this.id!.href, options), - }; - } - - const _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length == 1) { - proxy.owner = _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; - } - - const _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem.length == 1) { - proxy.publicKey = _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem[0]; - } - + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); return proxy; } } // deno-lint-ignore no-explicit-any -(CryptographicKey.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = +(FeatureRequest.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = function ( - this: CryptographicKey, + this: FeatureRequest, inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { const proxy = this._getCustomInspectProxy(); - return \\"CryptographicKey \\" + inspect(proxy, options); + return \\"FeatureRequest \\" + inspect(proxy, options); }; // deno-lint-ignore no-explicit-any -(CryptographicKey.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = +(FeatureRequest.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = function ( - this: CryptographicKey, + this: FeatureRequest, _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); - return \\"CryptographicKey \\" + inspect(proxy, options); + return \\"FeatureRequest \\" + inspect(proxy, options); }; - /** Represents a key owned by an actor according to [FEP-521a: Representing - * actor's public keys.][1] + /** A \`Collection\` is a subtype of {@link Object} that represents ordered or + * unordered sets of {@link Object} or {@link Link} instances. * - * [1]: https://w3id.org/fep/521a + * Refer to the Activity Streams 2.0 Core specification for a complete + * description of the Collection type. * */ -export class Multikey { - - readonly #documentLoader?: DocumentLoader; - readonly #contextLoader?: DocumentLoader; - readonly #tracerProvider?: TracerProvider; - readonly #warning?: { - category: string[]; - message: string; - values?: Record; - }; - #cachedJsonLd?: unknown; - readonly #_baseUrl?: URL; - readonly id: URL | null; - - protected get _documentLoader(): DocumentLoader | undefined { - return this.#documentLoader; - } - - protected get _contextLoader(): DocumentLoader | undefined { - return this.#contextLoader; - } - - protected get _tracerProvider(): TracerProvider | undefined { - return this.#tracerProvider; - } - - protected get _warning(): { - category: string[]; - message: string; - values?: Record; - } | undefined { - return this.#warning; - } - - protected get _cachedJsonLd(): unknown | undefined { - return this.#cachedJsonLd; - } - - protected set _cachedJsonLd(value: unknown | undefined) { - this.#cachedJsonLd = value; - } +export class Collection extends Object { - protected get _baseUrl(): URL | undefined { - return this.#_baseUrl; - } - /** - * The type URI of {@link Multikey}: \`https://w3id.org/security#Multikey\`. + * The type URI of {@link Collection}: \`https://www.w3.org/ns/activitystreams#Collection\`. */ - static get typeId(): URL { - return new URL(\\"https://w3id.org/security#Multikey\\"); + static override get typeId(): URL { + return new URL(\\"https://www.w3.org/ns/activitystreams#Collection\\"); } - - #_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: (Application | Group | Organization | Person | Service | URL)[] = []; - #_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: Set = new Set(); - #_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase: (CryptoKey)[] = []; + #_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems: (number)[] = []; + #_3UyUdxnyn6cDn53QKrh4MBiearma_current: (CollectionPage | URL)[] = []; + #_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current: Set = new Set(); + + #_J52RqweMe6hhv7RnLJMC8BExTE5_first: (CollectionPage | URL)[] = []; + #_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first: Set = new Set(); + + #_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last: (CollectionPage | URL)[] = []; + #_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last: Set = new Set(); + + #_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: (Object | Link | URL)[] = []; + #_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: Set = new Set(); + + #_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf: (Object | URL)[] = []; + #_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf: Set = new Set(); + + #_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf: (Object | URL)[] = []; + #_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf: Set = new Set(); + + #_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf: (Object | URL)[] = []; + #_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf: Set = new Set(); + + #_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf: (Object | URL)[] = []; + #_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf: Set = new Set(); + + #_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf: (Object | URL)[] = []; + #_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf: Set = new Set(); + + #_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf: (Object | URL)[] = []; + #_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf: Set = new Set(); + + #_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf: (Object | URL)[] = []; + #_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf: Set = new Set(); + + #_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf: (Object | URL)[] = []; + #_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf: Set = new Set(); + /** - * Constructs a new instance of Multikey with the given values. + * Constructs a new instance of Collection with the given values. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ @@ -29753,7 +28455,23 @@ export class Multikey { values: { id?: URL | null; -controller?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;totalItems?: number | null;current?: CollectionPage | URL | null;first?: CollectionPage | URL | null;last?: CollectionPage | URL | null;items?: (Object | Link | URL)[];likesOf?: Object | URL | null;sharesOf?: Object | URL | null;repliesOf?: Object | URL | null;inboxOf?: Object | URL | null;outboxOf?: Object | URL | null;followersOf?: Object | URL | null;followingOf?: Object | URL | null;likedOf?: Object | URL | null;} , options: { documentLoader?: DocumentLoader, @@ -29761,50 +28479,178 @@ controller?: Application | Group | Organization | Person | Service | URL | null; tracerProvider?: TracerProvider, } = {}, ) { - - this.#documentLoader = options.documentLoader; - this.#contextLoader = options.contextLoader; - this.#tracerProvider = options.tracerProvider; - const baseUrl = (options as { baseUrl?: URL }).baseUrl; - this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); - if (\\"\$warning\\" in options) { - this.#warning = options.\$warning as unknown as { - category: string[]; - message: string; - values?: Record; - }; - } - if (values.id == null || values.id instanceof URL) { - this.id = values.id ?? null; - } else { - throw new TypeError(\\"The id must be a URL.\\"); - } - - if (\\"controller\\" in values && values.controller != null) { - if (values.controller instanceof Application || values.controller instanceof Group || values.controller instanceof Organization || values.controller instanceof Person || values.controller instanceof Service || values.controller instanceof URL) { + super(values, options); + if (\\"totalItems\\" in values && values.totalItems != null) { + if (typeof values.totalItems === \\"number\\" && Number.isInteger(values.totalItems) && values.totalItems >= 0) { // @ts-ignore: type is checked above. - this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = [values.controller]; - this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.add(0); + this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems = [values.totalItems]; + } else { throw new TypeError( - \\"The controller must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + \\"The totalItems must be of type \\" + + \\"number\\" + \\".\\", ); } } - if (\\"publicKey\\" in values && values.publicKey != null) { - if ( - // @ts-ignore: CryptoKey exists in the global scope. - values.publicKey instanceof CryptoKey - ) { + if (\\"current\\" in values && values.current != null) { + if (values.current instanceof CollectionPage || values.current instanceof URL) { // @ts-ignore: type is checked above. - this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = [values.publicKey]; + this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current = [values.current]; + this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.add(0); + } else { + throw new TypeError( + \\"The current must be of type \\" + + \\"CollectionPage | URL\\" + \\".\\", + ); + } + } + if (\\"first\\" in values && values.first != null) { + if (values.first instanceof CollectionPage || values.first instanceof URL) { + // @ts-ignore: type is checked above. + this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first = [values.first]; + this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.add(0); } else { throw new TypeError( - \\"The publicKey must be of type \\" + - \\"CryptoKey\\" + \\".\\", + \\"The first must be of type \\" + + \\"CollectionPage | URL\\" + \\".\\", + ); + } + } + + if (\\"last\\" in values && values.last != null) { + if (values.last instanceof CollectionPage || values.last instanceof URL) { + // @ts-ignore: type is checked above. + this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = [values.last]; + this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.add(0); + } else { + throw new TypeError( + \\"The last must be of type \\" + + \\"CollectionPage | URL\\" + \\".\\", + ); + } + } + + if (\\"items\\" in values && values.items != null) { + + if (Array.isArray(values.items) && + values.items.every(v => v instanceof Object || v instanceof Link || v instanceof URL)) { + // @ts-ignore: type is checked above. + this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = values.items; + + for (let i = 0; i < values.items.length; i++) { + this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.add(i); + } + + } else { + throw new TypeError( + \\"The items must be an array of type \\" + + \\"Object | Link | URL\\" + \\".\\", + ); + } + } + + if (\\"likesOf\\" in values && values.likesOf != null) { + if (values.likesOf instanceof Object || values.likesOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = [values.likesOf]; + this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.add(0); + } else { + throw new TypeError( + \\"The likesOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"sharesOf\\" in values && values.sharesOf != null) { + if (values.sharesOf instanceof Object || values.sharesOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = [values.sharesOf]; + this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.add(0); + } else { + throw new TypeError( + \\"The sharesOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"repliesOf\\" in values && values.repliesOf != null) { + if (values.repliesOf instanceof Object || values.repliesOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = [values.repliesOf]; + this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.add(0); + } else { + throw new TypeError( + \\"The repliesOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"inboxOf\\" in values && values.inboxOf != null) { + if (values.inboxOf instanceof Object || values.inboxOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = [values.inboxOf]; + this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.add(0); + } else { + throw new TypeError( + \\"The inboxOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"outboxOf\\" in values && values.outboxOf != null) { + if (values.outboxOf instanceof Object || values.outboxOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = [values.outboxOf]; + this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.add(0); + } else { + throw new TypeError( + \\"The outboxOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"followersOf\\" in values && values.followersOf != null) { + if (values.followersOf instanceof Object || values.followersOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = [values.followersOf]; + this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.add(0); + } else { + throw new TypeError( + \\"The followersOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"followingOf\\" in values && values.followingOf != null) { + if (values.followingOf instanceof Object || values.followingOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = [values.followingOf]; + this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.add(0); + } else { + throw new TypeError( + \\"The followingOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"likedOf\\" in values && values.likedOf != null) { + if (values.likedOf instanceof Object || values.likedOf instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = [values.likedOf]; + this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.add(0); + } else { + throw new TypeError( + \\"The likedOf must be of type \\" + + \\"Object | URL\\" + \\".\\", ); } } @@ -29816,18 +28662,34 @@ controller?: Application | Group | Organization | Person | Service | URL | null; * @param options The options to use for cloning. * @returns The cloned instance. */ - clone( + override clone( values: { id?: URL | null; -controller?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;totalItems?: number | null;current?: CollectionPage | URL | null;first?: CollectionPage | URL | null;last?: CollectionPage | URL | null;items?: (Object | Link | URL)[];likesOf?: Object | URL | null;sharesOf?: Object | URL | null;repliesOf?: Object | URL | null;inboxOf?: Object | URL | null;outboxOf?: Object | URL | null;followersOf?: Object | URL | null;followingOf?: Object | URL | null;likedOf?: Object | URL | null;} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): Multikey { + ): Collection { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -29836,68 +28698,225 @@ controller?: Application | Group | Organization | Person | Service | URL | null; // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - - // @ts-ignore: this.constructor is not recognized as a constructor, but it is. - const clone: Multikey = new this.constructor( - { id: values.id ?? this.id }, - options - ); - clone.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller;clone.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = new Set(this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller); - if (\\"controller\\" in values && values.controller != null) { - if (values.controller instanceof Application || values.controller instanceof Group || values.controller instanceof Organization || values.controller instanceof Person || values.controller instanceof Service || values.controller instanceof URL) { + const clone = super.clone(values, options) as unknown as Collection;clone.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems = this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems; + if (\\"totalItems\\" in values && values.totalItems != null) { + if (typeof values.totalItems === \\"number\\" && Number.isInteger(values.totalItems) && values.totalItems >= 0) { // @ts-ignore: type is checked above. - clone.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = [values.controller]; - clone.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = new Set([0]); + clone.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems = [values.totalItems]; + } else { throw new TypeError( - \\"The controller must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + \\"The totalItems must be of type \\" + + \\"number\\" + \\".\\", ); } } - clone.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase; - if (\\"publicKey\\" in values && values.publicKey != null) { - if ( - // @ts-ignore: CryptoKey exists in the global scope. - values.publicKey instanceof CryptoKey - ) { + clone.#_3UyUdxnyn6cDn53QKrh4MBiearma_current = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current;clone.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current = new Set(this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current); + if (\\"current\\" in values && values.current != null) { + if (values.current instanceof CollectionPage || values.current instanceof URL) { // @ts-ignore: type is checked above. - clone.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = [values.publicKey]; - + clone.#_3UyUdxnyn6cDn53QKrh4MBiearma_current = [values.current]; + clone.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current = new Set([0]); } else { throw new TypeError( - \\"The publicKey must be of type \\" + - \\"CryptoKey\\" + \\".\\", + \\"The current must be of type \\" + + \\"CollectionPage | URL\\" + \\".\\", ); } } - - return clone; - } - - async #fetchController( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + clone.#_J52RqweMe6hhv7RnLJMC8BExTE5_first = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first;clone.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first = new Set(this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first); + if (\\"first\\" in values && values.first != null) { + if (values.first instanceof CollectionPage || values.first instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_J52RqweMe6hhv7RnLJMC8BExTE5_first = [values.first]; + clone.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first = new Set([0]); + } else { + throw new TypeError( + \\"The first must be of type \\" + + \\"CollectionPage | URL\\" + \\".\\", + ); + } + } + clone.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last;clone.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = new Set(this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last); + if (\\"last\\" in values && values.last != null) { + if (values.last instanceof CollectionPage || values.last instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = [values.last]; + clone.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = new Set([0]); + } else { + throw new TypeError( + \\"The last must be of type \\" + + \\"CollectionPage | URL\\" + \\".\\", + ); + } + } + clone.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items;clone.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = new Set(this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items); + if (\\"items\\" in values && values.items != null) { + + if (Array.isArray(values.items) && + values.items.every(v => v instanceof Object || v instanceof Link || v instanceof URL)) { + // @ts-ignore: type is checked above. + clone.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = values.items; + + clone.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = new Set(); + for (let i = 0; i < values.items.length; i++) { + clone.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.add(i); + } + + } else { + throw new TypeError( + \\"The items must be an array of type \\" + + \\"Object | Link | URL\\" + \\".\\", + ); + } + } + clone.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf;clone.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = new Set(this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf); + if (\\"likesOf\\" in values && values.likesOf != null) { + if (values.likesOf instanceof Object || values.likesOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = [values.likesOf]; + clone.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = new Set([0]); + } else { + throw new TypeError( + \\"The likesOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf;clone.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = new Set(this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf); + if (\\"sharesOf\\" in values && values.sharesOf != null) { + if (values.sharesOf instanceof Object || values.sharesOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = [values.sharesOf]; + clone.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = new Set([0]); + } else { + throw new TypeError( + \\"The sharesOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf;clone.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = new Set(this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf); + if (\\"repliesOf\\" in values && values.repliesOf != null) { + if (values.repliesOf instanceof Object || values.repliesOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = [values.repliesOf]; + clone.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = new Set([0]); + } else { + throw new TypeError( + \\"The repliesOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf;clone.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = new Set(this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf); + if (\\"inboxOf\\" in values && values.inboxOf != null) { + if (values.inboxOf instanceof Object || values.inboxOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = [values.inboxOf]; + clone.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = new Set([0]); + } else { + throw new TypeError( + \\"The inboxOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf;clone.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = new Set(this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf); + if (\\"outboxOf\\" in values && values.outboxOf != null) { + if (values.outboxOf instanceof Object || values.outboxOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = [values.outboxOf]; + clone.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = new Set([0]); + } else { + throw new TypeError( + \\"The outboxOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf;clone.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = new Set(this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf); + if (\\"followersOf\\" in values && values.followersOf != null) { + if (values.followersOf instanceof Object || values.followersOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = [values.followersOf]; + clone.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = new Set([0]); + } else { + throw new TypeError( + \\"The followersOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf;clone.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = new Set(this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf); + if (\\"followingOf\\" in values && values.followingOf != null) { + if (values.followingOf instanceof Object || values.followingOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = [values.followingOf]; + clone.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = new Set([0]); + } else { + throw new TypeError( + \\"The followingOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf;clone.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = new Set(this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf); + if (\\"likedOf\\" in values && values.likedOf != null) { + if (values.likedOf instanceof Object || values.likedOf instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = [values.likedOf]; + clone.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = new Set([0]); + } else { + throw new TypeError( + \\"The likedOf must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + return clone; + } + +/** A non-negative integer specifying the total number of objects contained by + * the logical view of the collection. This number might not reflect the actual + * number of items serialized within the {@link Collection} object instance. + * + */ + get totalItems(): (number | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems.length < 1) return null; + return this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems[0]; + } + + async #fetchCurrent( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { fetchResult = await documentLoader(lookupUrl); } catch (error) { @@ -29918,7 +28937,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; const { document, documentUrl } = fetchResult; const baseUrl = parseIri(documentUrl); try { - const obj = await this.#controller_fromJsonLd( + const obj = await this.#current_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); @@ -29966,7 +28985,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; }); } - async #controller_fromJsonLd( + async #current_fromJsonLd( jsonLd: unknown, options: { documentLoader?: DocumentLoader, @@ -29974,7 +28993,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; tracerProvider?: TracerProvider, baseUrl?: URL } - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -29984,7 +29003,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; const baseUrl = options.baseUrl; try { - return await Application.fromJsonLd( + return await CollectionPage.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); @@ -29992,35 +29011,227 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (!(e instanceof TypeError)) throw e; } - try { - return await Group.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#CollectionPage\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link Collection.getCurrent}, + * but returns its \`@id\` URL instead of the object itself. + */ + get currentId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; } + if (this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current.length < 1) return null; + const v = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current[0]; + if (v instanceof URL) return v; + return v.id; + } - try { - return await Organization.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, +/** In a paged {@link Collection}, indicates the page that contains + * the most recently updated member items. + * + */ + + async getCurrent( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; } + if (this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current.length < 1) return null; + let v = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchCurrent(v, options); + if (fetched == null) return null; + this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current[0] = fetched; + this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.add(0); + this._cachedJsonLd = undefined; + return fetched; + } + + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"current\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"current\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#current_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; + } + async #fetchFirst( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - return await Person.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } + ); + return null; + } + throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#first_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href ); + return obj; } catch (e) { - if (!(e instanceof TypeError)) throw e; + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); } - + }); + } + + async #first_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + try { - return await Service.fromJsonLd( + return await CollectionPage.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); @@ -30029,32 +29240,34 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Service\\"].join(\\", \\")); + [\\"https://www.w3.org/ns/activitystreams#CollectionPage\\"].join(\\", \\")); } /** * Similar to - * {@link Multikey.getController}, + * {@link Collection.getFirst}, * but returns its \`@id\` URL instead of the object itself. */ - get controllerId(): URL | null { + get firstId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; - const v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; + if (this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first.length < 1) return null; + const v = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first[0]; if (v instanceof URL) return v; return v.id; } -/** An actor who owns this key. +/** In a paged {@link Collection}, indicates the furthest preceding page of + * items in the collection. + * */ - async getController( + async getFirst( options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, @@ -30062,27 +29275,27 @@ controller?: Application | Group | Organization | Person | Service | URL | null; tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {} - ): Promise { + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; - let v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; + if (this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first.length < 1) return null; + let v = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first[0]; if (!(v instanceof URL) && v.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { + !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { v = v.id; } if (v instanceof URL) { const fetched = - await this.#fetchController(v, options); + await this.#fetchFirst(v, options); if (fetched == null) return null; - this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0] = fetched; - this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.add(0); + this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first[0] = fetched; + this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.add(0); this._cachedJsonLd = undefined; return fetched; } @@ -30091,14 +29304,14 @@ controller?: Application | Group | Organization | Person | Service | URL | null; this._cachedJsonLd != null && typeof this._cachedJsonLd === \\"object\\" && \\"@context\\" in this._cachedJsonLd && - \\"controller\\" in this._cachedJsonLd + \\"first\\" in this._cachedJsonLd ) { const prop = this._cachedJsonLd[ - \\"controller\\"]; + \\"first\\"]; const doc = Array.isArray(prop) ? prop[0] : prop; if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - v = await this.#controller_fromJsonLd(doc, { + v = await this.#first_fromJsonLd(doc, { ...options, baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this._baseUrl ?? @@ -30114,7 +29327,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (v?.id != null && this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { + !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -30137,3632 +29350,2595 @@ controller?: Application | Group | Organization | Person | Service | URL | null; return v; } -/** A [Multibase]-encoded value of a [Multicodec] prefix and the key. - * - * [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0 - * [Multicodec]: https://github.com/multiformats/multicodec/ - * - */ - get publicKey(): (CryptoKey | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase.length < 1) return null; - return this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase[0]; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { - const result: Record = {}; - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { - const item = ( - v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Group ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Organization ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Person ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"controller\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase) { - const item = ( - await exportMultibaseKey(v) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"publicKeyMultibase\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"Multikey\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = \\"https://w3id.org/security/multikey/v1\\"; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - const values: Record = {}; - array = []; - for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#controller\\"] = propValue; - - } - - array = []; - for (const v of this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase) { - const element = ( - { - \\"@type\\": \\"https://w3id.org/security#multibase\\", - \\"@value\\": await exportMultibaseKey(v), - } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#publicKeyMultibase\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://w3id.org/security#Multikey\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, + async #fetchLast( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", ); - } - const docContext = options.context ?? - \\"https://w3id.org/security/multikey/v1\\"; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - } - return compacted; - } - - protected isCompactable(): boolean { - - return true; - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__Multikey__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } 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: lookupUrl } + ); + return null; + } throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#last_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; } finally { span.end(); } - }, - ); - } - - protected static async __fromJsonLd__Multikey__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://w3id.org/security#Multikey\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - const instance = new this( - { - id - }, - options, - ); - - const _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: (Application | Group | Organization | Person | Service | URL)[] = []; - const _trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: Set = new Set(); - - let _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array = values[\\"https://w3id.org/security#controller\\"]; - - for ( - const v of _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array == null - ? [] - : _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array.length === 1 && \\"@list\\" in _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array[0] - ? _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array[0][\\"@list\\"] - : _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = - typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\") ? await Application.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Group\\") ? await Group.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Organization\\") ? await Organization.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Person\\") ? await Person.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Service\\") ? await Service.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(decoded); - } - instance.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller; - const _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase: (CryptoKey)[] = []; - let _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array = values[\\"https://w3id.org/security#publicKeyMultibase\\"]; - - for ( - const v of _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array == null - ? [] - : _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array.length === 1 && \\"@list\\" in _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array[0] - ? _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array[0][\\"@list\\"] - : _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array - ) { - if (v == null) continue; - - const decoded = await importMultibaseKey(v[\\"@value\\"]); - if (typeof decoded === \\"undefined\\") continue; - _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase.push(decoded); - } - instance.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase; + async #last_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, + try { + return await CollectionPage.fromJsonLd( jsonLd, - options.contextLoader, + { documentLoader, contextLoader, tracerProvider, baseUrl }, ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected _getCustomInspectProxy(): Record { - - const proxy: Record = {}; - if (this.id != null) { - proxy.id = { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(this.id!.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(this.id!.href, options), - }; - } - - const _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length == 1) { - proxy.controller = _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; - } - const _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#CollectionPage\\"].join(\\", \\")); + } + - if (_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase.length == 1) { - proxy.publicKey = _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase[0]; + /** + * Similar to + * {@link Collection.getLast}, + * but returns its \`@id\` URL instead of the object itself. + */ + get lastId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.length < 1) return null; + const v = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0]; + if (v instanceof URL) return v; + return v.id; } - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Multikey.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Multikey, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Multikey \\" + inspect(proxy, options); - }; +/** In a paged {@link Collection}, indicates the furthest proceeding page of + * the collection. + * + */ -// deno-lint-ignore no-explicit-any -(Multikey.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Multikey, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Multikey \\" + inspect(proxy, options); - }; - /** The agreement reached between parties responding to a {@link Proposal}. - * - * An interested party sends an \`Agreement\` wrapped in an {@link Offer} - * activity. The proposing party then either finalizes the agreement by - * sending an {@link Accept} activity with the finalized \`Agreement\` as - * its \`result\`, or sends a {@link Reject} activity. - * - * Note: This type extends ActivityStreams \`Object\` for practical - * interoperability within ActivityPub federation, even though FEP-0837 - * defines \`Agreement\` as a pure ValueFlows type. Extending \`Object\` - * provides useful inherited properties such as \`id\`, \`attributedTo\`, - * \`url\`, \`to\`, and \`published\` without needing to redefine them. - * - */ -export class Agreement extends Object { - - /** - * The type URI of {@link Agreement}: \`https://w3id.org/valueflows/ont/vf#Agreement\`. - */ - static override get typeId(): URL { - return new URL(\\"https://w3id.org/valueflows/ont/vf#Agreement\\"); - } - #_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates: (Commitment)[] = []; -#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal: (Commitment)[] = []; - - /** - * Constructs a new instance of Agreement with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;stipulates?: Commitment | null;stipulatesReciprocal?: Commitment | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options); - if (\\"stipulates\\" in values && values.stipulates != null) { - if (values.stipulates instanceof Commitment) { - // @ts-ignore: type is checked above. - this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = [values.stipulates]; - - } else { - throw new TypeError( - \\"The stipulates must be of type \\" + - \\"Commitment\\" + \\".\\", - ); - } + async getLast( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.length < 1) return null; + let v = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchLast(v, options); + if (fetched == null) return null; + this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0] = fetched; + this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.add(0); + this._cachedJsonLd = undefined; + return fetched; } - if (\\"stipulatesReciprocal\\" in values && values.stipulatesReciprocal != null) { - if (values.stipulatesReciprocal instanceof Commitment) { - // @ts-ignore: type is checked above. - this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = [values.stipulatesReciprocal]; + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"last\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"last\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - } else { - throw new TypeError( - \\"The stipulatesReciprocal must be of type \\" + - \\"Commitment\\" + \\".\\", + v = await this.#last_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' ); } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; } + return v; } - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;stipulates?: Commitment | null;stipulatesReciprocal?: Commitment | null;} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Agreement { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Agreement;clone.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates; - if (\\"stipulates\\" in values && values.stipulates != null) { - if (values.stipulates instanceof Commitment) { - // @ts-ignore: type is checked above. - clone.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = [values.stipulates]; - } else { - throw new TypeError( - \\"The stipulates must be of type \\" + - \\"Commitment\\" + \\".\\", + async #fetchItem( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } ); + return null; } + throw error; } - clone.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal; - if (\\"stipulatesReciprocal\\" in values && values.stipulatesReciprocal != null) { - if (values.stipulatesReciprocal instanceof Commitment) { - // @ts-ignore: type is checked above. - clone.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = [values.stipulatesReciprocal]; - - } else { - throw new TypeError( - \\"The stipulatesReciprocal must be of type \\" + - \\"Commitment\\" + \\".\\", + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#item_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } ); + return null; } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); + } + }); + } + + async #item_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - return clone; - } - -/** The primary {@link Commitment} associated with the agreement. This - * commitment satisfies the primary {@link Intent} of the corresponding - * {@link Proposal}. - * - */ - get stipulates(): (Commitment | null) { + try { + return await Link.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } 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\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link Collection.getItems}, + * but returns their \`@id\`s instead of the objects themselves. + */ + get itemIds(): URL[] { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates.length < 1) return null; - return this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates[0]; + return this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.map((v) => + v instanceof URL ? v : v.id! + ).filter(id => id !== null); } -/** The reciprocal {@link Commitment} associated with the agreement. - * Required if the corresponding {@link Proposal} has a reciprocal - * {@link Intent}. +/** Identifies the items contained in a collection. The items might be ordered + * or unordered. * */ - get stipulatesReciprocal(): (Commitment | null) { + + async* getItems( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): AsyncIterable { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal.length < 1) return null; - return this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal[0]; - } + const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; + for (let i = 0; i < vs.length; i++) { + let v = vs[i]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchItem(v, options); + if (fetched == null) continue; + vs[i] = fetched; + this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.add(i); + this._cachedJsonLd = undefined; + yield fetched; + continue; + } - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { - - const result = await super.toJsonLd({ - ...options, - format: undefined, - context: undefined, - }) as Record; + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"items\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"items\\"]; + const obj = Array.isArray(prop) ? prop[i] : prop; + if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { + v = await this.#item_fromJsonLd(obj, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - result[\\"stipulates\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; + } + } + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin \\" + + 'option to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + continue; + } + yield v; + } } - compactItems = []; - for (const v of this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"stipulatesReciprocal\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"Agreement\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Agreement\\":\\"vf:Agreement\\",\\"Commitment\\":\\"vf:Commitment\\",\\"stipulates\\":\\"vf:stipulates\\",\\"stipulatesReciprocal\\":\\"vf:stipulatesReciprocal\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; - - array = []; - for (const v of this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#stipulates\\"] = propValue; - - } - - array = []; - for (const v of this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#stipulatesReciprocal\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Agreement\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, + async #fetchLikesOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", ); - } - const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Agreement\\":\\"vf:Agreement\\",\\"Commitment\\":\\"vf:Commitment\\",\\"stipulates\\":\\"vf:stipulates\\",\\"stipulatesReciprocal\\":\\"vf:stipulatesReciprocal\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; - } - } else { - compacted.proof[\\"@context\\"] = docContext; - } - } - - } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__Agreement__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } 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: lookupUrl } + ); + return null; + } throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#likesOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; } finally { span.end(); } - }, - ); - } - - protected static async __fromJsonLd__Agreement__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Agreement\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - delete values[\\"@type\\"]; - const instance = await super.fromJsonLd(values, { - ...options, - // @ts-ignore: an internal option - _fromSubclass: true, - }); - if (!(instance instanceof Agreement)) { - throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); - } - const _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates: (Commitment)[] = []; - - let _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array = values[\\"https://w3id.org/valueflows/ont/vf#stipulates\\"]; - - for ( - const v of _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array == null - ? [] - : _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array.length === 1 && \\"@list\\" in _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array[0] - ? _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array[0][\\"@list\\"] - : _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array - ) { - if (v == null) continue; - - const decoded = await Commitment.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates.push(decoded); } - instance.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates; - const _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal: (Commitment)[] = []; - let _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array = values[\\"https://w3id.org/valueflows/ont/vf#stipulatesReciprocal\\"]; - - for ( - const v of _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array == null - ? [] - : _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array.length === 1 && \\"@list\\" in _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array[0] - ? _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array[0][\\"@list\\"] - : _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array - ) { - if (v == null) continue; - - const decoded = await Commitment.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal.push(decoded); - } - instance.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal; + async #likesOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, + try { + return await Object.fromJsonLd( jsonLd, - options.contextLoader, + { documentLoader, contextLoader, tracerProvider, baseUrl }, ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - const _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates.length == 1) { - proxy.stipulates = _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates[0]; - } - const _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); + } + - if (_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal.length == 1) { - proxy.stipulatesReciprocal = _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal[0]; + /** + * Similar to + * {@link Collection.getLikesOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get likesOfId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.length < 1) return null; + const v = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0]; + if (v instanceof URL) return v; + return v.id; } - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Agreement.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Agreement, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Agreement \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Agreement.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Agreement, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Agreement \\" + inspect(proxy, options); - }; - /** A promised economic transaction, referenced by an {@link Agreement}. - * - * A commitment satisfies an {@link Intent} of a {@link Proposal} and - * specifies the actual amount of the economic resource being committed. +/** Defines an object for which the collection is the value of the likes property. * */ -export class Commitment { - - readonly #documentLoader?: DocumentLoader; - readonly #contextLoader?: DocumentLoader; - readonly #tracerProvider?: TracerProvider; - readonly #warning?: { - category: string[]; - message: string; - values?: Record; - }; - #cachedJsonLd?: unknown; - readonly #_baseUrl?: URL; - readonly id: URL | null; - - protected get _documentLoader(): DocumentLoader | undefined { - return this.#documentLoader; - } - - protected get _contextLoader(): DocumentLoader | undefined { - return this.#contextLoader; - } - - protected get _tracerProvider(): TracerProvider | undefined { - return this.#tracerProvider; - } - - protected get _warning(): { - category: string[]; - message: string; - values?: Record; - } | undefined { - return this.#warning; - } - - protected get _cachedJsonLd(): unknown | undefined { - return this.#cachedJsonLd; - } - - protected set _cachedJsonLd(value: unknown | undefined) { - this.#cachedJsonLd = value; - } - - protected get _baseUrl(): URL | undefined { - return this.#_baseUrl; - } - - /** - * The type URI of {@link Commitment}: \`https://w3id.org/valueflows/ont/vf#Commitment\`. - */ - static get typeId(): URL { - return new URL(\\"https://w3id.org/valueflows/ont/vf#Commitment\\"); - } - #_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; -#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; - /** - * Constructs a new instance of Commitment with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -satisfies?: URL | null;resourceQuantity?: Measure | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - - this.#documentLoader = options.documentLoader; - this.#contextLoader = options.contextLoader; - this.#tracerProvider = options.tracerProvider; - const baseUrl = (options as { baseUrl?: URL }).baseUrl; - this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); - if (\\"\$warning\\" in options) { - this.#warning = options.\$warning as unknown as { - category: string[]; - message: string; - values?: Record; - }; - } - if (values.id == null || values.id instanceof URL) { - this.id = values.id ?? null; - } else { - throw new TypeError(\\"The id must be a URL.\\"); - } - - if (\\"satisfies\\" in values && values.satisfies != null) { - if (values.satisfies instanceof URL) { - // @ts-ignore: type is checked above. - this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = [values.satisfies]; - - } else { - throw new TypeError( - \\"The satisfies must be of type \\" + - \\"URL\\" + \\".\\", - ); - } + async getLikesOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.length < 1) return null; + let v = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchLikesOf(v, options); + if (fetched == null) return null; + this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0] = fetched; + this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.add(0); + this._cachedJsonLd = undefined; + return fetched; } - if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { - if (values.resourceQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"likesOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"likesOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - } else { - throw new TypeError( - \\"The resourceQuantity must be of type \\" + - \\"Measure\\" + \\".\\", + v = await this.#likesOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' ); } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; } + return v; } - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - clone( - values: - { -id?: URL | null; -satisfies?: URL | null;resourceQuantity?: Measure | null;} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Commitment { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - - // @ts-ignore: this.constructor is not recognized as a constructor, but it is. - const clone: Commitment = new this.constructor( - { id: values.id ?? this.id }, - options - ); - clone.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies; - if (\\"satisfies\\" in values && values.satisfies != null) { - if (values.satisfies instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = [values.satisfies]; - } else { - throw new TypeError( - \\"The satisfies must be of type \\" + - \\"URL\\" + \\".\\", + async #fetchSharesOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } ); + return null; } + throw error; } - clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; - if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { - if (values.resourceQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; - - } else { - throw new TypeError( - \\"The resourceQuantity must be of type \\" + - \\"Measure\\" + \\".\\", + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#sharesOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } ); + return null; } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); + } + }); + } + + async #sharesOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - return clone; - } - -/** The {@link Intent} of a {@link Proposal} that this commitment - * satisfies. The value is the proposal's URI with a - * [fragment](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment) - * appended to identify the intent. Recommended fragments are - * \`primary\` and \`reciprocal\`. - * - */ - get satisfies(): (URL | null) { + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link Collection.getSharesOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get sharesOfId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.length < 1) return null; - return this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies[0]; + if (this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.length < 1) return null; + const v = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0]; + if (v instanceof URL) return v; + return v.id; } -/** The amount and unit of the economic resource being committed. The - * unit must match the unit specified in the corresponding {@link Intent} - * of the proposal. +/** Defines an object for which the collection is the value of the shares property. * */ - get resourceQuantity(): (Measure | null) { + + async getSharesOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length < 1) return null; - return this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { - const result: Record = {}; - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { - const item = ( - formatIri(v) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { + if (this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.length < 1) return null; + let v = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchSharesOf(v, options); + if (fetched == null) return null; + this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0] = fetched; + this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.add(0); + this._cachedJsonLd = undefined; + return fetched; + } - result[\\"satisfies\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"sharesOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"sharesOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - compactItems = []; - for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { + v = await this.#sharesOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - result[\\"resourceQuantity\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; + } + } + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; } - result[\\"type\\"] = \\"Commitment\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Commitment\\":\\"vf:Commitment\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - const values: Record = {}; - array = []; - for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { - const element = ( - { \\"@id\\": formatIri(v) } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#satisfies\\"] = propValue; - - } - - array = []; - for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { - const element = ( - await v.toJsonLd(options) + async #fetchRepliesOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Commitment\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, - ); - } - const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Commitment\\":\\"vf:Commitment\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - } - return compacted; - } - - protected isCompactable(): boolean { - - return true; - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__Commitment__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } 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: lookupUrl } + ); + return null; + } throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#repliesOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; } finally { span.end(); } - }, - ); - } - - protected static async __fromJsonLd__Commitment__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Commitment\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); } - - const instance = new this( - { - id - }, - options, - ); - const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; - - let _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array = values[\\"https://w3id.org/valueflows/ont/vf#satisfies\\"]; - - for ( - const v of _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array == null - ? [] - : _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array.length === 1 && \\"@list\\" in _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array[0] - ? _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array[0][\\"@list\\"] - : _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array - ) { - if (v == null) continue; - - const decoded = parseIri(v[\\"@id\\"], options.baseUrl); - if (typeof decoded === \\"undefined\\") continue; - _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.push(decoded); - } - instance.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies; - const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; - let _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"]; - - for ( - const v of _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array == null - ? [] - : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array.length === 1 && \\"@list\\" in _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0] - ? _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0][\\"@list\\"] - : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array - ) { - if (v == null) continue; - - const decoded = await Measure.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.push(decoded); - } - instance.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; + async #repliesOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, + try { + return await Object.fromJsonLd( jsonLd, - options.contextLoader, + { documentLoader, contextLoader, tracerProvider, baseUrl }, ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected _getCustomInspectProxy(): Record { - - const proxy: Record = {}; - if (this.id != null) { - proxy.id = { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(this.id!.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(this.id!.href, options), - }; - } - - const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.length == 1) { - proxy.satisfies = _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies[0]; - } - const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); + } + - if (_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length == 1) { - proxy.resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; + /** + * Similar to + * {@link Collection.getRepliesOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get repliesOfId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.length < 1) return null; + const v = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0]; + if (v instanceof URL) return v; + return v.id; } - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Commitment.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Commitment, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Commitment \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Commitment.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Commitment, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Commitment \\" + inspect(proxy, options); - }; - /** A proposed economic transaction describing what is being offered or requested - * in a {@link Proposal}. +/** Defines an object for which the collection is the value of the replies property. * */ -export class Intent { - readonly #documentLoader?: DocumentLoader; - readonly #contextLoader?: DocumentLoader; - readonly #tracerProvider?: TracerProvider; - readonly #warning?: { - category: string[]; - message: string; - values?: Record; - }; - #cachedJsonLd?: unknown; - readonly #_baseUrl?: URL; - readonly id: URL | null; - - protected get _documentLoader(): DocumentLoader | undefined { - return this.#documentLoader; - } - - protected get _contextLoader(): DocumentLoader | undefined { - return this.#contextLoader; - } - - protected get _tracerProvider(): TracerProvider | undefined { - return this.#tracerProvider; - } - - protected get _warning(): { - category: string[]; - message: string; - values?: Record; - } | undefined { - return this.#warning; - } - - protected get _cachedJsonLd(): unknown | undefined { - return this.#cachedJsonLd; - } - - protected set _cachedJsonLd(value: unknown | undefined) { - this.#cachedJsonLd = value; - } - - protected get _baseUrl(): URL | undefined { - return this.#_baseUrl; - } - - /** - * The type URI of {@link Intent}: \`https://w3id.org/valueflows/ont/vf#Intent\`. - */ - static get typeId(): URL { - return new URL(\\"https://w3id.org/valueflows/ont/vf#Intent\\"); - } - #_38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; -#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo: (URL)[] = []; -#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; -#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity: (Measure)[] = []; -#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity: (Measure)[] = []; - - /** - * Constructs a new instance of Intent with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measure | null;availableQuantity?: Measure | null;minimumQuantity?: Measure | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - - this.#documentLoader = options.documentLoader; - this.#contextLoader = options.contextLoader; - this.#tracerProvider = options.tracerProvider; - const baseUrl = (options as { baseUrl?: URL }).baseUrl; - this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); - if (\\"\$warning\\" in options) { - this.#warning = options.\$warning as unknown as { - category: string[]; - message: string; - values?: Record; - }; - } - if (values.id == null || values.id instanceof URL) { - this.id = values.id ?? null; - } else { - throw new TypeError(\\"The id must be a URL.\\"); - } - - if (\\"action\\" in values && values.action != null) { - if (typeof values.action === \\"string\\") { - // @ts-ignore: type is checked above. - this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = [values.action]; - - } else { - throw new TypeError( - \\"The action must be of type \\" + - \\"string\\" + \\".\\", - ); - } + async getRepliesOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); } - - if (\\"resourceConformsTo\\" in values && values.resourceConformsTo != null) { - if (values.resourceConformsTo instanceof URL) { - // @ts-ignore: type is checked above. - this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = [values.resourceConformsTo]; - - } else { - throw new TypeError( - \\"The resourceConformsTo must be of type \\" + - \\"URL\\" + \\".\\", - ); - } - } - - if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { - if (values.resourceQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; - - } else { - throw new TypeError( - \\"The resourceQuantity must be of type \\" + - \\"Measure\\" + \\".\\", - ); - } + if (this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.length < 1) return null; + let v = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { + v = v.id; } - - if (\\"availableQuantity\\" in values && values.availableQuantity != null) { - if (values.availableQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = [values.availableQuantity]; - - } else { - throw new TypeError( - \\"The availableQuantity must be of type \\" + - \\"Measure\\" + \\".\\", - ); - } + if (v instanceof URL) { + const fetched = + await this.#fetchRepliesOf(v, options); + if (fetched == null) return null; + this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0] = fetched; + this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.add(0); + this._cachedJsonLd = undefined; + return fetched; } - if (\\"minimumQuantity\\" in values && values.minimumQuantity != null) { - if (values.minimumQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = [values.minimumQuantity]; + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"repliesOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"repliesOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - } else { - throw new TypeError( - \\"The minimumQuantity must be of type \\" + - \\"Measure\\" + \\".\\", - ); - } - } - } - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - clone( - values: - { -id?: URL | null; -action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measure | null;availableQuantity?: Measure | null;minimumQuantity?: Measure | null;} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Intent { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - - // @ts-ignore: this.constructor is not recognized as a constructor, but it is. - const clone: Intent = new this.constructor( - { id: values.id ?? this.id }, - options - ); - clone.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action; - if (\\"action\\" in values && values.action != null) { - if (typeof values.action === \\"string\\") { - // @ts-ignore: type is checked above. - clone.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = [values.action]; + v = await this.#repliesOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - } else { - throw new TypeError( - \\"The action must be of type \\" + - \\"string\\" + \\".\\", - ); } } - clone.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo; - if (\\"resourceConformsTo\\" in values && values.resourceConformsTo != null) { - if (values.resourceConformsTo instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = [values.resourceConformsTo]; - - } else { - throw new TypeError( - \\"The resourceConformsTo must be of type \\" + - \\"URL\\" + \\".\\", + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' ); } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; } - clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; - if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { - if (values.resourceQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; + return v; + } - } else { - throw new TypeError( - \\"The resourceQuantity must be of type \\" + - \\"Measure\\" + \\".\\", + async #fetchInboxOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } ); + return null; } + throw error; } - clone.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity; - if (\\"availableQuantity\\" in values && values.availableQuantity != null) { - if (values.availableQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - clone.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = [values.availableQuantity]; - - } else { - throw new TypeError( - \\"The availableQuantity must be of type \\" + - \\"Measure\\" + \\".\\", + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#inboxOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, ); + return null; } - } - clone.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity; - if (\\"minimumQuantity\\" in values && values.minimumQuantity != null) { - if (values.minimumQuantity instanceof Measure) { - // @ts-ignore: type is checked above. - clone.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = [values.minimumQuantity]; - - } else { - throw new TypeError( - \\"The minimumQuantity must be of type \\" + - \\"Measure\\" + \\".\\", + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } ); + return null; } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); } - - return clone; - } - -/** The type of economic transaction. The value of this property should be - * either \`\\"deliverService\\"\` or \`\\"transfer\\"\`. - * - */ - get action(): (string | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action.length < 1) return null; - return this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action[0]; + }); + } + + async #inboxOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL } - -/** The type of an economic resource. Could be any URI. - * - */ - get resourceConformsTo(): (URL | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - if (this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.length < 1) return null; - return this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo[0]; - } -/** The amount and unit of the economic resource. - * - */ - get resourceQuantity(): (Measure | null) { + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link Collection.getInboxOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get inboxOfId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length < 1) return null; - return this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; + if (this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.length < 1) return null; + const v = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0]; + if (v instanceof URL) return v; + return v.id; } -/** The quantity of the offered resource currently available. +/** Defines an actor for which the collection is the value of the inbox property. * */ - get availableQuantity(): (Measure | null) { + + async getInboxOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity.length < 1) return null; - return this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity[0]; - } - -/** The minimum possible quantity of the resource. - * - */ - get minimumQuantity(): (Measure | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); + if (this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.length < 1) return null; + let v = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchInboxOf(v, options); + if (fetched == null) return null; + this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0] = fetched; + this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.add(0); + this._cachedJsonLd = undefined; + return fetched; } - if (this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity.length < 1) return null; - return this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity[0]; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { - const result: Record = {}; - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"action\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { - const item = ( - formatIri(v) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - result[\\"resourceConformsTo\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"inboxOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"inboxOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - compactItems = []; - for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { + v = await this.#inboxOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - result[\\"resourceQuantity\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; + } + } + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; } - compactItems = []; - for (const v of this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"availableQuantity\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"minimumQuantity\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"Intent\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Intent\\":\\"vf:Intent\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - const values: Record = {}; - array = []; - for (const v of this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#action\\"] = propValue; - - } - - array = []; - for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { - const element = ( - { \\"@id\\": formatIri(v) } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\"] = propValue; - - } - - array = []; - for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"] = propValue; - - } - - array = []; - for (const v of this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#availableQuantity\\"] = propValue; - - } - - array = []; - for (const v of this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#minimumQuantity\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Intent\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, + async #fetchOutboxOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", ); - } - const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Intent\\":\\"vf:Intent\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - } - return compacted; - } - - protected isCompactable(): boolean { - - return true; - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__Intent__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } 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: lookupUrl } + ); + return null; + } throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#outboxOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; } finally { span.end(); } - }, - ); - } - - protected static async __fromJsonLd__Intent__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Intent\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - const instance = new this( - { - id - }, - options, - ); - const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; - - let _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array = values[\\"https://w3id.org/valueflows/ont/vf#action\\"]; - - for ( - const v of _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array == null - ? [] - : _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array.length === 1 && \\"@list\\" in _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array[0] - ? _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array[0][\\"@list\\"] - : _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _38VmZKmXJSBy3AvgqNa9GVqbdphy_action.push(decoded); - } - instance.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = _38VmZKmXJSBy3AvgqNa9GVqbdphy_action; - const _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo: (URL)[] = []; - - let _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array = values[\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\"]; - - for ( - const v of _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array == null - ? [] - : _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array.length === 1 && \\"@list\\" in _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array[0] - ? _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array[0][\\"@list\\"] - : _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array - ) { - if (v == null) continue; - - const decoded = parseIri(v[\\"@id\\"], options.baseUrl); - if (typeof decoded === \\"undefined\\") continue; - _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.push(decoded); - } - instance.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo; - const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; - - let _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"]; - - for ( - const v of _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array == null - ? [] - : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array.length === 1 && \\"@list\\" in _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0] - ? _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0][\\"@list\\"] - : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array - ) { - if (v == null) continue; - - const decoded = await Measure.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.push(decoded); } - instance.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; - const _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity: (Measure)[] = []; - let _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#availableQuantity\\"]; - - for ( - const v of _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array == null - ? [] - : _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array.length === 1 && \\"@list\\" in _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array[0] - ? _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array[0][\\"@list\\"] - : _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array - ) { - if (v == null) continue; + async #outboxOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - const decoded = await Measure.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity.push(decoded); + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } 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\\"].join(\\", \\")); } - instance.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity; - const _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity: (Measure)[] = []; - let _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#minimumQuantity\\"]; - - for ( - const v of _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array == null - ? [] - : _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array.length === 1 && \\"@list\\" in _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array[0] - ? _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array[0][\\"@list\\"] - : _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array - ) { - if (v == null) continue; - - const decoded = await Measure.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity.push(decoded); - } - instance.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, + /** + * Similar to + * {@link Collection.getOutboxOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get outboxOfId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected _getCustomInspectProxy(): Record { - - const proxy: Record = {}; - if (this.id != null) { - proxy.id = { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(this.id!.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(this.id!.href, options), - }; - } - - const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action = this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_38VmZKmXJSBy3AvgqNa9GVqbdphy_action.length == 1) { - proxy.action = _38VmZKmXJSBy3AvgqNa9GVqbdphy_action[0]; - } - - const _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.length == 1) { - proxy.resourceConformsTo = _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo[0]; - } - - const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length == 1) { - proxy.resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; - } - - const _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity.length == 1) { - proxy.availableQuantity = _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity[0]; - } - - const _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity.length == 1) { - proxy.minimumQuantity = _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity[0]; + if (this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.length < 1) return null; + const v = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0]; + if (v instanceof URL) return v; + return v.id; } - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Intent.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Intent, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Intent \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Intent.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Intent, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Intent \\" + inspect(proxy, options); - }; - /** A published request or offer, sometimes with what is expected in return. - * - * Proposals contain a primary {@link Intent} (via \`publishes\`) describing - * what is being offered or requested, and optionally a reciprocal - * {@link Intent} describing what is expected or offered in return. - * - * Note: This type extends ActivityStreams \`Object\` for practical - * interoperability within ActivityPub federation, even though FEP-0837 - * defines \`Proposal\` as a pure ValueFlows type. Extending \`Object\` - * provides useful inherited properties such as \`name\`, \`content\`, - * \`attributedTo\`, \`published\`, \`to\`, and \`location\` without needing to - * redefine them. +/** Defines an actor for which the collection is the value of the outbox property. * */ -export class Proposal extends Object { - - /** - * The type URI of {@link Proposal}: \`https://w3id.org/valueflows/ont/vf#Proposal\`. - */ - static override get typeId(): URL { - return new URL(\\"https://w3id.org/valueflows/ont/vf#Proposal\\"); - } - #_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose: (string)[] = []; -#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes: (Intent)[] = []; -#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal: (Intent)[] = []; -#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased: (boolean)[] = []; - /** - * Constructs a new instance of Proposal with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;purpose?: string | null;publishes?: Intent | null;reciprocal?: Intent | null;unitBased?: boolean | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options); - if (\\"purpose\\" in values && values.purpose != null) { - if (typeof values.purpose === \\"string\\") { - // @ts-ignore: type is checked above. - this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = [values.purpose]; - - } else { - throw new TypeError( - \\"The purpose must be of type \\" + - \\"string\\" + \\".\\", - ); - } + async getOutboxOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); } - - if (\\"publishes\\" in values && values.publishes != null) { - if (values.publishes instanceof Intent) { - // @ts-ignore: type is checked above. - this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = [values.publishes]; - - } else { - throw new TypeError( - \\"The publishes must be of type \\" + - \\"Intent\\" + \\".\\", - ); - } + if (this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.length < 1) return null; + let v = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchOutboxOf(v, options); + if (fetched == null) return null; + this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0] = fetched; + this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.add(0); + this._cachedJsonLd = undefined; + return fetched; } - if (\\"reciprocal\\" in values && values.reciprocal != null) { - if (values.reciprocal instanceof Intent) { - // @ts-ignore: type is checked above. - this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = [values.reciprocal]; + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"outboxOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"outboxOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#outboxOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - } else { - throw new TypeError( - \\"The reciprocal must be of type \\" + - \\"Intent\\" + \\".\\", - ); } } - - if (\\"unitBased\\" in values && values.unitBased != null) { - if (typeof values.unitBased === \\"boolean\\") { - // @ts-ignore: type is checked above. - this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = [values.unitBased]; - - } else { - throw new TypeError( - \\"The unitBased must be of type \\" + - \\"boolean\\" + \\".\\", + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' ); } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; } + return v; } - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;purpose?: string | null;publishes?: Intent | null;reciprocal?: Intent | null;unitBased?: boolean | null;} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Proposal { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Proposal;clone.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose; - if (\\"purpose\\" in values && values.purpose != null) { - if (typeof values.purpose === \\"string\\") { - // @ts-ignore: type is checked above. - clone.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = [values.purpose]; - } else { - throw new TypeError( - \\"The purpose must be of type \\" + - \\"string\\" + \\".\\", + async #fetchFollowersOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } ); + return null; } + throw error; } - clone.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes; - if (\\"publishes\\" in values && values.publishes != null) { - if (values.publishes instanceof Intent) { - // @ts-ignore: type is checked above. - clone.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = [values.publishes]; - - } else { - throw new TypeError( - \\"The publishes must be of type \\" + - \\"Intent\\" + \\".\\", + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#followersOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, ); + return null; } - } - clone.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal; - if (\\"reciprocal\\" in values && values.reciprocal != null) { - if (values.reciprocal instanceof Intent) { - // @ts-ignore: type is checked above. - clone.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = [values.reciprocal]; - - } else { - throw new TypeError( - \\"The reciprocal must be of type \\" + - \\"Intent\\" + \\".\\", + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } ); + return null; } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); } - clone.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased; - if (\\"unitBased\\" in values && values.unitBased != null) { - if (typeof values.unitBased === \\"boolean\\") { - // @ts-ignore: type is checked above. - clone.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = [values.unitBased]; - - } else { - throw new TypeError( - \\"The unitBased must be of type \\" + - \\"boolean\\" + \\".\\", - ); - } + }); + } + + async #followersOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - return clone; - } - -/** The type of proposal. Possible values are \`\\"offer\\"\` and \`\\"request\\"\`. - * - */ - get purpose(): (string | null) { + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link Collection.getFollowersOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get followersOfId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose.length < 1) return null; - return this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose[0]; + if (this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.length < 1) return null; + const v = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0]; + if (v instanceof URL) return v; + return v.id; } -/** The primary intent of this proposal, describing what is being offered - * or requested. +/** Defines an actor for which the collection is the value of the followers property. * */ - get publishes(): (Intent | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes.length < 1) return null; - return this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes[0]; - } - -/** The reciprocal intent of this proposal, describing what is expected - * or offered in return. - * - */ - get reciprocal(): (Intent | null) { + + async getFollowersOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal.length < 1) return null; - return this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal[0]; - } - -/** Indicates whether the quantities expressed in the proposal can be - * multiplied or not. The default is \`false\`. - * - */ - get unitBased(): (boolean | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); + if (this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.length < 1) return null; + let v = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchFollowersOf(v, options); + if (fetched == null) return null; + this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0] = fetched; + this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.add(0); + this._cachedJsonLd = undefined; + return fetched; } - if (this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased.length < 1) return null; - return this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased[0]; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { - - const result = await super.toJsonLd({ - ...options, - format: undefined, - context: undefined, - }) as Record; - - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"purpose\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"publishes\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - result[\\"reciprocal\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"followersOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"followersOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - compactItems = []; - for (const v of this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { + v = await this.#followersOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - result[\\"unitBased\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; + } + } - } - - result[\\"type\\"] = \\"Proposal\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Proposal\\":\\"vf:Proposal\\",\\"Intent\\":\\"vf:Intent\\",\\"purpose\\":\\"vf:purpose\\",\\"unitBased\\":\\"vf:unitBased\\",\\"publishes\\":\\"vf:publishes\\",\\"reciprocal\\":\\"vf:reciprocal\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; - - array = []; - for (const v of this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#purpose\\"] = propValue; - - } - - array = []; - for (const v of this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#publishes\\"] = propValue; - - } - - array = []; - for (const v of this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal) { - const element = ( - await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#reciprocal\\"] = propValue; - - } - - array = []; - for (const v of this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/valueflows/ont/vf#unitBased\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Proposal\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, - ); - } - const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Proposal\\":\\"vf:Proposal\\",\\"Intent\\":\\"vf:Intent\\",\\"purpose\\":\\"vf:purpose\\",\\"unitBased\\":\\"vf:unitBased\\",\\"publishes\\":\\"vf:publishes\\",\\"reciprocal\\":\\"vf:reciprocal\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); } - } else { - compacted.proof[\\"@context\\"] = docContext; + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; } + return v; } - } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { + async #fetchFollowingOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; try { - const object = await this.__fromJsonLd__Proposal__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; + fetchResult = await documentLoader(lookupUrl); } 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: lookupUrl } + ); + return null; + } throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#followingOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; } finally { span.end(); } - }, - ); - } - - protected static async __fromJsonLd__Proposal__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Proposal\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - delete values[\\"@type\\"]; - const instance = await super.fromJsonLd(values, { - ...options, - // @ts-ignore: an internal option - _fromSubclass: true, - }); - if (!(instance instanceof Proposal)) { - throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } - const _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose: (string)[] = []; - let _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array = values[\\"https://w3id.org/valueflows/ont/vf#purpose\\"]; - - for ( - const v of _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array == null - ? [] - : _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array.length === 1 && \\"@list\\" in _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array[0] - ? _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array[0][\\"@list\\"] - : _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array - ) { - if (v == null) continue; + async #followingOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose.push(decoded); + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } 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\\"].join(\\", \\")); } - instance.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose; - const _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes: (Intent)[] = []; - let _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array = values[\\"https://w3id.org/valueflows/ont/vf#publishes\\"]; - - for ( - const v of _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array == null - ? [] - : _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array.length === 1 && \\"@list\\" in _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array[0] - ? _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array[0][\\"@list\\"] - : _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array - ) { - if (v == null) continue; - const decoded = await Intent.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes.push(decoded); - } - instance.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes; - const _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal: (Intent)[] = []; + /** + * Similar to + * {@link Collection.getFollowingOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get followingOfId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.length < 1) return null; + const v = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0]; + if (v instanceof URL) return v; + return v.id; + } + +/** Defines an actor for which the collection is the value of the following property. + * + */ - let _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array = values[\\"https://w3id.org/valueflows/ont/vf#reciprocal\\"]; - - for ( - const v of _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array == null - ? [] - : _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array.length === 1 && \\"@list\\" in _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array[0] - ? _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array[0][\\"@list\\"] - : _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array - ) { - if (v == null) continue; - - const decoded = await Intent.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal.push(decoded); + async getFollowingOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.length < 1) return null; + let v = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchFollowingOf(v, options); + if (fetched == null) return null; + this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0] = fetched; + this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.add(0); + this._cachedJsonLd = undefined; + return fetched; + } + + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"followingOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"followingOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#followingOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; + } + + async #fetchLikedOf( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } + ); + return null; + } + throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#likedOf_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); + } + }); } - instance.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal; - const _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased: (boolean)[] = []; - let _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array = values[\\"https://w3id.org/valueflows/ont/vf#unitBased\\"]; - - for ( - const v of _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array == null - ? [] - : _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array.length === 1 && \\"@list\\" in _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array[0] - ? _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array[0][\\"@list\\"] - : _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array - ) { - if (v == null) continue; + async #likedOf_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased.push(decoded); + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } 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\\"].join(\\", \\")); } - instance.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased; + - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, + /** + * Similar to + * {@link Collection.getLikedOf}, + * but returns its \`@id\` URL instead of the object itself. + */ + get likedOfId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); + if (this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.length < 1) return null; + const v = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0]; + if (v instanceof URL) return v; + return v.id; + } + +/** Defines an actor for which the collection is the value of the liked property. + * + */ + + async getLikedOf( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.length < 1) return null; + let v = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchLikedOf(v, options); + if (fetched == null) return null; + this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0] = fetched; + this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.add(0); + this._cachedJsonLd = undefined; + return fetched; + } + + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"likedOf\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"likedOf\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#likedOf_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; } + + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; } - return instance; - } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - const _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); + if (options.format == null && this.isCompactable()) { - if (_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose.length == 1) { - proxy.purpose = _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose[0]; - } + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; - const _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; - if (_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes.length == 1) { - proxy.publishes = _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes[0]; + compactItems = []; + for (const v of this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems) { + const item = ( + v + ); + compactItems.push(item); } + if (compactItems.length > 0) { - const _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal.length == 1) { - proxy.reciprocal = _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal[0]; + result[\\"totalItems\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + } - const _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased.length == 1) { - proxy.unitBased = _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased[0]; + compactItems = []; + for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); } + if (compactItems.length > 0) { - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Proposal.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Proposal, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Proposal \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Proposal.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Proposal, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Proposal \\" + inspect(proxy, options); - }; - /** Indicates that the \`actor\` accepts the \`object\`. The \`target\` property can be - * used in certain circumstances to indicate the context into which the \`object\` - * has been accepted. - * - */ -export class Accept extends Activity { - - /** - * The type URI of {@link Accept}: \`https://www.w3.org/ns/activitystreams#Accept\`. - */ - static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Accept\\"); - } - - /** - * Constructs a new instance of Accept with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options);} - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Accept { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Accept; - return clone; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); + result[\\"current\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"first\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"last\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { + const item = ( + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"items\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"likesOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"sharesOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"repliesOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"inboxOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"outboxOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"followersOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"followingOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"likedOf\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + result[\\"type\\"] = \\"Collection\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; + return result; } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - + // deno-lint-ignore no-unused-vars prefer-const let array: unknown[]; @@ -33776,373 +31952,205 @@ instruments?: (Object | URL)[];} unknown[] | { \\"@list\\": unknown[] } | string >; - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Accept\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, + array = []; + for (const v of this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems) { + const element = ( + { + \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\", + \\"@value\\": v, + } ); + array.push(element);; } - const docContext = options.context ?? - [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; - } - } else { - compacted.proof[\\"@context\\"] = docContext; - } - } - + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://www.w3.org/ns/activitystreams#totalItems\\"] = propValue; + } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { - try { - const object = await this.__fromJsonLd__Accept__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; - } catch (error) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(error), - }); - throw error; - } finally { - span.end(); - } - }, - ); - } - - protected static async __fromJsonLd__Accept__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + + array = []; + for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, - }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://www.w3.org/ns/activitystreams#current\\"] = propValue; + } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; + + array = []; + for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\")) { - return await TentativeAccept.fromJsonLd(json, options); + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://www.w3.org/ns/activitystreams#first\\"] = propValue; + } - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Accept\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + array = []; + for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://www.w3.org/ns/activitystreams#last\\"] = propValue; + } - - delete values[\\"@type\\"]; - const instance = await super.fromJsonLd(values, { - ...options, - // @ts-ignore: an internal option - _fromSubclass: true, - }); - if (!(instance instanceof Accept)) { - throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + + array = []; + for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + ); + array.push(element);; } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://www.w3.org/ns/activitystreams#items\\"] = propValue; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, - ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); - } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } } - return instance; - } - - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Accept.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Accept, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Accept \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Accept.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Accept, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Accept \\" + inspect(proxy, options); - }; - /** Indicates that the \`actor\` has added the \`object\` to the \`target\`. - * If the \`target\` property is not explicitly specified, the target would need - * to be determined implicitly by context. The \`origin\` can be used to identify - * the context from which the \`object\` originated. - * - */ -export class Add extends Activity { - - /** - * The type URI of {@link Add}: \`https://www.w3.org/ns/activitystreams#Add\`. - */ - static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Add\\"); + + array = []; + for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; } - - /** - * Constructs a new instance of Add with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options);} - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Add { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values + if (array.length > 0) { + const propValue = ( + array ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; + values[\\"https://w3id.org/fep/5711#likesOf\\"] = propValue; + } - const clone = super.clone(values, options) as unknown as Add; - return clone; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; + + array = []; + for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" + if (array.length > 0) { + const propValue = ( + array ); + values[\\"https://w3id.org/fep/5711#sharesOf\\"] = propValue; + } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Add\\"]; + array = []; + for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/5711#repliesOf\\"] = propValue; + + } + + array = []; + for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/5711#inboxOf\\"] = propValue; + + } + + array = []; + for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/5711#outboxOf\\"] = propValue; + + } + + array = []; + for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/5711#followersOf\\"] = propValue; + + } + + array = []; + for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/5711#followingOf\\"] = propValue; + + } + + array = []; + for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/5711#likedOf\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Collection\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -34151,7 +32159,7 @@ instruments?: (Object | URL)[];} ); } const docContext = options.context ?? - [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; const compacted = await jsonld.compact( values, docContext, @@ -34199,7 +32207,7 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -34209,7 +32217,7 @@ instruments?: (Object | URL)[];} \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__Add__( + const object = await this.__fromJsonLd__Collection__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -34228,7 +32236,7 @@ instruments?: (Object | URL)[];} ); } - protected static async __fromJsonLd__Add__( + protected static async __fromJsonLd__Collection__( json: unknown, span: Span, options: { @@ -34237,7 +32245,7 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -34274,7 +32282,23 @@ instruments?: (Object | URL)[];} if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Add\\")) { + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#CollectionPage\\")) { + return await CollectionPage.fromJsonLd(json, options); + } + + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\")) { + return await OrderedCollectionPage.fromJsonLd(json, options); + } + + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\")) { + return await OrderedCollection.fromJsonLd(json, options); + } + + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeaturedCollection\\")) { + return await FeaturedCollection.fromJsonLd(json, options); + } + + if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Collection\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -34296,1246 +32320,1591 @@ instruments?: (Object | URL)[];} // @ts-ignore: an internal option _fromSubclass: true, }); - if (!(instance instanceof Add)) { + if (!(instance instanceof Collection)) { throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } + const _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems: (number)[] = []; + + let _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems__array = values[\\"https://www.w3.org/ns/activitystreams#totalItems\\"]; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, - ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); - } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Add.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Add, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Add \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Add.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Add, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Add \\" + inspect(proxy, options); - }; - /** Indicates that the \`actor\` is calling the \`target\`'s attention the \`object\`. - * - * The \`origin\` typically has no defined meaning. - * - */ -export class Announce extends Activity { - - /** - * The type URI of {@link Announce}: \`https://www.w3.org/ns/activitystreams#Announce\`. - */ - static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Announce\\"); - } - - /** - * Constructs a new instance of Announce with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options);} - - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} - - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Announce { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Announce; - return clone; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; + for ( + const v of _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems__array == null + ? [] + : _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems__array.length === 1 && \\"@list\\" in _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems__array[0] + ? _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems__array[0][\\"@list\\"] + : _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems__array + ) { + if (v == null) continue; - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Announce\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, - ); + const decoded = v[\\"@value\\"]; + if (typeof decoded === \\"undefined\\") continue; + _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems.push(decoded); } - const docContext = options.context ?? - [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":{\\"@id\\":\\"toot:votersCount\\",\\"@type\\":\\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\"},\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; - } - } else { - compacted.proof[\\"@context\\"] = docContext; - } + instance.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems = _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems; + + const _3UyUdxnyn6cDn53QKrh4MBiearma_current: (CollectionPage | URL)[] = []; + const _trust_3UyUdxnyn6cDn53QKrh4MBiearma_current: Set = new Set(); + + let _3UyUdxnyn6cDn53QKrh4MBiearma_current__array = values[\\"https://www.w3.org/ns/activitystreams#current\\"]; + + for ( + const v of _3UyUdxnyn6cDn53QKrh4MBiearma_current__array == null + ? [] + : _3UyUdxnyn6cDn53QKrh4MBiearma_current__array.length === 1 && \\"@list\\" in _3UyUdxnyn6cDn53QKrh4MBiearma_current__array[0] + ? _3UyUdxnyn6cDn53QKrh4MBiearma_current__array[0][\\"@list\\"] + : _3UyUdxnyn6cDn53QKrh4MBiearma_current__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _3UyUdxnyn6cDn53QKrh4MBiearma_current.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; } - } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { - try { - const object = await this.__fromJsonLd__Announce__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; - } catch (error) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(error), - }); - throw error; - } finally { - span.end(); - } - }, + const decoded = await CollectionPage.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } ); - } - - protected static async __fromJsonLd__Announce__( - json: unknown, - span: Span, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise { - if (typeof json === \\"undefined\\") { - throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); - } - else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); - options = { - ...options, - documentLoader: options.documentLoader ?? getDocumentLoader(), - contextLoader: options.contextLoader ?? getDocumentLoader(), - tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), - }; - // deno-lint-ignore no-explicit-any - let values: Record & { \\"@id\\"?: string }; - let expanded: unknown[]; - if (globalThis.Object.keys(json).length == 0) { - values = {}; - expanded = [values]; - } else { - expanded = await jsonld.expand(json, { - documentLoader: options.contextLoader, - keepFreeFloatingNodes: true, - }); - values = - // deno-lint-ignore no-explicit-any - (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); - } - const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); - if (id != null && options.baseUrl == null) { - options = { ...options, baseUrl: id }; - } - - if (\\"@type\\" in values) { - span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); - } - if (\\"@type\\" in values && - !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Announce\\")) { - throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); - } - } - - let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass - ? normalizeJsonLdIris( - expanded, - PORTABLE_IRI_KEYS, - PORTABLE_IRI_PATTERN, - ) - : undefined; - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - cacheJsonLd = structuredClone(cacheJsonLd); - } - - delete values[\\"@type\\"]; - const instance = await super.fromJsonLd(values, { - ...options, - // @ts-ignore: an internal option - _fromSubclass: true, - }); - if (!(instance instanceof Announce)) { - throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + if (typeof decoded === \\"undefined\\") continue; + _3UyUdxnyn6cDn53QKrh4MBiearma_current.push(decoded); } + instance.#_3UyUdxnyn6cDn53QKrh4MBiearma_current = _3UyUdxnyn6cDn53QKrh4MBiearma_current; - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, - ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); - } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); + const _J52RqweMe6hhv7RnLJMC8BExTE5_first: (CollectionPage | URL)[] = []; + const _trust_J52RqweMe6hhv7RnLJMC8BExTE5_first: Set = new Set(); + + let _J52RqweMe6hhv7RnLJMC8BExTE5_first__array = values[\\"https://www.w3.org/ns/activitystreams#first\\"]; + + for ( + const v of _J52RqweMe6hhv7RnLJMC8BExTE5_first__array == null + ? [] + : _J52RqweMe6hhv7RnLJMC8BExTE5_first__array.length === 1 && \\"@list\\" in _J52RqweMe6hhv7RnLJMC8BExTE5_first__array[0] + ? _J52RqweMe6hhv7RnLJMC8BExTE5_first__array[0][\\"@list\\"] + : _J52RqweMe6hhv7RnLJMC8BExTE5_first__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _J52RqweMe6hhv7RnLJMC8BExTE5_first.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; } + + const decoded = await CollectionPage.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _J52RqweMe6hhv7RnLJMC8BExTE5_first.push(decoded); } - return instance; - } - - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Announce.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Announce, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Announce \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Announce.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Announce, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Announce \\" + inspect(proxy, options); - }; - /** Describes a software application. - */ -export class Application extends Object { - - /** - * The type URI of {@link Application}: \`https://www.w3.org/ns/activitystreams#Application\`. - */ - static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Application\\"); - } - #_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername: ((string | LanguageString))[] = []; - - #_axq166E2eZADq34V4MYUc8KMZdC_publicKey: (CryptographicKey | URL)[] = []; - #_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey: Set = new Set(); - - #_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod: (Multikey | URL)[] = []; - #_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod: Set = new Set(); - #_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers: (boolean)[] = []; - - #_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox: (OrderedCollection | OrderedCollectionPage | URL)[] = []; - #_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox: Set = new Set(); + instance.#_J52RqweMe6hhv7RnLJMC8BExTE5_first = _J52RqweMe6hhv7RnLJMC8BExTE5_first; - #_41QwhqJouoLg3h8dRPKat21brynC_outbox: (OrderedCollection | OrderedCollectionPage | URL)[] = []; - #_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox: Set = new Set(); + const _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last: (CollectionPage | URL)[] = []; + const _trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last: Set = new Set(); - #_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following: (Collection | URL)[] = []; - #_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following: Set = new Set(); + let _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last__array = values[\\"https://www.w3.org/ns/activitystreams#last\\"]; - #_BBCTgfphhsFzpVfKTykGSpBNwoA_followers: (Collection | URL)[] = []; - #_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers: Set = new Set(); + for ( + const v of _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last__array == null + ? [] + : _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last__array.length === 1 && \\"@list\\" in _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last__array[0] + ? _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last__array[0][\\"@list\\"] + : _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last__array + ) { + if (v == null) continue; - #_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked: (Collection | URL)[] = []; - #_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked: Set = new Set(); + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } + + const decoded = await CollectionPage.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push(decoded); + } + instance.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last; - #_4N1vBJzXDf8NbBumeECQMFvKetja_featured: (Collection | URL)[] = []; - #_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured: Set = new Set(); + const _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: (Object | Link | URL)[] = []; + const _trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: Set = new Set(); - #_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags: (Collection | URL)[] = []; - #_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags: Set = new Set(); + let _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array = values[\\"https://www.w3.org/ns/activitystreams#items\\"]; - #_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams: (Collection | URL)[] = []; - #_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams: Set = new Set(); - #_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints: (Endpoints)[] = []; -#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable: (boolean)[] = []; -#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended: (boolean)[] = []; -#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial: (boolean)[] = []; -#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable: (boolean)[] = []; - - #_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo: (Application | Group | Organization | Person | Service | URL)[] = []; - #_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo: Set = new Set(); - - #_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs: (Application | Group | Organization | Person | Service | URL)[] = []; - #_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs: Set = new Set(); + for ( + const v of _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array == null + ? [] + : _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array.length === 1 && \\"@list\\" in _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array[0] + ? _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array[0][\\"@list\\"] + : _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array + ) { + if (v == null) continue; - #_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service: (DidService | URL)[] = []; - #_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service: Set = new Set(); - #_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage: (string)[] = []; -#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat: (boolean)[] = []; - - /** - * Constructs a new instance of Application with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;preferredUsername?: string | LanguageString | null; -preferredUsernames?: ((string | LanguageString))[];publicKey?: CryptographicKey | URL | null; -publicKeys?: (CryptographicKey | URL)[];assertionMethod?: Multikey | URL | null; -assertionMethods?: (Multikey | URL)[];manuallyApprovesFollowers?: boolean | null;inbox?: OrderedCollection | OrderedCollectionPage | URL | null;outbox?: OrderedCollection | OrderedCollectionPage | URL | null;following?: Collection | URL | null;followers?: Collection | URL | null;liked?: Collection | URL | null;featured?: Collection | URL | null;featuredTags?: Collection | URL | null;streams?: (Collection | URL)[];endpoints?: Endpoints | null;discoverable?: boolean | null;suspended?: boolean | null;memorial?: boolean | null;indexable?: boolean | null;successor?: Application | Group | Organization | Person | Service | URL | null;alias?: Application | Group | Organization | Person | Service | URL | null; -aliases?: (Application | Group | Organization | Person | Service | URL)[];service?: DidService | URL | null; -services?: (DidService | URL)[];followedMessage?: string | null;cat?: boolean | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options); - if (\\"preferredUsername\\" in values && values.preferredUsername != null) { - if (typeof values.preferredUsername === \\"string\\" || values.preferredUsername instanceof LanguageString) { - // @ts-ignore: type is checked above. - this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = [values.preferredUsername]; - - } else { - throw new TypeError( - \\"The preferredUsername must be of type \\" + - \\"string | LanguageString\\" + \\".\\", - ); - } - } + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"preferredUsernames\\" in values && values.preferredUsernames != null) { + const decoded = + typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Link\\",\\"https://www.w3.org/ns/activitystreams#Hashtag\\",\\"https://www.w3.org/ns/activitystreams#Mention\\"].some( + t => v[\\"@type\\"].includes(t)) ? await Link.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : undefined + ; + if (typeof decoded === \\"undefined\\") continue; + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(decoded); - if (\\"preferredUsername\\" in values && - values.preferredUsername != null) { - throw new TypeError( - \\"Cannot initialize both preferredUsername and \\" + - \\"preferredUsernames at the same time.\\", - ); - } - - if (Array.isArray(values.preferredUsernames) && - values.preferredUsernames.every(v => typeof v === \\"string\\" || v instanceof LanguageString)) { - // @ts-ignore: type is checked above. - this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = values.preferredUsernames; + } + instance.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; + + const _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf: (Object | URL)[] = []; + const _trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf: Set = new Set(); + + let _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf__array = values[\\"https://w3id.org/fep/5711#likesOf\\"]; + + for ( + const v of _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf__array == null + ? [] + : _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf__array.length === 1 && \\"@list\\" in _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf__array[0] + ? _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf__array[0][\\"@list\\"] + : _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - } else { - throw new TypeError( - \\"The preferredUsernames must be an array of type \\" + - \\"string | LanguageString\\" + \\".\\", - ); - } - } + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push(decoded); + } + instance.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf; + + const _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf: (Object | URL)[] = []; + const _trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf: Set = new Set(); + + let _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf__array = values[\\"https://w3id.org/fep/5711#sharesOf\\"]; + + for ( + const v of _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf__array == null + ? [] + : _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf__array.length === 1 && \\"@list\\" in _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf__array[0] + ? _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf__array[0][\\"@list\\"] + : _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"publicKey\\" in values && values.publicKey != null) { - if (values.publicKey instanceof CryptographicKey || values.publicKey instanceof URL) { - // @ts-ignore: type is checked above. - this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey = [values.publicKey]; - this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.add(0); - } else { - throw new TypeError( - \\"The publicKey must be of type \\" + - \\"CryptographicKey | URL\\" + \\".\\", - ); - } - } + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push(decoded); + } + instance.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf; + + const _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf: (Object | URL)[] = []; + const _trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf: Set = new Set(); + + let _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf__array = values[\\"https://w3id.org/fep/5711#repliesOf\\"]; + + for ( + const v of _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf__array == null + ? [] + : _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf__array.length === 1 && \\"@list\\" in _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf__array[0] + ? _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf__array[0][\\"@list\\"] + : _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"publicKeys\\" in values && values.publicKeys != null) { + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push(decoded); + } + instance.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf; + + const _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf: (Object | URL)[] = []; + const _trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf: Set = new Set(); + + let _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf__array = values[\\"https://w3id.org/fep/5711#inboxOf\\"]; + + for ( + const v of _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf__array == null + ? [] + : _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf__array.length === 1 && \\"@list\\" in _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf__array[0] + ? _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf__array[0][\\"@list\\"] + : _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"publicKey\\" in values && - values.publicKey != null) { - throw new TypeError( - \\"Cannot initialize both publicKey and \\" + - \\"publicKeys at the same time.\\", - ); - } - - if (Array.isArray(values.publicKeys) && - values.publicKeys.every(v => v instanceof CryptographicKey || v instanceof URL)) { - // @ts-ignore: type is checked above. - this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey = values.publicKeys; + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push(decoded); + } + instance.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf; + + const _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf: (Object | URL)[] = []; + const _trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf: Set = new Set(); + + let _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf__array = values[\\"https://w3id.org/fep/5711#outboxOf\\"]; + + for ( + const v of _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf__array == null + ? [] + : _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf__array.length === 1 && \\"@list\\" in _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf__array[0] + ? _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf__array[0][\\"@list\\"] + : _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - for (let i = 0; i < values.publicKeys.length; i++) { - this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.add(i); - } - - } else { - throw new TypeError( - \\"The publicKeys must be an array of type \\" + - \\"CryptographicKey | URL\\" + \\".\\", - ); - } - } + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push(decoded); + } + instance.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf; + + const _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf: (Object | URL)[] = []; + const _trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf: Set = new Set(); + + let _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf__array = values[\\"https://w3id.org/fep/5711#followersOf\\"]; + + for ( + const v of _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf__array == null + ? [] + : _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf__array.length === 1 && \\"@list\\" in _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf__array[0] + ? _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf__array[0][\\"@list\\"] + : _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"assertionMethod\\" in values && values.assertionMethod != null) { - if (values.assertionMethod instanceof Multikey || values.assertionMethod instanceof URL) { - // @ts-ignore: type is checked above. - this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = [values.assertionMethod]; - this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.add(0); - } else { - throw new TypeError( - \\"The assertionMethod must be of type \\" + - \\"Multikey | URL\\" + \\".\\", - ); - } - } + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push(decoded); + } + instance.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf; + + const _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf: (Object | URL)[] = []; + const _trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf: Set = new Set(); + + let _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf__array = values[\\"https://w3id.org/fep/5711#followingOf\\"]; + + for ( + const v of _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf__array == null + ? [] + : _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf__array.length === 1 && \\"@list\\" in _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf__array[0] + ? _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf__array[0][\\"@list\\"] + : _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"assertionMethods\\" in values && values.assertionMethods != null) { + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push(decoded); + } + instance.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf; + + const _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf: (Object | URL)[] = []; + const _trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf: Set = new Set(); + + let _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf__array = values[\\"https://w3id.org/fep/5711#likedOf\\"]; + + for ( + const v of _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf__array == null + ? [] + : _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf__array.length === 1 && \\"@list\\" in _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf__array[0] + ? _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf__array[0][\\"@list\\"] + : _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"assertionMethod\\" in values && - values.assertionMethod != null) { - throw new TypeError( - \\"Cannot initialize both assertionMethod and \\" + - \\"assertionMethods at the same time.\\", - ); - } - - if (Array.isArray(values.assertionMethods) && - values.assertionMethods.every(v => v instanceof Multikey || v instanceof URL)) { - // @ts-ignore: type is checked above. - this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = values.assertionMethods; + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push(decoded); + } + instance.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } + } + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + const _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems = this.#_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_XDbmNDuWHmrhqH712zqtecdbv1V_totalItems.length == 1) { + proxy.totalItems = _XDbmNDuWHmrhqH712zqtecdbv1V_totalItems[0]; + } - for (let i = 0; i < values.assertionMethods.length; i++) { - this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.add(i); + const _3UyUdxnyn6cDn53QKrh4MBiearma_current = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), } - - } else { - throw new TypeError( - \\"The assertionMethods must be an array of type \\" + - \\"Multikey | URL\\" + \\".\\", - ); - } - } + : v); + + if (_3UyUdxnyn6cDn53QKrh4MBiearma_current.length == 1) { + proxy.current = _3UyUdxnyn6cDn53QKrh4MBiearma_current[0]; + } - if (\\"manuallyApprovesFollowers\\" in values && values.manuallyApprovesFollowers != null) { - if (typeof values.manuallyApprovesFollowers === \\"boolean\\") { - // @ts-ignore: type is checked above. - this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers = [values.manuallyApprovesFollowers]; + const _J52RqweMe6hhv7RnLJMC8BExTE5_first = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_J52RqweMe6hhv7RnLJMC8BExTE5_first.length == 1) { + proxy.first = _J52RqweMe6hhv7RnLJMC8BExTE5_first[0]; + } - } else { - throw new TypeError( - \\"The manuallyApprovesFollowers must be of type \\" + - \\"boolean\\" + \\".\\", - ); - } - } - - if (\\"inbox\\" in values && values.inbox != null) { - if (values.inbox instanceof OrderedCollection || values.inbox instanceof OrderedCollectionPage || values.inbox instanceof URL) { - // @ts-ignore: type is checked above. - this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = [values.inbox]; - this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.add(0); - } else { - throw new TypeError( - \\"The inbox must be of type \\" + - \\"OrderedCollection | OrderedCollectionPage | URL\\" + \\".\\", - ); - } - } - - if (\\"outbox\\" in values && values.outbox != null) { - if (values.outbox instanceof OrderedCollection || values.outbox instanceof OrderedCollectionPage || values.outbox instanceof URL) { - // @ts-ignore: type is checked above. - this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox = [values.outbox]; - this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.add(0); - } else { - throw new TypeError( - \\"The outbox must be of type \\" + - \\"OrderedCollection | OrderedCollectionPage | URL\\" + \\".\\", - ); - } - } + const _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.length == 1) { + proxy.last = _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0]; + } - if (\\"following\\" in values && values.following != null) { - if (values.following instanceof Collection || values.following instanceof URL) { - // @ts-ignore: type is checked above. - this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = [values.following]; - this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.add(0); - } else { - throw new TypeError( - \\"The following must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } + const _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.length > 1 + || !(\\"item\\" in proxy) + && _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.length > 0) { + proxy.items = _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; + } - if (\\"followers\\" in values && values.followers != null) { - if (values.followers instanceof Collection || values.followers instanceof URL) { - // @ts-ignore: type is checked above. - this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers = [values.followers]; - this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.add(0); - } else { - throw new TypeError( - \\"The followers must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } + const _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.length == 1) { + proxy.likesOf = _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0]; + } - if (\\"liked\\" in values && values.liked != null) { - if (values.liked instanceof Collection || values.liked instanceof URL) { - // @ts-ignore: type is checked above. - this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = [values.liked]; - this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.add(0); - } else { - throw new TypeError( - \\"The liked must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } + const _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.length == 1) { + proxy.sharesOf = _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0]; + } - if (\\"featured\\" in values && values.featured != null) { - if (values.featured instanceof Collection || values.featured instanceof URL) { - // @ts-ignore: type is checked above. - this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured = [values.featured]; - this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.add(0); - } else { - throw new TypeError( - \\"The featured must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } + const _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.length == 1) { + proxy.repliesOf = _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0]; + } - if (\\"featuredTags\\" in values && values.featuredTags != null) { - if (values.featuredTags instanceof Collection || values.featuredTags instanceof URL) { - // @ts-ignore: type is checked above. - this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = [values.featuredTags]; - this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.add(0); - } else { - throw new TypeError( - \\"The featuredTags must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } + const _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.length == 1) { + proxy.inboxOf = _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0]; + } - if (\\"streams\\" in values && values.streams != null) { + const _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.length == 1) { + proxy.outboxOf = _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0]; + } - if (Array.isArray(values.streams) && - values.streams.every(v => v instanceof Collection || v instanceof URL)) { - // @ts-ignore: type is checked above. - this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = values.streams; + const _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.length == 1) { + proxy.followersOf = _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0]; + } - for (let i = 0; i < values.streams.length; i++) { - this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.add(i); + const _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), } - - } else { - throw new TypeError( - \\"The streams must be an array of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } + : v); + + if (_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.length == 1) { + proxy.followingOf = _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0]; + } - if (\\"endpoints\\" in values && values.endpoints != null) { - if (values.endpoints instanceof Endpoints) { - // @ts-ignore: type is checked above. - this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints = [values.endpoints]; + const _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.length == 1) { + proxy.likedOf = _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0]; + } - } else { - throw new TypeError( - \\"The endpoints must be of type \\" + - \\"Endpoints\\" + \\".\\", - ); - } - } + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(Collection.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Collection, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Collection \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Collection.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Collection, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Collection \\" + inspect(proxy, options); + }; + /** A subtype of {@link Collection} in which members of the logical collection + * are assumed to always be strictly ordered. + * + */ +export class OrderedCollection extends Collection { + + /** + * The type URI of {@link OrderedCollection}: \`https://www.w3.org/ns/activitystreams#OrderedCollection\`. + */ + static override get typeId(): URL { + return new URL(\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\"); + } + + #_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: (Object | Link | URL)[] = []; + #_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: Set = new Set(); + + /** + * Constructs a new instance of OrderedCollection with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;totalItems?: number | null;current?: CollectionPage | URL | null;first?: CollectionPage | URL | null;last?: CollectionPage | URL | null;likesOf?: Object | URL | null;sharesOf?: Object | URL | null;repliesOf?: Object | URL | null;inboxOf?: Object | URL | null;outboxOf?: Object | URL | null;followersOf?: Object | URL | null;followingOf?: Object | URL | null;likedOf?: Object | URL | null;items?: (Object | Link | URL)[];} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + super(values, options); + if (\\"items\\" in values && values.items != null) { - if (\\"discoverable\\" in values && values.discoverable != null) { - if (typeof values.discoverable === \\"boolean\\") { + if (Array.isArray(values.items) && + values.items.every(v => v instanceof Object || v instanceof Link || v instanceof URL)) { // @ts-ignore: type is checked above. - this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable = [values.discoverable]; + this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = values.items; + for (let i = 0; i < values.items.length; i++) { + this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.add(i); + } + } else { throw new TypeError( - \\"The discoverable must be of type \\" + - \\"boolean\\" + \\".\\", + \\"The items must be an array of type \\" + + \\"Object | Link | URL\\" + \\".\\", ); } } + } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + override clone( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;totalItems?: number | null;current?: CollectionPage | URL | null;first?: CollectionPage | URL | null;last?: CollectionPage | URL | null;likesOf?: Object | URL | null;sharesOf?: Object | URL | null;repliesOf?: Object | URL | null;inboxOf?: Object | URL | null;outboxOf?: Object | URL | null;followersOf?: Object | URL | null;followingOf?: Object | URL | null;likedOf?: Object | URL | null;items?: (Object | Link | URL)[];} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): OrderedCollection { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + const clone = super.clone(values, options) as unknown as OrderedCollection;clone.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items;clone.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = new Set(this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items); + if (\\"items\\" in values && values.items != null) { - if (\\"suspended\\" in values && values.suspended != null) { - if (typeof values.suspended === \\"boolean\\") { + if (Array.isArray(values.items) && + values.items.every(v => v instanceof Object || v instanceof Link || v instanceof URL)) { // @ts-ignore: type is checked above. - this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended = [values.suspended]; + clone.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = values.items; + clone.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = new Set(); + for (let i = 0; i < values.items.length; i++) { + clone.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.add(i); + } + } else { throw new TypeError( - \\"The suspended must be of type \\" + - \\"boolean\\" + \\".\\", + \\"The items must be an array of type \\" + + \\"Object | Link | URL\\" + \\".\\", ); } } - if (\\"memorial\\" in values && values.memorial != null) { - if (typeof values.memorial === \\"boolean\\") { - // @ts-ignore: type is checked above. - this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial = [values.memorial]; - - } else { - throw new TypeError( - \\"The memorial must be of type \\" + - \\"boolean\\" + \\".\\", + return clone; + } + + async #fetchItem( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } ); + return null; } + throw error; } - - if (\\"indexable\\" in values && values.indexable != null) { - if (typeof values.indexable === \\"boolean\\") { - // @ts-ignore: type is checked above. - this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable = [values.indexable]; - - } else { - throw new TypeError( - \\"The indexable must be of type \\" + - \\"boolean\\" + \\".\\", + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#item_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, ); + return null; } - } - - if (\\"successor\\" in values && values.successor != null) { - if (values.successor instanceof Application || values.successor instanceof Group || values.successor instanceof Organization || values.successor instanceof Person || values.successor instanceof Service || values.successor instanceof URL) { - // @ts-ignore: type is checked above. - this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = [values.successor]; - this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.add(0); - } else { - throw new TypeError( - \\"The successor must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } ); + return null; } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); + } + }); + } + + async #item_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - if (\\"alias\\" in values && values.alias != null) { - if (values.alias instanceof Application || values.alias instanceof Group || values.alias instanceof Organization || values.alias instanceof Person || values.alias instanceof Service || values.alias instanceof URL) { - // @ts-ignore: type is checked above. - this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = [values.alias]; - this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.add(0); - } else { - throw new TypeError( - \\"The alias must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); - } + try { + return await Link.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; } - if (\\"aliases\\" in values && values.aliases != null) { + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"https://www.w3.org/ns/activitystreams#Link\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link OrderedCollection.getItems}, + * but returns their \`@id\`s instead of the objects themselves. + */ + override get itemIds(): URL[] { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + return this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.map((v) => + v instanceof URL ? v : v.id! + ).filter(id => id !== null); + } - if (\\"alias\\" in values && - values.alias != null) { - throw new TypeError( - \\"Cannot initialize both alias and \\" + - \\"aliases at the same time.\\", - ); +/** Identifies the items contained in a collection. The items might be ordered + * or unordered. + * + */ + + override async* getItems( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): AsyncIterable { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; + for (let i = 0; i < vs.length; i++) { + let v = vs[i]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { + v = v.id; } - - if (Array.isArray(values.aliases) && - values.aliases.every(v => v instanceof Application || v instanceof Group || v instanceof Organization || v instanceof Person || v instanceof Service || v instanceof URL)) { - // @ts-ignore: type is checked above. - this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = values.aliases; - - for (let i = 0; i < values.aliases.length; i++) { - this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.add(i); - } - - } else { - throw new TypeError( - \\"The aliases must be an array of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); + if (v instanceof URL) { + const fetched = + await this.#fetchItem(v, options); + if (fetched == null) continue; + vs[i] = fetched; + this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.add(i); + this._cachedJsonLd = undefined; + yield fetched; + continue; } - } - if (\\"service\\" in values && values.service != null) { - if (values.service instanceof DidService || values.service instanceof URL) { - // @ts-ignore: type is checked above. - this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = [values.service]; - this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.add(0); - } else { - throw new TypeError( - \\"The service must be of type \\" + - \\"DidService | URL\\" + \\".\\", - ); - } - } + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"orderedItems\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"orderedItems\\"]; + const obj = Array.isArray(prop) ? prop[i] : prop; + if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { - if (\\"services\\" in values && values.services != null) { + v = await this.#item_fromJsonLd(obj, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); - if (\\"service\\" in values && - values.service != null) { - throw new TypeError( - \\"Cannot initialize both service and \\" + - \\"services at the same time.\\", - ); + } } - if (Array.isArray(values.services) && - values.services.every(v => v instanceof DidService || v instanceof URL)) { - // @ts-ignore: type is checked above. - this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = values.services; - - for (let i = 0; i < values.services.length; i++) { - this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.add(i); + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); } - - } else { - throw new TypeError( - \\"The services must be an array of type \\" + - \\"DidService | URL\\" + \\".\\", + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin \\" + + 'option to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, ); + continue; } + yield v; } + } - if (\\"followedMessage\\" in values && values.followedMessage != null) { - if (typeof values.followedMessage === \\"string\\") { - // @ts-ignore: type is checked above. - this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage = [values.followedMessage]; - - } else { - throw new TypeError( - \\"The followedMessage must be of type \\" + - \\"string\\" + \\".\\", - ); - } - } + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + if (options.format == null && this.isCompactable()) { + + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; + delete result[\\"items\\"]; + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + + compactItems = []; + for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { + const item = ( + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { - if (\\"cat\\" in values && values.cat != null) { - if (typeof values.cat === \\"boolean\\") { - // @ts-ignore: type is checked above. - this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat = [values.cat]; + result[\\"orderedItems\\"] = compactItems; + + } - } else { - throw new TypeError( - \\"The cat must be of type \\" + - \\"boolean\\" + \\".\\", - ); + result[\\"type\\"] = \\"OrderedCollection\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; + return result; + } + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + + array = []; + for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + { \\"@list\\": array } + ); + values[\\"https://www.w3.org/ns/activitystreams#items\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; } + } else { + compacted.proof[\\"@context\\"] = docContext; } } + + } + return compacted; + } + + protected override isCompactable(): boolean { + return super.isCompactable(); + } + /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;preferredUsername?: string | LanguageString | null; -preferredUsernames?: ((string | LanguageString))[];publicKey?: CryptographicKey | URL | null; -publicKeys?: (CryptographicKey | URL)[];assertionMethod?: Multikey | URL | null; -assertionMethods?: (Multikey | URL)[];manuallyApprovesFollowers?: boolean | null;inbox?: OrderedCollection | OrderedCollectionPage | URL | null;outbox?: OrderedCollection | OrderedCollectionPage | URL | null;following?: Collection | URL | null;followers?: Collection | URL | null;liked?: Collection | URL | null;featured?: Collection | URL | null;featuredTags?: Collection | URL | null;streams?: (Collection | URL)[];endpoints?: Endpoints | null;discoverable?: boolean | null;suspended?: boolean | null;memorial?: boolean | null;indexable?: boolean | null;successor?: Application | Group | Organization | Person | Service | URL | null;alias?: Application | Group | Organization | Person | Service | URL | null; -aliases?: (Application | Group | Organization | Person | Service | URL)[];service?: DidService | URL | null; -services?: (DidService | URL)[];followedMessage?: string | null;cat?: boolean | null;} - - = {}, + static override async fromJsonLd( + json: unknown, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, - } = {} - ): Application { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Application;clone.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername; - if (\\"preferredUsername\\" in values && values.preferredUsername != null) { - if (typeof values.preferredUsername === \\"string\\" || values.preferredUsername instanceof LanguageString) { - // @ts-ignore: type is checked above. - clone.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = [values.preferredUsername]; - - } else { - throw new TypeError( - \\"The preferredUsername must be of type \\" + - \\"string | LanguageString\\" + \\".\\", - ); + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { + try { + const object = await this.__fromJsonLd__OrderedCollection__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); } + return object; + } catch (error) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(error), + }); + throw error; + } finally { + span.end(); } + }, + ); + } + + protected static async __fromJsonLd__OrderedCollection__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, + }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + } + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeaturedCollection\\")) { + return await FeaturedCollection.fromJsonLd(json, options); + } + + if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof OrderedCollection)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + } + + const _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: (Object | Link | URL)[] = []; + const _trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items: Set = new Set(); + + let _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array = values[\\"https://www.w3.org/ns/activitystreams#items\\"]; + + for ( + const v of _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array == null + ? [] + : _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array.length === 1 && \\"@list\\" in _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array[0] + ? _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array[0][\\"@list\\"] + : _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - if (\\"preferredUsernames\\" in values && values.preferredUsernames != null) { - - if (\\"preferredUsername\\" in values && - values.preferredUsername != null) { - throw new TypeError( - \\"Cannot update both preferredUsername and \\" + - \\"preferredUsernames at the same time.\\", - ); - } - - if (Array.isArray(values.preferredUsernames) && - values.preferredUsernames.every(v => typeof v === \\"string\\" || v instanceof LanguageString)) { - // @ts-ignore: type is checked above. - clone.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = values.preferredUsernames; - - } else { - throw new TypeError( - \\"The preferredUsernames must be an array of type \\" + - \\"string | LanguageString\\" + \\".\\", - ); - } - } - clone.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey;clone.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey = new Set(this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey); - if (\\"publicKey\\" in values && values.publicKey != null) { - if (values.publicKey instanceof CryptographicKey || values.publicKey instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey = [values.publicKey]; - clone.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey = new Set([0]); - } else { - throw new TypeError( - \\"The publicKey must be of type \\" + - \\"CryptographicKey | URL\\" + \\".\\", - ); - } - } - - if (\\"publicKeys\\" in values && values.publicKeys != null) { - - if (\\"publicKey\\" in values && - values.publicKey != null) { - throw new TypeError( - \\"Cannot update both publicKey and \\" + - \\"publicKeys at the same time.\\", - ); - } - - if (Array.isArray(values.publicKeys) && - values.publicKeys.every(v => v instanceof CryptographicKey || v instanceof URL)) { - // @ts-ignore: type is checked above. - clone.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey = values.publicKeys; + const decoded = + typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Object\\",\\"http://joinmastodon.org/ns#Emoji\\",\\"http://litepub.social/ns#ChatMessage\\",\\"https://gotosocial.org/ns#AnnounceAuthorization\\",\\"https://gotosocial.org/ns#LikeApproval\\",\\"https://gotosocial.org/ns#ReplyAuthorization\\",\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\",\\"https://w3id.org/fep/7aa9#FeaturedItem\\",\\"https://w3id.org/valueflows/ont/vf#Agreement\\",\\"https://w3id.org/valueflows/ont/vf#Proposal\\",\\"https://www.w3.org/ns/activitystreams#Activity\\",\\"http://litepub.social/ns#EmojiReact\\",\\"https://gotosocial.org/ns#AnnounceRequest\\",\\"https://gotosocial.org/ns#LikeRequest\\",\\"https://gotosocial.org/ns#ReplyRequest\\",\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"https://w3id.org/fep/7aa9#FeatureRequest\\",\\"https://www.w3.org/ns/activitystreams#Accept\\",\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\",\\"https://www.w3.org/ns/activitystreams#Add\\",\\"https://www.w3.org/ns/activitystreams#Announce\\",\\"https://www.w3.org/ns/activitystreams#Create\\",\\"https://www.w3.org/ns/activitystreams#Delete\\",\\"https://www.w3.org/ns/activitystreams#Dislike\\",\\"https://www.w3.org/ns/activitystreams#Flag\\",\\"https://www.w3.org/ns/activitystreams#Follow\\",\\"https://www.w3.org/ns/activitystreams#Ignore\\",\\"https://www.w3.org/ns/activitystreams#Block\\",\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\",\\"https://www.w3.org/ns/activitystreams#Arrive\\",\\"https://www.w3.org/ns/activitystreams#Question\\",\\"https://www.w3.org/ns/activitystreams#Travel\\",\\"https://www.w3.org/ns/activitystreams#Join\\",\\"https://www.w3.org/ns/activitystreams#Leave\\",\\"https://www.w3.org/ns/activitystreams#Like\\",\\"https://www.w3.org/ns/activitystreams#Listen\\",\\"https://www.w3.org/ns/activitystreams#Move\\",\\"https://www.w3.org/ns/activitystreams#Offer\\",\\"https://www.w3.org/ns/activitystreams#Invite\\",\\"https://www.w3.org/ns/activitystreams#Read\\",\\"https://www.w3.org/ns/activitystreams#Reject\\",\\"https://www.w3.org/ns/activitystreams#TentativeReject\\",\\"https://www.w3.org/ns/activitystreams#Remove\\",\\"https://www.w3.org/ns/activitystreams#Undo\\",\\"https://www.w3.org/ns/activitystreams#Update\\",\\"https://www.w3.org/ns/activitystreams#View\\",\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Article\\",\\"https://www.w3.org/ns/activitystreams#Collection\\",\\"https://www.w3.org/ns/activitystreams#CollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://w3id.org/fep/7aa9#FeaturedCollection\\",\\"https://www.w3.org/ns/activitystreams#Document\\",\\"https://www.w3.org/ns/activitystreams#Audio\\",\\"https://www.w3.org/ns/activitystreams#Image\\",\\"https://www.w3.org/ns/activitystreams#Page\\",\\"https://www.w3.org/ns/activitystreams#Video\\",\\"https://www.w3.org/ns/activitystreams#Event\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Note\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Place\\",\\"https://www.w3.org/ns/activitystreams#Profile\\",\\"https://www.w3.org/ns/activitystreams#Relationship\\",\\"https://www.w3.org/ns/activitystreams#Service\\",\\"https://www.w3.org/ns/activitystreams#Tombstone\\"].some( + t => v[\\"@type\\"].includes(t)) ? await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Link\\",\\"https://www.w3.org/ns/activitystreams#Hashtag\\",\\"https://www.w3.org/ns/activitystreams#Mention\\"].some( + t => v[\\"@type\\"].includes(t)) ? await Link.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : undefined + ; + if (typeof decoded === \\"undefined\\") continue; + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(decoded); - clone.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey = new Set(); - for (let i = 0; i < values.publicKeys.length; i++) { - clone.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.add(i); - } - - } else { - throw new TypeError( - \\"The publicKeys must be an array of type \\" + - \\"CryptographicKey | URL\\" + \\".\\", - ); - } - } - clone.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod;clone.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = new Set(this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod); - if (\\"assertionMethod\\" in values && values.assertionMethod != null) { - if (values.assertionMethod instanceof Multikey || values.assertionMethod instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = [values.assertionMethod]; - clone.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = new Set([0]); - } else { - throw new TypeError( - \\"The assertionMethod must be of type \\" + - \\"Multikey | URL\\" + \\".\\", - ); - } + } + instance.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - - if (\\"assertionMethods\\" in values && values.assertionMethods != null) { - - if (\\"assertionMethod\\" in values && - values.assertionMethod != null) { - throw new TypeError( - \\"Cannot update both assertionMethod and \\" + - \\"assertionMethods at the same time.\\", - ); - } - - if (Array.isArray(values.assertionMethods) && - values.assertionMethods.every(v => v instanceof Multikey || v instanceof URL)) { - // @ts-ignore: type is checked above. - clone.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = values.assertionMethods; - - clone.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = new Set(); - for (let i = 0; i < values.assertionMethods.length; i++) { - clone.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.add(i); + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } + } + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + const _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), } - - } else { - throw new TypeError( - \\"The assertionMethods must be an array of type \\" + - \\"Multikey | URL\\" + \\".\\", - ); - } - } - clone.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers = this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers; - if (\\"manuallyApprovesFollowers\\" in values && values.manuallyApprovesFollowers != null) { - if (typeof values.manuallyApprovesFollowers === \\"boolean\\") { - // @ts-ignore: type is checked above. - clone.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers = [values.manuallyApprovesFollowers]; + : v); + + if (_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.length > 1 + || !(\\"item\\" in proxy) + && _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.length > 0) { + proxy.items = _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; + } - } else { - throw new TypeError( - \\"The manuallyApprovesFollowers must be of type \\" + - \\"boolean\\" + \\".\\", - ); - } - } - clone.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox;clone.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = new Set(this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox); - if (\\"inbox\\" in values && values.inbox != null) { - if (values.inbox instanceof OrderedCollection || values.inbox instanceof OrderedCollectionPage || values.inbox instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = [values.inbox]; - clone.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = new Set([0]); - } else { - throw new TypeError( - \\"The inbox must be of type \\" + - \\"OrderedCollection | OrderedCollectionPage | URL\\" + \\".\\", - ); - } - } - clone.#_41QwhqJouoLg3h8dRPKat21brynC_outbox = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox;clone.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox = new Set(this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox); - if (\\"outbox\\" in values && values.outbox != null) { - if (values.outbox instanceof OrderedCollection || values.outbox instanceof OrderedCollectionPage || values.outbox instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_41QwhqJouoLg3h8dRPKat21brynC_outbox = [values.outbox]; - clone.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox = new Set([0]); - } else { - throw new TypeError( - \\"The outbox must be of type \\" + - \\"OrderedCollection | OrderedCollectionPage | URL\\" + \\".\\", - ); - } - } - clone.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following;clone.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = new Set(this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following); - if (\\"following\\" in values && values.following != null) { - if (values.following instanceof Collection || values.following instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = [values.following]; - clone.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = new Set([0]); - } else { - throw new TypeError( - \\"The following must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } - clone.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers;clone.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers = new Set(this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers); - if (\\"followers\\" in values && values.followers != null) { - if (values.followers instanceof Collection || values.followers instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers = [values.followers]; - clone.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers = new Set([0]); - } else { - throw new TypeError( - \\"The followers must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } - clone.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked;clone.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = new Set(this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked); - if (\\"liked\\" in values && values.liked != null) { - if (values.liked instanceof Collection || values.liked instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = [values.liked]; - clone.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = new Set([0]); - } else { - throw new TypeError( - \\"The liked must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } - clone.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured;clone.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured = new Set(this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured); - if (\\"featured\\" in values && values.featured != null) { - if (values.featured instanceof Collection || values.featured instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured = [values.featured]; - clone.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured = new Set([0]); - } else { - throw new TypeError( - \\"The featured must be of type \\" + - \\"Collection | URL\\" + \\".\\", - ); - } - } - clone.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags;clone.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = new Set(this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags); - if (\\"featuredTags\\" in values && values.featuredTags != null) { - if (values.featuredTags instanceof Collection || values.featuredTags instanceof URL) { + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(OrderedCollection.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: OrderedCollection, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"OrderedCollection \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(OrderedCollection.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: OrderedCollection, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"OrderedCollection \\" + inspect(proxy, options); + }; + /** A curated collection of recommended actors or other objects. + * + * See [FEP-7aa9](https://w3id.org/fep/7aa9) for details. + * + */ +export class FeaturedCollection extends OrderedCollection { + + /** + * The type URI of {@link FeaturedCollection}: \`https://w3id.org/fep/7aa9#FeaturedCollection\`. + */ + static override get typeId(): URL { + return new URL(\\"https://w3id.org/fep/7aa9#FeaturedCollection\\"); + } + #_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic: (Hashtag)[] = []; +#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable: (boolean)[] = []; + + /** + * Constructs a new instance of FeaturedCollection with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;totalItems?: number | null;current?: CollectionPage | URL | null;first?: CollectionPage | URL | null;last?: CollectionPage | URL | null;likesOf?: Object | URL | null;sharesOf?: Object | URL | null;repliesOf?: Object | URL | null;inboxOf?: Object | URL | null;outboxOf?: Object | URL | null;followersOf?: Object | URL | null;followingOf?: Object | URL | null;likedOf?: Object | URL | null;items?: (Object | Link | URL)[];topic?: Hashtag | null;discoverable?: boolean | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + super(values, options); + if (\\"topic\\" in values && values.topic != null) { + if (values.topic instanceof Hashtag) { // @ts-ignore: type is checked above. - clone.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = [values.featuredTags]; - clone.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = new Set([0]); + this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic = [values.topic]; + } else { throw new TypeError( - \\"The featuredTags must be of type \\" + - \\"Collection | URL\\" + \\".\\", + \\"The topic must be of type \\" + + \\"Hashtag\\" + \\".\\", ); } } - clone.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams;clone.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = new Set(this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams); - if (\\"streams\\" in values && values.streams != null) { - if (Array.isArray(values.streams) && - values.streams.every(v => v instanceof Collection || v instanceof URL)) { + if (\\"discoverable\\" in values && values.discoverable != null) { + if (typeof values.discoverable === \\"boolean\\") { // @ts-ignore: type is checked above. - clone.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = values.streams; + this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable = [values.discoverable]; - clone.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = new Set(); - for (let i = 0; i < values.streams.length; i++) { - clone.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.add(i); - } - } else { throw new TypeError( - \\"The streams must be an array of type \\" + - \\"Collection | URL\\" + \\".\\", + \\"The discoverable must be of type \\" + + \\"boolean\\" + \\".\\", ); } } - clone.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints = this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints; - if (\\"endpoints\\" in values && values.endpoints != null) { - if (values.endpoints instanceof Endpoints) { + } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + override clone( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;totalItems?: number | null;current?: CollectionPage | URL | null;first?: CollectionPage | URL | null;last?: CollectionPage | URL | null;likesOf?: Object | URL | null;sharesOf?: Object | URL | null;repliesOf?: Object | URL | null;inboxOf?: Object | URL | null;outboxOf?: Object | URL | null;followersOf?: Object | URL | null;followingOf?: Object | URL | null;likedOf?: Object | URL | null;items?: (Object | Link | URL)[];topic?: Hashtag | null;discoverable?: boolean | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): FeaturedCollection { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + const clone = super.clone(values, options) as unknown as FeaturedCollection;clone.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic = this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic; + if (\\"topic\\" in values && values.topic != null) { + if (values.topic instanceof Hashtag) { // @ts-ignore: type is checked above. - clone.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints = [values.endpoints]; + clone.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic = [values.topic]; } else { throw new TypeError( - \\"The endpoints must be of type \\" + - \\"Endpoints\\" + \\".\\", + \\"The topic must be of type \\" + + \\"Hashtag\\" + \\".\\", ); } } @@ -35552,337 +33921,754 @@ services?: (DidService | URL)[];followedMessage?: string | null;cat?: boolean | ); } } - clone.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended = this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended; - if (\\"suspended\\" in values && values.suspended != null) { - if (typeof values.suspended === \\"boolean\\") { - // @ts-ignore: type is checked above. - clone.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended = [values.suspended]; - } else { - throw new TypeError( - \\"The suspended must be of type \\" + - \\"boolean\\" + \\".\\", - ); - } + return clone; + } + +/** A single {@link Hashtag} object that represents the main topic or category + * of this featured collection. + * + */ + get topic(): (Hashtag | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); } - clone.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial = this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial; - if (\\"memorial\\" in values && values.memorial != null) { - if (typeof values.memorial === \\"boolean\\") { - // @ts-ignore: type is checked above. - clone.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial = [values.memorial]; + if (this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic.length < 1) return null; + return this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic[0]; + } - } else { - throw new TypeError( - \\"The memorial must be of type \\" + - \\"boolean\\" + \\".\\", - ); - } - } - clone.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable = this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable; - if (\\"indexable\\" in values && values.indexable != null) { - if (typeof values.indexable === \\"boolean\\") { - // @ts-ignore: type is checked above. - clone.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable = [values.indexable]; - - } else { - throw new TypeError( - \\"The indexable must be of type \\" + - \\"boolean\\" + \\".\\", - ); - } - } - clone.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo;clone.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = new Set(this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo); - if (\\"successor\\" in values && values.successor != null) { - if (values.successor instanceof Application || values.successor instanceof Group || values.successor instanceof Organization || values.successor instanceof Person || values.successor instanceof Service || values.successor instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = [values.successor]; - clone.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = new Set([0]); - } else { - throw new TypeError( - \\"The successor must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); - } - } - clone.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs;clone.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = new Set(this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs); - if (\\"alias\\" in values && values.alias != null) { - if (values.alias instanceof Application || values.alias instanceof Group || values.alias instanceof Organization || values.alias instanceof Person || values.alias instanceof Service || values.alias instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = [values.alias]; - clone.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = new Set([0]); - } else { - throw new TypeError( - \\"The alias must be of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); - } +/** When present and set to \`false\`, signals that this featured collection is + * not meant to be discovered by search, onboarding, or similar discovery + * features. + * + */ + get discoverable(): (boolean | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); } + if (this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable.length < 1) return null; + return this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable[0]; + } - if (\\"aliases\\" in values && values.aliases != null) { + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + if (options.format == null && this.isCompactable()) { + + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; - if (\\"alias\\" in values && - values.alias != null) { - throw new TypeError( - \\"Cannot update both alias and \\" + - \\"aliases at the same time.\\", - ); - } - - if (Array.isArray(values.aliases) && - values.aliases.every(v => v instanceof Application || v instanceof Group || v instanceof Organization || v instanceof Person || v instanceof Service || v instanceof URL)) { - // @ts-ignore: type is checked above. - clone.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = values.aliases; + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + + compactItems = []; + for (const v of this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { - clone.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = new Set(); - for (let i = 0; i < values.aliases.length; i++) { - clone.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.add(i); - } + result[\\"topic\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; - } else { - throw new TypeError( - \\"The aliases must be an array of type \\" + - \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", - ); - } - } - clone.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service;clone.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = new Set(this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service); - if (\\"service\\" in values && values.service != null) { - if (values.service instanceof DidService || values.service instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = [values.service]; - clone.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = new Set([0]); - } else { - throw new TypeError( - \\"The service must be of type \\" + - \\"DidService | URL\\" + \\".\\", - ); - } - } - - if (\\"services\\" in values && values.services != null) { + } - if (\\"service\\" in values && - values.service != null) { - throw new TypeError( - \\"Cannot update both service and \\" + - \\"services at the same time.\\", - ); - } - - if (Array.isArray(values.services) && - values.services.every(v => v instanceof DidService || v instanceof URL)) { - // @ts-ignore: type is checked above. - clone.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = values.services; + compactItems = []; + for (const v of this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable) { + const item = ( + v + ); + compactItems.push(item); + } + if (compactItems.length > 0) { - clone.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = new Set(); - for (let i = 0; i < values.services.length; i++) { - clone.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.add(i); - } + result[\\"discoverable\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; - } else { - throw new TypeError( - \\"The services must be an array of type \\" + - \\"DidService | URL\\" + \\".\\", - ); - } - } - clone.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage = this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage; - if (\\"followedMessage\\" in values && values.followedMessage != null) { - if (typeof values.followedMessage === \\"string\\") { - // @ts-ignore: type is checked above. - clone.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage = [values.followedMessage]; - - } else { - throw new TypeError( - \\"The followedMessage must be of type \\" + - \\"string\\" + \\".\\", - ); - } - } - clone.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat = this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat; - if (\\"cat\\" in values && values.cat != null) { - if (typeof values.cat === \\"boolean\\") { - // @ts-ignore: type is checked above. - clone.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat = [values.cat]; + } - } else { - throw new TypeError( - \\"The cat must be of type \\" + - \\"boolean\\" + \\".\\", - ); + result[\\"type\\"] = \\"FeaturedCollection\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"discoverable\\":\\"toot:discoverable\\",\\"Hashtag\\":\\"as:Hashtag\\"}]; + return result; + } + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + + array = []; + for (const v of this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/7aa9#topic\\"] = propValue; + + } + + array = []; + for (const v of this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable) { + const element = ( + { \\"@value\\": v } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"http://joinmastodon.org/ns#discoverable\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/fep/7aa9#FeaturedCollection\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"discoverable\\":\\"toot:discoverable\\",\\"Hashtag\\":\\"as:Hashtag\\"}]; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; } + } else { + compacted.proof[\\"@context\\"] = docContext; } + } - return clone; + } + return compacted; + } + + protected override isCompactable(): boolean { + + return super.isCompactable(); } -/** A short username which may be used to refer to the actor, - * with no uniqueness guarantees. - * - */ - get preferredUsername(): (string | LanguageString | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername.length < 1) return null; - return this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername[0]; - } - -/** A short username which may be used to refer to the actor, - * with no uniqueness guarantees. - * - */ -get preferredUsernames(): ((string | LanguageString))[] { - return this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername; - } - - async #fetchPublicKey( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static override async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__FeaturedCollection__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#publicKey_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } + }, + ); + } + + protected static async __fromJsonLd__FeaturedCollection__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - - async #publicKey_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await CryptographicKey.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://w3id.org/security#Key\\"].join(\\", \\")); + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeaturedCollection\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof FeaturedCollection)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } + const _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic: (Hashtag)[] = []; + let _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic__array = values[\\"https://w3id.org/fep/7aa9#topic\\"]; - /** - * Similar to - * {@link Application.getPublicKey}, - * but returns its \`@id\` URL instead of the object itself. + for ( + const v of _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic__array == null + ? [] + : _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic__array.length === 1 && \\"@list\\" in _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic__array[0] + ? _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic__array[0][\\"@list\\"] + : _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic__array + ) { + if (v == null) continue; + + const decoded = await Hashtag.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic.push(decoded); + } + instance.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic = _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic; + const _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable: (boolean)[] = []; + + let _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array = values[\\"http://joinmastodon.org/ns#discoverable\\"]; + + for ( + const v of _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array == null + ? [] + : _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array.length === 1 && \\"@list\\" in _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array[0] + ? _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array[0][\\"@list\\"] + : _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array + ) { + if (v == null) continue; + + const decoded = v[\\"@value\\"]; + if (typeof decoded === \\"undefined\\") continue; + _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable.push(decoded); + } + instance.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable = _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } + } + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + const _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic = this.#_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic.length == 1) { + proxy.topic = _pc4UXYHNrYa2zyQ8Bh7zvdZRKnZ_topic[0]; + } + + const _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable = this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable.length == 1) { + proxy.discoverable = _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable[0]; + } + + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(FeaturedCollection.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: FeaturedCollection, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"FeaturedCollection \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(FeaturedCollection.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: FeaturedCollection, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"FeaturedCollection \\" + inspect(proxy, options); + }; + /** A single entry in a {@link FeaturedCollection}. + * + * See [FEP-7aa9](https://w3id.org/fep/7aa9) for details. + * + */ +export class FeaturedItem extends Object { + + /** + * The type URI of {@link FeaturedItem}: \`https://w3id.org/fep/7aa9#FeaturedItem\`. + */ + static override get typeId(): URL { + return new URL(\\"https://w3id.org/fep/7aa9#FeaturedItem\\"); + } + + #_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject: (Object | URL)[] = []; + #_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject: Set = new Set(); + + #_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization: (FeatureAuthorization | URL)[] = []; + #_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization: Set = new Set(); + + /** + * Constructs a new instance of FeaturedItem with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;featuredObject?: Object | URL | null;featureAuthorization?: FeatureAuthorization | URL | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + super(values, options); + if (\\"featuredObject\\" in values && values.featuredObject != null) { + if (values.featuredObject instanceof Object || values.featuredObject instanceof URL) { + // @ts-ignore: type is checked above. + this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = [values.featuredObject]; + this.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.add(0); + } else { + throw new TypeError( + \\"The featuredObject must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + + if (\\"featureAuthorization\\" in values && values.featureAuthorization != null) { + if (values.featureAuthorization instanceof FeatureAuthorization || values.featureAuthorization instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = [values.featureAuthorization]; + this.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.add(0); + } else { + throw new TypeError( + \\"The featureAuthorization must be of type \\" + + \\"FeatureAuthorization | URL\\" + \\".\\", + ); + } + } + } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + override clone( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;featuredObject?: Object | URL | null;featureAuthorization?: FeatureAuthorization | URL | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): FeaturedItem { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + const clone = super.clone(values, options) as unknown as FeaturedItem;clone.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject;clone.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = new Set(this.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject); + if (\\"featuredObject\\" in values && values.featuredObject != null) { + if (values.featuredObject instanceof Object || values.featuredObject instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = [values.featuredObject]; + clone.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = new Set([0]); + } else { + throw new TypeError( + \\"The featuredObject must be of type \\" + + \\"Object | URL\\" + \\".\\", + ); + } + } + clone.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization;clone.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = new Set(this.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization); + if (\\"featureAuthorization\\" in values && values.featureAuthorization != null) { + if (values.featureAuthorization instanceof FeatureAuthorization || values.featureAuthorization instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = [values.featureAuthorization]; + clone.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = new Set([0]); + } else { + throw new TypeError( + \\"The featureAuthorization must be of type \\" + + \\"FeatureAuthorization | URL\\" + \\".\\", + ); + } + } + + return clone; + } + + async #fetchFeaturedObject( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } + ); + return null; + } + throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#featuredObject_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); + } + }); + } + + async #featuredObject_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL + } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Object.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } 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\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link FeaturedItem.getFeaturedObject}, + * but returns its \`@id\` URL instead of the object itself. */ - get publicKeyId(): URL | null { + get featuredObjectId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; - const v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; + if (this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.length < 1) return null; + const v = this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject[0]; if (v instanceof URL) return v; return v.id; } -/** A public part of the key pair owned by this actor. +/** The object being featured. */ - async getPublicKey( + async getFeaturedObject( options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, @@ -35890,27 +34676,27 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {} - ): Promise { + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; - let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; + if (this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.length < 1) return null; + let v = this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject[0]; if (!(v instanceof URL) && v.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + !this.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.has(0)) { v = v.id; } if (v instanceof URL) { const fetched = - await this.#fetchPublicKey(v, options); + await this.#fetchFeaturedObject(v, options); if (fetched == null) return null; - this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0] = fetched; - this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.add(0); + this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject[0] = fetched; + this.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.add(0); this._cachedJsonLd = undefined; return fetched; } @@ -35919,14 +34705,14 @@ get preferredUsernames(): ((string | LanguageString))[] { this._cachedJsonLd != null && typeof this._cachedJsonLd === \\"object\\" && \\"@context\\" in this._cachedJsonLd && - \\"publicKey\\" in this._cachedJsonLd + \\"featuredObject\\" in this._cachedJsonLd ) { const prop = this._cachedJsonLd[ - \\"publicKey\\"]; + \\"featuredObject\\"]; const doc = Array.isArray(prop) ? prop[0] : prop; if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - v = await this.#publicKey_fromJsonLd(doc, { + v = await this.#featuredObject_fromJsonLd(doc, { ...options, baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this._baseUrl ?? @@ -35942,7 +34728,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (v?.id != null && this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + !this.#_trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -35965,113 +34751,7 @@ get preferredUsernames(): ((string | LanguageString))[] { return v; } - /** - * Similar to - * {@link Application.getPublicKeys}, - * but returns their \`@id\`s instead of the objects themselves. - */ - get publicKeyIds(): URL[] { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - return this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.map((v) => - v instanceof URL ? v : v.id! - ).filter(id => id !== null); - } - -/** A public part of the key pair owned by this actor. - */ - - async* getPublicKeys( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): AsyncIterable { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; - for (let i = 0; i < vs.length; i++) { - let v = vs[i]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchPublicKey(v, options); - if (fetched == null) continue; - vs[i] = fetched; - this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.add(i); - this._cachedJsonLd = undefined; - yield fetched; - continue; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"publicKey\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"publicKey\\"]; - const obj = Array.isArray(prop) ? prop[i] : prop; - if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { - - v = await this.#publicKey_fromJsonLd(obj, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin \\" + - 'option to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - continue; - } - yield v; - } - } - - async #fetchAssertionMethod( + async #fetchFeatureAuthorization( url: URL, options: { documentLoader?: DocumentLoader, @@ -36080,7 +34760,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {}, - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -36114,7 +34794,7 @@ get preferredUsernames(): ((string | LanguageString))[] { const { document, documentUrl } = fetchResult; const baseUrl = parseIri(documentUrl); try { - const obj = await this.#assertionMethod_fromJsonLd( + const obj = await this.#featureAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); @@ -36162,7 +34842,7 @@ get preferredUsernames(): ((string | LanguageString))[] { }); } - async #assertionMethod_fromJsonLd( + async #featureAuthorization_fromJsonLd( jsonLd: unknown, options: { documentLoader?: DocumentLoader, @@ -36170,7 +34850,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, baseUrl?: URL } - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -36180,7 +34860,7 @@ get preferredUsernames(): ((string | LanguageString))[] { const baseUrl = options.baseUrl; try { - return await Multikey.fromJsonLd( + return await FeatureAuthorization.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); @@ -36189,36 +34869,34 @@ get preferredUsernames(): ((string | LanguageString))[] { } throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://w3id.org/security#Multikey\\"].join(\\", \\")); + [\\"https://w3id.org/fep/7aa9#FeatureAuthorization\\"].join(\\", \\")); } /** * Similar to - * {@link Application.getAssertionMethod}, + * {@link FeaturedItem.getFeatureAuthorization}, * but returns its \`@id\` URL instead of the object itself. */ - get assertionMethodId(): URL | null { + get featureAuthorizationId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; - const v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; + if (this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.length < 1) return null; + const v = this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization[0]; if (v instanceof URL) return v; return v.id; } -/** Represents this actor's public keys. It serves as equivalent to - * the \`publicKeys\` property, but is used for [FEP-521a] compliance. - * - * [FEP-521a]: https://w3id.org/fep/521a +/** The {@link FeatureAuthorization} proving that the featured actor consented + * to inclusion in the featured collection. * */ - async getAssertionMethod( + async getFeatureAuthorization( options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, @@ -36226,27 +34904,27 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {} - ): Promise { + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; - let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; + if (this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.length < 1) return null; + let v = this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization[0]; if (!(v instanceof URL) && v.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + !this.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.has(0)) { v = v.id; } if (v instanceof URL) { const fetched = - await this.#fetchAssertionMethod(v, options); + await this.#fetchFeatureAuthorization(v, options); if (fetched == null) return null; - this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0] = fetched; - this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.add(0); + this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization[0] = fetched; + this.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.add(0); this._cachedJsonLd = undefined; return fetched; } @@ -36255,14 +34933,14 @@ get preferredUsernames(): ((string | LanguageString))[] { this._cachedJsonLd != null && typeof this._cachedJsonLd === \\"object\\" && \\"@context\\" in this._cachedJsonLd && - \\"assertionMethod\\" in this._cachedJsonLd + \\"featureAuthorization\\" in this._cachedJsonLd ) { const prop = this._cachedJsonLd[ - \\"assertionMethod\\"]; + \\"featureAuthorization\\"]; const doc = Array.isArray(prop) ? prop[0] : prop; if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - v = await this.#assertionMethod_fromJsonLd(doc, { + v = await this.#featureAuthorization_fromJsonLd(doc, { ...options, baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this._baseUrl ?? @@ -36278,7 +34956,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (v?.id != null && this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + !this.#_trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -36301,1094 +34979,1577 @@ get preferredUsernames(): ((string | LanguageString))[] { return v; } - /** - * Similar to - * {@link Application.getAssertionMethods}, - * but returns their \`@id\`s instead of the objects themselves. - */ - get assertionMethodIds(): URL[] { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - return this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.map((v) => - v instanceof URL ? v : v.id! - ).filter(id => id !== null); - } + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + if (options.format == null && this.isCompactable()) { + + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; -/** Represents this actor's public keys. It serves as equivalent to - * the \`publicKeys\` property, but is used for [FEP-521a] compliance. - * - * [FEP-521a]: https://w3id.org/fep/521a - * - */ - - async* getAssertionMethods( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): AsyncIterable { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; - for (let i = 0; i < vs.length; i++) { - let v = vs[i]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchAssertionMethod(v, options); - if (fetched == null) continue; - vs[i] = fetched; - this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.add(i); - this._cachedJsonLd = undefined; - yield fetched; - continue; - } + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + + compactItems = []; + for (const v of this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"assertionMethod\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"assertionMethod\\"]; - const obj = Array.isArray(prop) ? prop[i] : prop; - if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { + result[\\"featuredObject\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } - v = await this.#assertionMethod_fromJsonLd(obj, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + compactItems = []; + for (const v of this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization) { + const item = ( + v instanceof URL ? formatIri(v) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { - } - } + result[\\"featureAuthorization\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin \\" + - 'option to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - continue; - } - yield v; - } } -/** When \`true\`, conveys that for this actor, follow requests are not usually - * automatically approved, but instead are examined by a person who may accept - * or reject the request, at some time in the future. Setting of \`false\` - * conveys no information and may be ignored. This information is typically - * used to affect display of accounts, such as showing an account as private or - * locked. - * - */ - get manuallyApprovesFollowers(): (boolean | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); + result[\\"type\\"] = \\"FeaturedItem\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\"]; + return result; + } + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + + array = []; + for (const v of this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/7aa9#featuredObject\\"] = propValue; + + } + + array = []; + for (const v of this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/fep/7aa9#featureAuthorization\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/fep/7aa9#FeaturedItem\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",\\"https://w3id.org/fep/7aa9\\"]; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; + } + } else { + compacted.proof[\\"@context\\"] = docContext; } - if (this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers.length < 1) return null; - return this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers[0]; } - async #fetchInbox( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + } + return compacted; + } + + protected override isCompactable(): boolean { + + return super.isCompactable(); + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static override async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__FeaturedItem__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#inbox_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } + }, + ); + } + + protected static async __fromJsonLd__FeaturedItem__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - - async #inbox_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/fep/7aa9#FeaturedItem\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof FeaturedItem)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + } + + const _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject: (Object | URL)[] = []; + const _trust_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject: Set = new Set(); + + let _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject__array = values[\\"https://w3id.org/fep/7aa9#featuredObject\\"]; + + for ( + const v of _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject__array == null + ? [] + : _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject__array.length === 1 && \\"@list\\" in _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject__array[0] + ? _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject__array[0][\\"@list\\"] + : _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; + + const decoded = await Object.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.push(decoded); + } + instance.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject; - try { - return await OrderedCollection.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } + const _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization: (FeatureAuthorization | URL)[] = []; + const _trust_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization: Set = new Set(); + + let _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization__array = values[\\"https://w3id.org/fep/7aa9#featureAuthorization\\"]; + + for ( + const v of _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization__array == null + ? [] + : _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization__array.length === 1 && \\"@list\\" in _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization__array[0] + ? _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization__array[0][\\"@list\\"] + : _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } - try { - return await OrderedCollectionPage.fromJsonLd( + const decoded = await FeatureAuthorization.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.push(decoded); + } + instance.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, + options.contextLoader, ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\"].join(\\", \\")); + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } } - + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + const _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject = this.#_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); - /** - * Similar to - * {@link Application.getInbox}, - * but returns its \`@id\` URL instead of the object itself. - */ - get inboxId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; - const v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (v instanceof URL) return v; - return v.id; + if (_Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject.length == 1) { + proxy.featuredObject = _Ht5F1pFtcuyJkybWck37rPhwyQv_featuredObject[0]; } -/** The inbox stream contains all activities received by the actor. The server - * SHOULD filter content according to the requester's permission. In general, - * the owner of an inbox is likely to be able to access all of their inbox - * contents. Depending on access control, some other content may be public, - * whereas other content may require authentication for non-owner users, - * if they can access the inbox at all. - * - * The server MUST perform de-duplication of activities returned by the inbox. - * Duplication can occur if an activity is addressed both to an actor's - * followers, and a specific actor who also follows the recipient actor, - * and the server has failed to de-duplicate the recipients list. - * Such deduplication MUST be performed by comparing the \`id\` of the activities - * and dropping any activities already seen. + const _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization = this.#_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization.length == 1) { + proxy.featureAuthorization = _2gG5sxnwav2sb69C22RbERtJ8rba_featureAuthorization[0]; + } + + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(FeaturedItem.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: FeaturedItem, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"FeaturedItem \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(FeaturedItem.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: FeaturedItem, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"FeaturedItem \\" + inspect(proxy, options); + }; + /** Means of communicating or interacting with the DID subject or associated + * entities via one or more service endpoints. Examples include discovery + * services, agent services, social networking services, file storage services, + * and verifiable credential repository services. * */ +export class DidService { - async getInbox( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; - let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchInbox(v, options); - if (fetched == null) return null; - this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0] = fetched; - this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.add(0); - this._cachedJsonLd = undefined; - return fetched; - } + readonly #documentLoader?: DocumentLoader; + readonly #contextLoader?: DocumentLoader; + readonly #tracerProvider?: TracerProvider; + readonly #warning?: { + category: string[]; + message: string; + values?: Record; + }; + #cachedJsonLd?: unknown; + readonly #_baseUrl?: URL; + readonly id: URL | null; + + protected get _documentLoader(): DocumentLoader | undefined { + return this.#documentLoader; + } + + protected get _contextLoader(): DocumentLoader | undefined { + return this.#contextLoader; + } + + protected get _tracerProvider(): TracerProvider | undefined { + return this.#tracerProvider; + } + + protected get _warning(): { + category: string[]; + message: string; + values?: Record; + } | undefined { + return this.#warning; + } + + protected get _cachedJsonLd(): unknown | undefined { + return this.#cachedJsonLd; + } + + protected set _cachedJsonLd(value: unknown | undefined) { + this.#cachedJsonLd = value; + } + + protected get _baseUrl(): URL | undefined { + return this.#_baseUrl; + } + + /** + * The type URI of {@link DidService}: \`https://www.w3.org/ns/did#Service\`. + */ + static get typeId(): URL { + return new URL(\\"https://www.w3.org/ns/did#Service\\"); + } + #_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; + + /** + * Constructs a new instance of DidService with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +endpoint?: URL | null; +endpoints?: (URL)[];} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + + this.#documentLoader = options.documentLoader; + this.#contextLoader = options.contextLoader; + this.#tracerProvider = options.tracerProvider; + const baseUrl = (options as { baseUrl?: URL }).baseUrl; + this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); + if (\\"\$warning\\" in options) { + this.#warning = options.\$warning as unknown as { + category: string[]; + message: string; + values?: Record; + }; + } + if (values.id == null || values.id instanceof URL) { + this.id = values.id ?? null; + } else { + throw new TypeError(\\"The id must be a URL.\\"); + } + + if (\\"endpoint\\" in values && values.endpoint != null) { + if (values.endpoint instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = [values.endpoint]; - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"inbox\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"inbox\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + } else { + throw new TypeError( + \\"The endpoint must be of type \\" + + \\"URL\\" + \\".\\", + ); + } + } - v = await this.#inbox_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + if (\\"endpoints\\" in values && values.endpoints != null) { + if (\\"endpoint\\" in values && + values.endpoint != null) { + throw new TypeError( + \\"Cannot initialize both endpoint and \\" + + \\"endpoints at the same time.\\", + ); } - } - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' + if (Array.isArray(values.endpoints) && + values.endpoints.every(v => v instanceof URL)) { + // @ts-ignore: type is checked above. + this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = values.endpoints; + + } else { + throw new TypeError( + \\"The endpoints must be an array of type \\" + + \\"URL\\" + \\".\\", ); } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; } - return v; } - - async #fetchOutbox( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + clone( + values: + { +id?: URL | null; +endpoint?: URL | null; +endpoints?: (URL)[];} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): DidService { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; - try { - fetchResult = await documentLoader(lookupUrl); - } 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: lookupUrl } + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + + // @ts-ignore: this.constructor is not recognized as a constructor, but it is. + const clone: DidService = new this.constructor( + { id: values.id ?? this.id }, + options + ); + clone.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; + if (\\"endpoint\\" in values && values.endpoint != null) { + if (values.endpoint instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = [values.endpoint]; + + } else { + throw new TypeError( + \\"The endpoint must be of type \\" + + \\"URL\\" + \\".\\", ); - return null; } - throw error; } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#outbox_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, + + if (\\"endpoints\\" in values && values.endpoints != null) { + + if (\\"endpoint\\" in values && + values.endpoint != null) { + throw new TypeError( + \\"Cannot update both endpoint and \\" + + \\"endpoints at the same time.\\", ); - return null; } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } + + if (Array.isArray(values.endpoints) && + values.endpoints.every(v => v instanceof URL)) { + // @ts-ignore: type is checked above. + clone.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = values.endpoints; + + } else { + throw new TypeError( + \\"The endpoints must be an array of type \\" + + \\"URL\\" + \\".\\", ); - return null; } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; - } finally { - span.end(); - } - }); - } - - async #outbox_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await OrderedCollection.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await OrderedCollectionPage.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; } - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\",\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\"].join(\\", \\")); - } - - - /** - * Similar to - * {@link Application.getOutbox}, - * but returns its \`@id\` URL instead of the object itself. - */ - get outboxId(): URL | null { + return clone; + } + +/** A network address, such as an HTTP URL, at which services operate on behalf + * of a DID subject. + * + */ + get endpoint(): (URL | null) { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; - const v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (v instanceof URL) return v; - return v.id; + if (this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length < 1) return null; + return this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint[0]; } -/** The outbox stream contains activities the user has published, - * subject to the ability of the requestor to retrieve the activity - * (that is, the contents of the outbox are filtered by the permissions of - * the person reading it). If a user submits a request without - * [Authorization](https://www.w3.org/TR/activitypub/#authorization) - * the server should respond with all of the - * [Public](https://www.w3.org/TR/activitypub/#public-addressing) posts. - * This could potentially be all relevant objects published by the user, - * though the number of available items is left to the discretion of those - * implementing and deploying the server. +/** A network address, such as an HTTP URL, at which services operate on behalf + * of a DID subject. * */ - - async getOutbox( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; - let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchOutbox(v, options); - if (fetched == null) return null; - this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0] = fetched; - this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"outbox\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"outbox\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#outbox_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; +get endpoints(): (URL)[] { + return this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; } - async #fetchFollowing( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + const values: Record = {}; + array = []; + for (const v of this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint) { + const element = ( + { \\"@id\\": formatIri(v) } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://www.w3.org/ns/did#serviceEndpoint\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://www.w3.org/ns/did#Service\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + \\"https://www.w3.org/ns/did/v1\\"; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + } + return compacted; + } + + protected isCompactable(): boolean { + + return true; + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__DidService__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#following_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } + }, + ); + } + + protected static async __fromJsonLd__DidService__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + } + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (values[\\"@type\\"].includes(\\"https://w3id.org/fep/9091#Export\\")) { + return await Export.fromJsonLd(json, options); + } + + if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/did#Service\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); } + + const instance = new this( + { + id + }, + options, + ); + const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; - async #following_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; + let _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array = values[\\"https://www.w3.org/ns/did#serviceEndpoint\\"]; - try { - return await Collection.fromJsonLd( + for ( + const v of _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array == null + ? [] + : _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array.length === 1 && \\"@list\\" in _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array[0] + ? _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array[0][\\"@list\\"] + : _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint__array + ) { + if (v == null) continue; + + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); + if (typeof decoded === \\"undefined\\") continue; + _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.push(decoded); + } + instance.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, + options.contextLoader, ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Collection\\"].join(\\", \\")); + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } + } + return instance; + } + + protected _getCustomInspectProxy(): Record { + + const proxy: Record = {}; + if (this.id != null) { + proxy.id = { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(this.id!.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(this.id!.href, options), + }; } - - /** - * Similar to - * {@link Application.getFollowing}, - * but returns its \`@id\` URL instead of the object itself. - */ - get followingId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; - const v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (v instanceof URL) return v; - return v.id; + const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint = this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length == 1) { + proxy.endpoint = _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint[0]; } -/** This is a list of everybody that the actor has followed, added as a - * [side effect](https://www.w3.org/TR/activitypub/#follow-activity-outbox). - * The \`following\` collection MUST be either an {@link OrderedCollection} - * or a {@link Collection} and MAY be filtered on privileges of - * an authenticated user or as appropriate when no authentication is given. + if (_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length > 1 + || !(\\"endpoint\\" in proxy) + && _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.length > 0) { + proxy.endpoints = _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint; + } + + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(DidService.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: DidService, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"DidService \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(DidService.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: DidService, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"DidService \\" + inspect(proxy, options); + }; + /** \\"Export Actor\\" service. * */ +export class Export extends DidService { - async getFollowing( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; - let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchFollowing(v, options); - if (fetched == null) return null; - this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0] = fetched; - this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"following\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"following\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#following_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; - } - - async #fetchFollowers( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", + /** + * The type URI of {@link Export}: \`https://w3id.org/fep/9091#Export\`. + */ + static override get typeId(): URL { + return new URL(\\"https://w3id.org/fep/9091#Export\\"); + } + + /** + * Constructs a new instance of Export with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +endpoint?: URL | null; +endpoints?: (URL)[];} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + super(values, options);} + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + override clone( + values: + { +id?: URL | null; +endpoint?: URL | null; +endpoints?: (URL)[];} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): Export { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + const clone = super.clone(values, options) as unknown as Export; + return clone; + } + + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + + values[\\"@type\\"] = [\\"https://w3id.org/fep/9091#Export\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + \\"https://www.w3.org/ns/did/v1\\"; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + } + return compacted; + } + + protected override isCompactable(): boolean { + + return super.isCompactable(); + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static override async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__Export__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#followers_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } + }, + ); + } + + protected static async __fromJsonLd__Export__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + } + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/fep/9091#Export\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof Export)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } - - async #followers_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - try { - return await Collection.fromJsonLd( + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, + options.contextLoader, ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Collection\\"].join(\\", \\")); + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } } + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + return proxy; + } + } - - /** - * Similar to - * {@link Application.getFollowers}, - * but returns its \`@id\` URL instead of the object itself. - */ - get followersId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; - const v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (v instanceof URL) return v; - return v.id; - } - -/** This is a list of everyone who has sent a {@link Follow} activity - * for the actor, added as a - * [side effect](https://www.w3.org/TR/activitypub/#follow-activity-outbox). - * This is where one would find a list of all the actors that are following - * the actor. The \`followers\` collection MUST be either - * an {@link OrderedCollection} or a {@link Collection} and MAY be filtered on - * privileges of an authenticated user or as appropriate when no authentication - * is given. + +// deno-lint-ignore no-explicit-any +(Export.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Export, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Export \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Export.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Export, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Export \\" + inspect(proxy, options); + }; + /** A proof that can be added to any activity or object, allowing recipients to + * verify the identity of the actor and the integrity of the data. * */ +export class DataIntegrityProof { - async getFollowers( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; - let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchFollowers(v, options); - if (fetched == null) return null; - this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0] = fetched; - this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"followers\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"followers\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + readonly #documentLoader?: DocumentLoader; + readonly #contextLoader?: DocumentLoader; + readonly #tracerProvider?: TracerProvider; + readonly #warning?: { + category: string[]; + message: string; + values?: Record; + }; + #cachedJsonLd?: unknown; + readonly #_baseUrl?: URL; + readonly id: URL | null; + + protected get _documentLoader(): DocumentLoader | undefined { + return this.#documentLoader; + } + + protected get _contextLoader(): DocumentLoader | undefined { + return this.#contextLoader; + } + + protected get _tracerProvider(): TracerProvider | undefined { + return this.#tracerProvider; + } + + protected get _warning(): { + category: string[]; + message: string; + values?: Record; + } | undefined { + return this.#warning; + } + + protected get _cachedJsonLd(): unknown | undefined { + return this.#cachedJsonLd; + } + + protected set _cachedJsonLd(value: unknown | undefined) { + this.#cachedJsonLd = value; + } + + protected get _baseUrl(): URL | undefined { + return this.#_baseUrl; + } + + /** + * The type URI of {@link DataIntegrityProof}: \`https://w3id.org/security#DataIntegrityProof\`. + */ + static get typeId(): URL { + return new URL(\\"https://w3id.org/security#DataIntegrityProof\\"); + } + #_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: (\\"eddsa-jcs-2022\\")[] = []; + + #_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: (Multikey | URL)[] = []; + #_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: Set = new Set(); + #_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose: (\\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\")[] = []; +#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue: (Uint8Array)[] = []; +#_3qzP3ukEZoUziK5FEiA1RhU4aqac: (Temporal.Instant)[] = []; + + /** + * Constructs a new instance of DataIntegrityProof with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | null;proofPurpose?: \\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\" | null;proofValue?: Uint8Array | null;created?: Temporal.Instant | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + + this.#documentLoader = options.documentLoader; + this.#contextLoader = options.contextLoader; + this.#tracerProvider = options.tracerProvider; + const baseUrl = (options as { baseUrl?: URL }).baseUrl; + this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); + if (\\"\$warning\\" in options) { + this.#warning = options.\$warning as unknown as { + category: string[]; + message: string; + values?: Record; + }; + } + if (values.id == null || values.id instanceof URL) { + this.id = values.id ?? null; + } else { + throw new TypeError(\\"The id must be a URL.\\"); + } + + if (\\"cryptosuite\\" in values && values.cryptosuite != null) { + if (values.cryptosuite == \\"eddsa-jcs-2022\\") { + // @ts-ignore: type is checked above. + this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = [values.cryptosuite]; - v = await this.#followers_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + } else { + throw new TypeError( + \\"The cryptosuite must be of type \\" + + \\"\\\\\\"eddsa-jcs-2022\\\\\\"\\" + \\".\\", + ); + } + } + + if (\\"verificationMethod\\" in values && values.verificationMethod != null) { + if (values.verificationMethod instanceof Multikey || values.verificationMethod instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = [values.verificationMethod]; + this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.add(0); + } else { + throw new TypeError( + \\"The verificationMethod must be of type \\" + + \\"Multikey | URL\\" + \\".\\", + ); + } + } + + if (\\"proofPurpose\\" in values && values.proofPurpose != null) { + if (values.proofPurpose === \\"assertionMethod\\" || values.proofPurpose === \\"authentication\\" || + values.proofPurpose === \\"capabilityInvocation\\" || values.proofPurpose === \\"capabilityDelegation\\" || + values.proofPurpose === \\"keyAgreement\\") { + // @ts-ignore: type is checked above. + this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = [values.proofPurpose]; + } else { + throw new TypeError( + \\"The proofPurpose must be of type \\" + + \\"\\\\\\"assertionMethod\\\\\\" | \\\\\\"authentication\\\\\\" | \\\\\\"capabilityInvocation\\\\\\" | \\\\\\"capabilityDelegation\\\\\\" | \\\\\\"keyAgreement\\\\\\"\\" + \\".\\", + ); } } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' + + if (\\"proofValue\\" in values && values.proofValue != null) { + if (values.proofValue instanceof Uint8Array) { + // @ts-ignore: type is checked above. + this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = [values.proofValue]; + + } else { + throw new TypeError( + \\"The proofValue must be of type \\" + + \\"Uint8Array\\" + \\".\\", ); } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, + } + + if (\\"created\\" in values && values.created != null) { + if (isTemporalInstant(values.created)) { + // @ts-ignore: type is checked above. + this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = [values.created]; + + } else { + throw new TypeError( + \\"The created must be of type \\" + + \\"Temporal.Instant\\" + \\".\\", + ); + } + } + } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + clone( + values: + { +id?: URL | null; +cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | null;proofPurpose?: \\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\" | null;proofValue?: Uint8Array | null;created?: Temporal.Instant | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): DataIntegrityProof { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + + // @ts-ignore: this.constructor is not recognized as a constructor, but it is. + const clone: DataIntegrityProof = new this.constructor( + { id: values.id ?? this.id }, + options + ); + clone.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite; + if (\\"cryptosuite\\" in values && values.cryptosuite != null) { + if (values.cryptosuite == \\"eddsa-jcs-2022\\") { + // @ts-ignore: type is checked above. + clone.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = [values.cryptosuite]; + + } else { + throw new TypeError( + \\"The cryptosuite must be of type \\" + + \\"\\\\\\"eddsa-jcs-2022\\\\\\"\\" + \\".\\", + ); + } + } + clone.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod;clone.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = new Set(this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod); + if (\\"verificationMethod\\" in values && values.verificationMethod != null) { + if (values.verificationMethod instanceof Multikey || values.verificationMethod instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = [values.verificationMethod]; + clone.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = new Set([0]); + } else { + throw new TypeError( + \\"The verificationMethod must be of type \\" + + \\"Multikey | URL\\" + \\".\\", + ); + } + } + clone.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose; + if (\\"proofPurpose\\" in values && values.proofPurpose != null) { + if (values.proofPurpose === \\"assertionMethod\\" || values.proofPurpose === \\"authentication\\" || + values.proofPurpose === \\"capabilityInvocation\\" || values.proofPurpose === \\"capabilityDelegation\\" || + values.proofPurpose === \\"keyAgreement\\") { + // @ts-ignore: type is checked above. + clone.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = [values.proofPurpose]; + + } else { + throw new TypeError( + \\"The proofPurpose must be of type \\" + + \\"\\\\\\"assertionMethod\\\\\\" | \\\\\\"authentication\\\\\\" | \\\\\\"capabilityInvocation\\\\\\" | \\\\\\"capabilityDelegation\\\\\\" | \\\\\\"keyAgreement\\\\\\"\\" + \\".\\", + ); + } + } + clone.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue; + if (\\"proofValue\\" in values && values.proofValue != null) { + if (values.proofValue instanceof Uint8Array) { + // @ts-ignore: type is checked above. + clone.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = [values.proofValue]; + + } else { + throw new TypeError( + \\"The proofValue must be of type \\" + + \\"Uint8Array\\" + \\".\\", + ); + } + } + clone.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac; + if (\\"created\\" in values && values.created != null) { + if (isTemporalInstant(values.created)) { + // @ts-ignore: type is checked above. + clone.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = [values.created]; + + } else { + throw new TypeError( + \\"The created must be of type \\" + + \\"Temporal.Instant\\" + \\".\\", + ); + } + } + + return clone; + } + +/** The cryptographic suite used to create the proof. + * + */ + get cryptosuite(): (\\"eddsa-jcs-2022\\" | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - return null; } - return v; + if (this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite.length < 1) return null; + return this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite[0]; } - async #fetchLiked( + async #fetchVerificationMethod( url: URL, options: { documentLoader?: DocumentLoader, @@ -37397,7 +36558,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {}, - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -37431,7 +36592,7 @@ get preferredUsernames(): ((string | LanguageString))[] { const { document, documentUrl } = fetchResult; const baseUrl = parseIri(documentUrl); try { - const obj = await this.#liked_fromJsonLd( + const obj = await this.#verificationMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); @@ -37479,7 +36640,7 @@ get preferredUsernames(): ((string | LanguageString))[] { }); } - async #liked_fromJsonLd( + async #verificationMethod_fromJsonLd( jsonLd: unknown, options: { documentLoader?: DocumentLoader, @@ -37487,7 +36648,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, baseUrl?: URL } - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -37497,7 +36658,7 @@ get preferredUsernames(): ((string | LanguageString))[] { const baseUrl = options.baseUrl; try { - return await Collection.fromJsonLd( + return await Multikey.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); @@ -37506,38 +36667,36 @@ get preferredUsernames(): ((string | LanguageString))[] { } throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Collection\\"].join(\\", \\")); + [\\"https://w3id.org/security#Multikey\\"].join(\\", \\")); } /** * Similar to - * {@link Application.getLiked}, + * {@link DataIntegrityProof.getVerificationMethod}, * but returns its \`@id\` URL instead of the object itself. */ - get likedId(): URL | null { + get verificationMethodId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; - const v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; + if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; + const v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; if (v instanceof URL) return v; return v.id; } -/** This is a list of every object from all of the actor's {@link Like} - * activities, added as a - * [side effect](https://www.w3.org/TR/activitypub/#like-activity-outbox). - * The \`liked\` collection MUST be either an {@link OrderedCollection} or - * a {@link Collection} and MAY be filtered on privileges of an authenticated - * user or as appropriate when no authentication is given. +/** A key owned by an actor according to [FEP-521a: Representing actor's public + * keys][1]. + * + * [1]: https://w3id.org/fep/521a * */ - async getLiked( + async getVerificationMethod( options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, @@ -37545,59 +36704,34 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {} - ): Promise { + ): Promise { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; - let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; + if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; + let v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; if (!(v instanceof URL) && v.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { + !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { v = v.id; } if (v instanceof URL) { const fetched = - await this.#fetchLiked(v, options); + await this.#fetchVerificationMethod(v, options); if (fetched == null) return null; - this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0] = fetched; - this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.add(0); + this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0] = fetched; + this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.add(0); this._cachedJsonLd = undefined; return fetched; } - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"liked\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"liked\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#liked_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - if (v?.id != null && this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { + !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -37620,467 +36754,777 @@ get preferredUsernames(): ((string | LanguageString))[] { return v; } - async #fetchFeatured( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; - try { - fetchResult = await documentLoader(lookupUrl); - } 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: lookupUrl } - ); - return null; - } - throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#featured_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href +/** The reason the proof was created. + * + * - \`\\"assertionMethod\\"\` + * - \`\\"authentication\\"\` + * - \`\\"capabilityInvocation\\"\` + * - \`\\"capabilityDelegation\\"\` + * - \`\\"keyAgreement\\"\` + * + */ + get proofPurpose(): (\\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\" | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; - } finally { - span.end(); } - }); - } - - async #featured_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL + if (this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose.length < 1) return null; + return this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose[0]; } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await Collection.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, + +/** The proof value. + */ + get proofValue(): (Uint8Array | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Collection\\"].join(\\", \\")); - } - - - /** - * Similar to - * {@link Application.getFeatured}, - * but returns its \`@id\` URL instead of the object itself. - */ - get featuredId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; - const v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (v instanceof URL) return v; - return v.id; + if (this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue.length < 1) return null; + return this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue[0]; } -/** What is known in Mastodon as \\"pinned statuses\\", or statuses that are always - * featured at the top of people's profiles, is implemented using an extra - * property \`featured\` on the actor object that points to a {@link Collection} - * of objects. - * +/** The date and time the proof was created. */ - - async getFeatured( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { + get created(): (Temporal.Instant | null) { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; - let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchFeatured(v, options); - if (fetched == null) return null; - this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0] = fetched; - this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"featured\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"featured\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#featured_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; + if (this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac.length < 1) return null; + return this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac[0]; } - async #fetchFeaturedTags( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + const values: Record = {}; + array = []; + for (const v of this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite) { + const element = ( + { \\"@value\\": v } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#cryptosuite\\"] = propValue; + + } + + array = []; + for (const v of this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#verificationMethod\\"] = propValue; + + } + + array = []; + for (const v of this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose) { + const element = ( + { + \\"@id\\": \\"https://w3id.org/security#\\" + v, + } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#proofPurpose\\"] = propValue; + + } + + array = []; + for (const v of this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue) { + const element = ( + { + \\"@type\\": \\"https://w3id.org/security#multibase\\", + \\"@value\\": new TextDecoder().decode(encodeMultibase(\\"base58btc\\", v)), + } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#proofValue\\"] = propValue; + + } + + array = []; + for (const v of this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac) { + const element = ( + { + \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#dateTime\\", + \\"@value\\": v.toString(), + } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"http://purl.org/dc/terms/created\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/security#DataIntegrityProof\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + \\"https://w3id.org/security/data-integrity/v1\\"; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + } + return compacted; + } + + protected isCompactable(): boolean { + + return true; + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__DataIntegrityProof__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#featuredTags_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } + }, + ); + } + + protected static async __fromJsonLd__DataIntegrityProof__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + } + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/security#DataIntegrityProof\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); } + + const instance = new this( + { + id + }, + options, + ); + const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: (\\"eddsa-jcs-2022\\")[] = []; - async #featuredTags_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; + let _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array = values[\\"https://w3id.org/security#cryptosuite\\"]; - try { - return await Collection.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Collection\\"].join(\\", \\")); + for ( + const v of _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array == null + ? [] + : _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array.length === 1 && \\"@list\\" in _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array[0] + ? _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array[0][\\"@list\\"] + : _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite__array + ) { + if (v == null) continue; + + const decoded = v[\\"@value\\"]; + if (typeof decoded === \\"undefined\\") continue; + _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite.push(decoded); } - + instance.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite; - /** - * Similar to - * {@link Application.getFeaturedTags}, - * but returns its \`@id\` URL instead of the object itself. - */ - get featuredTagsId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; - const v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (v instanceof URL) return v; - return v.id; + const _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: (Multikey | URL)[] = []; + const _trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod: Set = new Set(); + + let _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array = values[\\"https://w3id.org/security#verificationMethod\\"]; + + for ( + const v of _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array == null + ? [] + : _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array.length === 1 && \\"@list\\" in _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array[0] + ? _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array[0][\\"@list\\"] + : _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; } -/** What is known in Mastodon as \\"featured hashtags\\", hashtags that are featured - * at people's profiles, is implemented using an extra property \`featuredTags\` - * on the actor object that points to a {@link Collection} of {@link Hashtag} - * objects specifically. - * - */ + const decoded = await Multikey.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(decoded); + } + instance.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod; + const _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose: (\\"assertionMethod\\" | \\"authentication\\" | \\"capabilityInvocation\\" | \\"capabilityDelegation\\" | \\"keyAgreement\\")[] = []; - async getFeaturedTags( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values + let _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array = values[\\"https://w3id.org/security#proofPurpose\\"]; + + for ( + const v of _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array == null + ? [] + : _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array.length === 1 && \\"@list\\" in _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array[0] + ? _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array[0][\\"@list\\"] + : _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose__array + ) { + if (v == null) continue; + + const decoded = v[\\"@id\\"].substring(26); + if (typeof decoded === \\"undefined\\") continue; + _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose.push(decoded); + } + instance.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose; + const _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue: (Uint8Array)[] = []; + + let _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array = values[\\"https://w3id.org/security#proofValue\\"]; + + for ( + const v of _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array == null + ? [] + : _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array.length === 1 && \\"@list\\" in _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array[0] + ? _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array[0][\\"@list\\"] + : _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue__array + ) { + if (v == null) continue; + + const decoded = decodeMultibase(v[\\"@value\\"]); + if (typeof decoded === \\"undefined\\") continue; + _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue.push(decoded); + } + instance.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue; + const _3qzP3ukEZoUziK5FEiA1RhU4aqac: (Temporal.Instant)[] = []; + + let _3qzP3ukEZoUziK5FEiA1RhU4aqac__array = values[\\"http://purl.org/dc/terms/created\\"]; + + for ( + const v of _3qzP3ukEZoUziK5FEiA1RhU4aqac__array == null + ? [] + : _3qzP3ukEZoUziK5FEiA1RhU4aqac__array.length === 1 && \\"@list\\" in _3qzP3ukEZoUziK5FEiA1RhU4aqac__array[0] + ? _3qzP3ukEZoUziK5FEiA1RhU4aqac__array[0][\\"@list\\"] + : _3qzP3ukEZoUziK5FEiA1RhU4aqac__array + ) { + if (v == null) continue; + + const decoded = Temporal.Instant.from( + v[\\"@value\\"].substring(19).match(/[Z+-]/) + ? v[\\"@value\\"] + : v[\\"@value\\"] + \\"Z\\" + ); + if (typeof decoded === \\"undefined\\") continue; + _3qzP3ukEZoUziK5FEiA1RhU4aqac.push(decoded); + } + instance.#_3qzP3ukEZoUziK5FEiA1RhU4aqac = _3qzP3ukEZoUziK5FEiA1RhU4aqac; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; - let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchFeaturedTags(v, options); - if (fetched == null) return null; - this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0] = fetched; - this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.add(0); - this._cachedJsonLd = undefined; - return fetched; - } + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } + } + return instance; + } + + protected _getCustomInspectProxy(): Record { + + const proxy: Record = {}; + if (this.id != null) { + proxy.id = { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(this.id!.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(this.id!.href, options), + }; + } + + const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite = this.#_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite.length == 1) { + proxy.cryptosuite = _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite[0]; + } - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"featuredTags\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"featuredTags\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + const _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length == 1) { + proxy.verificationMethod = _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; + } - v = await this.#featuredTags_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + const _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose = this.#_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose.length == 1) { + proxy.proofPurpose = _2AeEnPcAvVrPEuKbpmn9ZKNmWHKb_proofPurpose[0]; + } + + const _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue = this.#_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue.length == 1) { + proxy.proofValue = _3CjFK5vfKpX4HQuNh2b18TykoVLq_proofValue[0]; + } + + const _3qzP3ukEZoUziK5FEiA1RhU4aqac = this.#_3qzP3ukEZoUziK5FEiA1RhU4aqac + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_3qzP3ukEZoUziK5FEiA1RhU4aqac.length == 1) { + proxy.created = _3qzP3ukEZoUziK5FEiA1RhU4aqac[0]; + } + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(DataIntegrityProof.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: DataIntegrityProof, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"DataIntegrityProof \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(DataIntegrityProof.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: DataIntegrityProof, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"DataIntegrityProof \\" + inspect(proxy, options); + }; + /** A key owned by an actor. + */ +export class CryptographicKey { + + readonly #documentLoader?: DocumentLoader; + readonly #contextLoader?: DocumentLoader; + readonly #tracerProvider?: TracerProvider; + readonly #warning?: { + category: string[]; + message: string; + values?: Record; + }; + #cachedJsonLd?: unknown; + readonly #_baseUrl?: URL; + readonly id: URL | null; + + protected get _documentLoader(): DocumentLoader | undefined { + return this.#documentLoader; + } + + protected get _contextLoader(): DocumentLoader | undefined { + return this.#contextLoader; + } + + protected get _tracerProvider(): TracerProvider | undefined { + return this.#tracerProvider; + } + + protected get _warning(): { + category: string[]; + message: string; + values?: Record; + } | undefined { + return this.#warning; + } + + protected get _cachedJsonLd(): unknown | undefined { + return this.#cachedJsonLd; + } + + protected set _cachedJsonLd(value: unknown | undefined) { + this.#cachedJsonLd = value; + } + + protected get _baseUrl(): URL | undefined { + return this.#_baseUrl; + } + + /** + * The type URI of {@link CryptographicKey}: \`https://w3id.org/security#Key\`. + */ + static get typeId(): URL { + return new URL(\\"https://w3id.org/security#Key\\"); + } + + #_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: (Application | Group | Organization | Person | Service | URL)[] = []; + #_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: Set = new Set(); + #_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem: (CryptoKey)[] = []; + + /** + * Constructs a new instance of CryptographicKey with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +owner?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + + this.#documentLoader = options.documentLoader; + this.#contextLoader = options.contextLoader; + this.#tracerProvider = options.tracerProvider; + const baseUrl = (options as { baseUrl?: URL }).baseUrl; + this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); + if (\\"\$warning\\" in options) { + this.#warning = options.\$warning as unknown as { + category: string[]; + message: string; + values?: Record; + }; + } + if (values.id == null || values.id instanceof URL) { + this.id = values.id ?? null; + } else { + throw new TypeError(\\"The id must be a URL.\\"); + } + + if (\\"owner\\" in values && values.owner != null) { + if (values.owner instanceof Application || values.owner instanceof Group || values.owner instanceof Organization || values.owner instanceof Person || values.owner instanceof Service || values.owner instanceof URL) { + // @ts-ignore: type is checked above. + this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = [values.owner]; + this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.add(0); + } else { + throw new TypeError( + \\"The owner must be of type \\" + + \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + ); } } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' + + if (\\"publicKey\\" in values && values.publicKey != null) { + if ( + // @ts-ignore: CryptoKey exists in the global scope. + values.publicKey instanceof CryptoKey + ) { + // @ts-ignore: type is checked above. + this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = [values.publicKey]; + + } else { + throw new TypeError( + \\"The publicKey must be of type \\" + + \\"CryptoKey\\" + \\".\\", ); } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; } - return v; } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + clone( + values: + { +id?: URL | null; +owner?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): CryptographicKey { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + + // @ts-ignore: this.constructor is not recognized as a constructor, but it is. + const clone: CryptographicKey = new this.constructor( + { id: values.id ?? this.id }, + options + ); + clone.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner;clone.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = new Set(this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner); + if (\\"owner\\" in values && values.owner != null) { + if (values.owner instanceof Application || values.owner instanceof Group || values.owner instanceof Organization || values.owner instanceof Person || values.owner instanceof Service || values.owner instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = [values.owner]; + clone.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = new Set([0]); + } else { + throw new TypeError( + \\"The owner must be of type \\" + + \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + ); + } + } + clone.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem; + if (\\"publicKey\\" in values && values.publicKey != null) { + if ( + // @ts-ignore: CryptoKey exists in the global scope. + values.publicKey instanceof CryptoKey + ) { + // @ts-ignore: type is checked above. + clone.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = [values.publicKey]; - async #fetchStream( + } else { + throw new TypeError( + \\"The publicKey must be of type \\" + + \\"CryptoKey\\" + \\".\\", + ); + } + } + + return clone; + } + + async #fetchOwner( url: URL, options: { documentLoader?: DocumentLoader, @@ -38089,7 +37533,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; } = {}, - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -38123,7 +37567,7 @@ get preferredUsernames(): ((string | LanguageString))[] { const { document, documentUrl } = fetchResult; const baseUrl = parseIri(documentUrl); try { - const obj = await this.#stream_fromJsonLd( + const obj = await this.#owner_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); @@ -38171,7 +37615,7 @@ get preferredUsernames(): ((string | LanguageString))[] { }); } - async #stream_fromJsonLd( + async #owner_fromJsonLd( jsonLd: unknown, options: { documentLoader?: DocumentLoader, @@ -38179,7 +37623,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, baseUrl?: URL } - ): Promise { + ): Promise { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); const contextLoader = @@ -38189,311 +37633,7 @@ get preferredUsernames(): ((string | LanguageString))[] { const baseUrl = options.baseUrl; try { - return await Collection.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Collection\\"].join(\\", \\")); - } - - - /** - * Similar to - * {@link Application.getStreams}, - * but returns their \`@id\`s instead of the objects themselves. - */ - get streamIds(): URL[] { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - return this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.map((v) => - v instanceof URL ? v : v.id! - ).filter(id => id !== null); - } - -/** A list of supplementary Collections which may be of interest. - * - */ - - async* getStreams( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): AsyncIterable { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; - for (let i = 0; i < vs.length; i++) { - let v = vs[i]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchStream(v, options); - if (fetched == null) continue; - vs[i] = fetched; - this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.add(i); - this._cachedJsonLd = undefined; - yield fetched; - continue; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"streams\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"streams\\"]; - const obj = Array.isArray(prop) ? prop[i] : prop; - if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { - - v = await this.#stream_fromJsonLd(obj, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin \\" + - 'option to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - continue; - } - yield v; - } - } - -/** A JSON object which maps additional (typically server/domain-wide) endpoints - * which may be useful either for this actor or someone referencing this actor. - * This mapping may be nested inside the actor document as the value or may be - * a link to a JSON-LD document with these properties. - * - */ - get endpoints(): (Endpoints | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints.length < 1) return null; - return this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints[0]; - } - -/** Allows users to opt-in or opt-out of discoverability features like - * the profile directory. This flag may also be used as an indicator of - * the user's preferences toward being included in external discovery services, - * such as search engines or other indexing tools. - * - */ - get discoverable(): (boolean | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable.length < 1) return null; - return this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable[0]; - } - -/** Reports whether a user was locally suspended, for better handling of - * these accounts. - * - */ - get suspended(): (boolean | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended.length < 1) return null; - return this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended[0]; - } - -/** Whether the actor is in-memorial state. - */ - get memorial(): (boolean | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial.length < 1) return null; - return this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial[0]; - } - -/** Whether the actor allows to be indexed. - */ - get indexable(): (boolean | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable.length < 1) return null; - return this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable[0]; - } - - async #fetchSuccessor( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; - try { - fetchResult = await documentLoader(lookupUrl); - } 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: lookupUrl } - ); - return null; - } - throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#successor_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; - } finally { - span.end(); - } - }); - } - - async #successor_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await Application.fromJsonLd( + return await Application.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); @@ -38544,26 +37684,26 @@ get preferredUsernames(): ((string | LanguageString))[] { /** * Similar to - * {@link Application.getSuccessor}, + * {@link CryptographicKey.getOwner}, * but returns its \`@id\` URL instead of the object itself. */ - get successorId(): URL | null { + get ownerId(): URL | null { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; - const v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; + if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; + const v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; if (v instanceof URL) return v; return v.id; } -/** Signifies that an actor has been moved to a different ID. Used in Mastodon-style data portability with the {@link Move} activity; see [ActivityPub Data Portability/Move Action](https://swicg.github.io/activitypub-data-portability/#move-action) for more details. +/** An actor who owns this key. */ - async getSuccessor( + async getOwner( options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, @@ -38578,20 +37718,20 @@ get preferredUsernames(): ((string | LanguageString))[] { this._warning.values ); } - if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; - let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; + if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; + let v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; if (!(v instanceof URL) && v.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { + !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { v = v.id; } if (v instanceof URL) { const fetched = - await this.#fetchSuccessor(v, options); + await this.#fetchOwner(v, options); if (fetched == null) return null; - this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0] = fetched; - this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.add(0); + this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0] = fetched; + this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.add(0); this._cachedJsonLd = undefined; return fetched; } @@ -38600,14 +37740,14 @@ get preferredUsernames(): ((string | LanguageString))[] { this._cachedJsonLd != null && typeof this._cachedJsonLd === \\"object\\" && \\"@context\\" in this._cachedJsonLd && - \\"movedTo\\" in this._cachedJsonLd + \\"owner\\" in this._cachedJsonLd ) { const prop = this._cachedJsonLd[ - \\"movedTo\\"]; + \\"owner\\"]; const doc = Array.isArray(prop) ? prop[0] : prop; if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - v = await this.#successor_fromJsonLd(doc, { + v = await this.#owner_fromJsonLd(doc, { ...options, baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this._baseUrl ?? @@ -38623,7 +37763,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (v?.id != null && this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { + !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -38646,751 +37786,936 @@ get preferredUsernames(): ((string | LanguageString))[] { return v; } - async #fetchAlias( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; - try { - fetchResult = await documentLoader(lookupUrl); - } 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: lookupUrl } - ); - return null; - } - throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#alias_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; - } finally { - span.end(); - } - }); - } - - async #alias_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await Application.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Group.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Organization.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Person.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - try { - return await Service.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Service\\"].join(\\", \\")); - } - - - /** - * Similar to - * {@link Application.getAlias}, - * but returns its \`@id\` URL instead of the object itself. - */ - get aliasId(): URL | null { +/** A PEM-encoded public key. + */ + get publicKey(): (CryptoKey | null) { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; - const v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (v instanceof URL) return v; - return v.id; + if (this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem.length < 1) return null; + return this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem[0]; } -/** The \`aliases\` (\`alsoKnownAs\`) property is used to specify alternative names - * or aliases for an entity. It can be used to provide additional identifiers - * or labels for an entity, which can be useful in scenarios where an entity - * may have multiple names or aliases. - * - */ - - async getAlias( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; - let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchAlias(v, options); - if (fetched == null) return null; - this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0] = fetched; - this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"alsoKnownAs\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"alsoKnownAs\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#alias_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + if (options.format == null && this.isCompactable()) { + const result: Record = {}; + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + + compactItems = []; + for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { + const item = ( + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) : v instanceof Group ? await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) : v instanceof Organization ? await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) : v instanceof Person ? await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) : await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { - } - } + result[\\"owner\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; } - /** - * Similar to - * {@link Application.getAliases}, - * but returns their \`@id\`s instead of the objects themselves. - */ - get aliasIds(): URL[] { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - return this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.map((v) => - v instanceof URL ? v : v.id! - ).filter(id => id !== null); + compactItems = []; + for (const v of this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem) { + const item = ( + await exportSpki(v) + ); + compactItems.push(item); } + if (compactItems.length > 0) { -/** The \`aliases\` (\`alsoKnownAs\`) property is used to specify alternative names - * or aliases for an entity. It can be used to provide additional identifiers - * or labels for an entity, which can be useful in scenarios where an entity - * may have multiple names or aliases. - * - */ - - async* getAliases( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): AsyncIterable { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; - for (let i = 0; i < vs.length; i++) { - let v = vs[i]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchAlias(v, options); - if (fetched == null) continue; - vs[i] = fetched; - this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.add(i); - this._cachedJsonLd = undefined; - yield fetched; - continue; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"alsoKnownAs\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"alsoKnownAs\\"]; - const obj = Array.isArray(prop) ? prop[i] : prop; - if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { - - v = await this.#alias_fromJsonLd(obj, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } + result[\\"publicKeyPem\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin \\" + - 'option to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - continue; - } - yield v; - } } - async #fetchService( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", + result[\\"type\\"] = \\"CryptographicKey\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = \\"https://w3id.org/security/v1\\"; + return result; + } + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + const values: Record = {}; + array = []; + for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#owner\\"] = propValue; + + } + + array = []; + for (const v of this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem) { + const element = ( + { \\"@value\\": await exportSpki(v) } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#publicKeyPem\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/security#Key\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + \\"https://w3id.org/security/v1\\"; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + } + return compacted; + } + + protected isCompactable(): boolean { + + return true; + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__CryptographicKey__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#service_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } + }, + ); + } + + protected static async __fromJsonLd__CryptographicKey__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - - async #service_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await DidService.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://www.w3.org/ns/did#Service\\"].join(\\", \\")); + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } - - - /** - * Similar to - * {@link Application.getService}, - * but returns its \`@id\` URL instead of the object itself. - */ - get serviceId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; - const v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (v instanceof URL) return v; - return v.id; + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/security#Key\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + const instance = new this( + { + id + }, + options, + ); + + const _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: (Application | Group | Organization | Person | Service | URL)[] = []; + const _trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner: Set = new Set(); + + let _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array = values[\\"https://w3id.org/security#owner\\"]; + + for ( + const v of _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array == null + ? [] + : _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array.length === 1 && \\"@list\\" in _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array[0] + ? _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array[0][\\"@list\\"] + : _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner__array + ) { + if (v == null) continue; + + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; } -/** Means of communicating or interacting with the DID subject or associated - * entities via one or more service endpoints. Examples include discovery - * services, agent services, social networking services, file storage services, - * and verifiable credential repository services. - * - */ - - async getService( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; - let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchService(v, options); - if (fetched == null) return null; - this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0] = fetched; - this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"service\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"service\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#service_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + const decoded = + typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\") ? await Application.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Group\\") ? await Group.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Organization\\") ? await Organization.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Person\\") ? await Person.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Service\\") ? await Service.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : undefined + ; + if (typeof decoded === \\"undefined\\") continue; + _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(decoded); - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, + } + instance.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner; + const _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem: (CryptoKey)[] = []; + + let _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array = values[\\"https://w3id.org/security#publicKeyPem\\"]; + + for ( + const v of _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array == null + ? [] + : _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array.length === 1 && \\"@list\\" in _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array[0] + ? _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array[0][\\"@list\\"] + : _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem__array + ) { + if (v == null) continue; + + const decoded = await importPem(v[\\"@value\\"]); + if (typeof decoded === \\"undefined\\") continue; + _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem.push(decoded); + } + instance.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem; + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, ); - return null; + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - return v; + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } + } + return instance; + } + + protected _getCustomInspectProxy(): Record { + + const proxy: Record = {}; + if (this.id != null) { + proxy.id = { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(this.id!.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(this.id!.href, options), + }; + } + + const _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length == 1) { + proxy.owner = _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; } - /** - * Similar to - * {@link Application.getServices}, - * but returns their \`@id\`s instead of the objects themselves. - */ - get serviceIds(): URL[] { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - return this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.map((v) => - v instanceof URL ? v : v.id! - ).filter(id => id !== null); + const _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem = this.#_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem.length == 1) { + proxy.publicKey = _2fE2QMDdg6KFGqa4NEC3TmjApSAD_publicKeyPem[0]; } -/** Means of communicating or interacting with the DID subject or associated - * entities via one or more service endpoints. Examples include discovery - * services, agent services, social networking services, file storage services, - * and verifiable credential repository services. + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(CryptographicKey.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: CryptographicKey, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"CryptographicKey \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(CryptographicKey.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: CryptographicKey, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"CryptographicKey \\" + inspect(proxy, options); + }; + /** Represents a key owned by an actor according to [FEP-521a: Representing + * actor's public keys.][1] + * + * [1]: https://w3id.org/fep/521a * */ +export class Multikey { - async* getServices( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): AsyncIterable { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; - for (let i = 0; i < vs.length; i++) { - let v = vs[i]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchService(v, options); - if (fetched == null) continue; - vs[i] = fetched; - this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.add(i); - this._cachedJsonLd = undefined; - yield fetched; - continue; + readonly #documentLoader?: DocumentLoader; + readonly #contextLoader?: DocumentLoader; + readonly #tracerProvider?: TracerProvider; + readonly #warning?: { + category: string[]; + message: string; + values?: Record; + }; + #cachedJsonLd?: unknown; + readonly #_baseUrl?: URL; + readonly id: URL | null; + + protected get _documentLoader(): DocumentLoader | undefined { + return this.#documentLoader; + } + + protected get _contextLoader(): DocumentLoader | undefined { + return this.#contextLoader; + } + + protected get _tracerProvider(): TracerProvider | undefined { + return this.#tracerProvider; + } + + protected get _warning(): { + category: string[]; + message: string; + values?: Record; + } | undefined { + return this.#warning; + } + + protected get _cachedJsonLd(): unknown | undefined { + return this.#cachedJsonLd; + } + + protected set _cachedJsonLd(value: unknown | undefined) { + this.#cachedJsonLd = value; + } + + protected get _baseUrl(): URL | undefined { + return this.#_baseUrl; + } + + /** + * The type URI of {@link Multikey}: \`https://w3id.org/security#Multikey\`. + */ + static get typeId(): URL { + return new URL(\\"https://w3id.org/security#Multikey\\"); + } + + #_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: (Application | Group | Organization | Person | Service | URL)[] = []; + #_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: Set = new Set(); + #_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase: (CryptoKey)[] = []; + + /** + * Constructs a new instance of Multikey with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +controller?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + + this.#documentLoader = options.documentLoader; + this.#contextLoader = options.contextLoader; + this.#tracerProvider = options.tracerProvider; + const baseUrl = (options as { baseUrl?: URL }).baseUrl; + this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); + if (\\"\$warning\\" in options) { + this.#warning = options.\$warning as unknown as { + category: string[]; + message: string; + values?: Record; + }; + } + if (values.id == null || values.id instanceof URL) { + this.id = values.id ?? null; + } else { + throw new TypeError(\\"The id must be a URL.\\"); + } + + if (\\"controller\\" in values && values.controller != null) { + if (values.controller instanceof Application || values.controller instanceof Group || values.controller instanceof Organization || values.controller instanceof Person || values.controller instanceof Service || values.controller instanceof URL) { + // @ts-ignore: type is checked above. + this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = [values.controller]; + this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.add(0); + } else { + throw new TypeError( + \\"The controller must be of type \\" + + \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + ); } + } + if (\\"publicKey\\" in values && values.publicKey != null) { if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"service\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"service\\"]; - const obj = Array.isArray(prop) ? prop[i] : prop; - if (obj != null && typeof obj === \\"object\\" && \\"@context\\" in obj) { - - v = await this.#service_fromJsonLd(obj, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); + // @ts-ignore: CryptoKey exists in the global scope. + values.publicKey instanceof CryptoKey + ) { + // @ts-ignore: type is checked above. + this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = [values.publicKey]; - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin \\" + - 'option to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, + } else { + throw new TypeError( + \\"The publicKey must be of type \\" + + \\"CryptoKey\\" + \\".\\", ); - continue; } - yield v; } } - -/** This value is used for \`Actor\` type objects to show message on followed. - * - */ - get followedMessage(): (string | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage.length < 1) return null; - return this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage[0]; + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + clone( + values: + { +id?: URL | null; +controller?: Application | Group | Organization | Person | Service | URL | null;publicKey?: CryptoKey | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): Multikey { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + + // @ts-ignore: this.constructor is not recognized as a constructor, but it is. + const clone: Multikey = new this.constructor( + { id: values.id ?? this.id }, + options + ); + clone.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller;clone.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = new Set(this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller); + if (\\"controller\\" in values && values.controller != null) { + if (values.controller instanceof Application || values.controller instanceof Group || values.controller instanceof Organization || values.controller instanceof Person || values.controller instanceof Service || values.controller instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = [values.controller]; + clone.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = new Set([0]); + } else { + throw new TypeError( + \\"The controller must be of type \\" + + \\"Application | Group | Organization | Person | Service | URL\\" + \\".\\", + ); + } + } + clone.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase; + if (\\"publicKey\\" in values && values.publicKey != null) { + if ( + // @ts-ignore: CryptoKey exists in the global scope. + values.publicKey instanceof CryptoKey + ) { + // @ts-ignore: type is checked above. + clone.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = [values.publicKey]; + + } else { + throw new TypeError( + \\"The publicKey must be of type \\" + + \\"CryptoKey\\" + \\".\\", + ); + } + } + + return clone; + } + + async #fetchController( + url: URL, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {}, + ): Promise { + 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/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); + let fetchResult: RemoteDocument; + try { + fetchResult = await documentLoader(lookupUrl); + } 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: lookupUrl } + ); + return null; + } + throw error; + } + const { document, documentUrl } = fetchResult; + const baseUrl = parseIri(documentUrl); + try { + const obj = await this.#controller_fromJsonLd( + document, + { documentLoader, contextLoader, tracerProvider, baseUrl } + ); + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + + \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + + \\"the object. If you want to bypass this check and are aware of\\" + + 'the security implications, set the crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The object's @id ({objectId}) has a different origin than the document \\" + + \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + + \\"bypass this check and are aware of the security implications, \\" + + 'set the crossOrigin option to \\"trust\\".', + { ...fetchResult, objectId: obj.id.href }, + ); + return null; + } + span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); + span.setAttribute( + \\"activitypub.object.type\\", + // @ts-ignore: obj.constructor always has a typeId. + obj.constructor.typeId.href + ); + return obj; + } catch (e) { + if (options.suppressError) { + getLogger([\\"fedify\\", \\"vocab\\"]).error( + \\"Failed to parse {url}: {error}\\", + { error: e, url: lookupUrl } + ); + return null; + } + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(e), + }); + throw e; + } finally { + span.end(); + } + }); + } + + async #controller_fromJsonLd( + jsonLd: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL } + ): Promise { + const documentLoader = + options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); + const contextLoader = + options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); + const tracerProvider = options.tracerProvider ?? + this._tracerProvider ?? trace.getTracerProvider(); + const baseUrl = options.baseUrl; + + try { + return await Application.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; + } -/** Used on actors to indicate that they in some way identify as a cat, - * expressed as a boolean value. If this property is set to \`true\`, - * displaying the actor or their notes will have some special effects - * attached in some clients. + try { + return await Group.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; + } + + try { + return await Organization.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; + } + + try { + return await Person.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; + } + + try { + return await Service.fromJsonLd( + jsonLd, + { documentLoader, contextLoader, tracerProvider, baseUrl }, + ); + } catch (e) { + if (!(e instanceof TypeError)) throw e; + } + + throw new TypeError(\\"Expected an object of any type of: \\" + + [\\"https://www.w3.org/ns/activitystreams#Application\\",\\"https://www.w3.org/ns/activitystreams#Group\\",\\"https://www.w3.org/ns/activitystreams#Organization\\",\\"https://www.w3.org/ns/activitystreams#Person\\",\\"https://www.w3.org/ns/activitystreams#Service\\"].join(\\", \\")); + } + + + /** + * Similar to + * {@link Multikey.getController}, + * but returns its \`@id\` URL instead of the object itself. + */ + get controllerId(): URL | null { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; + const v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; + if (v instanceof URL) return v; + return v.id; + } + +/** An actor who owns this key. + */ + + async getController( + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + suppressError?: boolean, + tracerProvider?: TracerProvider, + crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; + } = {} + ): Promise { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; + let v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { + v = v.id; + } + if (v instanceof URL) { + const fetched = + await this.#fetchController(v, options); + if (fetched == null) return null; + this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0] = fetched; + this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.add(0); + this._cachedJsonLd = undefined; + return fetched; + } + + if ( + this._cachedJsonLd != null && + typeof this._cachedJsonLd === \\"object\\" && + \\"@context\\" in this._cachedJsonLd && + \\"controller\\" in this._cachedJsonLd + ) { + const prop = this._cachedJsonLd[ + \\"controller\\"]; + const doc = Array.isArray(prop) ? prop[0] : prop; + if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { + + v = await this.#controller_fromJsonLd(doc, { + ...options, + baseUrl: (options as { baseUrl?: URL }).baseUrl ?? + this._baseUrl ?? + (this.id != null && + (this.id.protocol === \\"http:\\" || + this.id.protocol === \\"https:\\") + ? this.id + : undefined), + }); + + } + } + + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { + if (options.crossOrigin === \\"throw\\") { + throw new Error( + \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + + \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + + \\"refusing to return the object. If you want to bypass this \\" + + \\"check and are aware of the security implications, set the \\" + + 'crossOrigin option to \\"trust\\".' + ); + } + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"The property object's @id ({objectId}) has a different origin \\" + + \\"than the property owner's @id ({parentObjectId}); refusing to \\" + + \\"return the object. If you want to bypass this check and are \\" + + \\"aware of the security implications, set the crossOrigin option \\" + + 'to \\"trust\\".', + { objectId: v.id.href, parentObjectId: this.id.href }, + ); + return null; + } + return v; + } + +/** A [Multibase]-encoded value of a [Multicodec] prefix and the key. + * + * [Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0 + * [Multicodec]: https://github.com/multiformats/multicodec/ * */ - get cat(): (boolean | null) { + get publicKey(): (CryptoKey | null) { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, this._warning.values ); } - if (this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat.length < 1) return null; - return this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat[0]; + if (this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase.length < 1) return null; + return this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase[0]; } /** @@ -39403,7 +38728,7 @@ get preferredUsernames(): ((string | LanguageString))[] { when \`format\` is set to \`'expand'\`. * @returns The JSON-LD representation of this object. */ - override async toJsonLd(options: { + async toJsonLd(options: { format?: \\"compact\\" | \\"expand\\", contextLoader?: DocumentLoader, context?: string | Record | (string | Record)[], @@ -39423,119 +38748,26 @@ get preferredUsernames(): ((string | LanguageString))[] { }; if (options.format == null && this.isCompactable()) { - - const result = await super.toJsonLd({ - ...options, - format: undefined, - context: undefined, - }) as Record; - + const result: Record = {}; // deno-lint-ignore no-unused-vars let compactItems: unknown[]; compactItems = []; - for (const v of this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername) { - const item = ( - typeof v === \\"string\\" ? v : { - \\"@value\\": v.toString(), - \\"@language\\": v.locale.baseName, - } - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"preferredUsername\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"publicKey\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { + for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"assertionMethod\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"manuallyApprovesFollowers\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { - const item = ( - v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ + }) : v instanceof Group ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, - }) : await v.toJsonLd({ + }) : v instanceof Organization ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"inbox\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { - const item = ( - v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ + }) : v instanceof Person ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39549,7 +38781,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (compactItems.length > 0) { - result[\\"outbox\\"] + result[\\"controller\\"] = compactItems.length > 1 ? compactItems : compactItems[0]; @@ -39557,358 +38789,51 @@ get preferredUsernames(): ((string | LanguageString))[] { } compactItems = []; - for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { + for (const v of this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase) { const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) + await exportMultibaseKey(v) ); compactItems.push(item); } if (compactItems.length > 0) { - result[\\"following\\"] + result[\\"publicKeyMultibase\\"] = compactItems.length > 1 ? compactItems : compactItems[0]; } - compactItems = []; - for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"followers\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"liked\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"featured\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"featuredTags\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"streams\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints) { - const item = ( - await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"endpoints\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"discoverable\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"suspended\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"memorial\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"indexable\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { - const item = ( - v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Group ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Organization ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Person ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"movedTo\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { - const item = ( - v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Group ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Organization ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : v instanceof Person ? await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"alsoKnownAs\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"service\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"_misskey_followedMessage\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"isCat\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"Application\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; - - array = []; - for (const v of this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername) { - const element = ( - typeof v === \\"string\\" ? { \\"@value\\": v } : { - \\"@value\\": v.toString(), - \\"@language\\": v.locale.baseName, + result[\\"type\\"] = \\"Multikey\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = \\"https://w3id.org/security/multikey/v1\\"; + return result; + } + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + const values: Record = {}; + array = []; + for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { + const element = ( + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/security#controller\\"] = propValue; + + } + + array = []; + for (const v of this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase) { + const element = ( + { + \\"@type\\": \\"https://w3id.org/security#multibase\\", + \\"@value\\": await exportMultibaseKey(v), } ); array.push(element);; @@ -39917,164 +38842,624 @@ get preferredUsernames(): ((string | LanguageString))[] { const propValue = ( array ); - values[\\"https://www.w3.org/ns/activitystreams#preferredUsername\\"] = propValue; + values[\\"https://w3id.org/security#publicKeyMultibase\\"] = propValue; } - array = []; - for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + values[\\"@type\\"] = [\\"https://w3id.org/security#Multikey\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, ); - array.push(element);; } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#publicKey\\"] = propValue; - + const docContext = options.context ?? + \\"https://w3id.org/security/multikey/v1\\"; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + } - - array = []; - for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; + return compacted; + } + + protected isCompactable(): boolean { + + return true; + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { + try { + const object = await this.__fromJsonLd__Multikey__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; + } catch (error) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(error), + }); + throw error; + } finally { + span.end(); + } + }, + ); + } + + protected static async __fromJsonLd__Multikey__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/security#assertionMethod\\"] = propValue; - + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, + }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - - array = []; - for (const v of this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers\\"] = propValue; - + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/security#Multikey\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } - - array = []; - for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) - ); - array.push(element);; + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"http://www.w3.org/ns/ldp#inbox\\"] = propValue; + + const instance = new this( + { + id + }, + options, + ); - } + const _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: (Application | Group | Organization | Person | Service | URL)[] = []; + const _trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller: Set = new Set(); - array = []; - for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#outbox\\"] = propValue; + let _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array = values[\\"https://w3id.org/security#controller\\"]; - } + for ( + const v of _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array == null + ? [] + : _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array.length === 1 && \\"@list\\" in _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array[0] + ? _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array[0][\\"@list\\"] + : _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller__array + ) { + if (v == null) continue; - array = []; - for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; + if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) + && globalThis.Object.keys(v).length === 1) { + if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; + _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(parseIri(v[\\"@id\\"], options.baseUrl)); + continue; + } + + const decoded = + typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\") ? await Application.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Group\\") ? await Group.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Organization\\") ? await Organization.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Person\\") ? await Person.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : typeof v === \\"object\\" && \\"@type\\" in v + && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Service\\") ? await Service.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ) : undefined + ; + if (typeof decoded === \\"undefined\\") continue; + _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(decoded); + } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#following\\"] = propValue; + instance.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller; + const _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase: (CryptoKey)[] = []; + + let _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array = values[\\"https://w3id.org/security#publicKeyMultibase\\"]; - } + for ( + const v of _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array == null + ? [] + : _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array.length === 1 && \\"@list\\" in _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array[0] + ? _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array[0][\\"@list\\"] + : _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase__array + ) { + if (v == null) continue; - array = []; - for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; + const decoded = await importMultibaseKey(v[\\"@value\\"]); + if (typeof decoded === \\"undefined\\") continue; + _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase.push(decoded); } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#followers\\"] = propValue; + instance.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase; + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); + } } - - array = []; - for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; + return instance; + } + + protected _getCustomInspectProxy(): Record { + + const proxy: Record = {}; + if (this.id != null) { + proxy.id = { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(this.id!.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(this.id!.href, options), + }; } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#liked\\"] = propValue; - } + const _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); - array = []; - for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"http://joinmastodon.org/ns#featured\\"] = propValue; + if (_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length == 1) { + proxy.controller = _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; + } + + const _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase = this.#_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + if (_4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase.length == 1) { + proxy.publicKey = _4XLHbsR2gLVWU3NpEqKt9wANzn4F_publicKeyMultibase[0]; + } + + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(Multikey.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Multikey, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Multikey \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Multikey.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Multikey, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Multikey \\" + inspect(proxy, options); + }; + /** The agreement reached between parties responding to a {@link Proposal}. + * + * An interested party sends an \`Agreement\` wrapped in an {@link Offer} + * activity. The proposing party then either finalizes the agreement by + * sending an {@link Accept} activity with the finalized \`Agreement\` as + * its \`result\`, or sends a {@link Reject} activity. + * + * Note: This type extends ActivityStreams \`Object\` for practical + * interoperability within ActivityPub federation, even though FEP-0837 + * defines \`Agreement\` as a pure ValueFlows type. Extending \`Object\` + * provides useful inherited properties such as \`id\`, \`attributedTo\`, + * \`url\`, \`to\`, and \`published\` without needing to redefine them. + * + */ +export class Agreement extends Object { + + /** + * The type URI of {@link Agreement}: \`https://w3id.org/valueflows/ont/vf#Agreement\`. + */ + static override get typeId(): URL { + return new URL(\\"https://w3id.org/valueflows/ont/vf#Agreement\\"); } - - array = []; - for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + #_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates: (Commitment)[] = []; +#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal: (Commitment)[] = []; + + /** + * Constructs a new instance of Agreement with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;stipulates?: Commitment | null;stipulatesReciprocal?: Commitment | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + super(values, options); + if (\\"stipulates\\" in values && values.stipulates != null) { + if (values.stipulates instanceof Commitment) { + // @ts-ignore: type is checked above. + this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = [values.stipulates]; + + } else { + throw new TypeError( + \\"The stipulates must be of type \\" + + \\"Commitment\\" + \\".\\", + ); + } + } + + if (\\"stipulatesReciprocal\\" in values && values.stipulatesReciprocal != null) { + if (values.stipulatesReciprocal instanceof Commitment) { + // @ts-ignore: type is checked above. + this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = [values.stipulatesReciprocal]; + + } else { + throw new TypeError( + \\"The stipulatesReciprocal must be of type \\" + + \\"Commitment\\" + \\".\\", + ); + } + } + } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + override clone( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;stipulates?: Commitment | null;stipulatesReciprocal?: Commitment | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): Agreement { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values ); - array.push(element);; + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; } - if (array.length > 0) { - const propValue = ( - array + const clone = super.clone(values, options) as unknown as Agreement;clone.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates; + if (\\"stipulates\\" in values && values.stipulates != null) { + if (values.stipulates instanceof Commitment) { + // @ts-ignore: type is checked above. + clone.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = [values.stipulates]; + + } else { + throw new TypeError( + \\"The stipulates must be of type \\" + + \\"Commitment\\" + \\".\\", + ); + } + } + clone.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal; + if (\\"stipulatesReciprocal\\" in values && values.stipulatesReciprocal != null) { + if (values.stipulatesReciprocal instanceof Commitment) { + // @ts-ignore: type is checked above. + clone.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = [values.stipulatesReciprocal]; + + } else { + throw new TypeError( + \\"The stipulatesReciprocal must be of type \\" + + \\"Commitment\\" + \\".\\", + ); + } + } + + return clone; + } + +/** The primary {@link Commitment} associated with the agreement. This + * commitment satisfies the primary {@link Intent} of the corresponding + * {@link Proposal}. + * + */ + get stipulates(): (Commitment | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates.length < 1) return null; + return this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates[0]; + } + +/** The reciprocal {@link Commitment} associated with the agreement. + * Required if the corresponding {@link Proposal} has a reciprocal + * {@link Intent}. + * + */ + get stipulatesReciprocal(): (Commitment | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal.length < 1) return null; + return this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal[0]; + } + + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" ); - values[\\"http://joinmastodon.org/ns#featuredTags\\"] = propValue; + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + if (options.format == null && this.isCompactable()) { + + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; + + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + compactItems = []; + for (const v of this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"stipulates\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"stipulatesReciprocal\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + result[\\"type\\"] = \\"Agreement\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Agreement\\":\\"vf:Agreement\\",\\"Commitment\\":\\"vf:Commitment\\",\\"stipulates\\":\\"vf:stipulates\\",\\"stipulatesReciprocal\\":\\"vf:stipulatesReciprocal\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; + return result; } + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + array = []; - for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { + for (const v of this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates) { const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) + await v.toJsonLd(options) ); array.push(element);; } @@ -40082,12 +39467,12 @@ get preferredUsernames(): ((string | LanguageString))[] { const propValue = ( array ); - values[\\"https://www.w3.org/ns/activitystreams#streams\\"] = propValue; + values[\\"https://w3id.org/valueflows/ont/vf#stipulates\\"] = propValue; } array = []; - for (const v of this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints) { + for (const v of this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal) { const element = ( await v.toJsonLd(options) ); @@ -40097,146 +39482,11 @@ get preferredUsernames(): ((string | LanguageString))[] { const propValue = ( array ); - values[\\"https://www.w3.org/ns/activitystreams#endpoints\\"] = propValue; + values[\\"https://w3id.org/valueflows/ont/vf#stipulatesReciprocal\\"] = propValue; } - array = []; - for (const v of this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"http://joinmastodon.org/ns#discoverable\\"] = propValue; - - } - - array = []; - for (const v of this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"http://joinmastodon.org/ns#suspended\\"] = propValue; - - } - - array = []; - for (const v of this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"http://joinmastodon.org/ns#memorial\\"] = propValue; - - } - - array = []; - for (const v of this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"http://joinmastodon.org/ns#indexable\\"] = propValue; - - } - - array = []; - for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#movedTo\\"] = propValue; - - } - - array = []; - for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#alsoKnownAs\\"] = propValue; - - } - - array = []; - for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/did#service\\"] = propValue; - - } - - array = []; - for (const v of this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://misskey-hub.net/ns#_misskey_followedMessage\\"] = propValue; - - } - - array = []; - for (const v of this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat) { - const element = ( - { \\"@value\\": v } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://misskey-hub.net/ns#isCat\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Application\\"]; + values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Agreement\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -40245,7 +39495,7 @@ get preferredUsernames(): ((string | LanguageString))[] { ); } const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Agreement\\":\\"vf:Agreement\\",\\"Commitment\\":\\"vf:Commitment\\",\\"stipulates\\":\\"vf:stipulates\\",\\"stipulatesReciprocal\\":\\"vf:stipulatesReciprocal\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; const compacted = await jsonld.compact( values, docContext, @@ -40271,16 +39521,6 @@ get preferredUsernames(): ((string | LanguageString))[] { protected override isCompactable(): boolean { - if ( - this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername != null && - this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername.length > 0 - ) return false; - - if ( - this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service != null && - this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length > 0 - ) return false; - return super.isCompactable(); } @@ -40303,7 +39543,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -40313,7 +39553,7 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__Application__( + const object = await this.__fromJsonLd__Agreement__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -40332,7 +39572,7 @@ get preferredUsernames(): ((string | LanguageString))[] { ); } - protected static async __fromJsonLd__Application__( + protected static async __fromJsonLd__Agreement__( json: unknown, span: Span, options: { @@ -40341,7 +39581,7 @@ get preferredUsernames(): ((string | LanguageString))[] { tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -40378,7 +39618,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\")) { + if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Agreement\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -40400,626 +39640,657 @@ get preferredUsernames(): ((string | LanguageString))[] { // @ts-ignore: an internal option _fromSubclass: true, }); - if (!(instance instanceof Application)) { + if (!(instance instanceof Agreement)) { throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } - const _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername: ((string | LanguageString))[] = []; + const _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates: (Commitment)[] = []; - let _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername__array = values[\\"https://www.w3.org/ns/activitystreams#preferredUsername\\"]; - - for ( - const v of _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername__array == null - ? [] - : _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername__array.length === 1 && \\"@list\\" in _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername__array[0] - ? _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername__array[0][\\"@list\\"] - : _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername__array - ) { - if (v == null) continue; - - const decoded = - typeof v === \\"object\\" && \\"@value\\" in v - && typeof v[\\"@value\\"] === \\"string\\" && !(\\"@language\\" in v) ? v[\\"@value\\"] : typeof v === \\"object\\" && \\"@language\\" in v && \\"@value\\" in v - && typeof v[\\"@language\\"] === \\"string\\" - && typeof v[\\"@value\\"] === \\"string\\" ? new LanguageString(v[\\"@value\\"], v[\\"@language\\"]) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername.push(decoded); - - } - instance.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername; - - const _axq166E2eZADq34V4MYUc8KMZdC_publicKey: (CryptographicKey | URL)[] = []; - const _trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey: Set = new Set(); - - let _axq166E2eZADq34V4MYUc8KMZdC_publicKey__array = values[\\"https://w3id.org/security#publicKey\\"]; + let _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array = values[\\"https://w3id.org/valueflows/ont/vf#stipulates\\"]; for ( - const v of _axq166E2eZADq34V4MYUc8KMZdC_publicKey__array == null + const v of _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array == null ? [] - : _axq166E2eZADq34V4MYUc8KMZdC_publicKey__array.length === 1 && \\"@list\\" in _axq166E2eZADq34V4MYUc8KMZdC_publicKey__array[0] - ? _axq166E2eZADq34V4MYUc8KMZdC_publicKey__array[0][\\"@list\\"] - : _axq166E2eZADq34V4MYUc8KMZdC_publicKey__array + : _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array.length === 1 && \\"@list\\" in _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array[0] + ? _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array[0][\\"@list\\"] + : _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates__array ) { if (v == null) continue; - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await CryptographicKey.fromJsonLd( + const decoded = await Commitment.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } ); if (typeof decoded === \\"undefined\\") continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(decoded); + _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates.push(decoded); } - instance.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey = _axq166E2eZADq34V4MYUc8KMZdC_publicKey; - - const _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod: (Multikey | URL)[] = []; - const _trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod: Set = new Set(); - - let _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod__array = values[\\"https://w3id.org/security#assertionMethod\\"]; + instance.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates; + const _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal: (Commitment)[] = []; + + let _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array = values[\\"https://w3id.org/valueflows/ont/vf#stipulatesReciprocal\\"]; for ( - const v of _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod__array == null + const v of _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array == null ? [] - : _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod__array.length === 1 && \\"@list\\" in _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod__array[0] - ? _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod__array[0][\\"@list\\"] - : _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod__array + : _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array.length === 1 && \\"@list\\" in _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array[0] + ? _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array[0][\\"@list\\"] + : _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal__array ) { if (v == null) continue; - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await Multikey.fromJsonLd( + const decoded = await Commitment.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } ); if (typeof decoded === \\"undefined\\") continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(decoded); - } - instance.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; - const _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers: (boolean)[] = []; - - let _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers__array = values[\\"https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers\\"]; - - for ( - const v of _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers__array == null - ? [] - : _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers__array.length === 1 && \\"@list\\" in _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers__array[0] - ? _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers__array[0][\\"@list\\"] - : _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers.push(decoded); + _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal.push(decoded); } - instance.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers = _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers; - - const _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox: (OrderedCollection | OrderedCollectionPage | URL)[] = []; - const _trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox: Set = new Set(); - - let _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox__array = values[\\"http://www.w3.org/ns/ldp#inbox\\"]; - - for ( - const v of _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox__array == null - ? [] - : _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox__array.length === 1 && \\"@list\\" in _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox__array[0] - ? _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox__array[0][\\"@list\\"] - : _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox__array - ) { - if (v == null) continue; + instance.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal; - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); } - - const decoded = - typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\") ? await OrderedCollection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\") ? await OrderedCollectionPage.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(decoded); - } - instance.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox; - - const _41QwhqJouoLg3h8dRPKat21brynC_outbox: (OrderedCollection | OrderedCollectionPage | URL)[] = []; - const _trust_41QwhqJouoLg3h8dRPKat21brynC_outbox: Set = new Set(); - - let _41QwhqJouoLg3h8dRPKat21brynC_outbox__array = values[\\"https://www.w3.org/ns/activitystreams#outbox\\"]; - - for ( - const v of _41QwhqJouoLg3h8dRPKat21brynC_outbox__array == null - ? [] - : _41QwhqJouoLg3h8dRPKat21brynC_outbox__array.length === 1 && \\"@list\\" in _41QwhqJouoLg3h8dRPKat21brynC_outbox__array[0] - ? _41QwhqJouoLg3h8dRPKat21brynC_outbox__array[0][\\"@list\\"] - : _41QwhqJouoLg3h8dRPKat21brynC_outbox__array - ) { - if (v == null) continue; + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + const _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates = this.#_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; + if (_37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates.length == 1) { + proxy.stipulates = _37zeAJ2NVyecrDdP8os69FGAn9Q6_stipulates[0]; } - const decoded = - typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\") ? await OrderedCollection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\") ? await OrderedCollectionPage.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(decoded); - - } - instance.#_41QwhqJouoLg3h8dRPKat21brynC_outbox = _41QwhqJouoLg3h8dRPKat21brynC_outbox; - - const _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following: (Collection | URL)[] = []; - const _trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following: Set = new Set(); - - let _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following__array = values[\\"https://www.w3.org/ns/activitystreams#following\\"]; - - for ( - const v of _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following__array == null - ? [] - : _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following__array.length === 1 && \\"@list\\" in _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following__array[0] - ? _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following__array[0][\\"@list\\"] - : _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following__array - ) { - if (v == null) continue; + const _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal = this.#_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; + if (_4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal.length == 1) { + proxy.stipulatesReciprocal = _4Vhx9DcywF65XWUQ4KZ35475FaJm_stipulatesReciprocal[0]; } - const decoded = await Collection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(decoded); + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(Agreement.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Agreement, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Agreement \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Agreement.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Agreement, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Agreement \\" + inspect(proxy, options); + }; + /** A promised economic transaction, referenced by an {@link Agreement}. + * + * A commitment satisfies an {@link Intent} of a {@link Proposal} and + * specifies the actual amount of the economic resource being committed. + * + */ +export class Commitment { + + readonly #documentLoader?: DocumentLoader; + readonly #contextLoader?: DocumentLoader; + readonly #tracerProvider?: TracerProvider; + readonly #warning?: { + category: string[]; + message: string; + values?: Record; + }; + #cachedJsonLd?: unknown; + readonly #_baseUrl?: URL; + readonly id: URL | null; + + protected get _documentLoader(): DocumentLoader | undefined { + return this.#documentLoader; } - instance.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following; - - const _BBCTgfphhsFzpVfKTykGSpBNwoA_followers: (Collection | URL)[] = []; - const _trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers: Set = new Set(); - - let _BBCTgfphhsFzpVfKTykGSpBNwoA_followers__array = values[\\"https://www.w3.org/ns/activitystreams#followers\\"]; - - for ( - const v of _BBCTgfphhsFzpVfKTykGSpBNwoA_followers__array == null - ? [] - : _BBCTgfphhsFzpVfKTykGSpBNwoA_followers__array.length === 1 && \\"@list\\" in _BBCTgfphhsFzpVfKTykGSpBNwoA_followers__array[0] - ? _BBCTgfphhsFzpVfKTykGSpBNwoA_followers__array[0][\\"@list\\"] - : _BBCTgfphhsFzpVfKTykGSpBNwoA_followers__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await Collection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(decoded); + + protected get _contextLoader(): DocumentLoader | undefined { + return this.#contextLoader; } - instance.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers = _BBCTgfphhsFzpVfKTykGSpBNwoA_followers; - - const _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked: (Collection | URL)[] = []; - const _trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked: Set = new Set(); - - let _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked__array = values[\\"https://www.w3.org/ns/activitystreams#liked\\"]; - - for ( - const v of _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked__array == null - ? [] - : _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked__array.length === 1 && \\"@list\\" in _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked__array[0] - ? _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked__array[0][\\"@list\\"] - : _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } + + protected get _tracerProvider(): TracerProvider | undefined { + return this.#tracerProvider; + } + + protected get _warning(): { + category: string[]; + message: string; + values?: Record; + } | undefined { + return this.#warning; + } + + protected get _cachedJsonLd(): unknown | undefined { + return this.#cachedJsonLd; + } + + protected set _cachedJsonLd(value: unknown | undefined) { + this.#cachedJsonLd = value; + } + + protected get _baseUrl(): URL | undefined { + return this.#_baseUrl; + } + + /** + * The type URI of {@link Commitment}: \`https://w3id.org/valueflows/ont/vf#Commitment\`. + */ + static get typeId(): URL { + return new URL(\\"https://w3id.org/valueflows/ont/vf#Commitment\\"); + } + #_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; +#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; + + /** + * Constructs a new instance of Commitment with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +satisfies?: URL | null;resourceQuantity?: Measure | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + + this.#documentLoader = options.documentLoader; + this.#contextLoader = options.contextLoader; + this.#tracerProvider = options.tracerProvider; + const baseUrl = (options as { baseUrl?: URL }).baseUrl; + this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); + if (\\"\$warning\\" in options) { + this.#warning = options.\$warning as unknown as { + category: string[]; + message: string; + values?: Record; + }; + } + if (values.id == null || values.id instanceof URL) { + this.id = values.id ?? null; + } else { + throw new TypeError(\\"The id must be a URL.\\"); + } + + if (\\"satisfies\\" in values && values.satisfies != null) { + if (values.satisfies instanceof URL) { + // @ts-ignore: type is checked above. + this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = [values.satisfies]; - const decoded = await Collection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } + } else { + throw new TypeError( + \\"The satisfies must be of type \\" + + \\"URL\\" + \\".\\", + ); + } + } + + if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { + if (values.resourceQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; + + } else { + throw new TypeError( + \\"The resourceQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } + } + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + clone( + values: + { +id?: URL | null; +satisfies?: URL | null;resourceQuantity?: Measure | null;} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): Commitment { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + + // @ts-ignore: this.constructor is not recognized as a constructor, but it is. + const clone: Commitment = new this.constructor( + { id: values.id ?? this.id }, + options ); - if (typeof decoded === \\"undefined\\") continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(decoded); + clone.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies; + if (\\"satisfies\\" in values && values.satisfies != null) { + if (values.satisfies instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = [values.satisfies]; + + } else { + throw new TypeError( + \\"The satisfies must be of type \\" + + \\"URL\\" + \\".\\", + ); + } + } + clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; + if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { + if (values.resourceQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; + + } else { + throw new TypeError( + \\"The resourceQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } + + return clone; + } + +/** The {@link Intent} of a {@link Proposal} that this commitment + * satisfies. The value is the proposal's URI with a + * [fragment](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment) + * appended to identify the intent. Recommended fragments are + * \`primary\` and \`reciprocal\`. + * + */ + get satisfies(): (URL | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.length < 1) return null; + return this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies[0]; + } + +/** The amount and unit of the economic resource being committed. The + * unit must match the unit specified in the corresponding {@link Intent} + * of the proposal. + * + */ + get resourceQuantity(): (Measure | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length < 1) return null; + return this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; + } + + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; } - instance.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked; + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + if (options.format == null && this.isCompactable()) { + const result: Record = {}; + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; - const _4N1vBJzXDf8NbBumeECQMFvKetja_featured: (Collection | URL)[] = []; - const _trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured: Set = new Set(); + compactItems = []; + for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { + const item = ( + formatIri(v) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"satisfies\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"resourceQuantity\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + result[\\"type\\"] = \\"Commitment\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Commitment\\":\\"vf:Commitment\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; + return result; + } - let _4N1vBJzXDf8NbBumeECQMFvKetja_featured__array = values[\\"http://joinmastodon.org/ns#featured\\"]; + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + const values: Record = {}; + array = []; + for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { + const element = ( + { \\"@id\\": formatIri(v) } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#satisfies\\"] = propValue; + + } + + array = []; + for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Commitment\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Commitment\\":\\"vf:Commitment\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + } + return compacted; + } + + protected isCompactable(): boolean { + + return true; + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { + try { + const object = await this.__fromJsonLd__Commitment__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; + } catch (error) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(error), + }); + throw error; + } finally { + span.end(); + } + }, + ); + } + + protected static async __fromJsonLd__Commitment__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, + }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + } + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Commitment\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + const instance = new this( + { + id + }, + options, + ); + const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; + + let _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array = values[\\"https://w3id.org/valueflows/ont/vf#satisfies\\"]; for ( - const v of _4N1vBJzXDf8NbBumeECQMFvKetja_featured__array == null + const v of _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array == null ? [] - : _4N1vBJzXDf8NbBumeECQMFvKetja_featured__array.length === 1 && \\"@list\\" in _4N1vBJzXDf8NbBumeECQMFvKetja_featured__array[0] - ? _4N1vBJzXDf8NbBumeECQMFvKetja_featured__array[0][\\"@list\\"] - : _4N1vBJzXDf8NbBumeECQMFvKetja_featured__array + : _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array.length === 1 && \\"@list\\" in _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array[0] + ? _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array[0][\\"@list\\"] + : _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies__array ) { if (v == null) continue; - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await Collection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(decoded); + _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.push(decoded); } - instance.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured = _4N1vBJzXDf8NbBumeECQMFvKetja_featured; - - const _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags: (Collection | URL)[] = []; - const _trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags: Set = new Set(); - - let _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags__array = values[\\"http://joinmastodon.org/ns#featuredTags\\"]; + instance.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies; + const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; + + let _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"]; for ( - const v of _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags__array == null + const v of _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array == null ? [] - : _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags__array.length === 1 && \\"@list\\" in _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags__array[0] - ? _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags__array[0][\\"@list\\"] - : _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags__array + : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array.length === 1 && \\"@list\\" in _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0] + ? _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0][\\"@list\\"] + : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array ) { if (v == null) continue; - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await Collection.fromJsonLd( + const decoded = await Measure.fromJsonLd( v, { ...options, baseUrl: options.baseUrl } ); if (typeof decoded === \\"undefined\\") continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(decoded); + _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.push(decoded); } - instance.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags; - - const _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams: (Collection | URL)[] = []; - const _trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams: Set = new Set(); - - let _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams__array = values[\\"https://www.w3.org/ns/activitystreams#streams\\"]; - - for ( - const v of _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams__array == null - ? [] - : _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams__array.length === 1 && \\"@list\\" in _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams__array[0] - ? _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams__array[0][\\"@list\\"] - : _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await Collection.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(decoded); - } - instance.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; - const _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints: (Endpoints)[] = []; - - let _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints__array = values[\\"https://www.w3.org/ns/activitystreams#endpoints\\"]; - - for ( - const v of _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints__array == null - ? [] - : _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints__array.length === 1 && \\"@list\\" in _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints__array[0] - ? _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints__array[0][\\"@list\\"] - : _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints__array - ) { - if (v == null) continue; - - const decoded = await Endpoints.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints.push(decoded); - } - instance.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints = _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints; - const _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable: (boolean)[] = []; - - let _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array = values[\\"http://joinmastodon.org/ns#discoverable\\"]; - - for ( - const v of _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array == null - ? [] - : _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array.length === 1 && \\"@list\\" in _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array[0] - ? _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array[0][\\"@list\\"] - : _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable.push(decoded); - } - instance.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable = _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable; - const _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended: (boolean)[] = []; - - let _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended__array = values[\\"http://joinmastodon.org/ns#suspended\\"]; - - for ( - const v of _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended__array == null - ? [] - : _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended__array.length === 1 && \\"@list\\" in _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended__array[0] - ? _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended__array[0][\\"@list\\"] - : _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended.push(decoded); - } - instance.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended = _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended; - const _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial: (boolean)[] = []; - - let _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial__array = values[\\"http://joinmastodon.org/ns#memorial\\"]; - - for ( - const v of _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial__array == null - ? [] - : _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial__array.length === 1 && \\"@list\\" in _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial__array[0] - ? _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial__array[0][\\"@list\\"] - : _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial.push(decoded); - } - instance.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial = _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial; - const _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable: (boolean)[] = []; - - let _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable__array = values[\\"http://joinmastodon.org/ns#indexable\\"]; - - for ( - const v of _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable__array == null - ? [] - : _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable__array.length === 1 && \\"@list\\" in _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable__array[0] - ? _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable__array[0][\\"@list\\"] - : _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable.push(decoded); - } - instance.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable = _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable; - - const _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo: (Application | Group | Organization | Person | Service | URL)[] = []; - const _trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo: Set = new Set(); - - let _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo__array = values[\\"https://www.w3.org/ns/activitystreams#movedTo\\"]; - - for ( - const v of _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo__array == null - ? [] - : _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo__array.length === 1 && \\"@list\\" in _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo__array[0] - ? _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo__array[0][\\"@list\\"] - : _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = - typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\") ? await Application.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Group\\") ? await Group.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Organization\\") ? await Organization.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Person\\") ? await Person.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Service\\") ? await Service.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(decoded); - - } - instance.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo; - - const _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs: (Application | Group | Organization | Person | Service | URL)[] = []; - const _trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs: Set = new Set(); - - let _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs__array = values[\\"https://www.w3.org/ns/activitystreams#alsoKnownAs\\"]; - - for ( - const v of _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs__array == null - ? [] - : _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs__array.length === 1 && \\"@list\\" in _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs__array[0] - ? _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs__array[0][\\"@list\\"] - : _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = - typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Application\\") ? await Application.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Group\\") ? await Group.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Organization\\") ? await Organization.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Person\\") ? await Person.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : typeof v === \\"object\\" && \\"@type\\" in v - && Array.isArray(v[\\"@type\\"])&& v[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Service\\") ? await Service.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ) : undefined - ; - if (typeof decoded === \\"undefined\\") continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(decoded); - - } - instance.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; - - const _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service: (DidService | URL)[] = []; - const _trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service: Set = new Set(); - - let _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service__array = values[\\"https://www.w3.org/ns/did#service\\"]; - - for ( - const v of _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service__array == null - ? [] - : _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service__array.length === 1 && \\"@list\\" in _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service__array[0] - ? _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service__array[0][\\"@list\\"] - : _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await DidService.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(decoded); - } - instance.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; - const _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage: (string)[] = []; - - let _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage__array = values[\\"https://misskey-hub.net/ns#_misskey_followedMessage\\"]; - - for ( - const v of _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage__array == null - ? [] - : _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage__array.length === 1 && \\"@list\\" in _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage__array[0] - ? _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage__array[0][\\"@list\\"] - : _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage.push(decoded); - } - instance.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage = _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage; - const _2xEU4QtkC53RAun67T81Egqt9vmL_isCat: (boolean)[] = []; - - let _2xEU4QtkC53RAun67T81Egqt9vmL_isCat__array = values[\\"https://misskey-hub.net/ns#isCat\\"]; - - for ( - const v of _2xEU4QtkC53RAun67T81Egqt9vmL_isCat__array == null - ? [] - : _2xEU4QtkC53RAun67T81Egqt9vmL_isCat__array.length === 1 && \\"@list\\" in _2xEU4QtkC53RAun67T81Egqt9vmL_isCat__array[0] - ? _2xEU4QtkC53RAun67T81Egqt9vmL_isCat__array[0][\\"@list\\"] - : _2xEU4QtkC53RAun67T81Egqt9vmL_isCat__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _2xEU4QtkC53RAun67T81Egqt9vmL_isCat.push(decoded); - } - instance.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat = _2xEU4QtkC53RAun67T81Egqt9vmL_isCat; + instance.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { @@ -41046,9 +40317,24 @@ get preferredUsernames(): ((string | LanguageString))[] { return instance; } - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - const _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername = this.#_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername + protected _getCustomInspectProxy(): Record { + + const proxy: Record = {}; + if (this.id != null) { + proxy.id = { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(this.id!.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(this.id!.href, options), + }; + } + + const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies = this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies // deno-lint-ignore no-explicit-any .map((v: any) => v instanceof URL ? { @@ -41064,17 +40350,11 @@ get preferredUsernames(): ((string | LanguageString))[] { } : v); - if (_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername.length == 1) { - proxy.preferredUsername = _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername[0]; - } - - if (_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername.length > 1 - || !(\\"preferredUsername\\" in proxy) - && _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername.length > 0) { - proxy.preferredUsernames = _3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername; + if (_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.length == 1) { + proxy.satisfies = _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies[0]; } - const _axq166E2eZADq34V4MYUc8KMZdC_publicKey = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey + const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity // deno-lint-ignore no-explicit-any .map((v: any) => v instanceof URL ? { @@ -41090,517 +40370,200 @@ get preferredUsernames(): ((string | LanguageString))[] { } : v); - if (_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length == 1) { - proxy.publicKey = _axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - } - - if (_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length > 1 - || !(\\"publicKey\\" in proxy) - && _axq166E2eZADq34V4MYUc8KMZdC_publicKey.length > 0) { - proxy.publicKeys = _axq166E2eZADq34V4MYUc8KMZdC_publicKey; + if (_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length == 1) { + proxy.resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; } - const _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(Commitment.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Commitment, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Commitment \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Commitment.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Commitment, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Commitment \\" + inspect(proxy, options); + }; + /** A proposed economic transaction describing what is being offered or requested + * in a {@link Proposal}. + * + */ +export class Intent { + + readonly #documentLoader?: DocumentLoader; + readonly #contextLoader?: DocumentLoader; + readonly #tracerProvider?: TracerProvider; + readonly #warning?: { + category: string[]; + message: string; + values?: Record; + }; + #cachedJsonLd?: unknown; + readonly #_baseUrl?: URL; + readonly id: URL | null; + + protected get _documentLoader(): DocumentLoader | undefined { + return this.#documentLoader; + } + + protected get _contextLoader(): DocumentLoader | undefined { + return this.#contextLoader; + } + + protected get _tracerProvider(): TracerProvider | undefined { + return this.#tracerProvider; + } + + protected get _warning(): { + category: string[]; + message: string; + values?: Record; + } | undefined { + return this.#warning; + } + + protected get _cachedJsonLd(): unknown | undefined { + return this.#cachedJsonLd; + } + + protected set _cachedJsonLd(value: unknown | undefined) { + this.#cachedJsonLd = value; + } + + protected get _baseUrl(): URL | undefined { + return this.#_baseUrl; + } - if (_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length == 1) { - proxy.assertionMethod = _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - } + /** + * The type URI of {@link Intent}: \`https://w3id.org/valueflows/ont/vf#Intent\`. + */ + static get typeId(): URL { + return new URL(\\"https://w3id.org/valueflows/ont/vf#Intent\\"); + } + #_38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; +#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo: (URL)[] = []; +#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; +#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity: (Measure)[] = []; +#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity: (Measure)[] = []; + + /** + * Constructs a new instance of Intent with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measure | null;availableQuantity?: Measure | null;minimumQuantity?: Measure | null;} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + + this.#documentLoader = options.documentLoader; + this.#contextLoader = options.contextLoader; + this.#tracerProvider = options.tracerProvider; + const baseUrl = (options as { baseUrl?: URL }).baseUrl; + this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href); + if (\\"\$warning\\" in options) { + this.#warning = options.\$warning as unknown as { + category: string[]; + message: string; + values?: Record; + }; + } + if (values.id == null || values.id instanceof URL) { + this.id = values.id ?? null; + } else { + throw new TypeError(\\"The id must be a URL.\\"); + } + + if (\\"action\\" in values && values.action != null) { + if (typeof values.action === \\"string\\") { + // @ts-ignore: type is checked above. + this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = [values.action]; - if (_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length > 1 - || !(\\"assertionMethod\\" in proxy) - && _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length > 0) { - proxy.assertionMethods = _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; - } + } else { + throw new TypeError( + \\"The action must be of type \\" + + \\"string\\" + \\".\\", + ); + } + } - const _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers = this.#_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers.length == 1) { - proxy.manuallyApprovesFollowers = _36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers[0]; - } + if (\\"resourceConformsTo\\" in values && values.resourceConformsTo != null) { + if (values.resourceConformsTo instanceof URL) { + // @ts-ignore: type is checked above. + this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = [values.resourceConformsTo]; - const _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length == 1) { - proxy.inbox = _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - } - - const _41QwhqJouoLg3h8dRPKat21brynC_outbox = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_41QwhqJouoLg3h8dRPKat21brynC_outbox.length == 1) { - proxy.outbox = _41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - } - - const _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length == 1) { - proxy.following = _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - } - - const _BBCTgfphhsFzpVfKTykGSpBNwoA_followers = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length == 1) { - proxy.followers = _BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - } - - const _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length == 1) { - proxy.liked = _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - } - - const _4N1vBJzXDf8NbBumeECQMFvKetja_featured = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length == 1) { - proxy.featured = _4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - } - - const _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length == 1) { - proxy.featuredTags = _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - } - - const _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.length > 1 - || !(\\"stream\\" in proxy) - && _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.length > 0) { - proxy.streams = _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; - } - - const _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints = this.#_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints.length == 1) { - proxy.endpoints = _sEoQwUbfk4hEfugzNQ2ZiDcLMkG_endpoints[0]; - } - - const _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable = this.#_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable.length == 1) { - proxy.discoverable = _gAJzg1QDc4rcefFsUzGSYmyXvNH_discoverable[0]; - } - - const _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended = this.#_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended.length == 1) { - proxy.suspended = _2kGKkJtoFWg8c18PaVSqj9NKP4t7_suspended[0]; - } - - const _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial = this.#_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial.length == 1) { - proxy.memorial = _79S8K4f5J9MWUgCxziRyUe6PTHZ_memorial[0]; - } - - const _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable = this.#_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2diCorzqPGQQqftp6e4SrCEwEnyk_indexable.length == 1) { - proxy.indexable = _2diCorzqPGQQqftp6e4SrCEwEnyk_indexable[0]; - } - - const _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length == 1) { - proxy.successor = _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - } + } else { + throw new TypeError( + \\"The resourceConformsTo must be of type \\" + + \\"URL\\" + \\".\\", + ); + } + } - const _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length == 1) { - proxy.alias = _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - } + if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { + if (values.resourceQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; - if (_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length > 1 - || !(\\"alias\\" in proxy) - && _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length > 0) { - proxy.aliases = _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; - } + } else { + throw new TypeError( + \\"The resourceQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } - const _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length == 1) { - proxy.service = _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - } + if (\\"availableQuantity\\" in values && values.availableQuantity != null) { + if (values.availableQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = [values.availableQuantity]; - if (_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length > 1 - || !(\\"service\\" in proxy) - && _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length > 0) { - proxy.services = _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; - } + } else { + throw new TypeError( + \\"The availableQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } - const _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage = this.#_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage.length == 1) { - proxy.followedMessage = _QuxorEK1txp7jGjq8BRQfTPvUwp__misskey_followedMessage[0]; - } + if (\\"minimumQuantity\\" in values && values.minimumQuantity != null) { + if (values.minimumQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = [values.minimumQuantity]; - const _2xEU4QtkC53RAun67T81Egqt9vmL_isCat = this.#_2xEU4QtkC53RAun67T81Egqt9vmL_isCat - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2xEU4QtkC53RAun67T81Egqt9vmL_isCat.length == 1) { - proxy.cat = _2xEU4QtkC53RAun67T81Egqt9vmL_isCat[0]; + } else { + throw new TypeError( + \\"The minimumQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } } - - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(Application.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: Application, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Application \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(Application.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: Application, - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"Application \\" + inspect(proxy, options); - }; - /** Instances of \`IntransitiveActivity\` are a subtype of {@link Activity} - * representing intransitive actions. The \`object\` property is therefore - * inappropriate for these activities. - * - */ -export class IntransitiveActivity extends Activity { - - /** - * The type URI of {@link IntransitiveActivity}: \`https://www.w3.org/ns/activitystreams#IntransitiveActivity\`. - */ - static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\"); - } - - /** - * Constructs a new instance of IntransitiveActivity with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options);} /** * Clones this instance, optionally updating it with the given values. @@ -41608,40 +40571,18 @@ instruments?: (Object | URL)[];} * @param options The options to use for cloning. * @returns The cloned instance. */ - override clone( + clone( values: { id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} +action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measure | null;availableQuantity?: Measure | null;minimumQuantity?: Measure | null;} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): IntransitiveActivity { + ): Intent { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -41650,10 +40591,152 @@ instruments?: (Object | URL)[];} // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - const clone = super.clone(values, options) as unknown as IntransitiveActivity; - return clone; + + // @ts-ignore: this.constructor is not recognized as a constructor, but it is. + const clone: Intent = new this.constructor( + { id: values.id ?? this.id }, + options + ); + clone.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action; + if (\\"action\\" in values && values.action != null) { + if (typeof values.action === \\"string\\") { + // @ts-ignore: type is checked above. + clone.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = [values.action]; + + } else { + throw new TypeError( + \\"The action must be of type \\" + + \\"string\\" + \\".\\", + ); + } + } + clone.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo; + if (\\"resourceConformsTo\\" in values && values.resourceConformsTo != null) { + if (values.resourceConformsTo instanceof URL) { + // @ts-ignore: type is checked above. + clone.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = [values.resourceConformsTo]; + + } else { + throw new TypeError( + \\"The resourceConformsTo must be of type \\" + + \\"URL\\" + \\".\\", + ); + } + } + clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; + if (\\"resourceQuantity\\" in values && values.resourceQuantity != null) { + if (values.resourceQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + clone.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = [values.resourceQuantity]; + + } else { + throw new TypeError( + \\"The resourceQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } + clone.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity; + if (\\"availableQuantity\\" in values && values.availableQuantity != null) { + if (values.availableQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + clone.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = [values.availableQuantity]; + + } else { + throw new TypeError( + \\"The availableQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } + clone.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity; + if (\\"minimumQuantity\\" in values && values.minimumQuantity != null) { + if (values.minimumQuantity instanceof Measure) { + // @ts-ignore: type is checked above. + clone.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = [values.minimumQuantity]; + + } else { + throw new TypeError( + \\"The minimumQuantity must be of type \\" + + \\"Measure\\" + \\".\\", + ); + } + } + + return clone; } +/** The type of economic transaction. The value of this property should be + * either \`\\"deliverService\\"\` or \`\\"transfer\\"\`. + * + */ + get action(): (string | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action.length < 1) return null; + return this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action[0]; + } + +/** The type of an economic resource. Could be any URI. + * + */ + get resourceConformsTo(): (URL | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.length < 1) return null; + return this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo[0]; + } + +/** The amount and unit of the economic resource. + * + */ + get resourceQuantity(): (Measure | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length < 1) return null; + return this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; + } + +/** The quantity of the offered resource currently available. + * + */ + get availableQuantity(): (Measure | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity.length < 1) return null; + return this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity[0]; + } + +/** The minimum possible quantity of the resource. + * + */ + get minimumQuantity(): (Measure | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity.length < 1) return null; + return this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity[0]; + } + /** * Converts this object to a JSON-LD structure. * @param options The options to use. @@ -41664,7 +40747,7 @@ instruments?: (Object | URL)[];} when \`format\` is set to \`'expand'\`. * @returns The JSON-LD representation of this object. */ - override async toJsonLd(options: { + async toJsonLd(options: { format?: \\"compact\\" | \\"expand\\", contextLoader?: DocumentLoader, context?: string | Record | (string | Record)[], @@ -41683,20 +40766,188 @@ instruments?: (Object | URL)[];} contextLoader: options.contextLoader ?? getDocumentLoader(), }; + if (options.format == null && this.isCompactable()) { + const result: Record = {}; + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + + compactItems = []; + for (const v of this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action) { + const item = ( + v + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"action\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { + const item = ( + formatIri(v) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"resourceConformsTo\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"resourceQuantity\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"availableQuantity\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"minimumQuantity\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + result[\\"type\\"] = \\"Intent\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Intent\\":\\"vf:Intent\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; + return result; + } + // deno-lint-ignore no-unused-vars prefer-const let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; + const values: Record = {}; + array = []; + for (const v of this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action) { + const element = ( + { \\"@value\\": v } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#action\\"] = propValue; - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\"]; + } + + array = []; + for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { + const element = ( + { \\"@id\\": formatIri(v) } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\"] = propValue; + + } + + array = []; + for (const v of this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"] = propValue; + + } + + array = []; + for (const v of this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#availableQuantity\\"] = propValue; + + } + + array = []; + for (const v of this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#minimumQuantity\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Intent\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -41705,7 +40956,7 @@ instruments?: (Object | URL)[];} ); } const docContext = options.context ?? - [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; + [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Intent\\":\\"vf:Intent\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; const compacted = await jsonld.compact( values, docContext, @@ -41714,24 +40965,13 @@ instruments?: (Object | URL)[];} if (docContext != null) { // Embed context - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; - } - } else { - compacted.proof[\\"@context\\"] = docContext; - } - } - } return compacted; } - protected override isCompactable(): boolean { + protected isCompactable(): boolean { - return super.isCompactable(); + return true; } /** @@ -41745,7 +40985,7 @@ instruments?: (Object | URL)[];} * @returns The object of this type. * @throws {TypeError} If the given \`json\` is invalid. */ - static override async fromJsonLd( + static async fromJsonLd( json: unknown, options: { documentLoader?: DocumentLoader, @@ -41753,7 +40993,7 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -41763,7 +41003,7 @@ instruments?: (Object | URL)[];} \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__IntransitiveActivity__( + const object = await this.__fromJsonLd__Intent__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -41782,7 +41022,7 @@ instruments?: (Object | URL)[];} ); } - protected static async __fromJsonLd__IntransitiveActivity__( + protected static async __fromJsonLd__Intent__( json: unknown, span: Span, options: { @@ -41791,7 +41031,7 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -41828,19 +41068,7 @@ instruments?: (Object | URL)[];} if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Arrive\\")) { - return await Arrive.fromJsonLd(json, options); - } - - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Question\\")) { - return await Question.fromJsonLd(json, options); - } - - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Travel\\")) { - return await Travel.fromJsonLd(json, options); - } - - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\")) { + if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Intent\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -41856,15 +41084,111 @@ instruments?: (Object | URL)[];} cacheJsonLd = structuredClone(cacheJsonLd); } - delete values[\\"@type\\"]; - const instance = await super.fromJsonLd(values, { - ...options, - // @ts-ignore: an internal option - _fromSubclass: true, - }); - if (!(instance instanceof IntransitiveActivity)) { - throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + const instance = new this( + { + id + }, + options, + ); + const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; + + let _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array = values[\\"https://w3id.org/valueflows/ont/vf#action\\"]; + + for ( + const v of _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array == null + ? [] + : _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array.length === 1 && \\"@list\\" in _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array[0] + ? _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array[0][\\"@list\\"] + : _38VmZKmXJSBy3AvgqNa9GVqbdphy_action__array + ) { + if (v == null) continue; + + const decoded = v[\\"@value\\"]; + if (typeof decoded === \\"undefined\\") continue; + _38VmZKmXJSBy3AvgqNa9GVqbdphy_action.push(decoded); + } + instance.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action = _38VmZKmXJSBy3AvgqNa9GVqbdphy_action; + const _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo: (URL)[] = []; + + let _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array = values[\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\"]; + + for ( + const v of _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array == null + ? [] + : _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array.length === 1 && \\"@list\\" in _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array[0] + ? _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array[0][\\"@list\\"] + : _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo__array + ) { + if (v == null) continue; + + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); + if (typeof decoded === \\"undefined\\") continue; + _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.push(decoded); + } + instance.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo; + const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity: (Measure)[] = []; + + let _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#resourceQuantity\\"]; + + for ( + const v of _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array == null + ? [] + : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array.length === 1 && \\"@list\\" in _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0] + ? _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array[0][\\"@list\\"] + : _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity__array + ) { + if (v == null) continue; + + const decoded = await Measure.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.push(decoded); + } + instance.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity; + const _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity: (Measure)[] = []; + + let _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#availableQuantity\\"]; + + for ( + const v of _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array == null + ? [] + : _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array.length === 1 && \\"@list\\" in _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array[0] + ? _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array[0][\\"@list\\"] + : _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity__array + ) { + if (v == null) continue; + + const decoded = await Measure.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity.push(decoded); + } + instance.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity; + const _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity: (Measure)[] = []; + + let _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array = values[\\"https://w3id.org/valueflows/ont/vf#minimumQuantity\\"]; + + for ( + const v of _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array == null + ? [] + : _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array.length === 1 && \\"@list\\" in _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array[0] + ? _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array[0][\\"@list\\"] + : _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity__array + ) { + if (v == null) continue; + + const decoded = await Measure.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity.push(decoded); } + instance.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { @@ -41891,51 +41215,179 @@ instruments?: (Object | URL)[];} return instance; } - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - return proxy; - } - } - - -// deno-lint-ignore no-explicit-any -(IntransitiveActivity.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = - function ( - this: IntransitiveActivity, - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string { - const proxy = this._getCustomInspectProxy(); - return \\"IntransitiveActivity \\" + inspect(proxy, options); - }; - -// deno-lint-ignore no-explicit-any -(IntransitiveActivity.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = - function ( - this: IntransitiveActivity, - _depth: number, + protected _getCustomInspectProxy(): Record { + + const proxy: Record = {}; + if (this.id != null) { + proxy.id = { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(this.id!.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(this.id!.href, options), + }; + } + + const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action = this.#_38VmZKmXJSBy3AvgqNa9GVqbdphy_action + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_38VmZKmXJSBy3AvgqNa9GVqbdphy_action.length == 1) { + proxy.action = _38VmZKmXJSBy3AvgqNa9GVqbdphy_action[0]; + } + + const _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo = this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.length == 1) { + proxy.resourceConformsTo = _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo[0]; + } + + const _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity = this.#_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity.length == 1) { + proxy.resourceQuantity = _2dLfqTbbRiggEcMQWbHpxkQrtmrc_resourceQuantity[0]; + } + + const _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity = this.#_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity.length == 1) { + proxy.availableQuantity = _YmNSnuih3Zk4VdR5JPVnQYroLAh_availableQuantity[0]; + } + + const _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity = this.#_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity.length == 1) { + proxy.minimumQuantity = _3XueAFds2NBrqNpnV8b7aC8hV72S_minimumQuantity[0]; + } + + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(Intent.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Intent, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Intent \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Intent.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Intent, + _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); - return \\"IntransitiveActivity \\" + inspect(proxy, options); + return \\"Intent \\" + inspect(proxy, options); }; - /** An \`IntransitiveActivity\` that indicates that the \`actor\` has arrived at the \`location\`. - * The \`origin\` can be used to identify the context from which the \`actor\` originated. - * The \`target\` typically has no defined meaning. + /** A published request or offer, sometimes with what is expected in return. + * + * Proposals contain a primary {@link Intent} (via \`publishes\`) describing + * what is being offered or requested, and optionally a reciprocal + * {@link Intent} describing what is expected or offered in return. + * + * Note: This type extends ActivityStreams \`Object\` for practical + * interoperability within ActivityPub federation, even though FEP-0837 + * defines \`Proposal\` as a pure ValueFlows type. Extending \`Object\` + * provides useful inherited properties such as \`name\`, \`content\`, + * \`attributedTo\`, \`published\`, \`to\`, and \`location\` without needing to + * redefine them. * */ -export class Arrive extends IntransitiveActivity { +export class Proposal extends Object { /** - * The type URI of {@link Arrive}: \`https://www.w3.org/ns/activitystreams#Arrive\`. + * The type URI of {@link Proposal}: \`https://w3id.org/valueflows/ont/vf#Proposal\`. */ static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Arrive\\"); + return new URL(\\"https://w3id.org/valueflows/ont/vf#Proposal\\"); } - + #_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose: (string)[] = []; +#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes: (Intent)[] = []; +#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal: (Intent)[] = []; +#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased: (boolean)[] = []; + /** - * Constructs a new instance of Arrive with the given values. + * Constructs a new instance of Proposal with the given values. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ @@ -41959,13 +41411,7 @@ tos?: (Object | URL)[];bto?: Object | URL | null; btos?: (Object | URL)[];cc?: Object | URL | null; ccs?: (Object | URL)[];bcc?: Object | URL | null; bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;purpose?: string | null;publishes?: Intent | null;reciprocal?: Intent | null;unitBased?: boolean | null;} , options: { documentLoader?: DocumentLoader, @@ -41973,7 +41419,59 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, } = {}, ) { - super(values, options);} + super(values, options); + if (\\"purpose\\" in values && values.purpose != null) { + if (typeof values.purpose === \\"string\\") { + // @ts-ignore: type is checked above. + this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = [values.purpose]; + + } else { + throw new TypeError( + \\"The purpose must be of type \\" + + \\"string\\" + \\".\\", + ); + } + } + + if (\\"publishes\\" in values && values.publishes != null) { + if (values.publishes instanceof Intent) { + // @ts-ignore: type is checked above. + this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = [values.publishes]; + + } else { + throw new TypeError( + \\"The publishes must be of type \\" + + \\"Intent\\" + \\".\\", + ); + } + } + + if (\\"reciprocal\\" in values && values.reciprocal != null) { + if (values.reciprocal instanceof Intent) { + // @ts-ignore: type is checked above. + this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = [values.reciprocal]; + + } else { + throw new TypeError( + \\"The reciprocal must be of type \\" + + \\"Intent\\" + \\".\\", + ); + } + } + + if (\\"unitBased\\" in values && values.unitBased != null) { + if (typeof values.unitBased === \\"boolean\\") { + // @ts-ignore: type is checked above. + this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = [values.unitBased]; + + } else { + throw new TypeError( + \\"The unitBased must be of type \\" + + \\"boolean\\" + \\".\\", + ); + } + } + } /** * Clones this instance, optionally updating it with the given values. @@ -42001,20 +41499,14 @@ tos?: (Object | URL)[];bto?: Object | URL | null; btos?: (Object | URL)[];cc?: Object | URL | null; ccs?: (Object | URL)[];bcc?: Object | URL | null; bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; -actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; -objects?: (Object | URL)[];target?: Object | URL | null; -targets?: (Object | URL)[];result?: Object | URL | null; -results?: (Object | URL)[];origin?: Object | URL | null; -origins?: (Object | URL)[];instrument?: Object | URL | null; -instruments?: (Object | URL)[];} +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;purpose?: string | null;publishes?: Intent | null;reciprocal?: Intent | null;unitBased?: boolean | null;} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): Arrive { + ): Proposal { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -42023,10 +41515,121 @@ instruments?: (Object | URL)[];} // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - const clone = super.clone(values, options) as unknown as Arrive; + const clone = super.clone(values, options) as unknown as Proposal;clone.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose; + if (\\"purpose\\" in values && values.purpose != null) { + if (typeof values.purpose === \\"string\\") { + // @ts-ignore: type is checked above. + clone.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = [values.purpose]; + + } else { + throw new TypeError( + \\"The purpose must be of type \\" + + \\"string\\" + \\".\\", + ); + } + } + clone.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes; + if (\\"publishes\\" in values && values.publishes != null) { + if (values.publishes instanceof Intent) { + // @ts-ignore: type is checked above. + clone.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = [values.publishes]; + + } else { + throw new TypeError( + \\"The publishes must be of type \\" + + \\"Intent\\" + \\".\\", + ); + } + } + clone.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal; + if (\\"reciprocal\\" in values && values.reciprocal != null) { + if (values.reciprocal instanceof Intent) { + // @ts-ignore: type is checked above. + clone.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = [values.reciprocal]; + + } else { + throw new TypeError( + \\"The reciprocal must be of type \\" + + \\"Intent\\" + \\".\\", + ); + } + } + clone.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased; + if (\\"unitBased\\" in values && values.unitBased != null) { + if (typeof values.unitBased === \\"boolean\\") { + // @ts-ignore: type is checked above. + clone.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = [values.unitBased]; + + } else { + throw new TypeError( + \\"The unitBased must be of type \\" + + \\"boolean\\" + \\".\\", + ); + } + } + return clone; } +/** The type of proposal. Possible values are \`\\"offer\\"\` and \`\\"request\\"\`. + * + */ + get purpose(): (string | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose.length < 1) return null; + return this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose[0]; + } + +/** The primary intent of this proposal, describing what is being offered + * or requested. + * + */ + get publishes(): (Intent | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes.length < 1) return null; + return this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes[0]; + } + +/** The reciprocal intent of this proposal, describing what is expected + * or offered in return. + * + */ + get reciprocal(): (Intent | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal.length < 1) return null; + return this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal[0]; + } + +/** Indicates whether the quantities expressed in the proposal can be + * multiplied or not. The default is \`false\`. + * + */ + get unitBased(): (boolean | null) { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + } + if (this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased.length < 1) return null; + return this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased[0]; + } + /** * Converts this object to a JSON-LD structure. * @param options The options to use. @@ -42056,6 +41659,95 @@ instruments?: (Object | URL)[];} contextLoader: options.contextLoader ?? getDocumentLoader(), }; + if (options.format == null && this.isCompactable()) { + + const result = await super.toJsonLd({ + ...options, + format: undefined, + context: undefined, + }) as Record; + + // deno-lint-ignore no-unused-vars + let compactItems: unknown[]; + + compactItems = []; + for (const v of this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose) { + const item = ( + v + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"purpose\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"publishes\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal) { + const item = ( + await v.toJsonLd({ + ...(options), + format: undefined, + context: undefined, + }) + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"reciprocal\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + compactItems = []; + for (const v of this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased) { + const item = ( + v + ); + compactItems.push(item); + } + if (compactItems.length > 0) { + + result[\\"unitBased\\"] + = compactItems.length > 1 + ? compactItems + : compactItems[0]; + + } + + result[\\"type\\"] = \\"Proposal\\"; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); + result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Proposal\\":\\"vf:Proposal\\",\\"Intent\\":\\"vf:Intent\\",\\"purpose\\":\\"vf:purpose\\",\\"unitBased\\":\\"vf:unitBased\\",\\"publishes\\":\\"vf:publishes\\",\\"reciprocal\\":\\"vf:reciprocal\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; + return result; + } + // deno-lint-ignore no-unused-vars prefer-const let array: unknown[]; @@ -42069,7 +41761,67 @@ instruments?: (Object | URL)[];} unknown[] | { \\"@list\\": unknown[] } | string >; - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Arrive\\"]; + array = []; + for (const v of this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose) { + const element = ( + { \\"@value\\": v } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#purpose\\"] = propValue; + + } + + array = []; + for (const v of this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#publishes\\"] = propValue; + + } + + array = []; + for (const v of this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal) { + const element = ( + await v.toJsonLd(options) + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#reciprocal\\"] = propValue; + + } + + array = []; + for (const v of this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased) { + const element = ( + { \\"@value\\": v } + ); + array.push(element);; + } + if (array.length > 0) { + const propValue = ( + array + ); + values[\\"https://w3id.org/valueflows/ont/vf#unitBased\\"] = propValue; + + } + + values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Proposal\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -42078,7 +41830,7 @@ instruments?: (Object | URL)[];} ); } const docContext = options.context ?? - [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; + [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Proposal\\":\\"vf:Proposal\\",\\"Intent\\":\\"vf:Intent\\",\\"purpose\\":\\"vf:purpose\\",\\"unitBased\\":\\"vf:unitBased\\",\\"publishes\\":\\"vf:publishes\\",\\"reciprocal\\":\\"vf:reciprocal\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; const compacted = await jsonld.compact( values, docContext, @@ -42126,7 +41878,7 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -42136,7 +41888,7 @@ instruments?: (Object | URL)[];} \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__Arrive__( + const object = await this.__fromJsonLd__Proposal__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -42155,7 +41907,7 @@ instruments?: (Object | URL)[];} ); } - protected static async __fromJsonLd__Arrive__( + protected static async __fromJsonLd__Proposal__( json: unknown, span: Span, options: { @@ -42164,7 +41916,7 @@ instruments?: (Object | URL)[];} tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -42201,7 +41953,7 @@ instruments?: (Object | URL)[];} if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Arrive\\")) { + if (!values[\\"@type\\"].includes(\\"https://w3id.org/valueflows/ont/vf#Proposal\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -42223,9 +41975,87 @@ instruments?: (Object | URL)[];} // @ts-ignore: an internal option _fromSubclass: true, }); - if (!(instance instanceof Arrive)) { + if (!(instance instanceof Proposal)) { throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } + const _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose: (string)[] = []; + + let _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array = values[\\"https://w3id.org/valueflows/ont/vf#purpose\\"]; + + for ( + const v of _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array == null + ? [] + : _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array.length === 1 && \\"@list\\" in _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array[0] + ? _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array[0][\\"@list\\"] + : _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose__array + ) { + if (v == null) continue; + + const decoded = v[\\"@value\\"]; + if (typeof decoded === \\"undefined\\") continue; + _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose.push(decoded); + } + instance.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose; + const _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes: (Intent)[] = []; + + let _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array = values[\\"https://w3id.org/valueflows/ont/vf#publishes\\"]; + + for ( + const v of _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array == null + ? [] + : _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array.length === 1 && \\"@list\\" in _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array[0] + ? _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array[0][\\"@list\\"] + : _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes__array + ) { + if (v == null) continue; + + const decoded = await Intent.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes.push(decoded); + } + instance.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes; + const _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal: (Intent)[] = []; + + let _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array = values[\\"https://w3id.org/valueflows/ont/vf#reciprocal\\"]; + + for ( + const v of _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array == null + ? [] + : _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array.length === 1 && \\"@list\\" in _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array[0] + ? _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array[0][\\"@list\\"] + : _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal__array + ) { + if (v == null) continue; + + const decoded = await Intent.fromJsonLd( + v, + { ...options, baseUrl: options.baseUrl } + ); + if (typeof decoded === \\"undefined\\") continue; + _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal.push(decoded); + } + instance.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal; + const _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased: (boolean)[] = []; + + let _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array = values[\\"https://w3id.org/valueflows/ont/vf#unitBased\\"]; + + for ( + const v of _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array == null + ? [] + : _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array.length === 1 && \\"@list\\" in _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array[0] + ? _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array[0][\\"@list\\"] + : _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased__array + ) { + if (v == null) continue; + + const decoded = v[\\"@value\\"]; + if (typeof decoded === \\"undefined\\") continue; + _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased.push(decoded); + } + instance.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { @@ -42254,53 +42084,129 @@ instruments?: (Object | URL)[];} protected override _getCustomInspectProxy(): Record { const proxy: Record = super._getCustomInspectProxy(); + const _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose = this.#_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose.length == 1) { + proxy.purpose = _4wb2xgUBheR2gaD2Se8QBH4LEC7_purpose[0]; + } + + const _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes = this.#_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes.length == 1) { + proxy.publishes = _sS5LvXX8cn4c3x6ux836AwYbTyJ_publishes[0]; + } + + const _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal = this.#_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal.length == 1) { + proxy.reciprocal = _Z4ntJgFwR9BaNTbFvkRTGNEwUwy_reciprocal[0]; + } + + const _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased = this.#_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased + // deno-lint-ignore no-explicit-any + .map((v: any) => v instanceof URL + ? { + [Symbol.for(\\"Deno.customInspect\\")]: ( + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string => \\"URL \\" + inspect(v.href, options), + [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string => \\"URL \\" + inspect(v.href, options), + } + : v); + + if (_48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased.length == 1) { + proxy.unitBased = _48ncwmfGhSoqAFByMVh2UxoiozPq_unitBased[0]; + } + return proxy; } } // deno-lint-ignore no-explicit-any -(Arrive.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = +(Proposal.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = function ( - this: Arrive, + this: Proposal, inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { const proxy = this._getCustomInspectProxy(); - return \\"Arrive \\" + inspect(proxy, options); + return \\"Proposal \\" + inspect(proxy, options); }; // deno-lint-ignore no-explicit-any -(Arrive.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = +(Proposal.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = function ( - this: Arrive, + this: Proposal, _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); - return \\"Arrive \\" + inspect(proxy, options); + return \\"Proposal \\" + inspect(proxy, options); }; - /** Represents any kind of multi-paragraph written work. + /** Indicates that the \`actor\` accepts the \`object\`. The \`target\` property can be + * used in certain circumstances to indicate the context into which the \`object\` + * has been accepted. + * */ -export class Article extends Object { +export class Accept extends Activity { /** - * The type URI of {@link Article}: \`https://www.w3.org/ns/activitystreams#Article\`. + * The type URI of {@link Accept}: \`https://www.w3.org/ns/activitystreams#Accept\`. */ static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Article\\"); + return new URL(\\"https://www.w3.org/ns/activitystreams#Accept\\"); } - #_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote: (Object | URL)[] = []; - #_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote: Set = new Set(); - #_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl: (URL)[] = []; - - #_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization: (QuoteAuthorization | URL)[] = []; - #_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization: Set = new Set(); - /** - * Constructs a new instance of Article with the given values. + * Constructs a new instance of Accept with the given values. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ @@ -42324,7 +42230,13 @@ tos?: (Object | URL)[];bto?: Object | URL | null; btos?: (Object | URL)[];cc?: Object | URL | null; ccs?: (Object | URL)[];bcc?: Object | URL | null; bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;quote?: Object | URL | null;quoteUrl?: URL | null;quoteAuthorization?: QuoteAuthorization | URL | null;} +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} , options: { documentLoader?: DocumentLoader, @@ -42332,46 +42244,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu tracerProvider?: TracerProvider, } = {}, ) { - super(values, options); - if (\\"quote\\" in values && values.quote != null) { - if (values.quote instanceof Object || values.quote instanceof URL) { - // @ts-ignore: type is checked above. - this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = [values.quote]; - this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.add(0); - } else { - throw new TypeError( - \\"The quote must be of type \\" + - \\"Object | URL\\" + \\".\\", - ); - } - } - - if (\\"quoteUrl\\" in values && values.quoteUrl != null) { - if (values.quoteUrl instanceof URL) { - // @ts-ignore: type is checked above. - this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl = [values.quoteUrl]; - - } else { - throw new TypeError( - \\"The quoteUrl must be of type \\" + - \\"URL\\" + \\".\\", - ); - } - } - - if (\\"quoteAuthorization\\" in values && values.quoteAuthorization != null) { - if (values.quoteAuthorization instanceof QuoteAuthorization || values.quoteAuthorization instanceof URL) { - // @ts-ignore: type is checked above. - this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = [values.quoteAuthorization]; - this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.add(0); - } else { - throw new TypeError( - \\"The quoteAuthorization must be of type \\" + - \\"QuoteAuthorization | URL\\" + \\".\\", - ); - } - } - } + super(values, options);} /** * Clones this instance, optionally updating it with the given values. @@ -42399,14 +42272,20 @@ tos?: (Object | URL)[];bto?: Object | URL | null; btos?: (Object | URL)[];cc?: Object | URL | null; ccs?: (Object | URL)[];bcc?: Object | URL | null; bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;quote?: Object | URL | null;quoteUrl?: URL | null;quoteAuthorization?: QuoteAuthorization | URL | null;} +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): Article { + ): Accept { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -42415,790 +42294,505 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - const clone = super.clone(values, options) as unknown as Article;clone.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote;clone.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = new Set(this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote); - if (\\"quote\\" in values && values.quote != null) { - if (values.quote instanceof Object || values.quote instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = [values.quote]; - clone.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = new Set([0]); - } else { - throw new TypeError( - \\"The quote must be of type \\" + - \\"Object | URL\\" + \\".\\", - ); - } - } - clone.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl = this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl; - if (\\"quoteUrl\\" in values && values.quoteUrl != null) { - if (values.quoteUrl instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl = [values.quoteUrl]; - - } else { - throw new TypeError( - \\"The quoteUrl must be of type \\" + - \\"URL\\" + \\".\\", - ); - } - } - clone.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization;clone.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = new Set(this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization); - if (\\"quoteAuthorization\\" in values && values.quoteAuthorization != null) { - if (values.quoteAuthorization instanceof QuoteAuthorization || values.quoteAuthorization instanceof URL) { - // @ts-ignore: type is checked above. - clone.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = [values.quoteAuthorization]; - clone.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = new Set([0]); - } else { - throw new TypeError( - \\"The quoteAuthorization must be of type \\" + - \\"QuoteAuthorization | URL\\" + \\".\\", - ); + const clone = super.clone(values, options) as unknown as Accept; + return clone; + } + + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + + values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Accept\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; } + } else { + compacted.proof[\\"@context\\"] = docContext; } + } - return clone; + } + return compacted; + } + + protected override isCompactable(): boolean { + + return super.isCompactable(); } - async #fetchQuote( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static override async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__Accept__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#quote_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; } finally { span.end(); } - }); - } + }, + ); + } - async #quote_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await Object.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } 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\\"].join(\\", \\")); + protected static async __fromJsonLd__Accept__( + json: unknown, + span: Span, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + if (typeof json === \\"undefined\\") { + throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); + } + else if (json === null) throw new TypeError(\\"Invalid JSON-LD: null.\\"); + options = { + ...options, + documentLoader: options.documentLoader ?? getDocumentLoader(), + contextLoader: options.contextLoader ?? getDocumentLoader(), + tracerProvider: options.tracerProvider ?? trace.getTracerProvider(), + }; + // deno-lint-ignore no-explicit-any + let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; + if (globalThis.Object.keys(json).length == 0) { + values = {}; + expanded = [values]; + } else { + expanded = await jsonld.expand(json, { + documentLoader: options.contextLoader, + keepFreeFloatingNodes: true, + }); + values = + // deno-lint-ignore no-explicit-any + (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); + } + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; + } + + if (\\"@type\\" in values) { + span.setAttribute(\\"activitypub.object.type\\", values[\\"@type\\"]); + } + if (\\"@type\\" in values && + !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { + + if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\")) { + return await TentativeAccept.fromJsonLd(json, options); } - - /** - * Similar to - * {@link Article.getQuote}, - * but returns its \`@id\` URL instead of the object itself. - */ - get quoteId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values + if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Accept\\")) { + throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); + } + } + + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + + delete values[\\"@type\\"]; + const instance = await super.fromJsonLd(values, { + ...options, + // @ts-ignore: an internal option + _fromSubclass: true, + }); + if (!(instance instanceof Accept)) { + throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); + } + + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); } - if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; - const v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (v instanceof URL) return v; - return v.id; + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); } - -/** The quoted ActivityStreams object. - * - * This property is serialized as an IRI-valued JSON-LD property. + } + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + return proxy; + } + } + + +// deno-lint-ignore no-explicit-any +(Accept.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = + function ( + this: Accept, + inspect: typeof Deno.inspect, + options: Deno.InspectOptions, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Accept \\" + inspect(proxy, options); + }; + +// deno-lint-ignore no-explicit-any +(Accept.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = + function ( + this: Accept, + _depth: number, + options: unknown, + inspect: (value: unknown, options: unknown) => string, + ): string { + const proxy = this._getCustomInspectProxy(); + return \\"Accept \\" + inspect(proxy, options); + }; + /** Indicates that the \`actor\` has added the \`object\` to the \`target\`. + * If the \`target\` property is not explicitly specified, the target would need + * to be determined implicitly by context. The \`origin\` can be used to identify + * the context from which the \`object\` originated. * */ +export class Add extends Activity { - async getQuote( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; - let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchQuote(v, options); - if (fetched == null) return null; - this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0] = fetched; - this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"quote\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"quote\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#quote_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); + /** + * The type URI of {@link Add}: \`https://www.w3.org/ns/activitystreams#Add\`. + */ + static override get typeId(): URL { + return new URL(\\"https://www.w3.org/ns/activitystreams#Add\\"); + } + + /** + * Constructs a new instance of Add with the given values. + * @param values The values to initialize the instance with. + * @param options The options to use for initialization. + */ + constructor( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} +, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + } = {}, + ) { + super(values, options);} + + /** + * Clones this instance, optionally updating it with the given values. + * @param values The values to update the clone with. + * @param options The options to use for cloning. + * @returns The cloned instance. + */ + override clone( + values: + { +id?: URL | null; +attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; +attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; +audiences?: (Object | URL)[];content?: string | LanguageString | null; +contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; +names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; +icons?: (Image | URL)[];image?: Image | URL | null; +images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; +replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; +locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; +previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; +summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; +urls?: ((URL | Link))[];to?: Object | URL | null; +tos?: (Object | URL)[];bto?: Object | URL | null; +btos?: (Object | URL)[];cc?: Object | URL | null; +ccs?: (Object | URL)[];bcc?: Object | URL | null; +bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} + + = {}, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + } = {} + ): Add { + if (this._warning != null) { + getLogger(this._warning.category).warn( + this._warning.message, + this._warning.values + ); + // @ts-ignore: \$warning is not recognized as a property, but it is. + options = { ...options, \$warning: this._warning }; + } + const clone = super.clone(values, options) as unknown as Add; + return clone; + } + + /** + * Converts this object to a JSON-LD structure. + * @param options The options to use. + * - \`format\`: The format of the output: \`compact\` or + \`expand\`. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`context\`: The JSON-LD context to use. Not applicable + when \`format\` is set to \`'expand'\`. + * @returns The JSON-LD representation of this object. + */ + override async toJsonLd(options: { + format?: \\"compact\\" | \\"expand\\", + contextLoader?: DocumentLoader, + context?: string | Record | (string | Record)[], + } = {}): Promise { + if (options.format == null && this._cachedJsonLd != null) { + return this._cachedJsonLd; + } + if (options.format !== \\"compact\\" && options.context != null) { + throw new TypeError( + \\"The context option can only be used when the format option is set \\" + + \\"to 'compact'.\\" + ); + } + options = { + ...options, + contextLoader: options.contextLoader ?? getDocumentLoader(), + }; + + // deno-lint-ignore no-unused-vars prefer-const + let array: unknown[]; + + const baseValues = await super.toJsonLd({ + ...options, + format: \\"expand\\", + context: undefined, + }) as unknown[]; + const values = baseValues[0] as Record< + string, + unknown[] | { \\"@list\\": unknown[] } | string + >; + + values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Add\\"]; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); + if (options.format === \\"expand\\") { + return await jsonld.expand( + values, + { documentLoader: options.contextLoader }, + ); + } + const docContext = options.context ?? + [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; + const compacted = await jsonld.compact( + values, + docContext, + { documentLoader: options.contextLoader }, + ); + if (docContext != null) { + // Embed context + + if (\\"proof\\" in compacted && + compacted.proof != null) { + if (Array.isArray(compacted.proof)) { + for (const element of compacted.proof) { + element[\\"@context\\"] = docContext; } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; - } - -/** The URI of the ActivityStreams object that this object quotes. - * - * This property sets three JSON-LD properties at once under the hood: - * - * 1. https://www.w3.org/ns/activitystreams#quoteUrl - * 2. https://misskey-hub.net/ns#_misskey_quote - * 3. http://fedibird.com/ns#quoteUri - * - * When a JSON-LD object is parsed, this property is filled with one of - * the values of those three properties in order. - * - */ - get quoteUrl(): (URL | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); + } else { + compacted.proof[\\"@context\\"] = docContext; } - if (this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.length < 1) return null; - return this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl[0]; } - async #fetchQuoteAuthorization( - url: URL, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {}, - ): Promise { - 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/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { - const lookupUrl = formatIri(url); - let fetchResult: RemoteDocument; + } + return compacted; + } + + protected override isCompactable(): boolean { + + return super.isCompactable(); + } + + /** + * Converts a JSON-LD structure to an object of this type. + * @param json The JSON-LD structure to convert. + * @param options The options to use. + * - \`documentLoader\`: The loader for remote JSON-LD documents. + * - \`contextLoader\`: The loader for remote JSON-LD contexts. + * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. + * If omitted, the global tracer provider is used. + * @returns The object of this type. + * @throws {TypeError} If the given \`json\` is invalid. + */ + static override async fromJsonLd( + json: unknown, + options: { + documentLoader?: DocumentLoader, + contextLoader?: DocumentLoader, + tracerProvider?: TracerProvider, + baseUrl?: URL, + } = {}, + ): Promise { + const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); + const tracer = tracerProvider.getTracer( + \\"@fedify/vocab-tools\\", + \\"0.0.0\\", + ); + return await tracer.startActiveSpan( + \\"activitypub.parse_object\\", + async (span) => { try { - fetchResult = await documentLoader(lookupUrl); + const object = await this.__fromJsonLd__Add__( + json, span, options); + if (object.id != null) { + span.setAttribute(\\"activitypub.object.id\\", object.id.href); + } + return object; } 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: lookupUrl } - ); - return null; - } throw error; - } - const { document, documentUrl } = fetchResult; - const baseUrl = parseIri(documentUrl); - try { - const obj = await this.#quoteAuthorization_fromJsonLd( - document, - { documentLoader, contextLoader, tracerProvider, baseUrl } - ); - if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + - \\"than the document URL (\\" + baseUrl.href + \\"); refusing to return \\" + - \\"the object. If you want to bypass this check and are aware of\\" + - 'the security implications, set the crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The object's @id ({objectId}) has a different origin than the document \\" + - \\"URL ({documentUrl}); refusing to return the object. If you want to \\" + - \\"bypass this check and are aware of the security implications, \\" + - 'set the crossOrigin option to \\"trust\\".', - { ...fetchResult, objectId: obj.id.href }, - ); - return null; - } - span.setAttribute(\\"activitypub.object.id\\", (obj.id ?? url).href); - span.setAttribute( - \\"activitypub.object.type\\", - // @ts-ignore: obj.constructor always has a typeId. - obj.constructor.typeId.href - ); - return obj; - } catch (e) { - if (options.suppressError) { - getLogger([\\"fedify\\", \\"vocab\\"]).error( - \\"Failed to parse {url}: {error}\\", - { error: e, url: lookupUrl } - ); - return null; - } - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(e), - }); - throw e; - } finally { - span.end(); - } - }); - } - - async #quoteAuthorization_fromJsonLd( - jsonLd: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL - } - ): Promise { - const documentLoader = - options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); - const contextLoader = - options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); - const tracerProvider = options.tracerProvider ?? - this._tracerProvider ?? trace.getTracerProvider(); - const baseUrl = options.baseUrl; - - try { - return await QuoteAuthorization.fromJsonLd( - jsonLd, - { documentLoader, contextLoader, tracerProvider, baseUrl }, - ); - } catch (e) { - if (!(e instanceof TypeError)) throw e; - } - - throw new TypeError(\\"Expected an object of any type of: \\" + - [\\"https://w3id.org/fep/044f#QuoteAuthorization\\"].join(\\", \\")); - } - - - /** - * Similar to - * {@link Article.getQuoteAuthorization}, - * but returns its \`@id\` URL instead of the object itself. - */ - get quoteAuthorizationId(): URL | null { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; - const v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (v instanceof URL) return v; - return v.id; - } - -/** A {@link QuoteAuthorization} object that proves this quote was approved - * by the quoted object's author. - * - */ - - async getQuoteAuthorization( - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - suppressError?: boolean, - tracerProvider?: TracerProvider, - crossOrigin?: \\"ignore\\" | \\"throw\\" | \\"trust\\"; - } = {} - ): Promise { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; - let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (!(v instanceof URL) && - v.id != null && - !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { - v = v.id; - } - if (v instanceof URL) { - const fetched = - await this.#fetchQuoteAuthorization(v, options); - if (fetched == null) return null; - this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0] = fetched; - this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.add(0); - this._cachedJsonLd = undefined; - return fetched; - } - - if ( - this._cachedJsonLd != null && - typeof this._cachedJsonLd === \\"object\\" && - \\"@context\\" in this._cachedJsonLd && - \\"quoteAuthorization\\" in this._cachedJsonLd - ) { - const prop = this._cachedJsonLd[ - \\"quoteAuthorization\\"]; - const doc = Array.isArray(prop) ? prop[0] : prop; - if (doc != null && typeof doc === \\"object\\" && \\"@context\\" in doc) { - - v = await this.#quoteAuthorization_fromJsonLd(doc, { - ...options, - baseUrl: (options as { baseUrl?: URL }).baseUrl ?? - this._baseUrl ?? - (this.id != null && - (this.id.protocol === \\"http:\\" || - this.id.protocol === \\"https:\\") - ? this.id - : undefined), - }); - - } - } - - if (v?.id != null && - this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && - !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { - if (options.crossOrigin === \\"throw\\") { - throw new Error( - \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + - \\"origin than the property owner's @id (\\" + this.id.href + \\"); \\" + - \\"refusing to return the object. If you want to bypass this \\" + - \\"check and are aware of the security implications, set the \\" + - 'crossOrigin option to \\"trust\\".' - ); - } - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"The property object's @id ({objectId}) has a different origin \\" + - \\"than the property owner's @id ({parentObjectId}); refusing to \\" + - \\"return the object. If you want to bypass this check and are \\" + - \\"aware of the security implications, set the crossOrigin option \\" + - 'to \\"trust\\".', - { objectId: v.id.href, parentObjectId: this.id.href }, - ); - return null; - } - return v; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { - - const result = await super.toJsonLd({ - ...options, - format: undefined, - context: undefined, - }) as Record; - - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"quote\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { - const item = ( - formatIri(v) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"quoteUrl\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - result[\\"_misskey_quote\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - result[\\"quoteUri\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { - const item = ( - v instanceof URL ? formatIri(v) : await v.toJsonLd({ - ...(options), - format: undefined, - context: undefined, - }) - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"quoteAuthorization\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"Article\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; - return result; - } - - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; - - array = []; - for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/fep/044f#quote\\"] = propValue; - - } - - array = []; - for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { - const element = ( - { \\"@value\\": formatIri(v) } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#quoteUrl\\"] = propValue; - - values[\\"https://misskey-hub.net/ns#_misskey_quote\\"] = propValue; - - values[\\"http://fedibird.com/ns#quoteUri\\"] = propValue; - - } - - array = []; - for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { - const element = ( - v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://w3id.org/fep/044f#quoteAuthorization\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Article\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, - ); - } - const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; - } - } else { - compacted.proof[\\"@context\\"] = docContext; - } - } - - } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise
{ - const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); - const tracer = tracerProvider.getTracer( - \\"@fedify/vocab-tools\\", - \\"0.0.0\\", - ); - return await tracer.startActiveSpan( - \\"activitypub.parse_object\\", - async (span) => { - try { - const object = await this.__fromJsonLd__Article__( - json, span, options); - if (object.id != null) { - span.setAttribute(\\"activitypub.object.id\\", object.id.href); - } - return object; - } catch (error) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: String(error), - }); - throw error; - } finally { - span.end(); + } finally { + span.end(); } }, ); } - protected static async __fromJsonLd__Article__( + protected static async __fromJsonLd__Add__( json: unknown, span: Span, options: { @@ -43207,7 +42801,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise
{ + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -43244,7 +42838,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Article\\")) { + if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Add\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -43266,225 +42860,80 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // @ts-ignore: an internal option _fromSubclass: true, }); - if (!(instance instanceof Article)) { + if (!(instance instanceof Add)) { throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } - const _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote: (Object | URL)[] = []; - const _trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote: Set = new Set(); - - let _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote__array = values[\\"https://w3id.org/fep/044f#quote\\"]; - - for ( - const v of _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote__array == null - ? [] - : _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote__array.length === 1 && \\"@list\\" in _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote__array[0] - ? _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote__array[0][\\"@list\\"] - : _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; + if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { + try { + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } + } catch { + getLogger([\\"fedify\\", \\"vocab\\"]).warn( + \\"Failed to cache JSON-LD: {json}\\", + { json }, + ); } - - const decoded = await Object.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(decoded); } - instance.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote; - const _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl: (URL)[] = []; - - let _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array = values[\\"https://www.w3.org/ns/activitystreams#quoteUrl\\"]; - - if (_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array == null || _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array.length < 1) { - _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array = values[\\"https://misskey-hub.net/ns#_misskey_quote\\"]; - } - - if (_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array == null || _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array.length < 1) { - _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array = values[\\"http://fedibird.com/ns#quoteUri\\"]; - } - - for ( - const v of _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array == null - ? [] - : _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array.length === 1 && \\"@list\\" in _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array[0] - ? _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array[0][\\"@list\\"] - : _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl__array - ) { - if (v == null) continue; - - const decoded = parseIri(v[\\"@value\\"]); - if (typeof decoded === \\"undefined\\") continue; - _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); - } - instance.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl = _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl; - - const _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization: (QuoteAuthorization | URL)[] = []; - const _trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization: Set = new Set(); - - let _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization__array = values[\\"https://w3id.org/fep/044f#quoteAuthorization\\"]; - - for ( - const v of _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization__array == null - ? [] - : _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization__array.length === 1 && \\"@list\\" in _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization__array[0] - ? _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization__array[0][\\"@list\\"] - : _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization__array - ) { - if (v == null) continue; - - if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) - && globalThis.Object.keys(v).length === 1) { - if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); - continue; - } - - const decoded = await QuoteAuthorization.fromJsonLd( - v, - { ...options, baseUrl: options.baseUrl } - ); - if (typeof decoded === \\"undefined\\") continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(decoded); - } - instance.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization; - - if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { - try { - if (cacheJsonLd != null && cacheJsonLd !== expanded) { - const compactArray = Array.isArray(json) && json.length === 1; - const jsonLd = compactArray ? json[0] : json; - const normalized = cacheJsonLd; - const cachedJsonLd = await compactJsonLdCache( - normalized, - jsonLd, - options.contextLoader, - ); - instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; - } else { - instance._cachedJsonLd = structuredClone(json); - } - } catch { - getLogger([\\"fedify\\", \\"vocab\\"]).warn( - \\"Failed to cache JSON-LD: {json}\\", - { json }, - ); - } - } - return instance; - } - - protected override _getCustomInspectProxy(): Record { - const proxy: Record = super._getCustomInspectProxy(); - const _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length == 1) { - proxy.quote = _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - } - - const _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl = this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.length == 1) { - proxy.quoteUrl = _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl[0]; - } - - const _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length == 1) { - proxy.quoteAuthorization = _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - } - - return proxy; - } - } + return instance; + } + + protected override _getCustomInspectProxy(): Record { + const proxy: Record = super._getCustomInspectProxy(); + return proxy; + } + } // deno-lint-ignore no-explicit-any -(Article.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = +(Add.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = function ( - this: Article, + this: Add, inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { const proxy = this._getCustomInspectProxy(); - return \\"Article \\" + inspect(proxy, options); + return \\"Add \\" + inspect(proxy, options); }; // deno-lint-ignore no-explicit-any -(Article.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = +(Add.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = function ( - this: Article, + this: Add, _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); - return \\"Article \\" + inspect(proxy, options); + return \\"Add \\" + inspect(proxy, options); }; - /** Represents a document of any kind. + /** Indicates that the \`actor\` is calling the \`target\`'s attention the \`object\`. + * + * The \`origin\` typically has no defined meaning. + * */ -export class Document extends Object { +export class Announce extends Activity { /** - * The type URI of {@link Document}: \`https://www.w3.org/ns/activitystreams#Document\`. + * The type URI of {@link Announce}: \`https://www.w3.org/ns/activitystreams#Announce\`. */ static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Document\\"); + return new URL(\\"https://www.w3.org/ns/activitystreams#Announce\\"); } - #_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width: (number)[] = []; -#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height: (number)[] = []; - + /** - * Constructs a new instance of Document with the given values. + * Constructs a new instance of Announce with the given values. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ @@ -43508,7 +42957,13 @@ tos?: (Object | URL)[];bto?: Object | URL | null; btos?: (Object | URL)[];cc?: Object | URL | null; ccs?: (Object | URL)[];bcc?: Object | URL | null; bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;width?: number | null;height?: number | null;} +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} , options: { documentLoader?: DocumentLoader, @@ -43516,33 +42971,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu tracerProvider?: TracerProvider, } = {}, ) { - super(values, options); - if (\\"width\\" in values && values.width != null) { - if (typeof values.width === \\"number\\" && Number.isInteger(values.width) && values.width >= 0) { - // @ts-ignore: type is checked above. - this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width = [values.width]; - - } else { - throw new TypeError( - \\"The width must be of type \\" + - \\"number\\" + \\".\\", - ); - } - } - - if (\\"height\\" in values && values.height != null) { - if (typeof values.height === \\"number\\" && Number.isInteger(values.height) && values.height >= 0) { - // @ts-ignore: type is checked above. - this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height = [values.height]; - - } else { - throw new TypeError( - \\"The height must be of type \\" + - \\"number\\" + \\".\\", - ); - } - } - } + super(values, options);} /** * Clones this instance, optionally updating it with the given values. @@ -43570,14 +42999,20 @@ tos?: (Object | URL)[];bto?: Object | URL | null; btos?: (Object | URL)[];cc?: Object | URL | null; ccs?: (Object | URL)[];bcc?: Object | URL | null; bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;width?: number | null;height?: number | null;} +proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;actor?: Application | Group | Organization | Person | Service | URL | null; +actors?: (Application | Group | Organization | Person | Service | URL)[];object?: Object | URL | null; +objects?: (Object | URL)[];target?: Object | URL | null; +targets?: (Object | URL)[];result?: Object | URL | null; +results?: (Object | URL)[];origin?: Object | URL | null; +origins?: (Object | URL)[];instrument?: Object | URL | null; +instruments?: (Object | URL)[];} = {}, options: { documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, } = {} - ): Document { + ): Announce { if (this._warning != null) { getLogger(this._warning.category).warn( this._warning.message, @@ -43586,66 +43021,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // @ts-ignore: \$warning is not recognized as a property, but it is. options = { ...options, \$warning: this._warning }; } - const clone = super.clone(values, options) as unknown as Document;clone.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width = this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width; - if (\\"width\\" in values && values.width != null) { - if (typeof values.width === \\"number\\" && Number.isInteger(values.width) && values.width >= 0) { - // @ts-ignore: type is checked above. - clone.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width = [values.width]; - - } else { - throw new TypeError( - \\"The width must be of type \\" + - \\"number\\" + \\".\\", - ); - } - } - clone.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height = this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height; - if (\\"height\\" in values && values.height != null) { - if (typeof values.height === \\"number\\" && Number.isInteger(values.height) && values.height >= 0) { - // @ts-ignore: type is checked above. - clone.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height = [values.height]; - - } else { - throw new TypeError( - \\"The height must be of type \\" + - \\"number\\" + \\".\\", - ); - } - } - + const clone = super.clone(values, options) as unknown as Announce; return clone; } -/** Specifies a hint as to the rendering width in - * device-independent pixels of the linked resource. - * - */ - get width(): (number | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width.length < 1) return null; - return this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width[0]; - } - -/** Specifies a hint as to the rendering height in - * device-independent pixels of the linked resource. - * - */ - get height(): (number | null) { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - } - if (this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height.length < 1) return null; - return this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height[0]; - } - /** * Converts this object to a JSON-LD structure. * @param options The options to use. @@ -43675,55 +43054,6 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu contextLoader: options.contextLoader ?? getDocumentLoader(), }; - if (options.format == null && this.isCompactable()) { - - const result = await super.toJsonLd({ - ...options, - format: undefined, - context: undefined, - }) as Record; - - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; - - compactItems = []; - for (const v of this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"width\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - compactItems = []; - for (const v of this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height) { - const item = ( - v - ); - compactItems.push(item); - } - if (compactItems.length > 0) { - - result[\\"height\\"] - = compactItems.length > 1 - ? compactItems - : compactItems[0]; - - } - - result[\\"type\\"] = \\"Document\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; - return result; - } - // deno-lint-ignore no-unused-vars prefer-const let array: unknown[]; @@ -43737,43 +43067,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu unknown[] | { \\"@list\\": unknown[] } | string >; - array = []; - for (const v of this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width) { - const element = ( - { - \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\", - \\"@value\\": v, - } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#width\\"] = propValue; - - } - - array = []; - for (const v of this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height) { - const element = ( - { - \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\", - \\"@value\\": v, - } - ); - array.push(element);; - } - if (array.length > 0) { - const propValue = ( - array - ); - values[\\"https://www.w3.org/ns/activitystreams#height\\"] = propValue; - - } - - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Document\\"]; + values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Announce\\"]; if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( @@ -43782,7 +43076,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ); } const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; + [\\"https://w3id.org/identity/v1\\",\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":{\\"@id\\":\\"toot:votersCount\\",\\"@type\\":\\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\"},\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; const compacted = await jsonld.compact( values, docContext, @@ -43830,7 +43124,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); const tracer = tracerProvider.getTracer( \\"@fedify/vocab-tools\\", @@ -43840,7 +43134,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"activitypub.parse_object\\", async (span) => { try { - const object = await this.__fromJsonLd__Document__( + const object = await this.__fromJsonLd__Announce__( json, span, options); if (object.id != null) { span.setAttribute(\\"activitypub.object.id\\", object.id.href); @@ -43859,7 +43153,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ); } - protected static async __fromJsonLd__Document__( + protected static async __fromJsonLd__Announce__( json: unknown, span: Span, options: { @@ -43868,7 +43162,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, - ): Promise { + ): Promise { if (typeof json === \\"undefined\\") { throw new TypeError(\\"Invalid JSON-LD: undefined.\\"); } @@ -43905,23 +43199,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (\\"@type\\" in values && !values[\\"@type\\"].every(t => t.startsWith(\\"_:\\"))) { - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Audio\\")) { - return await Audio.fromJsonLd(json, options); - } - - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Image\\")) { - return await Image.fromJsonLd(json, options); - } - - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Page\\")) { - return await Page.fromJsonLd(json, options); - } - - if (values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Video\\")) { - return await Video.fromJsonLd(json, options); - } - - if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Document\\")) { + if (!values[\\"@type\\"].includes(\\"https://www.w3.org/ns/activitystreams#Announce\\")) { throw new TypeError(\\"Invalid type: \\" + values[\\"@type\\"]); } } @@ -43943,45 +43221,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // @ts-ignore: an internal option _fromSubclass: true, }); - if (!(instance instanceof Document)) { + if (!(instance instanceof Announce)) { throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name); } - const _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width: (number)[] = []; - - let _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width__array = values[\\"https://www.w3.org/ns/activitystreams#width\\"]; - - for ( - const v of _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width__array == null - ? [] - : _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width__array.length === 1 && \\"@list\\" in _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width__array[0] - ? _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width__array[0][\\"@list\\"] - : _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width.push(decoded); - } - instance.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width = _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width; - const _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height: (number)[] = []; - - let _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height__array = values[\\"https://www.w3.org/ns/activitystreams#height\\"]; - - for ( - const v of _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height__array == null - ? [] - : _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height__array.length === 1 && \\"@list\\" in _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height__array[0] - ? _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height__array[0][\\"@list\\"] - : _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height__array - ) { - if (v == null) continue; - - const decoded = v[\\"@value\\"]; - if (typeof decoded === \\"undefined\\") continue; - _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height.push(decoded); - } - instance.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height = _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { @@ -44010,451 +43252,97 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu protected override _getCustomInspectProxy(): Record { const proxy: Record = super._getCustomInspectProxy(); - const _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width = this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width.length == 1) { - proxy.width = _2e9AP7WdHBJYAgXG6GEyq7nSkNMe_width[0]; - } - - const _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height = this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height - // deno-lint-ignore no-explicit-any - .map((v: any) => v instanceof URL - ? { - [Symbol.for(\\"Deno.customInspect\\")]: ( - inspect: typeof Deno.inspect, - options: Deno.InspectOptions, - ): string => \\"URL \\" + inspect(v.href, options), - [Symbol.for(\\"nodejs.util.inspect.custom\\")]: ( - _depth: number, - options: unknown, - inspect: (value: unknown, options: unknown) => string, - ): string => \\"URL \\" + inspect(v.href, options), - } - : v); - - if (_2cGKFeFJMmiNpGZFEF75mCwFQsKb_height.length == 1) { - proxy.height = _2cGKFeFJMmiNpGZFEF75mCwFQsKb_height[0]; - } - return proxy; } } // deno-lint-ignore no-explicit-any -(Document.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = +(Announce.prototype as any)[Symbol.for(\\"Deno.customInspect\\")] = function ( - this: Document, + this: Announce, inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { const proxy = this._getCustomInspectProxy(); - return \\"Document \\" + inspect(proxy, options); + return \\"Announce \\" + inspect(proxy, options); }; // deno-lint-ignore no-explicit-any -(Document.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = +(Announce.prototype as any)[Symbol.for(\\"nodejs.util.inspect.custom\\")] = function ( - this: Document, + this: Announce, _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); - return \\"Document \\" + inspect(proxy, options); + return \\"Announce \\" + inspect(proxy, options); }; - /** Represents an audio document of any kind. + /** Describes a software application. */ -export class Audio extends Document { +export class Application extends Object { /** - * The type URI of {@link Audio}: \`https://www.w3.org/ns/activitystreams#Audio\`. + * The type URI of {@link Application}: \`https://www.w3.org/ns/activitystreams#Application\`. */ static override get typeId(): URL { - return new URL(\\"https://www.w3.org/ns/activitystreams#Audio\\"); + return new URL(\\"https://www.w3.org/ns/activitystreams#Application\\"); } - - /** - * Constructs a new instance of Audio with the given values. - * @param values The values to initialize the instance with. - * @param options The options to use for initialization. - */ - constructor( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;width?: number | null;height?: number | null;} -, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - } = {}, - ) { - super(values, options);} + #_3isuDgRAKSntq9XdbjiNxjwyPZAf_preferredUsername: ((string | LanguageString))[] = []; - /** - * Clones this instance, optionally updating it with the given values. - * @param values The values to update the clone with. - * @param options The options to use for cloning. - * @returns The cloned instance. - */ - override clone( - values: - { -id?: URL | null; -attachments?: (Object | Link | PropertyValue | URL)[];attribution?: Application | Group | Organization | Person | Service | URL | null; -attributions?: (Application | Group | Organization | Person | Service | URL)[];audience?: Object | URL | null; -audiences?: (Object | URL)[];content?: string | LanguageString | null; -contents?: ((string | LanguageString))[];contexts?: (Object | Link | URL)[];name?: string | LanguageString | null; -names?: ((string | LanguageString))[];endTime?: Temporal.Instant | null;generators?: (Object | Link | URL)[];icon?: Image | URL | null; -icons?: (Image | URL)[];image?: Image | URL | null; -images?: (Image | URL)[];replyTarget?: Object | Link | URL | null; -replyTargets?: (Object | Link | URL)[];location?: Object | Link | URL | null; -locations?: (Object | Link | URL)[];preview?: Link | Object | URL | null; -previews?: (Link | Object | URL)[];published?: Temporal.Instant | null;replies?: Collection | URL | null;shares?: Collection | URL | null;likes?: Collection | URL | null;emojiReactions?: Collection | URL | null;startTime?: Temporal.Instant | null;summary?: string | LanguageString | null; -summaries?: ((string | LanguageString))[];tags?: (Object | Link | URL)[];updated?: Temporal.Instant | null;url?: URL | Link | null; -urls?: ((URL | Link))[];to?: Object | URL | null; -tos?: (Object | URL)[];bto?: Object | URL | null; -btos?: (Object | URL)[];cc?: Object | URL | null; -ccs?: (Object | URL)[];bcc?: Object | URL | null; -bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;source?: Source | null;proof?: DataIntegrityProof | URL | null; -proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | null;approvedBy?: URL | null;likeAuthorization?: LikeAuthorization | URL | null;replyAuthorization?: ReplyAuthorization | URL | null;announceAuthorization?: AnnounceAuthorization | URL | null;width?: number | null;height?: number | null;} + #_axq166E2eZADq34V4MYUc8KMZdC_publicKey: (CryptographicKey | URL)[] = []; + #_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey: Set = new Set(); + + #_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod: (Multikey | URL)[] = []; + #_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod: Set = new Set(); + #_36QNc9MxfkKf6h8sEUQSHnV9NZA_manuallyApprovesFollowers: (boolean)[] = []; - = {}, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - } = {} - ): Audio { - if (this._warning != null) { - getLogger(this._warning.category).warn( - this._warning.message, - this._warning.values - ); - // @ts-ignore: \$warning is not recognized as a property, but it is. - options = { ...options, \$warning: this._warning }; - } - const clone = super.clone(values, options) as unknown as Audio; - return clone; - } - - /** - * Converts this object to a JSON-LD structure. - * @param options The options to use. - * - \`format\`: The format of the output: \`compact\` or - \`expand\`. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`context\`: The JSON-LD context to use. Not applicable - when \`format\` is set to \`'expand'\`. - * @returns The JSON-LD representation of this object. - */ - override async toJsonLd(options: { - format?: \\"compact\\" | \\"expand\\", - contextLoader?: DocumentLoader, - context?: string | Record | (string | Record)[], - } = {}): Promise { - if (options.format == null && this._cachedJsonLd != null) { - return this._cachedJsonLd; - } - if (options.format !== \\"compact\\" && options.context != null) { - throw new TypeError( - \\"The context option can only be used when the format option is set \\" + - \\"to 'compact'.\\" - ); - } - options = { - ...options, - contextLoader: options.contextLoader ?? getDocumentLoader(), - }; - - if (options.format == null && this.isCompactable()) { + #_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox: (OrderedCollection | OrderedCollectionPage | URL)[] = []; + #_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox: Set = new Set(); - const result = await super.toJsonLd({ - ...options, - format: undefined, - context: undefined, - }) as Record; - - // deno-lint-ignore no-unused-vars - let compactItems: unknown[]; + #_41QwhqJouoLg3h8dRPKat21brynC_outbox: (OrderedCollection | OrderedCollectionPage | URL)[] = []; + #_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox: Set = new Set(); - result[\\"type\\"] = \\"Audio\\"; - if (this.id != null) result[\\"id\\"] = formatIri(this.id); - result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; - return result; - } + #_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following: (Collection | URL)[] = []; + #_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following: Set = new Set(); - // deno-lint-ignore no-unused-vars prefer-const - let array: unknown[]; - - const baseValues = await super.toJsonLd({ - ...options, - format: \\"expand\\", - context: undefined, - }) as unknown[]; - const values = baseValues[0] as Record< - string, - unknown[] | { \\"@list\\": unknown[] } | string - >; + #_BBCTgfphhsFzpVfKTykGSpBNwoA_followers: (Collection | URL)[] = []; + #_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers: Set = new Set(); - values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Audio\\"]; - if (this.id != null) values[\\"@id\\"] = formatIri(this.id); - if (options.format === \\"expand\\") { - return await jsonld.expand( - values, - { documentLoader: options.contextLoader }, - ); - } - const docContext = options.context ?? - [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; - const compacted = await jsonld.compact( - values, - docContext, - { documentLoader: options.contextLoader }, - ); - if (docContext != null) { - // Embed context - - if (\\"proof\\" in compacted && - compacted.proof != null) { - if (Array.isArray(compacted.proof)) { - for (const element of compacted.proof) { - element[\\"@context\\"] = docContext; - } - } else { - compacted.proof[\\"@context\\"] = docContext; - } - } - - } - return compacted; - } - - protected override isCompactable(): boolean { - - return super.isCompactable(); - } - - /** - * Converts a JSON-LD structure to an object of this type. - * @param json The JSON-LD structure to convert. - * @param options The options to use. - * - \`documentLoader\`: The loader for remote JSON-LD documents. - * - \`contextLoader\`: The loader for remote JSON-LD contexts. - * - \`tracerProvider\`: The OpenTelemetry tracer provider to use. - * If omitted, the global tracer provider is used. - * @returns The object of this type. - * @throws {TypeError} If the given \`json\` is invalid. - */ - static override async fromJsonLd( - json: unknown, - options: { - documentLoader?: DocumentLoader, - contextLoader?: DocumentLoader, - tracerProvider?: TracerProvider, - baseUrl?: URL, - } = {}, - ): Promise