Unverified Commit 12a69dc0 authored by Hong Minhee's avatar Hong Minhee
Browse files

Add PropertyValue to Activity Vocabulary API

parent 46f77429
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -45,6 +45,22 @@ To be released.
     -  Added `DenoKvStore` class.
     -  Added `DenoKvMessageQueue` class.

 -  Added `PropertyValue` to Activity Vocabulary API.  [[#29]]

     -  Added `PropertyValue` class.
     -  `new Object()` constructor's `attachments` option now accepts
        `PropertyValue` objects.
     -  `new Object()` constructor's `attachment` option now accepts
        a `PropertyValue` object.
     -  `Object.getAttachments()` method now yields `PropertyValue` objects
        besides `Object` and `Link` objects.
     -  `Object.getAttachment()` method now returns a `PropertyValue` object
        besides an `Object` and a `Link` object.
     -  `Object.clone()` method's `attachments` option now accepts
        `PropertyValue` objects.
     -  `Object.clone()` method's `attachment` option now accepts
        a `PropertyValue` object.

 -  Removed dependency on *jose*.

     -  Added `exportSpki()` function.
@@ -52,6 +68,7 @@ To be released.

[@fedify/fedify]: https://www.npmjs.com/package/@fedify/fedify
[#24]: https://github.com/dahlia/fedify/discussions/24
[#29]: https://github.com/dahlia/fedify/issues/29

Version 0.4.0
-------------
+878 −423

File changed.

Preview size limit exceeded, changes collapsed.

+11 −13
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ export async function* generateDecoder(
    }
  `;
  const subtypes = getSubtypes(typeUri, types, true);
  if (subtypes.length > 0) {
  yield 'if ("@type" in values) {\n';
  for (const subtypeUri of subtypes) {
    yield `
@@ -128,7 +127,6 @@ export async function* generateDecoder(
    }
  }
  `;
  }
  if (type.extends == null) {
    yield `
    const instance = new this({
+17 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import {
  getActorHandle,
  isActor,
  lookupObject,
  PropertyValue,
} from "@fedify/fedify/vocab";
import { Temporal } from "@js-temporal/polyfill";
import { convert } from "npm:html-to-text@^9.0.5";
@@ -15,6 +16,7 @@ export interface Actor {
  following: number | null;
  followers: number | null;
  posts: number | null;
  properties: Record<string, string>;
  joined: Temporal.Instant | null;
}

@@ -33,6 +35,14 @@ async function lookupActor(handle: string): Promise<Actor> {
  try {
    posts = await actor.getOutbox();
  } catch (_) {}
  const properties: Record<string, string> = {};
  for await (const attachment of actor.getAttachments()) {
    if (attachment instanceof PropertyValue && attachment.name != null) {
      properties[attachment.name] = convert(attachment.value ?? "", {
        selectors: [{ selector: "a", options: { ignoreHref: true } }],
      });
    }
  }
  return {
    handle: await getActorHandle(actor),
    url: actor.url,
@@ -43,6 +53,7 @@ async function lookupActor(handle: string): Promise<Actor> {
    following: following?.totalItems,
    followers: followers?.totalItems,
    posts: posts?.totalItems,
    properties,
    joined: actor.published,
  };
}
@@ -58,6 +69,12 @@ function displayActor(actor: Actor): void {
  if (actor.following) console.log(`Following: ${actor.following}`);
  if (actor.followers) console.log(`Followers: ${actor.followers}`);
  if (actor.posts) console.log(`Posts: ${actor.posts}`);
  if (Object.keys(actor.properties).length > 0) {
    console.log();
    for (const name in actor.properties) {
      console.log(`${name}: ${actor.properties[name]}`);
    }
  }
}

async function main() {
+3 −0
Original line number Diff line number Diff line
@@ -133,6 +133,9 @@ Deno.test("handleActor()", async () => {
        memorial: "toot:memorial",
        suspended: "toot:suspended",
        toot: "http://joinmastodon.org/ns#",
        schema: "http://schema.org#",
        PropertyValue: "schema:PropertyValue",
        value: "schema:value",
      },
    ],
    id: "https://example.com/users/someone",
Loading