Creates a new Drive instance
Initializes a drive with the provided configuration data and optional URI. The drive represents a container for organizing files and documents.
Drive configuration data
Optionaluri: stringOptional URI path for the drive endpoint. Defaults to '/drive'
Get the drive's items collection
This getter provides access to the drive's items through the DriveItems collection. It enables management of all files and documents within the drive.
DriveItems collection for managing drive items
Get the drive's upload jobs collection
This getter provides access to the drive's upload jobs through the UploadJobs collection. It enables management of all upload jobs for the drive.
Get the drive's vector indexes collection
This getter provides access to the drive's vector indexes through the VectorIndexes collection. It enables management of all vector indexes associated with this drive.
VectorIndexes collection for managing vector indexes
Get the access control functionality for this drive
This getter provides access to the drive's access control methods through the Access class. It allows for granting and revoking permissions to users, org users, agents, and clients.
Available roles for drives: READ_ONLY, VIEWER, CONTRIBUTOR, EDITOR, MANAGER
An Access instance configured for this drive
Grant access with different roles:
const drive = await client.drives.get({}, driveId);
// Grant viewer role (read-only)
await drive.access.grantByRole({ org_user: 'orguser123' }, 'VIEWER');
// Grant editor role (read, create, update)
await drive.access.grantByRole({ org_user: 'orguser123' }, 'EDITOR');
// Grant manager role (full access)
await drive.access.grantByRole({ org_user: 'orguser123' }, 'MANAGER');
Grant access with cascade to items:
const drive = await client.drives.get({}, driveId);
// Grant manager role and cascade to all items
await drive.access.grantByRole(
{ org_user: 'orguser123' },
'MANAGER',
{ cascade_to_items: true }
);
// Cascade only to folders
await drive.access.grantByRole(
{ org_user: 'orguser123' },
'EDITOR',
{ cascade_to_folders: true }
);
List all accessors:
const drive = await client.drives.get({}, driveId);
const result = await drive.access.list();
console.log(`Drive has ${result.accessors.length} accessors`);
result.accessors.forEach(accessor => {
console.log(`${accessor.accessor_type}: ${accessor.accessor_id} - ${accessor.role}`);
});
Revoke access:
const drive = await client.drives.get({}, driveId);
// Revoke all access from a user
const result = await drive.access.revoke({ org_user: 'orguser123' });
console.log(`Revoked ${result.revoked_count} permissions`);
// Revoke all access from an agent
const agent = await client.agents.get({}, agentId);
const result = await drive.access.revoke({ agent: agent });
console.log(`Removed ${result.revoked_count} permissions`);
Check if the entity is active
This method checks the active status of the entity. Most entities in the system can be active or inactive, which affects their availability and usability in the platform.
True if the entity is active, false otherwise
Convert model instance to interface data
This method serializes the model instance to a plain object that matches the interface type. This is useful for:
The model data as a plain object matching the interface type
Convert model instance to API payload
This method creates a payload suitable for API requests by:
A clean object suitable for API requests
Update model data with new values
This method updates the model's data and instance properties with new values. It performs a shallow merge of the updates with existing data, allowing for partial updates of the model's properties.
Object containing properties to update
const user = new User({
email: 'old@example.com',
firstName: 'John'
});
// Update multiple properties
user.update({
email: 'new@example.com',
lastName: 'Doe'
});
// Save changes to API
await user.save();
This method only updates the local model instance. To persist changes to the API, call save after updating.
Save the model instance to the API
This method persists the current state of the model to the API using a PUT request. It requires the model to have an ID (existing instance). For new instances, use the collection's create method instead.
The method:
Promise resolving to the updated model data
Delete the model instance from the API
This method permanently deletes the model instance from the API and clears the local data. This operation cannot be undone.
The method:
Optionalparams: objectOptional query parameters for deletion (e.g., { delete: true, deleteS3: true })
Promise that resolves when deletion is successful
Basic deletion:
const user = await users.get({}, 'user-id');
if (user) {
await user.delete();
// User is now deleted and instance is cleared
}
Find a drive item or directory by URL path within this drive
Convenience method that wraps DriveItems.findByPath() for this drive instance. Resolves a URL path to a drive item by traversing the folder hierarchy. If the path resolves to a directory, returns an array of all items within that directory. If the path resolves to a file, returns a single DriveItem.
URL path like '/documents/report.pdf' or '/folder1/subfolder/file.txt'
Optionaloptions: { caseSensitive?: boolean }Optional options for path resolution
OptionalcaseSensitive?: booleanWhether name matching is case-sensitive (default: true)
Promise resolving to DriveItem for files, DriveItem[] for directories, or null if not found
Find a file by path:
const drive = await client.drives.get({}, driveId);
const item = await drive.findItemByPath('/documents/report.pdf');
if (item) {
console.log('Found file:', item.name);
}
Find a directory (returns array):
const drive = await client.drives.get({}, driveId);
const items = await drive.findItemByPath('/documents');
if (Array.isArray(items)) {
console.log(`Directory contains ${items.length} items`);
items.forEach(item => console.log(item.name));
}
Drive class for managing file storage drives
This class represents a drive in the Mosaia platform, which is a container for organizing and managing files and documents. Drives can be scoped to users or organizations.
Features:
Remarks
Drives provide:
Example
Basic drive setup:
Example
Managing drive items: