-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9ed0e9
commit 75e5ba9
Showing
52 changed files
with
7,692 additions
and
3,521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": true, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@napolab/alpha-blend": patch | ||
--- | ||
|
||
change config add sourcemap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"y-durableobjects": minor | ||
--- | ||
|
||
y-durableobjects publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
example | ||
node_modules | ||
.turbo | ||
pnpm-lock.yaml | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
extends: ["@naporin0624/eslint-config"], | ||
parserOptions: { | ||
project: "./tsconfig.eslint.json", | ||
}, | ||
rules: { | ||
"no-restricted-imports": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: PR Checks | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
type-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: "package.json" | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm i | ||
|
||
- name: Type Check | ||
run: pnpm run typecheck | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: "package.json" | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm i | ||
|
||
- name: Lint | ||
run: pnpm run lint | ||
|
||
publint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: "package.json" | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm i | ||
|
||
- name: Build | ||
run: pnpm run build | ||
|
||
- name: Publint | ||
run: pnpm run publint | ||
|
||
concurrency: | ||
group: pr-${{ github.head_ref }} | ||
cancel-in-progress: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: "package.json" | ||
cache: "pnpm" | ||
|
||
- name: Install Dependencies | ||
run: pnpm i | ||
|
||
- name: Build | ||
run: | | ||
pnpm run build | ||
pnpm run publint | ||
- name: Create Release Pull Request | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
publish: pnpm run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
example | ||
node_modules | ||
.turbo | ||
pnpm-lock.yaml | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,127 @@ | ||
# Yjs on Cloudflare Workers with Durable Objects Demo | ||
|
||
This project demonstrates the integration of Yjs, a real-time collaboration framework, with Cloudflare Workers using Durable Objects, eliminating the dependency on Node.js. This setup is inspired by the `y-websocket` adapter and aims to provide a scalable and efficient solution for real-time collaborative applications. | ||
# y-durableobjects | ||
|
||
[![Yjs on Cloudflare Workers with Durable Objects Demo Movie](https://i.gyazo.com/e94637740dbb11fc5107b0cd0850326d.gif)](https://gyazo.com/e94637740dbb11fc5107b0cd0850326d) | ||
|
||
Demo: https://yjs.napochaan.dev/ | ||
The `y-durableobjects` library is designed to facilitate real-time collaboration in Cloudflare Workers environment using Yjs and Durable Objects. It provides a straightforward way to integrate Yjs for decentralized, scalable real-time editing features. | ||
|
||
## Getting Started | ||
## Installation | ||
|
||
To get the demo running on your local environment, follow these steps: | ||
To use `y-durableobjects`, you need to install the package along with `hono`, as it is a peer dependency. | ||
|
||
### Prerequisites | ||
```bash | ||
npm install y-durableobjects hono | ||
``` | ||
|
||
Ensure you have the latest version of Node.js installed on your machine. | ||
or using yarn: | ||
|
||
### Installation | ||
```bash | ||
yarn add y-durableobjects hono | ||
``` | ||
|
||
Clone the repository and install the dependencies: | ||
or pnpm: | ||
|
||
```bash | ||
git clone https://github.com/napolab/yjs-worker | ||
cd yjs-worker | ||
npm install | ||
pnpm add y-durableobjects hono | ||
``` | ||
|
||
### Running the UI | ||
Below is an updated section for your README, including the recommended `wrangler.toml` configuration for Durable Objects, followed by the new section providing guidance on configuring Durable Objects: | ||
|
||
Navigate to the UI application directory and start the development server: | ||
--- | ||
|
||
```bash | ||
cd apps/web | ||
npm run dev | ||
## Configuring Durable Objects | ||
|
||
To use Durable Objects with `y-durableobjects`, include the following configuration in your `wrangler.toml` file. This setup is essential for defining the Durable Object bindings that your Cloudflare Worker will use. | ||
|
||
```toml | ||
name = "your-worker-name" | ||
main = "index.js" | ||
compatibility_date = "2021-10-01" | ||
|
||
account_id = "your-account-id" | ||
workers_dev = true | ||
route = "" | ||
zone_id = "" | ||
|
||
# Durable Objects binding | ||
[durable_objects] | ||
bindings = [ | ||
{ name = "Y_DURABLE_OBJECTS", class_name = "YDurableObjects" } | ||
] | ||
|
||
# Add your KV Namespaces and other bindings here | ||
# [kv_namespaces] | ||
# ... | ||
|
||
# Your environment variables | ||
# [vars] | ||
# ... | ||
``` | ||
|
||
This command will serve the UI on a local web server. Open your preferred web browser and navigate to the provided URL to interact with the UI. | ||
### Configuration for Durable Objects | ||
|
||
### Running the Server | ||
To properly utilize Durable Objects, you need to configure bindings in your `wrangler.toml` file. This involves specifying the name of the Durable Object binding and the class name that represents your Durable Object. For detailed instructions on how to set up your `wrangler.toml` for Durable Objects, including setting up environment variables and additional resources, refer to [Cloudflare's Durable Objects documentation](https://developers.cloudflare.com/durable-objects/get-started/#5-configure-durable-object-bindings). | ||
|
||
To start the server that includes the Cloudflare Worker with Durable Objects: | ||
This configuration ensures that your Cloudflare Worker can correctly instantiate and interact with Durable Objects, allowing `y-durableobjects` to manage real-time collaboration sessions. | ||
|
||
```bash | ||
cd apps/workers | ||
npm run dev | ||
## Extending Hono with Bindings | ||
|
||
To integrate `y-durableobjects` with Hono, extend the `Env` interface to include the `Bindings` type for better type safety and IntelliSense support in your editor. | ||
|
||
```typescript | ||
export type Bindings = { | ||
Y_DURABLE_OBJECTS: DurableObjectNamespace; | ||
}; | ||
|
||
declare module "hono" { | ||
interface Env { | ||
Bindings: Bindings; | ||
} | ||
} | ||
``` | ||
|
||
This will emulate the Cloudflare Worker environment locally, allowing you to test the Yjs integration. | ||
This allows you to use `Y_DURABLE_OBJECTS` directly in your Hono application with full type support. | ||
|
||
## Usage | ||
|
||
## Future Plans | ||
### With Hono shorthand | ||
|
||
- Implement ping/pong and describe behavior on close to ensure stable connections. | ||
- Improve the demo using Lexical for a more robust real-time collaborative editing experience. | ||
```typescript | ||
import { Hono } from "hono"; | ||
import { cors } from "hono/cors"; | ||
import { YDurableObjects, yRoute } from "y-durableobjects"; | ||
|
||
Contributions and feedback are welcome as we continue to enhance the capabilities of this demo. | ||
const app = new Hono<Env>(); | ||
app.use("*", cors()); | ||
|
||
const route = app.route( | ||
"/editor", | ||
yRoute((env) => env.Y_DURABLE_OBJECTS), | ||
); | ||
|
||
export default route; | ||
export { YDurableObjects }; | ||
``` | ||
|
||
### Without the shorthand | ||
|
||
```typescript | ||
import { Hono } from "hono"; | ||
import { cors } from "hono/cors"; | ||
import { YDurableObjects } from "y-durableobjects"; | ||
|
||
const app = new Hono<Env>(); | ||
app.use("*", cors()); | ||
app.get("/editor/:id", async (c) => { | ||
const id = c.env.Y_DURABLE_OBJECTS.idFromName(c.req.param("id")); | ||
const obj = c.env.Y_DURABLE_OBJECTS.get(id); | ||
|
||
// get websocket connection | ||
const url = new URL("/", c.req.url); | ||
const res = await obj.fetch(url.href, { | ||
headers: c.req.raw.headers, | ||
}); | ||
if (res.webSocket === null) return c.body(null, 500); | ||
|
||
return new Response(null, { webSocket: res.webSocket, status: res.status }); | ||
}); | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.