Creates a new Drive Items API client instance
Initializes the drive items client with the appropriate endpoint URI and model class for handling drive item operations.
The constructor sets up the API endpoint to /drive/:driveId/item (or ${uri}/drive/:driveId/item if a base URI is provided),
which corresponds to the Mosaia API's drive items endpoint.
Base URI path. Typically /drive/:driveId where :driveId is the drive ID.
If not provided, defaults to /drive/item.
Get entities with optional filtering and pagination
This method retrieves entities from the API. When called without an ID, it returns a list of entities with optional filtering and pagination. When called with an ID, it returns a specific entity.
Optional query parameters for filtering and pagination
Query parameters interface for API requests
Used to define common query parameters that can be passed to API endpoints for filtering, sorting, and pagination.
Additional custom query parameters
Optionalq?: stringSearch term for text-based filtering
Optionallimit?: numberMaximum number of items to return
Optionaloffset?: numberNumber of items to skip (for offset-based pagination)
Optionaltags?: string[]Array of tags to filter by
Optionalactive?: booleanFilter by active status
Optionalexternal_id?: stringFilter by external ID
Optional specific entity ID to retrieve
Promise resolving to:
- BatchAPIResponse
Get multiple entities with filtering:
const result = await collection.get({
limit: 10,
offset: 0,
q: 'search term',
active: true,
tags: ['tag1', 'tag2']
});
console.log('Items:', result.data);
console.log('Total:', result.paging?.total);
Get entities with optional filtering and pagination
This method retrieves entities from the API. When called without an ID, it returns a list of entities with optional filtering and pagination. When called with an ID, it returns a specific entity.
Optionalparams: QueryParamsOptional query parameters for filtering and pagination
Query parameters interface for API requests
Used to define common query parameters that can be passed to API endpoints for filtering, sorting, and pagination.
Additional custom query parameters
Optionalq?: stringSearch term for text-based filtering
Optionallimit?: numberMaximum number of items to return
Optionaloffset?: numberNumber of items to skip (for offset-based pagination)
Optionaltags?: string[]Array of tags to filter by
Optionalactive?: booleanFilter by active status
Optionalexternal_id?: stringFilter by external ID
Promise resolving to:
- BatchAPIResponse
Get multiple entities with filtering:
const result = await collection.get({
limit: 10,
offset: 0,
q: 'search term',
active: true,
tags: ['tag1', 'tag2']
});
console.log('Items:', result.data);
console.log('Total:', result.paging?.total);
Create a new entity
This method creates a new entity in the system. The entity ID will be automatically generated by the server. The method returns a new model instance initialized with the created entity's data.
Entity data for the new entity (without ID)
Promise resolving to a new model instance
Create a new user:
const newUser = await users.create({
email: 'user@example.com',
firstName: 'John',
lastName: 'Doe',
active: true
});
console.log('Created user:', newUser.id);
Update an existing entity
This method updates an existing entity in the system. Only the fields provided in the update data will be updated.
The entity ID to update
Partial entity data for the update (only provided fields will be updated)
Optionalparams: QueryParamsOptional query parameters for the request
Promise resolving to the updated model instance
Delete an entity
This method permanently deletes an entity from the system. This action cannot be undone.
The entity ID to delete
Optionalparams: QueryParamsOptional query parameters object. Can include:
force: Force deletion even if entity has dependencies (boolean)Promise that resolves when deletion is successful
Upload files to the drive using presigned URLs
Uploads one or more files to the drive using presigned URLs for direct S3 uploads. This method supports batch file uploads and directory uploads with structure preservation. The backend returns presigned URLs that you can use to upload files directly to S3.
Array of File objects to upload (required for file uploads)
Optionaloptions: {Optional upload options
Optionalpath?: stringBase path where files should be uploaded (defaults to '/')
OptionalrelativePaths?: string | string[]Array of relative paths for directory structure preservation
OptionalpreserveStructure?: booleanBoolean flag to enable/disable structure preservation (default: true if relativePaths provided)
Promise resolving to upload job information with presigned URLs
// Single file upload
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files[0];
const result = await items.uploadFiles([file], {
path: '/documents'
});
console.log('Upload job ID:', result.uploadJob.id);
// Upload each file to S3 using presignedUrl
for (const fileInfo of result.files) {
await fetch(fileInfo.presignedUrl, {
method: 'PUT',
body: file
});
}
Upload a single file to the drive
Convenience method for uploading a single file using presigned URLs for direct S3 upload.
File object to upload
Optionaloptions: { path?: string; relativePath?: string; preserveStructure?: boolean }Optional upload options
Optionalpath?: stringOptional path within the drive (defaults to '/')
OptionalrelativePath?: stringOptional relative path for the file
OptionalpreserveStructure?: booleanBoolean flag to enable/disable structure preservation
Promise resolving to upload job information with presigned URL
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files[0];
const result = await items.uploadFile(file, {
path: '/documents',
relativePath: 'folder/file.txt'
});
console.log('Upload job ID:', result.uploadJob.id);
// Upload file to S3 using presignedUrl
const fileInfo = result.files[0];
await fetch(fileInfo.presignedUrl, {
method: 'PUT',
body: file
});
Get upload job status
Retrieves the status of an asynchronous file upload job.
The upload job ID returned from uploadFile or uploadFiles
Promise resolving to upload job status information
Mark a file upload as failed
Marks a file upload as failed if the client-side upload to S3 fails. This method should be called if the upload to the presigned URL fails.
The file ID of the upload to mark as failed
Optionalerror: { error?: string; errorMessage?: string }Optional error message or object describing the failure
Promise resolving to the file status after marking as failed
try {
const result = await items.uploadFile(file);
const fileInfo = result.files[0];
// Try to upload to S3
const uploadResponse = await fetch(fileInfo.presignedUrl, {
method: 'PUT',
body: file
});
if (!uploadResponse.ok) {
// Mark as failed if S3 upload fails
await items.markUploadFailed(fileInfo.fileId, {
error: `Upload failed: ${uploadResponse.statusText}`
});
}
} catch (error) {
// Mark as failed if there's an exception
await items.markUploadFailed(fileInfo.fileId, {
error: error.message
});
}
Drive Items API client for the Mosaia SDK
Provides CRUD operations for managing drive items (files and documents) in the Mosaia platform. Drive items are files and documents stored within drives.
This class inherits from BaseCollection and provides the following functionality:
Example