@autonomys/auto-drive 1.2.8 → 1.3.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 (66) hide show
  1. package/.env +6 -0
  2. package/README.md +22 -25
  3. package/dist/api/calls/download.d.ts +3 -3
  4. package/dist/api/calls/download.d.ts.map +1 -1
  5. package/dist/api/calls/index.d.ts +26 -19
  6. package/dist/api/calls/index.d.ts.map +1 -1
  7. package/dist/api/calls/read.d.ts +35 -18
  8. package/dist/api/calls/read.d.ts.map +1 -1
  9. package/dist/api/calls/read.js +39 -9
  10. package/dist/api/calls/upload.d.ts +11 -11
  11. package/dist/api/calls/upload.d.ts.map +1 -1
  12. package/dist/api/calls/upload.js +5 -5
  13. package/dist/api/calls/write.d.ts +9 -9
  14. package/dist/api/calls/write.d.ts.map +1 -1
  15. package/dist/api/calls/write.js +4 -4
  16. package/dist/api/connection.d.ts +2 -24
  17. package/dist/api/connection.d.ts.map +1 -1
  18. package/dist/api/connection.js +6 -30
  19. package/dist/api/handler.d.ts +3 -0
  20. package/dist/api/handler.d.ts.map +1 -0
  21. package/dist/api/handler.js +30 -0
  22. package/dist/api/index.d.ts +2 -0
  23. package/dist/api/index.d.ts.map +1 -1
  24. package/dist/api/index.js +2 -0
  25. package/dist/api/models/objects.d.ts +4 -0
  26. package/dist/api/models/objects.d.ts.map +1 -1
  27. package/dist/api/type.d.ts +172 -0
  28. package/dist/api/type.d.ts.map +1 -0
  29. package/dist/api/type.js +8 -0
  30. package/dist/api/types.d.ts +172 -0
  31. package/dist/api/types.d.ts.map +1 -0
  32. package/dist/api/types.js +8 -0
  33. package/dist/api/wrappers.d.ts +2 -115
  34. package/dist/api/wrappers.d.ts.map +1 -1
  35. package/dist/api/wrappers.js +178 -240
  36. package/dist/fs/wrappers.d.ts +1 -2
  37. package/dist/fs/wrappers.d.ts.map +1 -1
  38. package/dist/fs/wrappers.js +18 -19
  39. package/dist/node.d.ts +2 -2
  40. package/dist/node.d.ts.map +1 -1
  41. package/dist/node.js +25 -2
  42. package/package.json +4 -4
  43. package/src/api/calls/download.ts +3 -3
  44. package/src/api/calls/read.ts +61 -18
  45. package/src/api/calls/upload.ts +11 -11
  46. package/src/api/calls/write.ts +10 -10
  47. package/src/api/connection.ts +6 -61
  48. package/src/api/handler.ts +34 -0
  49. package/src/api/index.ts +2 -0
  50. package/src/api/models/objects.ts +5 -0
  51. package/src/api/types.ts +201 -0
  52. package/src/api/wrappers.ts +247 -300
  53. package/src/fs/wrappers.ts +11 -14
  54. package/src/node.ts +2 -2
  55. package/dist/index.d.ts +0 -3
  56. package/dist/index.d.ts.map +0 -1
  57. package/dist/index.js +0 -2
  58. package/dist/utils/folder.d.ts +0 -2
  59. package/dist/utils/folder.d.ts.map +0 -1
  60. package/dist/utils/folder.js +0 -23
  61. package/dist/utils/observable.d.ts +0 -7
  62. package/dist/utils/observable.d.ts.map +0 -1
  63. package/dist/utils/observable.js +0 -15
  64. package/dist/utils/stream.d.ts +0 -3
  65. package/dist/utils/stream.d.ts.map +0 -1
  66. package/dist/utils/stream.js +0 -22
@@ -0,0 +1,201 @@
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
+
7
+ export interface AutoDriveApi extends AutoDriveApiHandler {
8
+ /**
9
+ * Uploads a file to the server with optional encryption and compression.
10
+ *
11
+ * This function reads a file from the provided input, optionally encrypts it
12
+ * using the specified password, and compresses it using the specified algorithm if requested.
13
+ * It uploads the file in chunks to the server, creating an upload session and
14
+ * completing it once all chunks have been successfully uploaded.
15
+ *
16
+ * @param {AutoDriveApi} api - The API instance used to send requests.
17
+ * @param {File} file - The file to be uploaded.
18
+ * @param {UploadFileOptions} options - Options for the upload process.
19
+ * @param {string} [options.password] - The password for encryption (optional).
20
+ * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
21
+ * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
22
+ * @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
23
+ * @throws {Error} - Throws an error if the upload fails at any stage.
24
+ */
25
+ uploadFileFromInput: (
26
+ file: File,
27
+ options: UploadFileOptions,
28
+ uploadChunkSize?: number,
29
+ ) => Promise<string>
30
+ /**
31
+ * Uploads a file to the server with optional encryption and compression.
32
+ *
33
+ * This function reads a file from the provided input, optionally encrypts it
34
+ * using the specified password, and compresses it using the specified algorithm if requested.
35
+ * It uploads the file in chunks to the server, creating an upload session and
36
+ * completing it once all chunks have been successfully uploaded.
37
+ *
38
+ * @param {AutoDriveApi} api - The API instance used to send requests.
39
+ * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
40
+ * @param {UploadFileOptions} options - Options for the upload process.
41
+ * @param {string} [options.password] - The password for encryption (optional).
42
+ * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
43
+ * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
44
+ * @returns {Promise<string>} - The CID of the uploaded file.
45
+ * @throws {Error} - Throws an error if the upload fails at any stage.
46
+ */
47
+ uploadFile: (
48
+ file: GenericFile,
49
+ options: UploadFileOptions,
50
+ uploadChunkSize?: number,
51
+ ) => Promise<string>
52
+ /**
53
+ * Uploads an object as a JSON file to the server.
54
+ *
55
+ * This function serializes the provided object to a JSON string,
56
+ * and then uploads the JSON string as a file to the server.
57
+ *
58
+ * @param {AutoDriveApi} api - The API instance used to send requests.
59
+ * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
60
+ * @param {UploadFileOptions} options - Options for the upload process.
61
+ * @param {string} [options.password] - The password for encryption (optional).
62
+ * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
63
+ * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
64
+ * @returns {Promise<string>} - The CID of the uploaded file.
65
+ * @throws {Error} - Throws an error if the upload fails at any stage.
66
+ */
67
+ uploadObjectAsJSON: (
68
+ object: unknown,
69
+ name?: string | undefined,
70
+ options?: UploadFileOptions,
71
+ uploadChunkSize?: number,
72
+ ) => Promise<string>
73
+ /**
74
+ * Uploads an entire folder to the server.
75
+ *
76
+ * This function retrieves all files within the specified folder,
77
+ * constructs a file tree representation, and initiates the upload
78
+ * process. It also handles optional compression of the files during
79
+ * the upload. If a password is provided, the files will be zipped
80
+ * before uploading.
81
+ *
82
+ * @param {AutoDriveApi} api - The API instance used to send requests.
83
+ * @param {FileList | File[]} fileList - The list of files to be uploaded.
84
+ * @param {Object} options - Options for the upload process.
85
+ * @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
86
+ * @param {string} [options.password] - The password for encryption (optional).
87
+ * @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
88
+ * @throws {Error} - Throws an error if the upload fails at any stage.
89
+ */
90
+ uploadFolderFromInput: (
91
+ fileList: FileList | File[],
92
+ options: {
93
+ uploadChunkSize?: number
94
+ password?: string
95
+ onProgress?: (progress: number) => void
96
+ },
97
+ ) => Promise<string>
98
+ /**
99
+ * Uploads a file within an existing folder upload session.
100
+ *
101
+ * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
102
+ * @param {string} uploadId - The ID of the folder upload session to which the file will be added.
103
+ * @param {string} filepath - The path of the file to be uploaded.
104
+ *
105
+ * @returns {Promise<void>} A promise that resolves when the file upload is complete.
106
+ */
107
+ uploadFileWithinFolderUpload: (
108
+ uploadId: string,
109
+ file: GenericFileWithinFolder,
110
+ uploadChunkSize?: number,
111
+ options?: Pick<UploadFileOptions, 'onProgress'>,
112
+ ) => Promise<string>
113
+ /**
114
+ * Downloads a file from the AutoDrive service.
115
+ *
116
+ * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
117
+ * @param {string} cid - The CID of the file to be downloaded.
118
+ * @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
119
+ */
120
+ downloadFile: (cid: string, password?: string) => Promise<AsyncIterable<Buffer>>
121
+ /**
122
+ * Gets the pending credits for the current user.
123
+ *
124
+ * @returns {Promise<{ upload: number; download: number }>} A promise that resolves to the pending credits.
125
+ */
126
+ getPendingCredits: () => Promise<{ upload: number; download: number }>
127
+ /**
128
+ * Gets the subscription info for the current user.
129
+ *
130
+ * @returns {Promise<SubscriptionInfo>} A promise that resolves to the subscription info.
131
+ */
132
+ getSubscriptionInfo: () => Promise<SubscriptionInfo>
133
+ /**
134
+ * Publishes an object by sending a request to the server.
135
+ *
136
+ * If already published, it will return the same public download URL.
137
+ *
138
+ * @param cid {string} - The CID of the object to publish.
139
+ * @returns {Promise<string>} - The public download URL of the published object.
140
+ */
141
+ publishObject: (cid: string) => Promise<string>
142
+ /**
143
+ * Gets the files of the current user.
144
+ *
145
+ * @param page {number} - The page number to get.
146
+ * @param limit {number} - The number of files to get per page.
147
+ * @returns {Promise<PaginatedResult<ObjectSummary>>} - A promise that resolves to the paginated result of the files.
148
+ */
149
+ getMyFiles: (page: number, limit: number) => Promise<PaginatedResult<ObjectSummary>>
150
+ /**
151
+ * Searches for files by name or CID in the user's files.
152
+ *
153
+ * @param value {string} - The value to search for.
154
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to the list of files matching the search criteria.
155
+ */
156
+ searchByNameOrCIDInMyFiles: (value: string) => Promise<ObjectSummary[]>
157
+ /**
158
+ * Searches for files by name or CID in the global files.
159
+ *
160
+ * @param value {string} - The value to search for.
161
+ * @returns {Promise<ObjectSummary[]>} - A promise that resolves to the list of files matching the search criteria.
162
+ */
163
+ searchByNameOrCID: (value: string) => Promise<ObjectSummary[]>
164
+ }
165
+
166
+ export interface AutoDriveApiHandler {
167
+ sendRequest: (
168
+ relativeUrl: string,
169
+ request: Partial<Request>,
170
+ body?: BodyInit,
171
+ ) => Promise<Response>
172
+ baseUrl: string
173
+ }
174
+
175
+ export type UploadFileOptions = {
176
+ password?: string
177
+ compression?: boolean
178
+ onProgress?: (progress: number) => void
179
+ }
180
+
181
+ export enum OAuthProvider {
182
+ GOOGLE = 'google',
183
+ DISCORD = 'discord',
184
+ }
185
+
186
+ export type ApiKeyAuthProvider = 'apikey'
187
+ export type AuthProvider = ApiKeyAuthProvider | 'oauth'
188
+
189
+ export type ConnectionOptions =
190
+ | {
191
+ provider?: AuthProvider
192
+ apiKey?: string
193
+ url?: null
194
+ network: AutoDriveNetwork
195
+ }
196
+ | {
197
+ provider?: AuthProvider
198
+ apiKey?: string
199
+ url: string
200
+ network?: null
201
+ }