Skip to main content
Version: Current

Document Actions

  • os.getLocalDocument(name: string): Promise<SharedDocument>

    Gets a shared document that is only stored locally on this device.

    Note that local documents are inst-specific. This means that they are only accessible within the inst they were created in.

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

    Examples
    Get a local document.
    const doc = await os.getLocalDocument('myDocument');
    Get a map from a local document.
    const doc = await os.getLocalDocument('myDocument');
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    Get an array from a local document.
    const doc = await os.getLocalDocument('myDocument');
    const array = doc.getArray('myArray');
    array.push('myValue');
    Get text from a local document
    const doc = await os.getLocalDocument('myDocument');
    const text = doc.getText('myText');
    text.insert(0, 'Hello, World!');

    os.toast(text.toString());
    Efficiently batch multiple updates
    const doc = await os.getLocalDocument('myDocument');
    doc.transact(() => {
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    map.set('myKey2', 'myValue2');
    map.set('myKey3', 'myValue3');
    });
  • os.getMemoryDocument(): Promise<SharedDocument>

    Gets a document that is not shared or saved to the device.

    Examples
    Get a memory document.
    const doc = await os.getMemoryDocument('myDocument');
    Get a map from a memory document.
    const doc = await os.getMemoryDocument('myDocument');
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    Get an array from a memory document.
    const doc = await os.getMemoryDocument('myDocument');
    const array = doc.getArray('myArray');
    array.push('myValue');
    Get text from a memory document
    const doc = await os.getMemoryDocument('myDocument');
    const text = doc.getText('myText');
    text.insert(0, 'Hello, World!');

    os.toast(text.toString());
    Get the serialized state of the document.
    const doc = await os.getMemoryDocument('myDocument');
    const state = doc.getStateUpdate();
    Efficiently batch multiple updates
    const doc = await os.getLocalDocument('myDocument');
    doc.transact(() => {
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    map.set('myKey2', 'myValue2');
    map.set('myKey3', 'myValue3');
    });
  • os.getSharedDocument(name: string): Promise<SharedDocument>

    Gets a shared document record from this inst by its name.

    Shared documents are a way to share data across insts in a easy and secure manner.

    Returns a promise that resolves with the shared document.

    The first parameter is a string and is the name of the shared document.

    Examples
    Get a shared document from the current inst by name.
    const sharedDocument = await os.getSharedDocument('myDocument');
    Get a map from a shared document.
    const doc = await os.getSharedDocument('myDocument');
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    Get an array from a shared document.
    const doc = await os.getSharedDocument('myDocument');
    const array = doc.getArray('myArray');
    array.push('myValue');
    Get text from a shared document
    const doc = await os.getSharedDocument('myDocument');
    const text = doc.getText('myText');
    text.insert(0, 'Hello, World!');

    os.toast(text.toString());
    Efficiently batch multiple updates
    const doc = await os.getSharedDocument('myDocument');
    doc.transact(() => {
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    map.set('myKey2', 'myValue2');
    map.set('myKey3', 'myValue3');
    });
  • os.getSharedDocument(name: string, options: object): Promise<SharedDocument>

    Gets a shared document from the current inst with the given options.

    Shared documents are a way to share data across insts in a easy and secure manner.

    Returns a promise that resolves with the shared document.

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

    The second parameter is a object and is the options for the shared document.

    Examples
    Get a shared document with custom markers.
    const sharedDocument = await os.getSharedDocument('myDocument', {
    markers: ['secret', 'team']
    });
  • os.getSharedDocument(recordName: string, inst: string, name: string): Promise<SharedDocument>

    Gets a shared document record from the given inst by its name.

    Shared documents are a way to share data across insts in a easy and secure manner.

    Returns a promise that resolves with the shared document.

    The first parameter is a string and is the name of the record. If null, then a public inst will be used.

    The second parameter is a string and is the name of the inst that the shared document is in.

    The third parameter is a string and

    Examples
    Get a shared document from the given inst.
    const sharedDocument = await os.getSharedDocument('recordName', 'myInst', 'myDocument');
    Get a map from a shared document.
    const doc = await os.getSharedDocument('recordName', 'myInst', 'myDocument');
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    Get an array from a shared document.
    const doc = await os.getSharedDocument('recordName', 'myInst', 'myDocument');
    const array = doc.getArray('myArray');
    array.push('myValue');
    Get text from a shared document
    const doc = await os.getSharedDocument('recordName', 'myInst', 'myDocument');
    const text = doc.getText('myText');
    text.insert(0, 'Hello, World!');

    os.toast(text.toString());
    Efficiently batch multiple updates
    const doc = await os.getSharedDocument('recordName', 'myInst', 'myDocument');
    doc.transact(() => {
    const map = doc.getMap('myValues');
    map.set('myKey', 'myValue');
    map.set('myKey2', 'myValue2');
    map.set('myKey3', 'myValue3');
    });
  • os.getSharedDocument(recordName: string, inst: string, name: string, options: object): Promise<SharedDocument>

    Gets a shared document record from the given inst by its name with options.

    Shared documents are a way to share data across insts in a easy and secure manner.

    Returns a promise that resolves with the shared document.

    The first parameter is a string and is the name of the record. If null, then a public inst will be used.

    The second parameter is a string and is the name of the inst that the shared document is in.

    The third parameter is a string and

    The fourth parameter is a object and is the options for the shared document.

    Examples
    Get a shared document from the given inst with custom markers.
    const sharedDocument = await os.getSharedDocument('recordName', 'myInst', 'myDocument', {
    markers: ['secret', 'team']
    });