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.16.3 to 0.16.4-beta1

index.mjs

730

index.d.ts

@@ -1,729 +0,5 @@

/**
* 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 | undefined;
};
import { C as ClientOptions, a as Client } from './shared';
export { B as BroadcastOptions, a as Client, H as History, J as Json, d as JsonObject, c as LiveList, b as LiveMap, L as LiveObject, e as Lson, f as LsonObject, O as Others, P as Presence, R as Room, S as StorageUpdate, U as User } from './shared';
/**
* 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 | undefined;
};
/**
* 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?: TItem[]);
/**
* Returns the number of elements.
*/
get length(): number;
/**
* Adds one element to the end of the LiveList.
* @param element The element to add to the end of the LiveList.
*/
push(element: TItem): void;
/**
* Inserts one element at a specified index.
* @param element The element to insert.
* @param index The index at which you want to insert the element.
*/
insert(element: TItem, index: number): void;
/**
* Move one element from one index to another.
* @param index The index of the element to move
* @param targetIndex The index where the element should be after moving.
*/
move(index: number, targetIndex: number): void;
/**
* Deletes an element at the specified index
* @param index The index of the element to delete
*/
delete(index: number): void;
clear(): void;
set(index: number, item: TItem): void;
/**
* Returns an Array of all the elements in the LiveList.
*/
toArray(): TItem[];
/**
* Tests whether all elements pass the test implemented by the provided function.
* @param predicate Function to test for each element, taking two arguments (the element and its index).
* @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
*/
every(predicate: (value: TItem, index: number) => unknown): boolean;
/**
* Creates an array with all elements that pass the test implemented by the provided function.
* @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
* @returns An array with the elements that pass the test.
*/
filter(predicate: (value: TItem, index: number) => unknown): TItem[];
/**
* Returns the first element that satisfies the provided testing function.
* @param predicate Function to execute on each value.
* @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
*/
find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
/**
* Returns the index of the first element in the LiveList that satisfies the provided testing function.
* @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
* @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
*/
findIndex(predicate: (value: TItem, index: number) => unknown): number;
/**
* Executes a provided function once for each element.
* @param callbackfn Function to execute on each element.
*/
forEach(callbackfn: (value: TItem, index: number) => void): void;
/**
* Get the element at the specified index.
* @param index The index on the element to get.
* @returns The element at the specified index or undefined.
*/
get(index: number): TItem | undefined;
/**
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
* @param searchElement Element to locate.
* @param fromIndex The index to start the search at.
* @returns The first index of the element in the LiveList; -1 if not found.
*/
indexOf(searchElement: TItem, fromIndex?: number): number;
/**
* 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.
* @param searchElement Element to locate.
* @param fromIndex The index at which to start searching backwards.
* @returns
*/
lastIndexOf(searchElement: TItem, fromIndex?: number): number;
/**
* Creates an array populated with the results of calling a provided function on every element.
* @param callback Function that is called for every element.
* @returns An array with each element being the result of the callback function.
*/
map<U>(callback: (value: TItem, index: number) => U): U[];
/**
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
* @param predicate Function to test for each element.
* @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
*/
some(predicate: (value: TItem, index: number) => unknown): boolean;
[Symbol.iterator](): IterableIterator<TItem>;
}
declare type MyPresenceCallback<T extends Presence = Presence> = (me: T) => void;
declare type OthersEventCallback<T extends Presence = Presence> = (others: Others<T>, event: OthersEvent<T>) => void;
declare type EventCallback = ({ connectionId, event, }: {
connectionId: number;
event: Json;
}) => void;
declare type ErrorCallback = (error: Error) => void;
declare type ConnectionCallback = (state: ConnectionState) => void;
declare type UpdateDelta = {
type: "update";
} | {
type: "delete";
};
/**
* A LiveMap notification that is sent in-client to any subscribers whenever
* one or more of the values inside the LiveMap instance have changed.
*/
declare type LiveMapUpdates<TKey extends string, TValue extends Lson> = {
type: "LiveMap";
node: LiveMap<TKey, TValue>;
updates: {
[key: string]: UpdateDelta;
};
};
declare type LiveObjectUpdateDelta<O extends {
[key: string]: unknown;
}> = {
[K in keyof O]?: UpdateDelta | undefined;
};
/**
* A LiveObject notification that is sent in-client to any subscribers whenever
* one or more of the entries inside the LiveObject instance have changed.
*/
declare type LiveObjectUpdates<TData extends LsonObject> = {
type: "LiveObject";
node: LiveObject<TData>;
updates: LiveObjectUpdateDelta<TData>;
};
declare type LiveListUpdateDelta = {
index: number;
item: any;
type: "insert";
} | {
index: number;
type: "delete";
} | {
index: number;
previousIndex: number;
item: any;
type: "move";
} | {
index: number;
item: any;
type: "set";
};
/**
* A LiveList notification that is sent in-client to any subscribers whenever
* one or more of the items inside the LiveList instance have changed.
*/
declare type LiveListUpdates<TItem extends Lson> = {
type: "LiveList";
node: LiveList<TItem>;
updates: LiveListUpdateDelta[];
};
declare type BroadcastOptions = {
/**
* Whether or not event is queued if the connection is currently closed.
*
* ❗ We are not sure if we want to support this option in the future so it might be deprecated to be replaced by something else
*/
shouldQueueEventIfNotReady: boolean;
};
/**
* The payload of notifications sent (in-client) when LiveStructures change.
* Messages of this kind are not originating from the network, but are 100%
* in-client.
*/
declare type StorageUpdate = LiveMapUpdates<string, Lson> | LiveObjectUpdates<LsonObject> | LiveListUpdates<Lson>;
declare type Client = {
/**
* Gets a room. Returns null if {@link Client.enter} has not been called previously.
*
* @param roomId The id of the room
*/
getRoom(roomId: string): Room | null;
/**
* Enters a room and returns it.
* @param roomId The id of the room
* @param defaultPresence Optional. Should be serializable to JSON. If omitted, an empty object will be used.
*/
enter<TStorageRoot extends Record<string, any> = Record<string, any>>(roomId: string, options?: {
defaultPresence?: Presence;
defaultStorageRoot?: TStorageRoot;
}): Room;
/**
* Leaves a room.
* @param roomId The id of the room
*/
leave(roomId: string): void;
};
/**
* Represents all the other users connected in the room. Treated as immutable.
*/
interface Others<TPresence extends Presence = Presence> {
/**
* Number of other users in the room.
*/
readonly count: number;
/**
* Returns a new Iterator object that contains the users.
*/
[Symbol.iterator](): IterableIterator<User<TPresence>>;
/**
* Returns the array of connected users in room.
*/
toArray(): User<TPresence>[];
/**
* This function let you map over the connected users in the room.
*/
map<U>(callback: (user: User<TPresence>) => U): U[];
}
/**
* Represents a user connected in a room. Treated as immutable.
*/
declare type User<TPresence extends Presence = Presence> = {
/**
* The connection id of the user. It is unique and increment at every new connection.
*/
readonly connectionId: number;
/**
* The id of the user that has been set in the authentication endpoint.
* Useful to get additional information about the connected user.
*/
readonly id?: string;
/**
* Additional user information that has been set in the authentication endpoint.
*/
readonly info?: any;
/**
* The user presence.
*/
readonly presence?: TPresence;
};
declare type Presence = Record<string, unknown>;
declare type AuthEndpointCallback = (room: string) => Promise<{
token: string;
}>;
declare type AuthEndpoint = string | AuthEndpointCallback;
/**
* The authentication endpoint that is called to ensure that the current user has access to a room.
* Can be an url or a callback if you need to add additional headers.
*/
declare type ClientOptions = {
throttle?: number;
fetchPolyfill?: any;
WebSocketPolyfill?: any;
} & ({
publicApiKey: string;
authEndpoint?: never;
} | {
publicApiKey?: never;
authEndpoint: AuthEndpoint;
});
declare type ConnectionState = "closed" | "authenticating" | "unavailable" | "failed" | "open" | "connecting";
declare type OthersEvent<T extends Presence = Presence> = {
type: "leave";
user: User<T>;
} | {
type: "enter";
user: User<T>;
} | {
type: "update";
user: User<T>;
updates: Partial<T>;
} | {
type: "reset";
};
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 = {
/**
* The id of the room.
*/
readonly id: string;
getConnectionState(): ConnectionState;
subscribe: {
/**
* Subscribe to the current user presence updates.
*
* @param listener the callback that is called every time the current user presence is updated with {@link Room.updatePresence}.
*
* @example
* room.subscribe("my-presence", (presence) => {
* // Do something
* });
*/
<T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): () => void;
/**
* Subscribe to the other users updates.
*
* @param listener the callback that is called when a user enters or leaves the room or when a user update its presence.
*
* @example
* room.subscribe("others", (others) => {
* // Do something
* });
*/
<T extends Presence>(type: "others", listener: OthersEventCallback<T>): () => void;
/**
* Subscribe to events broadcasted by {@link Room.broadcastEvent}
*
* @param listener the callback that is called when a user calls {@link Room.broadcastEvent}
*
* @example
* room.subscribe("event", ({ event, connectionId }) => {
* // Do something
* });
*/
(type: "event", listener: EventCallback): () => void;
/**
* Subscribe to errors thrown in the room.
*/
(type: "error", listener: ErrorCallback): () => void;
/**
* Subscribe to connection state updates.
*/
(type: "connection", listener: ConnectionCallback): () => void;
/**
* Subscribes to changes made on a {@link LiveMap}. Returns an unsubscribe function.
* In a future version, we will also expose what exactly changed in the {@link LiveMap}.
*
* @param listener the callback this called when the {@link LiveMap} changes.
*
* @returns Unsubscribe function.
*
* @example
* const liveMap = new LiveMap();
* const unsubscribe = room.subscribe(liveMap, (liveMap) => { });
* unsubscribe();
*/
<TKey extends string, TValue extends Lson>(liveMap: LiveMap<TKey, TValue>, listener: (liveMap: LiveMap<TKey, TValue>) => void): () => void;
/**
* Subscribes to changes made on a {@link LiveObject}. Returns an unsubscribe function.
* In a future version, we will also expose what exactly changed in the {@link LiveObject}.
*
* @param listener the callback this called when the {@link LiveObject} changes.
*
* @returns Unsubscribe function.
*
* @example
* const liveObject = new LiveObject();
* const unsubscribe = room.subscribe(liveObject, (liveObject) => { });
* unsubscribe();
*/
<TData extends JsonObject>(liveObject: LiveObject<TData>, callback: (liveObject: LiveObject<TData>) => void): () => void;
/**
* Subscribes to changes made on a {@link LiveList}. Returns an unsubscribe function.
* In a future version, we will also expose what exactly changed in the {@link LiveList}.
*
* @param listener the callback this called when the {@link LiveList} changes.
*
* @returns Unsubscribe function.
*
* @example
* const liveList = new LiveList();
* const unsubscribe = room.subscribe(liveList, (liveList) => { });
* unsubscribe();
*/
<TItem extends Lson>(liveList: LiveList<TItem>, callback: (liveList: LiveList<TItem>) => void): () => void;
/**
* Subscribes to changes made on a {@link LiveMap} and all the nested data structures. Returns an unsubscribe function.
* In a future version, we will also expose what exactly changed in the {@link LiveMap}.
*
* @param listener the callback this called when the {@link LiveMap} changes.
*
* @returns Unsubscribe function.
*
* @example
* const liveMap = new LiveMap();
* const unsubscribe = room.subscribe(liveMap, (liveMap) => { }, { isDeep: true });
* unsubscribe();
*/
<TKey extends string, TValue extends Lson>(liveMap: LiveMap<TKey, TValue>, callback: (updates: LiveMapUpdates<TKey, TValue>[]) => void, options: {
isDeep: true;
}): () => void;
/**
* Subscribes to changes made on a {@link LiveObject} and all the nested data structures. Returns an unsubscribe function.
* In a future version, we will also expose what exactly changed in the {@link LiveObject}.
*
* @param listener the callback this called when the {@link LiveObject} changes.
*
* @returns Unsubscribe function.
*
* @example
* const liveObject = new LiveObject();
* const unsubscribe = room.subscribe(liveObject, (liveObject) => { }, { isDeep: true });
* unsubscribe();
*/
<TData extends LsonObject>(liveObject: LiveObject<TData>, callback: (updates: LiveObjectUpdates<TData>[]) => void, options: {
isDeep: true;
}): () => void;
/**
* Subscribes to changes made on a {@link LiveList} and all the nested data structures. Returns an unsubscribe function.
* In a future version, we will also expose what exactly changed in the {@link LiveList}.
*
* @param listener the callback this called when the {@link LiveList} changes.
*
* @returns Unsubscribe function.
*
* @example
* const liveList = new LiveList();
* const unsubscribe = room.subscribe(liveList, (liveList) => { }, { isDeep: true });
* unsubscribe();
*/
<TItem extends Lson>(liveList: LiveList<TItem>, callback: (updates: LiveListUpdates<TItem>[]) => void, options: {
isDeep: true;
}): () => void;
};
/**
* Room's history contains functions that let you undo and redo operation made on by the current client on the presence and storage.
*/
history: History;
/**
* @deprecated use the callback returned by subscribe instead.
* See v0.13 release notes for more information.
* Will be removed in a future version.
*/
unsubscribe: {
/**
* @deprecated use the callback returned by subscribe instead.
* See v0.13 release notes for more information.
* Will be removed in a future version.
*/
<T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): void;
/**
* @deprecated use the callback returned by subscribe instead.
* See v0.13 release notes for more information.
* Will be removed in a future version.
*/
<T extends Presence>(type: "others", listener: OthersEventCallback<T>): void;
/**
* @deprecated use the callback returned by subscribe instead.
* See v0.13 release notes for more information.
* Will be removed in a future version.
*/
(type: "event", listener: EventCallback): void;
/**
* @deprecated use the callback returned by subscribe instead.
* See v0.13 release notes for more information.
* Will be removed in a future version.
*/
(type: "error", listener: ErrorCallback): void;
/**
* @deprecated use the callback returned by subscribe instead.
* See v0.13 release notes for more information.
* Will be removed in a future version.
*/
(type: "connection", listener: ConnectionCallback): void;
};
/**
* Gets the current user.
* Returns null if not it is not yet connected to the room.
*
* @example
* const user = room.getSelf();
*/
getSelf<TPresence extends Presence = Presence>(): User<TPresence> | null;
/**
* Gets the presence of the current user.
*
* @example
* const presence = room.getPresence();
*/
getPresence: <T extends Presence>() => T;
/**
* Gets all the other users in the room.
*
* @example
* const others = room.getOthers();
*/
getOthers: <T extends Presence>() => Others<T>;
/**
* Updates the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
* @param overrides A partial object that contains the properties you want to update.
* @param overrides Optional object to configure the behavior of updatePresence.
*
* @example
* room.updatePresence({ x: 0 });
* room.updatePresence({ y: 0 });
*
* const presence = room.getPresence();
* // presence is equivalent to { x: 0, y: 0 }
*/
updatePresence: <T extends Presence>(overrides: Partial<T>, options?: {
/**
* Whether or not the presence should have an impact on the undo/redo history.
*/
addToHistory: boolean;
}) => void;
/**
* Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
* @param {any} event the event to broadcast. Should be serializable to JSON
*
* @example
* // On client A
* room.broadcastEvent({ type: "EMOJI", emoji: "🔥" });
*
* // On client B
* room.subscribe("event", ({ event }) => {
* if(event.type === "EMOJI") {
* // Do something
* }
* });
*/
broadcastEvent: (event: JsonObject, options?: BroadcastOptions) => void;
/**
* Get the room's storage asynchronously.
* The storage's root is a {@link LiveObject}.
*
* @example
* const { root } = await room.getStorage();
*/
getStorage: <TRoot extends LsonObject>() => Promise<{
root: LiveObject<TRoot>;
}>;
/**
* Batches modifications made during the given function.
* All the modifications are sent to other clients in a single message.
* All the subscribers are called only after the batch is over.
* All the modifications are merged in a single history item (undo/redo).
*
* @example
* const { root } = await room.getStorage();
* room.batch(() => {
* root.set("x", 0);
* room.updatePresence({ cursor: { x: 100, y: 100 }});
* });
*/
batch: (fn: () => void) => void;
};
declare abstract class AbstractCrdt {
private __parent?;
private __doc?;
private __id?;
private __parentKey?;
get roomId(): string | null;
}
/**
* The LiveObject class is similar to a JavaScript object 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 LiveObject<O extends LsonObject = LsonObject> extends AbstractCrdt {
private _map;
private _propToLastUpdate;
constructor(object?: O);
private _applyUpdate;
private _applyDeleteObjectKey;
/**
* Transform the LiveObject into a javascript object
*/
toObject(): O;
/**
* Adds or updates a property with a specified key and a value.
* @param key The key of the property to add
* @param value The value of the property to add
*/
set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
/**
* Returns a specified property from the LiveObject.
* @param key The key of the property to get
*/
get<TKey extends keyof O>(key: TKey): O[TKey];
/**
* Deletes a key from the LiveObject
* @param key The key of the property to delete
*/
delete(key: keyof O): void;
/**
* Adds or updates multiple properties at once with an object.
* @param overrides The object used to overrides properties
*/
update(overrides: Partial<O>): void;
}
/**
* Create a client that will be responsible to communicate with liveblocks servers.

@@ -755,2 +31,2 @@ *

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

@@ -1,20 +0,4 @@

/**
* 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 | undefined;
};
import { J as Json, P as Presence, d as JsonObject } from './shared';
export { g as Resolve } from './shared';
declare type Presence = Record<string, unknown>;
/**

@@ -287,2 +271,14 @@ * Messages that can be sent from the server to the client.

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 };
/**
* Displays a deprecation warning in the dev console. Only in dev mode, and
* only once per message/key. In production, this is a no-op.
*/
declare function deprecate(message: string, key?: string): void;
/**
* Conditionally displays a deprecation warning in the dev
* console if the first argument is truthy. Only in dev mode, and
* only once per message/key. In production, this is a no-op.
*/
declare function deprecateIf(condition: unknown, message: string, key?: string): void;
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, deprecate, deprecateIf, makePosition, max, min, pos, posCodes };

@@ -5,191 +5,33 @@ 'use strict';

exports.ServerMessageType = void 0;
var LiveObject = require('./shared.js');
(function (ServerMessageType) {
ServerMessageType[ServerMessageType["UpdatePresence"] = 100] = "UpdatePresence";
ServerMessageType[ServerMessageType["UserJoined"] = 101] = "UserJoined";
ServerMessageType[ServerMessageType["UserLeft"] = 102] = "UserLeft";
ServerMessageType[ServerMessageType["Event"] = 103] = "Event";
ServerMessageType[ServerMessageType["RoomState"] = 104] = "RoomState";
ServerMessageType[ServerMessageType["InitialStorageState"] = 200] = "InitialStorageState";
ServerMessageType[ServerMessageType["UpdateStorage"] = 201] = "UpdateStorage";
})(exports.ServerMessageType || (exports.ServerMessageType = {}));
exports.ClientMessageType = void 0;
(function (ClientMessageType) {
ClientMessageType[ClientMessageType["UpdatePresence"] = 100] = "UpdatePresence";
ClientMessageType[ClientMessageType["ClientEvent"] = 103] = "ClientEvent";
ClientMessageType[ClientMessageType["FetchStorage"] = 200] = "FetchStorage";
ClientMessageType[ClientMessageType["UpdateStorage"] = 201] = "UpdateStorage";
})(exports.ClientMessageType || (exports.ClientMessageType = {}));
exports.CrdtType = void 0;
(function (CrdtType) {
CrdtType[CrdtType["Object"] = 0] = "Object";
CrdtType[CrdtType["List"] = 1] = "List";
CrdtType[CrdtType["Map"] = 2] = "Map";
CrdtType[CrdtType["Register"] = 3] = "Register";
})(exports.CrdtType || (exports.CrdtType = {}));
exports.OpType = void 0;
(function (OpType) {
OpType[OpType["Init"] = 0] = "Init";
OpType[OpType["SetParentKey"] = 1] = "SetParentKey";
OpType[OpType["CreateList"] = 2] = "CreateList";
OpType[OpType["UpdateObject"] = 3] = "UpdateObject";
OpType[OpType["CreateObject"] = 4] = "CreateObject";
OpType[OpType["DeleteCrdt"] = 5] = "DeleteCrdt";
OpType[OpType["DeleteObjectKey"] = 6] = "DeleteObjectKey";
OpType[OpType["CreateMap"] = 7] = "CreateMap";
OpType[OpType["CreateRegister"] = 8] = "CreateRegister";
})(exports.OpType || (exports.OpType = {}));
exports.WebsocketCloseCodes = void 0;
(function (WebsocketCloseCodes) {
WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
WebsocketCloseCodes[WebsocketCloseCodes["INVALID_MESSAGE_FORMAT"] = 4000] = "INVALID_MESSAGE_FORMAT";
WebsocketCloseCodes[WebsocketCloseCodes["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
})(exports.WebsocketCloseCodes || (exports.WebsocketCloseCodes = {}));
var min = 32;
var max = 126;
function makePosition(before, after) {
if (before == null && after == null) {
return pos([min + 1]);
}
if (before != null && after == null) {
return getNextPosition(before);
}
if (before == null && after != null) {
return getPreviousPosition(after);
}
return pos(makePositionFromCodes(posCodes(before), posCodes(after)));
}
function getPreviousPosition(after) {
var result = [];
var afterCodes = posCodes(after);
for (var i = 0; i < afterCodes.length; i++) {
var code = afterCodes[i];
if (code <= min + 1) {
result.push(min);
if (afterCodes.length - 1 === i) {
result.push(max);
break;
}
} else {
result.push(code - 1);
break;
}
}
return pos(result);
}
function getNextPosition(before) {
var result = [];
var beforeCodes = posCodes(before);
for (var i = 0; i < beforeCodes.length; i++) {
var code = beforeCodes[i];
if (code === max) {
result.push(code);
if (beforeCodes.length - 1 === i) {
result.push(min + 1);
break;
}
} else {
result.push(code + 1);
break;
}
}
return pos(result);
}
function makePositionFromCodes(before, after) {
var index = 0;
var result = [];
while (true) {
var beforeDigit = before[index] || min;
var afterDigit = after[index] || max;
if (beforeDigit > afterDigit) {
throw new Error("Impossible to generate position between " + before + " and " + after);
}
if (beforeDigit === afterDigit) {
result.push(beforeDigit);
index++;
continue;
}
if (afterDigit - beforeDigit === 1) {
result.push(beforeDigit);
result.push.apply(result, makePositionFromCodes(before.slice(index + 1), []));
break;
}
var mid = afterDigit + beforeDigit >> 1;
result.push(mid);
break;
}
return result;
}
function posCodes(str) {
var codes = [];
for (var i = 0; i < str.length; i++) {
codes.push(str.charCodeAt(i));
}
return codes;
}
function pos(codes) {
return String.fromCharCode.apply(String, codes);
}
function compare(posA, posB) {
var aCodes = posCodes(posA);
var bCodes = posCodes(posB);
var maxLength = Math.max(aCodes.length, bCodes.length);
for (var i = 0; i < maxLength; i++) {
var a = aCodes[i] == null ? min : aCodes[i];
var b = bCodes[i] == null ? min : bCodes[i];
if (a === b) {
continue;
} else {
return a - b;
}
}
throw new Error("Impossible to compare similar position \"" + posA + "\" and \"" + posB + "\"");
}
exports.compare = compare;
exports.makePosition = makePosition;
exports.max = max;
exports.min = min;
exports.pos = pos;
exports.posCodes = posCodes;
Object.defineProperty(exports, 'ClientMessageType', {
enumerable: true,
get: function () { return LiveObject.ClientMessageType; }
});
Object.defineProperty(exports, 'CrdtType', {
enumerable: true,
get: function () { return LiveObject.CrdtType; }
});
Object.defineProperty(exports, 'OpType', {
enumerable: true,
get: function () { return LiveObject.OpType; }
});
Object.defineProperty(exports, 'ServerMessageType', {
enumerable: true,
get: function () { return LiveObject.ServerMessageType; }
});
Object.defineProperty(exports, 'WebsocketCloseCodes', {
enumerable: true,
get: function () { return LiveObject.WebsocketCloseCodes; }
});
exports.compare = LiveObject.compare;
exports.deprecate = LiveObject.deprecate;
exports.deprecateIf = LiveObject.deprecateIf;
exports.makePosition = LiveObject.makePosition;
exports.max = LiveObject.max;
exports.min = LiveObject.min;
exports.pos = LiveObject.pos;
exports.posCodes = LiveObject.posCodes;
{
"name": "@liveblocks/client",
"version": "0.16.3",
"version": "0.16.4-beta1",
"description": "A client that lets you interact with Liveblocks servers.",
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",

@@ -10,17 +11,2 @@ "files": [

],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./index.d.ts",
"module": "./esm/index.js",
"import": "./esm/index.mjs",
"default": "./index.js"
},
"./internal": {
"types": "./internal.d.ts",
"module": "./esm/internal.js",
"import": "./esm/internal.mjs",
"default": "./internal.js"
}
},
"keywords": [

@@ -37,2 +23,3 @@ "liveblocks",

"build": "rollup -c && cp ./package.json ./README.md ./lib",
"lint": "eslint src/ test/",
"test": "jest --watch",

@@ -50,2 +37,3 @@ "test-ci": "jest"

"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-typescript": "^8.3.1",

@@ -64,4 +52,4 @@ "@types/jest": "^26.0.21",

"rollup": "^2.68.0",
"rollup-plugin-command": "^1.1.3",
"rollup-plugin-dts": "^4.1.0",
"rollup-plugin-esbuild": "^4.8.2",
"typescript": "^4.4.0",

@@ -75,3 +63,4 @@ "whatwg-fetch": "^3.6.2",

"directory": "packages/liveblocks-client"
}
},
"sideEffects": false
}

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