@autonomys/auto-drive 1.1.2 → 1.1.3

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 (79) hide show
  1. package/package.json +5 -3
  2. package/src/api/calls/index.ts +11 -4
  3. package/src/api/wrappers.ts +12 -22
  4. package/src/fs/wrappers.ts +3 -3
  5. package/tsconfig.json +1 -8
  6. package/.env +0 -6
  7. package/LICENSE +0 -18
  8. package/dist/api/calls/download.d.ts +0 -6
  9. package/dist/api/calls/download.d.ts.map +0 -1
  10. package/dist/api/calls/download.js +0 -25
  11. package/dist/api/calls/index.d.ts +0 -5
  12. package/dist/api/calls/index.d.ts.map +0 -1
  13. package/dist/api/calls/index.js +0 -20
  14. package/dist/api/calls/read.d.ts +0 -99
  15. package/dist/api/calls/read.d.ts.map +0 -1
  16. package/dist/api/calls/read.js +0 -159
  17. package/dist/api/calls/upload.d.ts +0 -93
  18. package/dist/api/calls/upload.d.ts.map +0 -1
  19. package/dist/api/calls/upload.js +0 -137
  20. package/dist/api/calls/write.d.ts +0 -49
  21. package/dist/api/calls/write.d.ts.map +0 -1
  22. package/dist/api/calls/write.js +0 -80
  23. package/dist/api/connection.d.ts +0 -15
  24. package/dist/api/connection.d.ts.map +0 -1
  25. package/dist/api/connection.js +0 -28
  26. package/dist/api/index.d.ts +0 -5
  27. package/dist/api/index.d.ts.map +0 -1
  28. package/dist/api/index.js +0 -20
  29. package/dist/api/models/common.d.ts +0 -5
  30. package/dist/api/models/common.d.ts.map +0 -1
  31. package/dist/api/models/common.js +0 -2
  32. package/dist/api/models/file.d.ts +0 -10
  33. package/dist/api/models/file.d.ts.map +0 -1
  34. package/dist/api/models/file.js +0 -2
  35. package/dist/api/models/folderTree.d.ts +0 -47
  36. package/dist/api/models/folderTree.d.ts.map +0 -1
  37. package/dist/api/models/folderTree.js +0 -105
  38. package/dist/api/models/index.d.ts +0 -3
  39. package/dist/api/models/index.d.ts.map +0 -1
  40. package/dist/api/models/index.js +0 -18
  41. package/dist/api/models/objects.d.ts +0 -72
  42. package/dist/api/models/objects.d.ts.map +0 -1
  43. package/dist/api/models/objects.js +0 -13
  44. package/dist/api/models/uploads.d.ts +0 -148
  45. package/dist/api/models/uploads.d.ts.map +0 -1
  46. package/dist/api/models/uploads.js +0 -51
  47. package/dist/api/wrappers.d.ts +0 -84
  48. package/dist/api/wrappers.d.ts.map +0 -1
  49. package/dist/api/wrappers.js +0 -286
  50. package/dist/browser.d.ts +0 -3
  51. package/dist/browser.d.ts.map +0 -1
  52. package/dist/browser.js +0 -18
  53. package/dist/fs/index.d.ts +0 -3
  54. package/dist/fs/index.d.ts.map +0 -1
  55. package/dist/fs/index.js +0 -18
  56. package/dist/fs/utils.d.ts +0 -6
  57. package/dist/fs/utils.d.ts.map +0 -1
  58. package/dist/fs/utils.js +0 -84
  59. package/dist/fs/wrappers.d.ts +0 -45
  60. package/dist/fs/wrappers.d.ts.map +0 -1
  61. package/dist/fs/wrappers.js +0 -123
  62. package/dist/node.d.ts +0 -3
  63. package/dist/node.d.ts.map +0 -1
  64. package/dist/node.js +0 -18
  65. package/dist/utils/async.d.ts +0 -5
  66. package/dist/utils/async.d.ts.map +0 -1
  67. package/dist/utils/async.js +0 -73
  68. package/dist/utils/index.d.ts +0 -5
  69. package/dist/utils/index.d.ts.map +0 -1
  70. package/dist/utils/index.js +0 -20
  71. package/dist/utils/misc.d.ts +0 -2
  72. package/dist/utils/misc.d.ts.map +0 -1
  73. package/dist/utils/misc.js +0 -5
  74. package/dist/utils/observable.d.ts +0 -7
  75. package/dist/utils/observable.d.ts.map +0 -1
  76. package/dist/utils/observable.js +0 -52
  77. package/dist/utils/types.d.ts +0 -6
  78. package/dist/utils/types.d.ts.map +0 -1
  79. package/dist/utils/types.js +0 -2
@@ -1 +0,0 @@
1
- {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/api/models/objects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,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iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;CACjC;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,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"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OwnerRole = exports.Scope = void 0;
4
- var Scope;
5
- (function (Scope) {
6
- Scope["Global"] = "global";
7
- Scope["User"] = "user";
8
- })(Scope || (exports.Scope = Scope = {}));
9
- var OwnerRole;
10
- (function (OwnerRole) {
11
- OwnerRole["ADMIN"] = "admin";
12
- OwnerRole["VIEWER"] = "viewer";
13
- })(OwnerRole || (exports.OwnerRole = OwnerRole = {}));
@@ -1,148 +0,0 @@
1
- import { z } from 'zod';
2
- export declare enum UploadType {
3
- FILE = "file",
4
- FOLDER = "folder"
5
- }
6
- export declare enum UploadStatus {
7
- PENDING = "pending",
8
- COMPLETED = "completed",
9
- MIGRATING = "migrating",
10
- CANCELLED = "cancelled",
11
- FAILED = "failed"
12
- }
13
- export declare const fileUploadSchema: z.ZodObject<{
14
- id: z.ZodString;
15
- rootId: z.ZodString;
16
- relativeId: z.ZodNullable<z.ZodString>;
17
- type: z.ZodNativeEnum<typeof UploadType>;
18
- status: z.ZodNativeEnum<typeof UploadStatus>;
19
- fileTree: z.ZodNull;
20
- name: z.ZodString;
21
- mimeType: z.ZodNullable<z.ZodString>;
22
- oauthProvider: z.ZodString;
23
- oauthUserId: z.ZodString;
24
- }, "strip", z.ZodTypeAny, {
25
- name: string;
26
- type: UploadType;
27
- status: UploadStatus;
28
- id: string;
29
- rootId: string;
30
- relativeId: string | null;
31
- fileTree: null;
32
- mimeType: string | null;
33
- oauthProvider: string;
34
- oauthUserId: string;
35
- }, {
36
- name: string;
37
- type: UploadType;
38
- status: UploadStatus;
39
- id: string;
40
- rootId: string;
41
- relativeId: string | null;
42
- fileTree: null;
43
- mimeType: string | null;
44
- oauthProvider: string;
45
- oauthUserId: string;
46
- }>;
47
- export declare enum CompressionAlgorithm {
48
- ZLIB = "ZLIB"
49
- }
50
- export interface CompressionOptions {
51
- algorithm: CompressionAlgorithm;
52
- level?: number;
53
- chunkSize?: number;
54
- }
55
- export type FileUploadOptions = {
56
- compression?: CompressionOptions;
57
- encryption?: EncryptionOptions;
58
- };
59
- export declare enum EncryptionAlgorithm {
60
- AES_256_GCM = "AES_256_GCM"
61
- }
62
- export interface EncryptionOptions {
63
- algorithm: EncryptionAlgorithm;
64
- chunkSize?: number;
65
- }
66
- export type FileUpload = z.infer<typeof fileUploadSchema> & {
67
- uploadOptions: FileUploadOptions | null;
68
- };
69
- export declare const folderUploadSchema: z.ZodObject<{
70
- id: z.ZodString;
71
- rootId: z.ZodString;
72
- relativeId: z.ZodNullable<z.ZodString>;
73
- type: z.ZodNativeEnum<typeof UploadType>;
74
- status: z.ZodNativeEnum<typeof UploadStatus>;
75
- fileTree: z.ZodObject<{
76
- name: z.ZodString;
77
- type: z.ZodLiteral<"folder">;
78
- children: z.ZodArray<z.ZodLazy<z.ZodType<import("./folderTree").FolderTree, z.ZodTypeDef, import("./folderTree").FolderTree>>, "many">;
79
- id: z.ZodString;
80
- }, "strip", z.ZodTypeAny, {
81
- name: string;
82
- type: "folder";
83
- children: import("./folderTree").FolderTree[];
84
- id: string;
85
- }, {
86
- name: string;
87
- type: "folder";
88
- children: import("./folderTree").FolderTree[];
89
- id: string;
90
- }>;
91
- name: z.ZodString;
92
- mimeType: z.ZodNull;
93
- oauthProvider: z.ZodString;
94
- oauthUserId: z.ZodString;
95
- uploadOptions: z.ZodNull;
96
- }, "strip", z.ZodTypeAny, {
97
- name: string;
98
- type: UploadType;
99
- status: UploadStatus;
100
- id: string;
101
- rootId: string;
102
- relativeId: string | null;
103
- fileTree: {
104
- name: string;
105
- type: "folder";
106
- children: import("./folderTree").FolderTree[];
107
- id: string;
108
- };
109
- mimeType: null;
110
- oauthProvider: string;
111
- oauthUserId: string;
112
- uploadOptions: null;
113
- }, {
114
- name: string;
115
- type: UploadType;
116
- status: UploadStatus;
117
- id: string;
118
- rootId: string;
119
- relativeId: string | null;
120
- fileTree: {
121
- name: string;
122
- type: "folder";
123
- children: import("./folderTree").FolderTree[];
124
- id: string;
125
- };
126
- mimeType: null;
127
- oauthProvider: string;
128
- oauthUserId: string;
129
- uploadOptions: null;
130
- }>;
131
- export type FolderUpload = z.infer<typeof folderUploadSchema>;
132
- export type CompleteUploadResponse = {
133
- cid: string;
134
- };
135
- export type UploadFileStatus = {
136
- type: 'file';
137
- progress: number;
138
- cid?: string;
139
- };
140
- export type UploadFolderStatus = {
141
- type: 'folder';
142
- progress: number;
143
- cid?: string;
144
- };
145
- export type UploadChunksStatus = {
146
- uploadBytes: number;
147
- };
148
- //# sourceMappingURL=uploads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/api/models/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,oBAAY,UAAU;IACpB,IAAI,SAAS;I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AAkB,GAAG;IAC/B,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.folderUploadSchema = exports.EncryptionAlgorithm = exports.CompressionAlgorithm = exports.fileUploadSchema = exports.UploadStatus = exports.UploadType = void 0;
4
- const zod_1 = require("zod");
5
- const folderTree_1 = require("./folderTree");
6
- var UploadType;
7
- (function (UploadType) {
8
- UploadType["FILE"] = "file";
9
- UploadType["FOLDER"] = "folder";
10
- })(UploadType || (exports.UploadType = UploadType = {}));
11
- var UploadStatus;
12
- (function (UploadStatus) {
13
- UploadStatus["PENDING"] = "pending";
14
- UploadStatus["COMPLETED"] = "completed";
15
- UploadStatus["MIGRATING"] = "migrating";
16
- UploadStatus["CANCELLED"] = "cancelled";
17
- UploadStatus["FAILED"] = "failed";
18
- })(UploadStatus || (exports.UploadStatus = UploadStatus = {}));
19
- exports.fileUploadSchema = zod_1.z.object({
20
- id: zod_1.z.string(),
21
- rootId: zod_1.z.string(),
22
- relativeId: zod_1.z.string().nullable(),
23
- type: zod_1.z.nativeEnum(UploadType),
24
- status: zod_1.z.nativeEnum(UploadStatus),
25
- fileTree: zod_1.z.null(),
26
- name: zod_1.z.string(),
27
- mimeType: zod_1.z.string().nullable(),
28
- oauthProvider: zod_1.z.string(),
29
- oauthUserId: zod_1.z.string(),
30
- });
31
- var CompressionAlgorithm;
32
- (function (CompressionAlgorithm) {
33
- CompressionAlgorithm["ZLIB"] = "ZLIB";
34
- })(CompressionAlgorithm || (exports.CompressionAlgorithm = CompressionAlgorithm = {}));
35
- var EncryptionAlgorithm;
36
- (function (EncryptionAlgorithm) {
37
- EncryptionAlgorithm["AES_256_GCM"] = "AES_256_GCM";
38
- })(EncryptionAlgorithm || (exports.EncryptionAlgorithm = EncryptionAlgorithm = {}));
39
- exports.folderUploadSchema = zod_1.z.object({
40
- id: zod_1.z.string(),
41
- rootId: zod_1.z.string(),
42
- relativeId: zod_1.z.string().nullable(),
43
- type: zod_1.z.nativeEnum(UploadType),
44
- status: zod_1.z.nativeEnum(UploadStatus),
45
- fileTree: folderTree_1.FolderTreeFolderSchema,
46
- name: zod_1.z.string(),
47
- mimeType: zod_1.z.null(),
48
- oauthProvider: zod_1.z.string(),
49
- oauthUserId: zod_1.z.string(),
50
- uploadOptions: zod_1.z.null(),
51
- });
@@ -1,84 +0,0 @@
1
- import { PromisedObservable } from '../utils/observable';
2
- import { AutoDriveApi } from './connection';
3
- import { GenericFile, GenericFileWithinFolder } from './models/file';
4
- import { UploadChunksStatus, UploadFileStatus, UploadFolderStatus } from './models/uploads';
5
- export type UploadFileOptions = {
6
- password?: string;
7
- compression?: boolean;
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) => PromisedObservable<UploadFileStatus>;
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 {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
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) => PromisedObservable<UploadFileStatus>;
45
- /**
46
- * Uploads an entire folder to the server.
47
- *
48
- * This function retrieves all files within the specified folder,
49
- * constructs a file tree representation, and initiates the upload
50
- * process. It also handles optional compression of the files during
51
- * the upload. If a password is provided, the files will be zipped
52
- * before uploading.
53
- *
54
- * @param {AutoDriveApi} api - The API instance used to send requests.
55
- * @param {FileList | File[]} fileList - The list of files to be uploaded.
56
- * @param {Object} options - Options for the upload process.
57
- * @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
58
- * @param {string} [options.password] - The password for encryption (optional).
59
- * @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
60
- * @throws {Error} - Throws an error if the upload fails at any stage.
61
- */
62
- export declare const uploadFolderFromInput: (api: AutoDriveApi, fileList: FileList | File[], { uploadChunkSize, password }?: {
63
- uploadChunkSize?: number;
64
- password?: string;
65
- }) => Promise<PromisedObservable<UploadFileStatus | UploadFolderStatus>>;
66
- /**
67
- * Uploads a file within an existing folder upload session.
68
- *
69
- * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
70
- * @param {string} uploadId - The ID of the folder upload session to which the file will be added.
71
- * @param {string} filepath - The path of the file to be uploaded.
72
- *
73
- * @returns {Promise<void>} A promise that resolves when the file upload is complete.
74
- */
75
- export declare const uploadFileWithinFolderUpload: (api: AutoDriveApi, uploadId: string, file: GenericFileWithinFolder, uploadChunkSize?: number) => PromisedObservable<UploadChunksStatus>;
76
- /**
77
- * Downloads a file from the AutoDrive service.
78
- *
79
- * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
80
- * @param {string} cid - The CID of the file to be downloaded.
81
- * @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
82
- */
83
- export declare const downloadFile: (api: AutoDriveApi, cid: string, password?: string) => Promise<AsyncIterable<Buffer>>;
84
- //# sourceMappingURL=wrappers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src/api/wrappers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAWxD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEpE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE3F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAuBD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,QACzB,YAAY,QACX,IAAI,YACD,iBAAiB,oBACR,MAAM,KACvB,kBAAkB,CAAC,gBAAgB,CAgDrC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,QAChB,YAAY,QACX,WAAW,YACR,iBAAiB,oBACR,MAAM,KACvB,kBAAkB,CAAC,gBAAgB,CAiDrC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,QAC3B,YAAY,YACP,QAAQ,GAAG,IAAI,EAAE,kCACI;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7E,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,GAAG,kBAAkB,CAAC,CA8DnE,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,QAClC,YAAY,YACP,MAAM,QACV,uBAAuB,oBACX,MAAM,KACvB,kBAAkB,CAAC,kBAAkB,CAkBvC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAClB,YAAY,OACZ,MAAM,aACA,MAAM,KAChB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAwB/B,CAAA"}
@@ -1,286 +0,0 @@
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
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __importDefault = (this && this.__importDefault) || function (mod) {
19
- return (mod && mod.__esModule) ? mod : { "default": mod };
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.downloadFile = exports.uploadFileWithinFolderUpload = exports.uploadFolderFromInput = exports.uploadFile = exports.uploadFileFromInput = void 0;
23
- const mime_types_1 = __importDefault(require("mime-types"));
24
- const async_1 = require("../utils/async");
25
- const misc_1 = require("../utils/misc");
26
- const observable_1 = require("../utils/observable");
27
- const index_1 = require("./calls/index");
28
- const folderTree_1 = require("./models/folderTree");
29
- const UPLOAD_FILE_CHUNK_SIZE = 1024 * 1024;
30
- const uploadFileChunks = (api, fileUploadId, asyncIterable, uploadChunkSize = UPLOAD_FILE_CHUNK_SIZE) => {
31
- return new observable_1.PromisedObservable((subscriber) => __awaiter(void 0, void 0, void 0, function* () {
32
- var _a, e_1, _b, _c;
33
- let index = 0;
34
- let uploadBytes = 0;
35
- try {
36
- for (var _d = true, _e = __asyncValues((0, async_1.asyncByChunk)(asyncIterable, uploadChunkSize)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
37
- _c = _f.value;
38
- _d = false;
39
- const chunk = _c;
40
- yield (0, index_1.uploadFileChunk)(api, { uploadId: fileUploadId, chunk, index });
41
- uploadBytes += chunk.length;
42
- subscriber.next({ uploadBytes });
43
- index++;
44
- }
45
- }
46
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
47
- finally {
48
- try {
49
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
50
- }
51
- finally { if (e_1) throw e_1.error; }
52
- }
53
- subscriber.complete();
54
- }));
55
- };
56
- /**
57
- * Uploads a file to the server with optional encryption and compression.
58
- *
59
- * This function reads a file from the provided input, optionally encrypts it
60
- * using the specified password, and compresses it using the specified algorithm if requested.
61
- * It uploads the file in chunks to the server, creating an upload session and
62
- * completing it once all chunks have been successfully uploaded.
63
- *
64
- * @param {AutoDriveApi} api - The API instance used to send requests.
65
- * @param {File} file - The file to be uploaded.
66
- * @param {UploadFileOptions} options - Options for the upload process.
67
- * @param {string} [options.password] - The password for encryption (optional).
68
- * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
69
- * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
70
- * @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
71
- * @throws {Error} - Throws an error if the upload fails at any stage.
72
- */
73
- const uploadFileFromInput = (api, file, options = {}, uploadChunkSize) => {
74
- const { password = undefined, compression = true } = options;
75
- return new observable_1.PromisedObservable((subscriber) => __awaiter(void 0, void 0, void 0, function* () {
76
- const { stringToCid, compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = yield import('@autonomys/auto-dag-data');
77
- let asyncIterable = (0, async_1.fileToIterable)(file);
78
- if (compression) {
79
- asyncIterable = compressFile(asyncIterable, {
80
- level: 9,
81
- algorithm: CompressionAlgorithm.ZLIB,
82
- });
83
- }
84
- if (password) {
85
- asyncIterable = encryptFile(asyncIterable, password, {
86
- algorithm: EncryptionAlgorithm.AES_256_GCM,
87
- });
88
- }
89
- const uploadOptions = {
90
- compression: compression
91
- ? {
92
- level: 9,
93
- algorithm: CompressionAlgorithm.ZLIB,
94
- }
95
- : undefined,
96
- encryption: password
97
- ? {
98
- algorithm: EncryptionAlgorithm.AES_256_GCM,
99
- }
100
- : undefined,
101
- };
102
- const fileUpload = yield (0, index_1.createFileUpload)(api, {
103
- mimeType: mime_types_1.default.lookup(file.name) || undefined,
104
- filename: file.name,
105
- uploadOptions,
106
- });
107
- yield uploadFileChunks(api, fileUpload.id, asyncIterable, uploadChunkSize).forEach((e) => subscriber.next({ type: 'file', progress: (0, misc_1.progressToPercentage)(e.uploadBytes, file.size) }));
108
- const result = yield (0, index_1.completeUpload)(api, { uploadId: fileUpload.id });
109
- subscriber.next({ type: 'file', progress: 100, cid: result.cid });
110
- subscriber.complete();
111
- }));
112
- };
113
- exports.uploadFileFromInput = uploadFileFromInput;
114
- /**
115
- * Uploads a file to the server with optional encryption and compression.
116
- *
117
- * This function reads a file from the provided input, optionally encrypts it
118
- * using the specified password, and compresses it using the specified algorithm if requested.
119
- * It uploads the file in chunks to the server, creating an upload session and
120
- * completing it once all chunks have been successfully uploaded.
121
- *
122
- * @param {AutoDriveApi} api - The API instance used to send requests.
123
- * @param {File | GenericFile} file - The file to be uploaded, which can be a File or a GenericFile.
124
- * @param {UploadFileOptions} options - Options for the upload process.
125
- * @param {string} [options.password] - The password for encryption (optional).
126
- * @param {boolean} [options.compression=true] - Whether to compress the file (optional).
127
- * @param {number} [uploadChunkSize] - The size of each chunk to upload (optional).
128
- * @returns {PromisedObservable<UploadFileStatus>} - An observable that emits the upload status.
129
- * @throws {Error} - Throws an error if the upload fails at any stage.
130
- */
131
- const uploadFile = (api, file, options = {}, uploadChunkSize) => {
132
- const { password = undefined, compression = true } = options;
133
- return new observable_1.PromisedObservable((subscriber) => __awaiter(void 0, void 0, void 0, function* () {
134
- const { stringToCid, compressFile, CompressionAlgorithm, encryptFile, EncryptionAlgorithm } = yield import('@autonomys/auto-dag-data');
135
- let asyncIterable = file.read();
136
- if (compression) {
137
- asyncIterable = compressFile(asyncIterable, {
138
- level: 9,
139
- algorithm: CompressionAlgorithm.ZLIB,
140
- });
141
- }
142
- if (password) {
143
- asyncIterable = encryptFile(asyncIterable, password, {
144
- algorithm: EncryptionAlgorithm.AES_256_GCM,
145
- });
146
- }
147
- const uploadOptions = {
148
- compression: compression
149
- ? {
150
- level: 9,
151
- algorithm: CompressionAlgorithm.ZLIB,
152
- }
153
- : undefined,
154
- encryption: password
155
- ? {
156
- algorithm: EncryptionAlgorithm.AES_256_GCM,
157
- }
158
- : undefined,
159
- };
160
- const fileUpload = yield (0, index_1.createFileUpload)(api, {
161
- mimeType: mime_types_1.default.lookup(file.name) || undefined,
162
- filename: file.name,
163
- uploadOptions,
164
- });
165
- yield uploadFileChunks(api, fileUpload.id, asyncIterable, uploadChunkSize).forEach((e) => subscriber.next({ type: 'file', progress: (0, misc_1.progressToPercentage)(e.uploadBytes, file.size) }));
166
- const result = yield (0, index_1.completeUpload)(api, { uploadId: fileUpload.id });
167
- subscriber.next({ type: 'file', progress: 100, cid: result.cid });
168
- subscriber.complete();
169
- }));
170
- };
171
- exports.uploadFile = uploadFile;
172
- /**
173
- * Uploads an entire folder to the server.
174
- *
175
- * This function retrieves all files within the specified folder,
176
- * constructs a file tree representation, and initiates the upload
177
- * process. It also handles optional compression of the files during
178
- * the upload. If a password is provided, the files will be zipped
179
- * before uploading.
180
- *
181
- * @param {AutoDriveApi} api - The API instance used to send requests.
182
- * @param {FileList | File[]} fileList - The list of files to be uploaded.
183
- * @param {Object} options - Options for the upload process.
184
- * @param {number} [options.uploadChunkSize] - The size of each chunk to upload (optional).
185
- * @param {string} [options.password] - The password for encryption (optional).
186
- * @returns {PromisedObservable<UploadFileStatus | UploadFolderStatus>} - An observable that emits the upload status.
187
- * @throws {Error} - Throws an error if the upload fails at any stage.
188
- */
189
- const uploadFolderFromInput = (api_1, fileList_1, ...args_1) => __awaiter(void 0, [api_1, fileList_1, ...args_1], void 0, function* (api, fileList, { uploadChunkSize, password } = {}) {
190
- const files = fileList instanceof FileList ? Array.from(fileList) : fileList;
191
- const fileTree = (0, folderTree_1.constructFromInput)(files);
192
- // If password is provided, we zip the files and upload the zip file
193
- if (password) {
194
- const filesMap = Object.fromEntries(files.map((file) => [file.webkitRelativePath, file]));
195
- const zipBlob = yield (0, folderTree_1.constructZipBlobFromTreeAndPaths)(fileTree, filesMap);
196
- const name = fileList[0].webkitRelativePath.split('/').filter(Boolean)[0];
197
- return (0, exports.uploadFile)(api, {
198
- read: () => (0, async_1.fileToIterable)(zipBlob),
199
- name: `${name}.zip`,
200
- mimeType: 'application/zip',
201
- size: zipBlob.size,
202
- }, {
203
- password,
204
- compression: true,
205
- });
206
- }
207
- return new observable_1.PromisedObservable((subscriber) => __awaiter(void 0, void 0, void 0, function* () {
208
- // Otherwise, we upload the files as a folder w/o compression or encryption
209
- const folderUpload = yield (0, index_1.createFolderUpload)(api, {
210
- fileTree,
211
- });
212
- let currentBytesUploaded = 0;
213
- const totalSize = files.reduce((acc, file) => acc + file.size, 0);
214
- for (const file of files) {
215
- yield (0, exports.uploadFileWithinFolderUpload)(api, folderUpload.id, {
216
- read: () => (0, async_1.fileToIterable)(file),
217
- name: file.name,
218
- mimeType: mime_types_1.default.lookup(file.name) || undefined,
219
- size: file.size,
220
- path: file.webkitRelativePath,
221
- }, uploadChunkSize).forEach((e) => {
222
- subscriber.next({
223
- type: 'folder',
224
- progress: (0, misc_1.progressToPercentage)(currentBytesUploaded + e.uploadBytes, totalSize),
225
- });
226
- });
227
- currentBytesUploaded += file.size;
228
- }
229
- const result = yield (0, index_1.completeUpload)(api, { uploadId: folderUpload.id });
230
- subscriber.next({ type: 'folder', progress: 100, cid: result.cid });
231
- subscriber.complete();
232
- }));
233
- });
234
- exports.uploadFolderFromInput = uploadFolderFromInput;
235
- /**
236
- * Uploads a file within an existing folder upload session.
237
- *
238
- * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
239
- * @param {string} uploadId - The ID of the folder upload session to which the file will be added.
240
- * @param {string} filepath - The path of the file to be uploaded.
241
- *
242
- * @returns {Promise<void>} A promise that resolves when the file upload is complete.
243
- */
244
- const uploadFileWithinFolderUpload = (api, uploadId, file, uploadChunkSize) => {
245
- return new observable_1.PromisedObservable((subscriber) => __awaiter(void 0, void 0, void 0, function* () {
246
- const fileUpload = yield (0, index_1.createFileUploadWithinFolderUpload)(api, {
247
- uploadId,
248
- name: file.name,
249
- mimeType: file.mimeType,
250
- relativeId: file.path,
251
- uploadOptions: {},
252
- });
253
- yield uploadFileChunks(api, fileUpload.id, file.read(), uploadChunkSize).forEach((e) => subscriber.next({ uploadBytes: e.uploadBytes }));
254
- yield (0, index_1.completeUpload)(api, { uploadId: fileUpload.id });
255
- subscriber.complete();
256
- }));
257
- };
258
- exports.uploadFileWithinFolderUpload = uploadFileWithinFolderUpload;
259
- /**
260
- * Downloads a file from the AutoDrive service.
261
- *
262
- * @param {AutoDriveApi} api - The API instance to interact with the AutoDrive service.
263
- * @param {string} cid - The CID of the file to be downloaded.
264
- * @returns {Promise<ReadableStream<Uint8Array>>} A promise that resolves to a ReadableStream of the downloaded file.
265
- */
266
- const downloadFile = (api, cid, password) => __awaiter(void 0, void 0, void 0, function* () {
267
- var _a, _b;
268
- const { decompressFile, CompressionAlgorithm, EncryptionAlgorithm, decryptFile } = yield import('@autonomys/auto-dag-data');
269
- const metadata = yield (0, index_1.getObjectMetadata)(api, { cid });
270
- let iterable = (0, async_1.asyncFromStream)(yield (0, index_1.downloadObject)(api, { cid }));
271
- if ((_a = metadata.uploadOptions) === null || _a === void 0 ? void 0 : _a.encryption) {
272
- if (!password) {
273
- throw new Error('Password is required to decrypt the file');
274
- }
275
- iterable = decryptFile(iterable, password, {
276
- algorithm: EncryptionAlgorithm.AES_256_GCM,
277
- });
278
- }
279
- if ((_b = metadata.uploadOptions) === null || _b === void 0 ? void 0 : _b.compression) {
280
- iterable = decompressFile(iterable, {
281
- algorithm: CompressionAlgorithm.ZLIB,
282
- });
283
- }
284
- return iterable;
285
- });
286
- exports.downloadFile = downloadFile;
package/dist/browser.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './api/index';
2
- export * from './utils/index';
3
- //# sourceMappingURL=browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
package/dist/browser.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./api/index"), exports);
18
- __exportStar(require("./utils/index"), exports);
@@ -1,3 +0,0 @@
1
- export * from './utils';
2
- export * from './wrappers';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
package/dist/fs/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./utils"), exports);
18
- __exportStar(require("./wrappers"), exports);
@@ -1,6 +0,0 @@
1
- import { WriteStream } from 'fs';
2
- import { FolderTree } from '../api/models/folderTree';
3
- export declare const getFiles: (folderPath: string) => Promise<string[]>;
4
- export declare const createWriteStreamAdapter: (nodeWriteStream: WriteStream) => WritableStream<Uint8Array>;
5
- export declare const constructZipFromTreeAndFileSystemPaths: (tree: FolderTree, files: Record<string, string>) => Promise<Blob>;
6
- //# sourceMappingURL=utils.d.ts.map