@mysten/walrus 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +184 -23
- package/dist/cjs/client.d.ts +90 -2
- package/dist/cjs/client.js +300 -2
- package/dist/cjs/client.js.map +3 -3
- package/dist/cjs/files/blob.d.ts +21 -0
- package/dist/cjs/files/blob.js +94 -0
- package/dist/cjs/files/blob.js.map +7 -0
- package/dist/cjs/files/file.d.ts +21 -0
- package/dist/cjs/files/file.js +62 -0
- package/dist/cjs/files/file.js.map +7 -0
- package/dist/cjs/files/readers/blob.d.ts +70 -0
- package/dist/cjs/files/readers/blob.js +132 -0
- package/dist/cjs/files/readers/blob.js.map +7 -0
- package/dist/cjs/files/readers/local.d.ts +12 -0
- package/dist/cjs/files/readers/local.js +61 -0
- package/dist/cjs/files/readers/local.js.map +7 -0
- package/dist/cjs/files/readers/quilt-file.d.ts +21 -0
- package/dist/cjs/files/readers/quilt-file.js +75 -0
- package/dist/cjs/files/readers/quilt-file.js.map +7 -0
- package/dist/cjs/files/readers/quilt.d.ts +29 -0
- package/dist/cjs/files/readers/quilt.js +219 -0
- package/dist/cjs/files/readers/quilt.js.map +7 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.d.ts +28 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +15 -0
- package/dist/cjs/utils/index.js +42 -6
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/quilts.d.ts +34 -0
- package/dist/cjs/utils/quilts.js +166 -14
- package/dist/cjs/utils/quilts.js.map +3 -3
- package/dist/esm/client.d.ts +90 -2
- package/dist/esm/client.js +300 -2
- package/dist/esm/client.js.map +3 -3
- package/dist/esm/files/blob.d.ts +21 -0
- package/dist/esm/files/blob.js +74 -0
- package/dist/esm/files/blob.js.map +7 -0
- package/dist/esm/files/file.d.ts +21 -0
- package/dist/esm/files/file.js +42 -0
- package/dist/esm/files/file.js.map +7 -0
- package/dist/esm/files/readers/blob.d.ts +70 -0
- package/dist/esm/files/readers/blob.js +112 -0
- package/dist/esm/files/readers/blob.js.map +7 -0
- package/dist/esm/files/readers/local.d.ts +12 -0
- package/dist/esm/files/readers/local.js +41 -0
- package/dist/esm/files/readers/local.js.map +7 -0
- package/dist/esm/files/readers/quilt-file.d.ts +21 -0
- package/dist/esm/files/readers/quilt-file.js +55 -0
- package/dist/esm/files/readers/quilt-file.js.map +7 -0
- package/dist/esm/files/readers/quilt.d.ts +29 -0
- package/dist/esm/files/readers/quilt.js +203 -0
- package/dist/esm/files/readers/quilt.js.map +7 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.d.ts +28 -1
- package/dist/esm/utils/index.d.ts +15 -0
- package/dist/esm/utils/index.js +42 -6
- package/dist/esm/utils/index.js.map +2 -2
- package/dist/esm/utils/quilts.d.ts +34 -0
- package/dist/esm/utils/quilts.js +169 -11
- package/dist/esm/utils/quilts.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -9
- package/dist/cjs/quilt/reader.d.ts +0 -27
- package/dist/cjs/quilt/reader.js +0 -267
- package/dist/cjs/quilt/reader.js.map +0 -7
- package/dist/cjs/quilt/write.d.ts +0 -21
- package/dist/cjs/quilt/write.js +0 -167
- package/dist/cjs/quilt/write.js.map +0 -7
- package/dist/esm/quilt/reader.d.ts +0 -27
- package/dist/esm/quilt/reader.js +0 -247
- package/dist/esm/quilt/reader.js.map +0 -7
- package/dist/esm/quilt/write.d.ts +0 -21
- package/dist/esm/quilt/write.js +0 -156
- package/dist/esm/quilt/write.js.map +0 -7
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface FileReader {
|
|
2
|
+
getIdentifier(): Promise<string | null>;
|
|
3
|
+
getTags(): Promise<Record<string, string>>;
|
|
4
|
+
getBytes(): Promise<Uint8Array>;
|
|
5
|
+
}
|
|
6
|
+
export declare class WalrusFile {
|
|
7
|
+
#private;
|
|
8
|
+
static from(options: {
|
|
9
|
+
contents: Uint8Array | Blob;
|
|
10
|
+
identifier: string;
|
|
11
|
+
tags?: Record<string, string>;
|
|
12
|
+
}): WalrusFile;
|
|
13
|
+
constructor({ reader }: {
|
|
14
|
+
reader: FileReader;
|
|
15
|
+
});
|
|
16
|
+
getIdentifier(): Promise<string | null>;
|
|
17
|
+
getTags(): Promise<Record<string, string>>;
|
|
18
|
+
bytes(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
19
|
+
text(): Promise<string>;
|
|
20
|
+
json(): Promise<any>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _reader;
|
|
9
|
+
import { LocalReader } from "./readers/local.js";
|
|
10
|
+
const _WalrusFile = class _WalrusFile {
|
|
11
|
+
constructor({ reader }) {
|
|
12
|
+
__privateAdd(this, _reader);
|
|
13
|
+
__privateSet(this, _reader, reader);
|
|
14
|
+
}
|
|
15
|
+
static from(options) {
|
|
16
|
+
return new _WalrusFile({
|
|
17
|
+
reader: new LocalReader(options)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
getIdentifier() {
|
|
21
|
+
return __privateGet(this, _reader).getIdentifier();
|
|
22
|
+
}
|
|
23
|
+
getTags() {
|
|
24
|
+
return __privateGet(this, _reader).getTags();
|
|
25
|
+
}
|
|
26
|
+
bytes() {
|
|
27
|
+
return __privateGet(this, _reader).getBytes();
|
|
28
|
+
}
|
|
29
|
+
async text() {
|
|
30
|
+
const bytes = await this.bytes();
|
|
31
|
+
return new TextDecoder().decode(bytes);
|
|
32
|
+
}
|
|
33
|
+
async json() {
|
|
34
|
+
return JSON.parse(await this.text());
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
_reader = new WeakMap();
|
|
38
|
+
let WalrusFile = _WalrusFile;
|
|
39
|
+
export {
|
|
40
|
+
WalrusFile
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/files/file.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { LocalReader } from './readers/local.js';\n\nexport interface FileReader {\n\tgetIdentifier(): Promise<string | null>;\n\tgetTags(): Promise<Record<string, string>>;\n\tgetBytes(): Promise<Uint8Array>;\n}\n\nexport class WalrusFile {\n\t#reader: FileReader;\n\n\tstatic from(options: {\n\t\tcontents: Uint8Array | Blob;\n\t\tidentifier: string;\n\t\ttags?: Record<string, string>;\n\t}) {\n\t\treturn new WalrusFile({\n\t\t\treader: new LocalReader(options),\n\t\t});\n\t}\n\n\tconstructor({ reader }: { reader: FileReader }) {\n\t\tthis.#reader = reader;\n\t}\n\n\tgetIdentifier() {\n\t\treturn this.#reader.getIdentifier();\n\t}\n\tgetTags() {\n\t\treturn this.#reader.getTags();\n\t}\n\n\tbytes() {\n\t\treturn this.#reader.getBytes();\n\t}\n\n\tasync text() {\n\t\tconst bytes = await this.bytes();\n\n\t\treturn new TextDecoder().decode(bytes);\n\t}\n\n\tasync json() {\n\t\treturn JSON.parse(await this.text());\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAGA,SAAS,mBAAmB;AAQrB,MAAM,cAAN,MAAM,YAAW;AAAA,EAavB,YAAY,EAAE,OAAO,GAA2B;AAZhD;AAaC,uBAAK,SAAU;AAAA,EAChB;AAAA,EAZA,OAAO,KAAK,SAIT;AACF,WAAO,IAAI,YAAW;AAAA,MACrB,QAAQ,IAAI,YAAY,OAAO;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EAMA,gBAAgB;AACf,WAAO,mBAAK,SAAQ,cAAc;AAAA,EACnC;AAAA,EACA,UAAU;AACT,WAAO,mBAAK,SAAQ,QAAQ;AAAA,EAC7B;AAAA,EAEA,QAAQ;AACP,WAAO,mBAAK,SAAQ,SAAS;AAAA,EAC9B;AAAA,EAEA,MAAM,OAAO;AACZ,UAAM,QAAQ,MAAM,KAAK,MAAM;AAE/B,WAAO,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,EACtC;AAAA,EAEA,MAAM,OAAO;AACZ,WAAO,KAAK,MAAM,MAAM,KAAK,KAAK,CAAC;AAAA,EACpC;AACD;AApCC;AADM,IAAM,aAAN;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { FileReader } from '../file.js';
|
|
2
|
+
import type { WalrusClient } from '../../client.js';
|
|
3
|
+
import { QuiltReader } from './quilt.js';
|
|
4
|
+
export interface BlobReaderOptions {
|
|
5
|
+
client: WalrusClient;
|
|
6
|
+
blobId: string;
|
|
7
|
+
numShards: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class BlobReader implements FileReader {
|
|
10
|
+
#private;
|
|
11
|
+
blobId: string;
|
|
12
|
+
hasStartedLoadingFullBlob: boolean;
|
|
13
|
+
constructor({ client, blobId, numShards }: BlobReaderOptions);
|
|
14
|
+
getIdentifier(): Promise<null>;
|
|
15
|
+
getTags(): Promise<{}>;
|
|
16
|
+
getQuiltReader(): QuiltReader;
|
|
17
|
+
getBytes(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
18
|
+
getMetadata(): {
|
|
19
|
+
blobId: string;
|
|
20
|
+
metadata: {
|
|
21
|
+
V1: {
|
|
22
|
+
encoding_type: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
23
|
+
RedStuff: true;
|
|
24
|
+
RS2: true;
|
|
25
|
+
}, "RedStuff" | "RS2">;
|
|
26
|
+
unencoded_length: string;
|
|
27
|
+
hashes: {
|
|
28
|
+
primary_hash: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
29
|
+
Empty: true;
|
|
30
|
+
Digest: Uint8Array<ArrayBufferLike>;
|
|
31
|
+
}, "Empty" | "Digest">;
|
|
32
|
+
secondary_hash: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
33
|
+
Empty: true;
|
|
34
|
+
Digest: Uint8Array<ArrayBufferLike>;
|
|
35
|
+
}, "Empty" | "Digest">;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
$kind: "V1";
|
|
39
|
+
};
|
|
40
|
+
} | Promise<{
|
|
41
|
+
blobId: string;
|
|
42
|
+
metadata: {
|
|
43
|
+
V1: {
|
|
44
|
+
encoding_type: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
45
|
+
RedStuff: true;
|
|
46
|
+
RS2: true;
|
|
47
|
+
}, "RedStuff" | "RS2">;
|
|
48
|
+
unencoded_length: string;
|
|
49
|
+
hashes: {
|
|
50
|
+
primary_hash: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
51
|
+
Empty: true;
|
|
52
|
+
Digest: Uint8Array<ArrayBufferLike>;
|
|
53
|
+
}, "Empty" | "Digest">;
|
|
54
|
+
secondary_hash: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
55
|
+
Empty: true;
|
|
56
|
+
Digest: Uint8Array<ArrayBufferLike>;
|
|
57
|
+
}, "Empty" | "Digest">;
|
|
58
|
+
}[];
|
|
59
|
+
};
|
|
60
|
+
$kind: "V1";
|
|
61
|
+
};
|
|
62
|
+
}>;
|
|
63
|
+
getColumnSize(): Promise<number>;
|
|
64
|
+
getSymbolSize(): Promise<number>;
|
|
65
|
+
getRowSize(): Promise<number>;
|
|
66
|
+
getSecondarySliver({ sliverIndex, signal }: {
|
|
67
|
+
sliverIndex: number;
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}): Promise<Uint8Array<ArrayBufferLike>>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _cache, _client, _secondarySlivers, _numShards;
|
|
9
|
+
import { ClientCache } from "@mysten/sui/experimental";
|
|
10
|
+
import { getSizes, getSourceSymbols } from "../../utils/index.js";
|
|
11
|
+
import { QuiltReader } from "./quilt.js";
|
|
12
|
+
class BlobReader {
|
|
13
|
+
constructor({ client, blobId, numShards }) {
|
|
14
|
+
__privateAdd(this, _cache, new ClientCache());
|
|
15
|
+
__privateAdd(this, _client);
|
|
16
|
+
__privateAdd(this, _secondarySlivers, /* @__PURE__ */ new Map());
|
|
17
|
+
this.hasStartedLoadingFullBlob = false;
|
|
18
|
+
__privateAdd(this, _numShards);
|
|
19
|
+
__privateSet(this, _client, client);
|
|
20
|
+
this.blobId = blobId;
|
|
21
|
+
__privateSet(this, _numShards, numShards);
|
|
22
|
+
}
|
|
23
|
+
async getIdentifier() {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
async getTags() {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
getQuiltReader() {
|
|
30
|
+
return new QuiltReader({ blob: this });
|
|
31
|
+
}
|
|
32
|
+
async getBytes() {
|
|
33
|
+
return __privateGet(this, _cache).read(["getBytes"], async () => {
|
|
34
|
+
this.hasStartedLoadingFullBlob = true;
|
|
35
|
+
try {
|
|
36
|
+
const blob = await __privateGet(this, _client).readBlob({ blobId: this.blobId });
|
|
37
|
+
return blob;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
this.hasStartedLoadingFullBlob = false;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getMetadata() {
|
|
45
|
+
return __privateGet(this, _cache).read(
|
|
46
|
+
["getMetadata"],
|
|
47
|
+
() => __privateGet(this, _client).getBlobMetadata({ blobId: this.blobId })
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
async getColumnSize() {
|
|
51
|
+
return __privateGet(this, _cache).read(["getColumnSize"], async () => {
|
|
52
|
+
const loadingSlivers = [...__privateGet(this, _secondarySlivers).values()];
|
|
53
|
+
if (loadingSlivers.length > 0) {
|
|
54
|
+
const sliver = await Promise.any(loadingSlivers).catch(() => null);
|
|
55
|
+
if (sliver) {
|
|
56
|
+
return sliver.length;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (this.hasStartedLoadingFullBlob) {
|
|
60
|
+
const blob = await this.getBytes();
|
|
61
|
+
const { columnSize: columnSize2 } = getSizes(blob.length, __privateGet(this, _numShards));
|
|
62
|
+
return columnSize2;
|
|
63
|
+
}
|
|
64
|
+
const metadata = await this.getMetadata();
|
|
65
|
+
const { columnSize } = getSizes(
|
|
66
|
+
Number(metadata.metadata.V1.unencoded_length),
|
|
67
|
+
__privateGet(this, _numShards)
|
|
68
|
+
);
|
|
69
|
+
return columnSize;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async getSymbolSize() {
|
|
73
|
+
const columnSize = await this.getColumnSize();
|
|
74
|
+
const { primarySymbols } = getSourceSymbols(__privateGet(this, _numShards));
|
|
75
|
+
if (columnSize % primarySymbols !== 0) {
|
|
76
|
+
throw new Error("column size should be divisible by primary symbols");
|
|
77
|
+
}
|
|
78
|
+
return columnSize / primarySymbols;
|
|
79
|
+
}
|
|
80
|
+
async getRowSize() {
|
|
81
|
+
const symbolSize = await this.getSymbolSize();
|
|
82
|
+
const { secondarySymbols } = getSourceSymbols(__privateGet(this, _numShards));
|
|
83
|
+
return symbolSize * secondarySymbols;
|
|
84
|
+
}
|
|
85
|
+
async getSecondarySliver({ sliverIndex, signal }) {
|
|
86
|
+
if (__privateGet(this, _secondarySlivers).has(sliverIndex)) {
|
|
87
|
+
return __privateGet(this, _secondarySlivers).get(sliverIndex);
|
|
88
|
+
}
|
|
89
|
+
const sliverPromise = __privateGet(this, _client).getSecondarySliver({
|
|
90
|
+
blobId: this.blobId,
|
|
91
|
+
index: sliverIndex,
|
|
92
|
+
signal
|
|
93
|
+
}).then((sliver) => new Uint8Array(sliver.symbols.data));
|
|
94
|
+
__privateGet(this, _secondarySlivers).set(sliverIndex, sliverPromise);
|
|
95
|
+
try {
|
|
96
|
+
const sliver = await sliverPromise;
|
|
97
|
+
__privateGet(this, _secondarySlivers).set(sliverIndex, sliver);
|
|
98
|
+
return sliver;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
__privateGet(this, _secondarySlivers).delete(sliverIndex);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
_cache = new WeakMap();
|
|
106
|
+
_client = new WeakMap();
|
|
107
|
+
_secondarySlivers = new WeakMap();
|
|
108
|
+
_numShards = new WeakMap();
|
|
109
|
+
export {
|
|
110
|
+
BlobReader
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=blob.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/files/readers/blob.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { ClientCache } from '@mysten/sui/experimental';\nimport type { FileReader } from '../file.js';\nimport type { WalrusClient } from '../../client.js';\nimport { getSizes, getSourceSymbols } from '../../utils/index.js';\nimport { QuiltReader } from './quilt.js';\n\nexport interface BlobReaderOptions {\n\tclient: WalrusClient;\n\tblobId: string;\n\tnumShards: number;\n}\n\nexport class BlobReader implements FileReader {\n\tblobId: string;\n\n\t#cache = new ClientCache();\n\n\t#client: WalrusClient;\n\t#secondarySlivers = new Map<number, Uint8Array | Promise<Uint8Array>>();\n\thasStartedLoadingFullBlob = false;\n\t#numShards: number;\n\n\tconstructor({ client, blobId, numShards }: BlobReaderOptions) {\n\t\tthis.#client = client;\n\t\tthis.blobId = blobId;\n\t\tthis.#numShards = numShards;\n\t}\n\n\tasync getIdentifier() {\n\t\treturn null;\n\t}\n\n\tasync getTags() {\n\t\treturn {};\n\t}\n\n\tgetQuiltReader() {\n\t\treturn new QuiltReader({ blob: this });\n\t}\n\n\tasync getBytes() {\n\t\treturn this.#cache.read(['getBytes'], async () => {\n\t\t\tthis.hasStartedLoadingFullBlob = true;\n\t\t\ttry {\n\t\t\t\tconst blob = await this.#client.readBlob({ blobId: this.blobId });\n\t\t\t\treturn blob;\n\t\t\t} catch (error) {\n\t\t\t\tthis.hasStartedLoadingFullBlob = false;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\t}\n\n\tgetMetadata() {\n\t\treturn this.#cache.read(['getMetadata'], () =>\n\t\t\tthis.#client.getBlobMetadata({ blobId: this.blobId }),\n\t\t);\n\t}\n\n\tasync getColumnSize() {\n\t\treturn this.#cache.read(['getColumnSize'], async () => {\n\t\t\tconst loadingSlivers = [...this.#secondarySlivers.values()];\n\n\t\t\tif (loadingSlivers.length > 0) {\n\t\t\t\tconst sliver = await Promise.any(loadingSlivers).catch(() => null);\n\n\t\t\t\tif (sliver) {\n\t\t\t\t\treturn sliver.length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.hasStartedLoadingFullBlob) {\n\t\t\t\tconst blob = await this.getBytes();\n\t\t\t\tconst { columnSize } = getSizes(blob.length, this.#numShards);\n\t\t\t\treturn columnSize;\n\t\t\t}\n\n\t\t\tconst metadata = await this.getMetadata();\n\t\t\tconst { columnSize } = getSizes(\n\t\t\t\tNumber(metadata.metadata.V1.unencoded_length),\n\t\t\t\tthis.#numShards,\n\t\t\t);\n\n\t\t\treturn columnSize;\n\t\t});\n\t}\n\n\tasync getSymbolSize() {\n\t\tconst columnSize = await this.getColumnSize();\n\t\tconst { primarySymbols } = getSourceSymbols(this.#numShards);\n\n\t\tif (columnSize % primarySymbols !== 0) {\n\t\t\tthrow new Error('column size should be divisible by primary symbols');\n\t\t}\n\n\t\treturn columnSize / primarySymbols;\n\t}\n\n\tasync getRowSize() {\n\t\tconst symbolSize = await this.getSymbolSize();\n\t\tconst { secondarySymbols } = getSourceSymbols(this.#numShards);\n\t\treturn symbolSize * secondarySymbols;\n\t}\n\n\tasync getSecondarySliver({ sliverIndex, signal }: { sliverIndex: number; signal?: AbortSignal }) {\n\t\tif (this.#secondarySlivers.has(sliverIndex)) {\n\t\t\treturn this.#secondarySlivers.get(sliverIndex)!;\n\t\t}\n\n\t\tconst sliverPromise = this.#client\n\t\t\t.getSecondarySliver({\n\t\t\t\tblobId: this.blobId,\n\t\t\t\tindex: sliverIndex,\n\t\t\t\tsignal,\n\t\t\t})\n\t\t\t.then((sliver) => new Uint8Array(sliver.symbols.data));\n\n\t\tthis.#secondarySlivers.set(sliverIndex, sliverPromise);\n\n\t\ttry {\n\t\t\tconst sliver = await sliverPromise;\n\t\t\tthis.#secondarySlivers.set(sliverIndex, sliver);\n\t\t\treturn sliver;\n\t\t} catch (error) {\n\t\t\tthis.#secondarySlivers.delete(sliverIndex);\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["columnSize"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FileReader } from '../file.js';
|
|
2
|
+
export declare class LocalReader implements FileReader {
|
|
3
|
+
#private;
|
|
4
|
+
constructor({ contents, identifier, tags, }: {
|
|
5
|
+
contents: Uint8Array | Blob;
|
|
6
|
+
identifier?: string;
|
|
7
|
+
tags?: Record<string, string>;
|
|
8
|
+
});
|
|
9
|
+
getBytes(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
10
|
+
getIdentifier(): Promise<string | null>;
|
|
11
|
+
getTags(): Promise<Record<string, string>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _contents, _identifier, _tags;
|
|
9
|
+
class LocalReader {
|
|
10
|
+
constructor({
|
|
11
|
+
contents,
|
|
12
|
+
identifier,
|
|
13
|
+
tags
|
|
14
|
+
}) {
|
|
15
|
+
__privateAdd(this, _contents);
|
|
16
|
+
__privateAdd(this, _identifier);
|
|
17
|
+
__privateAdd(this, _tags);
|
|
18
|
+
__privateSet(this, _contents, contents);
|
|
19
|
+
__privateSet(this, _identifier, identifier ?? null);
|
|
20
|
+
__privateSet(this, _tags, tags ?? {});
|
|
21
|
+
}
|
|
22
|
+
async getBytes() {
|
|
23
|
+
if ("arrayBuffer" in __privateGet(this, _contents)) {
|
|
24
|
+
return new Uint8Array(await __privateGet(this, _contents).arrayBuffer());
|
|
25
|
+
}
|
|
26
|
+
return __privateGet(this, _contents);
|
|
27
|
+
}
|
|
28
|
+
async getIdentifier() {
|
|
29
|
+
return __privateGet(this, _identifier);
|
|
30
|
+
}
|
|
31
|
+
async getTags() {
|
|
32
|
+
return __privateGet(this, _tags);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
_contents = new WeakMap();
|
|
36
|
+
_identifier = new WeakMap();
|
|
37
|
+
_tags = new WeakMap();
|
|
38
|
+
export {
|
|
39
|
+
LocalReader
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/files/readers/local.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { FileReader } from '../file.js';\n\nexport class LocalReader implements FileReader {\n\t#contents: Uint8Array | Blob;\n\t#identifier: string | null;\n\t#tags: Record<string, string>;\n\n\tconstructor({\n\t\tcontents,\n\t\tidentifier,\n\t\ttags,\n\t}: {\n\t\tcontents: Uint8Array | Blob;\n\t\tidentifier?: string;\n\t\ttags?: Record<string, string>;\n\t}) {\n\t\tthis.#contents = contents;\n\t\tthis.#identifier = identifier ?? null;\n\t\tthis.#tags = tags ?? {};\n\t}\n\n\tasync getBytes() {\n\t\tif ('arrayBuffer' in this.#contents) {\n\t\t\treturn new Uint8Array(await this.#contents.arrayBuffer());\n\t\t}\n\n\t\treturn this.#contents;\n\t}\n\n\tasync getIdentifier() {\n\t\treturn this.#identifier;\n\t}\n\n\tasync getTags() {\n\t\treturn this.#tags;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAKO,MAAM,YAAkC;AAAA,EAK9C,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAIG;AAZH;AACA;AACA;AAWC,uBAAK,WAAY;AACjB,uBAAK,aAAc,cAAc;AACjC,uBAAK,OAAQ,QAAQ,CAAC;AAAA,EACvB;AAAA,EAEA,MAAM,WAAW;AAChB,QAAI,iBAAiB,mBAAK,YAAW;AACpC,aAAO,IAAI,WAAW,MAAM,mBAAK,WAAU,YAAY,CAAC;AAAA,IACzD;AAEA,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,gBAAgB;AACrB,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,UAAU;AACf,WAAO,mBAAK;AAAA,EACb;AACD;AAjCC;AACA;AACA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FileReader } from '../file.js';
|
|
2
|
+
import type { QuiltReader } from './quilt.js';
|
|
3
|
+
export interface QuiltBlobHeader {
|
|
4
|
+
identifier: string;
|
|
5
|
+
tags: Record<string, string> | null;
|
|
6
|
+
blobSize: number;
|
|
7
|
+
contentOffset: number;
|
|
8
|
+
columnSize: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class QuiltFileReader implements FileReader {
|
|
11
|
+
#private;
|
|
12
|
+
constructor({ quilt, sliverIndex, identifier, tags, }: {
|
|
13
|
+
quilt: QuiltReader;
|
|
14
|
+
sliverIndex: number;
|
|
15
|
+
identifier?: string;
|
|
16
|
+
tags?: Record<string, string>;
|
|
17
|
+
});
|
|
18
|
+
getBytes(): Promise<Uint8Array>;
|
|
19
|
+
getIdentifier(): Promise<string>;
|
|
20
|
+
getTags(): Promise<Record<string, string>>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _quilt, _sliverIndex, _identifier, _tags;
|
|
9
|
+
class QuiltFileReader {
|
|
10
|
+
constructor({
|
|
11
|
+
quilt,
|
|
12
|
+
sliverIndex,
|
|
13
|
+
identifier,
|
|
14
|
+
tags
|
|
15
|
+
}) {
|
|
16
|
+
__privateAdd(this, _quilt);
|
|
17
|
+
__privateAdd(this, _sliverIndex);
|
|
18
|
+
__privateAdd(this, _identifier);
|
|
19
|
+
__privateAdd(this, _tags);
|
|
20
|
+
__privateSet(this, _quilt, quilt);
|
|
21
|
+
__privateSet(this, _sliverIndex, sliverIndex);
|
|
22
|
+
__privateSet(this, _identifier, identifier ?? null);
|
|
23
|
+
__privateSet(this, _tags, tags);
|
|
24
|
+
}
|
|
25
|
+
async getBytes() {
|
|
26
|
+
const { blobContents, identifier, tags } = await __privateGet(this, _quilt).readBlob(__privateGet(this, _sliverIndex));
|
|
27
|
+
__privateSet(this, _identifier, identifier);
|
|
28
|
+
__privateSet(this, _tags, tags ?? {});
|
|
29
|
+
return blobContents;
|
|
30
|
+
}
|
|
31
|
+
async getIdentifier() {
|
|
32
|
+
if (__privateGet(this, _identifier) !== null) {
|
|
33
|
+
return __privateGet(this, _identifier);
|
|
34
|
+
}
|
|
35
|
+
const header = await __privateGet(this, _quilt).getBlobHeader(__privateGet(this, _sliverIndex));
|
|
36
|
+
__privateSet(this, _identifier, header.identifier);
|
|
37
|
+
return __privateGet(this, _identifier);
|
|
38
|
+
}
|
|
39
|
+
async getTags() {
|
|
40
|
+
if (__privateGet(this, _tags) !== void 0) {
|
|
41
|
+
return __privateGet(this, _tags);
|
|
42
|
+
}
|
|
43
|
+
const header = await __privateGet(this, _quilt).getBlobHeader(__privateGet(this, _sliverIndex));
|
|
44
|
+
__privateSet(this, _tags, header.tags ?? {});
|
|
45
|
+
return __privateGet(this, _tags);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_quilt = new WeakMap();
|
|
49
|
+
_sliverIndex = new WeakMap();
|
|
50
|
+
_identifier = new WeakMap();
|
|
51
|
+
_tags = new WeakMap();
|
|
52
|
+
export {
|
|
53
|
+
QuiltFileReader
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=quilt-file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/files/readers/quilt-file.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { FileReader } from '../file.js';\nimport type { QuiltReader } from './quilt.js';\n\nexport interface QuiltBlobHeader {\n\tidentifier: string;\n\ttags: Record<string, string> | null;\n\tblobSize: number;\n\tcontentOffset: number;\n\tcolumnSize: number;\n}\n\nexport class QuiltFileReader implements FileReader {\n\t#quilt: QuiltReader;\n\t#sliverIndex: number;\n\t#identifier: string | null;\n\t#tags?: Record<string, string>;\n\n\tconstructor({\n\t\tquilt,\n\t\tsliverIndex,\n\t\tidentifier,\n\t\ttags,\n\t}: {\n\t\tquilt: QuiltReader;\n\t\tsliverIndex: number;\n\t\tidentifier?: string;\n\t\ttags?: Record<string, string>;\n\t}) {\n\t\tthis.#quilt = quilt;\n\t\tthis.#sliverIndex = sliverIndex;\n\t\tthis.#identifier = identifier ?? null;\n\t\tthis.#tags = tags;\n\t}\n\n\tasync getBytes(): Promise<Uint8Array> {\n\t\tconst { blobContents, identifier, tags } = await this.#quilt.readBlob(this.#sliverIndex);\n\t\tthis.#identifier = identifier;\n\t\tthis.#tags = tags ?? {};\n\t\treturn blobContents;\n\t}\n\n\tasync getIdentifier() {\n\t\tif (this.#identifier !== null) {\n\t\t\treturn this.#identifier;\n\t\t}\n\n\t\tconst header = await this.#quilt.getBlobHeader(this.#sliverIndex);\n\n\t\tthis.#identifier = header.identifier;\n\t\treturn this.#identifier;\n\t}\n\n\tasync getTags() {\n\t\tif (this.#tags !== undefined) {\n\t\t\treturn this.#tags;\n\t\t}\n\n\t\tconst header = await this.#quilt.getBlobHeader(this.#sliverIndex);\n\t\tthis.#tags = header.tags ?? {};\n\t\treturn this.#tags;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAcO,MAAM,gBAAsC;AAAA,EAMlD,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAKG;AAfH;AACA;AACA;AACA;AAaC,uBAAK,QAAS;AACd,uBAAK,cAAe;AACpB,uBAAK,aAAc,cAAc;AACjC,uBAAK,OAAQ;AAAA,EACd;AAAA,EAEA,MAAM,WAAgC;AACrC,UAAM,EAAE,cAAc,YAAY,KAAK,IAAI,MAAM,mBAAK,QAAO,SAAS,mBAAK,aAAY;AACvF,uBAAK,aAAc;AACnB,uBAAK,OAAQ,QAAQ,CAAC;AACtB,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,gBAAgB;AACrB,QAAI,mBAAK,iBAAgB,MAAM;AAC9B,aAAO,mBAAK;AAAA,IACb;AAEA,UAAM,SAAS,MAAM,mBAAK,QAAO,cAAc,mBAAK,aAAY;AAEhE,uBAAK,aAAc,OAAO;AAC1B,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,UAAU;AACf,QAAI,mBAAK,WAAU,QAAW;AAC7B,aAAO,mBAAK;AAAA,IACb;AAEA,UAAM,SAAS,MAAM,mBAAK,QAAO,cAAc,mBAAK,aAAY;AAChE,uBAAK,OAAQ,OAAO,QAAQ,CAAC;AAC7B,WAAO,mBAAK;AAAA,EACb;AACD;AAjDC;AACA;AACA;AACA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BlobReader } from './blob.js';
|
|
2
|
+
import { QuiltFileReader } from './quilt-file.js';
|
|
3
|
+
export interface QuiltReaderOptions {
|
|
4
|
+
blob: BlobReader;
|
|
5
|
+
}
|
|
6
|
+
export declare class QuiltReader {
|
|
7
|
+
#private;
|
|
8
|
+
constructor({ blob }: QuiltReaderOptions);
|
|
9
|
+
getBlobHeader(sliverIndex: number): Promise<{
|
|
10
|
+
identifier: string;
|
|
11
|
+
tags: Record<string, string> | null;
|
|
12
|
+
blobSize: number;
|
|
13
|
+
contentOffset: number;
|
|
14
|
+
}>;
|
|
15
|
+
readBlob(sliverIndex: number): Promise<{
|
|
16
|
+
identifier: string;
|
|
17
|
+
tags: Record<string, string> | null;
|
|
18
|
+
blobContents: Uint8Array<ArrayBuffer>;
|
|
19
|
+
}>;
|
|
20
|
+
readerForPatchId(id: string): QuiltFileReader;
|
|
21
|
+
readIndex(): Promise<{
|
|
22
|
+
identifier: string;
|
|
23
|
+
patchId: string;
|
|
24
|
+
tags: {
|
|
25
|
+
[k: string]: string;
|
|
26
|
+
};
|
|
27
|
+
reader: QuiltFileReader;
|
|
28
|
+
}[]>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var _blob, _cache, _QuiltReader_instances, readBytesFromSlivers_fn, readBytesFromBlob_fn, readBytes_fn;
|
|
10
|
+
import { ClientCache } from "@mysten/sui/experimental";
|
|
11
|
+
import { QuiltPatchBlobHeader, QuiltPatchId } from "../../utils/bcs.js";
|
|
12
|
+
import {
|
|
13
|
+
HAS_TAGS_FLAG,
|
|
14
|
+
parseQuiltPatchId,
|
|
15
|
+
QUILT_PATCH_BLOB_HEADER_SIZE
|
|
16
|
+
} from "../../utils/quilts.js";
|
|
17
|
+
import { bcs } from "@mysten/bcs";
|
|
18
|
+
import { QuiltPatchTags } from "../../utils/bcs.js";
|
|
19
|
+
import { QuiltIndexV1 } from "../../utils/bcs.js";
|
|
20
|
+
import { urlSafeBase64 } from "../../utils/index.js";
|
|
21
|
+
import { QuiltFileReader } from "./quilt-file.js";
|
|
22
|
+
class QuiltReader {
|
|
23
|
+
constructor({ blob }) {
|
|
24
|
+
__privateAdd(this, _QuiltReader_instances);
|
|
25
|
+
__privateAdd(this, _blob);
|
|
26
|
+
__privateAdd(this, _cache, new ClientCache());
|
|
27
|
+
__privateSet(this, _blob, blob);
|
|
28
|
+
}
|
|
29
|
+
async getBlobHeader(sliverIndex) {
|
|
30
|
+
return __privateGet(this, _cache).read(["getBlobHeader", sliverIndex.toString()], async () => {
|
|
31
|
+
const blobHeader = QuiltPatchBlobHeader.parse(
|
|
32
|
+
await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, QUILT_PATCH_BLOB_HEADER_SIZE)
|
|
33
|
+
);
|
|
34
|
+
let offset = QUILT_PATCH_BLOB_HEADER_SIZE;
|
|
35
|
+
let blobSize = blobHeader.length;
|
|
36
|
+
const identifierLength = new DataView(
|
|
37
|
+
(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, 2, offset)).buffer
|
|
38
|
+
).getUint16(0, true);
|
|
39
|
+
blobSize -= 2 + identifierLength;
|
|
40
|
+
offset += 2;
|
|
41
|
+
const identifier = bcs.string().parse(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, identifierLength, offset));
|
|
42
|
+
offset += identifierLength;
|
|
43
|
+
let tags = null;
|
|
44
|
+
if (blobHeader.mask & HAS_TAGS_FLAG) {
|
|
45
|
+
const tagsSize = new DataView(
|
|
46
|
+
(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, 2, offset)).buffer
|
|
47
|
+
).getUint16(0, true);
|
|
48
|
+
offset += 2;
|
|
49
|
+
tags = QuiltPatchTags.parse(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, tagsSize, offset));
|
|
50
|
+
blobSize -= tagsSize + 2;
|
|
51
|
+
offset += tagsSize;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
identifier,
|
|
55
|
+
tags,
|
|
56
|
+
blobSize,
|
|
57
|
+
contentOffset: offset
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async readBlob(sliverIndex) {
|
|
62
|
+
const { identifier, tags, blobSize, contentOffset } = await this.getBlobHeader(sliverIndex);
|
|
63
|
+
const blobContents = await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, blobSize, contentOffset);
|
|
64
|
+
return {
|
|
65
|
+
identifier,
|
|
66
|
+
tags,
|
|
67
|
+
blobContents
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
readerForPatchId(id) {
|
|
71
|
+
const { quiltId, patchId } = parseQuiltPatchId(id);
|
|
72
|
+
if (quiltId !== __privateGet(this, _blob).blobId) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`The requested patch ${patchId} is not part of the quilt ${__privateGet(this, _blob).blobId}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return new QuiltFileReader({ quilt: this, sliverIndex: patchId.startIndex });
|
|
78
|
+
}
|
|
79
|
+
async readIndex() {
|
|
80
|
+
const header = new DataView((await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, 0, 5)).buffer);
|
|
81
|
+
const version = header.getUint8(0);
|
|
82
|
+
if (version !== 1) {
|
|
83
|
+
throw new Error(`Unsupported quilt version ${version}`);
|
|
84
|
+
}
|
|
85
|
+
const indexSize = header.getUint32(1, true);
|
|
86
|
+
const indexBytes = await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, 0, indexSize, 5);
|
|
87
|
+
const columnSize = await __privateGet(this, _blob).getColumnSize();
|
|
88
|
+
const indexSlivers = Math.ceil(indexSize / columnSize);
|
|
89
|
+
const index = QuiltIndexV1.parse(indexBytes);
|
|
90
|
+
return index.patches.map((patch, i) => {
|
|
91
|
+
const startIndex = i === 0 ? indexSlivers : index.patches[i - 1].endIndex;
|
|
92
|
+
const reader = new QuiltFileReader({
|
|
93
|
+
quilt: this,
|
|
94
|
+
sliverIndex: startIndex,
|
|
95
|
+
identifier: patch.identifier,
|
|
96
|
+
tags: patch.tags
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
identifier: patch.identifier,
|
|
100
|
+
patchId: urlSafeBase64(
|
|
101
|
+
QuiltPatchId.serialize({
|
|
102
|
+
quiltId: __privateGet(this, _blob).blobId,
|
|
103
|
+
patchId: {
|
|
104
|
+
version: 1,
|
|
105
|
+
startIndex,
|
|
106
|
+
endIndex: patch.endIndex
|
|
107
|
+
}
|
|
108
|
+
}).toBytes()
|
|
109
|
+
),
|
|
110
|
+
tags: patch.tags,
|
|
111
|
+
reader
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
_blob = new WeakMap();
|
|
117
|
+
_cache = new WeakMap();
|
|
118
|
+
_QuiltReader_instances = new WeakSet();
|
|
119
|
+
readBytesFromSlivers_fn = async function(sliver, length, offset = 0, columnSize) {
|
|
120
|
+
if (!length) {
|
|
121
|
+
return new Uint8Array(0);
|
|
122
|
+
}
|
|
123
|
+
__privateGet(this, _blob).getSecondarySliver({ sliverIndex: sliver }).catch(() => {
|
|
124
|
+
});
|
|
125
|
+
columnSize = columnSize ?? await __privateGet(this, _blob).getColumnSize();
|
|
126
|
+
const columnOffset = Math.floor(offset / columnSize);
|
|
127
|
+
let remainingOffset = offset % columnSize;
|
|
128
|
+
const bytes = new Uint8Array(length);
|
|
129
|
+
let bytesRead = 0;
|
|
130
|
+
const nSlivers = Math.ceil(length / columnSize);
|
|
131
|
+
const slivers = new Array(nSlivers).fill(0).map((_, i) => __privateGet(this, _blob).getSecondarySliver({ sliverIndex: sliver + columnOffset + i }));
|
|
132
|
+
slivers.forEach((p) => p.catch(() => {
|
|
133
|
+
}));
|
|
134
|
+
for (const sliverPromise of slivers) {
|
|
135
|
+
const sliver2 = await sliverPromise;
|
|
136
|
+
let chunk = remainingOffset > 0 ? sliver2.subarray(remainingOffset) : sliver2;
|
|
137
|
+
remainingOffset -= chunk.length;
|
|
138
|
+
if (chunk.length > length - bytesRead) {
|
|
139
|
+
chunk = chunk.subarray(0, length - bytesRead);
|
|
140
|
+
}
|
|
141
|
+
bytes.set(chunk, bytesRead);
|
|
142
|
+
bytesRead += chunk.length;
|
|
143
|
+
if (bytesRead >= length) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return bytes;
|
|
148
|
+
};
|
|
149
|
+
readBytesFromBlob_fn = async function(startColumn, length, offset = 0) {
|
|
150
|
+
const result = new Uint8Array(length);
|
|
151
|
+
if (!length) {
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
const blob = await __privateGet(this, _blob).getBytes();
|
|
155
|
+
const [rowSize, symbolSize] = await Promise.all([
|
|
156
|
+
__privateGet(this, _blob).getRowSize(),
|
|
157
|
+
__privateGet(this, _blob).getSymbolSize()
|
|
158
|
+
]);
|
|
159
|
+
const nRows = blob.length / rowSize;
|
|
160
|
+
const symbolsToSkip = Math.floor(offset / symbolSize);
|
|
161
|
+
let remainingOffset = offset % symbolSize;
|
|
162
|
+
let currentCol = startColumn + Math.floor(symbolsToSkip / nRows);
|
|
163
|
+
let currentRow = symbolsToSkip % nRows;
|
|
164
|
+
let bytesRead = 0;
|
|
165
|
+
while (bytesRead < length) {
|
|
166
|
+
const baseIndex = currentRow * rowSize + currentCol * symbolSize;
|
|
167
|
+
const startIndex = baseIndex + remainingOffset;
|
|
168
|
+
const endIndex = Math.min(
|
|
169
|
+
baseIndex + symbolSize,
|
|
170
|
+
startIndex + length - bytesRead,
|
|
171
|
+
blob.length
|
|
172
|
+
);
|
|
173
|
+
if (startIndex >= blob.length) {
|
|
174
|
+
throw new Error("Index out of bounds");
|
|
175
|
+
}
|
|
176
|
+
const size = endIndex - startIndex;
|
|
177
|
+
for (let i = 0; i < size; i++) {
|
|
178
|
+
result[bytesRead + i] = blob[startIndex + i];
|
|
179
|
+
}
|
|
180
|
+
bytesRead += size;
|
|
181
|
+
remainingOffset = 0;
|
|
182
|
+
currentRow = (currentRow + 1) % nRows;
|
|
183
|
+
if (currentRow === 0) {
|
|
184
|
+
currentCol += 1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
};
|
|
189
|
+
readBytes_fn = async function(sliver, length, offset = 0, columnSize) {
|
|
190
|
+
if (__privateGet(this, _blob).hasStartedLoadingFullBlob) {
|
|
191
|
+
return __privateMethod(this, _QuiltReader_instances, readBytesFromBlob_fn).call(this, sliver, length, offset);
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const bytes = await __privateMethod(this, _QuiltReader_instances, readBytesFromSlivers_fn).call(this, sliver, length, offset, columnSize);
|
|
195
|
+
return bytes;
|
|
196
|
+
} catch (_error) {
|
|
197
|
+
return __privateMethod(this, _QuiltReader_instances, readBytesFromBlob_fn).call(this, sliver, length, offset);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
export {
|
|
201
|
+
QuiltReader
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=quilt.js.map
|