Skip to main content
Version: Current

Shared Documents

  • RelativePosition​

    An object that represents a position in a shared text object that is relative to a specific character in the text.

    No properties are defined on this interface since the implementation is internal.

    Members​

    • RemoteClientEvent​

      Defines an event that is emitted when a remote client connects or disconnects from a shared document.

      Members​

      • client ConnectionInfo​

        The connection info of the client that connected or disconnected.

      • isSelf boolean​

        Whether this event is for the current client. This will be true when client.connectionId is the same as the configBot.id and false otherwise.

      • type ("client_connected" | "client_disconnected")​

        The type of the event.

        "client_connected" is emitted when a new client connects to the document. "client_disconnected" is emitted when a client disconnects from the document.

    • SharedArray​

      Defines an array that can be shared between multiple clients.

      Members​

      • changes Observable<SharedArrayChanges>​

        Gets an observable that resolves whenever the array is changed.

      • deepChanges Observable<SharedTypeChanges[]>​

        Gets an observable that resolves whenever this array or any children are changed.

      • doc SharedDocument​

        The document that the map is associated with.

      • length number​

        Gets the number of elements in the array.

      • parent SharedType​

        The type that this map is stored in.

      • size number​

        Gets the number of elements in the array.

      • [iterator](): IterableIterator<T>​

        Gets an iterator for the items in the array.

      • applyDelta(delta: SharedArrayOp[]): void​

        Applies the given delta to the array.

        The first parameter is a SharedArrayOp[] and is the delta to apply.

      • clone(): SharedArray​

        Creates a new shared array that is a clone of this array.

      • delete(index: number, count: number): void​

        Deletes the given number of items, starting at the given index.

        The first parameter is a number and is the index of the first item to be deleted.

        The second parameter is a number and is the number of items to delete.

      • filter(predicate: (value: T,index: number,array: SharedArray) => boolean): T[]​

        Creates a new JavaScript array with all elements that pass the test implemented by the provided function.

        The first parameter is a (value: T,index: number,array: SharedArray) => boolean and is the function to execute.

      • forEach(callback: (value: T,index: number,array: SharedArray) => void): void​

        Execute the given callback function for each item in the array.

        The first parameter is a (value: T,index: number,array: SharedArray) => void and is the function to execute.

      • get(index: number): T​

        Gets the item at the given index.

        The first parameter is a number and is the index to get.

      • insert(index: number, items: T[]): void​

        Insert items at the given index.

        The first parameter is a number and is the index to insert the items at. Items at or after this index will be pushed back to make space for the new items. If the index is greater than the length of the array, then the items are appended to the end of the array.

        The second parameter is a T[] and is the items to insert.

      • map(callback: (value: T,index: number,array: SharedArray) => T): T[]​

        Creates a new JavaScript array with the results of calling a provided function on every element in this array.

        The first parameter is a (value: T,index: number,array: SharedArray) => T and is the function to execute.

      • pop(): T​

        Removes the last item from the array and returns it.

      • push(...items: T[]): void​

        Append items to the end of the array.

        Each parameter is a T and are the items to add.

      • shift(): T​

        Removes the first item from the array and returns it.

      • slice(start?: number, end?: number): T[]​

        Gets a range of items from the array. Negative indexes can be used to start from the end of the array.

        The first parameter is optional and is a number and is the index of the first item to retrieve.

        The second parameter is optional and is a number and is the index of the last item to retrieve.

      • splice(start: number, deleteCount: number, ...items: T[]): T[]​

        Changes the contents of the array by removing or replacing existing elements and/or adding new elements. Returns a JavaScript array containing the removed elements.

        The first parameter is a number and is the index at which to start changing the array.

        The second parameter is a number and is the number of elements in the array to remove from start.

        Each other parameter is a T and are the elements to add to the array.

      • toArray(): T[]​

        Creates a new JavaScript array that is a clone of this array.

      • toJSON(): T[]​

        Transforms this map into an array that can be serialized to JSON.

      • unshift(...items: T[]): void​

        Prepend items to the beginning of the array.

        Each parameter is a T and are the items to add.

    • SharedArrayChanges​

      An object that represents changes that occurred in a shared array.

      Members​

    • SharedArrayDeleteOp​

      An object that represents one or more items that were deleted from a shared array.

      Members​

      • count number​

        The number of items that were deleted.

      • type "delete"​

    • SharedArrayInsertOp​

      An object that represents one or more items that were inserted into a shared array.

      Members​

      • type "insert"​

      • values T[]​

        The values that were inserted.

    • SharedArrayOp​

      The possible individual changes that were made to a shared array.

      A SharedArrayOp can be one of the following values:

    • SharedArrayPreserveOp​

      An object that represents no changes to one or more individual items in a shared array.

      Members​

      • count number​

        The number of items that were preserved.

      • type "preserve"​

    • SharedDocument​

      Defines an interface for objects that are able to synchronize data between multiple clients.

      Members​

      • address string​

        The address of the document. If null, then the document is stored locally.

      • branch string​

        The branch that was loaded for the document.

      • clientId number​

        The ID of the remote client that the document is associated with.

      • closed boolean​

      • onClientError Observable<ClientError>​

        Gets the observable list of client errors from the document. That is, errors that were caused by the client's behavior.

      • onError Observable<any>​

        Gets an observable list of errors from the partition. That is, errors that the client cannot handle.

      • onEvents Observable<Action[]>​

        Gets the observable list of remote events from the partition.

      • onStatusUpdated Observable<StatusUpdate>​

        Gets the observable list of status updates from the partition.

      • onUpdates Observable<string[]>​

        Gets the observable list of updates from the partition.

      • onVersionUpdated Observable<CurrentVersion>​

        Gets an observable list that resolves whenever the partition state version is updated.

      • recordName string​

        The name of the record that the document is stored under. If null, then the document is public.

      • remoteClients Observable<RemoteClientEvent>​

        The events that are emitted when remote clients connect or disconnect from the document.

        When subscribed to, this observable will emit an event whenever a remote client connects or disconnects from the document. Additionally, the current remote clients will be emitted when the subscription is first made.

      • remoteClientsRaw Observable<RemoteClientEvent>​

        The events that are emitted when remote clients connect or disconnect from the document.

        When subscribed to, this observable will emit an event whenever a remote client connects or disconnects from the document. Notably, the current remote clients will NOT be emitted when the subscription is first made, so this can be used to only listen for future client connections and disconnections.

      • applyStateUpdates(updates: InstUpdate[]): void​

        Applies the given inst updates to the document.

        The first parameter is a InstUpdate[] and is the updates to apply.

      • applyUpdates(updates: string[]): void​

        Applies the given raw updates to the document.

        The first parameter is a string[] and is the updates to apply.

      • connect(): void​

        Tells the document to connect to its backing store.

      • createArray(): SharedArray​

        Creates a new array that can be shared between multiple clients.

      • createMap(): SharedMap​

        Creates a new map that can be shared between multiple clients.

      • createText(): SharedText​

        Creates a new text object that can be shared between multiple clients.

      • getArray(name: string): SharedArray​

        Gets a top-level array that can be used to store a list of items.

        The first parameter is a string and is the name of the array.

      • getMap(name: string): SharedMap​

        Gets a top-level map that can be used to store key/value data.

        The first parameter is a string and is the name of the map.

      • getStateUpdate(): InstUpdate​

        Gets the update that represents the current state of the document.

      • getText(name: string): SharedText​

        Gets a top-level text object that can be used to store rich text.

        The first parameter is a string and is the name of the text.

      • transact(callback: () => void): void​

        Batches changes that occur within the given callback function into a single transaction. This makes multiple updates more efficient.

        The first parameter is a () => void and is the function to execute.

      • unsubscribe(): void​

    • SharedMap​

      Defines a map that can be shared between multiple clients.

      Members​

      • changes Observable<SharedMapChanges>​

        Gets an observable that resolves whenever the map is changed.

      • deepChanges Observable<SharedTypeChanges[]>​

        Gets an observable that resolves whenever this map or any children are changed.

      • doc SharedDocument​

        The document that the map is associated with.

      • parent SharedType​

        The type that this map is stored in.

      • size number​

        Gets the number of keys that are in the map.

      • [iterator](): IterableIterator<[string, T]>​

        Gets an iterator for the key/value pairs stored in the map.

      • clear(): void​

        Clears the map.

      • clone(): SharedMap​

        Creates a new map that is a clone of this map.

      • delete(key: string): void​

        Deletes the given key from the map.

        The first parameter is a string and deletes the given key.

      • entries(): IterableIterator<[string, T]>​

        Gets an iterator for the key/value pairs stored in the map.

      • forEach(callback: (value: T,key: string,map: SharedMap) => void): void​

        Execute the provided function once on every key/value pair.

        The first parameter is a (value: T,key: string,map: SharedMap) => void and is the function to execute.

      • get(key: string): T​

        Gets the value for the given key.

        The first parameter is a string and is the key to get.

      • has(key: string): boolean​

        Determines if the given key exists in the map.

        The first parameter is a string and is the key.

      • keys(): IterableIterator<string>​

        Gets an iterator for the keys stored in the map.

      • set(key: string, value: T): void​

        Sets the given key to the given value.

        The first parameter is a string and is the key to set.

        The second parameter is a T and is the value to set.

      • toJSON(): object​

        Transforms this map into an object that can be serialized to JSON.

      • values(): IterableIterator<T>​

        Gets an iterator for the values stored in the map.

    • SharedMapChange​

      Defines an individual change that occurred in a shared map.

      Members​

      • action ("update" | "delete" | "add")​

        The action that caused this change.

      • oldValue T​

        The old value of the key.

    • SharedMapChanges​

      An object that represents changes that occurred in a shared map.

      Members​

    • SharedText​

      Defines an object that represents rich text that can be shared between multiple clients.

      Members​

      • changes Observable<SharedTextChanges>​

        Gets an observable that resolves whenever the array is changed.

      • deepChanges Observable<SharedTextChanges[]>​

        Gets an observable that resolves whenever this array or any children are changed.

      • doc SharedDocument​

        The document that the map is associated with.

      • length number​

        Gets the length of the string in UTF-16 code units.

      • parent SharedType​

        The type that this map is stored in.

      • applyDelta(delta: SharedTextDelta): void​

        Applies the given delta to the text.

        The first parameter is a SharedTextDelta and is the delta to apply.

      • clone(): SharedText​

        Creates a new shared array that is a clone of this array.

      • decodeRelativePosition(position: RelativePosition): number​

        Gets the index that the given relative position is associated with.

        The first parameter is a RelativePosition and is the relative position to decode.

      • delete(index: number, count: number): void​

        Deletes the given number of items, starting at the given index.

        The first parameter is a number and is the index of the first item to be deleted.

        The second parameter is a number and is the number of items to delete.

      • encodeRelativePosition(index: number, assoc?: number): RelativePosition​

        Creates a relative position that is fixed to the code point at the given index.

        The first parameter is a number and is the index of the character to create the relative position for.

        The second parameter is optional and is a number and is the association of the relative position to the character. < 0 is before, >= 0 is after.

      • insert(index: number, text: string, attribtues?: Record): void​

        Insert text at the given index. Optionally apply formatting to the inserted text.

        The first parameter is a number and is the index to insert the text at.

        The second parameter is a string and is the text to insert.

        The third parameter is optional and is a Record and is the formatting attributes to apply to the inserted text.

      • slice(start?: number, end?: number): string​

        Gets a range of text from this object. Negative indexes can be used to start from the end of the string.

        The first parameter is optional and is a number and is the index of the first code point to retrieve.

        The second parameter is optional and is a number and is the index of the last code point to retrieve.

      • toDelta(): SharedTextDelta​

        Converts this text into a delta that can be applied to another text object.

      • toJSON(): string​

        Transforms this text into a string that can be serialized to JSON.

      • toString(): string​

        Creates a new JavaScript string that is a clone of this text.

    • SharedTextChanges​

      An object that represents changes that occurred in a shared text object.

      Members​

    • SharedTextDeleteOp​

      An object that represents one or more characters that were deleted from a shared text object.

      Members​

      • count number​

        The number of items that were deleted.

      • type "delete"​

    • SharedTextDelta​

      The array of changes that were made to the text.

    • SharedTextInsertOp​

      An object that represents one or more characters that were inserted into a shared text object.

      Members​

      • attributes Record​

        The formatting that was applied to the inserted text.

      • text string​

        The text that was inserted.

      • type "insert"​

    • SharedTextOp​

      The possible individual changes that were made to the text.

      A SharedTextOp can be one of the following values:

    • SharedTextPreserveOp​

      An object that represents no changes to one or more individual characters in a shared text object.

      Members​

      • count number​

        The number of characters that were preserved.

      • type "preserve"​

    • SharedType​

      Defienes a type that can be shared between multiple clients. This can be a map, array, or text.

      A SharedType can be one of the following values:

    • SharedTypeChanges​

      Defines the type of changes that can occur in a shared document.

      This can be a change to a map, array, or text.

      A SharedTypeChanges can be one of the following values: