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

Constructor Description
(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

Method Return Type Description
create(runtime, id) SharedDirectory Create a new shared directory
getFactory() IChannelFactory Get a factory for SharedDirectory to register with the data store.

Properties

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

Methods

Method Return Type Description
[Symbol.iterator]() IterableIterator<[string, any]> Get an iterator over the entries under this IDirectory.
clear() void Deletes all keys from within this IDirectory.
countSubDirectory() number Get the number of sub directory within the directory.
createSubDirectory(subdirName) IDirectory Creates an IDirectory child of this IDirectory, or retrieves the existing IDirectory child if one with the same name already exists.
delete(key) boolean Deletes the given key from within this IDirectory.
deleteSubDirectory(subdirName) boolean Deletes 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) void Issue a callback on each entry under this IDirectory.
get(key) T | undefined Retrieves the value stored at the given key from the directory.
getSubDirectory(subdirName) IDirectory | undefined Gets an IDirectory child of this IDirectory, if it exists.
getWorkingDirectory(relativePath) IDirectory | undefined Get an IDirectory within the directory, in order to use relative paths from that location.
has(key) boolean Checks whether the given key exists in this IDirectory.
hasSubDirectory(subdirName) boolean Checks 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) this Sets 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.

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
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);

Parameters

Parameter Type Description
id string String identifier for the SharedDirectory
runtime IFluidDataStoreRuntime Data store runtime
attributes IChannelAttributes

Property Details

[Symbol.toStringTag]

String representation for the class.

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
[Symbol.toStringTag]: string;

Type: string

absolutePath

The absolute path of the directory.

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
get absolutePath(): string;

Type: string

disposed

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
get disposed(): boolean;

Type: boolean

size

The number of entries under this IDirectory.

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
get size(): number;

Type: number

Method Details

[Symbol.iterator]

Get an iterator over the entries under this IDirectory.

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
[Symbol.iterator](): IterableIterator<[string, any]>;

Returns

The iterator

Return type: IterableIterator<[string, any]>

clear

Deletes all keys from within this IDirectory.

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
clear(): void;

countSubDirectory

Get the number of sub directory within the directory.

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
countSubDirectory(): number;

Returns

The number of sub directory within a directory.

Return type: number

create

Create a new shared directory

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
static create(runtime: IFluidDataStoreRuntime, id?: string): SharedDirectory;

Parameters

Parameter Modifiers Type Description
runtime IFluidDataStoreRuntime Data store runtime the new shared directory belongs to
id optional string Optional 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.

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
createSubDirectory(subdirName: string): IDirectory;

Parameters

Parameter Type Description
subdirName string Name 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.

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
delete(key: string): boolean;

Parameters

Parameter Type Description
key string The 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.

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
deleteSubDirectory(subdirName: string): boolean;

Parameters

Parameter Type Description
subdirName string Name 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

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
dispose(error?: Error): void;

Parameters

Parameter Modifiers Type Description
error optional Error

entries

Get an iterator over the entries under this IDirectory.

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
entries(): IterableIterator<[string, any]>;

Returns

The iterator

Return type: IterableIterator<[string, any]>

forEach

Issue a callback on each entry under this IDirectory.

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
forEach(callback: (value: any, key: string, map: Map<string, any>) => void): void;

Parameters

Parameter Type Description
callback (value: any, key: string, map: Map<string, any>) => void Callback to issue

get

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

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
get<T = any>(key: string): T | undefined;
Type Parameters
Parameter Default Description
T any

Parameters

Parameter Type Description
key string Key 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.

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
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.

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
getSubDirectory(subdirName: string): IDirectory | undefined;

Parameters

Parameter Type Description
subdirName string Name 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.

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
getWorkingDirectory(relativePath: string): IDirectory | undefined;

Parameters

Parameter Type Description
relativePath string Path 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.

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
has(key: string): boolean;

Parameters

Parameter Type Description
key string The 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.

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
hasSubDirectory(subdirName: string): boolean;

Parameters

Parameter Type Description
subdirName string Name 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.

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
keys(): IterableIterator<string>;

Returns

The iterator

Return type: IterableIterator<string>

set

Sets the value stored at key to the provided value.

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
set<T = any>(key: string, value: T): this;
Type Parameters
Parameter Default Description
T any

Parameters

Parameter Type Description
key string Key to set at
value T Value to set

Returns

The IDirectory itself

Return type: this

subdirectories

Gets an iterator over the IDirectory children of this IDirectory.

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
subdirectories(): IterableIterator<[string, IDirectory]>;

Returns

The IDirectory iterator

Return type: IterableIterator<[string, IDirectory]>

values

Get an iterator over the values under this IDirectory.

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
values(): IterableIterator<any>;

Returns

The iterator

Return type: IterableIterator<any>