Loading CHANGES.md +17 −0 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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 ------------- Loading codegen/__snapshots__/class.test.ts.snap +878 −423 File changed.Preview size limit exceeded, changes collapsed. Show changes codegen/codec.ts +11 −13 Original line number Diff line number Diff line Loading @@ -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 ` Loading @@ -128,7 +127,6 @@ export async function* generateDecoder( } } `; } if (type.extends == null) { yield ` const instance = new this({ Loading examples/actor-lookup-cli/main.ts +17 −0 Original line number Diff line number Diff line Loading @@ -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"; Loading @@ -15,6 +16,7 @@ export interface Actor { following: number | null; followers: number | null; posts: number | null; properties: Record<string, string>; joined: Temporal.Instant | null; } Loading @@ -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, Loading @@ -43,6 +53,7 @@ async function lookupActor(handle: string): Promise<Actor> { following: following?.totalItems, followers: followers?.totalItems, posts: posts?.totalItems, properties, joined: actor.published, }; } Loading @@ -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() { Loading federation/handler.test.ts +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
CHANGES.md +17 −0 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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 ------------- Loading
codegen/__snapshots__/class.test.ts.snap +878 −423 File changed.Preview size limit exceeded, changes collapsed. Show changes
codegen/codec.ts +11 −13 Original line number Diff line number Diff line Loading @@ -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 ` Loading @@ -128,7 +127,6 @@ export async function* generateDecoder( } } `; } if (type.extends == null) { yield ` const instance = new this({ Loading
examples/actor-lookup-cli/main.ts +17 −0 Original line number Diff line number Diff line Loading @@ -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"; Loading @@ -15,6 +16,7 @@ export interface Actor { following: number | null; followers: number | null; posts: number | null; properties: Record<string, string>; joined: Temporal.Instant | null; } Loading @@ -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, Loading @@ -43,6 +53,7 @@ async function lookupActor(handle: string): Promise<Actor> { following: following?.totalItems, followers: followers?.totalItems, posts: posts?.totalItems, properties, joined: actor.published, }; } Loading @@ -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() { Loading
federation/handler.test.ts +3 −0 Original line number Diff line number Diff line Loading @@ -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