@fluid-experimental/odsp-client
TypeScript icon, indicating that this package has built-in type declarations

2.0.0-dev.7.4.0.215366 • Public • Published

@fluid-experimental/odsp-client

The odsp-client package provides a simple and powerful way to consume collaborative Fluid data with the ODSP as a storage mechanism. Please note that odsp-client is currently an experimental package. We'd love for you to try it out and provide feedback but it is not yet recommended/supported for production scnearios.

Using odsp-client

The odsp-client package has an `OdspClient`` class that allows you to interact with Fluid

import { OdspClient } from "@fluid-experimental/odsp-client";

Example usage

import { OdspClient, OdspConnectionConfig, OdspClientProps } from "@fluid-experimental/odsp-client";

const connectionConfig: OdspConnectionConfig = {
	tokenProvider: "<YOUR_TOKEN_PROVIDER>",
	siteUrl: "<SITE_URL>",
	driveId: "<RAAS_DRIVE_ID>",
	path: "<FOLDER_PATH>",
};

export const clientProps: OdspClientProps = {
	connection: connectionConfig,
};

const client = new OdspClient(clientProps);

Experimental Features

OdspClient could be instantiated with experimental features. These features are experimental in nature and should NOT be used in production applications. To learn more, see Experimental Features.

Fluid Containers

A Container instance is a organizational unit within Fluid. Each Container instance has a connection to the defined Fluid Service and contains a collection of collaborative objects.

Containers are created and identified by unique IDs. Management and storage of these IDs are the responsibility of the developer.

Defining Fluid Containers

Fluid Containers are defined by a schema. The schema includes initial properties of the Container as well as what collaborative objects can be dynamically created.

const containerSchema = {
	initialObjects: {
		/* ... */
	},
	dynamicObjectTypes: [
		/*...*/
	],
};
const odspClient = new OdspClient(clientProps);
const { container, services } = await OdspClient.createContainer(containerSchema);

const itemId = await container.attach();
const attributes = await services.tenantAttributes();
const sharingUrl = attributes.sharingUrl;
const driveId = attributes.driveId;

Using Fluid Containers

Using the OdspClient class the developer can create and get Fluid containers. Because Fluid needs to be connected to a server, containers need to be created and retrieved asynchronously.

import { OdspClient } from "@fluid-experimental/odsp-client";

const odspClient = new OdspClient(props);
const { container, services } = await OdspClient.getContainer("_unique-id_", schema);

Using initial objects

The most common way to use Fluid is through initial collaborative objects that are created when the Container is created. Distributed data structures and DataObjects are both supported types of collaborative objects.

initialObjects are loaded into memory when the Container is loaded and the developer can access them via the Container's initialObjects property. The initialObjects property has the same signature as the Container schema.

// Define the keys and types of the initial list of collaborative objects.
// Here, we are using a SharedMap DDS on key "map1" and a SharedString on key "text1".
const schema = {
	initialObjects: {
		map1: SharedMap,
		text1: SharedString,
	},
};

// Fetch back the container that had been created earlier with the same url and schema
const { container, services } = await OdspClient.getContainer("_unique-url_", schema);

// Get our list of initial objects that we had defined in the schema. initialObjects here will have the same signature
const initialObjects = container.initialObjects;
// Use the keys that we had set in the schema to load the individual objects
const map1 = initialObjects.map1;
const text1 = initialObjects.text1;

/@fluid-experimental/odsp-client/

    Package Sidebar

    Install

    npm i @fluid-experimental/odsp-client

    Weekly Downloads

    88

    Version

    2.0.0-dev.7.4.0.215366

    License

    MIT

    Unpacked Size

    84.4 kB

    Total Files

    44

    Last publish

    Collaborators

    • ms-fluid-bot