@autonomys/auto-drive 1.4.6 → 1.4.7
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.
- package/dist/browser.d.ts +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -0
- package/dist/offline/cid.d.ts +10 -0
- package/dist/offline/cid.d.ts.map +1 -0
- package/dist/offline/cid.js +60 -0
- package/dist/offline/index.d.ts +2 -0
- package/dist/offline/index.d.ts.map +1 -0
- package/dist/offline/index.js +17 -0
- package/package.json +6 -5
- package/src/browser.ts +1 -0
- package/src/offline/cid.ts +61 -0
- package/src/offline/index.ts +1 -0
package/dist/browser.d.ts
CHANGED
package/dist/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA"}
|
package/dist/browser.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./api/index"), exports);
|
|
18
|
+
__exportStar(require("./offline/index"), exports);
|
|
18
19
|
__exportStar(require("./utils/index"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GenericFile } from '../api/models/file';
|
|
2
|
+
/**
|
|
3
|
+
* Precompute the CID of a file
|
|
4
|
+
* @param file - The file to precompute the CID of
|
|
5
|
+
* @param name - The name of the file (ignored if file is a GenericFile)
|
|
6
|
+
* @returns The CID of the file
|
|
7
|
+
*/
|
|
8
|
+
export declare const precomputeCid: (file: File | GenericFile | Buffer, name?: string) => Promise<import("multiformats", { with: { "resolution-mode": "import" } }).CID<unknown, number, number, import("multiformats", { with: { "resolution-mode": "import" } }).Version>>;
|
|
9
|
+
export declare const blake3Hash: (cid: string) => Promise<Buffer<ArrayBuffer>>;
|
|
10
|
+
//# sourceMappingURL=cid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../../src/offline/cid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAuChD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAU,MAAM,IAAI,GAAG,WAAW,GAAG,MAAM,EAAE,OAAO,MAAM,uLAQnF,CAAA;AAED,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,iCAI3C,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.blake3Hash = exports.precomputeCid = void 0;
|
|
13
|
+
const asynchronous_1 = require("@autonomys/asynchronous");
|
|
14
|
+
const precomputeCidFromGenericFile = (file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const { processFileToIPLDFormat } = yield import('@autonomys/auto-dag-data');
|
|
16
|
+
const { MemoryBlockstore } = yield import('blockstore-core');
|
|
17
|
+
const blockstore = new MemoryBlockstore();
|
|
18
|
+
return processFileToIPLDFormat(blockstore, file.read(), BigInt(file.size), file.name);
|
|
19
|
+
});
|
|
20
|
+
const precomputeCidFromBuffer = (buffer, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const { processFileToIPLDFormat } = yield import('@autonomys/auto-dag-data');
|
|
22
|
+
const { MemoryBlockstore } = yield import('blockstore-core');
|
|
23
|
+
const blockstore = new MemoryBlockstore();
|
|
24
|
+
return processFileToIPLDFormat(blockstore, (0, asynchronous_1.bufferToAsyncIterable)(buffer), BigInt(buffer.byteLength), name);
|
|
25
|
+
});
|
|
26
|
+
const precomputeCidFromFile = (file, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const { processFileToIPLDFormat } = yield import('@autonomys/auto-dag-data');
|
|
28
|
+
const { MemoryBlockstore } = yield import('blockstore-core');
|
|
29
|
+
const blockstore = new MemoryBlockstore();
|
|
30
|
+
return processFileToIPLDFormat(blockstore, (0, asynchronous_1.fileToIterable)(file), BigInt(file.size), name);
|
|
31
|
+
});
|
|
32
|
+
const isGenericFile = (file) => {
|
|
33
|
+
return 'read' in file && typeof file.read === 'function';
|
|
34
|
+
};
|
|
35
|
+
const isBuffer = (file) => {
|
|
36
|
+
return file instanceof Buffer;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Precompute the CID of a file
|
|
40
|
+
* @param file - The file to precompute the CID of
|
|
41
|
+
* @param name - The name of the file (ignored if file is a GenericFile)
|
|
42
|
+
* @returns The CID of the file
|
|
43
|
+
*/
|
|
44
|
+
const precomputeCid = (file, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
if (isGenericFile(file)) {
|
|
46
|
+
return precomputeCidFromGenericFile(file);
|
|
47
|
+
}
|
|
48
|
+
else if (isBuffer(file)) {
|
|
49
|
+
return precomputeCidFromBuffer(file, name);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return precomputeCidFromFile(file, name);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
exports.precomputeCid = precomputeCid;
|
|
56
|
+
const blake3Hash = (cid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const { blake3HashFromCid, stringToCid } = yield import('@autonomys/auto-dag-data');
|
|
58
|
+
return Buffer.from(blake3HashFromCid(stringToCid(cid)));
|
|
59
|
+
});
|
|
60
|
+
exports.blake3Hash = blake3Hash;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/offline/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./cid"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-drive",
|
|
3
3
|
"packageManager": "yarn@4.7.0",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
"typescript": "^5.6.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@autonomys/asynchronous": "^1.4.
|
|
46
|
-
"@autonomys/auto-dag-data": "^1.4.
|
|
47
|
-
"@autonomys/auto-utils": "^1.4.
|
|
45
|
+
"@autonomys/asynchronous": "^1.4.7",
|
|
46
|
+
"@autonomys/auto-dag-data": "^1.4.7",
|
|
47
|
+
"@autonomys/auto-utils": "^1.4.7",
|
|
48
|
+
"blockstore-core": "^5.0.2",
|
|
48
49
|
"jszip": "^3.10.1",
|
|
49
50
|
"mime-types": "^2.1.35",
|
|
50
51
|
"process": "^0.11.10",
|
|
51
52
|
"stream": "^0.0.3",
|
|
52
53
|
"zod": "^3.24.2"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "79014d250300c8150ed1ef65299c704bfd1054c1"
|
|
55
56
|
}
|
package/src/browser.ts
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { bufferToAsyncIterable, fileToIterable } from '@autonomys/asynchronous'
|
|
2
|
+
import { GenericFile } from '../api/models/file'
|
|
3
|
+
|
|
4
|
+
const precomputeCidFromGenericFile = async (file: GenericFile) => {
|
|
5
|
+
const { processFileToIPLDFormat } = await import('@autonomys/auto-dag-data')
|
|
6
|
+
const { MemoryBlockstore } = await import('blockstore-core')
|
|
7
|
+
|
|
8
|
+
const blockstore = new MemoryBlockstore()
|
|
9
|
+
return processFileToIPLDFormat(blockstore, file.read(), BigInt(file.size), file.name)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const precomputeCidFromBuffer = async (buffer: Buffer, name?: string) => {
|
|
13
|
+
const { processFileToIPLDFormat } = await import('@autonomys/auto-dag-data')
|
|
14
|
+
const { MemoryBlockstore } = await import('blockstore-core')
|
|
15
|
+
|
|
16
|
+
const blockstore = new MemoryBlockstore()
|
|
17
|
+
return processFileToIPLDFormat(
|
|
18
|
+
blockstore,
|
|
19
|
+
bufferToAsyncIterable(buffer),
|
|
20
|
+
BigInt(buffer.byteLength),
|
|
21
|
+
name,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const precomputeCidFromFile = async (file: File | Blob, name?: string) => {
|
|
26
|
+
const { processFileToIPLDFormat } = await import('@autonomys/auto-dag-data')
|
|
27
|
+
const { MemoryBlockstore } = await import('blockstore-core')
|
|
28
|
+
|
|
29
|
+
const blockstore = new MemoryBlockstore()
|
|
30
|
+
return processFileToIPLDFormat(blockstore, fileToIterable(file), BigInt(file.size), name)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isGenericFile = (file: File | GenericFile | Buffer): file is GenericFile => {
|
|
34
|
+
return 'read' in file && typeof file.read === 'function'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isBuffer = (file: File | GenericFile | Buffer): file is Buffer => {
|
|
38
|
+
return file instanceof Buffer
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Precompute the CID of a file
|
|
43
|
+
* @param file - The file to precompute the CID of
|
|
44
|
+
* @param name - The name of the file (ignored if file is a GenericFile)
|
|
45
|
+
* @returns The CID of the file
|
|
46
|
+
*/
|
|
47
|
+
export const precomputeCid = async (file: File | GenericFile | Buffer, name?: string) => {
|
|
48
|
+
if (isGenericFile(file)) {
|
|
49
|
+
return precomputeCidFromGenericFile(file)
|
|
50
|
+
} else if (isBuffer(file)) {
|
|
51
|
+
return precomputeCidFromBuffer(file, name)
|
|
52
|
+
} else {
|
|
53
|
+
return precomputeCidFromFile(file, name)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const blake3Hash = async (cid: string) => {
|
|
58
|
+
const { blake3HashFromCid, stringToCid } = await import('@autonomys/auto-dag-data')
|
|
59
|
+
|
|
60
|
+
return Buffer.from(blake3HashFromCid(stringToCid(cid)))
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cid'
|