Skip to main content
Version: v1

SharedDirectory Class

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.

Sealed

This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.

Signature

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

Extends: SharedObject<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

ConstructorDescription
(constructor)(id, runtime, attributes)Constructs a new shared directory. If the object is non-local an id and service interfaces will be provided.

Static Methods

MethodReturn TypeDescription
create(runtime, id)SharedDirectoryCreate a new shared directory
getFactory()IChannelFactoryGet a factory for SharedDirectory to register with the data store.

Properties

PropertyTypeDescription
[Symbol.toStringTag]stringString representation for the class.
absolutePathstringThe absolute path of the directory.
disposedboolean
sizenumberThe number of entries under this IDirectory.

Methods

MethodReturn TypeDescription
[Symbol.iterator]()IterableIterator<[string, any]>Get an iterator over the entries under this IDirectory.
clear()voidDeletes all keys from within this IDirectory.
countSubDirectory()numberGet the number of sub directory within the directory.
createSubDirectory(subdirName)IDirectoryCreates an IDirectory child of this IDirectory, or retrieves the existing IDirectory child if one with the same name already exists.
delete(key)booleanDeletes the given key from within this IDirectory.
deleteSubDirectory(subdirName)booleanDeletes an IDirectory child of this IDirectory, if it exists, along with all descendent keys and directories.
dispose(error)void
entries()IterableIterator<[string, any]>Get an iterator over the entries under this IDirectory.
forEach(callback)voidIssue a callback on each entry under this IDirectory.
get(key)T | undefinedRetrieves the value stored at the given key from the directory.
getSubDirectory(subdirName)IDirectory | undefinedGets an IDirectory child of this IDirectory, if it exists.
getWorkingDirectory(relativePath)IDirectory | undefinedGet an IDirectory within the directory, in order to use relative paths from that location.
has(key)booleanChecks whether the given key exists in this IDirectory.
hasSubDirectory(subdirName)booleanChecks whether this directory has a child directory with the given name.
keys()IterableIterator<string>Get an iterator over the keys under this IDirectory.
set(key, value)thisSets the value stored at key to the provided value.
subdirectories()IterableIterator<[string, IDirectory]>Gets an iterator over the IDirectory children of this IDirectory.
values()IterableIterator<any>Get an iterator over the values under this IDirectory.

Constructor Details

(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

ParameterTypeDescription
idstringString identifier for the SharedDirectory
runtimeIFluidDataStoreRuntimeData store runtime
attributesIChannelAttributes

Property Details

[Symbol.toStringTag]

String representation for the class.

Signature

[Symbol.toStringTag]: string;

Type: string

absolutePath

The absolute path of the directory.

Signature

get absolutePath(): string;

Type: string

disposed

Signature

get disposed(): boolean;

Type: boolean

size

The number of entries under this IDirectory.

Signature

get size(): number;

Type: number

Method Details

[Symbol.iterator]

Get an iterator over the entries under this IDirectory.

Signature

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

Returns

The iterator

Return type: IterableIterator<[string, any]>

clear

Deletes all keys from within this IDirectory.

Signature

clear(): void;

countSubDirectory

Get the number of sub directory within the directory.

Signature

countSubDirectory(): number;

Returns

The number of sub directory within a directory.

Return type: number

create

Create a new shared directory

Signature

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

Parameters

ParameterModifiersTypeDescription
runtimeIFluidDataStoreRuntimeData store runtime the new shared directory belongs to
idoptionalstringOptional name of the shared directory

Returns

Newly create shared directory (but not attached yet)

Return type: SharedDirectory

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

ParameterTypeDescription
subdirNamestringName of the new child directory to create

Returns

The IDirectory child that was created or retrieved

Return type: IDirectory

delete

Deletes the given key from within this IDirectory.

Signature

delete(key: string): boolean;

Parameters

ParameterTypeDescription
keystringThe key to delete

Returns

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

Return type: boolean

deleteSubDirectory

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

Signature

deleteSubDirectory(subdirName: string): boolean;

Parameters

ParameterTypeDescription
subdirNamestringName of the child directory to delete

Returns

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

Return type: boolean

dispose

Signature

dispose(error?: Error): void;

Parameters

ParameterModifiersTypeDescription
erroroptionalError

entries

Get an iterator over the entries under this IDirectory.

Signature

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

Returns

The iterator

Return type: IterableIterator<[string, any]>

forEach

Issue a callback on each entry under this IDirectory.

Signature

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

Parameters

ParameterTypeDescription
callback(value: any, key: string, map: Map<string, any>) => voidCallback to issue

get

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

Signature

get<T = any>(key: string): T | undefined;
Type Parameters
ParameterDefaultDescription
Tany

Parameters

ParameterTypeDescription
keystringKey to retrieve from

Returns

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

Return type: T | undefined

getFactory

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

Signature

static getFactory(): IChannelFactory;

Returns

A factory that creates and load SharedDirectory

Return type: IChannelFactory

getSubDirectory

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

Signature

getSubDirectory(subdirName: string): IDirectory | undefined;

Parameters

ParameterTypeDescription
subdirNamestringName of the child directory to get

Returns

The requested IDirectory

Return type: IDirectory | undefined

getWorkingDirectory

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

Signature

getWorkingDirectory(relativePath: string): IDirectory | undefined;

Parameters

ParameterTypeDescription
relativePathstringPath of the IDirectory to get, relative to this IDirectory

Returns

The requested IDirectory

Return type: IDirectory | undefined

has

Checks whether the given key exists in this IDirectory.

Signature

has(key: string): boolean;

Parameters

ParameterTypeDescription
keystringThe key to check

Returns

True if the key exists, false otherwise

Return type: boolean

hasSubDirectory

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

Signature

hasSubDirectory(subdirName: string): boolean;

Parameters

ParameterTypeDescription
subdirNamestringName of the child directory to check

Returns

True if it exists, false otherwise

Return type: boolean

keys

Get an iterator over the keys under this IDirectory.

Signature

keys(): IterableIterator<string>;

Returns

The iterator

Return type: IterableIterator<string>

set

Sets the value stored at key to the provided value.

Signature

set<T = any>(key: string, value: T): this;
Type Parameters
ParameterDefaultDescription
Tany

Parameters

ParameterTypeDescription
keystringKey to set at
valueTValue to set

Returns

The IDirectory itself

Return type: this

subdirectories

Gets an iterator over the IDirectory children of this IDirectory.

Signature

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

Returns

The IDirectory iterator

Return type: IterableIterator<[string, IDirectory]>

values

Get an iterator over the values under this IDirectory.

Signature

values(): IterableIterator<any>;

Returns

The iterator

Return type: IterableIterator<any>