@autonomys/auto-drive 0.7.3 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +44 -137
  2. package/dist/api/calls/download.d.ts +6 -0
  3. package/dist/api/calls/download.d.ts.map +1 -0
  4. package/dist/api/calls/download.js +12 -0
  5. package/dist/api/calls/index.d.ts +5 -0
  6. package/dist/api/calls/index.d.ts.map +1 -0
  7. package/dist/api/calls/index.js +4 -0
  8. package/dist/api/calls/read.d.ts +98 -0
  9. package/dist/api/calls/read.d.ts.map +1 -0
  10. package/dist/api/calls/read.js +140 -0
  11. package/dist/api/calls/upload.d.ts +94 -0
  12. package/dist/api/calls/upload.d.ts.map +1 -0
  13. package/dist/api/calls/upload.js +120 -0
  14. package/dist/api/calls/write.d.ts +49 -0
  15. package/dist/api/calls/write.d.ts.map +1 -0
  16. package/dist/api/calls/write.js +65 -0
  17. package/dist/api/connection.d.ts +8 -0
  18. package/dist/api/connection.d.ts.map +1 -0
  19. package/dist/api/connection.js +17 -0
  20. package/dist/api/index.d.ts +5 -0
  21. package/dist/api/index.d.ts.map +1 -0
  22. package/dist/api/index.js +4 -0
  23. package/dist/api/models/folderTree.d.ts +45 -0
  24. package/dist/api/models/folderTree.d.ts.map +1 -0
  25. package/dist/api/models/folderTree.js +56 -0
  26. package/dist/api/models/index.d.ts +3 -0
  27. package/dist/api/models/index.d.ts.map +1 -0
  28. package/dist/api/models/index.js +2 -0
  29. package/dist/api/models/objects.d.ts +41 -0
  30. package/dist/api/models/objects.d.ts.map +1 -0
  31. package/dist/api/models/objects.js +10 -0
  32. package/dist/api/models/uploads.d.ts +114 -0
  33. package/dist/api/models/uploads.d.ts.map +1 -0
  34. package/dist/api/models/uploads.js +40 -0
  35. package/dist/api/wrappers.d.ts +67 -0
  36. package/dist/api/wrappers.d.ts.map +1 -0
  37. package/dist/api/wrappers.js +158 -0
  38. package/dist/index.d.ts +2 -3
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -3
  41. package/dist/utils/async.d.ts +3 -0
  42. package/dist/utils/async.d.ts.map +1 -0
  43. package/dist/utils/async.js +21 -0
  44. package/dist/utils/folder.d.ts +2 -0
  45. package/dist/utils/folder.d.ts.map +1 -0
  46. package/dist/utils/folder.js +14 -0
  47. package/dist/utils/index.d.ts +5 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +4 -0
  50. package/dist/utils/stream.d.ts +3 -0
  51. package/dist/utils/stream.d.ts.map +1 -0
  52. package/dist/utils/stream.js +22 -0
  53. package/dist/utils/types.d.ts +6 -0
  54. package/dist/utils/types.d.ts.map +1 -0
  55. package/package.json +11 -32
  56. package/src/api/calls/download.ts +21 -0
  57. package/src/api/calls/index.ts +4 -0
  58. package/src/api/calls/read.ts +194 -0
  59. package/src/api/calls/upload.ts +198 -0
  60. package/src/api/calls/write.ts +88 -0
  61. package/src/api/connection.ts +32 -0
  62. package/src/api/index.ts +4 -0
  63. package/src/api/models/folderTree.ts +77 -0
  64. package/src/api/models/index.ts +2 -0
  65. package/src/api/models/objects.ts +47 -0
  66. package/src/api/models/uploads.ts +49 -0
  67. package/src/api/wrappers.ts +229 -0
  68. package/src/index.ts +2 -3
  69. package/src/utils/async.ts +29 -0
  70. package/src/utils/folder.ts +15 -0
  71. package/src/utils/index.ts +4 -0
  72. package/src/utils/stream.ts +25 -0
  73. package/src/utils/types.ts +6 -0
  74. package/tsconfig.json +3 -1
  75. package/LICENSE +0 -18
  76. package/dist/cid/index.d.ts +0 -9
  77. package/dist/cid/index.d.ts.map +0 -1
  78. package/dist/cid/index.js +0 -20
  79. package/dist/ipld/builders.d.ts +0 -11
  80. package/dist/ipld/builders.d.ts.map +0 -1
  81. package/dist/ipld/builders.js +0 -13
  82. package/dist/ipld/chunker.d.ts +0 -32
  83. package/dist/ipld/chunker.d.ts.map +0 -1
  84. package/dist/ipld/chunker.js +0 -195
  85. package/dist/ipld/index.d.ts +0 -5
  86. package/dist/ipld/index.d.ts.map +0 -1
  87. package/dist/ipld/index.js +0 -4
  88. package/dist/ipld/nodes.d.ts +0 -15
  89. package/dist/ipld/nodes.d.ts.map +0 -1
  90. package/dist/ipld/nodes.js +0 -89
  91. package/dist/ipld/utils.d.ts +0 -8
  92. package/dist/ipld/utils.d.ts.map +0 -1
  93. package/dist/ipld/utils.js +0 -50
  94. package/dist/metadata/index.d.ts +0 -3
  95. package/dist/metadata/index.d.ts.map +0 -1
  96. package/dist/metadata/index.js +0 -2
  97. package/dist/metadata/offchain/base.d.ts +0 -4
  98. package/dist/metadata/offchain/base.d.ts.map +0 -1
  99. package/dist/metadata/offchain/file.d.ts +0 -16
  100. package/dist/metadata/offchain/file.d.ts.map +0 -1
  101. package/dist/metadata/offchain/file.js +0 -12
  102. package/dist/metadata/offchain/folder.d.ts +0 -20
  103. package/dist/metadata/offchain/folder.d.ts.map +0 -1
  104. package/dist/metadata/offchain/folder.js +0 -26
  105. package/dist/metadata/offchain/index.d.ts +0 -4
  106. package/dist/metadata/offchain/index.d.ts.map +0 -1
  107. package/dist/metadata/offchain/index.js +0 -3
  108. package/dist/metadata/onchain/index.d.ts +0 -3
  109. package/dist/metadata/onchain/index.d.ts.map +0 -1
  110. package/dist/metadata/onchain/index.js +0 -2
  111. package/dist/metadata/onchain/protobuf/OnchainMetadata.d.ts +0 -28
  112. package/dist/metadata/onchain/protobuf/OnchainMetadata.d.ts.map +0 -1
  113. package/dist/metadata/onchain/protobuf/OnchainMetadata.js +0 -112
  114. package/dist/metadata/onchain/utils.d.ts +0 -4
  115. package/dist/metadata/onchain/utils.d.ts.map +0 -1
  116. package/dist/metadata/onchain/utils.js +0 -12
  117. package/jest.config.ts +0 -17
  118. package/src/cid/index.ts +0 -26
  119. package/src/ipld/builders.ts +0 -38
  120. package/src/ipld/chunker.ts +0 -194
  121. package/src/ipld/index.ts +0 -4
  122. package/src/ipld/nodes.ts +0 -199
  123. package/src/ipld/utils.ts +0 -21
  124. package/src/metadata/index.ts +0 -2
  125. package/src/metadata/offchain/base.ts +0 -4
  126. package/src/metadata/offchain/file.ts +0 -35
  127. package/src/metadata/offchain/folder.ts +0 -51
  128. package/src/metadata/offchain/index.ts +0 -3
  129. package/src/metadata/onchain/index.ts +0 -2
  130. package/src/metadata/onchain/protobuf/OnchainMetadata.proto +0 -21
  131. package/src/metadata/onchain/protobuf/OnchainMetadata.ts +0 -137
  132. package/src/metadata/onchain/utils.ts +0 -15
  133. package/tests/chunker.spec.ts +0 -294
  134. package/tests/cid.spec.ts +0 -20
  135. package/tests/nodes.spec.ts +0 -74
  136. /package/dist/{metadata/offchain/base.js → utils/types.js} +0 -0
package/README.md CHANGED
@@ -1,167 +1,74 @@
1
- # Auto-Drive
1
+ # auto-drive
2
2
 
3
- ![Autonomys Banner](https://github.com/autonomys/auto-sdk/blob/main/.github/images/autonomys-banner.webp)
3
+ ## auto-drive API Tools
4
4
 
5
- [![Latest Github release](https://img.shields.io/github/v/tag/autonomys/auto-sdk.svg)](https://github.com/autonomys/auto-sdk/tags)
6
- [![Build status of the main branch on Linux/OSX](https://img.shields.io/github/actions/workflow/status/autonomys/auto-sdk/build.yaml?branch=main&label=Linux%2FOSX%20build)](https://github.com/autonomys/auto-sdk/actions/workflows/build.yaml)
7
- [![npm version](https://badge.fury.io/js/@autonomys%2Fauto-drive.svg)](https://badge.fury.io/js/@autonomys/auto-drive)
5
+ The `auto-drive` package provides a set of tools to interact with the auto-drive API. Below are some key functionalities:
8
6
 
9
- ## Overview
7
+ ### Installation
10
8
 
11
- The **Autonomys Auto Drive SDK** (`@autonomys/auto-drive`) provides utilities for creating and managing IPLD DAGs (InterPlanetary Linked Data Directed Acyclic Graphs) for files and folders. It facilitates chunking large files, handling metadata, and creating folder structures suitable for distributed storage systems like IPFS.
12
-
13
- ## Features
14
-
15
- - **File Chunking and DAG Creation**: Efficiently split large files into smaller chunks and create IPLD DAGs.
16
- - **Folder Structure Creation**: Generate IPLD DAGs for directory structures.
17
- - **Metadata Handling**: Add and manage metadata for files and folders.
18
- - **CID Management**: Utilities for working with Content Identifiers (CIDs).
19
- - **TypeScript Support**: Fully typed for enhanced developer experience.
20
-
21
- ## Installation
22
-
23
- You can install Auto-Drive using npm or yarn:
24
-
25
- ```bash
26
- npm install @autonomys/auto-drive
27
- ```
28
-
29
- or
9
+ To install the package, use the following command:
30
10
 
31
11
  ```bash
32
12
  yarn add @autonomys/auto-drive
33
13
  ```
34
14
 
35
- ## Usage
15
+ ### How to use it?
36
16
 
37
- ### Creating an IPLD DAG from a File
17
+ ### Example Usage
38
18
 
39
- To create an IPLD DAG from a file, you can use the `createFileIPLDDag` function:
19
+ Here is an example of how to use the `uploadFile` method to upload a file with optional encryption and compression:
40
20
 
41
21
  ```typescript
42
- import { createFileIPLDDag } from '@autonomys/auto-drive'
43
- import fs from 'fs'
44
-
45
- const fileBuffer = fs.readFileSync('path/to/your/file.txt')
46
-
47
- const dag = createFileIPLDDag(fileBuffer, 'file.txt')
48
- ```
49
-
50
- ### Creating an IPLD DAG from a Folder
51
-
52
- To create an IPLD DAG from a folder, you can use the `createFolderIPLDDag` function:
22
+ import { uploadFile } from '@autonomys/auto-drive'
53
23
 
54
- ```typescript
55
- import { createFolderIPLDDag } from '@autonomys/auto-drive'
56
- import { CID } from 'multiformats'
57
-
58
- // Example child CIDs and folder information
59
- const childCIDs: CID[] = [
60
- /* array of CIDs */
61
- ]
62
- const folderName = 'my-folder'
63
- const folderSize = 1024 // size in bytes
64
-
65
- const folderDag = createFolderIPLDDag(childCIDs, folderName, folderSize)
66
- ```
67
-
68
- ### Working with CIDs
69
-
70
- You can use functions from the `cid` module to work with CIDs:
71
-
72
- ```typescript
73
- import { cidOfNode, cidToString, stringToCid } from '@autonomys/auto-drive'
74
-
75
- // Create a CID from a node
76
- const cid = cidOfNode(dag.head)
77
-
78
- // Convert the CID to a string
79
- const cidString = cidToString(cid)
80
-
81
- // Parse a string back into a CID
82
- const parsedCID = stringToCid(cidString)
83
- ```
84
-
85
- ### Encoding and Decoding Nodes
86
-
87
- You can encode and decode IPLD nodes:
88
-
89
- ```typescript
90
- import { encodeNode, decodeNode } from '@autonomys/auto-drive'
91
-
92
- // Encode a node
93
- const encodedNode = encodeNode(dag.head)
24
+ const api = new AutoDriveApi() // Initialize your API instance
25
+ const filePath = 'path/to/your/file.txt' // Specify the path to your file
26
+ const options = {
27
+ password: 'your-encryption-password', // Optional: specify a password for encryption
28
+ compression: true,
29
+ }
94
30
 
95
- // Decode a node
96
- const decodedNode = decodeNode(encodedNode)
31
+ uploadFile(api, filePath, options)
32
+ .then(() => {
33
+ console.log('File uploaded successfully!')
34
+ })
35
+ .catch((error) => {
36
+ console.error('Error uploading file:', error)
37
+ })
97
38
  ```
98
39
 
99
- ### Handling Metadata
40
+ ### Example Usage of Download
100
41
 
101
- To add metadata to a node, you can create a metadata node:
42
+ Here is an example of how to use the `downloadFile` method to download a file from the server:
102
43
 
103
44
  ```typescript
104
- import { createMetadataNode } from '@autonomys/auto-drive'
45
+ import { getRoots } from '@autonomys/auto-drive'
105
46
 
106
- const metadata = {
107
- name: 'My File',
108
- description: 'This is a sample file',
109
- // ... other metadata fields
110
- }
47
+ const api = new AutoDriveApi() // Initialize your API instance
111
48
 
112
- const metadataNode = createMetadataNode(metadata)
49
+ getRoots(api)
50
+ .then((roots) => {
51
+ console.log('Root directories:', roots)
52
+ })
53
+ .catch((error) => {
54
+ console.error('Error retrieving root directories:', error)
55
+ })
113
56
  ```
114
57
 
115
- ### Example: Creating a File DAG and Converting to CID
116
-
117
- ```typescript
118
- import { createFileIPLDDag, cidOfNode, cidToString } from '@autonomys/auto-drive'
119
- import fs from 'fs'
120
-
121
- const fileBuffer = fs.readFileSync('path/to/your/file.txt')
122
-
123
- const dag = createFileIPLDDag(fileBuffer, 'file.txt')
124
-
125
- const cid = cidOfNode(dag.headCID)
126
- const cidString = cidToString(cid)
58
+ ### Example Usage of getRoots
127
59
 
128
- console.log(`CID of the file DAG: ${cidString}`)
129
- ```
130
-
131
- ### Example: Converting Metadata To DAG
60
+ Here is an example of how to use the `getRoots` method to retrieve the root directories:
132
61
 
133
62
  ```typescript
134
- import {
135
- createMetadataIPLDDag,
136
- cidOfNode,
137
- cidToString,
138
- type OffchainMetadata,
139
- } from '@autonomys/auto-drive'
140
- import fs from 'fs'
141
-
142
- const metadata: OffchainMetadata = fs.readFileSync('path/to/your/metadata.json')
63
+ import { getRoots } from '@autonomys/auto-drive'
143
64
 
144
- const dag = createMetadataIPLDDag(metadata)
65
+ const api = new AutoDriveApi() // Initialize your API instance
145
66
 
146
- const cid = cidOfNode(dag.headCID)
147
- const cidString = cidToString(cid)
148
-
149
- console.log(`CID of the metadata DAG: ${cidString}`)
67
+ getRoots(api)
68
+ .then((roots) => {
69
+ console.log('Root directories:', roots)
70
+ })
71
+ .catch((error) => {
72
+ console.error('Error retrieving root directories:', error)
73
+ })
150
74
  ```
151
-
152
- ## License
153
-
154
- This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
155
-
156
- ## Additional Resources
157
-
158
- - **Autonomys Academy**: Learn more at [Autonomys Academy](https://academy.autonomys.xyz).
159
- - **Auto-Utils Package**: Utility functions used alongside `auto-drive` can be found in [`@autonomys/auto-utils`](../Auto-Utils/README.md).
160
-
161
- ## Contact
162
-
163
- If you have any questions or need support, feel free to reach out:
164
-
165
- - **GitHub Issues**: [GitHub Issues Page](https://github.com/autonomys/auto-sdk/issues)
166
-
167
- We appreciate your feedback and contributions!
@@ -0,0 +1,6 @@
1
+ import { ArgsWithoutPagination } from '../../utils/types.js';
2
+ import { AutoDriveApi } from '../connection.js';
3
+ export declare const downloadObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
4
+ cid: string;
5
+ }>) => Promise<ReadableStream<Uint8Array>>;
6
+ //# sourceMappingURL=download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/api/calls/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,eAAO,MAAM,cAAc,QACpB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAcpC,CAAA"}
@@ -0,0 +1,12 @@
1
+ export const downloadObject = async (api, query) => {
2
+ const response = await api.sendRequest(`/objects/${query.cid}/download`, {
3
+ method: 'GET',
4
+ });
5
+ if (!response.ok) {
6
+ throw new Error(`Failed to download file: ${response.statusText}`);
7
+ }
8
+ if (!response.body) {
9
+ throw new Error('No body returned from download request');
10
+ }
11
+ return response.body;
12
+ };
@@ -0,0 +1,5 @@
1
+ export * from './download.js';
2
+ export * from './read.js';
3
+ export * from './upload.js';
4
+ export * from './write.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/calls/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './download.js';
2
+ export * from './read.js';
3
+ export * from './upload.js';
4
+ export * from './write.js';
@@ -0,0 +1,98 @@
1
+ import { ArgsWithoutPagination, ArgsWithPagination } from '../../utils/types.js';
2
+ import { AutoDriveApi } from '../connection.js';
3
+ import { ObjectInformation, ObjectSummary, Scope } from '../models/objects.js';
4
+ /**
5
+ * Retrieves the root objects based on the specified scope.
6
+ *
7
+ * @param {AutoDriveApi} api - The API instance used to send requests.
8
+ * @param {ArgsWithPagination<{ scope: Scope }>} query - The query parameters including scope, limit, and offset.
9
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the root objects.
10
+ * @throws {Error} - Throws an error if the request fails.
11
+ */
12
+ export declare const getRoots: (api: AutoDriveApi, query: ArgsWithPagination<{
13
+ scope: Scope;
14
+ }>) => Promise<ObjectSummary[]>;
15
+ /**
16
+ * Retrieves the objects that have been shared with the authenticated user.
17
+ *
18
+ * This method sends a request to the server to fetch a list of objects
19
+ * that are shared with the user, based on the specified pagination parameters.
20
+ *
21
+ * @param {AutoDriveApi} api - The API instance used to send requests.
22
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
23
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the shared objects.
24
+ * @throws {Error} - Throws an error if the request fails.
25
+ */
26
+ export declare const getSharedWithMe: (api: AutoDriveApi, query: ArgsWithPagination) => Promise<ObjectSummary[]>;
27
+ /**
28
+ * Retrieves the objects that have been marked as deleted.
29
+ *
30
+ * This method sends a request to the server to fetch a list of objects
31
+ * that have been deleted, based on the specified pagination parameters.
32
+ *
33
+ * @param {AutoDriveApi} api - The API instance used to send requests.
34
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
35
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the deleted objects.
36
+ * @throws {Error} - Throws an error if the request fails.
37
+ */
38
+ export declare const getDeleted: (api: AutoDriveApi, query: ArgsWithPagination) => Promise<ObjectSummary[]>;
39
+ /**
40
+ * Retrieves the aggregated information of a specific object identified by its CID.
41
+ *
42
+ * This method sends a request to the server to fetch details about the
43
+ * object, including its metadata and other relevant information.
44
+ *
45
+ * @param {AutoDriveApi} api - The API instance used to send requests.
46
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to retrieve.
47
+ * @returns {Promise<ObjectInformation>} - A promise that resolves to the information of the requested object.
48
+ * @throws {Error} - Throws an error if the request fails.
49
+ */
50
+ export declare const getObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
51
+ cid: string;
52
+ }>) => Promise<ObjectInformation>;
53
+ /**
54
+ * Retrieves the upload status of a specific object identified by its CID.
55
+ *
56
+ * This method sends a request to the server to fetch the current upload status
57
+ * of the object, which can indicate whether the upload is pending, completed,
58
+ * or failed.
59
+ *
60
+ * @param {AutoDriveApi} api - The API instance used to send requests.
61
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose upload status is to be retrieved.
62
+ * @returns {Promise<ObjectInformation['uploadStatus']>} - A promise that resolves to the upload status of the requested object.
63
+ * @throws {Error} - Throws an error if the request fails.
64
+ */
65
+ export declare const getObjectUploadStatus: (api: AutoDriveApi, query: ArgsWithoutPagination<{
66
+ cid: string;
67
+ }>) => Promise<ObjectInformation["uploadStatus"]>;
68
+ /**
69
+ * Retrieves the owners of a specific object identified by its CID.
70
+ *
71
+ * This method sends a request to the server to fetch the list of owners
72
+ * associated with the object. The owners can provide insights into who
73
+ * has access to or control over the object.
74
+ *
75
+ * @param {AutoDriveApi} api - The API instance used to send requests.
76
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose owners are to be retrieved.
77
+ * @returns {Promise<ObjectInformation['owners']>} - A promise that resolves to the list of owners of the requested object.
78
+ * @throws {Error} - Throws an error if the request fails.
79
+ */
80
+ export declare const getObjectOwners: (api: AutoDriveApi, query: ArgsWithoutPagination<{
81
+ cid: string;
82
+ }>) => Promise<ObjectInformation["owners"]>;
83
+ /**
84
+ * Retrieves the metadata of a specific object identified by its CID.
85
+ *
86
+ * This method sends a request to the server to fetch the metadata associated
87
+ * with the object. The metadata can include various details about the object,
88
+ * such as its name, type, size, and other relevant information.
89
+ *
90
+ * @param {AutoDriveApi} api - The API instance used to send requests.
91
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose metadata is to be retrieved.
92
+ * @returns {Promise<ObjectInformation['metadata']>} - A promise that resolves to the metadata of the requested object.
93
+ * @throws {Error} - Throws an error if the request fails.
94
+ */
95
+ export declare const getObjectMetadata: (api: AutoDriveApi, query: ArgsWithoutPagination<{
96
+ cid: string;
97
+ }>) => Promise<ObjectInformation["metadata"]>;
98
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/api/calls/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,QACd,YAAY,SACV,kBAAkB,CAAC;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,KAC1C,OAAO,CAAC,aAAa,EAAE,CAazB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,QACrB,YAAY,SACV,kBAAkB,KACxB,OAAO,CAAC,aAAa,EAAE,CAazB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,QAChB,YAAY,SACV,kBAAkB,KACxB,OAAO,CAAC,aAAa,EAAE,CAazB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,QACf,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAU3B,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,QAC3B,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAU3C,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,QACrB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAUrC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,QACvB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAUvC,CAAA"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Retrieves the root objects based on the specified scope.
3
+ *
4
+ * @param {AutoDriveApi} api - The API instance used to send requests.
5
+ * @param {ArgsWithPagination<{ scope: Scope }>} query - The query parameters including scope, limit, and offset.
6
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the root objects.
7
+ * @throws {Error} - Throws an error if the request fails.
8
+ */
9
+ export const getRoots = async (api, query) => {
10
+ const response = await api.sendRequest(`/objects/roots?scope=${query.scope}&limit=${query.limit}&offset=${query.offset}`, {
11
+ method: 'GET',
12
+ });
13
+ if (!response.ok) {
14
+ throw new Error(`Failed to get roots: ${response.statusText}`);
15
+ }
16
+ return response.json();
17
+ };
18
+ /**
19
+ * Retrieves the objects that have been shared with the authenticated user.
20
+ *
21
+ * This method sends a request to the server to fetch a list of objects
22
+ * that are shared with the user, based on the specified pagination parameters.
23
+ *
24
+ * @param {AutoDriveApi} api - The API instance used to send requests.
25
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
26
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the shared objects.
27
+ * @throws {Error} - Throws an error if the request fails.
28
+ */
29
+ export const getSharedWithMe = async (api, query) => {
30
+ const response = await api.sendRequest(`/objects/roots/shared?limit=${query.limit}&offset=${query.offset}`, {
31
+ method: 'GET',
32
+ });
33
+ if (!response.ok) {
34
+ throw new Error(`Failed to get shared with me: ${response.statusText}`);
35
+ }
36
+ return response.json();
37
+ };
38
+ /**
39
+ * Retrieves the objects that have been marked as deleted.
40
+ *
41
+ * This method sends a request to the server to fetch a list of objects
42
+ * that have been deleted, based on the specified pagination parameters.
43
+ *
44
+ * @param {AutoDriveApi} api - The API instance used to send requests.
45
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
46
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the deleted objects.
47
+ * @throws {Error} - Throws an error if the request fails.
48
+ */
49
+ export const getDeleted = async (api, query) => {
50
+ const response = await api.sendRequest(`/objects/roots/deleted?limit=${query.limit}&offset=${query.offset}`, {
51
+ method: 'GET',
52
+ });
53
+ if (!response.ok) {
54
+ throw new Error(`Failed to get deleted: ${response.statusText}`);
55
+ }
56
+ return response.json();
57
+ };
58
+ /**
59
+ * Retrieves the aggregated information of a specific object identified by its CID.
60
+ *
61
+ * This method sends a request to the server to fetch details about the
62
+ * object, including its metadata and other relevant information.
63
+ *
64
+ * @param {AutoDriveApi} api - The API instance used to send requests.
65
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to retrieve.
66
+ * @returns {Promise<ObjectInformation>} - A promise that resolves to the information of the requested object.
67
+ * @throws {Error} - Throws an error if the request fails.
68
+ */
69
+ export const getObject = async (api, query) => {
70
+ const response = await api.sendRequest(`/objects/${query.cid}`, {
71
+ method: 'GET',
72
+ });
73
+ if (!response.ok) {
74
+ throw new Error(`Failed to get object: ${response.statusText}`);
75
+ }
76
+ return response.json();
77
+ };
78
+ /**
79
+ * Retrieves the upload status of a specific object identified by its CID.
80
+ *
81
+ * This method sends a request to the server to fetch the current upload status
82
+ * of the object, which can indicate whether the upload is pending, completed,
83
+ * or failed.
84
+ *
85
+ * @param {AutoDriveApi} api - The API instance used to send requests.
86
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose upload status is to be retrieved.
87
+ * @returns {Promise<ObjectInformation['uploadStatus']>} - A promise that resolves to the upload status of the requested object.
88
+ * @throws {Error} - Throws an error if the request fails.
89
+ */
90
+ export const getObjectUploadStatus = async (api, query) => {
91
+ const response = await api.sendRequest(`/objects/${query.cid}/status`, {
92
+ method: 'GET',
93
+ });
94
+ if (!response.ok) {
95
+ throw new Error(`Failed to get object: ${response.statusText}`);
96
+ }
97
+ return response.json();
98
+ };
99
+ /**
100
+ * Retrieves the owners of a specific object identified by its CID.
101
+ *
102
+ * This method sends a request to the server to fetch the list of owners
103
+ * associated with the object. The owners can provide insights into who
104
+ * has access to or control over the object.
105
+ *
106
+ * @param {AutoDriveApi} api - The API instance used to send requests.
107
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose owners are to be retrieved.
108
+ * @returns {Promise<ObjectInformation['owners']>} - A promise that resolves to the list of owners of the requested object.
109
+ * @throws {Error} - Throws an error if the request fails.
110
+ */
111
+ export const getObjectOwners = async (api, query) => {
112
+ const response = await api.sendRequest(`/objects/${query.cid}/owners`, {
113
+ method: 'GET',
114
+ });
115
+ if (!response.ok) {
116
+ throw new Error(`Failed to get object: ${response.statusText}`);
117
+ }
118
+ return response.json();
119
+ };
120
+ /**
121
+ * Retrieves the metadata of a specific object identified by its CID.
122
+ *
123
+ * This method sends a request to the server to fetch the metadata associated
124
+ * with the object. The metadata can include various details about the object,
125
+ * such as its name, type, size, and other relevant information.
126
+ *
127
+ * @param {AutoDriveApi} api - The API instance used to send requests.
128
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose metadata is to be retrieved.
129
+ * @returns {Promise<ObjectInformation['metadata']>} - A promise that resolves to the metadata of the requested object.
130
+ * @throws {Error} - Throws an error if the request fails.
131
+ */
132
+ export const getObjectMetadata = async (api, query) => {
133
+ const response = await api.sendRequest(`/objects/${query.cid}/metadata`, {
134
+ method: 'GET',
135
+ });
136
+ if (!response.ok) {
137
+ throw new Error(`Failed to get object: ${response.statusText}`);
138
+ }
139
+ return response.json();
140
+ };
@@ -0,0 +1,94 @@
1
+ import { FileUploadOptions } from '@autonomys/auto-dag-data';
2
+ import { ArgsWithoutPagination } from '../../utils/types.js';
3
+ import { AutoDriveApi } from '../connection.js';
4
+ import { FolderTree } from '../models/folderTree.js';
5
+ import { FileUpload, FolderUpload } from '../models/uploads.js';
6
+ /**
7
+ * Initiates a file upload to the server.
8
+ *
9
+ * @param {AutoDriveApi} api - The API instance used to send requests.
10
+ * @param {ArgsWithoutPagination<{ mimeType?: string; filename: string; uploadOptions: FileUploadOptions | null }>} args - The arguments for the file upload.
11
+ * @param {string} args.mimeType - The MIME type of the file (optional).
12
+ * @param {string} args.filename - The name of the file to be uploaded.
13
+ * @param {FileUploadOptions | null} args.uploadOptions - Additional options for the file upload (optional).
14
+ * @returns {Promise<FileUpload>} - A promise that resolves to the file upload information.
15
+ * @throws {Error} - Throws an error if the upload fails.
16
+ */
17
+ export declare const createFileUpload: (api: AutoDriveApi, { mimeType, filename, uploadOptions, }: ArgsWithoutPagination<{
18
+ mimeType?: string;
19
+ filename: string;
20
+ uploadOptions: FileUploadOptions | null;
21
+ }>) => Promise<FileUpload>;
22
+ /**
23
+ * Initiates a folder upload to the server.
24
+ *
25
+ * @param {AutoDriveApi} api - The API instance used to send requests.
26
+ * @param {ArgsWithoutPagination<{ fileTree: FolderTree; uploadOptions: FileUploadOptions }>} args - The arguments for the folder upload.
27
+ * @param {FolderTree} args.fileTree - The structure of the folder and its contents to be uploaded.
28
+ * @param {FileUploadOptions} args.uploadOptions - Additional options for the folder upload.
29
+ * @returns {Promise<FolderUpload>} - A promise that resolves to the folder upload information.
30
+ * @throws {Error} - Throws an error if the upload fails.
31
+ */
32
+ export declare const createFolderUpload: (api: AutoDriveApi, { fileTree, uploadOptions, }: ArgsWithoutPagination<{
33
+ fileTree: FolderTree;
34
+ uploadOptions: FileUploadOptions;
35
+ }>) => Promise<FolderUpload>;
36
+ /**
37
+ * Creates a file upload within an existing folder upload.
38
+ *
39
+ * @param {AutoDriveApi} api - The API instance used to send requests.
40
+ * @param {ArgsWithoutPagination<{ uploadId: string; name: string; mimeType: string; relativeId: string; uploadOptions: FileUploadOptions }>} args - The arguments for the file upload.
41
+ * @param {string} args.uploadId - The ID of the folder upload to which the file will be added.
42
+ * @param {string} args.name - The name of the file to be uploaded.
43
+ * @param {string} args.mimeType - The MIME type of the file being uploaded.
44
+ * @param {string} args.relativeId - The relative ID of the file within the folder structure.
45
+ * @param {FileUploadOptions} [args.uploadOptions={}] - Additional options for the file upload.
46
+ * @returns {Promise<FileUpload>} - A promise that resolves to the file upload information.
47
+ * @throws {Error} - Throws an error if the upload fails.
48
+ */
49
+ export declare const createFileUploadWithinFolderUpload: (api: AutoDriveApi, { uploadId, name, mimeType, relativeId, uploadOptions, }: ArgsWithoutPagination<{
50
+ uploadId: string;
51
+ name: string;
52
+ mimeType?: string;
53
+ relativeId: string;
54
+ uploadOptions: FileUploadOptions;
55
+ }>) => Promise<FileUpload>;
56
+ /**
57
+ * Uploads a chunk of a file to the server.
58
+ *
59
+ * This function allows for the uploading of a specific chunk of a file
60
+ * during a multi-part upload process. It sends the chunk along with its
61
+ * index to the server, which can be used to reconstruct the file on the
62
+ * server side.
63
+ *
64
+ * @param {AutoDriveApi} api - The API instance used to send requests.
65
+ * @param {ArgsWithoutPagination<{ uploadId: string; chunk: Buffer; index: number }>} args - The arguments for the file chunk upload.
66
+ * @param {string} args.uploadId - The ID of the upload session.
67
+ * @param {Buffer} args.chunk - The chunk of the file to be uploaded.
68
+ * @param {number} args.index - The index of the chunk in the overall file.
69
+ * @returns {Promise<void>} - A promise that resolves when the chunk is uploaded successfully.
70
+ * @throws {Error} - Throws an error if the upload fails.
71
+ */
72
+ export declare const uploadFileChunk: (api: AutoDriveApi, { uploadId, chunk, index, }: ArgsWithoutPagination<{
73
+ uploadId: string;
74
+ chunk: Buffer;
75
+ index: number;
76
+ }>) => Promise<void>;
77
+ /**
78
+ * Completes a file or folder upload session on the server.
79
+ *
80
+ * This function sends a request to the server to finalize the upload
81
+ * process for a given upload session identified by the upload ID. It is
82
+ * typically called after all file chunks have been uploaded. This method
83
+ * can be used to complete both file and folder uploads.
84
+ *
85
+ * @param {AutoDriveApi} api - The API instance used to send requests.
86
+ * @param {ArgsWithoutPagination<{ uploadId: string }>} args - The arguments for completing the upload.
87
+ * @param {string} args.uploadId - The ID of the upload session to complete.
88
+ * @returns {Promise<any>} - A promise that resolves to the response from the server.
89
+ * @throws {Error} - Throws an error if the completion of the upload fails.
90
+ */
91
+ export declare const completeUpload: (api: AutoDriveApi, { uploadId }: ArgsWithoutPagination<{
92
+ uploadId: string;
93
+ }>) => Promise<any>;
94
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/api/calls/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,QACtB,YAAY,0CAKd,qBAAqB,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC,CAAC,KACD,OAAO,CAAC,UAAU,CAiBpB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,QACxB,YAAY,gCAId,qBAAqB,CAAC;IAAE,QAAQ,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,iBAAiB,CAAA;CAAE,CAAC,KACnF,OAAO,CAAC,YAAY,CAiBtB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kCAAkC,QACxC,YAAY,4DAOd,qBAAqB,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,iBAAiB,CAAA;CACjC,CAAC,KACD,OAAO,CAAC,UAAU,CAiBpB,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,QACrB,YAAY,+BAKd,qBAAqB,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,KAC3E,OAAO,CAAC,IAAI,CAgBd,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,QACpB,YAAY,gBACH,qBAAqB,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,iBAW1D,CAAA"}