@protontech/drive-sdk 0.0.11 → 0.0.12

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 (100) hide show
  1. package/dist/cache/index.d.ts +2 -0
  2. package/dist/cache/index.js +6 -0
  3. package/dist/cache/index.js.map +1 -0
  4. package/dist/cache/interface.d.ts +105 -0
  5. package/dist/cache/interface.js +3 -0
  6. package/dist/cache/interface.js.map +1 -0
  7. package/dist/cache/memoryCache.d.ts +18 -0
  8. package/dist/cache/memoryCache.js +78 -0
  9. package/dist/cache/memoryCache.js.map +1 -0
  10. package/dist/cache/memoryCache.test.d.ts +1 -0
  11. package/dist/cache/memoryCache.test.js +121 -0
  12. package/dist/cache/memoryCache.test.js.map +1 -0
  13. package/dist/crypto/hmac.d.ts +22 -0
  14. package/dist/crypto/hmac.js +44 -0
  15. package/dist/crypto/hmac.js.map +1 -0
  16. package/dist/crypto/utils.d.ts +2 -0
  17. package/dist/crypto/utils.js +35 -0
  18. package/dist/crypto/utils.js.map +1 -0
  19. package/dist/errors.d.ts +138 -0
  20. package/dist/errors.js +163 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/interface/account.js +3 -0
  23. package/dist/interface/account.js.map +1 -0
  24. package/dist/interface/author.d.ts +26 -0
  25. package/dist/interface/author.js +3 -0
  26. package/dist/interface/author.js.map +1 -0
  27. package/dist/interface/download.d.ts +29 -0
  28. package/dist/interface/download.js +3 -0
  29. package/dist/interface/download.js.map +1 -0
  30. package/dist/interface/httpClient.d.ts +38 -0
  31. package/dist/interface/httpClient.js +3 -0
  32. package/dist/interface/httpClient.js.map +1 -0
  33. package/dist/interface/result.d.ts +9 -0
  34. package/dist/interface/result.js +11 -0
  35. package/dist/interface/result.js.map +1 -0
  36. package/dist/interface/thumbnail.d.ts +17 -0
  37. package/dist/interface/thumbnail.js +9 -0
  38. package/dist/interface/thumbnail.js.map +1 -0
  39. package/dist/interface/upload.d.ts +16 -0
  40. package/dist/interface/upload.js +3 -0
  41. package/dist/interface/upload.js.map +1 -0
  42. package/dist/internal/apiService/errorCodes.d.ts +30 -0
  43. package/dist/internal/apiService/errorCodes.js +11 -0
  44. package/dist/internal/apiService/errorCodes.js.map +1 -0
  45. package/dist/internal/apiService/observerStream.d.ts +3 -0
  46. package/dist/internal/apiService/observerStream.js +15 -0
  47. package/dist/internal/apiService/observerStream.js.map +1 -0
  48. package/dist/internal/batchLoading.d.ts +34 -0
  49. package/dist/internal/batchLoading.js +68 -0
  50. package/dist/internal/batchLoading.js.map +1 -0
  51. package/dist/internal/batchLoading.test.d.ts +1 -0
  52. package/dist/internal/batchLoading.test.js +50 -0
  53. package/dist/internal/batchLoading.test.js.map +1 -0
  54. package/dist/internal/download/controller.d.ts +8 -0
  55. package/dist/internal/download/controller.js +22 -0
  56. package/dist/internal/download/controller.js.map +1 -0
  57. package/dist/internal/download/queue.d.ts +5 -0
  58. package/dist/internal/download/queue.js +31 -0
  59. package/dist/internal/download/queue.js.map +1 -0
  60. package/dist/internal/errors.js +28 -0
  61. package/dist/internal/errors.js.map +1 -0
  62. package/dist/internal/errors.test.js +22 -0
  63. package/dist/internal/errors.test.js.map +1 -0
  64. package/dist/internal/events/interface.d.ts +47 -0
  65. package/dist/internal/events/interface.js +12 -0
  66. package/dist/internal/events/interface.js.map +1 -0
  67. package/dist/internal/nodes/mediaTypes.d.ts +2 -0
  68. package/dist/internal/nodes/mediaTypes.js +13 -0
  69. package/dist/internal/nodes/mediaTypes.js.map +1 -0
  70. package/dist/internal/nodes/validations.d.ts +4 -0
  71. package/dist/internal/nodes/validations.js +21 -0
  72. package/dist/internal/nodes/validations.js.map +1 -0
  73. package/dist/internal/uids.d.ts +38 -0
  74. package/dist/internal/uids.js +85 -0
  75. package/dist/internal/uids.js.map +1 -0
  76. package/dist/internal/upload/chunkStreamReader.d.ts +13 -0
  77. package/dist/internal/upload/chunkStreamReader.js +46 -0
  78. package/dist/internal/upload/chunkStreamReader.js.map +1 -0
  79. package/dist/internal/upload/chunkStreamReader.test.d.ts +1 -0
  80. package/dist/internal/upload/chunkStreamReader.test.js +75 -0
  81. package/dist/internal/upload/chunkStreamReader.test.js.map +1 -0
  82. package/dist/internal/upload/controller.d.ts +8 -0
  83. package/dist/internal/upload/controller.js +25 -0
  84. package/dist/internal/upload/controller.js.map +1 -0
  85. package/dist/internal/upload/digests.d.ts +8 -0
  86. package/dist/internal/upload/digests.js +22 -0
  87. package/dist/internal/upload/digests.js.map +1 -0
  88. package/dist/internal/upload/queue.d.ts +5 -0
  89. package/dist/internal/upload/queue.js +32 -0
  90. package/dist/internal/upload/queue.js.map +1 -0
  91. package/dist/internal/utils.d.ts +1 -0
  92. package/dist/internal/utils.js +13 -0
  93. package/dist/internal/utils.js.map +1 -0
  94. package/dist/internal/wait.d.ts +3 -0
  95. package/dist/internal/wait.js +28 -0
  96. package/dist/internal/wait.js.map +1 -0
  97. package/dist/internal/wait.test.d.ts +1 -0
  98. package/dist/internal/wait.test.js +21 -0
  99. package/dist/internal/wait.test.js.map +1 -0
  100. package/package.json +1 -1
package/dist/errors.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegrityError = exports.DecryptionError = exports.ConnectionError = exports.RateLimitedError = exports.ServerError = exports.NodeAlreadyExistsValidationError = exports.ValidationError = exports.AbortError = exports.ProtonDriveError = void 0;
4
+ const ttag_1 = require("ttag");
5
+ /**
6
+ * Base class for all SDK errors.
7
+ *
8
+ * This class can be used for catching all SDK errors. The error should have
9
+ * translated message in the `message` property that should be shown to the
10
+ * user without any modification.
11
+ *
12
+ * No retries should be done as that is already handled by the SDK.
13
+ *
14
+ * When SDK throws an error and it is not `ProtonDriveError`, it is unhandled error
15
+ * by the SDK and usually indicates bug in the SDK. Please, report it.
16
+ */
17
+ class ProtonDriveError extends Error {
18
+ name = 'ProtonDriveError';
19
+ }
20
+ exports.ProtonDriveError = ProtonDriveError;
21
+ /**
22
+ * Error thrown when the operation is aborted.
23
+ *
24
+ * This error is thrown when the operation is aborted by the user.
25
+ * For example, by calling `abort()` on the `AbortSignal`.
26
+ */
27
+ class AbortError extends ProtonDriveError {
28
+ name = 'AbortError';
29
+ constructor(message) {
30
+ super(message || (0, ttag_1.c)('Error').t `Operation aborted`);
31
+ }
32
+ }
33
+ exports.AbortError = AbortError;
34
+ /**
35
+ * Error thrown when the validation fails.
36
+ *
37
+ * This error is thrown when the validation of the input fails.
38
+ * Validation can be done on the client side or on the server side.
39
+ *
40
+ * For example, on the client, it can be thrown when the node name doesn't
41
+ * follow the required format, etc., while on the server side, it can be thrown
42
+ * when there is not enough permissions, etc.
43
+ */
44
+ class ValidationError extends ProtonDriveError {
45
+ name = 'ValidationError';
46
+ /**
47
+ * Internal API code.
48
+ *
49
+ * Use only for debugging purposes.
50
+ */
51
+ code;
52
+ constructor(message, code) {
53
+ super(message);
54
+ this.code = code;
55
+ }
56
+ }
57
+ exports.ValidationError = ValidationError;
58
+ /**
59
+ * Error thrown when the node already exists.
60
+ *
61
+ * This error is thrown when the node with the same name already exists in the
62
+ * parent folder. The client should ask the user to replace the existing node
63
+ * or choose another name. The available name is provided in the `availableName`
64
+ * property (that will contain original name with the index that can be used).
65
+ */
66
+ class NodeAlreadyExistsValidationError extends ValidationError {
67
+ name = 'NodeAlreadyExistsValidationError';
68
+ availableName;
69
+ constructor(message, code, availableName) {
70
+ super(message, code);
71
+ this.availableName = availableName;
72
+ }
73
+ }
74
+ exports.NodeAlreadyExistsValidationError = NodeAlreadyExistsValidationError;
75
+ /**
76
+ * Error thrown when the API call fails.
77
+ *
78
+ * This error covers both HTTP errors and API errors. SDK automatically
79
+ * retries the request before the error is thrown. The sepcific algorithm
80
+ * used for retries depends on the type of the error.
81
+ *
82
+ * Client should not retry the request when this error is thrown.
83
+ */
84
+ class ServerError extends ProtonDriveError {
85
+ name = 'ServerError';
86
+ /**
87
+ * HTTP status code of the response.
88
+ *
89
+ * Use only for debugging purposes.
90
+ */
91
+ statusCode;
92
+ /**
93
+ * Internal API code.
94
+ *
95
+ * Use only for debugging purposes.
96
+ */
97
+ code;
98
+ }
99
+ exports.ServerError = ServerError;
100
+ /**
101
+ * Error thrown when the client makes too many requests to the API.
102
+ *
103
+ * SDK is configured to stay below the rate limits, but it can still happen if
104
+ * client is running multiple SDKs in parallel, or if the rate limits are
105
+ * changed on the server side.
106
+ *
107
+ * SDK automatically retries the request before the error is thrown after
108
+ * waiting for the required time specified by the server.
109
+ *
110
+ * Client should slow down calling SDK when this error is thrown.
111
+ *
112
+ * You can be also notified about the rate limits by the `requestsThrottled`
113
+ * event. See `onMessage` method on the SDK class for more details.
114
+ */
115
+ class RateLimitedError extends ServerError {
116
+ name = 'RateLimitedError';
117
+ code = 429;
118
+ }
119
+ exports.RateLimitedError = RateLimitedError;
120
+ /**
121
+ * Error thrown when the client is not connected to the internet.
122
+ *
123
+ * Client should check the internet connection when this error is thrown.
124
+ *
125
+ * You can also be notified about the connection status by the `offline` event
126
+ * See `onMessage` method on the SDK class for more details.
127
+ */
128
+ class ConnectionError extends ProtonDriveError {
129
+ name = 'ConnectionError';
130
+ }
131
+ exports.ConnectionError = ConnectionError;
132
+ /**
133
+ * Error thrown when the decryption fails.
134
+ *
135
+ * Client should report this error to the user and report bug report.
136
+ *
137
+ * In most cases, there is no decryption error. Every decryption error should
138
+ * be not exposed but set as empty value on the node, for example. But in the
139
+ * case of the file content, if block cannot be decrypted, decryption error
140
+ * is thrown.
141
+ */
142
+ class DecryptionError extends ProtonDriveError {
143
+ name = 'DecryptionError';
144
+ }
145
+ exports.DecryptionError = DecryptionError;
146
+ /**
147
+ * Error thrown when the data integrity check fails.
148
+ *
149
+ * Client should report this error to the user and report bug report.
150
+ *
151
+ * For example, it can happen when hashes don't match, etc. In some cases,
152
+ * SDK allows to run command without verification checks for debug purposes.
153
+ */
154
+ class IntegrityError extends ProtonDriveError {
155
+ name = 'IntegrityError';
156
+ debug;
157
+ constructor(message, debug) {
158
+ super(message);
159
+ this.debug = debug;
160
+ }
161
+ }
162
+ exports.IntegrityError = IntegrityError;
163
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,+BAAyB;AAEzB;;;;;;;;;;;GAWG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACvC,IAAI,GAAG,kBAAkB,CAAC;CAC7B;AAFD,4CAEC;AAED;;;;;GAKG;AACH,MAAa,UAAW,SAAQ,gBAAgB;IAC5C,IAAI,GAAG,YAAY,CAAC;IAEpB,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,IAAI,IAAA,QAAC,EAAC,OAAO,CAAC,CAAC,CAAC,CAAA,mBAAmB,CAAC,CAAC;IACtD,CAAC;CACJ;AAND,gCAMC;AAED;;;;;;;;;GASG;AACH,MAAa,eAAgB,SAAQ,gBAAgB;IACjD,IAAI,GAAG,iBAAiB,CAAC;IAEzB;;;;OAIG;IACa,IAAI,CAAU;IAE9B,YAAY,OAAe,EAAE,IAAa;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAdD,0CAcC;AAED;;;;;;;GAOG;AACH,MAAa,gCAAiC,SAAQ,eAAe;IACjE,IAAI,GAAG,kCAAkC,CAAC;IAE1B,aAAa,CAAS;IAEtC,YAAY,OAAe,EAAE,IAAY,EAAE,aAAqB;QAC5D,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;CACJ;AATD,4EASC;AAED;;;;;;;;GAQG;AACH,MAAa,WAAY,SAAQ,gBAAgB;IAC7C,IAAI,GAAG,aAAa,CAAC;IAErB;;;;OAIG;IACa,UAAU,CAAU;IACpC;;;;OAIG;IACa,IAAI,CAAU;CACjC;AAfD,kCAeC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAa,gBAAiB,SAAQ,WAAW;IAC7C,IAAI,GAAG,kBAAkB,CAAC;IAE1B,IAAI,GAAG,GAAG,CAAC;CACd;AAJD,4CAIC;AAED;;;;;;;GAOG;AACH,MAAa,eAAgB,SAAQ,gBAAgB;IACjD,IAAI,GAAG,iBAAiB,CAAC;CAC5B;AAFD,0CAEC;AAED;;;;;;;;;GASG;AACH,MAAa,eAAgB,SAAQ,gBAAgB;IACjD,IAAI,GAAG,iBAAiB,CAAC;CAC5B;AAFD,0CAEC;AAED;;;;;;;GAOG;AACH,MAAa,cAAe,SAAQ,gBAAgB;IAChD,IAAI,GAAG,gBAAgB,CAAC;IAER,KAAK,CAAU;IAE/B,YAAY,OAAe,EAAE,KAAc;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AATD,wCASC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/interface/account.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { Result } from './result';
2
+ /**
3
+ * Author with verification status.
4
+ *
5
+ * It can be either a string (email) or an anonymous user.
6
+ *
7
+ * If author cannot be verified, the result is failure with an error.
8
+ * The client can still get claimed author from the error object, but
9
+ * it must be used with caution.
10
+ */
11
+ export type Author = Result<string | AnonymousUser, UnverifiedAuthorError>;
12
+ /**
13
+ * Anonymous user. Used when user shares folder publicly and anonymous
14
+ * users can access the folder and upload new files without being logged in.
15
+ */
16
+ export type AnonymousUser = null;
17
+ /**
18
+ * Unverified author.
19
+ *
20
+ * If author cannot be verified, the result is this object containing
21
+ * the claimed author and the verification error.
22
+ */
23
+ export type UnverifiedAuthorError = {
24
+ claimedAuthor?: string;
25
+ error: string;
26
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=author.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"author.js","sourceRoot":"","sources":["../../src/interface/author.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ export interface FileDownloader {
2
+ /**
3
+ * Get the claimed size of the file in bytes.
4
+ *
5
+ * This provides total clear-text size of the file. This is encrypted
6
+ * information that is not known to the Proton Drive and thus it is
7
+ * explicitely stated as claimed only and must be treated that way.
8
+ * It can be wrong or missing completely.
9
+ */
10
+ getClaimedSizeInBytes(): number | undefined;
11
+ /**
12
+ * Download, decrypt and verify the content from the server and write
13
+ * to the provided stream.
14
+ *
15
+ * @param onProgress - Callback that is called with the number of downloaded bytes
16
+ */
17
+ writeToStream(streamFactory: WritableStream, onProgress: (downloadedBytes: number) => void): DownloadController;
18
+ /**
19
+ * Same as `writeToStream` but without verification checks.
20
+ *
21
+ * Use this only for debugging purposes.
22
+ */
23
+ unsafeWriteToStream(streamFactory: WritableStream, onProgress: (downloadedBytes: number) => void): DownloadController;
24
+ }
25
+ export interface DownloadController {
26
+ pause(): void;
27
+ resume(): void;
28
+ completion(): Promise<void>;
29
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=download.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/interface/download.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ export interface ProtonDriveHTTPClient {
2
+ fetchJson(options: ProtonDriveHTTPClientJsonOptions): Promise<Response>;
3
+ fetchBlob(options: ProtonDriveHTTPClientBlobOptions): Promise<Response>;
4
+ }
5
+ export type ProtonDriveHTTPClientJsonOptions = ProtonDriveHTTPClientBaseOptions & {
6
+ json?: object;
7
+ };
8
+ export type ProtonDriveHTTPClientBlobOptions = ProtonDriveHTTPClientBaseOptions & {
9
+ body?: XMLHttpRequestBodyInit;
10
+ onProgress?: (progress: number) => void;
11
+ };
12
+ type ProtonDriveHTTPClientBaseOptions = {
13
+ url: string;
14
+ method: string;
15
+ headers: Headers;
16
+ /**
17
+ * The timeout in milliseconds.
18
+ *
19
+ * When timeout is reached, the request will be aborted with TimeoutError.
20
+ */
21
+ timeoutMs: number;
22
+ signal?: AbortSignal;
23
+ };
24
+ export type ProtonDriveConfig = {
25
+ /**
26
+ * The base URL for the Proton Drive (without schema).
27
+ *
28
+ * If not provided, defaults to 'drive-api.proton.me'.
29
+ */
30
+ baseUrl?: string;
31
+ /**
32
+ * The language to use for error messages.
33
+ *
34
+ * If not provided, defaults to 'en'.
35
+ */
36
+ language?: string;
37
+ };
38
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=httpClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../src/interface/httpClient.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export type Result<T, E> = {
2
+ ok: true;
3
+ value: T;
4
+ } | {
5
+ ok: false;
6
+ error: E;
7
+ };
8
+ export declare function resultOk<T, E>(value: T): Result<T, E>;
9
+ export declare function resultError<T, E>(error: E): Result<T, E>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resultOk = resultOk;
4
+ exports.resultError = resultError;
5
+ function resultOk(value) {
6
+ return { ok: true, value };
7
+ }
8
+ function resultError(error) {
9
+ return { ok: false, error };
10
+ }
11
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/interface/result.ts"],"names":[],"mappings":";;AAIA,4BAEC;AAED,kCAEC;AAND,SAAgB,QAAQ,CAAO,KAAQ;IACnC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC;AAED,SAAgB,WAAW,CAAO,KAAQ;IACtC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,17 @@
1
+ export type Thumbnail = {
2
+ type: ThumbnailType;
3
+ thumbnail: Uint8Array;
4
+ };
5
+ export declare enum ThumbnailType {
6
+ Type1 = 1,
7
+ Type2 = 2
8
+ }
9
+ export type ThumbnailResult = {
10
+ nodeUid: string;
11
+ ok: true;
12
+ thumbnail: Uint8Array;
13
+ } | {
14
+ nodeUid: string;
15
+ ok: false;
16
+ error: string;
17
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThumbnailType = void 0;
4
+ var ThumbnailType;
5
+ (function (ThumbnailType) {
6
+ ThumbnailType[ThumbnailType["Type1"] = 1] = "Type1";
7
+ ThumbnailType[ThumbnailType["Type2"] = 2] = "Type2";
8
+ })(ThumbnailType || (exports.ThumbnailType = ThumbnailType = {}));
9
+ //# sourceMappingURL=thumbnail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thumbnail.js","sourceRoot":"","sources":["../../src/interface/thumbnail.ts"],"names":[],"mappings":";;;AAMA,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,mDAAS,CAAA;IACT,mDAAS,CAAA;AACb,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
@@ -0,0 +1,16 @@
1
+ import { Thumbnail } from "./thumbnail";
2
+ export type UploadMetadata = {
3
+ mediaType: string;
4
+ expectedSize: number;
5
+ modificationTime?: Date;
6
+ additionalMetadata?: object;
7
+ };
8
+ export interface Fileuploader {
9
+ writeStream(stream: ReadableStream, thumnbails: Thumbnail[], onProgress?: (uploadedBytes: number) => void): UploadController;
10
+ writeFile(fileObject: File, thumnbails: Thumbnail[], onProgress?: (uploadedBytes: number) => void): UploadController;
11
+ }
12
+ export interface UploadController {
13
+ pause(): void;
14
+ resume(): void;
15
+ completion(): Promise<string>;
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/interface/upload.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ export declare const enum HTTPErrorCode {
2
+ OK = 200,
3
+ NOT_FOUND = 404,
4
+ TOO_MANY_REQUESTS = 429,
5
+ INTERNAL_SERVER_ERROR = 500
6
+ }
7
+ export declare function isCodeOk(code: number): boolean;
8
+ export declare function isCodeOkAsync(code: number): boolean;
9
+ export declare const enum ErrorCode {
10
+ OK = 1000,
11
+ OK_MANY = 1001,
12
+ OK_ASYNC = 1002,
13
+ NOT_ENOUGH_PERMISSIONS = 2011,
14
+ NOT_ENOUGH_PERMISSIONS_TO_GRANT_PERMISSIONS = 2026,
15
+ ALREADY_EXISTS = 2500,
16
+ NOT_EXISTS = 2501,
17
+ INSUFFICIENT_QUOTA = 200001,
18
+ INSUFFICIENT_SPACE = 200002,
19
+ MAX_FILE_SIZE_FOR_FREE_USER = 200003,
20
+ MAX_PUBLIC_EDIT_MODE_FOR_FREE_USER = 200004,
21
+ INSUFFICIENT_VOLUME_QUOTA = 200100,
22
+ INSUFFICIENT_DEVICE_QUOTA = 200101,
23
+ ALREADY_MEMBER_OF_SHARE_IN_VOLUME_WITH_ANOTHER_ADDRESS = 200201,
24
+ TOO_MANY_CHILDREN = 200300,
25
+ NESTING_TOO_DEEP = 200301,
26
+ INSUFFICIENT_INVITATION_QUOTA = 200600,
27
+ INSUFFICIENT_SHARE_QUOTA = 200601,
28
+ INSUFFICIENT_SHARE_JOINED_QUOTA = 200602,
29
+ INSUFFICIENT_BOOKMARKS_QUOTA = 200800
30
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCodeOk = isCodeOk;
4
+ exports.isCodeOkAsync = isCodeOkAsync;
5
+ function isCodeOk(code) {
6
+ return code === 1000 /* ErrorCode.OK */ || code === 1001 /* ErrorCode.OK_MANY */ || code === 1002 /* ErrorCode.OK_ASYNC */;
7
+ }
8
+ function isCodeOkAsync(code) {
9
+ return code === 1002 /* ErrorCode.OK_ASYNC */;
10
+ }
11
+ //# sourceMappingURL=errorCodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorCodes.js","sourceRoot":"","sources":["../../../src/internal/apiService/errorCodes.ts"],"names":[],"mappings":";;AAOA,4BAEC;AAED,sCAEC;AAND,SAAgB,QAAQ,CAAC,IAAY;IACjC,OAAO,IAAI,4BAAiB,IAAI,IAAI,iCAAsB,IAAI,IAAI,kCAAuB,CAAC;AAC9F,CAAC;AAED,SAAgB,aAAa,CAAC,IAAY;IACtC,OAAO,IAAI,kCAAuB,CAAC;AACvC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare class ObserverStream extends TransformStream<Uint8Array, Uint8Array> {
2
+ constructor(fn?: (chunk: Uint8Array) => void);
3
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObserverStream = void 0;
4
+ class ObserverStream extends TransformStream {
5
+ constructor(fn) {
6
+ super({
7
+ transform(chunk, controller) {
8
+ fn?.(chunk);
9
+ controller.enqueue(chunk);
10
+ },
11
+ });
12
+ }
13
+ }
14
+ exports.ObserverStream = ObserverStream;
15
+ //# sourceMappingURL=observerStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observerStream.js","sourceRoot":"","sources":["../../../src/internal/apiService/observerStream.ts"],"names":[],"mappings":";;;AAAA,MAAa,cAAe,SAAQ,eAAuC;IACvE,YAAY,EAAgC;QACxC,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAE,UAAU;gBACvB,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBACZ,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AATD,wCASC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Helper class for batch loading items.
3
+ *
4
+ * The class is responsible for fetching items in batches. Any call to
5
+ * `load` will add the item to the batch (without fetching anything),
6
+ * and if the batch reaches the limit, it will fetch the items and yield
7
+ * them transparently to the caller.
8
+ *
9
+ * Example:
10
+ *
11
+ * ```typescript
12
+ * const batchLoading = new BatchLoading<string, DecryptedNode>({ loadItems: loadNodesCallback });
13
+ * for (const nodeUid of nodeUids) {
14
+ * for await (const node of batchLoading.load(nodeUid)) {
15
+ * console.log(node);
16
+ * }
17
+ * }
18
+ * for await (const node of batchLoading.loadRest()) {
19
+ * console.log(node);
20
+ * }
21
+ * ```
22
+ */
23
+ export declare class BatchLoading<ID, ITEM> {
24
+ private batchSize;
25
+ private iterateItems;
26
+ private itemsToFetch;
27
+ constructor(options: {
28
+ loadItems?: (ids: ID[]) => Promise<ITEM[]>;
29
+ iterateItems?: (ids: ID[]) => AsyncGenerator<ITEM>;
30
+ batchSize?: number;
31
+ });
32
+ load(nodeUid: ID): AsyncGenerator<Awaited<ITEM>, void, any>;
33
+ loadRest(): AsyncGenerator<Awaited<ITEM>, void, any>;
34
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BatchLoading = void 0;
4
+ const DEFAULT_BATCH_LOADING = 10;
5
+ /**
6
+ * Helper class for batch loading items.
7
+ *
8
+ * The class is responsible for fetching items in batches. Any call to
9
+ * `load` will add the item to the batch (without fetching anything),
10
+ * and if the batch reaches the limit, it will fetch the items and yield
11
+ * them transparently to the caller.
12
+ *
13
+ * Example:
14
+ *
15
+ * ```typescript
16
+ * const batchLoading = new BatchLoading<string, DecryptedNode>({ loadItems: loadNodesCallback });
17
+ * for (const nodeUid of nodeUids) {
18
+ * for await (const node of batchLoading.load(nodeUid)) {
19
+ * console.log(node);
20
+ * }
21
+ * }
22
+ * for await (const node of batchLoading.loadRest()) {
23
+ * console.log(node);
24
+ * }
25
+ * ```
26
+ */
27
+ class BatchLoading {
28
+ batchSize = DEFAULT_BATCH_LOADING;
29
+ iterateItems;
30
+ itemsToFetch;
31
+ constructor(options) {
32
+ this.itemsToFetch = [];
33
+ if (options.loadItems) {
34
+ const loadItems = options.loadItems;
35
+ this.iterateItems = async function* (ids) {
36
+ for (const item of await loadItems(ids)) {
37
+ yield item;
38
+ }
39
+ };
40
+ }
41
+ else if (options.iterateItems) {
42
+ this.iterateItems = options.iterateItems;
43
+ }
44
+ else {
45
+ // This is developer error.
46
+ throw new Error('Either loadItems or iterateItems must be provided');
47
+ }
48
+ if (options.batchSize) {
49
+ this.batchSize = options.batchSize;
50
+ }
51
+ }
52
+ async *load(nodeUid) {
53
+ this.itemsToFetch.push(nodeUid);
54
+ if (this.itemsToFetch.length >= this.batchSize) {
55
+ yield* this.iterateItems(this.itemsToFetch);
56
+ this.itemsToFetch = [];
57
+ }
58
+ }
59
+ async *loadRest() {
60
+ if (this.itemsToFetch.length === 0) {
61
+ return;
62
+ }
63
+ yield* this.iterateItems(this.itemsToFetch);
64
+ this.itemsToFetch = [];
65
+ }
66
+ }
67
+ exports.BatchLoading = BatchLoading;
68
+ //# sourceMappingURL=batchLoading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batchLoading.js","sourceRoot":"","sources":["../../src/internal/batchLoading.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,YAAY;IACb,SAAS,GAAG,qBAAqB,CAAC;IAClC,YAAY,CAAsC;IAElD,YAAY,CAAO;IAE3B,YAAY,OAIX;QACG,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QAEvB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;YACpC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oading");
4
+ describe("BatchLoading", () => {
5
+ let batchLoading;
6
+ beforeEach(() => {
7
+ jest.clearAllMocks();
8
+ });
9
+ it("should load in batches with loadItems", async () => {
10
+ const loadItems = jest.fn((items) => Promise.resolve(items.map((item) => `loaded:${item}`)));
11
+ batchLoading = new batchLoading_1.BatchLoading({ loadItems, batchSize: 2 });
12
+ const result = [];
13
+ for (const item of ["a", "b", "c", "d", "e"]) {
14
+ for await (const loadedItem of batchLoading.load(item)) {
15
+ result.push(loadedItem);
16
+ }
17
+ }
18
+ for await (const loadedItem of batchLoading.loadRest()) {
19
+ result.push(loadedItem);
20
+ }
21
+ expect(result).toEqual(["loaded:a", "loaded:b", "loaded:c", "loaded:d", "loaded:e"]);
22
+ expect(loadItems).toHaveBeenCalledTimes(3);
23
+ expect(loadItems).toHaveBeenNthCalledWith(1, ["a", "b"]);
24
+ expect(loadItems).toHaveBeenNthCalledWith(2, ["c", "d"]);
25
+ expect(loadItems).toHaveBeenNthCalledWith(3, ["e"]);
26
+ });
27
+ it("should load in batches with iterateItems", async () => {
28
+ const iterateItems = jest.fn(async function* (items) {
29
+ for (const item of items) {
30
+ yield `loaded:${item}`;
31
+ }
32
+ });
33
+ batchLoading = new batchLoading_1.BatchLoading({ iterateItems, batchSize: 2 });
34
+ const result = [];
35
+ for (const item of ["a", "b", "c", "d", "e"]) {
36
+ for await (const loadedItem of batchLoading.load(item)) {
37
+ result.push(loadedItem);
38
+ }
39
+ }
40
+ for await (const loadedItem of batchLoading.loadRest()) {
41
+ result.push(loadedItem);
42
+ }
43
+ expect(result).toEqual(["loaded:a", "loaded:b", "loaded:c", "loaded:d", "loaded:e"]);
44
+ expect(iterateItems).toHaveBeenCalledTimes(3);
45
+ expect(iterateItems).toHaveBeenNthCalledWith(1, ["a", "b"]);
46
+ expect(iterateItems).toHaveBeenNthCalledWith(2, ["c", "d"]);
47
+ expect(iterateItems).toHaveBeenNthCalledWith(3, ["e"]);
48
+ });
49
+ });
50
+ //# sourceMappingURL=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AAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;QACrF,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare class DownloadController {
2
+ private paused;
3
+ promise?: Promise<void>;
4
+ waitWhilePaused(): Promise<void>;
5
+ pause(): void;
6
+ resume(): void;
7
+ completion(): Promise<void>;
8
+ }