@autonomys/auto-drive 1.2.8 → 1.3.1

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 (50) hide show
  1. package/README.md +22 -25
  2. package/dist/api/calls/download.d.ts +3 -3
  3. package/dist/api/calls/download.d.ts.map +1 -1
  4. package/dist/api/calls/index.d.ts +26 -19
  5. package/dist/api/calls/index.d.ts.map +1 -1
  6. package/dist/api/calls/read.d.ts +35 -18
  7. package/dist/api/calls/read.d.ts.map +1 -1
  8. package/dist/api/calls/read.js +39 -9
  9. package/dist/api/calls/upload.d.ts +11 -11
  10. package/dist/api/calls/upload.d.ts.map +1 -1
  11. package/dist/api/calls/upload.js +5 -5
  12. package/dist/api/calls/write.d.ts +9 -9
  13. package/dist/api/calls/write.d.ts.map +1 -1
  14. package/dist/api/calls/write.js +4 -4
  15. package/dist/api/connection.d.ts +2 -24
  16. package/dist/api/connection.d.ts.map +1 -1
  17. package/dist/api/connection.js +6 -30
  18. package/dist/api/handler.d.ts +3 -0
  19. package/dist/api/handler.d.ts.map +1 -0
  20. package/dist/api/handler.js +30 -0
  21. package/dist/api/index.d.ts +2 -0
  22. package/dist/api/index.d.ts.map +1 -1
  23. package/dist/api/index.js +2 -0
  24. package/dist/api/models/objects.d.ts +4 -0
  25. package/dist/api/models/objects.d.ts.map +1 -1
  26. package/dist/api/types.d.ts +172 -0
  27. package/dist/api/types.d.ts.map +1 -0
  28. package/dist/api/types.js +8 -0
  29. package/dist/api/wrappers.d.ts +2 -115
  30. package/dist/api/wrappers.d.ts.map +1 -1
  31. package/dist/api/wrappers.js +178 -240
  32. package/dist/fs/wrappers.d.ts +1 -2
  33. package/dist/fs/wrappers.d.ts.map +1 -1
  34. package/dist/fs/wrappers.js +18 -19
  35. package/dist/node.d.ts +2 -2
  36. package/dist/node.d.ts.map +1 -1
  37. package/dist/node.js +25 -2
  38. package/package.json +4 -4
  39. package/src/api/calls/download.ts +3 -3
  40. package/src/api/calls/read.ts +61 -18
  41. package/src/api/calls/upload.ts +11 -11
  42. package/src/api/calls/write.ts +10 -10
  43. package/src/api/connection.ts +6 -61
  44. package/src/api/handler.ts +34 -0
  45. package/src/api/index.ts +2 -0
  46. package/src/api/models/objects.ts +5 -0
  47. package/src/api/types.ts +201 -0
  48. package/src/api/wrappers.ts +247 -300
  49. package/src/fs/wrappers.ts +11 -14
  50. package/src/node.ts +2 -2
@@ -13,7 +13,7 @@ exports.completeUpload = exports.uploadFileChunk = exports.createFileUploadWithi
13
13
  /**
14
14
  * Initiates a file upload to the server.
15
15
  *
16
- * @param {AutoDriveApi} api - The API instance used to send requests.
16
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
17
17
  * @param {ArgsWithoutPagination<{ mimeType?: string; filename: string; uploadOptions: FileUploadOptions | null }>} args - The arguments for the file upload.
18
18
  * @param {string} args.mimeType - The MIME type of the file (optional).
19
19
  * @param {string} args.filename - The name of the file to be uploaded.
@@ -37,7 +37,7 @@ exports.createFileUpload = createFileUpload;
37
37
  /**
38
38
  * Initiates a folder upload to the server.
39
39
  *
40
- * @param {AutoDriveApi} api - The API instance used to send requests.
40
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
41
41
  * @param {ArgsWithoutPagination<{ fileTree: FolderTree; uploadOptions: FileUploadOptions }>} args - The arguments for the folder upload.
42
42
  * @param {FolderTree} args.fileTree - The structure of the folder and its contents to be uploaded.
43
43
  * @param {FileUploadOptions} args.uploadOptions - Additional options for the folder upload.
@@ -60,7 +60,7 @@ exports.createFolderUpload = createFolderUpload;
60
60
  /**
61
61
  * Creates a file upload within an existing folder upload.
62
62
  *
63
- * @param {AutoDriveApi} api - The API instance used to send requests.
63
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
64
64
  * @param {ArgsWithoutPagination<{ uploadId: string; name: string; mimeType: string; relativeId: string; uploadOptions: FileUploadOptions }>} args - The arguments for the file upload.
65
65
  * @param {string} args.uploadId - The ID of the folder upload to which the file will be added.
66
66
  * @param {string} args.name - The name of the file to be uploaded.
@@ -91,7 +91,7 @@ exports.createFileUploadWithinFolderUpload = createFileUploadWithinFolderUpload;
91
91
  * index to the server, which can be used to reconstruct the file on the
92
92
  * server side.
93
93
  *
94
- * @param {AutoDriveApi} api - The API instance used to send requests.
94
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
95
95
  * @param {ArgsWithoutPagination<{ uploadId: string; chunk: Buffer; index: number }>} args - The arguments for the file chunk upload.
96
96
  * @param {string} args.uploadId - The ID of the upload session.
97
97
  * @param {Buffer} args.chunk - The chunk of the file to be uploaded.
@@ -119,7 +119,7 @@ exports.uploadFileChunk = uploadFileChunk;
119
119
  * typically called after all file chunks have been uploaded. This method
120
120
  * can be used to complete both file and folder uploads.
121
121
  *
122
- * @param {AutoDriveApi} api - The API instance used to send requests.
122
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
123
123
  * @param {ArgsWithoutPagination<{ uploadId: string }>} args - The arguments for completing the upload.
124
124
  * @param {string} args.uploadId - The ID of the upload session to complete.
125
125
  * @returns {Promise<any>} - A promise that resolves to the response from the server.
@@ -1,5 +1,5 @@
1
1
  import { ArgsWithoutPagination } from '../../utils/types';
2
- import { AutoDriveApi } from '../connection';
2
+ import { AutoDriveApiHandler } from '../types';
3
3
  /**
4
4
  * Shares an object with a specified public ID.
5
5
  *
@@ -7,12 +7,12 @@ import { AutoDriveApi } from '../connection';
7
7
  * by its CID. The object will be shared with the provided public ID, allowing
8
8
  * access to the object for users with that ID.
9
9
  *
10
- * @param {AutoDriveApi} api - The API instance used to send requests.
10
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
11
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
12
  * @returns {Promise<any>} - A promise that resolves to the response from the server.
13
13
  * @throws {Error} - Throws an error if the sharing process fails.
14
14
  */
15
- export declare const shareObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
15
+ export declare const shareObject: (api: AutoDriveApiHandler, query: ArgsWithoutPagination<{
16
16
  cid: string;
17
17
  publicId: string;
18
18
  }>) => Promise<any>;
@@ -23,12 +23,12 @@ export declare const shareObject: (api: AutoDriveApi, query: ArgsWithoutPaginati
23
23
  * by its CID as deleted. This action is typically irreversible and should
24
24
  * be used with caution.
25
25
  *
26
- * @param {AutoDriveApi} api - The API instance used to send requests.
26
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
27
27
  * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to mark as deleted.
28
28
  * @returns {Promise<void>} - A promise that resolves when the object has been marked as deleted.
29
29
  * @throws {Error} - Throws an error if the marking process fails.
30
30
  */
31
- export declare const markObjectAsDeleted: (api: AutoDriveApi, query: ArgsWithoutPagination<{
31
+ export declare const markObjectAsDeleted: (api: AutoDriveApiHandler, query: ArgsWithoutPagination<{
32
32
  cid: string;
33
33
  }>) => Promise<void>;
34
34
  /**
@@ -38,12 +38,12 @@ export declare const markObjectAsDeleted: (api: AutoDriveApi, query: ArgsWithout
38
38
  * by its CID. The restoration process may depend on the server's implementation
39
39
  * and the object's current state.
40
40
  *
41
- * @param {AutoDriveApi} api - The API instance used to send requests.
41
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
42
42
  * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to restore.
43
43
  * @returns {Promise<void>} - A promise that resolves when the object has been successfully restored.
44
44
  * @throws {Error} - Throws an error if the restoration process fails.
45
45
  */
46
- export declare const restoreObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
46
+ export declare const restoreObject: (api: AutoDriveApiHandler, query: ArgsWithoutPagination<{
47
47
  cid: string;
48
48
  }>) => Promise<void>;
49
49
  /**
@@ -53,12 +53,12 @@ export declare const restoreObject: (api: AutoDriveApi, query: ArgsWithoutPagina
53
53
  * by its CID. The publication process may depend on the server's implementation
54
54
  * and the object's current state.
55
55
  *
56
- * @param {AutoDriveApi} api - The API instance used to send requests.
56
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
57
57
  * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to publish.
58
58
  * @returns {Promise<void>} - A promise that resolves when the object has been successfully published.
59
59
  * @throws {Error} - Throws an error if the publication process fails.
60
60
  */
61
- export declare const publishObject: (api: AutoDriveApi, query: ArgsWithoutPagination<{
61
+ export declare const publishObject: (api: AutoDriveApiHandler, query: ArgsWithoutPagination<{
62
62
  cid: string;
63
63
  }>) => Promise<{
64
64
  result: string;
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;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;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QACnB,YAAY,SACV,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAU5B,CAAA"}
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/api/calls/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,QACjB,mBAAmB,SACjB,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,iBAkBhE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QACzB,mBAAmB,SACjB,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAQd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QACnB,mBAAmB,SACjB,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC,IAAI,CAUd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QACnB,mBAAmB,SACjB,qBAAqB,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,KAC5C,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAU5B,CAAA"}
@@ -17,7 +17,7 @@ exports.publishObject = exports.restoreObject = exports.markObjectAsDeleted = ex
17
17
  * by its CID. The object will be shared with the provided public ID, allowing
18
18
  * access to the object for users with that ID.
19
19
  *
20
- * @param {AutoDriveApi} api - The API instance used to send requests.
20
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
21
21
  * @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.
22
22
  * @returns {Promise<any>} - A promise that resolves to the response from the server.
23
23
  * @throws {Error} - Throws an error if the sharing process fails.
@@ -42,7 +42,7 @@ exports.shareObject = shareObject;
42
42
  * by its CID as deleted. This action is typically irreversible and should
43
43
  * be used with caution.
44
44
  *
45
- * @param {AutoDriveApi} api - The API instance used to send requests.
45
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
46
46
  * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to mark as deleted.
47
47
  * @returns {Promise<void>} - A promise that resolves when the object has been marked as deleted.
48
48
  * @throws {Error} - Throws an error if the marking process fails.
@@ -63,7 +63,7 @@ exports.markObjectAsDeleted = markObjectAsDeleted;
63
63
  * by its CID. The restoration process may depend on the server's implementation
64
64
  * and the object's current state.
65
65
  *
66
- * @param {AutoDriveApi} api - The API instance used to send requests.
66
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
67
67
  * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to restore.
68
68
  * @returns {Promise<void>} - A promise that resolves when the object has been successfully restored.
69
69
  * @throws {Error} - Throws an error if the restoration process fails.
@@ -85,7 +85,7 @@ exports.restoreObject = restoreObject;
85
85
  * by its CID. The publication process may depend on the server's implementation
86
86
  * and the object's current state.
87
87
  *
88
- * @param {AutoDriveApi} api - The API instance used to send requests.
88
+ * @param {AutoDriveApiHandler} api - The API instance used to send requests.
89
89
  * @param {ArgsWithoutPagination<{ cid: string }>} query - The query parameters containing the CID of the object to publish.
90
90
  * @returns {Promise<void>} - A promise that resolves when the object has been successfully published.
91
91
  * @throws {Error} - Throws an error if the publication process fails.
@@ -1,25 +1,3 @@
1
- import { AutoDriveNetwork } from './networks';
2
- export interface AutoDriveApi {
3
- sendRequest: (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => Promise<Response>;
4
- baseUrl: string;
5
- }
6
- export declare enum OAuthProvider {
7
- GOOGLE = "google",
8
- DISCORD = "discord"
9
- }
10
- export type ApiKeyAuthProvider = 'apikey';
11
- export type AuthProvider = ApiKeyAuthProvider | 'oauth';
12
- type ConnectionOptions = {
13
- provider?: AuthProvider;
14
- apiKey?: string;
15
- url?: null;
16
- network: AutoDriveNetwork;
17
- } | {
18
- provider?: AuthProvider;
19
- apiKey?: string;
20
- url: string;
21
- network?: null;
22
- };
23
- export declare const createAutoDriveApi: ({ provider, apiKey, url, network, }: ConnectionOptions) => AutoDriveApi;
24
- export {};
1
+ import { AutoDriveApi, ConnectionOptions } from './types';
2
+ export declare const createAutoDriveApi: (options: ConnectionOptions) => AutoDriveApi;
25
3
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,YAAY,CAAA;AAEtE,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,CACX,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,IAAI,CAAC,EAAE,QAAQ,KACZ,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAA;AACzC,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,OAAO,CAAA;AAEvD,KAAK,iBAAiB,GAClB;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,gBAAgB,CAAA;CAC1B,GACD;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA;AAEL,eAAO,MAAM,kBAAkB,wCAK5B,iBAAiB,KAAG,YAuBtB,CAAA"}
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGzD,eAAO,MAAM,kBAAkB,YAAa,iBAAiB,KAAG,YAG/D,CAAA"}
@@ -1,34 +1,10 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createAutoDriveApi = exports.OAuthProvider = void 0;
13
- const networks_1 = require("./networks");
14
- var OAuthProvider;
15
- (function (OAuthProvider) {
16
- OAuthProvider["GOOGLE"] = "google";
17
- OAuthProvider["DISCORD"] = "discord";
18
- })(OAuthProvider || (exports.OAuthProvider = OAuthProvider = {}));
19
- const createAutoDriveApi = ({ provider = 'apikey', apiKey, url = null, network, }) => {
20
- const baseUrl = !network ? url : (0, networks_1.getNetworkUrl)(network);
21
- if (!baseUrl) {
22
- throw new Error('No base URL provided');
23
- }
24
- return {
25
- sendRequest: (relativeUrl, request, body) => __awaiter(void 0, void 0, void 0, function* () {
26
- var _a;
27
- const headers = new Headers(Object.assign(Object.assign({}, Object.fromEntries(((_a = request.headers) === null || _a === void 0 ? void 0 : _a.entries()) || [])), { 'x-auth-provider': provider, Authorization: `Bearer ${apiKey}` }));
28
- const fullRequest = Object.assign(Object.assign({}, request), { headers: new Headers(headers), body });
29
- return fetch(`${baseUrl}${relativeUrl}`, fullRequest);
30
- }),
31
- baseUrl,
32
- };
3
+ exports.createAutoDriveApi = void 0;
4
+ const handler_1 = require("./handler");
5
+ const wrappers_1 = require("./wrappers");
6
+ const createAutoDriveApi = (options) => {
7
+ const apiHandler = (0, handler_1.createApiRequestHandler)(options);
8
+ return (0, wrappers_1.createApiInterface)(apiHandler);
33
9
  };
34
10
  exports.createAutoDriveApi = createAutoDriveApi;
@@ -0,0 +1,3 @@
1
+ import { AutoDriveApiHandler, ConnectionOptions } from './types';
2
+ export declare const createApiRequestHandler: ({ provider, apiKey, url, network, }: ConnectionOptions) => AutoDriveApiHandler;
3
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/api/handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhE,eAAO,MAAM,uBAAuB,wCAKjC,iBAAiB,KAAG,mBAyBtB,CAAA"}
@@ -0,0 +1,30 @@
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.createApiRequestHandler = void 0;
13
+ const networks_1 = require("./networks");
14
+ const createApiRequestHandler = ({ provider = 'apikey', apiKey, url = null, network, }) => {
15
+ const baseUrl = !network ? url : (0, networks_1.getNetworkUrl)(network);
16
+ if (!baseUrl) {
17
+ throw new Error('No base URL provided');
18
+ }
19
+ const api = {
20
+ sendRequest: (relativeUrl, request, body) => __awaiter(void 0, void 0, void 0, function* () {
21
+ var _a;
22
+ const headers = new Headers(Object.assign(Object.assign({}, Object.fromEntries(((_a = request.headers) === null || _a === void 0 ? void 0 : _a.entries()) || [])), { 'x-auth-provider': provider, Authorization: `Bearer ${apiKey}` }));
23
+ const fullRequest = Object.assign(Object.assign({}, request), { headers: new Headers(headers), body });
24
+ return fetch(`${baseUrl}${relativeUrl}`, fullRequest);
25
+ }),
26
+ baseUrl,
27
+ };
28
+ return api;
29
+ };
30
+ exports.createApiRequestHandler = createApiRequestHandler;
@@ -1,5 +1,7 @@
1
1
  export * from './calls/index';
2
2
  export * from './connection';
3
+ export * from './handler';
3
4
  export * from './models/index';
5
+ export * from './types';
4
6
  export * from './wrappers';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
package/dist/api/index.js CHANGED
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./calls/index"), exports);
18
18
  __exportStar(require("./connection"), exports);
19
+ __exportStar(require("./handler"), exports);
19
20
  __exportStar(require("./models/index"), exports);
21
+ __exportStar(require("./types"), exports);
20
22
  __exportStar(require("./wrappers"), exports);
@@ -47,6 +47,10 @@ export interface ObjectUploadStatus {
47
47
  minimumBlockDepth: number | null;
48
48
  maximumBlockDepth: number | null;
49
49
  }
50
+ export interface ObjectSearchResult {
51
+ cid: string;
52
+ name: string;
53
+ }
50
54
  export type ObjectSummary = {
51
55
  headCid: string;
52
56
  name?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/api/models/objects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,sBAAsB,CAAA;AAC5E,UAAU,gBAAgB;IACxB,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,gBAAgB,EAAE,CAAA;IAC5B,aAAa,EAAE,iBAAiB,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,SAAS,EAAE,CAAA;IACnB,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC,CAAA;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,oBAAY,KAAK;IACf,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB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AO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,YAAY,EAAE,kBAAkB,CAAA;CACjC,GAAG,CACA;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,CAAC,gBAAgB,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,UAAU,CAAC,CAAA;CAC9D,CACJ,CAAA;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,YAAY,EAAE,kBAAkB,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB"}
@@ -0,0 +1,172 @@
1
+ import { ObjectSummary } from './models';
2
+ import { PaginatedResult } from './models/common';
3
+ import { GenericFile, GenericFileWithinFolder } from './models/file';
4
+ import { SubscriptionInfo } from './models/user';
5
+ import { AutoDriveNetwork } from './networks';
6
+ export interface AutoDriveApi extends AutoDriveApiHandler {
7
+ /**
8
+ * Uploads a file to the server with optional encryption and compression.
9
+ *
10
+ * This function reads a file from the provided input, optionally encrypts it
11
+ * using the specified password, and compresses it using the specified algorithm if requested.
12
+ * It uploads the file in chunks to the server, creating an upload session and
13
+ * completing it once all chunks have been successfully uploaded.
14
+ *
15
+ * @param {AutoDriveApi} api - The API instance used to send requests.
16
+ * @param {File} file - The file to be uploaded.
17
+ * @param {UploadFileOptions} options - Options for the upload process.
18
+ * @param {string} [options.password] - The password for encryption (optional).
19
+ * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
20
+ * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
21
+ * @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
22
+ * @throws {Error} - Throws an error if the upload fails at any stage.
23
+ */
24
+ uploadFileFromInput: (file: File, options: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
25
+ /**
26
+ * Uploads a file to the server with optional encryption and compression.
27
+ *
28
+ * This function reads a file from the provided input, optionally encrypts it
29
+ * using the specified password, and compresses it using the specified algorithm if requested.
30
+ * It uploads the file in chunks to the server, creating an upload session and
31
+ * completing it once all chunks have been successfully uploaded.
32
+ *
33
+ * @param {AutoDriveApi} api - The API instance used to send requests.
34
+ * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
35
+ * @param {UploadFileOptions} options - Options for the upload process.
36
+ * @param {string} [options.password] - The password for encryption (optional).
37
+ * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
38
+ * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
39
+ * @returns {Promise<string>} - The CID of the uploaded file.
40
+ * @throws {Error} - Throws an error if the upload fails at any stage.
41
+ */
42
+ uploadFile: (file: GenericFile, options: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
43
+ /**
44
+ * Uploads an object as a JSON file to the server.
45
+ *
46
+ * This function serializes the provided object to a JSON string,
47
+ * and then uploads the JSON string as a file to the server.
48
+ *
49
+ * @param {AutoDriveApi} api - The API instance used to send requests.
50
+ * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
51
+ * @param {UploadFileOptions} options - Options for the upload process.
52
+ * @param {string} [options.password] - The password for encryption (optional).
53
+ * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
54
+ * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
55
+ * @returns {Promise<string>} - The CID of the uploaded file.
56
+ * @throws {Error} - Throws an error if the upload fails at any stage.
57
+ */
58
+ uploadObjectAsJSON: (object: unknown, name?: string | undefined, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
59
+ /**
60
+ * Uploads an entire folder to the server.
61
+ *
62
+ * This function retrieves all files within the specified folder,
63
+ * constructs a file tree representation, and initiates the upload
64
+ * process. It also handles optional compression of the files during
65
+ * the upload. If a password is provided, the files will be zipped
66
+ * before uploading.
67
+ *
68
+ * @param {AutoDriveApi} api - The API instance used to send requests.
69
+ * @param {FileList | File[]} fileList - The list of files to be uploaded.
70
+ * @param {Object} options - Options for the upload process.
71
+ * @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
72
+ * @param {string} [options.password] - The password for encryption (optional).
73
+ * @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
74
+ * @throws {Error} - Throws an error if the upload fails at any stage.
75
+ */
76
+ uploadFolderFromInput: (fileList: FileList | File[], options: {
77
+ uploadChunkSize?: number;
78
+ password?: string;
79
+ onProgress?: (progress: number) => void;
80
+ }) => Promise<string>;
81
+ /**
82
+ * Uploads a file within an existing folder upload session.
83
+ *
84
+ * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
85
+ * @param {string} uploadId - The ID of the folder upload session to which the file will be added.
86
+ * @param {string} filepath - The path of the file to be uploaded.
87
+ *
88
+ * @returns {Promise<void>} A promise that resolves when the file upload is complete.
89
+ */
90
+ uploadFileWithinFolderUpload: (uploadId: string, file: GenericFileWithinFolder, uploadChunkSize?: number, options?: Pick<UploadFileOptions, 'onProgress'>) => Promise<string>;
91
+ /**
92
+ * Downloads a file from the AutoDrive service.
93
+ *
94
+ * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
95
+ * @param {string} cid - The CID of the file to be downloaded.
96
+ * @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
97
+ */
98
+ downloadFile: (cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
99
+ /**
100
+ * Gets the pending credits for the current user.
101
+ *
102
+ * @returns {Promise<{ upload: number; download: number }>} A promise that resolves to the pending credits.
103
+ */
104
+ getPendingCredits: () => Promise<{
105
+ upload: number;
106
+ download: number;
107
+ }>;
108
+ /**
109
+ * Gets the subscription info for the current user.
110
+ *
111
+ * @returns {Promise<SubscriptionInfo>} A promise that resolves to the subscription info.
112
+ */
113
+ getSubscriptionInfo: () => Promise<SubscriptionInfo>;
114
+ /**
115
+ * Publishes an object by sending a request to the server.
116
+ *
117
+ * If already published, it will return the same public download URL.
118
+ *
119
+ * @param cid {string} - The CID of the object to publish.
120
+ * @returns {Promise<string>} - The public download URL of the published object.
121
+ */
122
+ publishObject: (cid: string) => Promise<string>;
123
+ /**
124
+ * Gets the files of the current user.
125
+ *
126
+ * @param page {number} - The page number to get.
127
+ * @param limit {number} - The number of files to get per page.
128
+ * @returns {Promise<PaginatedResult<ObjectSummary>>} - A promise that resolves to the paginated result of the files.
129
+ */
130
+ getMyFiles: (page: number, limit: number) => Promise<PaginatedResult<ObjectSummary>>;
131
+ /**
132
+ * Searches for files by name or CID in the user's files.
133
+ *
134
+ * @param value {string} - The value to search for.
135
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to the list of files matching the search criteria.
136
+ */
137
+ searchByNameOrCIDInMyFiles: (value: string) => Promise<ObjectSummary[]>;
138
+ /**
139
+ * Searches for files by name or CID in the global files.
140
+ *
141
+ * @param value {string} - The value to search for.
142
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to the list of files matching the search criteria.
143
+ */
144
+ searchByNameOrCID: (value: string) => Promise<ObjectSummary[]>;
145
+ }
146
+ export interface AutoDriveApiHandler {
147
+ sendRequest: (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => Promise<Response>;
148
+ baseUrl: string;
149
+ }
150
+ export type UploadFileOptions = {
151
+ password?: string;
152
+ compression?: boolean;
153
+ onProgress?: (progress: number) => void;
154
+ };
155
+ export declare enum OAuthProvider {
156
+ GOOGLE = "google",
157
+ DISCORD = "discord"
158
+ }
159
+ export type ApiKeyAuthProvider = 'apikey';
160
+ export type AuthProvider = ApiKeyAuthProvider | 'oauth';
161
+ export type ConnectionOptions = {
162
+ provider?: AuthProvider;
163
+ apiKey?: string;
164
+ url?: null;
165
+ network: AutoDriveNetwork;
166
+ } | {
167
+ provider?: AuthProvider;
168
+ apiKey?: string;
169
+ url: string;
170
+ network?: null;
171
+ };
172
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD;;;;;;;;;;;;;;;;OAgBG;IACH,mBAAmB,EAAE,CACnB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,iBAAiB,EAC1B,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,MAAM,CAAC,CAAA;IACpB;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,EAAE,CACV,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,iBAAiB,EAC1B,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,MAAM,CAAC,CAAA;IACpB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,EAAE,CAClB,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,EACzB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,MAAM,CAAC,CAAA;IACpB;;;;;;;;;;;;;;;;OAgBG;IACH,qBAAqB,EAAE,CACrB,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,EAC3B,OAAO,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,CAAC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QAAQ,KACZ,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC,CAAA;AAED,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAA;AACzC,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,OAAO,CAAA;AAEvD,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,gBAAgB,CAAA;CAC1B,GACD;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuthProvider = void 0;
4
+ var OAuthProvider;
5
+ (function (OAuthProvider) {
6
+ OAuthProvider["GOOGLE"] = "google";
7
+ OAuthProvider["DISCORD"] = "discord";
8
+ })(OAuthProvider || (exports.OAuthProvider = OAuthProvider = {}));
@@ -1,116 +1,3 @@
1
- import { AutoDriveApi } from './connection';
2
- import { GenericFile, GenericFileWithinFolder } from './models/file';
3
- import { SubscriptionInfo } from './models/user';
4
- export type UploadFileOptions = {
5
- password?: string;
6
- compression?: boolean;
7
- onProgress?: (progress: number) => void;
8
- };
9
- /**
10
- * Uploads a file to the server with optional encryption and compression.
11
- *
12
- * This function reads a file from the provided input, optionally encrypts it
13
- * using the specified password, and compresses it using the specified algorithm if requested.
14
- * It uploads the file in chunks to the server, creating an upload session and
15
- * completing it once all chunks have been successfully uploaded.
16
- *
17
- * @param {AutoDriveApi} api - The API instance used to send requests.
18
- * @param {File} file - The file to be uploaded.
19
- * @param {UploadFileOptions} options - Options for the upload process.
20
- * @param {string} [options.password] - The password for encryption (optional).
21
- * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
22
- * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
23
- * @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
24
- * @throws {Error} - Throws an error if the upload fails at any stage.
25
- */
26
- export declare const uploadFileFromInput: (api: AutoDriveApi, file: File, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
27
- /**
28
- * Uploads a file to the server with optional encryption and compression.
29
- *
30
- * This function reads a file from the provided input, optionally encrypts it
31
- * using the specified password, and compresses it using the specified algorithm if requested.
32
- * It uploads the file in chunks to the server, creating an upload session and
33
- * completing it once all chunks have been successfully uploaded.
34
- *
35
- * @param {AutoDriveApi} api - The API instance used to send requests.
36
- * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
37
- * @param {UploadFileOptions} options - Options for the upload process.
38
- * @param {string} [options.password] - The password for encryption (optional).
39
- * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
40
- * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
41
- * @returns {Promise<string>} - The CID of the uploaded file.
42
- * @throws {Error} - Throws an error if the upload fails at any stage.
43
- */
44
- export declare const uploadFile: (api: AutoDriveApi, file: GenericFile, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
45
- /**
46
- * Uploads an object as a JSON file to the server.
47
- *
48
- * This function serializes the provided object to a JSON string,
49
- * and then uploads the JSON string as a file to the server.
50
- *
51
- * @param {AutoDriveApi} api - The API instance used to send requests.
52
- * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
53
- * @param {UploadFileOptions} options - Options for the upload process.
54
- * @param {string} [options.password] - The password for encryption (optional).
55
- * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
56
- * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
57
- * @returns {Promise<string>} - The CID of the uploaded file.
58
- * @throws {Error} - Throws an error if the upload fails at any stage.
59
- */
60
- export declare const uploadObjectAsJSON: (api: AutoDriveApi, object: unknown, name?: string | undefined, options?: UploadFileOptions, uploadChunkSize?: number) => Promise<string>;
61
- /**
62
- * Uploads an entire folder to the server.
63
- *
64
- * This function retrieves all files within the specified folder,
65
- * constructs a file tree representation, and initiates the upload
66
- * process. It also handles optional compression of the files during
67
- * the upload. If a password is provided, the files will be zipped
68
- * before uploading.
69
- *
70
- * @param {AutoDriveApi} api - The API instance used to send requests.
71
- * @param {FileList | File[]} fileList - The list of files to be uploaded.
72
- * @param {Object} options - Options for the upload process.
73
- * @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
74
- * @param {string} [options.password] - The password for encryption (optional).
75
- * @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
76
- * @throws {Error} - Throws an error if the upload fails at any stage.
77
- */
78
- export declare const uploadFolderFromInput: (api: AutoDriveApi, fileList: FileList | File[], { uploadChunkSize, password, onProgress, }?: {
79
- uploadChunkSize?: number;
80
- password?: string;
81
- onProgress?: (progress: number) => void;
82
- }) => Promise<string>;
83
- /**
84
- * Uploads a file within an existing folder upload session.
85
- *
86
- * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
87
- * @param {string} uploadId - The ID of the folder upload session to which the file will be added.
88
- * @param {string} filepath - The path of the file to be uploaded.
89
- *
90
- * @returns {Promise<void>} A promise that resolves when the file upload is complete.
91
- */
92
- export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId: string, file: GenericFileWithinFolder, uploadChunkSize?: number, options?: Pick<UploadFileOptions, "onProgress">) => Promise<string>;
93
- /**
94
- * Downloads a file from the AutoDrive service.
95
- *
96
- * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
97
- * @param {string} cid - The CID of the file to be downloaded.
98
- * @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
99
- */
100
- export declare const downloadFile: (api: AutoDriveApi, cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
101
- export declare const getPendingCredits: (api: AutoDriveApi) => Promise<{
102
- upload: number;
103
- download: number;
104
- }>;
105
- export declare const getSubscriptionInfo: (api: AutoDriveApi) => Promise<SubscriptionInfo>;
106
- /**
107
- * Publishes an object by sending a request to the server.
108
- *
109
- * If already published, it will return the same public download URL.
110
- *
111
- * @param api {AutoDriveApi} - The API instance used to send requests.
112
- * @param cid {string} - The CID of the object to publish.
113
- * @returns {Promise<string>} - The public download URL of the published object.
114
- */
115
- export declare const publishObject: (api: AutoDriveApi, cid: string) => Promise<string>;
1
+ import { AutoDriveApi, AutoDriveApiHandler } from './types';
2
+ export declare const createApiInterface: (api: AutoDriveApiHandler) => AutoDriveApi;
116
3
  //# sourceMappingURL=wrappers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/api/wrappers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC,CAAA;AA6BD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,QACzB,YAAY,QACX,IAAI,YACD,iBAAiB,oBACR,MAAM,KACvB,OAAO,C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