Class: Items
appLib/SDKDrivers/xFrameDriver/items.Items
Items repository.
The Items class allows you to manage items in datasets.
Hierarchy
-
Repository
↳
Items
Implements
Table of contents
Constructors
Methods
Constructors
constructor
• new Items(agent
)
Creates an instance of Repository.
Parameters
Name | Type |
---|---|
agent |
PeerAgent |
Inherited from
Methods
countByQuery
▸ countByQuery(query
, options?
): Promise
<number
>
Counts the number of items by query.
Example
await dl.items.countByQuery({
"resource": "items",
"filter": {
"$and": [
{
"annotated": true
},
{
"hidden": false
},
{
"type": "file"
}
]
}
})
Parameters
Name | Type | Description |
---|---|---|
query |
DqlObj |
The query to count by. |
options |
Object |
- |
options.timeout? |
number |
- |
Returns
Promise
<number
>
Implementation of
IBundle.countByQuery
create
▸ create(payload
, options?
): Promise
<SDKItem
>
Creates a new item in the Items repository.
Example
const file = new File(['content'], 'filename.txt', { type: 'text/plain' });
const itemPayload = {
file: file,
path: 'path/to/item',
metadata: {
key: 'value'
},
binaries: true
};
const item = await sdk.items.create(itemPayload);
Parameters
Name | Type | Description |
---|---|---|
payload |
Object |
The payload for the item. |
payload.binaries? |
boolean |
Whether to upload the item to the Binaries dataset. |
payload.datasetId? |
string |
The id of the dataset to create the item in. |
payload.file |
File |
The file to upload. |
payload.metadata? |
any |
The metadata to add to the item. |
payload.overwrite? |
boolean |
Whether to overwrite the item if it already exists. |
payload.path? |
string |
The path to the item. |
options |
Object |
|
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<SDKItem
>
- A promise that resolves with the created item.
Implementation of
IBundle.create
crudReq
▸ crudReq(data
): void
Sends a CRUD request to the xFrame.
Parameters
Name | Type |
---|---|
data |
any |
Returns
void
Inherited from
crudReqSync
▸ crudReqSync(data
, options?
): Promise
<any
>
Sends a CRUD request to the xFrame.
Parameters
Name | Type | Description |
---|---|---|
data |
any |
The data to send. |
options |
Object |
|
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<any
>
Inherited from
delete
▸ delete(payload?
): Promise
<void
>
Deletes an item from the repository. If the itemId is not provided, the active itemId is used. If the datasetId is not provided, the active datasetId is used.
Example
// delete an item with ID 'item1' in dataset with ID 'dataset1'
await dl.items.delete({ itemId: 'item1', datasetId: 'dataset1' });
Parameters
Name | Type | Description |
---|---|---|
payload? |
Object |
The payload containing the itemId and datasetId of the item to be deleted. |
payload.datasetId? |
string |
- |
payload.itemId |
string |
- |
Returns
Promise
<void
>
- A promise that resolves once the item is deleted.
Implementation of
IBundle.delete
fetch
▸ fetch(id?
, options?
): Promise
<any
>
Fetches the raw contents of an item by id. When the id is not provided, it uses the active item.
Example
// Given a text file with the contents "hello world"
const rawItem = await dl.items.fetch('a-txt-file-id')
console.log(rawItem)
// logs: "hello world"
Parameters
Name | Type | Description |
---|---|---|
id? |
string |
The id of the item to be fetched. |
options |
Object |
|
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<any
>
- A promise that resolves to the content data.
Implementation of
IBundle.fetch
get
▸ get(id?
, options?
): Promise
<SDKItem
>
Gets an item by id. When the id is not provided, it returns the active item.
Example
const activeItem = await dl.items.get()
Example
const item = await dl.items.get('item-id-123')
Parameters
Name | Type | Description |
---|---|---|
id? |
string |
The id of the item to retrieve. |
options |
Object |
|
options.signed? |
boolean |
an option to fetch the item stream by signed url. |
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<SDKItem
>
- A promise that resolves to the item data.
Implementation of
IBundle.get
getByName
▸ getByName(name?
, options?
): Promise
<SDKItem
>
Gets an item by name. When the name is not provided, it returns the active item.
Parameters
Name | Type | Description |
---|---|---|
name? |
string |
The name of the item to retrieve. |
options |
Object |
- |
options.binaries? |
boolean |
get the item from the binaries dataset. |
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<SDKItem
>
- A promise that resolves to the item data.
Implementation of
IBundle.getByName
query
▸ query(payload?
, options?
): Promise
<IPagedResponse
<SDKItem
>>
Lists all items by filter. When no payload is provided, it returns all the items in the active dataset.
Example
const pagedResponse = await dl.items.query()
const itemsArray = pagedResponse.items
Parameters
Name | Type | Description |
---|---|---|
payload? |
Object |
contains DQL filter. |
payload.filter |
DQL <SDKItem > |
- |
options |
Object |
|
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<IPagedResponse
<SDKItem
>>
- Returns a Promise that resolves to a paged response object of items.
Implementation of
IBundle.query
stream
▸ stream(url?
, options?
): Promise
<string
>
Retrieves the stream of an item by an item's stream URL.
Example
const stream = await dl.items.stream('https://gate.dataloop.ai/api/v1/items/item-id/stream')
Parameters
Name | Type | Description |
---|---|---|
url? |
string |
The stream url of the item. |
options |
Object |
|
options.signed? |
boolean |
an option to fetch the item stream by signed url. |
options.timeout? |
number |
- |
Returns
Promise
<string
>
- A promise that resolves to the stream's string.
Implementation of
IBundle.stream
update
▸ update(fieldsToUpdate
, options?
): Promise
<SDKItem
>
Update an existing item.
Example
const updatedItem = await dl.items.update({
id: "item-1",
name: "Updated item name"
})
Parameters
Name | Type | Description |
---|---|---|
fieldsToUpdate |
Partial <SDKItem > & { system? : boolean } |
The fields to update on the item. |
options |
Object |
|
options.timeout? |
number |
an option to set the timeout for the request. |
Returns
Promise
<SDKItem
>
- The updated item.
Implementation of
IBundle.update