Socket
Socket
Sign inDemoInstall

@liveblocks/yjs

Package Overview
Dependencies
Maintainers
6
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liveblocks/yjs - npm Package Compare versions

Comparing version 1.1.1-yjs1 to 1.1.1-yjs2

dist/index.d.mts

19

dist/index.d.ts

@@ -5,5 +5,2 @@ import { Room, JsonObject, LsonObject, BaseUserMeta, Json } from '@liveblocks/client';

declare type LiveblocksYjsOptions = {
httpEndpoint?: string;
};
declare type MetaClientState = {

@@ -14,12 +11,12 @@ clock: number;

/**
* This class will store YJS awareness in Liveblock's presence under the __yjs key
* IMPORTANT: The yjs awareness protocol uses ydoc.clientId to reference users
* to their respective documents. To avoid mapping yjs clientIds to liveblock's connectionId,
* This class will store Yjs awareness in Liveblock's presence under the __yjs key
* IMPORTANT: The Yjs awareness protocol uses ydoc.clientId to reference users
* to their respective documents. To avoid mapping Yjs clientIds to liveblock's connectionId,
* we simply set the clientId of the doc to the connectionId. Then no further mapping is required
*/
declare class Awareness extends Observable<any> {
declare class Awareness extends Observable<unknown> {
private room;
doc: Y.Doc;
clientID: number;
states: Map<number, any>;
states: Map<number, unknown>;
meta: Map<number, MetaClientState>;

@@ -33,3 +30,3 @@ _checkInterval: number;

setLocalStateField(field: string, value: JsonObject | null): void;
getStates(): Map<number, any>;
getStates(): Map<number, unknown>;
}

@@ -39,10 +36,8 @@ declare class LiveblocksProvider<P extends JsonObject, S extends LsonObject, U extends BaseUserMeta, E extends Json> {

private httpEndpoint?;
private lastUpdateDate;
private doc;
private unsubscribers;
awareness: Awareness;
constructor(room: Room<P, S, U, E>, doc: Y.Doc, config?: LiveblocksYjsOptions);
constructor(room: Room<P, S, U, E>, doc: Y.Doc);
private syncDoc;
private updateHandler;
private resyncHttp;
destroy(): void;

@@ -49,0 +44,0 @@ }

@@ -113,2 +113,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var __defProp = Object.defineProperty;

var _yjs = require('yjs'); var Y = _interopRequireWildcard(_yjs);
var Y_PRESENCE_KEY = "__yjs";
var Awareness = class extends Observable {

@@ -122,3 +123,3 @@ constructor(doc, room) {

// _checkInterval this would hold a timer to remove users, but Liveblock's presence already handles this
// unfortunately it's expected to exist by various integrations.
// unfortunately it's typed by various integrations
this._checkInterval = 0;

@@ -157,10 +158,10 @@ this.doc = doc;

const presence = this.room.getPresence();
if (Object.keys(this.room.getPresence()).length === 0) {
if (Object.keys(presence).length === 0 || typeof presence[Y_PRESENCE_KEY] === "undefined") {
return null;
}
return presence["__yjs"];
return presence[Y_PRESENCE_KEY];
}
setLocalState(state) {
var _a;
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence["__yjs"];
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence[Y_PRESENCE_KEY];
this.room.updatePresence({

@@ -172,3 +173,3 @@ __yjs: __spreadValues(__spreadValues({}, presence || {}), state || {})

var _a;
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence["__yjs"];
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence[Y_PRESENCE_KEY];
const update = { [field]: value };

@@ -186,3 +187,3 @@ this.room.updatePresence({

currentValue.connectionId,
currentValue.presence["__yjs"] || {}
currentValue.presence[Y_PRESENCE_KEY] || {}
);

@@ -196,4 +197,3 @@ }

var LiveblocksProvider = class {
constructor(room, doc, config) {
this.lastUpdateDate = null;
constructor(room, doc) {
this.unsubscribers = [];

@@ -205,3 +205,3 @@ this.syncDoc = () => {

const encodedVector = _jsbase64.Base64.fromUint8Array(Y.encodeStateVector(this.doc));
this.room.getYDoc(encodedVector);
this.room.fetchYDoc(encodedVector);
};

@@ -230,4 +230,4 @@ this.updateHandler = (update, origin) => __async(this, null, function* () {

this.unsubscribers.push(
this.room.events.connection.subscribe((e) => {
if (e === "open") {
this.room.events.status.subscribe((status) => {
if (status === "connected") {
this.syncDoc();

@@ -238,36 +238,8 @@ }

this.unsubscribers.push(
this.room.events.docUpdated.subscribe((update) => {
this.room.events.ydoc.subscribe((update) => {
Y.applyUpdate(this.doc, _jsbase64.Base64.toUint8Array(update), "backend");
})
);
if (config == null ? void 0 : config.httpEndpoint) {
this.httpEndpoint = config.httpEndpoint + "?room=" + this.room.id;
this.unsubscribers.push(
this.room.events.customEvent.subscribe(({ event }) => {
if ((event == null ? void 0 : event.type) === "REFRESH") {
void this.resyncHttp();
}
})
);
void this.resyncHttp();
}
this.syncDoc();
}
resyncHttp() {
return __async(this, null, function* () {
if (!this.httpEndpoint) {
return;
}
const response = yield fetch(
`${this.httpEndpoint}${this.lastUpdateDate !== null ? `&after=${this.lastUpdateDate.toISOString()}` : ""}`
);
const { updates, lastUpdate } = yield response.json();
if (updates.length === 0) {
return;
}
this.lastUpdateDate = new Date(lastUpdate);
const update = Y.mergeUpdates(updates.map(_jsbase64.Base64.toUint8Array));
Y.applyUpdate(this.doc, update, "backend");
});
}
destroy() {

@@ -274,0 +246,0 @@ this.doc.off("update", this.updateHandler);

{
"name": "@liveblocks/yjs",
"version": "1.1.1-yjs1",
"version": "1.1.1-yjs2",
"description": "An integration with . Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",

@@ -14,5 +14,6 @@ "license": "Apache-2.0",

"dev": "tsup --watch",
"build": "tsup --format cjs,esm --dts --clean",
"build": "tsup && cp dist/index.d.ts dist/index.d.mts",
"format": "eslint --fix src/; prettier --write src/",
"lint": "eslint src/",
"lint:package": "publint --strict && attw /tmp/$( npm pack -q --pack-destination /tmp )",
"test": "jest --silent --verbose --color=always",

@@ -24,10 +25,15 @@ "test:types": "tsd",

".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"dependencies": {
"@liveblocks/client": "1.1.1-yjs1",
"@liveblocks/core": "1.1.1-yjs1",
"@liveblocks/client": "1.1.1-yjs2",
"@liveblocks/core": "1.1.1-yjs2",
"js-base64": "^3.7.5"

@@ -34,0 +40,0 @@ },

@@ -12,3 +12,3 @@ <p align="center">

Provides YJS integration to effortlessly back your YJS apps with Liveblocks
Provides Yjs integration to effortlessly back your Yjs apps with Liveblocks

@@ -15,0 +15,0 @@ ## Installation

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc