latest
fedify-dev/fedifyWorks with
•JSR Score100%•This package works with Cloudflare Workers, Node.js, Deno, Bun



License
•MIT
Downloads444/wk
•Published6 hours ago (2.3.2)
Vocabularies library for Fedify
@fedify/vocab: ActivityPub vocabulary for Fedify
This package provides a collection of type-safe objects that represent the Activity Vocabulary and vendor-specific extensions for the Fedify framework. It is the core vocabulary library that powers ActivityPub object handling in Fedify applications.
Features
- Type-safe objects for Activity Vocabulary types (
Create,Note,Person, etc.) - Vendor-specific extensions (Mastodon, Misskey, etc.)
- JSON-LD serialization and deserialization
- Immutable object design with
clone()method for modifications - Support for looking up remote objects
- Actor handle resolution via WebFinger
Installation
deno add jsr:@fedify/vocab # Deno npm add @fedify/vocab # npm pnpm add @fedify/vocab # pnpm yarn add @fedify/vocab # Yarn bun add @fedify/vocab # Bun
Usage
Instantiation
You can instantiate an object by calling the constructor with properties:
import { Create, Note } from "@fedify/vocab"; const create = new Create({ id: new URL("https://example.com/activities/123"), actor: new URL("https://example.com/users/alice"), object: new Note({ id: new URL("https://example.com/notes/456"), content: "Hello, world!", }), });
JSON-LD serialization
Deserialize from JSON-LD:
import { Create } from "@fedify/vocab"; const create = await Create.fromJsonLd({ "@context": "https://www.w3.org/ns/activitystreams", "type": "Create", "id": "https://example.com/activities/123", "actor": "https://example.com/users/alice", "object": { "type": "Note", "id": "https://example.com/notes/456", "content": "Hello, world!", } });
Serialize to JSON-LD:
const jsonLd = await create.toJsonLd();
Immutability
All objects are immutable. Use clone() to create modified copies:
import { Note } from "@fedify/vocab"; import { LanguageString } from "@fedify/vocab-runtime"; const noteInEnglish = new Note({ id: new URL("https://example.com/notes/123"), content: new LanguageString("Hello, world!", "en"), }); const noteInChinese = noteInEnglish.clone({ content: new LanguageString("你好,世界!", "zh"), });
Looking up remote objects
import { lookupObject } from "@fedify/vocab"; const object = await lookupObject("https://example.com/users/alice");
Documentation
For comprehensive documentation, please refer to:
Related packages
- @fedify/fedify: The main Fedify framework
- @fedify/vocab-runtime: Runtime utilities for vocabulary objects
- @fedify/vocab-tools: Code generation tools for Activity Vocabulary
License
Add Package
deno add jsr:@fedify/vocab
Import symbol
import * as vocab from "@fedify/vocab";
Import directly with a jsr specifier
import * as vocab from "jsr:@fedify/vocab";