Closed naporin0624 closed 3 months ago
Latest commit: 4b6afef618b719effd0655a16a4e45326e692ea5
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Latest commit: |
4b6afef
|
Status: | ✅ Deploy successful! |
Preview URL: | https://f9f3aef5.yjs-worker.pages.dev |
Branch Preview URL: | https://feat-add-y-doc-handle-method.yjs-worker.pages.dev |
File | Before | After |
---|---|---|
dist/chunk-44JZXIF7.js |
— | 379 B |
dist/chunk-44JZXIF7.js.map |
— | 784 B |
dist/chunk-GLWCU3YD.cjs |
— | 473 B |
dist/chunk-GLWCU3YD.cjs.map |
— | 783 B |
dist/helpers/upgrade.cjs |
— | 216 B |
dist/helpers/upgrade.cjs.map |
— | 51 B |
dist/helpers/upgrade.d.cts |
— | 273 B |
dist/helpers/upgrade.d.ts |
— | 273 B |
dist/helpers/upgrade.js |
— | 107 B |
dist/helpers/upgrade.js.map |
— | 71 B |
dist/index.cjs |
11.3 kB |
6%↑12.0 kB |
dist/index.cjs.map |
20.9 kB |
7%↑22.2 kB |
dist/index.d.cts |
2.2 kB |
114%↑4.7 kB |
dist/index.d.ts |
2.2 kB |
114%↑4.7 kB |
dist/index.js |
9.9 kB |
6%↑10.5 kB |
dist/index.js.map |
21.0 kB |
7%↑22.4 kB |
package.json |
2.0 kB |
18%↑2.4 kB |
README.md |
5.0 kB |
58%↑7.8 kB |
Total (Includes all files) | 75.6 kB |
21%↑91.3 kB |
Tarball size | 15.3 kB |
22%↑18.7 kB |
🤖 This report was automatically generated by pkg-size-action
Hi, @tobimori
I have pre-released an enhanced version of y-durableobjects with JSRPC added. It is available from https://pkg.pr.new/napolab/y-durableobjects@50
so please try it out and let me know what you think.
If it seems to be working well, I will release it.
Usage including fetch (https://github.com/napolab/y-durableobjects/blob/6c2063d8b5745cab03c47d6f01fe6a70a7146868/src/e2e/e2e.test.ts)
getYDoc
API to get YDoc as Uint8Array
app.get("/rooms/:id/state", async (c) => {
const roomId = c.req.param("id");
const id = c.env.Y_DURABLE_OBJECTS.idFromName(roomId);
const stub = c.env.Y_DURABLE_OBJECTS.get(id);
const doc = await stub.getYDoc();
const base64 = fromUint8Array(doc);
return c.json({ doc: base64 }, 200);
});
updateYDoc
API for updating YDoc from Uint8Array
app.post("/rooms/:id/update", async (c) => {
const roomId = c.req.param("id");
const id = c.env.Y_DURABLE_OBJECTS.idFromName(roomId);
const stub = c.env.Y_DURABLE_OBJECTS.get(id);
const buffer = await c.req.arrayBuffer();
const update = new Uint8Array(buffer);
await stub.updateYDoc(update);
return c.json(null, 200);
});
Partial support: https://github.com/napolab/y-durableobjects/pull/20
closed: #49 closed: #46
This PR introduces several significant updates to the
y-durableobjects
library, with a major focus on adding new JS RPC support forgetYDoc
andupdateYDoc
APIs. These enhancements significantly improve the library's functionality and ease of integration with Hono. Key changes include:Major Features:
getYDoc
andupdateYDoc
:getYDoc
) and update (updateYDoc
) YDocs within Durable Objects.Hono Integration:
y-durableobjects
with Hono, using both shorthand and detailed methods.Extending with JS RPC:
y-durableobjects
for advanced operations, including accessing and manipulating protected fields:app
: The Hono app instance used to handle requests.doc
: An instance ofWSSharedDoc
managing the YDoc state.storage
: AYTransactionStorageImpl
instance for storing and retrieving YDoc updates.sessions
: A map to manage active WebSocket sessions.awarenessClients
: A set to track client awareness states.YDurableObjects
.Client-side Typed Fetch with Hono RPC:
hc
fromhono/client
to facilitate Hono RPC on the client side.Documentation Updates:
These enhancements aim to provide developers with more robust tools and clearer guidance for integrating Yjs and Durable Objects within the Cloudflare Workers environment, leveraging the power of Hono for efficient and scalable real-time collaboration solutions.