@autonomys/auto-drive 1.1.3 → 1.2.0

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 (84) hide show
  1. package/.env +6 -0
  2. package/LICENSE +18 -0
  3. package/README.md +42 -84
  4. package/dist/api/calls/download.d.ts +6 -0
  5. package/dist/api/calls/download.d.ts.map +1 -0
  6. package/dist/api/calls/download.js +25 -0
  7. package/dist/api/calls/index.d.ts +57 -0
  8. package/dist/api/calls/index.d.ts.map +1 -0
  9. package/dist/api/calls/index.js +41 -0
  10. package/dist/api/calls/read.d.ts +99 -0
  11. package/dist/api/calls/read.d.ts.map +1 -0
  12. package/dist/api/calls/read.js +159 -0
  13. package/dist/api/calls/upload.d.ts +93 -0
  14. package/dist/api/calls/upload.d.ts.map +1 -0
  15. package/dist/api/calls/upload.js +137 -0
  16. package/dist/api/calls/write.d.ts +49 -0
  17. package/dist/api/calls/write.d.ts.map +1 -0
  18. package/dist/api/calls/write.js +80 -0
  19. package/dist/api/connection.d.ts +15 -0
  20. package/dist/api/connection.d.ts.map +1 -0
  21. package/dist/api/connection.js +28 -0
  22. package/dist/api/index.d.ts +5 -0
  23. package/dist/api/index.d.ts.map +1 -0
  24. package/dist/api/index.js +20 -0
  25. package/dist/api/models/common.d.ts +5 -0
  26. package/dist/api/models/common.d.ts.map +1 -0
  27. package/dist/api/models/common.js +2 -0
  28. package/dist/api/models/file.d.ts +10 -0
  29. package/dist/api/models/file.d.ts.map +1 -0
  30. package/dist/api/models/file.js +2 -0
  31. package/dist/api/models/folderTree.d.ts +47 -0
  32. package/dist/api/models/folderTree.d.ts.map +1 -0
  33. package/dist/api/models/folderTree.js +105 -0
  34. package/dist/api/models/index.d.ts +3 -0
  35. package/dist/api/models/index.d.ts.map +1 -0
  36. package/dist/api/models/index.js +18 -0
  37. package/dist/api/models/objects.d.ts +72 -0
  38. package/dist/api/models/objects.d.ts.map +1 -0
  39. package/dist/api/models/objects.js +13 -0
  40. package/dist/api/models/uploads.d.ts +148 -0
  41. package/dist/api/models/uploads.d.ts.map +1 -0
  42. package/dist/api/models/uploads.js +51 -0
  43. package/dist/api/wrappers.d.ts +84 -0
  44. package/dist/api/wrappers.d.ts.map +1 -0
  45. package/dist/api/wrappers.js +287 -0
  46. package/dist/browser.d.ts +3 -0
  47. package/dist/browser.d.ts.map +1 -0
  48. package/dist/browser.js +18 -0
  49. package/dist/fs/index.d.ts +3 -0
  50. package/dist/fs/index.d.ts.map +1 -0
  51. package/dist/fs/index.js +18 -0
  52. package/dist/fs/utils.d.ts +6 -0
  53. package/dist/fs/utils.d.ts.map +1 -0
  54. package/dist/fs/utils.js +84 -0
  55. package/dist/fs/wrappers.d.ts +44 -0
  56. package/dist/fs/wrappers.d.ts.map +1 -0
  57. package/dist/fs/wrappers.js +124 -0
  58. package/dist/node.d.ts +3 -0
  59. package/dist/node.d.ts.map +1 -0
  60. package/dist/node.js +18 -0
  61. package/dist/utils/async.d.ts +5 -0
  62. package/dist/utils/async.d.ts.map +1 -0
  63. package/dist/utils/async.js +73 -0
  64. package/dist/utils/autohash.d.ts +17 -0
  65. package/dist/utils/autohash.d.ts.map +1 -0
  66. package/dist/utils/autohash.js +73 -0
  67. package/dist/utils/index.d.ts +4 -0
  68. package/dist/utils/index.d.ts.map +1 -0
  69. package/dist/utils/index.js +19 -0
  70. package/dist/utils/misc.d.ts +2 -0
  71. package/dist/utils/misc.d.ts.map +1 -0
  72. package/dist/utils/misc.js +5 -0
  73. package/dist/utils/observable.d.ts +2 -0
  74. package/dist/utils/observable.d.ts.map +1 -0
  75. package/dist/utils/observable.js +2 -0
  76. package/dist/utils/types.d.ts +6 -0
  77. package/dist/utils/types.d.ts.map +1 -0
  78. package/dist/utils/types.js +2 -0
  79. package/package.json +3 -4
  80. package/src/api/wrappers.ts +113 -112
  81. package/src/fs/wrappers.ts +44 -39
  82. package/src/utils/index.ts +0 -1
  83. package/tsconfig.json +3 -1
  84. package/src/utils/observable.ts +0 -19
package/.env ADDED
@@ -0,0 +1,6 @@
1
+ OBJECT_MAPPING_ARCHIVER_URL=ws://127.0.0.1:1234
2
+ RPC_ENDPOINT=ws://127.0.0.1:1234
3
+ PRIVATE_KEYS_PATH=//Alice
4
+ CORS_ALLOW_ORIGINS=*
5
+ DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
6
+ MAX_CACHE_SIZE=1073741824
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Autonomys Network (autonomys.xyz)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ 1. **Attribution**: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ 2. **No Warranty**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+
16
+ 3. **Limitation of Liability**: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+
18
+ ---
package/README.md CHANGED
@@ -25,43 +25,40 @@ yarn add @autonomys/auto-drive
25
25
  Here is an example of how to use the `uploadFileFromFilepath` method to upload a file with optional encryption and compression:
26
26
 
27
27
  ```typescript
28
- import { uploadFileFromFilepath } from '@autonomys/auto-drive'
28
+ import { uploadFileFromFilepath,createAutoDriveApi } from '@autonomys/auto-drive'
29
29
 
30
30
  const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
31
31
  const filePath = 'path/to/your/file.txt' // Specify the path to your file
32
32
  const options = {
33
33
  password: 'your-encryption-password', // Optional: specify a password for encryption
34
34
  compression: true,
35
+ // an optional callback useful for large file uploads
36
+ onProgress?: (progress: number) => {
37
+ console.log(`The upload is completed is ${progress}% completed`)
38
+ }
35
39
  }
36
40
 
37
- const uploadObservable = uploadFileFromFilepath(api, filePath, options)
38
- .then(() => {
39
- console.log('File uploaded successfully!')
40
- })
41
- .catch((error) => {
42
- console.error('Error uploading file:', error)
43
- })
41
+ const cid = await uploadFileFromFilepath(api, filePath, options)
42
+
43
+ console.log(`The file is uploaded and its cid is ${cid}`)
44
44
  ```
45
45
 
46
46
  ### How to upload [File](https://developer.mozilla.org/en-US/docs/Web/API/File) interface
47
47
 
48
48
  ```typescript
49
- import { uploadFileFromFilepath } from '@autonomys/auto-drive'
49
+ import { uploadFileFromInput, createAutoDriveApi } from '@autonomys/auto-drive'
50
50
 
51
51
  const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
52
- const filePath = 'path/to/your/file.txt' // Specify the path to your file
52
+
53
+ // e.g Get File from object from HTML event
54
+ const file: File = e.target.value // Substitute with your file
53
55
  const options = {
54
56
  password: 'your-encryption-password', // Optional: specify a password for encryption
55
57
  compression: true,
56
58
  }
59
+ const cid = await uploadFileFromInput(api, file, options)
57
60
 
58
- const uploadObservable = uploadFile(api, filePath, options)
59
- .then(() => {
60
- console.log('File uploaded successfully!')
61
- })
62
- .catch((error) => {
63
- console.error('Error uploading file:', error)
64
- })
61
+ console.log(`The file is uploaded and its cid is ${cid}`)
65
62
  ```
66
63
 
67
64
  ### How to upload a file from a custom interface?
@@ -83,7 +80,7 @@ For more info about asynn generator visit [this website](https://developer.mozil
83
80
  You could upload any file that could be represented in that way. For example, uploading a file as a `Buffer`
84
81
 
85
82
  ```typescript
86
- import { uploadFile } from '@autonomys/auto-drive'
83
+ import { createAutoDriveApi, uploadFile } from '@autonomys/auto-drive'
87
84
 
88
85
  const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
89
86
  const buffer = Buffer.from(...);
@@ -100,21 +97,21 @@ const genericFile = {
100
97
  const options = {
101
98
  password: 'your-encryption-password', // Optional: specify a password for encryption
102
99
  compression: true,
100
+ // an optional callback useful for large file uploads
101
+ onProgress?: (progress: number) => {
102
+ console.log(`The upload is completed is ${progress}% completed`)
103
+ }
103
104
  }
104
105
 
105
- const uploadObservable = uploadFile(api, genericFile, options)
106
- .then(() => {
107
- console.log('File uploaded successfully!')
108
- })
109
- .catch((error) => {
110
- console.error('Error uploading file:', error)
111
- })
106
+ const cid = uploadFile(api, genericFile, options)
107
+
108
+ console.log(`The file is uploaded and its cid is ${cid}`)
112
109
  ```
113
110
 
114
111
  ### How to upload a folder from folder? (Not available in browser)
115
112
 
116
113
  ```ts
117
- import { uploadFolderFromFolderPath } from '@autonomys/auto-drive'
114
+ import { createAutoDriveApi, uploadFolderFromFolderPath } from '@autonomys/auto-drive'
118
115
 
119
116
  const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
120
117
  const folderPath = 'path/to/your/folder' // Specify the path to your folder
@@ -122,74 +119,31 @@ const folderPath = 'path/to/your/folder' // Specify the path to your folder
122
119
  const options = {
123
120
  uploadChunkSize: 1024 * 1024, // Optional: specify the chunk size for uploads
124
121
  password: 'your-encryption-password', // Optional: If folder is encrypted
122
+ // an optional callback useful for large file uploads
123
+ onProgress: (progress: number) => {
124
+ console.log(`The upload is completed is ${progress}% completed`)
125
+ },
125
126
  }
126
127
 
127
- const uploadObservable = uploadFolderFromFolderPath(api, folderPath, options)
128
- ```
129
-
130
- **Note: If a folder is tried to be encrypted a zip file would be generated and that file would be encrypted and uploaded.**
131
-
132
- ### Handle observables
133
-
134
- Since uploads may take some time, specially in big-sized files. Uploads do implement `rxjs` observables so you could have feedback about the process or even show your users the progress of the upload.
135
-
136
- For that reason when file upload functions return `PromisedObservable<UploadFileStatus>`:
137
-
138
- ```typescript
139
- export type UploadFileStatus = {
140
- type: 'file'
141
- progress: number
142
- cid?: CID
143
- }
144
- ```
145
-
146
- Being the cid only returned (and thus optional) when the upload is completed.
147
-
148
- Similarly, for folder uploads the functions return `PromisedObservable<UploadFolderStatus>`
149
-
150
- ```ts
151
- export type UploadFolderStatus = {
152
- type: 'folder'
153
- progress: number
154
- cid?: CID
155
- }
156
- ```
157
-
158
- **e.g Show upload progress in React**
159
-
160
- ```typescript
161
- const [progress, setProgress] = useState<number>(0)
128
+ const folderCID = await uploadFolderFromFolderPath(api, folderPath, options)
162
129
 
163
- useEffect(async () => {
164
- const finalStatus = await uploadFileFromInput(api, genericFile, options).forEach((status) => {
165
- setProgress(status.progress)
166
- })
167
- })
130
+ console.log(`The folder is uploaded and its cid is ${folderCID}`)
168
131
  ```
169
132
 
170
- **e.g Ignore observables**
171
-
172
- Other users may want to not use the progress observability. For having a promise instead the field `promise` is a Promise that resolves into `UploadFileStatus` and `UploadFolderStatus` for files and folders respectively.
173
-
174
- e.g
175
-
176
- ```ts
177
- const status = await uploadFileFromInput(api, genericFile, options).promise
178
- const cid = status.cid
179
- ```
133
+ **Note: If a folder is tried to be encrypted a zip file would be generated and that file would be encrypted and uploaded.**
180
134
 
181
135
  ### Example Usage of Download
182
136
 
183
137
  Here is an example of how to use the `downloadFile` method to download a file from the server:
184
138
 
185
139
  ```typescript
186
- import { downloadObject } from '@autonomys/auto-drive'
140
+ import { createAutoDriveApi, downloadFile } from '@autonomys/auto-drive'
187
141
 
188
142
  const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
189
143
 
190
144
  try {
191
145
  const cid = '..'
192
- const stream = await downloadObject(api, { cid })
146
+ const stream = await downloadFile(api, cid)
193
147
  let file = Buffer.alloc(0)
194
148
  for await (const chunk of stream) {
195
149
  file = Buffer.concat([file, chunk])
@@ -205,16 +159,20 @@ try {
205
159
  Here is an example of how to use the `getRoots` method to retrieve the root directories:
206
160
 
207
161
  ```typescript
208
- import { createAutoDriveApi, downloadObject } from '@autonomys/auto-drive'
209
- import fs from 'fs'
162
+ import { createAutoDriveApi, apiCalls, Scope } from '@autonomys/auto-drive'
210
163
 
211
164
  const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
212
165
 
213
166
  try {
214
- const stream = fs.createWriteStream('/path/to/file')
215
- const asyncBuffer = await downloadObject(api, { cid })
216
- for await (const buffer of asyncBuffer) {
217
- stream.write(buffer)
167
+ const myFiles = await apiCalls.getRoots(api, {
168
+ scope: Scope.User,
169
+ limit: 100,
170
+ offset: 0,
171
+ })
172
+
173
+ console.log(`Retrieved ${myFiles.rows.length} files of ${myFiles.totalCount} total`)
174
+ for (const file of myFiles.rows) {
175
+ console.log(`${file.name} - ${file.headCid}: ${file.size}`)
218
176
  }
219
177
  } catch (error) {
220
178
  console.error('Error downloading file:', error)
@@ -0,0 +1,6 @@
1
+ import { ArgsWithoutPagination } from '../../utils/types';
2
+ import { AutoDriveApi } from '../connection';
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,mBAAmB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,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,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.downloadObject = void 0;
13
+ const downloadObject = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const response = yield api.sendRequest(`/objects/${query.cid}/download`, {
15
+ method: 'GET',
16
+ });
17
+ if (!response.ok) {
18
+ throw new Error(`Failed to download file: ${response.statusText}`);
19
+ }
20
+ if (!response.body) {
21
+ throw new Error('No body returned from download request');
22
+ }
23
+ return response.body;
24
+ });
25
+ exports.downloadObject = downloadObject;
@@ -0,0 +1,57 @@
1
+ export declare const apiCalls: {
2
+ shareObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
3
+ cid: string;
4
+ publicId: string;
5
+ }>) => Promise<any>;
6
+ markObjectAsDeleted: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
7
+ cid: string;
8
+ }>) => Promise<void>;
9
+ restoreObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
10
+ cid: string;
11
+ }>) => Promise<void>;
12
+ createFileUpload: (api: import("..").AutoDriveApi, { mimeType, filename, uploadOptions, }: import("../../utils").ArgsWithoutPagination<{
13
+ mimeType?: string;
14
+ filename: string;
15
+ uploadOptions: import("..").FileUploadOptions | null;
16
+ }>) => Promise<import("..").FileUpload>;
17
+ createFolderUpload: (api: import("..").AutoDriveApi, { fileTree, uploadOptions, }: import("../../utils").ArgsWithoutPagination<{
18
+ fileTree: import("../models/folderTree").FolderTree;
19
+ uploadOptions?: import("..").FileUploadOptions;
20
+ }>) => Promise<import("..").FolderUpload>;
21
+ createFileUploadWithinFolderUpload: (api: import("..").AutoDriveApi, { uploadId, name, mimeType, relativeId, uploadOptions, }: import("../../utils").ArgsWithoutPagination<{
22
+ uploadId: string;
23
+ name: string;
24
+ mimeType?: string;
25
+ relativeId: string;
26
+ uploadOptions: import("..").FileUploadOptions;
27
+ }>) => Promise<import("..").FileUpload>;
28
+ uploadFileChunk: (api: import("..").AutoDriveApi, { uploadId, chunk, index, }: import("../../utils").ArgsWithoutPagination<{
29
+ uploadId: string;
30
+ chunk: Buffer;
31
+ index: number;
32
+ }>) => Promise<void>;
33
+ completeUpload: (api: import("..").AutoDriveApi, { uploadId }: import("../../utils").ArgsWithoutPagination<{
34
+ uploadId: string;
35
+ }>) => Promise<import("..").CompleteUploadResponse>;
36
+ getRoots: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithPagination<{
37
+ scope: import("..").Scope;
38
+ }>) => Promise<import("../models/common").PaginatedResult<import("..").ObjectSummary>>;
39
+ getSharedWithMe: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithPagination) => Promise<import("../models/common").PaginatedResult<import("..").ObjectSummary>>;
40
+ getDeleted: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithPagination) => Promise<import("../models/common").PaginatedResult<import("..").ObjectSummary>>;
41
+ getObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
42
+ cid: string;
43
+ }>) => Promise<import("..").ObjectInformation>;
44
+ getObjectUploadStatus: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
45
+ cid: string;
46
+ }>) => Promise<import("..").ObjectInformation["uploadStatus"]>;
47
+ getObjectOwners: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
48
+ cid: string;
49
+ }>) => Promise<import("..").ObjectInformation["owners"]>;
50
+ getObjectMetadata: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
51
+ cid: string;
52
+ }>) => Promise<import("..").ObjectInformation["metadata"]>;
53
+ downloadObject: (api: import("..").AutoDriveApi, query: import("../../utils").ArgsWithoutPagination<{
54
+ cid: string;
55
+ }>) => Promise<ReadableStream<Uint8Array>>;
56
+ };
57
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/calls/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;;;;;;;;;;;gBAMg0B,CAAC;;;;;;qBAAgvC,CAAC;;;;;gBAAkiD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADzmH,CAAA"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.apiCalls = void 0;
37
+ const downloadCalls = __importStar(require("./download"));
38
+ const readCalls = __importStar(require("./read"));
39
+ const uploadCalls = __importStar(require("./upload"));
40
+ const writeCalls = __importStar(require("./write"));
41
+ exports.apiCalls = Object.assign(Object.assign(Object.assign(Object.assign({}, downloadCalls), readCalls), uploadCalls), writeCalls);
@@ -0,0 +1,99 @@
1
+ import { ArgsWithoutPagination, ArgsWithPagination } from '../../utils/types';
2
+ import { AutoDriveApi } from '../connection';
3
+ import { PaginatedResult } from '../models/common';
4
+ import { ObjectInformation, ObjectSummary, Scope } from '../models/objects';
5
+ /**
6
+ * Retrieves the root objects based on the specified scope.
7
+ *
8
+ * @param {AutoDriveApi} api - The API instance used to send requests.
9
+ * @param {ArgsWithPagination<{ scope: Scope }>} query - The query parameters including scope, limit, and offset.
10
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the root objects.
11
+ * @throws {Error} - Throws an error if the request fails.
12
+ */
13
+ export declare const getRoots: (api: AutoDriveApi, query: ArgsWithPagination<{
14
+ scope: Scope;
15
+ }>) => Promise<PaginatedResult<ObjectSummary>>;
16
+ /**
17
+ * Retrieves the objects that have been shared with the authenticated user.
18
+ *
19
+ * This method sends a request to the server to fetch a list of objects
20
+ * that are shared with the user, based on the specified pagination parameters.
21
+ *
22
+ * @param {AutoDriveApi} api - The API instance used to send requests.
23
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
24
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the shared objects.
25
+ * @throws {Error} - Throws an error if the request fails.
26
+ */
27
+ export declare const getSharedWithMe: (api: AutoDriveApi, query: ArgsWithPagination) => Promise<PaginatedResult<ObjectSummary>>;
28
+ /**
29
+ * Retrieves the objects that have been marked as deleted.
30
+ *
31
+ * This method sends a request to the server to fetch a list of objects
32
+ * that have been deleted, based on the specified pagination parameters.
33
+ *
34
+ * @param {AutoDriveApi} api - The API instance used to send requests.
35
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
36
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the deleted objects.
37
+ * @throws {Error} - Throws an error if the request fails.
38
+ */
39
+ export declare const getDeleted: (api: AutoDriveApi, query: ArgsWithPagination) => Promise<PaginatedResult<ObjectSummary>>;
40
+ /**
41
+ * Retrieves the aggregated information of a specific object identified by its CID.
42
+ *
43
+ * This method sends a request to the server to fetch details about the
44
+ * object, including its metadata and other relevant information.
45
+ *
46
+ * @param {AutoDriveApi} api - The API instance used to send requests.
47
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to retrieve.
48
+ * @returns {Promise<ObjectInformation>} - A promise that resolves to the information of the requested object.
49
+ * @throws {Error} - Throws an error if the request fails.
50
+ */
51
+ export declare const getObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
52
+ cid: string;
53
+ }>) => Promise<ObjectInformation>;
54
+ /**
55
+ * Retrieves the upload status of a specific object identified by its CID.
56
+ *
57
+ * This method sends a request to the server to fetch the current upload status
58
+ * of the object, which can indicate whether the upload is pending, completed,
59
+ * or failed.
60
+ *
61
+ * @param {AutoDriveApi} api - The API instance used to send requests.
62
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose upload status is to be retrieved.
63
+ * @returns {Promise<ObjectInformation['uploadStatus']>} - A promise that resolves to the upload status of the requested object.
64
+ * @throws {Error} - Throws an error if the request fails.
65
+ */
66
+ export declare const getObjectUploadStatus: (api: AutoDriveApi, query: ArgsWithoutPagination<{
67
+ cid: string;
68
+ }>) => Promise<ObjectInformation["uploadStatus"]>;
69
+ /**
70
+ * Retrieves the owners of a specific object identified by its CID.
71
+ *
72
+ * This method sends a request to the server to fetch the list of owners
73
+ * associated with the object. The owners can provide insights into who
74
+ * has access to or control over the object.
75
+ *
76
+ * @param {AutoDriveApi} api - The API instance used to send requests.
77
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose owners are to be retrieved.
78
+ * @returns {Promise<ObjectInformation['owners']>} - A promise that resolves to the list of owners of the requested object.
79
+ * @throws {Error} - Throws an error if the request fails.
80
+ */
81
+ export declare const getObjectOwners: (api: AutoDriveApi, query: ArgsWithoutPagination<{
82
+ cid: string;
83
+ }>) => Promise<ObjectInformation["owners"]>;
84
+ /**
85
+ * Retrieves the metadata of a specific object identified by its CID.
86
+ *
87
+ * This method sends a request to the server to fetch the metadata associated
88
+ * with the object. The metadata can include various details about the object,
89
+ * such as its name, type, size, and other relevant information.
90
+ *
91
+ * @param {AutoDriveApi} api - The API instance used to send requests.
92
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose metadata is to be retrieved.
93
+ * @returns {Promise<ObjectInformation['metadata']>} - A promise that resolves to the metadata of the requested object.
94
+ * @throws {Error} - Throws an error if the request fails.
95
+ */
96
+ export declare const getObjectMetadata: (api: AutoDriveApi, query: ArgsWithoutPagination<{
97
+ cid: string;
98
+ }>) => Promise<ObjectInformation["metadata"]>;
99
+ //# 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,mBAAmB,CAAA;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE3E;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,QACd,YAAY,SACV,kBAAkB,CAAC;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,KAC1C,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAaxC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,QACrB,YAAY,SACV,kBAAkB,KACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAaxC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,QAChB,YAAY,SACV,kBAAkB,KACxB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAaxC,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,159 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getObjectMetadata = exports.getObjectOwners = exports.getObjectUploadStatus = exports.getObject = exports.getDeleted = exports.getSharedWithMe = exports.getRoots = void 0;
13
+ /**
14
+ * Retrieves the root objects based on the specified scope.
15
+ *
16
+ * @param {AutoDriveApi} api - The API instance used to send requests.
17
+ * @param {ArgsWithPagination<{ scope: Scope }>} query - The query parameters including scope, limit, and offset.
18
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the root objects.
19
+ * @throws {Error} - Throws an error if the request fails.
20
+ */
21
+ const getRoots = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const response = yield api.sendRequest(`/objects/roots?scope=${query.scope}&limit=${query.limit}&offset=${query.offset}`, {
23
+ method: 'GET',
24
+ });
25
+ if (!response.ok) {
26
+ throw new Error(`Failed to get roots: ${response.statusText}`);
27
+ }
28
+ return response.json();
29
+ });
30
+ exports.getRoots = getRoots;
31
+ /**
32
+ * Retrieves the objects that have been shared with the authenticated user.
33
+ *
34
+ * This method sends a request to the server to fetch a list of objects
35
+ * that are shared with the user, based on the specified pagination parameters.
36
+ *
37
+ * @param {AutoDriveApi} api - The API instance used to send requests.
38
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
39
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the shared objects.
40
+ * @throws {Error} - Throws an error if the request fails.
41
+ */
42
+ const getSharedWithMe = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
43
+ const response = yield api.sendRequest(`/objects/roots/shared?limit=${query.limit}&offset=${query.offset}`, {
44
+ method: 'GET',
45
+ });
46
+ if (!response.ok) {
47
+ throw new Error(`Failed to get shared with me: ${response.statusText}`);
48
+ }
49
+ return response.json();
50
+ });
51
+ exports.getSharedWithMe = getSharedWithMe;
52
+ /**
53
+ * Retrieves the objects that have been marked as deleted.
54
+ *
55
+ * This method sends a request to the server to fetch a list of objects
56
+ * that have been deleted, based on the specified pagination parameters.
57
+ *
58
+ * @param {AutoDriveApi} api - The API instance used to send requests.
59
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
60
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the deleted objects.
61
+ * @throws {Error} - Throws an error if the request fails.
62
+ */
63
+ const getDeleted = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const response = yield api.sendRequest(`/objects/roots/deleted?limit=${query.limit}&offset=${query.offset}`, {
65
+ method: 'GET',
66
+ });
67
+ if (!response.ok) {
68
+ throw new Error(`Failed to get deleted: ${response.statusText}`);
69
+ }
70
+ return response.json();
71
+ });
72
+ exports.getDeleted = getDeleted;
73
+ /**
74
+ * Retrieves the aggregated information of a specific object identified by its CID.
75
+ *
76
+ * This method sends a request to the server to fetch details about the
77
+ * object, including its metadata and other relevant information.
78
+ *
79
+ * @param {AutoDriveApi} api - The API instance used to send requests.
80
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to retrieve.
81
+ * @returns {Promise<ObjectInformation>} - A promise that resolves to the information of the requested object.
82
+ * @throws {Error} - Throws an error if the request fails.
83
+ */
84
+ const getObject = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
85
+ const response = yield api.sendRequest(`/objects/${query.cid}`, {
86
+ method: 'GET',
87
+ });
88
+ if (!response.ok) {
89
+ throw new Error(`Failed to get object: ${response.statusText}`);
90
+ }
91
+ return response.json();
92
+ });
93
+ exports.getObject = getObject;
94
+ /**
95
+ * Retrieves the upload status of a specific object identified by its CID.
96
+ *
97
+ * This method sends a request to the server to fetch the current upload status
98
+ * of the object, which can indicate whether the upload is pending, completed,
99
+ * or failed.
100
+ *
101
+ * @param {AutoDriveApi} api - The API instance used to send requests.
102
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose upload status is to be retrieved.
103
+ * @returns {Promise<ObjectInformation['uploadStatus']>} - A promise that resolves to the upload status of the requested object.
104
+ * @throws {Error} - Throws an error if the request fails.
105
+ */
106
+ const getObjectUploadStatus = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
107
+ const response = yield api.sendRequest(`/objects/${query.cid}/status`, {
108
+ method: 'GET',
109
+ });
110
+ if (!response.ok) {
111
+ throw new Error(`Failed to get object: ${response.statusText}`);
112
+ }
113
+ return response.json();
114
+ });
115
+ exports.getObjectUploadStatus = getObjectUploadStatus;
116
+ /**
117
+ * Retrieves the owners of a specific object identified by its CID.
118
+ *
119
+ * This method sends a request to the server to fetch the list of owners
120
+ * associated with the object. The owners can provide insights into who
121
+ * has access to or control over the object.
122
+ *
123
+ * @param {AutoDriveApi} api - The API instance used to send requests.
124
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose owners are to be retrieved.
125
+ * @returns {Promise<ObjectInformation['owners']>} - A promise that resolves to the list of owners of the requested object.
126
+ * @throws {Error} - Throws an error if the request fails.
127
+ */
128
+ const getObjectOwners = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
129
+ const response = yield api.sendRequest(`/objects/${query.cid}/owners`, {
130
+ method: 'GET',
131
+ });
132
+ if (!response.ok) {
133
+ throw new Error(`Failed to get object: ${response.statusText}`);
134
+ }
135
+ return response.json();
136
+ });
137
+ exports.getObjectOwners = getObjectOwners;
138
+ /**
139
+ * Retrieves the metadata of a specific object identified by its CID.
140
+ *
141
+ * This method sends a request to the server to fetch the metadata associated
142
+ * with the object. The metadata can include various details about the object,
143
+ * such as its name, type, size, and other relevant information.
144
+ *
145
+ * @param {AutoDriveApi} api - The API instance used to send requests.
146
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose metadata is to be retrieved.
147
+ * @returns {Promise<ObjectInformation['metadata']>} - A promise that resolves to the metadata of the requested object.
148
+ * @throws {Error} - Throws an error if the request fails.
149
+ */
150
+ const getObjectMetadata = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
151
+ const response = yield api.sendRequest(`/objects/${query.cid}/metadata`, {
152
+ method: 'GET',
153
+ });
154
+ if (!response.ok) {
155
+ throw new Error(`Failed to get object: ${response.statusText}`);
156
+ }
157
+ return response.json();
158
+ });
159
+ exports.getObjectMetadata = getObjectMetadata;