@autonomys/auto-drive 1.3.0 → 1.3.2

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.
@@ -0,0 +1,3 @@
1
+ export * from './api/index.js';
2
+ export * from './utils/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './api/index.js';
2
+ export * from './utils/index.js';
@@ -0,0 +1,2 @@
1
+ export declare const getFiles: (folderPath: string) => Promise<string[]>;
2
+ //# sourceMappingURL=folder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../../src/utils/folder.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,eAAsB,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAWnE,CAAA"}
@@ -0,0 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fs from 'fs/promises';
11
+ import path from 'path';
12
+ export const getFiles = (folderPath) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const stat = yield fs.stat(folderPath);
14
+ if (stat.isDirectory()) {
15
+ const files = yield fs.readdir(folderPath);
16
+ const promises = files.map((file) => getFiles(path.join(folderPath, file)));
17
+ const allFiles = yield Promise.all(promises);
18
+ return allFiles.flat();
19
+ }
20
+ else {
21
+ return [folderPath];
22
+ }
23
+ });
@@ -0,0 +1,7 @@
1
+ import * as rxjs from 'rxjs';
2
+ export declare class PromisedObservable<T> extends rxjs.Observable<T> {
3
+ constructor(subscribe?: (this: rxjs.Observable<T>, subscriber: rxjs.Subscriber<T>) => void);
4
+ get promise(): Promise<T>;
5
+ }
6
+ export declare const firstValueFrom: typeof rxjs.firstValueFrom, lastValueFrom: typeof rxjs.lastValueFrom;
7
+ //# sourceMappingURL=observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/utils/observable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAQ5B,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBAC/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;IAI1F,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAExB;CACF;AAED,eAAO,MAAQ,cAAc,8BAAE,aAAa,2BAAS,CAAA"}
@@ -0,0 +1,15 @@
1
+ import * as rxjs from 'rxjs';
2
+ const asyncCallback = (callback) => {
3
+ return (t) => {
4
+ callback(t);
5
+ };
6
+ };
7
+ export class PromisedObservable extends rxjs.Observable {
8
+ constructor(subscribe) {
9
+ super(subscribe && asyncCallback(subscribe));
10
+ }
11
+ get promise() {
12
+ return lastValueFrom(this);
13
+ }
14
+ }
15
+ export const { firstValueFrom, lastValueFrom } = rxjs;
@@ -0,0 +1,3 @@
1
+ import { WriteStream } from 'fs';
2
+ export declare const createWriteStreamAdapter: (nodeWriteStream: WriteStream) => WritableStream<Uint8Array>;
3
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAEhC,eAAO,MAAM,wBAAwB,oBAClB,WAAW,KAC3B,cAAc,CAAC,UAAU,CAoB3B,CAAA"}
@@ -0,0 +1,22 @@
1
+ export const createWriteStreamAdapter = (nodeWriteStream) => {
2
+ return new WritableStream({
3
+ write(chunk) {
4
+ return new Promise((resolve, reject) => {
5
+ nodeWriteStream.write(chunk, (err) => {
6
+ if (err) {
7
+ reject(err);
8
+ }
9
+ else {
10
+ resolve();
11
+ }
12
+ });
13
+ });
14
+ },
15
+ close() {
16
+ nodeWriteStream.end();
17
+ },
18
+ abort(err) {
19
+ nodeWriteStream.destroy(err);
20
+ },
21
+ });
22
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@autonomys/auto-drive",
3
3
  "packageManager": "yarn@4.2.2",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -42,13 +42,13 @@
42
42
  "typescript": "^5.6.3"
43
43
  },
44
44
  "dependencies": {
45
- "@autonomys/auto-dag-data": "^1.3.0",
46
- "@autonomys/auto-utils": "^1.3.0",
45
+ "@autonomys/auto-dag-data": "^1.3.2",
46
+ "@autonomys/auto-utils": "^1.3.2",
47
47
  "jszip": "^3.10.1",
48
48
  "mime-types": "^2.1.35",
49
49
  "process": "^0.11.10",
50
50
  "stream": "^0.0.3",
51
51
  "zod": "^3.23.8"
52
52
  },
53
- "gitHead": "c3194075c27e38d074dbff97abdcd6607dca75ae"
53
+ "gitHead": "31634b3a4f4c64bb74c7249d64ec883761125637"
54
54
  }
package/.env DELETED
@@ -1,6 +0,0 @@
1
- OBJECT_MAPPING_ARCHIVER_URL=ws://127.0.0.1:1234
2
- RPC_ENDPOINT=ws://127.0.0.1:1234
3
- PRIVATE_KEYS_PATH=//Alice
4
- CORS_ALLOW_ORIGINS=*
5
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
6
- MAX_CACHE_SIZE=1073741824
@@ -1,172 +0,0 @@
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=type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/api/type.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;I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CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA"}
package/dist/api/type.js DELETED
@@ -1,8 +0,0 @@
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 = {}));