Commit 92d31874 authored by ChanHaeng Lee's avatar ChanHaeng Lee
Browse files

Added README.md for new packages

parent d78d0c62
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
<!-- deno-fmt-ignore-file -->

@fedify/cfworkers: Adapt Fedify with Cloudflare Workers
======================================================

[![JSR][JSR badge]][JSR]
[![npm][npm badge]][npm]
[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]

*This package is available since Fedify 1.9.0.*

This package provides [Fedify]'s [`KvStore`] and [`MessageQueue`]
implementations for [Cloudflare Workers]:

 -  [`WorkersKvStore`]
 -  [`WorkersMessageQueue`]

~~~~ typescript
import type { Federation } from "@fedify/fedify";
import { WorkersKvStore, WorkersMessageQueue } from "@fedify/cfworkers";

export default {
  async fetch(request, env, ctx) {
    const federation = createFederation({
      kv: new WorkersKvStore(env.KV_BINDING),
      queue: new WorkersMessageQueue(env.QUEUE_BINDING),
      // ... other options
    });
    
    return federation.handle(request, { contextData: env });
  },
  
  async queue(batch, env, ctx) {
    const federation = createFederation({
      kv: new WorkersKvStore(env.KV_BINDING),
      queue: new WorkersMessageQueue(env.QUEUE_BINDING),
      // ... other options
    });
    
    for (const message of batch.messages) {
      await federation.processQueuedTask(message.body);
    }
  }
} satisfies ExportedHandler<{ 
  KV_BINDING: KVNamespace<string>;
  QUEUE_BINDING: Queue;
}>;
~~~~

`WorkersKvStore`
----------------

`WorkersKvStore` is a key–value store implementation for [Cloudflare Workers]
that uses Cloudflare's built-in [Cloudflare Workers KV] API.  It provides
persistent storage and good performance for Cloudflare Workers environments.
It's suitable for production use in Cloudflare Workers applications.

`WorkersMessageQueue`
---------------------

`WorkersMessageQueue` is a message queue implementation for [Cloudflare Workers]
that uses Cloudflare's built-in [Cloudflare Queues] API.  It provides
scalability and high performance, making it suitable for production use in
Cloudflare Workers environments.  It requires a Cloudflare Queues setup and
management.

> [!NOTE]
> Since your `KVNamespace` and `Queue` are not bound to global variables, but rather
> passed as arguments to the `fetch()` and `queue()` methods, you need to instantiate
> your `Federation` object inside these methods, rather than at the top level.
>
> For better organization, you probably want to use a builder pattern to
> register your dispatchers and listeners before instantiating the `Federation`
> object.

> [!NOTE]
> The [Cloudflare Queues] API does not provide a way to poll messages from
> the queue, so `WorkersMessageQueue.listen()` method always throws
> a `TypeError` when invoked.  Instead, you should define a `queue()` method
> in your Cloudflare worker, which will be called by the Cloudflare Queues
> API when new messages are available in the queue.  Inside the `queue()`
> method, you need to call `Federation.processQueuedTask()` method to manually
> process the messages.  The `queue()` method is the only way to consume
> messages from the queue in Cloudflare Workers.

Installation
------------

~~~~ sh
deno add jsr:@fedify/cfworkers  # Deno
npm  add     @fedify/cfworkers  # npm
pnpm add     @fedify/cfworkers  # pnpm
yarn add     @fedify/cfworkers  # Yarn
bun  add     @fedify/cfworkers  # Bun
~~~~

[JSR]: https://jsr.io/@fedify/cfworkers
[JSR badge]: https://jsr.io/badges/@fedify/cfworkers
[npm]: https://www.npmjs.com/package/@fedify/cfworkers
[npm badge]: https://img.shields.io/npm/v/@fedify/cfworkers?logo=npm
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
[@fedify@hollo.social]: https://hollo.social/@fedify
[Fedify]: https://fedify.dev/
[`KvStore`]: https://jsr.io/@fedify/fedify/doc/federation/~/KvStore
[`MessageQueue`]: https://jsr.io/@fedify/fedify/doc/federation/~/MessageQueue
[`WorkersKvStore`]: https://jsr.io/@fedify/cfworkers/doc/~/WorkersKvStore
[`WorkersMessageQueue`]: https://jsr.io/@fedify/cfworkers/doc/~/WorkersMessageQueue
[Cloudflare Workers]: https://workers.cloudflare.com/
[Cloudflare Workers KV]: https://developers.cloudflare.com/kv/
[Cloudflare Queues]: https://developers.cloudflare.com/queues/
+65 −0
Original line number Diff line number Diff line
<!-- deno-fmt-ignore-file -->

@fedify/denokv: Adapt Fedify with Deno KV
=========================================

[![JSR][JSR badge]][JSR]
[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]

*This package is available since Fedify 1.9.0.*

This package provides [Fedify]'s [`KvStore`] and [`MessageQueue`]
implementations for [Deno] runtime that uses Deno's built-in [`Deno.openKv()`] API:

 -  [`DenoKvStore`]
 -  [`DenoKvMessageQueue`]

~~~~ typescript
import { createFederation } from "@fedify/fedify";
import { DenoKvStore, DenoKvMessageQueue } from "@fedify/denokv";

const kv = await Deno.openKv();

const federation = createFederation({
  kv: new DenoKvStore(kv),
  queue: new DenoKvMessageQueue(kv),
  // ... other options
});
~~~~

`DenoKvStore`
-------------

`DenoKvStore` is a key–value store implementation for [Deno] runtime that uses
Deno's built-in [`Deno.openKv()`] API. It provides persistent storage and good
performance for Deno environments.  It's suitable for production use in Deno
applications.

`DenoKvMessageQueue`
--------------------

`DenoKvMessageQueue` is a message queue implementation for [Deno] runtime that
uses Deno's built-in [`Deno.openKv()`] API. It provides persistent storage and
good performance for Deno environments.  It's suitable for production use in
Deno applications.


Installation
------------

~~~~ sh
deno add jsr:@fedify/denokv  # Deno
~~~~


[JSR]: https://jsr.io/@fedify/denokv
[JSR badge]: https://jsr.io/badges/@fedify/denokv
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
[@fedify@hollo.social]: https://hollo.social/@fedify
[Fedify]: https://fedify.dev/
[`KvStore`]: https://jsr.io/@fedify/fedify/doc/federation/~/KvStore
[`MessageQueue`]: https://jsr.io/@fedify/fedify/doc/federation/~/MessageQueue
[`DenoKvStore`]: https://jsr.io/@fedify/denokv/doc/~/DenoKvStore
[`DenoKvMessageQueue`]: https://jsr.io/@fedify/denokv/doc/~/DenoKvMessageQueue
[Deno]: https://deno.com/
[`Deno.openKv()`]: https://docs.deno.com/api/deno/~/Deno.openKv
+65 −0
Original line number Diff line number Diff line
<!-- deno-fmt-ignore-file -->

@fedify/hono: Integrate Fedify with Hono
========================================

[![JSR][JSR badge]][JSR]
[![npm][npm badge]][npm]
[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]

*This package is available since Fedify 1.9.0.*

This package provides a simple way to integrate [Fedify] with [Hono].

The integration code looks like this:

~~~~ typescript
import { createFederation } from "@fedify/fedify";
import { federation } from "@fedify/hono";
import { Hono } from "hono";

const fedi = createFederation<string>({
  // Omitted for brevity; see the related section for details.
});

const app = new Hono();
app.use(federation(fedi, (ctx) => "context data"));
~~~~

How it works
------------

Fedify behaves as a middleware that wraps around the Hono request handler.
The middleware intercepts the incoming HTTP requests and dispatches them to
the appropriate handler based on the request path and the `Accept` header
(i.e., content negotiation).  This architecture allows Fedify and your Hono
application to coexist in the same domain and port.

For example, if you make a request to */.well-known/webfinger* Fedify will
handle the request by itself, but if you make a request to */users/alice*
(assuming your Hono app has a handler for `/users/:handle`) with `Accept:
text/html` header, Fedify will dispatch the request to the Hono app's
appropriate handler for `/users/:handle`.  Or if you define an actor dispatcher
for `/users/{handle}` in Fedify, and the request is made with `Accept:
application/activity+json` header, Fedify will dispatch the request to the
appropriate actor dispatcher.

Installation
------------

~~~~ sh
deno add jsr:@fedify/hono  # Deno
npm  add     @fedify/hono  # npm
pnpm add     @fedify/hono  # pnpm
yarn add     @fedify/hono  # Yarn
bun  add     @fedify/hono  # Bun
~~~~

[JSR]: https://jsr.io/@fedify/hono
[JSR badge]: https://jsr.io/badges/@fedify/hono
[npm]: https://www.npmjs.com/package/@fedify/hono
[npm badge]: https://img.shields.io/npm/v/@fedify/hono?logo=npm
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
[@fedify@hollo.social]: https://hollo.social/@fedify
[Fedify]: https://fedify.dev/
[Hono]: https://hono.dev/
+66 −0
Original line number Diff line number Diff line
<!-- deno-fmt-ignore-file -->

@fedify/sveltekit: Integrate Fedify with SvelteKit
==================================================

[![JSR][JSR badge]][JSR]
[![npm][npm badge]][npm]
[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]

*This package is available since Fedify 1.9.0.*

This package provides a simple way to integrate [Fedify] with [SvelteKit].

The integration code looks like this:

~~~~ typescript
import { createFederation } from "@fedify/fedify";
import { fedifyHook } from "@fedify/sveltekit";

const federation = createFederation<string>({
  // Omitted for brevity; see the related section for details.
});

// This is the entry point to the Fedify hook from the SvelteKit framework:
export const handle = fedifyHook(federation, (req) => "context data");
~~~~

Put the above code in your *hooks.server.ts* file.

How it works
------------

Fedify behaves as a hook handler that wraps around the SvelteKit request handler.
The hook intercepts the incoming HTTP requests and dispatches them to
the appropriate handler based on the request path and the `Accept` header
(i.e., content negotiation).  This architecture allows Fedify and your SvelteKit
application to coexist in the same domain and port.

For example, if you make a request to */.well-known/webfinger* Fedify will
handle the request by itself, but if you make a request to */users/alice*
(assuming your SvelteKit app has a handler for `/users/[handle]`) with `Accept:
text/html` header, Fedify will dispatch the request to the SvelteKit app's
appropriate handler for `/users/[handle]`.  Or if you define an actor dispatcher
for `/users/{handle}` in Fedify, and the request is made with `Accept:
application/activity+json` header, Fedify will dispatch the request to the
appropriate actor dispatcher.

Installation
------------

~~~~ sh
deno add jsr:@fedify/sveltekit  # Deno
npm  add     @fedify/sveltekit  # npm
pnpm add     @fedify/sveltekit  # pnpm
yarn add     @fedify/sveltekit  # Yarn
bun  add     @fedify/sveltekit  # Bun
~~~~

[JSR]: https://jsr.io/@fedify/sveltekit
[JSR badge]: https://jsr.io/badges/@fedify/sveltekit
[npm]: https://www.npmjs.com/package/@fedify/sveltekit
[npm badge]: https://img.shields.io/npm/v/@fedify/sveltekit?logo=npm
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
[@fedify@hollo.social]: https://hollo.social/@fedify
[Fedify]: https://fedify.dev/
[SvelteKit]: https://kit.svelte.dev/