@autonomys/auto-drive 1.0.2 → 1.0.4

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 (68) hide show
  1. package/dist/api/calls/download.d.ts +6 -0
  2. package/dist/api/calls/download.d.ts.map +1 -0
  3. package/dist/api/calls/download.js +21 -0
  4. package/dist/api/calls/index.d.ts +5 -0
  5. package/dist/api/calls/index.d.ts.map +1 -0
  6. package/dist/api/calls/index.js +4 -0
  7. package/dist/api/calls/read.d.ts +98 -0
  8. package/dist/api/calls/read.d.ts.map +1 -0
  9. package/dist/api/calls/read.js +149 -0
  10. package/dist/api/calls/upload.d.ts +94 -0
  11. package/dist/api/calls/upload.d.ts.map +1 -0
  12. package/dist/api/calls/upload.js +129 -0
  13. package/dist/api/calls/write.d.ts +49 -0
  14. package/dist/api/calls/write.d.ts.map +1 -0
  15. package/dist/api/calls/write.js +74 -0
  16. package/dist/api/connection.d.ts +15 -0
  17. package/dist/api/connection.d.ts.map +1 -0
  18. package/dist/api/connection.js +24 -0
  19. package/dist/api/index.d.ts +5 -0
  20. package/dist/api/index.d.ts.map +1 -0
  21. package/dist/api/index.js +4 -0
  22. package/dist/api/models/folderTree.d.ts +45 -0
  23. package/dist/api/models/folderTree.d.ts.map +1 -0
  24. package/dist/api/models/folderTree.js +56 -0
  25. package/dist/api/models/index.d.ts +3 -0
  26. package/dist/api/models/index.d.ts.map +1 -0
  27. package/dist/api/models/index.js +2 -0
  28. package/dist/api/models/objects.d.ts +41 -0
  29. package/dist/api/models/objects.d.ts.map +1 -0
  30. package/dist/api/models/objects.js +10 -0
  31. package/dist/api/models/uploads.d.ts +117 -0
  32. package/dist/api/models/uploads.d.ts.map +1 -0
  33. package/dist/api/models/uploads.js +40 -0
  34. package/dist/api/wrappers.d.ts +68 -0
  35. package/dist/api/wrappers.d.ts.map +1 -0
  36. package/dist/api/wrappers.js +192 -0
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +2 -0
  40. package/dist/utils/async.d.ts +3 -0
  41. package/dist/utils/async.d.ts.map +1 -0
  42. package/dist/utils/async.js +58 -0
  43. package/dist/utils/folder.d.ts +2 -0
  44. package/dist/utils/folder.d.ts.map +1 -0
  45. package/dist/utils/folder.js +23 -0
  46. package/dist/utils/index.d.ts +5 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/utils/index.js +4 -0
  49. package/dist/utils/stream.d.ts +3 -0
  50. package/dist/utils/stream.d.ts.map +1 -0
  51. package/dist/utils/stream.js +22 -0
  52. package/dist/utils/types.d.ts +6 -0
  53. package/dist/utils/types.d.ts.map +1 -0
  54. package/dist/utils/types.js +1 -0
  55. package/package.json +3 -3
  56. package/src/api/calls/download.ts +2 -2
  57. package/src/api/calls/index.ts +4 -4
  58. package/src/api/calls/read.ts +3 -3
  59. package/src/api/calls/upload.ts +7 -7
  60. package/src/api/calls/write.ts +2 -2
  61. package/src/api/connection.ts +11 -1
  62. package/src/api/index.ts +4 -4
  63. package/src/api/models/index.ts +2 -2
  64. package/src/api/models/uploads.ts +5 -1
  65. package/src/api/wrappers.ts +19 -11
  66. package/src/index.ts +2 -2
  67. package/src/utils/index.ts +4 -4
  68. package/tsconfig.json +1 -3
@@ -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,21 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const downloadObject = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
11
+ const response = yield api.sendRequest(`/objects/${query.cid}/download`, {
12
+ method: 'GET',
13
+ });
14
+ if (!response.ok) {
15
+ throw new Error(`Failed to download file: ${response.statusText}`);
16
+ }
17
+ if (!response.body) {
18
+ throw new Error('No body returned from download request');
19
+ }
20
+ return response.body;
21
+ });
@@ -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,149 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Retrieves the root objects based on the specified scope.
12
+ *
13
+ * @param {AutoDriveApi} api - The API instance used to send requests.
14
+ * @param {ArgsWithPagination<{ scope: Scope }>} query - The query parameters including scope, limit, and offset.
15
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the root objects.
16
+ * @throws {Error} - Throws an error if the request fails.
17
+ */
18
+ export const getRoots = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const response = yield api.sendRequest(`/objects/roots?scope=${query.scope}&limit=${query.limit}&offset=${query.offset}`, {
20
+ method: 'GET',
21
+ });
22
+ if (!response.ok) {
23
+ throw new Error(`Failed to get roots: ${response.statusText}`);
24
+ }
25
+ return response.json();
26
+ });
27
+ /**
28
+ * Retrieves the objects that have been shared with the authenticated user.
29
+ *
30
+ * This method sends a request to the server to fetch a list of objects
31
+ * that are shared with the user, 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 shared objects.
36
+ * @throws {Error} - Throws an error if the request fails.
37
+ */
38
+ export const getSharedWithMe = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const response = yield api.sendRequest(`/objects/roots/shared?limit=${query.limit}&offset=${query.offset}`, {
40
+ method: 'GET',
41
+ });
42
+ if (!response.ok) {
43
+ throw new Error(`Failed to get shared with me: ${response.statusText}`);
44
+ }
45
+ return response.json();
46
+ });
47
+ /**
48
+ * Retrieves the objects that have been marked as deleted.
49
+ *
50
+ * This method sends a request to the server to fetch a list of objects
51
+ * that have been deleted, based on the specified pagination parameters.
52
+ *
53
+ * @param {AutoDriveApi} api - The API instance used to send requests.
54
+ * @param {ArgsWithPagination} query - The query parameters including limit and offset for pagination.
55
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to an array of ObjectSummary representing the deleted objects.
56
+ * @throws {Error} - Throws an error if the request fails.
57
+ */
58
+ export const getDeleted = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
59
+ const response = yield api.sendRequest(`/objects/roots/deleted?limit=${query.limit}&offset=${query.offset}`, {
60
+ method: 'GET',
61
+ });
62
+ if (!response.ok) {
63
+ throw new Error(`Failed to get deleted: ${response.statusText}`);
64
+ }
65
+ return response.json();
66
+ });
67
+ /**
68
+ * Retrieves the aggregated information of a specific object identified by its CID.
69
+ *
70
+ * This method sends a request to the server to fetch details about the
71
+ * object, including its metadata and other relevant information.
72
+ *
73
+ * @param {AutoDriveApi} api - The API instance used to send requests.
74
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to retrieve.
75
+ * @returns {Promise<ObjectInformation>} - A promise that resolves to the information of the requested object.
76
+ * @throws {Error} - Throws an error if the request fails.
77
+ */
78
+ export const getObject = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
79
+ const response = yield api.sendRequest(`/objects/${query.cid}`, {
80
+ method: 'GET',
81
+ });
82
+ if (!response.ok) {
83
+ throw new Error(`Failed to get object: ${response.statusText}`);
84
+ }
85
+ return response.json();
86
+ });
87
+ /**
88
+ * Retrieves the upload status of a specific object identified by its CID.
89
+ *
90
+ * This method sends a request to the server to fetch the current upload status
91
+ * of the object, which can indicate whether the upload is pending, completed,
92
+ * or failed.
93
+ *
94
+ * @param {AutoDriveApi} api - The API instance used to send requests.
95
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose upload status is to be retrieved.
96
+ * @returns {Promise<ObjectInformation['uploadStatus']>} - A promise that resolves to the upload status of the requested object.
97
+ * @throws {Error} - Throws an error if the request fails.
98
+ */
99
+ export const getObjectUploadStatus = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
100
+ const response = yield api.sendRequest(`/objects/${query.cid}/status`, {
101
+ method: 'GET',
102
+ });
103
+ if (!response.ok) {
104
+ throw new Error(`Failed to get object: ${response.statusText}`);
105
+ }
106
+ return response.json();
107
+ });
108
+ /**
109
+ * Retrieves the owners of a specific object identified by its CID.
110
+ *
111
+ * This method sends a request to the server to fetch the list of owners
112
+ * associated with the object. The owners can provide insights into who
113
+ * has access to or control over the object.
114
+ *
115
+ * @param {AutoDriveApi} api - The API instance used to send requests.
116
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose owners are to be retrieved.
117
+ * @returns {Promise<ObjectInformation['owners']>} - A promise that resolves to the list of owners of the requested object.
118
+ * @throws {Error} - Throws an error if the request fails.
119
+ */
120
+ export const getObjectOwners = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
121
+ const response = yield api.sendRequest(`/objects/${query.cid}/owners`, {
122
+ method: 'GET',
123
+ });
124
+ if (!response.ok) {
125
+ throw new Error(`Failed to get object: ${response.statusText}`);
126
+ }
127
+ return response.json();
128
+ });
129
+ /**
130
+ * Retrieves the metadata of a specific object identified by its CID.
131
+ *
132
+ * This method sends a request to the server to fetch the metadata associated
133
+ * with the object. The metadata can include various details about the object,
134
+ * such as its name, type, size, and other relevant information.
135
+ *
136
+ * @param {AutoDriveApi} api - The API instance used to send requests.
137
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object whose metadata is to be retrieved.
138
+ * @returns {Promise<ObjectInformation['metadata']>} - A promise that resolves to the metadata of the requested object.
139
+ * @throws {Error} - Throws an error if the request fails.
140
+ */
141
+ export const getObjectMetadata = (api, query) => __awaiter(void 0, void 0, void 0, function* () {
142
+ const response = yield api.sendRequest(`/objects/${query.cid}/metadata`, {
143
+ method: 'GET',
144
+ });
145
+ if (!response.ok) {
146
+ throw new Error(`Failed to get object: ${response.statusText}`);
147
+ }
148
+ return response.json();
149
+ });
@@ -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 { CompleteUploadResponse, 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<CompleteUploadResponse>;
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,EAAO,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,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,sBAAsB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEvF;;;;;;;;;;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,KACxD,OAAO,CAAC,sBAAsB,CAUhC,CAAA"}
@@ -0,0 +1,129 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Initiates a file upload to the server.
12
+ *
13
+ * @param {AutoDriveApi} api - The API instance used to send requests.
14
+ * @param {ArgsWithoutPagination<{ mimeType?: string; filename: string; uploadOptions: FileUploadOptions | null }>} args - The arguments for the file upload.
15
+ * @param {string} args.mimeType - The MIME type of the file (optional).
16
+ * @param {string} args.filename - The name of the file to be uploaded.
17
+ * @param {FileUploadOptions | null} args.uploadOptions - Additional options for the file upload (optional).
18
+ * @returns {Promise<FileUpload>} - A promise that resolves to the file upload information.
19
+ * @throws {Error} - Throws an error if the upload fails.
20
+ */
21
+ export const createFileUpload = (api_1, _a) => __awaiter(void 0, [api_1, _a], void 0, function* (api, { mimeType, filename, uploadOptions = {}, }) {
22
+ const response = yield api.sendRequest(`/uploads/file`, {
23
+ method: 'POST',
24
+ headers: new Headers({
25
+ 'Content-Type': 'application/json',
26
+ }),
27
+ }, JSON.stringify({ mimeType, filename, uploadOptions }));
28
+ if (!response.ok) {
29
+ throw new Error(`Failed to create file upload: ${response.statusText}`);
30
+ }
31
+ return response.json();
32
+ });
33
+ /**
34
+ * Initiates a folder upload to the server.
35
+ *
36
+ * @param {AutoDriveApi} api - The API instance used to send requests.
37
+ * @param {ArgsWithoutPagination<{ fileTree: FolderTree; uploadOptions: FileUploadOptions }>} args - The arguments for the folder upload.
38
+ * @param {FolderTree} args.fileTree - The structure of the folder and its contents to be uploaded.
39
+ * @param {FileUploadOptions} args.uploadOptions - Additional options for the folder upload.
40
+ * @returns {Promise<FolderUpload>} - A promise that resolves to the folder upload information.
41
+ * @throws {Error} - Throws an error if the upload fails.
42
+ */
43
+ export const createFolderUpload = (api_1, _a) => __awaiter(void 0, [api_1, _a], void 0, function* (api, { fileTree, uploadOptions, }) {
44
+ const response = yield api.sendRequest(`/uploads/folder`, {
45
+ method: 'POST',
46
+ headers: new Headers({
47
+ 'Content-Type': 'application/json',
48
+ }),
49
+ }, JSON.stringify({ fileTree, uploadOptions }));
50
+ if (!response.ok) {
51
+ throw new Error(`Failed to create folder upload: ${response.statusText}`);
52
+ }
53
+ return response.json();
54
+ });
55
+ /**
56
+ * Creates a file upload within an existing folder upload.
57
+ *
58
+ * @param {AutoDriveApi} api - The API instance used to send requests.
59
+ * @param {ArgsWithoutPagination<{ uploadId: string; name: string; mimeType: string; relativeId: string; uploadOptions: FileUploadOptions }>} args - The arguments for the file upload.
60
+ * @param {string} args.uploadId - The ID of the folder upload to which the file will be added.
61
+ * @param {string} args.name - The name of the file to be uploaded.
62
+ * @param {string} args.mimeType - The MIME type of the file being uploaded.
63
+ * @param {string} args.relativeId - The relative ID of the file within the folder structure.
64
+ * @param {FileUploadOptions} [args.uploadOptions={}] - Additional options for the file upload.
65
+ * @returns {Promise<FileUpload>} - A promise that resolves to the file upload information.
66
+ * @throws {Error} - Throws an error if the upload fails.
67
+ */
68
+ export const createFileUploadWithinFolderUpload = (api_1, _a) => __awaiter(void 0, [api_1, _a], void 0, function* (api, { uploadId, name, mimeType, relativeId, uploadOptions = {}, }) {
69
+ const response = yield api.sendRequest(`/uploads/folder/${uploadId}/file`, {
70
+ method: 'POST',
71
+ headers: new Headers({
72
+ 'Content-Type': 'application/json',
73
+ }),
74
+ }, JSON.stringify({ name, mimeType, relativeId, uploadOptions }));
75
+ if (!response.ok) {
76
+ throw new Error(`Failed to create file upload within folder upload: ${response.statusText}`);
77
+ }
78
+ return response.json();
79
+ });
80
+ /**
81
+ * Uploads a chunk of a file to the server.
82
+ *
83
+ * This function allows for the uploading of a specific chunk of a file
84
+ * during a multi-part upload process. It sends the chunk along with its
85
+ * index to the server, which can be used to reconstruct the file on the
86
+ * server side.
87
+ *
88
+ * @param {AutoDriveApi} api - The API instance used to send requests.
89
+ * @param {ArgsWithoutPagination<{ uploadId: string; chunk: Buffer; index: number }>} args - The arguments for the file chunk upload.
90
+ * @param {string} args.uploadId - The ID of the upload session.
91
+ * @param {Buffer} args.chunk - The chunk of the file to be uploaded.
92
+ * @param {number} args.index - The index of the chunk in the overall file.
93
+ * @returns {Promise<void>} - A promise that resolves when the chunk is uploaded successfully.
94
+ * @throws {Error} - Throws an error if the upload fails.
95
+ */
96
+ export const uploadFileChunk = (api_1, _a) => __awaiter(void 0, [api_1, _a], void 0, function* (api, { uploadId, chunk, index, }) {
97
+ const formData = new FormData();
98
+ formData.append('file', new Blob([chunk]));
99
+ formData.append('index', index.toString());
100
+ const response = yield api.sendRequest(`/uploads/file/${uploadId}/chunk`, {
101
+ method: 'POST',
102
+ }, formData);
103
+ if (!response.ok) {
104
+ throw new Error(`Failed to upload file chunk: ${response.statusText}`);
105
+ }
106
+ });
107
+ /**
108
+ * Completes a file or folder upload session on the server.
109
+ *
110
+ * This function sends a request to the server to finalize the upload
111
+ * process for a given upload session identified by the upload ID. It is
112
+ * typically called after all file chunks have been uploaded. This method
113
+ * can be used to complete both file and folder uploads.
114
+ *
115
+ * @param {AutoDriveApi} api - The API instance used to send requests.
116
+ * @param {ArgsWithoutPagination<{ uploadId: string }>} args - The arguments for completing the upload.
117
+ * @param {string} args.uploadId - The ID of the upload session to complete.
118
+ * @returns {Promise<any>} - A promise that resolves to the response from the server.
119
+ * @throws {Error} - Throws an error if the completion of the upload fails.
120
+ */
121
+ export const completeUpload = (api_1, _a) => __awaiter(void 0, [api_1, _a], void 0, function* (api, { uploadId }) {
122
+ const response = yield api.sendRequest(`/uploads/${uploadId}/complete`, {
123
+ method: 'POST',
124
+ });
125
+ if (!response.ok) {
126
+ throw new Error(`Failed to complete upload: ${response.statusText}`);
127
+ }
128
+ return response.json();
129
+ });
@@ -0,0 +1,49 @@
1
+ import { ArgsWithoutPagination } from '../../utils/types.js';
2
+ import { AutoDriveApi } from '../connection.js';
3
+ /**
4
+ * Shares an object with a specified public ID.
5
+ *
6
+ * This function sends a request to the server to share an object identified
7
+ * by its CID. The object will be shared with the provided public ID, allowing
8
+ * access to the object for users with that ID.
9
+ *
10
+ * @param {AutoDriveApi} api - The API instance used to send requests.
11
+ * @param {ArgsWithoutPagination<{ cid: string; publicId: string }>} query - The query parameters containing the CID of the object to share and the public ID to share it with.
12
+ * @returns {Promise<any>} - A promise that resolves to the response from the server.
13
+ * @throws {Error} - Throws an error if the sharing process fails.
14
+ */
15
+ export declare const shareObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
16
+ cid: string;
17
+ publicId: string;
18
+ }>) => Promise<any>;
19
+ /**
20
+ * Marks an object as deleted by sending a request to the server.
21
+ *
22
+ * This function sends a request to the server to mark an object identified
23
+ * by its CID as deleted. This action is typically irreversible and should
24
+ * be used with caution.
25
+ *
26
+ * @param {AutoDriveApi} api - The API instance used to send requests.
27
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to mark as deleted.
28
+ * @returns {Promise<void>} - A promise that resolves when the object has been marked as deleted.
29
+ * @throws {Error} - Throws an error if the marking process fails.
30
+ */
31
+ export declare const markObjectAsDeleted: (api: AutoDriveApi, query: ArgsWithoutPagination<{
32
+ cid: string;
33
+ }>) => Promise<void>;
34
+ /**
35
+ * Restores an object that has been marked as deleted by sending a request to the server.
36
+ *
37
+ * This function sends a request to the server to restore an object identified
38
+ * by its CID. The restoration process may depend on the server's implementation
39
+ * and the object's current state.
40
+ *
41
+ * @param {AutoDriveApi} api - The API instance used to send requests.
42
+ * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to restore.
43
+ * @returns {Promise<void>} - A promise that resolves when the object has been successfully restored.
44
+ * @throws {Error} - Throws an error if the restoration process fails.
45
+ */
46
+ export declare const restoreObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
47
+ cid: string;
48
+ }>) => Promise<void>;
49
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,QACjB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,iBAkBhE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QACzB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAQd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QACnB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAUd,CAAA"}