@pkcprotocol/pkc-js 0.0.141 → 0.0.143
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/README.md +1 -0
- package/dist/browser/clients/base-client-manager.js +6 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +15 -8
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +2 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +2 -0
- package/dist/browser/community/rpc-local-community.d.ts +12 -1
- package/dist/browser/community/rpc-local-community.js +133 -10
- package/dist/browser/community/rpc-local-community.js.map +1 -1
- package/dist/browser/community/schema.d.ts +19 -0
- package/dist/browser/community/schema.js +7 -3
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +18 -1
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/index-with-compile-cache.d.ts +2 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/object-key-util.js +5 -1
- package/dist/browser/object-key-util.js.map +1 -1
- package/dist/browser/pages/pages-client-manager.d.ts +1 -0
- package/dist/browser/pages/pages-client-manager.js +22 -5
- package/dist/browser/pages/pages-client-manager.js.map +1 -1
- package/dist/browser/pages/pkc-js-page-sorts/top.js +2 -1
- package/dist/browser/pages/pkc-js-page-sorts/top.js.map +1 -1
- package/dist/browser/pages/schema.js +3 -1
- package/dist/browser/pages/schema.js.map +1 -1
- package/dist/browser/pkc/pkc-with-rpc-client.js +9 -5
- package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -1
- package/dist/browser/pkc/pkc.d.ts +4 -1
- package/dist/browser/pkc/pkc.js +6 -5
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/publications/comment/comment-client-manager.js +11 -11
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/browser/publications/comment/comment.js +2 -0
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/community-edit/schema.d.ts +8 -0
- package/dist/browser/publications/publication-client-manager.js +7 -1
- package/dist/browser/publications/publication-client-manager.js.map +1 -1
- package/dist/browser/publications/publication.d.ts +7 -0
- package/dist/browser/publications/publication.js +88 -24
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/pubsub-messages/schema.d.ts +4 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +2 -0
- package/dist/browser/rpc/src/schema.d.ts +12 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/browser/runtime/node/community/db-handler.js +22 -4
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +70 -19
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.d.ts +14 -0
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js +206 -0
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community.js +4 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/page-sorts/index.js +10 -10
- package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +8 -0
- package/dist/browser/schema.d.ts +16 -0
- package/dist/browser/test/mock-ipfs-client.js +10 -4
- package/dist/browser/test/mock-ipfs-client.js.map +1 -1
- package/dist/browser/util.d.ts +5 -0
- package/dist/browser/util.js +52 -5
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +165 -123
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-C3zShnXN.js → helia-for-pkc-DpsMZzv8.js} +41 -34
- package/dist/bundled/chunks/{local-community-PFaUvMFo.js → local-community-BglT8AUy.js} +284 -47
- package/dist/bundled/chunks/{local-community-DMklqSLp.js → local-community-DEaDtekb.js} +1 -1
- package/dist/bundled/chunks/{node-CGmAA0az.js → node-Tkx_TCqE.js} +84 -34
- package/dist/bundled/chunks/{page-sort-scoring-Bz65Z28_.js → page-sort-scoring-DY7SvqJA.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-Dq_6nnU1.js → rpc-local-community-Br_xomgn.js} +128 -20
- package/dist/bundled/chunks/src-ABfmT8J2.js +2323 -0
- package/dist/bundled/chunks/src-BC60-Q7v.js +2 -0
- package/dist/bundled/chunks/src-BHqirG63.js +2 -0
- package/dist/bundled/chunks/{src-BggJ_InF.js → src-Bj5iE3qB.js} +2 -1999
- package/dist/bundled/chunks/src-CNab3O7M.js +2001 -0
- package/dist/bundled/chunks/{src-BsiPSkhv.js → src-ltPxiZKf.js} +1312 -3632
- package/dist/bundled/chunks/{util-C6YaxADn.js → util-C5RiQF_G.js} +59 -10
- package/dist/bundled/chunks/{util-CzoLr9RY.js → util-DIkZirPy.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-DMzx5r6y.js → validate-package-factories-DnW2JiL5.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.js +6 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +15 -8
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +2 -0
- package/dist/node/clients/rpc-client/schema.d.ts +2 -0
- package/dist/node/community/rpc-local-community.d.ts +12 -1
- package/dist/node/community/rpc-local-community.js +133 -10
- package/dist/node/community/rpc-local-community.js.map +1 -1
- package/dist/node/community/schema.d.ts +19 -0
- package/dist/node/community/schema.js +7 -3
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +18 -1
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/index-with-compile-cache.d.ts +2 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/object-key-util.js +5 -1
- package/dist/node/object-key-util.js.map +1 -1
- package/dist/node/pages/pages-client-manager.d.ts +1 -0
- package/dist/node/pages/pages-client-manager.js +22 -5
- package/dist/node/pages/pages-client-manager.js.map +1 -1
- package/dist/node/pages/pkc-js-page-sorts/top.js +2 -1
- package/dist/node/pages/pkc-js-page-sorts/top.js.map +1 -1
- package/dist/node/pages/schema.js +3 -1
- package/dist/node/pages/schema.js.map +1 -1
- package/dist/node/pkc/pkc-with-rpc-client.js +9 -5
- package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -1
- package/dist/node/pkc/pkc.d.ts +4 -1
- package/dist/node/pkc/pkc.js +6 -5
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/publications/comment/comment-client-manager.js +11 -11
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/node/publications/comment/comment.js +2 -0
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/community-edit/schema.d.ts +8 -0
- package/dist/node/publications/publication-client-manager.js +7 -1
- package/dist/node/publications/publication-client-manager.js.map +1 -1
- package/dist/node/publications/publication.d.ts +7 -0
- package/dist/node/publications/publication.js +88 -24
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/pubsub-messages/schema.d.ts +4 -0
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +2 -0
- package/dist/node/rpc/src/schema.d.ts +12 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/node/runtime/node/community/db-handler.js +22 -4
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js +70 -19
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.d.ts +14 -0
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js +206 -0
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community.js +4 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/page-sorts/index.js +10 -10
- package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +8 -0
- package/dist/node/schema.d.ts +16 -0
- package/dist/node/test/mock-ipfs-client.js +10 -4
- package/dist/node/test/mock-ipfs-client.js.map +1 -1
- package/dist/node/util.d.ts +5 -0
- package/dist/node/util.js +52 -5
- package/dist/node/util.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,2001 @@
|
|
|
1
|
+
import { fromString } from "uint8arrays/from-string";
|
|
2
|
+
import { allocUnsafe } from "uint8arrays/alloc";
|
|
3
|
+
import { withArrayBuffer } from "uint8arrays/with-array-buffer";
|
|
4
|
+
//#region node_modules/ipfs-unixfs/dist/src/errors.js
|
|
5
|
+
var InvalidTypeError = class InvalidTypeError extends Error {
|
|
6
|
+
static name = "InvalidTypeError";
|
|
7
|
+
static code = "ERR_INVALID_TYPE";
|
|
8
|
+
name = InvalidTypeError.name;
|
|
9
|
+
code = InvalidTypeError.code;
|
|
10
|
+
constructor(message = "Invalid type") {
|
|
11
|
+
super(message);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region node_modules/ipfs-unixfs/node_modules/uint8-varint/dist/src/index.js
|
|
16
|
+
const N1 = Math.pow(2, 7);
|
|
17
|
+
const N2 = Math.pow(2, 14);
|
|
18
|
+
const N3 = Math.pow(2, 21);
|
|
19
|
+
const N4 = Math.pow(2, 28);
|
|
20
|
+
const N5 = Math.pow(2, 35);
|
|
21
|
+
const N6 = Math.pow(2, 42);
|
|
22
|
+
const N7 = Math.pow(2, 49);
|
|
23
|
+
/** Most significant bit of a byte */
|
|
24
|
+
const MSB = 128;
|
|
25
|
+
/** Rest of the bits in a byte */
|
|
26
|
+
const REST = 127;
|
|
27
|
+
function encodingLength(value) {
|
|
28
|
+
if (value < N1) return 1;
|
|
29
|
+
if (value < N2) return 2;
|
|
30
|
+
if (value < N3) return 3;
|
|
31
|
+
if (value < N4) return 4;
|
|
32
|
+
if (value < N5) return 5;
|
|
33
|
+
if (value < N6) return 6;
|
|
34
|
+
if (value < N7) return 7;
|
|
35
|
+
if (Number.MAX_SAFE_INTEGER != null && value > Number.MAX_SAFE_INTEGER) throw new RangeError("Could not encode varint");
|
|
36
|
+
return 8;
|
|
37
|
+
}
|
|
38
|
+
function encodeUint8Array(value, buf, offset = 0) {
|
|
39
|
+
switch (encodingLength(value)) {
|
|
40
|
+
case 8:
|
|
41
|
+
buf[offset++] = value & 255 | MSB;
|
|
42
|
+
value /= 128;
|
|
43
|
+
case 7:
|
|
44
|
+
buf[offset++] = value & 255 | MSB;
|
|
45
|
+
value /= 128;
|
|
46
|
+
case 6:
|
|
47
|
+
buf[offset++] = value & 255 | MSB;
|
|
48
|
+
value /= 128;
|
|
49
|
+
case 5:
|
|
50
|
+
buf[offset++] = value & 255 | MSB;
|
|
51
|
+
value /= 128;
|
|
52
|
+
case 4:
|
|
53
|
+
buf[offset++] = value & 255 | MSB;
|
|
54
|
+
value >>>= 7;
|
|
55
|
+
case 3:
|
|
56
|
+
buf[offset++] = value & 255 | MSB;
|
|
57
|
+
value >>>= 7;
|
|
58
|
+
case 2:
|
|
59
|
+
buf[offset++] = value & 255 | MSB;
|
|
60
|
+
value >>>= 7;
|
|
61
|
+
case 1:
|
|
62
|
+
buf[offset++] = value & 255;
|
|
63
|
+
value >>>= 7;
|
|
64
|
+
break;
|
|
65
|
+
default: throw new Error("unreachable");
|
|
66
|
+
}
|
|
67
|
+
return buf;
|
|
68
|
+
}
|
|
69
|
+
function decodeUint8Array(buf, offset) {
|
|
70
|
+
let b = buf[offset];
|
|
71
|
+
let res = 0;
|
|
72
|
+
res += b & REST;
|
|
73
|
+
if (b < MSB) return res;
|
|
74
|
+
b = buf[offset + 1];
|
|
75
|
+
res += (b & REST) << 7;
|
|
76
|
+
if (b < MSB) return res;
|
|
77
|
+
b = buf[offset + 2];
|
|
78
|
+
res += (b & REST) << 14;
|
|
79
|
+
if (b < MSB) return res;
|
|
80
|
+
b = buf[offset + 3];
|
|
81
|
+
res += (b & REST) << 21;
|
|
82
|
+
if (b < MSB) return res;
|
|
83
|
+
b = buf[offset + 4];
|
|
84
|
+
res += (b & REST) * N4;
|
|
85
|
+
if (b < MSB) return res;
|
|
86
|
+
b = buf[offset + 5];
|
|
87
|
+
res += (b & REST) * N5;
|
|
88
|
+
if (b < MSB) return res;
|
|
89
|
+
b = buf[offset + 6];
|
|
90
|
+
res += (b & REST) * N6;
|
|
91
|
+
if (b < MSB) return res;
|
|
92
|
+
b = buf[offset + 7];
|
|
93
|
+
res += (b & REST) * N7;
|
|
94
|
+
if (b < MSB) return res;
|
|
95
|
+
throw new RangeError("Could not decode varint");
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/utils/float.js
|
|
99
|
+
const f32 = new Float32Array([-0]);
|
|
100
|
+
const f8b = new Uint8Array(f32.buffer);
|
|
101
|
+
/**
|
|
102
|
+
* Writes a 32 bit float to a buffer using little endian byte order
|
|
103
|
+
*/
|
|
104
|
+
function writeFloatLE(val, buf, pos) {
|
|
105
|
+
f32[0] = val;
|
|
106
|
+
buf[pos] = f8b[0];
|
|
107
|
+
buf[pos + 1] = f8b[1];
|
|
108
|
+
buf[pos + 2] = f8b[2];
|
|
109
|
+
buf[pos + 3] = f8b[3];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Reads a 32 bit float from a buffer using little endian byte order
|
|
113
|
+
*/
|
|
114
|
+
function readFloatLE(buf, pos) {
|
|
115
|
+
f8b[0] = buf[pos];
|
|
116
|
+
f8b[1] = buf[pos + 1];
|
|
117
|
+
f8b[2] = buf[pos + 2];
|
|
118
|
+
f8b[3] = buf[pos + 3];
|
|
119
|
+
return f32[0];
|
|
120
|
+
}
|
|
121
|
+
const f64 = new Float64Array([-0]);
|
|
122
|
+
const d8b = new Uint8Array(f64.buffer);
|
|
123
|
+
/**
|
|
124
|
+
* Writes a 64 bit double to a buffer using little endian byte order
|
|
125
|
+
*/
|
|
126
|
+
function writeDoubleLE(val, buf, pos) {
|
|
127
|
+
f64[0] = val;
|
|
128
|
+
buf[pos] = d8b[0];
|
|
129
|
+
buf[pos + 1] = d8b[1];
|
|
130
|
+
buf[pos + 2] = d8b[2];
|
|
131
|
+
buf[pos + 3] = d8b[3];
|
|
132
|
+
buf[pos + 4] = d8b[4];
|
|
133
|
+
buf[pos + 5] = d8b[5];
|
|
134
|
+
buf[pos + 6] = d8b[6];
|
|
135
|
+
buf[pos + 7] = d8b[7];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Reads a 64 bit double from a buffer using little endian byte order
|
|
139
|
+
*/
|
|
140
|
+
function readDoubleLE(buf, pos) {
|
|
141
|
+
d8b[0] = buf[pos];
|
|
142
|
+
d8b[1] = buf[pos + 1];
|
|
143
|
+
d8b[2] = buf[pos + 2];
|
|
144
|
+
d8b[3] = buf[pos + 3];
|
|
145
|
+
d8b[4] = buf[pos + 4];
|
|
146
|
+
d8b[5] = buf[pos + 5];
|
|
147
|
+
d8b[6] = buf[pos + 6];
|
|
148
|
+
d8b[7] = buf[pos + 7];
|
|
149
|
+
return f64[0];
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/utils/longbits.js
|
|
153
|
+
const MAX_SAFE_NUMBER_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
|
154
|
+
const MIN_SAFE_NUMBER_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
|
|
155
|
+
/**
|
|
156
|
+
* Constructs new long bits.
|
|
157
|
+
*
|
|
158
|
+
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
|
|
159
|
+
* @memberof util
|
|
160
|
+
* @function Object() { [native code] }
|
|
161
|
+
* @param {number} lo - Low 32 bits, unsigned
|
|
162
|
+
* @param {number} hi - High 32 bits, unsigned
|
|
163
|
+
*/
|
|
164
|
+
var LongBits = class LongBits {
|
|
165
|
+
lo;
|
|
166
|
+
hi;
|
|
167
|
+
constructor(lo, hi) {
|
|
168
|
+
/**
|
|
169
|
+
* Low bits
|
|
170
|
+
*/
|
|
171
|
+
this.lo = lo >>> 0;
|
|
172
|
+
/**
|
|
173
|
+
* High bits
|
|
174
|
+
*/
|
|
175
|
+
this.hi = hi >>> 0;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Converts this long bits to a possibly unsafe JavaScript number
|
|
179
|
+
*/
|
|
180
|
+
toNumber(unsigned = false) {
|
|
181
|
+
if (!unsigned && this.hi >>> 31 > 0) {
|
|
182
|
+
const lo = ~this.lo + 1 >>> 0;
|
|
183
|
+
let hi = ~this.hi >>> 0;
|
|
184
|
+
if (lo === 0) hi = hi + 1 >>> 0;
|
|
185
|
+
return -(lo + hi * 4294967296);
|
|
186
|
+
}
|
|
187
|
+
return this.lo + this.hi * 4294967296;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Converts this long bits to a bigint
|
|
191
|
+
*/
|
|
192
|
+
toBigInt(unsigned = false) {
|
|
193
|
+
if (unsigned) return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n);
|
|
194
|
+
if (this.hi >>> 31 !== 0) {
|
|
195
|
+
const lo = ~this.lo + 1 >>> 0;
|
|
196
|
+
let hi = ~this.hi >>> 0;
|
|
197
|
+
if (lo === 0) hi = hi + 1 >>> 0;
|
|
198
|
+
return -(BigInt(lo) + (BigInt(hi) << 32n));
|
|
199
|
+
}
|
|
200
|
+
return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Converts this long bits to a string
|
|
204
|
+
*/
|
|
205
|
+
toString(unsigned = false) {
|
|
206
|
+
return this.toBigInt(unsigned).toString();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Zig-zag encodes this long bits
|
|
210
|
+
*/
|
|
211
|
+
zzEncode() {
|
|
212
|
+
const mask = this.hi >> 31;
|
|
213
|
+
this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
|
|
214
|
+
this.lo = (this.lo << 1 ^ mask) >>> 0;
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Zig-zag decodes this long bits
|
|
219
|
+
*/
|
|
220
|
+
zzDecode() {
|
|
221
|
+
const mask = -(this.lo & 1);
|
|
222
|
+
this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
|
|
223
|
+
this.hi = (this.hi >>> 1 ^ mask) >>> 0;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Calculates the length of this longbits when encoded as a varint.
|
|
228
|
+
*/
|
|
229
|
+
length() {
|
|
230
|
+
const part0 = this.lo;
|
|
231
|
+
const part1 = (this.lo >>> 28 | this.hi << 4) >>> 0;
|
|
232
|
+
const part2 = this.hi >>> 24;
|
|
233
|
+
return part2 === 0 ? part1 === 0 ? part0 < 16384 ? part0 < 128 ? 1 : 2 : part0 < 2097152 ? 3 : 4 : part1 < 16384 ? part1 < 128 ? 5 : 6 : part1 < 2097152 ? 7 : 8 : part2 < 128 ? 9 : 10;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Constructs new long bits from the specified number
|
|
237
|
+
*/
|
|
238
|
+
static fromBigInt(value) {
|
|
239
|
+
if (value === 0n) return zero;
|
|
240
|
+
if (value < MAX_SAFE_NUMBER_INTEGER && value > MIN_SAFE_NUMBER_INTEGER) return this.fromNumber(Number(value));
|
|
241
|
+
const negative = value < 0n;
|
|
242
|
+
if (negative) value = -value;
|
|
243
|
+
let hi = value >> 32n;
|
|
244
|
+
let lo = value - (hi << 32n);
|
|
245
|
+
if (negative) {
|
|
246
|
+
hi = ~hi | 0n;
|
|
247
|
+
lo = ~lo | 0n;
|
|
248
|
+
if (++lo > TWO_32) {
|
|
249
|
+
lo = 0n;
|
|
250
|
+
if (++hi > TWO_32) hi = 0n;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return new LongBits(Number(lo), Number(hi));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Constructs new long bits from the specified number
|
|
257
|
+
*/
|
|
258
|
+
static fromNumber(value) {
|
|
259
|
+
if (value === 0) return zero;
|
|
260
|
+
const sign = value < 0;
|
|
261
|
+
if (sign) value = -value;
|
|
262
|
+
let lo = value >>> 0;
|
|
263
|
+
let hi = (value - lo) / 4294967296 >>> 0;
|
|
264
|
+
if (sign) {
|
|
265
|
+
hi = ~hi >>> 0;
|
|
266
|
+
lo = ~lo >>> 0;
|
|
267
|
+
if (++lo > 4294967295) {
|
|
268
|
+
lo = 0;
|
|
269
|
+
if (++hi > 4294967295) hi = 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return new LongBits(lo, hi);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Constructs new long bits from a number, long or string
|
|
276
|
+
*/
|
|
277
|
+
static from(value) {
|
|
278
|
+
if (typeof value === "number") return LongBits.fromNumber(value);
|
|
279
|
+
if (typeof value === "bigint") return LongBits.fromBigInt(value);
|
|
280
|
+
if (typeof value === "string") return LongBits.fromBigInt(BigInt(value));
|
|
281
|
+
return value.low != null || value.high != null ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const zero = new LongBits(0, 0);
|
|
285
|
+
zero.toBigInt = function() {
|
|
286
|
+
return 0n;
|
|
287
|
+
};
|
|
288
|
+
zero.zzEncode = zero.zzDecode = function() {
|
|
289
|
+
return this;
|
|
290
|
+
};
|
|
291
|
+
zero.length = function() {
|
|
292
|
+
return 1;
|
|
293
|
+
};
|
|
294
|
+
const TWO_32 = 4294967296n;
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/utils/utf8.js
|
|
297
|
+
/**
|
|
298
|
+
* Calculates the UTF8 byte length of a string
|
|
299
|
+
*/
|
|
300
|
+
function length(string) {
|
|
301
|
+
let len = 0;
|
|
302
|
+
let c = 0;
|
|
303
|
+
for (let i = 0; i < string.length; ++i) {
|
|
304
|
+
c = string.charCodeAt(i);
|
|
305
|
+
if (c < 128) len += 1;
|
|
306
|
+
else if (c < 2048) len += 2;
|
|
307
|
+
else if ((c & 64512) === 55296 && (string.charCodeAt(i + 1) & 64512) === 56320) {
|
|
308
|
+
++i;
|
|
309
|
+
len += 4;
|
|
310
|
+
} else len += 3;
|
|
311
|
+
}
|
|
312
|
+
return len;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Reads UTF8 bytes as a string
|
|
316
|
+
*/
|
|
317
|
+
function read(buffer, start, end) {
|
|
318
|
+
if (end - start < 1) return "";
|
|
319
|
+
let parts;
|
|
320
|
+
const chunk = [];
|
|
321
|
+
let i = 0;
|
|
322
|
+
let t;
|
|
323
|
+
while (start < end) {
|
|
324
|
+
t = buffer[start++];
|
|
325
|
+
if (t < 128) chunk[i++] = t;
|
|
326
|
+
else if (t > 191 && t < 224) chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
327
|
+
else if (t > 239 && t < 365) {
|
|
328
|
+
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 65536;
|
|
329
|
+
chunk[i++] = 55296 + (t >> 10);
|
|
330
|
+
chunk[i++] = 56320 + (t & 1023);
|
|
331
|
+
} else chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
332
|
+
if (i > 8191) {
|
|
333
|
+
(parts ?? (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
334
|
+
i = 0;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (parts != null) {
|
|
338
|
+
if (i > 0) parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
339
|
+
return parts.join("");
|
|
340
|
+
}
|
|
341
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Writes a string as UTF8 bytes
|
|
345
|
+
*/
|
|
346
|
+
function write(string, buffer, offset) {
|
|
347
|
+
const start = offset;
|
|
348
|
+
let c1;
|
|
349
|
+
let c2;
|
|
350
|
+
for (let i = 0; i < string.length; ++i) {
|
|
351
|
+
c1 = string.charCodeAt(i);
|
|
352
|
+
if (c1 < 128) buffer[offset++] = c1;
|
|
353
|
+
else if (c1 < 2048) {
|
|
354
|
+
buffer[offset++] = c1 >> 6 | 192;
|
|
355
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
356
|
+
} else if ((c1 & 64512) === 55296 && ((c2 = string.charCodeAt(i + 1)) & 64512) === 56320) {
|
|
357
|
+
c1 = 65536 + ((c1 & 1023) << 10) + (c2 & 1023);
|
|
358
|
+
++i;
|
|
359
|
+
buffer[offset++] = c1 >> 18 | 240;
|
|
360
|
+
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
361
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
362
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
363
|
+
} else {
|
|
364
|
+
buffer[offset++] = c1 >> 12 | 224;
|
|
365
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
366
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return offset - start;
|
|
370
|
+
}
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/utils/reader.js
|
|
373
|
+
/* istanbul ignore next */
|
|
374
|
+
function indexOutOfRange(reader, writeLength) {
|
|
375
|
+
return RangeError(`index out of range: ${reader.pos} + ${writeLength ?? 1} > ${reader.len}`);
|
|
376
|
+
}
|
|
377
|
+
function readFixed32End(buf, end) {
|
|
378
|
+
return (buf[end - 4] | buf[end - 3] << 8 | buf[end - 2] << 16 | buf[end - 1] << 24) >>> 0;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Constructs a new reader instance using the specified buffer.
|
|
382
|
+
*/
|
|
383
|
+
var Uint8ArrayReader = class {
|
|
384
|
+
buf;
|
|
385
|
+
pos;
|
|
386
|
+
len;
|
|
387
|
+
_slice = Uint8Array.prototype.subarray;
|
|
388
|
+
constructor(buffer) {
|
|
389
|
+
/**
|
|
390
|
+
* Read buffer
|
|
391
|
+
*/
|
|
392
|
+
this.buf = withArrayBuffer(buffer);
|
|
393
|
+
/**
|
|
394
|
+
* Read buffer position
|
|
395
|
+
*/
|
|
396
|
+
this.pos = 0;
|
|
397
|
+
/**
|
|
398
|
+
* Read buffer length
|
|
399
|
+
*/
|
|
400
|
+
this.len = buffer.length;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Reads a varint as an unsigned 32 bit value
|
|
404
|
+
*/
|
|
405
|
+
uint32() {
|
|
406
|
+
let value = 4294967295;
|
|
407
|
+
value = (this.buf[this.pos] & 127) >>> 0;
|
|
408
|
+
if (this.buf[this.pos++] < 128) return value;
|
|
409
|
+
value = (value | (this.buf[this.pos] & 127) << 7) >>> 0;
|
|
410
|
+
if (this.buf[this.pos++] < 128) return value;
|
|
411
|
+
value = (value | (this.buf[this.pos] & 127) << 14) >>> 0;
|
|
412
|
+
if (this.buf[this.pos++] < 128) return value;
|
|
413
|
+
value = (value | (this.buf[this.pos] & 127) << 21) >>> 0;
|
|
414
|
+
if (this.buf[this.pos++] < 128) return value;
|
|
415
|
+
value = (value | (this.buf[this.pos] & 15) << 28) >>> 0;
|
|
416
|
+
if (this.buf[this.pos++] < 128) return value;
|
|
417
|
+
if ((this.pos += 5) > this.len) {
|
|
418
|
+
this.pos = this.len;
|
|
419
|
+
throw indexOutOfRange(this, 10);
|
|
420
|
+
}
|
|
421
|
+
return value;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Reads a varint as a signed 32 bit value
|
|
425
|
+
*/
|
|
426
|
+
int32() {
|
|
427
|
+
return this.uint32() | 0;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Reads a zig-zag encoded varint as a signed 32 bit value
|
|
431
|
+
*/
|
|
432
|
+
sint32() {
|
|
433
|
+
const value = this.uint32();
|
|
434
|
+
return value >>> 1 ^ -(value & 1) | 0;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Reads a varint as a boolean
|
|
438
|
+
*/
|
|
439
|
+
bool() {
|
|
440
|
+
return this.uint32() !== 0;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Reads fixed 32 bits as an unsigned 32 bit integer
|
|
444
|
+
*/
|
|
445
|
+
fixed32() {
|
|
446
|
+
if (this.pos + 4 > this.len) throw indexOutOfRange(this, 4);
|
|
447
|
+
return readFixed32End(this.buf, this.pos += 4);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Reads fixed 32 bits as a signed 32 bit integer
|
|
451
|
+
*/
|
|
452
|
+
sfixed32() {
|
|
453
|
+
if (this.pos + 4 > this.len) throw indexOutOfRange(this, 4);
|
|
454
|
+
return readFixed32End(this.buf, this.pos += 4) | 0;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Reads a float (32 bit) as a number
|
|
458
|
+
*/
|
|
459
|
+
float() {
|
|
460
|
+
if (this.pos + 4 > this.len) throw indexOutOfRange(this, 4);
|
|
461
|
+
const value = readFloatLE(this.buf, this.pos);
|
|
462
|
+
this.pos += 4;
|
|
463
|
+
return value;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Reads a double (64 bit float) as a number
|
|
467
|
+
*/
|
|
468
|
+
double() {
|
|
469
|
+
/* istanbul ignore if */
|
|
470
|
+
if (this.pos + 8 > this.len) throw indexOutOfRange(this, 4);
|
|
471
|
+
const value = readDoubleLE(this.buf, this.pos);
|
|
472
|
+
this.pos += 8;
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Reads a sequence of bytes preceded by its length as a varint
|
|
477
|
+
*/
|
|
478
|
+
bytes() {
|
|
479
|
+
const length = this.uint32();
|
|
480
|
+
const start = this.pos;
|
|
481
|
+
const end = this.pos + length;
|
|
482
|
+
/* istanbul ignore if */
|
|
483
|
+
if (end > this.len) throw indexOutOfRange(this, length);
|
|
484
|
+
this.pos += length;
|
|
485
|
+
return start === end ? new Uint8Array(0) : this.buf.subarray(start, end);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Reads a string preceded by its byte length as a varint
|
|
489
|
+
*/
|
|
490
|
+
string() {
|
|
491
|
+
const bytes = this.bytes();
|
|
492
|
+
return read(bytes, 0, bytes.length);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Skips the specified number of bytes if specified, otherwise skips a varint
|
|
496
|
+
*/
|
|
497
|
+
skip(length) {
|
|
498
|
+
if (typeof length === "number") {
|
|
499
|
+
/* istanbul ignore if */
|
|
500
|
+
if (this.pos + length > this.len) throw indexOutOfRange(this, length);
|
|
501
|
+
this.pos += length;
|
|
502
|
+
} else do
|
|
503
|
+
/* istanbul ignore if */
|
|
504
|
+
if (this.pos >= this.len) throw indexOutOfRange(this);
|
|
505
|
+
while ((this.buf[this.pos++] & 128) !== 0);
|
|
506
|
+
return this;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Skips the next element of the specified wire type
|
|
510
|
+
*/
|
|
511
|
+
skipType(wireType) {
|
|
512
|
+
switch (wireType) {
|
|
513
|
+
case 0:
|
|
514
|
+
this.skip();
|
|
515
|
+
break;
|
|
516
|
+
case 1:
|
|
517
|
+
this.skip(8);
|
|
518
|
+
break;
|
|
519
|
+
case 2:
|
|
520
|
+
this.skip(this.uint32());
|
|
521
|
+
break;
|
|
522
|
+
case 3:
|
|
523
|
+
while ((wireType = this.uint32() & 7) !== 4) this.skipType(wireType);
|
|
524
|
+
break;
|
|
525
|
+
case 5:
|
|
526
|
+
this.skip(4);
|
|
527
|
+
break;
|
|
528
|
+
/* istanbul ignore next */
|
|
529
|
+
default: throw Error(`invalid wire type ${wireType} at offset ${this.pos}`);
|
|
530
|
+
}
|
|
531
|
+
return this;
|
|
532
|
+
}
|
|
533
|
+
readLongVarint() {
|
|
534
|
+
const bits = new LongBits(0, 0);
|
|
535
|
+
let i = 0;
|
|
536
|
+
if (this.len - this.pos > 4) {
|
|
537
|
+
for (; i < 4; ++i) {
|
|
538
|
+
bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
|
|
539
|
+
if (this.buf[this.pos++] < 128) return bits;
|
|
540
|
+
}
|
|
541
|
+
bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
|
|
542
|
+
bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
|
|
543
|
+
if (this.buf[this.pos++] < 128) return bits;
|
|
544
|
+
i = 0;
|
|
545
|
+
} else {
|
|
546
|
+
for (; i < 3; ++i) {
|
|
547
|
+
/* istanbul ignore if */
|
|
548
|
+
if (this.pos >= this.len) throw indexOutOfRange(this);
|
|
549
|
+
bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
|
|
550
|
+
if (this.buf[this.pos++] < 128) return bits;
|
|
551
|
+
}
|
|
552
|
+
bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
|
|
553
|
+
return bits;
|
|
554
|
+
}
|
|
555
|
+
if (this.len - this.pos > 4) for (; i < 5; ++i) {
|
|
556
|
+
bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
|
|
557
|
+
if (this.buf[this.pos++] < 128) return bits;
|
|
558
|
+
}
|
|
559
|
+
else for (; i < 5; ++i) {
|
|
560
|
+
if (this.pos >= this.len) throw indexOutOfRange(this);
|
|
561
|
+
bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
|
|
562
|
+
if (this.buf[this.pos++] < 128) return bits;
|
|
563
|
+
}
|
|
564
|
+
throw Error("invalid varint encoding");
|
|
565
|
+
}
|
|
566
|
+
readFixed64() {
|
|
567
|
+
if (this.pos + 8 > this.len) throw indexOutOfRange(this, 8);
|
|
568
|
+
return new LongBits(readFixed32End(this.buf, this.pos += 4), readFixed32End(this.buf, this.pos += 4));
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Reads a varint as a signed 64 bit value
|
|
572
|
+
*/
|
|
573
|
+
int64() {
|
|
574
|
+
return this.readLongVarint().toBigInt();
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Reads a varint as a signed 64 bit value returned as a possibly unsafe
|
|
578
|
+
* JavaScript number
|
|
579
|
+
*/
|
|
580
|
+
int64Number() {
|
|
581
|
+
return this.readLongVarint().toNumber();
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Reads a varint as a signed 64 bit value returned as a string
|
|
585
|
+
*/
|
|
586
|
+
int64String() {
|
|
587
|
+
return this.readLongVarint().toString();
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Reads a varint as an unsigned 64 bit value
|
|
591
|
+
*/
|
|
592
|
+
uint64() {
|
|
593
|
+
return this.readLongVarint().toBigInt(true);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Reads a varint as an unsigned 64 bit value returned as a possibly unsafe
|
|
597
|
+
* JavaScript number
|
|
598
|
+
*/
|
|
599
|
+
uint64Number() {
|
|
600
|
+
const value = decodeUint8Array(this.buf, this.pos);
|
|
601
|
+
this.pos += encodingLength(value);
|
|
602
|
+
return value;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Reads a varint as an unsigned 64 bit value returned as a string
|
|
606
|
+
*/
|
|
607
|
+
uint64String() {
|
|
608
|
+
return this.readLongVarint().toString(true);
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Reads a zig-zag encoded varint as a signed 64 bit value
|
|
612
|
+
*/
|
|
613
|
+
sint64() {
|
|
614
|
+
return this.readLongVarint().zzDecode().toBigInt();
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a
|
|
618
|
+
* possibly unsafe JavaScript number
|
|
619
|
+
*/
|
|
620
|
+
sint64Number() {
|
|
621
|
+
return this.readLongVarint().zzDecode().toNumber();
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a
|
|
625
|
+
* string
|
|
626
|
+
*/
|
|
627
|
+
sint64String() {
|
|
628
|
+
return this.readLongVarint().zzDecode().toString();
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Reads fixed 64 bits
|
|
632
|
+
*/
|
|
633
|
+
fixed64() {
|
|
634
|
+
return this.readFixed64().toBigInt();
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Reads fixed 64 bits returned as a possibly unsafe JavaScript number
|
|
638
|
+
*/
|
|
639
|
+
fixed64Number() {
|
|
640
|
+
return this.readFixed64().toNumber();
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Reads fixed 64 bits returned as a string
|
|
644
|
+
*/
|
|
645
|
+
fixed64String() {
|
|
646
|
+
return this.readFixed64().toString();
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Reads zig-zag encoded fixed 64 bits
|
|
650
|
+
*/
|
|
651
|
+
sfixed64() {
|
|
652
|
+
return this.readFixed64().toBigInt();
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe
|
|
656
|
+
* JavaScript number
|
|
657
|
+
*/
|
|
658
|
+
sfixed64Number() {
|
|
659
|
+
return this.readFixed64().toNumber();
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Reads zig-zag encoded fixed 64 bits returned as a string
|
|
663
|
+
*/
|
|
664
|
+
sfixed64String() {
|
|
665
|
+
return this.readFixed64().toString();
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
function createReader(buf) {
|
|
669
|
+
return new Uint8ArrayReader(buf instanceof Uint8Array ? buf : buf.subarray());
|
|
670
|
+
}
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/decode.js
|
|
673
|
+
function decodeMessage(buf, codec, opts) {
|
|
674
|
+
const reader = createReader(buf);
|
|
675
|
+
return codec.decode(reader, void 0, opts);
|
|
676
|
+
}
|
|
677
|
+
//#endregion
|
|
678
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/utils/pool.js
|
|
679
|
+
/**
|
|
680
|
+
* A general purpose buffer pool
|
|
681
|
+
*/
|
|
682
|
+
function pool(size) {
|
|
683
|
+
const SIZE = size ?? 8192;
|
|
684
|
+
const MAX = SIZE >>> 1;
|
|
685
|
+
let slab;
|
|
686
|
+
let offset = SIZE;
|
|
687
|
+
return function poolAlloc(size) {
|
|
688
|
+
if (size < 1 || size > MAX) return allocUnsafe(size);
|
|
689
|
+
if (offset + size > SIZE) {
|
|
690
|
+
slab = allocUnsafe(SIZE);
|
|
691
|
+
offset = 0;
|
|
692
|
+
}
|
|
693
|
+
const buf = slab.subarray(offset, offset += size);
|
|
694
|
+
if ((offset & 7) !== 0) offset = (offset | 7) + 1;
|
|
695
|
+
return buf;
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
//#endregion
|
|
699
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/utils/writer.js
|
|
700
|
+
/**
|
|
701
|
+
* Constructs a new writer operation instance.
|
|
702
|
+
*
|
|
703
|
+
* @classdesc Scheduled writer operation
|
|
704
|
+
*/
|
|
705
|
+
var Op = class {
|
|
706
|
+
/**
|
|
707
|
+
* Function to call
|
|
708
|
+
*/
|
|
709
|
+
fn;
|
|
710
|
+
/**
|
|
711
|
+
* Value byte length
|
|
712
|
+
*/
|
|
713
|
+
len;
|
|
714
|
+
/**
|
|
715
|
+
* Next operation
|
|
716
|
+
*/
|
|
717
|
+
next;
|
|
718
|
+
/**
|
|
719
|
+
* Value to write
|
|
720
|
+
*/
|
|
721
|
+
val;
|
|
722
|
+
constructor(fn, len, val) {
|
|
723
|
+
this.fn = fn;
|
|
724
|
+
this.len = len;
|
|
725
|
+
this.next = void 0;
|
|
726
|
+
this.val = val;
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
/* istanbul ignore next */
|
|
730
|
+
function noop() {}
|
|
731
|
+
/**
|
|
732
|
+
* Constructs a new writer state instance
|
|
733
|
+
*/
|
|
734
|
+
var State = class {
|
|
735
|
+
/**
|
|
736
|
+
* Current head
|
|
737
|
+
*/
|
|
738
|
+
head;
|
|
739
|
+
/**
|
|
740
|
+
* Current tail
|
|
741
|
+
*/
|
|
742
|
+
tail;
|
|
743
|
+
/**
|
|
744
|
+
* Current buffer length
|
|
745
|
+
*/
|
|
746
|
+
len;
|
|
747
|
+
/**
|
|
748
|
+
* Next state
|
|
749
|
+
*/
|
|
750
|
+
next;
|
|
751
|
+
constructor(writer) {
|
|
752
|
+
this.head = writer.head;
|
|
753
|
+
this.tail = writer.tail;
|
|
754
|
+
this.len = writer.len;
|
|
755
|
+
this.next = writer.states;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
const bufferPool = pool();
|
|
759
|
+
/**
|
|
760
|
+
* Allocates a buffer of the specified size
|
|
761
|
+
*/
|
|
762
|
+
function alloc$1(size) {
|
|
763
|
+
if (globalThis.Buffer != null) return allocUnsafe(size);
|
|
764
|
+
return bufferPool(size);
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* When a value is written, the writer calculates its byte length and puts it into a linked
|
|
768
|
+
* list of operations to perform when finish() is called. This both allows us to allocate
|
|
769
|
+
* buffers of the exact required size and reduces the amount of work we have to do compared
|
|
770
|
+
* to first calculating over objects and then encoding over objects. In our case, the encoding
|
|
771
|
+
* part is just a linked list walk calling operations with already prepared values.
|
|
772
|
+
*/
|
|
773
|
+
var Uint8ArrayWriter = class {
|
|
774
|
+
/**
|
|
775
|
+
* Current length
|
|
776
|
+
*/
|
|
777
|
+
len;
|
|
778
|
+
/**
|
|
779
|
+
* Operations head
|
|
780
|
+
*/
|
|
781
|
+
head;
|
|
782
|
+
/**
|
|
783
|
+
* Operations tail
|
|
784
|
+
*/
|
|
785
|
+
tail;
|
|
786
|
+
/**
|
|
787
|
+
* Linked forked states
|
|
788
|
+
*/
|
|
789
|
+
states;
|
|
790
|
+
constructor() {
|
|
791
|
+
this.len = 0;
|
|
792
|
+
this.head = new Op(noop, 0, 0);
|
|
793
|
+
this.tail = this.head;
|
|
794
|
+
this.states = null;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Pushes a new operation to the queue
|
|
798
|
+
*/
|
|
799
|
+
_push(fn, len, val) {
|
|
800
|
+
this.tail = this.tail.next = new Op(fn, len, val);
|
|
801
|
+
this.len += len;
|
|
802
|
+
return this;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Writes an unsigned 32 bit value as a varint
|
|
806
|
+
*/
|
|
807
|
+
uint32(value) {
|
|
808
|
+
this.len += (this.tail = this.tail.next = new VarintOp((value = value >>> 0) < 128 ? 1 : value < 16384 ? 2 : value < 2097152 ? 3 : value < 268435456 ? 4 : 5, value)).len;
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Writes a signed 32 bit value as a varint`
|
|
813
|
+
*/
|
|
814
|
+
int32(value) {
|
|
815
|
+
return value < 0 ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) : this.uint32(value);
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Writes a 32 bit value as a varint, zig-zag encoded
|
|
819
|
+
*/
|
|
820
|
+
sint32(value) {
|
|
821
|
+
return this.uint32((value << 1 ^ value >> 31) >>> 0);
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Writes an unsigned 64 bit value as a varint
|
|
825
|
+
*/
|
|
826
|
+
uint64(value) {
|
|
827
|
+
const bits = LongBits.fromBigInt(value);
|
|
828
|
+
return this._push(writeVarint64, bits.length(), bits);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Writes an unsigned 64 bit value as a varint
|
|
832
|
+
*/
|
|
833
|
+
uint64Number(value) {
|
|
834
|
+
return this._push(encodeUint8Array, encodingLength(value), value);
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Writes an unsigned 64 bit value as a varint
|
|
838
|
+
*/
|
|
839
|
+
uint64String(value) {
|
|
840
|
+
return this.uint64(BigInt(value));
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Writes a signed 64 bit value as a varint
|
|
844
|
+
*/
|
|
845
|
+
int64(value) {
|
|
846
|
+
return this.uint64(value);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Writes a signed 64 bit value as a varint
|
|
850
|
+
*/
|
|
851
|
+
int64Number(value) {
|
|
852
|
+
return this.uint64Number(value);
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Writes a signed 64 bit value as a varint
|
|
856
|
+
*/
|
|
857
|
+
int64String(value) {
|
|
858
|
+
return this.uint64String(value);
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Writes a signed 64 bit value as a varint, zig-zag encoded
|
|
862
|
+
*/
|
|
863
|
+
sint64(value) {
|
|
864
|
+
const bits = LongBits.fromBigInt(value).zzEncode();
|
|
865
|
+
return this._push(writeVarint64, bits.length(), bits);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Writes a signed 64 bit value as a varint, zig-zag encoded
|
|
869
|
+
*/
|
|
870
|
+
sint64Number(value) {
|
|
871
|
+
const bits = LongBits.fromNumber(value).zzEncode();
|
|
872
|
+
return this._push(writeVarint64, bits.length(), bits);
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Writes a signed 64 bit value as a varint, zig-zag encoded
|
|
876
|
+
*/
|
|
877
|
+
sint64String(value) {
|
|
878
|
+
return this.sint64(BigInt(value));
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Writes a boolish value as a varint
|
|
882
|
+
*/
|
|
883
|
+
bool(value) {
|
|
884
|
+
return this._push(writeByte, 1, value ? 1 : 0);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Writes an unsigned 32 bit value as fixed 32 bits
|
|
888
|
+
*/
|
|
889
|
+
fixed32(value) {
|
|
890
|
+
return this._push(writeFixed32, 4, value >>> 0);
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Writes a signed 32 bit value as fixed 32 bits
|
|
894
|
+
*/
|
|
895
|
+
sfixed32(value) {
|
|
896
|
+
return this.fixed32(value);
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Writes an unsigned 64 bit value as fixed 64 bits
|
|
900
|
+
*/
|
|
901
|
+
fixed64(value) {
|
|
902
|
+
const bits = LongBits.fromBigInt(value);
|
|
903
|
+
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Writes an unsigned 64 bit value as fixed 64 bits
|
|
907
|
+
*/
|
|
908
|
+
fixed64Number(value) {
|
|
909
|
+
const bits = LongBits.fromNumber(value);
|
|
910
|
+
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Writes an unsigned 64 bit value as fixed 64 bits
|
|
914
|
+
*/
|
|
915
|
+
fixed64String(value) {
|
|
916
|
+
return this.fixed64(BigInt(value));
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Writes a signed 64 bit value as fixed 64 bits
|
|
920
|
+
*/
|
|
921
|
+
sfixed64(value) {
|
|
922
|
+
return this.fixed64(value);
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Writes a signed 64 bit value as fixed 64 bits
|
|
926
|
+
*/
|
|
927
|
+
sfixed64Number(value) {
|
|
928
|
+
return this.fixed64Number(value);
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Writes a signed 64 bit value as fixed 64 bits
|
|
932
|
+
*/
|
|
933
|
+
sfixed64String(value) {
|
|
934
|
+
return this.fixed64String(value);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Writes a float (32 bit)
|
|
938
|
+
*/
|
|
939
|
+
float(value) {
|
|
940
|
+
return this._push(writeFloatLE, 4, value);
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Writes a double (64 bit float).
|
|
944
|
+
*
|
|
945
|
+
* @function
|
|
946
|
+
* @param {number} value - Value to write
|
|
947
|
+
* @returns {Writer} `this`
|
|
948
|
+
*/
|
|
949
|
+
double(value) {
|
|
950
|
+
return this._push(writeDoubleLE, 8, value);
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Writes a sequence of bytes
|
|
954
|
+
*/
|
|
955
|
+
bytes(value) {
|
|
956
|
+
const len = value.length >>> 0;
|
|
957
|
+
if (len === 0) return this._push(writeByte, 1, 0);
|
|
958
|
+
return this.uint32(len)._push(writeBytes, len, value);
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Writes a string
|
|
962
|
+
*/
|
|
963
|
+
string(value) {
|
|
964
|
+
const len = length(value);
|
|
965
|
+
return len !== 0 ? this.uint32(len)._push(write, len, value) : this._push(writeByte, 1, 0);
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Forks this writer's state by pushing it to a stack.
|
|
969
|
+
* Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
|
|
970
|
+
*/
|
|
971
|
+
fork() {
|
|
972
|
+
this.states = new State(this);
|
|
973
|
+
this.head = this.tail = new Op(noop, 0, 0);
|
|
974
|
+
this.len = 0;
|
|
975
|
+
return this;
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Resets this instance to the last state
|
|
979
|
+
*/
|
|
980
|
+
reset() {
|
|
981
|
+
if (this.states != null) {
|
|
982
|
+
this.head = this.states.head;
|
|
983
|
+
this.tail = this.states.tail;
|
|
984
|
+
this.len = this.states.len;
|
|
985
|
+
this.states = this.states.next;
|
|
986
|
+
} else {
|
|
987
|
+
this.head = this.tail = new Op(noop, 0, 0);
|
|
988
|
+
this.len = 0;
|
|
989
|
+
}
|
|
990
|
+
return this;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
|
|
994
|
+
*/
|
|
995
|
+
ldelim() {
|
|
996
|
+
const head = this.head;
|
|
997
|
+
const tail = this.tail;
|
|
998
|
+
const len = this.len;
|
|
999
|
+
this.reset().uint32(len);
|
|
1000
|
+
if (len !== 0) {
|
|
1001
|
+
this.tail.next = head.next;
|
|
1002
|
+
this.tail = tail;
|
|
1003
|
+
this.len += len;
|
|
1004
|
+
}
|
|
1005
|
+
return this;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Finishes the write operation
|
|
1009
|
+
*/
|
|
1010
|
+
finish() {
|
|
1011
|
+
let head = this.head.next;
|
|
1012
|
+
const buf = alloc$1(this.len);
|
|
1013
|
+
let pos = 0;
|
|
1014
|
+
while (head != null) {
|
|
1015
|
+
head.fn(head.val, buf, pos);
|
|
1016
|
+
pos += head.len;
|
|
1017
|
+
head = head.next;
|
|
1018
|
+
}
|
|
1019
|
+
return buf;
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
function writeByte(val, buf, pos) {
|
|
1023
|
+
buf[pos] = val & 255;
|
|
1024
|
+
}
|
|
1025
|
+
function writeVarint32(val, buf, pos) {
|
|
1026
|
+
while (val > 127) {
|
|
1027
|
+
buf[pos++] = val & 127 | 128;
|
|
1028
|
+
val >>>= 7;
|
|
1029
|
+
}
|
|
1030
|
+
buf[pos] = val;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Constructs a new varint writer operation instance.
|
|
1034
|
+
*
|
|
1035
|
+
* @classdesc Scheduled varint writer operation
|
|
1036
|
+
*/
|
|
1037
|
+
var VarintOp = class extends Op {
|
|
1038
|
+
next;
|
|
1039
|
+
constructor(len, val) {
|
|
1040
|
+
super(writeVarint32, len, val);
|
|
1041
|
+
this.next = void 0;
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
function writeVarint64(val, buf, pos) {
|
|
1045
|
+
while (val.hi !== 0) {
|
|
1046
|
+
buf[pos++] = val.lo & 127 | 128;
|
|
1047
|
+
val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
|
|
1048
|
+
val.hi >>>= 7;
|
|
1049
|
+
}
|
|
1050
|
+
while (val.lo > 127) {
|
|
1051
|
+
buf[pos++] = val.lo & 127 | 128;
|
|
1052
|
+
val.lo = val.lo >>> 7;
|
|
1053
|
+
}
|
|
1054
|
+
buf[pos++] = val.lo;
|
|
1055
|
+
}
|
|
1056
|
+
function writeFixed32(val, buf, pos) {
|
|
1057
|
+
buf[pos] = val & 255;
|
|
1058
|
+
buf[pos + 1] = val >>> 8 & 255;
|
|
1059
|
+
buf[pos + 2] = val >>> 16 & 255;
|
|
1060
|
+
buf[pos + 3] = val >>> 24;
|
|
1061
|
+
}
|
|
1062
|
+
function writeBytes(val, buf, pos) {
|
|
1063
|
+
buf.set(val, pos);
|
|
1064
|
+
}
|
|
1065
|
+
if (globalThis.Buffer != null) {
|
|
1066
|
+
Uint8ArrayWriter.prototype.bytes = function(value) {
|
|
1067
|
+
const len = value.length >>> 0;
|
|
1068
|
+
this.uint32(len);
|
|
1069
|
+
if (len > 0) this._push(writeBytesBuffer, len, value);
|
|
1070
|
+
return this;
|
|
1071
|
+
};
|
|
1072
|
+
Uint8ArrayWriter.prototype.string = function(value) {
|
|
1073
|
+
const len = globalThis.Buffer.byteLength(value);
|
|
1074
|
+
this.uint32(len);
|
|
1075
|
+
if (len > 0) this._push(writeStringBuffer, len, value);
|
|
1076
|
+
return this;
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function writeBytesBuffer(val, buf, pos) {
|
|
1080
|
+
buf.set(val, pos);
|
|
1081
|
+
}
|
|
1082
|
+
function writeStringBuffer(val, buf, pos) {
|
|
1083
|
+
if (val.length < 40) write(val, buf, pos);
|
|
1084
|
+
else if (buf.utf8Write != null) buf.utf8Write(val, pos);
|
|
1085
|
+
else buf.set(fromString(val), pos);
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Creates a new writer
|
|
1089
|
+
*/
|
|
1090
|
+
function createWriter() {
|
|
1091
|
+
return new Uint8ArrayWriter();
|
|
1092
|
+
}
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/encode.js
|
|
1095
|
+
function encodeMessage(message, codec) {
|
|
1096
|
+
const w = createWriter();
|
|
1097
|
+
codec.encode(message, w, { lengthDelimited: false });
|
|
1098
|
+
return w.finish();
|
|
1099
|
+
}
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/stream.js
|
|
1102
|
+
function* streamMessage(buf, codec, opts) {
|
|
1103
|
+
const reader = createReader(buf);
|
|
1104
|
+
yield* codec.stream(reader, void 0, ".", opts);
|
|
1105
|
+
}
|
|
1106
|
+
//#endregion
|
|
1107
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/codec.js
|
|
1108
|
+
const CODEC_TYPES = {
|
|
1109
|
+
VARINT: 0,
|
|
1110
|
+
BIT64: 1,
|
|
1111
|
+
LENGTH_DELIMITED: 2,
|
|
1112
|
+
START_GROUP: 3,
|
|
1113
|
+
END_GROUP: 4,
|
|
1114
|
+
BIT32: 5
|
|
1115
|
+
};
|
|
1116
|
+
function createCodec(name, type, encode, decode, stream) {
|
|
1117
|
+
return {
|
|
1118
|
+
name,
|
|
1119
|
+
type,
|
|
1120
|
+
encode,
|
|
1121
|
+
decode,
|
|
1122
|
+
stream
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/codecs/enum.js
|
|
1127
|
+
function enumeration(v) {
|
|
1128
|
+
function findValue(val) {
|
|
1129
|
+
if (v[val.toString()] == null) throw new Error("Invalid enum value");
|
|
1130
|
+
return v[val];
|
|
1131
|
+
}
|
|
1132
|
+
return createCodec("enum", CODEC_TYPES.VARINT, function enumEncode(val, writer) {
|
|
1133
|
+
const enumValue = findValue(val);
|
|
1134
|
+
writer.int32(enumValue);
|
|
1135
|
+
}, function enumDecode(reader) {
|
|
1136
|
+
return findValue(reader.int32());
|
|
1137
|
+
}, function* enumStream(reader, prefix) {});
|
|
1138
|
+
}
|
|
1139
|
+
//#endregion
|
|
1140
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/codecs/message.js
|
|
1141
|
+
function message(encode, decode, stream) {
|
|
1142
|
+
return createCodec("message", CODEC_TYPES.LENGTH_DELIMITED, encode, decode, stream);
|
|
1143
|
+
}
|
|
1144
|
+
//#endregion
|
|
1145
|
+
//#region node_modules/ipfs-unixfs/node_modules/protons-runtime/dist/src/index.js
|
|
1146
|
+
/**
|
|
1147
|
+
* Thrown when a repeated field has too many elements
|
|
1148
|
+
*/
|
|
1149
|
+
var MaxLengthError = class extends Error {
|
|
1150
|
+
/**
|
|
1151
|
+
* This will be removed in a future release
|
|
1152
|
+
*
|
|
1153
|
+
* @deprecated use the `.name` property instead
|
|
1154
|
+
*/
|
|
1155
|
+
code = "ERR_MAX_LENGTH";
|
|
1156
|
+
name = "MaxLengthError";
|
|
1157
|
+
};
|
|
1158
|
+
//#endregion
|
|
1159
|
+
//#region node_modules/ipfs-unixfs/dist/src/unixfs.js
|
|
1160
|
+
var UnixFS$1;
|
|
1161
|
+
(function(UnixFS) {
|
|
1162
|
+
(function(Type) {
|
|
1163
|
+
Type["RAW"] = "RAW";
|
|
1164
|
+
Type["DIRECTORY"] = "DIRECTORY";
|
|
1165
|
+
Type["FILE"] = "FILE";
|
|
1166
|
+
Type["METADATA"] = "METADATA";
|
|
1167
|
+
Type["SYMLINK"] = "SYMLINK";
|
|
1168
|
+
Type["HAMT_SHARD"] = "HAMT_SHARD";
|
|
1169
|
+
})(UnixFS.Type || (UnixFS.Type = {}));
|
|
1170
|
+
let __TypeValues;
|
|
1171
|
+
(function(__TypeValues) {
|
|
1172
|
+
__TypeValues[__TypeValues["RAW"] = 0] = "RAW";
|
|
1173
|
+
__TypeValues[__TypeValues["DIRECTORY"] = 1] = "DIRECTORY";
|
|
1174
|
+
__TypeValues[__TypeValues["FILE"] = 2] = "FILE";
|
|
1175
|
+
__TypeValues[__TypeValues["METADATA"] = 3] = "METADATA";
|
|
1176
|
+
__TypeValues[__TypeValues["SYMLINK"] = 4] = "SYMLINK";
|
|
1177
|
+
__TypeValues[__TypeValues["HAMT_SHARD"] = 5] = "HAMT_SHARD";
|
|
1178
|
+
})(__TypeValues || (__TypeValues = {}));
|
|
1179
|
+
(function(Type) {
|
|
1180
|
+
Type.codec = () => {
|
|
1181
|
+
return enumeration(__TypeValues);
|
|
1182
|
+
};
|
|
1183
|
+
})(UnixFS.Type || (UnixFS.Type = {}));
|
|
1184
|
+
let _codec;
|
|
1185
|
+
UnixFS.codec = () => {
|
|
1186
|
+
if (_codec == null) _codec = message((obj, w, opts = {}) => {
|
|
1187
|
+
if (opts.lengthDelimited !== false) w.fork();
|
|
1188
|
+
if (obj.type != null) {
|
|
1189
|
+
w.uint32(8);
|
|
1190
|
+
UnixFS.Type.codec().encode(obj.type, w);
|
|
1191
|
+
}
|
|
1192
|
+
if (obj.data != null) {
|
|
1193
|
+
w.uint32(18);
|
|
1194
|
+
w.bytes(obj.data);
|
|
1195
|
+
}
|
|
1196
|
+
if (obj.fileSize != null) {
|
|
1197
|
+
w.uint32(24);
|
|
1198
|
+
w.uint64(obj.fileSize);
|
|
1199
|
+
}
|
|
1200
|
+
if (obj.blockSizes != null && obj.blockSizes.length > 0) for (const value of obj.blockSizes) {
|
|
1201
|
+
w.uint32(32);
|
|
1202
|
+
w.uint64(value);
|
|
1203
|
+
}
|
|
1204
|
+
if (obj.hashType != null) {
|
|
1205
|
+
w.uint32(40);
|
|
1206
|
+
w.uint64(obj.hashType);
|
|
1207
|
+
}
|
|
1208
|
+
if (obj.fanOut != null) {
|
|
1209
|
+
w.uint32(48);
|
|
1210
|
+
w.uint64(obj.fanOut);
|
|
1211
|
+
}
|
|
1212
|
+
if (obj.mode != null) {
|
|
1213
|
+
w.uint32(56);
|
|
1214
|
+
w.uint32(obj.mode);
|
|
1215
|
+
}
|
|
1216
|
+
if (obj.mtime != null) {
|
|
1217
|
+
w.uint32(66);
|
|
1218
|
+
UnixTime.codec().encode(obj.mtime, w);
|
|
1219
|
+
}
|
|
1220
|
+
if (opts.lengthDelimited !== false) w.ldelim();
|
|
1221
|
+
}, (r, length, opts = {}) => {
|
|
1222
|
+
const obj = { blockSizes: [] };
|
|
1223
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1224
|
+
while (r.pos < end) {
|
|
1225
|
+
const tag = r.uint32();
|
|
1226
|
+
switch (tag >>> 3) {
|
|
1227
|
+
case 1:
|
|
1228
|
+
obj.type = UnixFS.Type.codec().decode(r);
|
|
1229
|
+
break;
|
|
1230
|
+
case 2:
|
|
1231
|
+
obj.data = r.bytes();
|
|
1232
|
+
break;
|
|
1233
|
+
case 3:
|
|
1234
|
+
obj.fileSize = r.uint64();
|
|
1235
|
+
break;
|
|
1236
|
+
case 4:
|
|
1237
|
+
if (opts.limits?.blockSizes != null && obj.blockSizes.length === opts.limits.blockSizes) throw new MaxLengthError("Decode error - repeated field \"blockSizes\" had too many elements");
|
|
1238
|
+
obj.blockSizes.push(r.uint64());
|
|
1239
|
+
break;
|
|
1240
|
+
case 5:
|
|
1241
|
+
obj.hashType = r.uint64();
|
|
1242
|
+
break;
|
|
1243
|
+
case 6:
|
|
1244
|
+
obj.fanOut = r.uint64();
|
|
1245
|
+
break;
|
|
1246
|
+
case 7:
|
|
1247
|
+
obj.mode = r.uint32();
|
|
1248
|
+
break;
|
|
1249
|
+
case 8:
|
|
1250
|
+
obj.mtime = UnixTime.codec().decode(r, r.uint32(), { limits: opts.limits?.mtime });
|
|
1251
|
+
break;
|
|
1252
|
+
default:
|
|
1253
|
+
r.skipType(tag & 7);
|
|
1254
|
+
break;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
return obj;
|
|
1258
|
+
}, function* (r, length, prefix, opts = {}) {
|
|
1259
|
+
const obj = { blockSizes: 0 };
|
|
1260
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1261
|
+
if (prefix !== ".") yield {
|
|
1262
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1263
|
+
type: "start",
|
|
1264
|
+
message: "UnixFS"
|
|
1265
|
+
};
|
|
1266
|
+
while (r.pos < end) {
|
|
1267
|
+
const tag = r.uint32();
|
|
1268
|
+
switch (tag >>> 3) {
|
|
1269
|
+
case 1:
|
|
1270
|
+
yield {
|
|
1271
|
+
field: `${prefix}type`,
|
|
1272
|
+
value: UnixFS.Type.codec().decode(r)
|
|
1273
|
+
};
|
|
1274
|
+
break;
|
|
1275
|
+
case 2:
|
|
1276
|
+
yield {
|
|
1277
|
+
field: `${prefix}data`,
|
|
1278
|
+
value: r.bytes()
|
|
1279
|
+
};
|
|
1280
|
+
break;
|
|
1281
|
+
case 3:
|
|
1282
|
+
yield {
|
|
1283
|
+
field: `${prefix}fileSize`,
|
|
1284
|
+
value: r.uint64()
|
|
1285
|
+
};
|
|
1286
|
+
break;
|
|
1287
|
+
case 4:
|
|
1288
|
+
if (opts.limits?.blockSizes != null && obj.blockSizes === opts.limits.blockSizes) throw new MaxLengthError("Streaming decode error - repeated field \"blockSizes\" had too many elements");
|
|
1289
|
+
yield {
|
|
1290
|
+
field: `${prefix}blockSizes[]`,
|
|
1291
|
+
index: obj.blockSizes,
|
|
1292
|
+
value: r.uint64()
|
|
1293
|
+
};
|
|
1294
|
+
obj.blockSizes++;
|
|
1295
|
+
break;
|
|
1296
|
+
case 5:
|
|
1297
|
+
yield {
|
|
1298
|
+
field: `${prefix}hashType`,
|
|
1299
|
+
value: r.uint64()
|
|
1300
|
+
};
|
|
1301
|
+
break;
|
|
1302
|
+
case 6:
|
|
1303
|
+
yield {
|
|
1304
|
+
field: `${prefix}fanOut`,
|
|
1305
|
+
value: r.uint64()
|
|
1306
|
+
};
|
|
1307
|
+
break;
|
|
1308
|
+
case 7:
|
|
1309
|
+
yield {
|
|
1310
|
+
field: `${prefix}mode`,
|
|
1311
|
+
value: r.uint32()
|
|
1312
|
+
};
|
|
1313
|
+
break;
|
|
1314
|
+
case 8:
|
|
1315
|
+
yield* UnixTime.codec().stream(r, r.uint32(), `${prefix}mtime.`, { limits: opts.limits?.mtime });
|
|
1316
|
+
break;
|
|
1317
|
+
default:
|
|
1318
|
+
r.skipType(tag & 7);
|
|
1319
|
+
break;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
if (prefix !== ".") yield {
|
|
1323
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1324
|
+
type: "end",
|
|
1325
|
+
message: "UnixFS"
|
|
1326
|
+
};
|
|
1327
|
+
});
|
|
1328
|
+
return _codec;
|
|
1329
|
+
};
|
|
1330
|
+
function encode(obj) {
|
|
1331
|
+
return encodeMessage(obj, UnixFS.codec());
|
|
1332
|
+
}
|
|
1333
|
+
UnixFS.encode = encode;
|
|
1334
|
+
function decode(buf, opts) {
|
|
1335
|
+
return decodeMessage(buf, UnixFS.codec(), opts);
|
|
1336
|
+
}
|
|
1337
|
+
UnixFS.decode = decode;
|
|
1338
|
+
function stream(buf, opts) {
|
|
1339
|
+
return streamMessage(buf, UnixFS.codec(), opts);
|
|
1340
|
+
}
|
|
1341
|
+
UnixFS.stream = stream;
|
|
1342
|
+
})(UnixFS$1 || (UnixFS$1 = {}));
|
|
1343
|
+
var UnixTime;
|
|
1344
|
+
(function(UnixTime) {
|
|
1345
|
+
let _codec;
|
|
1346
|
+
UnixTime.codec = () => {
|
|
1347
|
+
if (_codec == null) _codec = message((obj, w, opts = {}) => {
|
|
1348
|
+
if (opts.lengthDelimited !== false) w.fork();
|
|
1349
|
+
if (obj.seconds != null) {
|
|
1350
|
+
w.uint32(8);
|
|
1351
|
+
w.int64(obj.seconds);
|
|
1352
|
+
}
|
|
1353
|
+
if (obj.fractionalNanoseconds != null) {
|
|
1354
|
+
w.uint32(21);
|
|
1355
|
+
w.fixed32(obj.fractionalNanoseconds);
|
|
1356
|
+
}
|
|
1357
|
+
if (opts.lengthDelimited !== false) w.ldelim();
|
|
1358
|
+
}, (r, length) => {
|
|
1359
|
+
const obj = {};
|
|
1360
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1361
|
+
while (r.pos < end) {
|
|
1362
|
+
const tag = r.uint32();
|
|
1363
|
+
switch (tag >>> 3) {
|
|
1364
|
+
case 1:
|
|
1365
|
+
obj.seconds = r.int64();
|
|
1366
|
+
break;
|
|
1367
|
+
case 2:
|
|
1368
|
+
obj.fractionalNanoseconds = r.fixed32();
|
|
1369
|
+
break;
|
|
1370
|
+
default:
|
|
1371
|
+
r.skipType(tag & 7);
|
|
1372
|
+
break;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return obj;
|
|
1376
|
+
}, function* (r, length, prefix) {
|
|
1377
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1378
|
+
if (prefix !== ".") yield {
|
|
1379
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1380
|
+
type: "start",
|
|
1381
|
+
message: "UnixTime"
|
|
1382
|
+
};
|
|
1383
|
+
while (r.pos < end) {
|
|
1384
|
+
const tag = r.uint32();
|
|
1385
|
+
switch (tag >>> 3) {
|
|
1386
|
+
case 1:
|
|
1387
|
+
yield {
|
|
1388
|
+
field: `${prefix}seconds`,
|
|
1389
|
+
value: r.int64()
|
|
1390
|
+
};
|
|
1391
|
+
break;
|
|
1392
|
+
case 2:
|
|
1393
|
+
yield {
|
|
1394
|
+
field: `${prefix}fractionalNanoseconds`,
|
|
1395
|
+
value: r.fixed32()
|
|
1396
|
+
};
|
|
1397
|
+
break;
|
|
1398
|
+
default:
|
|
1399
|
+
r.skipType(tag & 7);
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
if (prefix !== ".") yield {
|
|
1404
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1405
|
+
type: "end",
|
|
1406
|
+
message: "UnixTime"
|
|
1407
|
+
};
|
|
1408
|
+
});
|
|
1409
|
+
return _codec;
|
|
1410
|
+
};
|
|
1411
|
+
function encode(obj) {
|
|
1412
|
+
return encodeMessage(obj, UnixTime.codec());
|
|
1413
|
+
}
|
|
1414
|
+
UnixTime.encode = encode;
|
|
1415
|
+
function decode(buf, opts) {
|
|
1416
|
+
return decodeMessage(buf, UnixTime.codec(), opts);
|
|
1417
|
+
}
|
|
1418
|
+
UnixTime.decode = decode;
|
|
1419
|
+
function stream(buf, opts) {
|
|
1420
|
+
return streamMessage(buf, UnixTime.codec(), opts);
|
|
1421
|
+
}
|
|
1422
|
+
UnixTime.stream = stream;
|
|
1423
|
+
})(UnixTime || (UnixTime = {}));
|
|
1424
|
+
var Metadata;
|
|
1425
|
+
(function(Metadata) {
|
|
1426
|
+
let _codec;
|
|
1427
|
+
Metadata.codec = () => {
|
|
1428
|
+
if (_codec == null) _codec = message((obj, w, opts = {}) => {
|
|
1429
|
+
if (opts.lengthDelimited !== false) w.fork();
|
|
1430
|
+
if (obj.mimeType != null) {
|
|
1431
|
+
w.uint32(10);
|
|
1432
|
+
w.string(obj.mimeType);
|
|
1433
|
+
}
|
|
1434
|
+
if (opts.lengthDelimited !== false) w.ldelim();
|
|
1435
|
+
}, (r, length) => {
|
|
1436
|
+
const obj = {};
|
|
1437
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1438
|
+
while (r.pos < end) {
|
|
1439
|
+
const tag = r.uint32();
|
|
1440
|
+
switch (tag >>> 3) {
|
|
1441
|
+
case 1:
|
|
1442
|
+
obj.mimeType = r.string();
|
|
1443
|
+
break;
|
|
1444
|
+
default:
|
|
1445
|
+
r.skipType(tag & 7);
|
|
1446
|
+
break;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
return obj;
|
|
1450
|
+
}, function* (r, length, prefix) {
|
|
1451
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1452
|
+
if (prefix !== ".") yield {
|
|
1453
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1454
|
+
type: "start",
|
|
1455
|
+
message: "Metadata"
|
|
1456
|
+
};
|
|
1457
|
+
while (r.pos < end) {
|
|
1458
|
+
const tag = r.uint32();
|
|
1459
|
+
switch (tag >>> 3) {
|
|
1460
|
+
case 1:
|
|
1461
|
+
yield {
|
|
1462
|
+
field: `${prefix}mimeType`,
|
|
1463
|
+
value: r.string()
|
|
1464
|
+
};
|
|
1465
|
+
break;
|
|
1466
|
+
default:
|
|
1467
|
+
r.skipType(tag & 7);
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (prefix !== ".") yield {
|
|
1472
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1473
|
+
type: "end",
|
|
1474
|
+
message: "Metadata"
|
|
1475
|
+
};
|
|
1476
|
+
});
|
|
1477
|
+
return _codec;
|
|
1478
|
+
};
|
|
1479
|
+
function encode(obj) {
|
|
1480
|
+
return encodeMessage(obj, Metadata.codec());
|
|
1481
|
+
}
|
|
1482
|
+
Metadata.encode = encode;
|
|
1483
|
+
function decode(buf, opts) {
|
|
1484
|
+
return decodeMessage(buf, Metadata.codec(), opts);
|
|
1485
|
+
}
|
|
1486
|
+
Metadata.decode = decode;
|
|
1487
|
+
function stream(buf, opts) {
|
|
1488
|
+
return streamMessage(buf, Metadata.codec(), opts);
|
|
1489
|
+
}
|
|
1490
|
+
Metadata.stream = stream;
|
|
1491
|
+
})(Metadata || (Metadata = {}));
|
|
1492
|
+
var Link;
|
|
1493
|
+
(function(Link) {
|
|
1494
|
+
let _codec;
|
|
1495
|
+
Link.codec = () => {
|
|
1496
|
+
if (_codec == null) _codec = message((obj, w, opts = {}) => {
|
|
1497
|
+
if (opts.lengthDelimited !== false) w.fork();
|
|
1498
|
+
if (obj.hash != null) {
|
|
1499
|
+
w.uint32(10);
|
|
1500
|
+
w.bytes(obj.hash);
|
|
1501
|
+
}
|
|
1502
|
+
if (obj.name != null) {
|
|
1503
|
+
w.uint32(18);
|
|
1504
|
+
w.string(obj.name);
|
|
1505
|
+
}
|
|
1506
|
+
if (obj.tSize != null) {
|
|
1507
|
+
w.uint32(24);
|
|
1508
|
+
w.uint64(obj.tSize);
|
|
1509
|
+
}
|
|
1510
|
+
if (opts.lengthDelimited !== false) w.ldelim();
|
|
1511
|
+
}, (r, length) => {
|
|
1512
|
+
const obj = {};
|
|
1513
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1514
|
+
while (r.pos < end) {
|
|
1515
|
+
const tag = r.uint32();
|
|
1516
|
+
switch (tag >>> 3) {
|
|
1517
|
+
case 1:
|
|
1518
|
+
obj.hash = r.bytes();
|
|
1519
|
+
break;
|
|
1520
|
+
case 2:
|
|
1521
|
+
obj.name = r.string();
|
|
1522
|
+
break;
|
|
1523
|
+
case 3:
|
|
1524
|
+
obj.tSize = r.uint64();
|
|
1525
|
+
break;
|
|
1526
|
+
default:
|
|
1527
|
+
r.skipType(tag & 7);
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return obj;
|
|
1532
|
+
}, function* (r, length, prefix) {
|
|
1533
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1534
|
+
if (prefix !== ".") yield {
|
|
1535
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1536
|
+
type: "start",
|
|
1537
|
+
message: "Link"
|
|
1538
|
+
};
|
|
1539
|
+
while (r.pos < end) {
|
|
1540
|
+
const tag = r.uint32();
|
|
1541
|
+
switch (tag >>> 3) {
|
|
1542
|
+
case 1:
|
|
1543
|
+
yield {
|
|
1544
|
+
field: `${prefix}hash`,
|
|
1545
|
+
value: r.bytes()
|
|
1546
|
+
};
|
|
1547
|
+
break;
|
|
1548
|
+
case 2:
|
|
1549
|
+
yield {
|
|
1550
|
+
field: `${prefix}name`,
|
|
1551
|
+
value: r.string()
|
|
1552
|
+
};
|
|
1553
|
+
break;
|
|
1554
|
+
case 3:
|
|
1555
|
+
yield {
|
|
1556
|
+
field: `${prefix}tSize`,
|
|
1557
|
+
value: r.uint64()
|
|
1558
|
+
};
|
|
1559
|
+
break;
|
|
1560
|
+
default:
|
|
1561
|
+
r.skipType(tag & 7);
|
|
1562
|
+
break;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (prefix !== ".") yield {
|
|
1566
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1567
|
+
type: "end",
|
|
1568
|
+
message: "Link"
|
|
1569
|
+
};
|
|
1570
|
+
});
|
|
1571
|
+
return _codec;
|
|
1572
|
+
};
|
|
1573
|
+
function encode(obj) {
|
|
1574
|
+
return encodeMessage(obj, Link.codec());
|
|
1575
|
+
}
|
|
1576
|
+
Link.encode = encode;
|
|
1577
|
+
function decode(buf, opts) {
|
|
1578
|
+
return decodeMessage(buf, Link.codec(), opts);
|
|
1579
|
+
}
|
|
1580
|
+
Link.decode = decode;
|
|
1581
|
+
function stream(buf, opts) {
|
|
1582
|
+
return streamMessage(buf, Link.codec(), opts);
|
|
1583
|
+
}
|
|
1584
|
+
Link.stream = stream;
|
|
1585
|
+
})(Link || (Link = {}));
|
|
1586
|
+
var Node;
|
|
1587
|
+
(function(Node) {
|
|
1588
|
+
let _codec;
|
|
1589
|
+
Node.codec = () => {
|
|
1590
|
+
if (_codec == null) _codec = message((obj, w, opts = {}) => {
|
|
1591
|
+
if (opts.lengthDelimited !== false) w.fork();
|
|
1592
|
+
if (obj.data != null) {
|
|
1593
|
+
w.uint32(10);
|
|
1594
|
+
UnixFS$1.codec().encode(obj.data, w);
|
|
1595
|
+
}
|
|
1596
|
+
if (obj.links != null && obj.links.length > 0) for (const value of obj.links) {
|
|
1597
|
+
w.uint32(18);
|
|
1598
|
+
Link.codec().encode(value, w);
|
|
1599
|
+
}
|
|
1600
|
+
if (opts.lengthDelimited !== false) w.ldelim();
|
|
1601
|
+
}, (r, length, opts = {}) => {
|
|
1602
|
+
const obj = { links: [] };
|
|
1603
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1604
|
+
while (r.pos < end) {
|
|
1605
|
+
const tag = r.uint32();
|
|
1606
|
+
switch (tag >>> 3) {
|
|
1607
|
+
case 1:
|
|
1608
|
+
obj.data = UnixFS$1.codec().decode(r, r.uint32(), { limits: opts.limits?.data });
|
|
1609
|
+
break;
|
|
1610
|
+
case 2:
|
|
1611
|
+
if (opts.limits?.links != null && obj.links.length === opts.limits.links) throw new MaxLengthError("Decode error - repeated field \"links\" had too many elements");
|
|
1612
|
+
obj.links.push(Link.codec().decode(r, r.uint32(), { limits: opts.limits?.links$ }));
|
|
1613
|
+
break;
|
|
1614
|
+
default:
|
|
1615
|
+
r.skipType(tag & 7);
|
|
1616
|
+
break;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
return obj;
|
|
1620
|
+
}, function* (r, length, prefix, opts = {}) {
|
|
1621
|
+
const obj = { links: 0 };
|
|
1622
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1623
|
+
if (prefix !== ".") yield {
|
|
1624
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1625
|
+
type: "start",
|
|
1626
|
+
message: "Node"
|
|
1627
|
+
};
|
|
1628
|
+
while (r.pos < end) {
|
|
1629
|
+
const tag = r.uint32();
|
|
1630
|
+
switch (tag >>> 3) {
|
|
1631
|
+
case 1:
|
|
1632
|
+
yield* UnixFS$1.codec().stream(r, r.uint32(), `${prefix}data.`, { limits: opts.limits?.data });
|
|
1633
|
+
break;
|
|
1634
|
+
case 2:
|
|
1635
|
+
if (opts.limits?.links != null && obj.links === opts.limits.links) throw new MaxLengthError("Streaming decode error - repeated field \"links\" had too many elements");
|
|
1636
|
+
for (const evt of Link.codec().stream(r, r.uint32(), `${prefix}links[].`, { limits: opts.limits?.links$ })) yield {
|
|
1637
|
+
...evt,
|
|
1638
|
+
index: obj.links
|
|
1639
|
+
};
|
|
1640
|
+
obj.links++;
|
|
1641
|
+
break;
|
|
1642
|
+
default:
|
|
1643
|
+
r.skipType(tag & 7);
|
|
1644
|
+
break;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
if (prefix !== ".") yield {
|
|
1648
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1649
|
+
type: "end",
|
|
1650
|
+
message: "Node"
|
|
1651
|
+
};
|
|
1652
|
+
});
|
|
1653
|
+
return _codec;
|
|
1654
|
+
};
|
|
1655
|
+
function encode(obj) {
|
|
1656
|
+
return encodeMessage(obj, Node.codec());
|
|
1657
|
+
}
|
|
1658
|
+
Node.encode = encode;
|
|
1659
|
+
function decode(buf, opts) {
|
|
1660
|
+
return decodeMessage(buf, Node.codec(), opts);
|
|
1661
|
+
}
|
|
1662
|
+
Node.decode = decode;
|
|
1663
|
+
function stream(buf, opts) {
|
|
1664
|
+
return streamMessage(buf, Node.codec(), opts);
|
|
1665
|
+
}
|
|
1666
|
+
Node.stream = stream;
|
|
1667
|
+
})(Node || (Node = {}));
|
|
1668
|
+
var LegacyNode;
|
|
1669
|
+
(function(LegacyNode) {
|
|
1670
|
+
let _codec;
|
|
1671
|
+
LegacyNode.codec = () => {
|
|
1672
|
+
if (_codec == null) _codec = message((obj, w, opts = {}) => {
|
|
1673
|
+
if (opts.lengthDelimited !== false) w.fork();
|
|
1674
|
+
if (obj.links != null && obj.links.length > 0) for (const value of obj.links) {
|
|
1675
|
+
w.uint32(18);
|
|
1676
|
+
Link.codec().encode(value, w);
|
|
1677
|
+
}
|
|
1678
|
+
if (obj.data != null) {
|
|
1679
|
+
w.uint32(10);
|
|
1680
|
+
UnixFS$1.codec().encode(obj.data, w);
|
|
1681
|
+
}
|
|
1682
|
+
if (opts.lengthDelimited !== false) w.ldelim();
|
|
1683
|
+
}, (r, length, opts = {}) => {
|
|
1684
|
+
const obj = { links: [] };
|
|
1685
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1686
|
+
while (r.pos < end) {
|
|
1687
|
+
const tag = r.uint32();
|
|
1688
|
+
switch (tag >>> 3) {
|
|
1689
|
+
case 2:
|
|
1690
|
+
if (opts.limits?.links != null && obj.links.length === opts.limits.links) throw new MaxLengthError("Decode error - repeated field \"links\" had too many elements");
|
|
1691
|
+
obj.links.push(Link.codec().decode(r, r.uint32(), { limits: opts.limits?.links$ }));
|
|
1692
|
+
break;
|
|
1693
|
+
case 1:
|
|
1694
|
+
obj.data = UnixFS$1.codec().decode(r, r.uint32(), { limits: opts.limits?.data });
|
|
1695
|
+
break;
|
|
1696
|
+
default:
|
|
1697
|
+
r.skipType(tag & 7);
|
|
1698
|
+
break;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
return obj;
|
|
1702
|
+
}, function* (r, length, prefix, opts = {}) {
|
|
1703
|
+
const obj = { links: 0 };
|
|
1704
|
+
const end = length == null ? r.len : r.pos + length;
|
|
1705
|
+
if (prefix !== ".") yield {
|
|
1706
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1707
|
+
type: "start",
|
|
1708
|
+
message: "LegacyNode"
|
|
1709
|
+
};
|
|
1710
|
+
while (r.pos < end) {
|
|
1711
|
+
const tag = r.uint32();
|
|
1712
|
+
switch (tag >>> 3) {
|
|
1713
|
+
case 2:
|
|
1714
|
+
if (opts.limits?.links != null && obj.links === opts.limits.links) throw new MaxLengthError("Streaming decode error - repeated field \"links\" had too many elements");
|
|
1715
|
+
for (const evt of Link.codec().stream(r, r.uint32(), `${prefix}links[].`, { limits: opts.limits?.links$ })) yield {
|
|
1716
|
+
...evt,
|
|
1717
|
+
index: obj.links
|
|
1718
|
+
};
|
|
1719
|
+
obj.links++;
|
|
1720
|
+
break;
|
|
1721
|
+
case 1:
|
|
1722
|
+
yield* UnixFS$1.codec().stream(r, r.uint32(), `${prefix}data.`, { limits: opts.limits?.data });
|
|
1723
|
+
break;
|
|
1724
|
+
default:
|
|
1725
|
+
r.skipType(tag & 7);
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
if (prefix !== ".") yield {
|
|
1730
|
+
field: prefix.endsWith(".") ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
1731
|
+
type: "end",
|
|
1732
|
+
message: "LegacyNode"
|
|
1733
|
+
};
|
|
1734
|
+
});
|
|
1735
|
+
return _codec;
|
|
1736
|
+
};
|
|
1737
|
+
function encode(obj) {
|
|
1738
|
+
return encodeMessage(obj, LegacyNode.codec());
|
|
1739
|
+
}
|
|
1740
|
+
LegacyNode.encode = encode;
|
|
1741
|
+
function decode(buf, opts) {
|
|
1742
|
+
return decodeMessage(buf, LegacyNode.codec(), opts);
|
|
1743
|
+
}
|
|
1744
|
+
LegacyNode.decode = decode;
|
|
1745
|
+
function stream(buf, opts) {
|
|
1746
|
+
return streamMessage(buf, LegacyNode.codec(), opts);
|
|
1747
|
+
}
|
|
1748
|
+
LegacyNode.stream = stream;
|
|
1749
|
+
})(LegacyNode || (LegacyNode = {}));
|
|
1750
|
+
//#endregion
|
|
1751
|
+
//#region node_modules/ipfs-unixfs/dist/src/index.js
|
|
1752
|
+
/**
|
|
1753
|
+
* @packageDocumentation
|
|
1754
|
+
*
|
|
1755
|
+
* This module contains the protobuf definition of the UnixFS data structure found at the root of all UnixFS DAGs.
|
|
1756
|
+
*
|
|
1757
|
+
* The UnixFS spec can be found in the [ipfs/specs repository](http://github.com/ipfs/specs)
|
|
1758
|
+
*
|
|
1759
|
+
* @example Create a file composed of several blocks
|
|
1760
|
+
*
|
|
1761
|
+
* ```TypeScript
|
|
1762
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1763
|
+
*
|
|
1764
|
+
* const data = new UnixFS({ type: 'file' })
|
|
1765
|
+
* data.addBlockSize(256n) // add the size of each block
|
|
1766
|
+
* data.addBlockSize(256n)
|
|
1767
|
+
* // ...
|
|
1768
|
+
* ```
|
|
1769
|
+
*
|
|
1770
|
+
* @example Create a directory that contains several files
|
|
1771
|
+
*
|
|
1772
|
+
* Creating a directory that contains several files is achieve by creating a unixfs element that identifies a MerkleDAG node as a directory. The links of that MerkleDAG node are the files that are contained in this directory.
|
|
1773
|
+
*
|
|
1774
|
+
* ```TypeScript
|
|
1775
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1776
|
+
*
|
|
1777
|
+
* const data = new UnixFS({ type: 'directory' })
|
|
1778
|
+
* ```
|
|
1779
|
+
*
|
|
1780
|
+
* @example Create an unixfs Data element
|
|
1781
|
+
*
|
|
1782
|
+
* ```TypeScript
|
|
1783
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1784
|
+
*
|
|
1785
|
+
* const data = new UnixFS({
|
|
1786
|
+
* // ...options
|
|
1787
|
+
* })
|
|
1788
|
+
* ```
|
|
1789
|
+
*
|
|
1790
|
+
* `options` is an optional object argument that might include the following keys:
|
|
1791
|
+
*
|
|
1792
|
+
* - type (string, default `file`): The type of UnixFS entry. Can be:
|
|
1793
|
+
* - `raw`
|
|
1794
|
+
* - `directory`
|
|
1795
|
+
* - `file`
|
|
1796
|
+
* - `metadata`
|
|
1797
|
+
* - `symlink`
|
|
1798
|
+
* - `hamt-sharded-directory`
|
|
1799
|
+
* - data (Uint8Array): The optional data field for this node
|
|
1800
|
+
* - blockSizes (Array, default: `[]`): If this is a `file` node that is made up of multiple blocks, `blockSizes` is a list numbers that represent the size of the file chunks stored in each child node. It is used to calculate the total file size.
|
|
1801
|
+
* - mode (Number, default `0644` for files, `0755` for directories/hamt-sharded-directories) file mode
|
|
1802
|
+
* - mtime (`Date`, `{ secs, nsecs }`, `{ Seconds, FractionalNanoseconds }`, `[ secs, nsecs ]`): The modification time of this node
|
|
1803
|
+
*
|
|
1804
|
+
* @example Add and remove a block size to the block size list
|
|
1805
|
+
*
|
|
1806
|
+
* ```TypeScript
|
|
1807
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1808
|
+
*
|
|
1809
|
+
* const data = new UnixFS({ type: 'file' })
|
|
1810
|
+
* const sizeInBytes = 100n
|
|
1811
|
+
* data.addBlockSize(sizeInBytes)
|
|
1812
|
+
* ```
|
|
1813
|
+
*
|
|
1814
|
+
* ```TypeScript
|
|
1815
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1816
|
+
*
|
|
1817
|
+
* const data = new UnixFS({ type: 'file' })
|
|
1818
|
+
*
|
|
1819
|
+
* const index = 0
|
|
1820
|
+
* data.removeBlockSize(index)
|
|
1821
|
+
* ```
|
|
1822
|
+
*
|
|
1823
|
+
* @example Get total fileSize
|
|
1824
|
+
*
|
|
1825
|
+
* ```TypeScript
|
|
1826
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1827
|
+
*
|
|
1828
|
+
* const data = new UnixFS({ type: 'file' })
|
|
1829
|
+
* data.fileSize() // => size in bytes
|
|
1830
|
+
* ```
|
|
1831
|
+
*
|
|
1832
|
+
* @example Marshal and unmarshal
|
|
1833
|
+
*
|
|
1834
|
+
* ```TypeScript
|
|
1835
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1836
|
+
*
|
|
1837
|
+
* const data = new UnixFS({ type: 'file' })
|
|
1838
|
+
* const marshaled = data.marshal()
|
|
1839
|
+
* const unmarshaled = UnixFS.unmarshal(marshaled)
|
|
1840
|
+
* ```
|
|
1841
|
+
*
|
|
1842
|
+
* @example Is this UnixFS entry a directory?
|
|
1843
|
+
*
|
|
1844
|
+
* ```TypeScript
|
|
1845
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1846
|
+
*
|
|
1847
|
+
* const dir = new UnixFS({ type: 'directory' })
|
|
1848
|
+
* dir.isDirectory() // true
|
|
1849
|
+
*
|
|
1850
|
+
* const file = new UnixFS({ type: 'file' })
|
|
1851
|
+
* file.isDirectory() // false
|
|
1852
|
+
* ```
|
|
1853
|
+
*
|
|
1854
|
+
* @example Has an mtime been set?
|
|
1855
|
+
*
|
|
1856
|
+
* If no modification time has been set, no `mtime` property will be present on the `Data` instance:
|
|
1857
|
+
*
|
|
1858
|
+
* ```TypeScript
|
|
1859
|
+
* import { UnixFS } from 'ipfs-unixfs'
|
|
1860
|
+
*
|
|
1861
|
+
* const file = new UnixFS({ type: 'file' })
|
|
1862
|
+
* file.mtime // undefined
|
|
1863
|
+
*
|
|
1864
|
+
* Object.prototype.hasOwnProperty.call(file, 'mtime') // false
|
|
1865
|
+
*
|
|
1866
|
+
* const dir = new UnixFS({ type: 'directory', mtime: { secs: 5n } })
|
|
1867
|
+
* dir.mtime // { secs: Number, nsecs: Number }
|
|
1868
|
+
* ```
|
|
1869
|
+
*/
|
|
1870
|
+
const types = {
|
|
1871
|
+
RAW: "raw",
|
|
1872
|
+
DIRECTORY: "directory",
|
|
1873
|
+
FILE: "file",
|
|
1874
|
+
METADATA: "metadata",
|
|
1875
|
+
SYMLINK: "symlink",
|
|
1876
|
+
HAMT_SHARD: "hamt-sharded-directory"
|
|
1877
|
+
};
|
|
1878
|
+
const dirTypes = ["directory", "hamt-sharded-directory"];
|
|
1879
|
+
const DEFAULT_FILE_MODE = parseInt("0644", 8);
|
|
1880
|
+
const DEFAULT_DIRECTORY_MODE = parseInt("0755", 8);
|
|
1881
|
+
var UnixFS = class UnixFS {
|
|
1882
|
+
/**
|
|
1883
|
+
* Decode from protobuf https://github.com/ipfs/specs/blob/master/UNIXFS.md
|
|
1884
|
+
*/
|
|
1885
|
+
static unmarshal(marshaled) {
|
|
1886
|
+
const message = UnixFS$1.decode(marshaled);
|
|
1887
|
+
const data = new UnixFS({
|
|
1888
|
+
type: types[message.type != null ? message.type.toString() : "FILE"],
|
|
1889
|
+
data: message.data,
|
|
1890
|
+
blockSizes: message.blockSizes,
|
|
1891
|
+
mode: message.mode,
|
|
1892
|
+
mtime: message.mtime != null ? {
|
|
1893
|
+
secs: message.mtime.seconds ?? 0n,
|
|
1894
|
+
nsecs: message.mtime.fractionalNanoseconds
|
|
1895
|
+
} : void 0,
|
|
1896
|
+
fanout: message.fanOut
|
|
1897
|
+
});
|
|
1898
|
+
data._originalMode = message.mode ?? 0;
|
|
1899
|
+
return data;
|
|
1900
|
+
}
|
|
1901
|
+
type;
|
|
1902
|
+
data;
|
|
1903
|
+
blockSizes;
|
|
1904
|
+
hashType;
|
|
1905
|
+
fanout;
|
|
1906
|
+
mtime;
|
|
1907
|
+
_mode;
|
|
1908
|
+
_originalMode;
|
|
1909
|
+
constructor(options = { type: "file" }) {
|
|
1910
|
+
const { type, data, blockSizes, hashType, fanout, mtime, mode } = options;
|
|
1911
|
+
if (type != null && !Object.values(types).includes(type)) throw new InvalidTypeError("Type: " + type + " is not valid");
|
|
1912
|
+
this.type = type ?? "file";
|
|
1913
|
+
this.hashType = hashType;
|
|
1914
|
+
this.fanout = fanout;
|
|
1915
|
+
this.blockSizes = blockSizes ?? [];
|
|
1916
|
+
this._originalMode = 0;
|
|
1917
|
+
this.mode = mode;
|
|
1918
|
+
this.mtime = mtime;
|
|
1919
|
+
if (data != null) this.data = withArrayBuffer(data);
|
|
1920
|
+
}
|
|
1921
|
+
set mode(mode) {
|
|
1922
|
+
if (mode == null) this._mode = this.isDirectory() ? DEFAULT_DIRECTORY_MODE : DEFAULT_FILE_MODE;
|
|
1923
|
+
else this._mode = mode & 4095;
|
|
1924
|
+
}
|
|
1925
|
+
get mode() {
|
|
1926
|
+
return this._mode;
|
|
1927
|
+
}
|
|
1928
|
+
isDirectory() {
|
|
1929
|
+
return dirTypes.includes(this.type);
|
|
1930
|
+
}
|
|
1931
|
+
addBlockSize(size) {
|
|
1932
|
+
this.blockSizes.push(size);
|
|
1933
|
+
}
|
|
1934
|
+
removeBlockSize(index) {
|
|
1935
|
+
this.blockSizes.splice(index, 1);
|
|
1936
|
+
}
|
|
1937
|
+
/**
|
|
1938
|
+
* Returns `0n` for directories or `data.length + sum(blockSizes)` for everything else
|
|
1939
|
+
*/
|
|
1940
|
+
fileSize() {
|
|
1941
|
+
if (this.isDirectory()) return 0n;
|
|
1942
|
+
let sum = 0n;
|
|
1943
|
+
this.blockSizes.forEach((size) => {
|
|
1944
|
+
sum += size;
|
|
1945
|
+
});
|
|
1946
|
+
if (this.data != null) sum += BigInt(this.data.length);
|
|
1947
|
+
return sum;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* encode to protobuf Uint8Array
|
|
1951
|
+
*/
|
|
1952
|
+
marshal() {
|
|
1953
|
+
let type;
|
|
1954
|
+
switch (this.type) {
|
|
1955
|
+
case "raw":
|
|
1956
|
+
type = UnixFS$1.Type.RAW;
|
|
1957
|
+
break;
|
|
1958
|
+
case "directory":
|
|
1959
|
+
type = UnixFS$1.Type.DIRECTORY;
|
|
1960
|
+
break;
|
|
1961
|
+
case "file":
|
|
1962
|
+
type = UnixFS$1.Type.FILE;
|
|
1963
|
+
break;
|
|
1964
|
+
case "metadata":
|
|
1965
|
+
type = UnixFS$1.Type.METADATA;
|
|
1966
|
+
break;
|
|
1967
|
+
case "symlink":
|
|
1968
|
+
type = UnixFS$1.Type.SYMLINK;
|
|
1969
|
+
break;
|
|
1970
|
+
case "hamt-sharded-directory":
|
|
1971
|
+
type = UnixFS$1.Type.HAMT_SHARD;
|
|
1972
|
+
break;
|
|
1973
|
+
default: throw new InvalidTypeError(`Type: ${type} is not valid`);
|
|
1974
|
+
}
|
|
1975
|
+
let data = this.data;
|
|
1976
|
+
if (this.data == null || this.data.length === 0) data = void 0;
|
|
1977
|
+
let mode;
|
|
1978
|
+
if (this.mode != null) {
|
|
1979
|
+
mode = this._originalMode & 4294963200 | (this.mode ?? 0);
|
|
1980
|
+
if (mode === DEFAULT_FILE_MODE && !this.isDirectory()) mode = void 0;
|
|
1981
|
+
if (mode === DEFAULT_DIRECTORY_MODE && this.isDirectory()) mode = void 0;
|
|
1982
|
+
}
|
|
1983
|
+
let mtime;
|
|
1984
|
+
if (this.mtime != null) mtime = {
|
|
1985
|
+
seconds: this.mtime.secs,
|
|
1986
|
+
fractionalNanoseconds: this.mtime.nsecs
|
|
1987
|
+
};
|
|
1988
|
+
return UnixFS$1.encode({
|
|
1989
|
+
type,
|
|
1990
|
+
data,
|
|
1991
|
+
fileSize: this.type === "file" || this.type === "raw" ? this.fileSize() : void 0,
|
|
1992
|
+
blockSizes: this.blockSizes,
|
|
1993
|
+
hashType: this.hashType,
|
|
1994
|
+
fanOut: this.fanout,
|
|
1995
|
+
mode,
|
|
1996
|
+
mtime
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
//#endregion
|
|
2001
|
+
export { Node as a, Metadata as i, LegacyNode as n, UnixTime as o, Link as r, InvalidTypeError as s, UnixFS as t };
|