Socket
Socket
Sign inDemoInstall

@liveblocks/client

Package Overview
Dependencies
Maintainers
4
Versions
388
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liveblocks/client - npm Package Compare versions

Comparing version 0.15.11 to 0.16.0

348

lib/index.d.ts
/**
* The LiveList class represents an ordered collection of items that is synchorinized across clients.
* Represents an indefinitely deep arbitrary JSON data structure. There are
* four types that make up the Json family:
*
* - Json any legal JSON value
* - JsonScalar any legal JSON leaf value (no lists or objects)
* - JsonArray a JSON value whose outer type is an array
* - JsonObject a JSON value whose outer type is an object
*
*/
declare class LiveList<T> extends AbstractCrdt {
declare type Json = JsonScalar | JsonArray | JsonObject;
declare type JsonScalar = string | number | boolean | null;
declare type JsonArray = Json[];
declare type JsonObject = {
[key: string]: Json;
};
/**
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
* Keys should be a string, and values should be serializable to JSON.
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
*/
declare class LiveMap<TKey extends string = string, TValue extends Lson = Lson> extends AbstractCrdt {
private _map;
constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
/**
* Returns a specified element from the LiveMap.
* @param key The key of the element to return.
* @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
*/
get(key: TKey): TValue | undefined;
/**
* Adds or updates an element with a specified key and a value.
* @param key The key of the element to add. Should be a string.
* @param value The value of the element to add. Should be serializable to JSON.
*/
set(key: TKey, value: TValue): void;
/**
* Returns the number of elements in the LiveMap.
*/
get size(): number;
/**
* Returns a boolean indicating whether an element with the specified key exists or not.
* @param key The key of the element to test for presence.
*/
has(key: TKey): boolean;
/**
* Removes the specified element by key.
* @param key The key of the element to remove.
* @returns true if an element existed and has been removed, or false if the element does not exist.
*/
delete(key: TKey): boolean;
/**
* Returns a new Iterator object that contains the [key, value] pairs for each element.
*/
entries(): IterableIterator<[TKey, TValue]>;
/**
* Same function object as the initial value of the entries method.
*/
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
/**
* Returns a new Iterator object that contains the keys for each element.
*/
keys(): IterableIterator<TKey>;
/**
* Returns a new Iterator object that contains the values for each element.
*/
values(): IterableIterator<TValue>;
/**
* Executes a provided function once per each key/value pair in the Map object, in insertion order.
* @param callback Function to execute for each entry in the map.
*/
forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
}
/**
* Think of Lson as a sibling of the Json data tree, except that the nested
* data structure can contain a mix of Json values and LiveStructure instances.
*/
declare type Lson = Json | LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson>;
/**
* A mapping of keys to Lson values. A Lson value is any valid JSON
* value or a Live storage data structure (LiveMap, LiveList, etc.)
*/
declare type LsonObject = {
[key: string]: Lson;
};
/**
* The LiveList class represents an ordered collection of items that is synchronized across clients.
*/
declare class LiveList<TItem extends Lson = Lson> extends AbstractCrdt {
private _items;
constructor(items?: T[]);
constructor(items?: TItem[]);
/**

@@ -15,3 +103,3 @@ * Returns the number of elements.

*/
push(element: T): void;
push(element: TItem): void;
/**

@@ -22,3 +110,3 @@ * Inserts one element at a specified index.

*/
insert(element: T, index: number): void;
insert(element: TItem, index: number): void;
/**

@@ -36,6 +124,7 @@ * Move one element from one index to another.

clear(): void;
set(index: number, item: TItem): void;
/**
* Returns an Array of all the elements in the LiveList.
*/
toArray(): T[];
toArray(): TItem[];
/**

@@ -46,3 +135,3 @@ * Tests whether all elements pass the test implemented by the provided function.

*/
every(predicate: (value: T, index: number) => unknown): boolean;
every(predicate: (value: TItem, index: number) => unknown): boolean;
/**

@@ -53,3 +142,3 @@ * Creates an array with all elements that pass the test implemented by the provided function.

*/
filter(predicate: (value: T, index: number) => unknown): T[];
filter(predicate: (value: TItem, index: number) => unknown): TItem[];
/**

@@ -60,3 +149,3 @@ * Returns the first element that satisfies the provided testing function.

*/
find(predicate: (value: T, index: number) => unknown): T | undefined;
find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
/**

@@ -67,3 +156,3 @@ * Returns the index of the first element in the LiveList that satisfies the provided testing function.

*/
findIndex(predicate: (value: T, index: number) => unknown): number;
findIndex(predicate: (value: TItem, index: number) => unknown): number;
/**

@@ -73,3 +162,3 @@ * Executes a provided function once for each element.

*/
forEach(callbackfn: (value: T, index: number) => void): void;
forEach(callbackfn: (value: TItem, index: number) => void): void;
/**

@@ -80,3 +169,3 @@ * Get the element at the specified index.

*/
get(index: number): T | undefined;
get(index: number): TItem | undefined;
/**

@@ -88,3 +177,3 @@ * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.

*/
indexOf(searchElement: T, fromIndex?: number): number;
indexOf(searchElement: TItem, fromIndex?: number): number;
/**

@@ -96,3 +185,3 @@ * Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveLsit is searched backwards, starting at fromIndex.

*/
lastIndexOf(searchElement: T, fromIndex?: number): number;
lastIndexOf(searchElement: TItem, fromIndex?: number): number;
/**

@@ -103,3 +192,3 @@ * Creates an array populated with the results of calling a provided function on every element.

*/
map<U>(callback: (value: T, index: number) => U): U[];
map<U>(callback: (value: TItem, index: number) => U): U[];
/**

@@ -110,64 +199,6 @@ * Tests whether at least one element in the LiveList passes the test implemented by the provided function.

*/
some(predicate: (value: T, index: number) => unknown): boolean;
[Symbol.iterator](): IterableIterator<T>;
some(predicate: (value: TItem, index: number) => unknown): boolean;
[Symbol.iterator](): IterableIterator<TItem>;
}
/**
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
* Keys should be a string, and values should be serializable to JSON.
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
*/
declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
private _map;
constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
/**
* Returns a specified element from the LiveMap.
* @param key The key of the element to return.
* @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
*/
get(key: TKey): TValue | undefined;
/**
* Adds or updates an element with a specified key and a value.
* @param key The key of the element to add. Should be a string.
* @param value The value of the element to add. Should be serializable to JSON.
*/
set(key: TKey, value: TValue): void;
/**
* Returns the number of elements in the LiveMap.
*/
get size(): number;
/**
* Returns a boolean indicating whether an element with the specified key exists or not.
* @param key The key of the element to test for presence.
*/
has(key: TKey): boolean;
/**
* Removes the specified element by key.
* @param key The key of the element to remove.
* @returns true if an element existed and has been removed, or false if the element does not exist.
*/
delete(key: TKey): boolean;
/**
* Returns a new Iterator object that contains the [key, value] pairs for each element.
*/
entries(): IterableIterator<[string, TValue]>;
/**
* Same function object as the initial value of the entries method.
*/
[Symbol.iterator](): IterableIterator<[string, TValue]>;
/**
* Returns a new Iterator object that contains the keys for each element.
*/
keys(): IterableIterator<TKey>;
/**
* Returns a new Iterator object that contains the values for each element.
*/
values(): IterableIterator<TValue>;
/**
* Executes a provided function once per each key/value pair in the Map object, in insertion order.
* @param callback Function to execute for each entry in the map.
*/
forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
}
declare type MyPresenceCallback<T extends Presence = Presence> = (me: T) => void;

@@ -177,3 +208,3 @@ declare type OthersEventCallback<T extends Presence = Presence> = (others: Others<T>, event: OthersEvent<T>) => void;

connectionId: number;
event: any;
event: Json;
}) => void;

@@ -187,11 +218,15 @@ declare type ErrorCallback = (error: Error) => void;

};
declare type LiveMapUpdates<TKey extends string = string, TValue = any> = {
declare type LiveMapUpdates<TKey extends string, TValue extends Lson> = {
type: "LiveMap";
node: LiveMap<TKey, TValue>;
updates: Record<TKey, UpdateDelta>;
updates: {
[key: string]: UpdateDelta;
};
};
declare type LiveObjectUpdateDelta<T> = Partial<{
[Property in keyof T]: UpdateDelta;
}>;
declare type LiveObjectUpdates<TData = any> = {
declare type LiveObjectUpdateDelta<O extends {
[key: string]: unknown;
}> = {
[K in keyof O]?: UpdateDelta | undefined;
};
declare type LiveObjectUpdates<TData extends LsonObject> = {
type: "LiveObject";

@@ -203,3 +238,3 @@ node: LiveObject<TData>;

index: number;
item: AbstractCrdt;
item: any;
type: "insert";

@@ -212,6 +247,10 @@ } | {

previousIndex: number;
item: AbstractCrdt;
item: any;
type: "move";
} | {
index: number;
item: any;
type: "set";
};
declare type LiveListUpdates<TItem = any> = {
declare type LiveListUpdates<TItem extends Lson> = {
type: "LiveList";

@@ -229,3 +268,3 @@ node: LiveList<TItem>;

};
declare type StorageUpdate = LiveMapUpdates | LiveObjectUpdates | LiveListUpdates;
declare type StorageUpdate = LiveMapUpdates<string, Lson> | LiveObjectUpdates<LsonObject> | LiveListUpdates<Lson>;
declare type Client = {

@@ -330,2 +369,54 @@ /**

};
interface History {
/**
* Undoes the last operation executed by the current client.
* It does not impact operations made by other clients.
*
* @example
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true });
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true });
* room.history.undo();
* // room.getPresence() equals { selectedId: "xxx" }
*/
undo: () => void;
/**
* Redoes the last operation executed by the current client.
* It does not impact operations made by other clients.
*
* @example
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true });
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true });
* room.history.undo();
* // room.getPresence() equals { selectedId: "xxx" }
* room.history.redo();
* // room.getPresence() equals { selectedId: "yyy" }
*/
redo: () => void;
/**
* All future modifications made on the Room will be merged together to create a single history item until resume is called.
*
* @example
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true });
* room.history.pause();
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true });
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true });
* room.history.resume();
* room.history.undo();
* // room.getPresence() equals { cursor: { x: 0, y: 0 } }
*/
pause: () => void;
/**
* Resumes history. Modifications made on the Room are not merged into a single history item anymore.
*
* @example
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true });
* room.history.pause();
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true });
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true });
* room.history.resume();
* room.history.undo();
* // room.getPresence() equals { cursor: { x: 0, y: 0 } }
*/
resume: () => void;
}
declare type Room = {

@@ -392,3 +483,3 @@ /**

*/
<TKey extends string, TValue>(liveMap: LiveMap<TKey, TValue>, listener: (liveMap: LiveMap<TKey, TValue>) => void): () => void;
<TKey extends string, TValue extends Lson>(liveMap: LiveMap<TKey, TValue>, listener: (liveMap: LiveMap<TKey, TValue>) => void): () => void;
/**

@@ -407,3 +498,3 @@ * Subscribes to changes made on a {@link LiveObject}. Returns an unsubscribe function.

*/
<TData>(liveObject: LiveObject<TData>, callback: (liveObject: LiveObject<TData>) => void): () => void;
<TData extends JsonObject>(liveObject: LiveObject<TData>, callback: (liveObject: LiveObject<TData>) => void): () => void;
/**

@@ -422,3 +513,3 @@ * Subscribes to changes made on a {@link LiveList}. Returns an unsubscribe function.

*/
<TItem>(liveList: LiveList<TItem>, callback: (liveList: LiveList<TItem>) => void): () => void;
<TItem extends Lson>(liveList: LiveList<TItem>, callback: (liveList: LiveList<TItem>) => void): () => void;
/**

@@ -437,3 +528,3 @@ * Subscribes to changes made on a {@link LiveMap} and all the nested data structures. Returns an unsubscribe function.

*/
<TKey extends string, TValue>(liveMap: LiveMap<TKey, TValue>, callback: (updates: StorageUpdate[]) => void, options: {
<TKey extends string, TValue extends Lson>(liveMap: LiveMap<TKey, TValue>, callback: (updates: LiveMapUpdates<TKey, TValue>[]) => void, options: {
isDeep: true;

@@ -454,3 +545,3 @@ }): () => void;

*/
<TData>(liveObject: LiveObject<TData>, callback: (updates: StorageUpdate[]) => void, options: {
<TData extends LsonObject>(liveObject: LiveObject<TData>, callback: (updates: LiveObjectUpdates<TData>[]) => void, options: {
isDeep: true;

@@ -471,3 +562,3 @@ }): () => void;

*/
<TItem>(liveList: LiveList<TItem>, callback: (updates: StorageUpdate[]) => void, options: {
<TItem extends Lson>(liveList: LiveList<TItem>, callback: (updates: LiveListUpdates<TItem>[]) => void, options: {
isDeep: true;

@@ -479,54 +570,3 @@ }): () => void;

*/
history: {
/**
* Undoes the last operation executed by the current client.
* It does not impact operations made by other clients.
*
* @example
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true });
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true });
* room.history.undo();
* // room.getPresence() equals { selectedId: "xxx" }
*/
undo: () => void;
/**
* Redoes the last operation executed by the current client.
* It does not impact operations made by other clients.
*
* @example
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true });
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true });
* room.history.undo();
* // room.getPresence() equals { selectedId: "xxx" }
* room.history.redo();
* // room.getPresence() equals { selectedId: "yyy" }
*/
redo: () => void;
/**
* All future modifications made on the Room will be merged together to create a single history item until resume is called.
*
* @example
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true });
* room.history.pause();
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true });
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true });
* room.history.resume();
* room.history.undo();
* // room.getPresence() equals { cursor: { x: 0, y: 0 } }
*/
pause: () => void;
/**
* Resumes history. Modifications made on the Room are not merged into a single history item anymore.
*
* @example
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true });
* room.history.pause();
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true });
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true });
* room.history.resume();
* room.history.undo();
* // room.getPresence() equals { cursor: { x: 0, y: 0 } }
*/
resume: () => void;
};
history: History;
/**

@@ -624,3 +664,3 @@ * @deprecated use the callback returned by subscribe instead.

*/
broadcastEvent: (event: any, options?: BroadcastOptions) => void;
broadcastEvent: (event: JsonObject, options?: BroadcastOptions) => void;
/**

@@ -633,3 +673,3 @@ * Get the room's storage asynchronously.

*/
getStorage: <TRoot>() => Promise<{
getStorage: <TRoot extends LsonObject>() => Promise<{
root: LiveObject<TRoot>;

@@ -666,6 +706,6 @@ }>;

*/
declare class LiveObject<T extends Record<string, any> = Record<string, any>> extends AbstractCrdt {
declare class LiveObject<O extends LsonObject = LsonObject> extends AbstractCrdt {
private _map;
private _propToLastUpdate;
constructor(object?: T);
constructor(object?: O);
private _applyUpdate;

@@ -676,3 +716,3 @@ private _applyDeleteObjectKey;

*/
toObject(): T;
toObject(): O;
/**

@@ -683,3 +723,3 @@ * Adds or updates a property with a specified key and a value.

*/
set<TKey extends keyof T>(key: TKey, value: T[TKey]): void;
set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
/**

@@ -689,3 +729,3 @@ * Returns a specified property from the LiveObject.

*/
get<TKey extends keyof T>(key: TKey): T[TKey];
get<TKey extends keyof O>(key: TKey): O[TKey];
/**

@@ -695,3 +735,3 @@ * Deletes a key from the LiveObject

*/
delete(key: keyof T): void;
delete(key: keyof O): void;
/**

@@ -701,3 +741,3 @@ * Adds or updates multiple properties at once with an object.

*/
update(overrides: Partial<T>): void;
update(overrides: Partial<O>): void;
}

@@ -732,2 +772,2 @@

export { BroadcastOptions, Client, LiveList, LiveMap, LiveObject, Others, Presence, Room, StorageUpdate, User, createClient };
export { BroadcastOptions, Client, History, Json, JsonObject, LiveList, LiveMap, LiveObject, Lson, LsonObject, Others, Presence, Room, StorageUpdate, User, createClient };

@@ -0,1 +1,18 @@

/**
* Represents an indefinitely deep arbitrary JSON data structure. There are
* four types that make up the Json family:
*
* - Json any legal JSON value
* - JsonScalar any legal JSON leaf value (no lists or objects)
* - JsonArray a JSON value whose outer type is an array
* - JsonObject a JSON value whose outer type is an object
*
*/
declare type Json = JsonScalar | JsonArray | JsonObject;
declare type JsonScalar = string | number | boolean | null;
declare type JsonArray = Json[];
declare type JsonObject = {
[key: string]: Json;
};
declare type Presence = Record<string, unknown>;

@@ -41,3 +58,3 @@

actor: number;
event: any;
event: Json;
};

@@ -62,3 +79,3 @@ declare type SerializedCrdtWithId = [id: string, crdt: SerializedCrdt];

type: ClientMessageType.ClientEvent;
event: any;
event: Json;
};

@@ -87,5 +104,3 @@ declare type UpdatePresenceClientMessage = {

parentKey?: string;
data: {
[key: string]: any;
};
data: JsonObject;
};

@@ -106,3 +121,3 @@ declare type SerializedList = {

parentKey: string;
data: any;
data: Json;
};

@@ -122,2 +137,3 @@ declare type SerializedCrdt = SerializedObject | SerializedList | SerializedMap | SerializedRegister;

declare type Op = CreateObjectOp | UpdateObjectOp | DeleteCrdtOp | CreateListOp | SetParentKeyOp | DeleteObjectKeyOp | CreateMapOp | CreateRegisterOp;
declare type CreateOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp;
declare type UpdateObjectOp = {

@@ -127,5 +143,3 @@ opId?: string;

type: OpType.UpdateObject;
data: {
[key: string]: any;
};
data: Partial<JsonObject>;
};

@@ -135,8 +149,7 @@ declare type CreateObjectOp = {

id: string;
intent?: "set";
type: OpType.CreateObject;
parentId?: string;
parentKey?: string;
data: {
[key: string]: any;
};
data: JsonObject;
};

@@ -146,2 +159,3 @@ declare type CreateListOp = {

id: string;
intent?: "set";
type: OpType.CreateList;

@@ -154,2 +168,3 @@ parentId: string;

id: string;
intent?: "set";
type: OpType.CreateMap;

@@ -162,2 +177,3 @@ parentId: string;

id: string;
intent?: "set";
type: OpType.CreateRegister;

@@ -203,2 +219,2 @@ parentId: string;

export { ClientEventMessage, ClientMessage, ClientMessageType, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateRegisterOp, DeleteCrdtOp, DeleteObjectKeyOp, EventMessage, FetchStorageClientMessage, InitialDocumentStateMessage, Op, OpType, RoomStateMessage, SerializedCrdt, SerializedCrdtWithId, SerializedList, SerializedMap, SerializedObject, SerializedRegister, ServerMessage, ServerMessageType, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMessage, UpdatePresenceMessage, UpdateStorageClientMessage, UpdateStorageMessage, UserJoinMessage, UserLeftMessage, WebsocketCloseCodes, compare, makePosition, max, min, pos, posCodes };
export { ClientEventMessage, ClientMessage, ClientMessageType, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, DeleteCrdtOp, DeleteObjectKeyOp, EventMessage, FetchStorageClientMessage, InitialDocumentStateMessage, Op, OpType, RoomStateMessage, SerializedCrdt, SerializedCrdtWithId, SerializedList, SerializedMap, SerializedObject, SerializedRegister, ServerMessage, ServerMessageType, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMessage, UpdatePresenceMessage, UpdateStorageClientMessage, UpdateStorageMessage, UserJoinMessage, UserLeftMessage, WebsocketCloseCodes, compare, makePosition, max, min, pos, posCodes };
{
"name": "@liveblocks/client",
"version": "0.15.11",
"description": "",
"version": "0.16.0",
"description": "A client that lets you interact with Liveblocks servers.",
"main": "./lib/index.js",

@@ -6,0 +6,0 @@ "types": "./lib/index.d.ts",

@@ -21,2 +21,4 @@ <p align="center">

A client that lets you interact with [Liveblocks](https://liveblocks.io) servers.
## Installation

@@ -23,0 +25,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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