SharedDirectory Class

Packages > fluid-framework > SharedDirectory

SharedDirectory provides a hierarchical organization of map-like data structures as SubDirectories. The values stored within can be accessed like a map, and the hierarchy can be navigated using path syntax. SubDirectories can be retrieved for use as working directories.

Signature:

/** @sealed */
export declare class SharedDirectory extends SharedObject<ISharedDirectoryEvents> implements ISharedDirectory 

Extends: ISharedDirectoryEvents

Implements: ISharedDirectory

Example

mySharedDirectory.createSubDirectory("a").createSubDirectory("b").createSubDirectory("c").set("foo", val1);
const mySubDir = mySharedDirectory.getWorkingDirectory("/a/b/c");
mySubDir.get("foo"); // returns val1

Constructors

List of constructors for this class
Constructor Modifiers Description
(constructor)(id, runtime, attributes) Constructs a new shared directory. If the object is non-local an id and service interfaces will be provided.

Properties

List of properties for this class
Property Modifiers Type Description
[Symbol.toStringTag] String representation for the class.
absolutePath The absolute path of the directory.
disposed
size The number of entries under this IDirectory.

Methods

List of methods on this class
Method Modifiers Description
[Symbol.iterator]() Get an iterator over the entries under this IDirectory.
clear() Deletes all keys from within this IDirectory.
countSubDirectory() Get the number of sub directory within the directory.
create(runtime, id) static Create a new shared directory
createSubDirectory(subdirName) Creates an IDirectory child of this IDirectory, or retrieves the existing IDirectory child if one with the same name already exists.
delete(key) Deletes the given key from within this IDirectory.
deleteSubDirectory(subdirName) Deletes an IDirectory child of this IDirectory, if it exists, along with all descendent keys and directories.
dispose(error)
entries() Get an iterator over the entries under this IDirectory.
forEach(callback) Issue a callback on each entry under this IDirectory.
get(key) Retrieves the value stored at the given key from the directory.
getFactory() static Get a factory for SharedDirectory to register with the data store.
getSubDirectory(subdirName) Gets an IDirectory child of this IDirectory, if it exists.
getWorkingDirectory(relativePath) Get an IDirectory within the directory, in order to use relative paths from that location.
has(key) Checks whether the given key exists in this IDirectory.
hasSubDirectory(subdirName) Checks whether this directory has a child directory with the given name.
keys() Get an iterator over the keys under this IDirectory.
set(key, value) Sets the value stored at key to the provided value.
subdirectories() Gets an iterator over the IDirectory children of this IDirectory.
values() Get an iterator over the values under this IDirectory.

Constructors

SharedDirectory.(constructor)

Constructs a new shared directory. If the object is non-local an id and service interfaces will be provided.

Signature:

constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);

Parameters

List of parameters
Parameter Type Description
id String identifier for the SharedDirectory
runtime Data store runtime
attributes

Properties

[Symbol.toStringTag]

String representation for the class.

Signature:

[Symbol.toStringTag]: string;

absolutePath

The absolute path of the directory.

Signature:

get absolutePath(): string;

disposed

Signature:

get disposed(): boolean;

size

The number of entries under this IDirectory.

Signature:

get size(): number;

Methods

[Symbol.iterator]

Get an iterator over the entries under this IDirectory.

Signature:

[Symbol.iterator](): IterableIterator<[string, any]>;

Returns:

The iterator

clear

Deletes all keys from within this IDirectory.

Signature:

clear(): void;

Returns:

countSubDirectory

Get the number of sub directory within the directory.

Signature:

countSubDirectory(): number;

Returns:

The number of sub directory within a directory.

create

Create a new shared directory

Signature:

static create(runtime: IFluidDataStoreRuntime, id?: string): SharedDirectory;

Parameters

List of parameters
Parameter Type Description
runtime Data store runtime the new shared directory belongs to
id Optional name of the shared directory

Returns:

SharedDirectory

Newly create shared directory (but not attached yet)

createSubDirectory

Creates an IDirectory child of this IDirectory, or retrieves the existing IDirectory child if one with the same name already exists.

Signature:

createSubDirectory(subdirName: string): IDirectory;

Parameters

List of parameters
Parameter Type Description
subdirName Name of the new child directory to create

Returns:

IDirectory

The IDirectory child that was created or retrieved

delete

Deletes the given key from within this IDirectory.

Signature:

delete(key: string): boolean;

Parameters

List of parameters
Parameter Type Description
key The key to delete

Returns:

True if the key existed and was deleted, false if it did not exist

deleteSubDirectory

Deletes an IDirectory child of this IDirectory, if it exists, along with all descendent keys and directories.

Signature:

deleteSubDirectory(subdirName: string): boolean;

Parameters

List of parameters
Parameter Type Description
subdirName Name of the child directory to delete

Returns:

True if the IDirectory existed and was deleted, false if it did not exist

dispose

Signature:

dispose(error?: Error): void;

Parameters

List of parameters
Parameter Type Description
error

Returns:

entries

Get an iterator over the entries under this IDirectory.

Signature:

entries(): IterableIterator<[string, any]>;

Returns:

The iterator

forEach

Issue a callback on each entry under this IDirectory.

Signature:

forEach(callback: (value: any, key: string, map: Map<string, any>) => void): void;

Parameters

List of parameters
Parameter Type Description
callback Callback to issue

Returns:

get

Retrieves the value stored at the given key from the directory.

Signature:

get<T = any>(key: string): T | undefined;

Parameters

List of parameters
Parameter Type Description
key Key to retrieve from

Returns:

The stored value, or undefined if the key is not set

getFactory

Get a factory for SharedDirectory to register with the data store.

Signature:

static getFactory(): IChannelFactory;

Returns:

A factory that creates and load SharedDirectory

getSubDirectory

Gets an IDirectory child of this IDirectory, if it exists.

Signature:

getSubDirectory(subdirName: string): IDirectory | undefined;

Parameters

List of parameters
Parameter Type Description
subdirName Name of the child directory to get

Returns:

IDirectory

The requested IDirectory

getWorkingDirectory

Get an IDirectory within the directory, in order to use relative paths from that location.

Signature:

getWorkingDirectory(relativePath: string): IDirectory | undefined;

Parameters

List of parameters
Parameter Type Description
relativePath Path of the IDirectory to get, relative to this IDirectory

Returns:

IDirectory

The requested IDirectory

has

Checks whether the given key exists in this IDirectory.

Signature:

has(key: string): boolean;

Parameters

List of parameters
Parameter Type Description
key The key to check

Returns:

True if the key exists, false otherwise

hasSubDirectory

Checks whether this directory has a child directory with the given name.

Signature:

hasSubDirectory(subdirName: string): boolean;

Parameters

List of parameters
Parameter Type Description
subdirName Name of the child directory to check

Returns:

True if it exists, false otherwise

keys

Get an iterator over the keys under this IDirectory.

Signature:

keys(): IterableIterator<string>;

Returns:

The iterator

set

Sets the value stored at key to the provided value.

Signature:

set<T = any>(key: string, value: T): this;

Parameters

List of parameters
Parameter Type Description
key Key to set at
value Value to set

Returns:

The IDirectory itself

subdirectories

Gets an iterator over the IDirectory children of this IDirectory.

Signature:

subdirectories(): IterableIterator<[string, IDirectory]>;

Returns:

IDirectory

The IDirectory iterator

values

Get an iterator over the values under this IDirectory.

Signature:

values(): IterableIterator<any>;

Returns:

The iterator