@wovin/core 0.1.35 → 0.2.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.
Files changed (212) hide show
  1. package/README.md +0 -12
  2. package/dist/applog/applog-helpers.d.ts +12 -12
  3. package/dist/applog/applog-helpers.d.ts.map +1 -1
  4. package/dist/applog/applog-utils.d.ts +25 -6
  5. package/dist/applog/applog-utils.d.ts.map +1 -1
  6. package/dist/applog/datom-types.d.ts +4 -5
  7. package/dist/applog/datom-types.d.ts.map +1 -1
  8. package/dist/applog.d.ts +3 -3
  9. package/dist/applog.d.ts.map +1 -1
  10. package/dist/{applog.min.js → applog.js} +6 -7
  11. package/dist/blockstore.d.ts +1 -1
  12. package/dist/blockstore.d.ts.map +1 -1
  13. package/dist/{blockstore.min.js → blockstore.js} +1 -3
  14. package/dist/{blockstore.min.js.map → blockstore.js.map} +1 -1
  15. package/dist/{chunk-KXMTKPF4.min.js → chunk-3JZMOEOD.js} +8 -8
  16. package/dist/chunk-3JZMOEOD.js.map +1 -0
  17. package/dist/chunk-3WZVG277.js +434 -0
  18. package/dist/chunk-3WZVG277.js.map +1 -0
  19. package/dist/chunk-7Z5YDQKK.js +1 -0
  20. package/dist/chunk-CPSDKFBG.js +147 -0
  21. package/dist/chunk-CPSDKFBG.js.map +1 -0
  22. package/dist/chunk-E46VTKTZ.js +1 -0
  23. package/dist/{chunk-H3VQJP56.min.js → chunk-J2FDHGOZ.js} +9 -9
  24. package/dist/chunk-J2FDHGOZ.js.map +1 -0
  25. package/dist/chunk-L5EEEGE6.js +1862 -0
  26. package/dist/chunk-L5EEEGE6.js.map +1 -0
  27. package/dist/{chunk-BRC7LSM6.min.js → chunk-PD3C7XUM.js} +5 -5
  28. package/dist/chunk-PD3C7XUM.js.map +1 -0
  29. package/dist/chunk-QZXKQCAY.js +1026 -0
  30. package/dist/chunk-QZXKQCAY.js.map +1 -0
  31. package/dist/{chunk-QPGEBDMJ.min.js → chunk-YDAKBU6Q.js} +1 -1
  32. package/dist/chunk-YDAKBU6Q.js.map +1 -0
  33. package/dist/chunk-ZAADLBSB.js +36 -0
  34. package/dist/chunk-ZAADLBSB.js.map +1 -0
  35. package/dist/index.d.ts +7 -7
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/{index.min.js → index.js} +73 -46
  38. package/dist/ipfs/car.d.ts +11 -11
  39. package/dist/ipfs/car.d.ts.map +1 -1
  40. package/dist/ipfs/ipfs-utils.d.ts +2 -2
  41. package/dist/ipfs/ipfs-utils.d.ts.map +1 -1
  42. package/dist/ipfs.d.ts +3 -3
  43. package/dist/ipfs.d.ts.map +1 -1
  44. package/dist/{ipfs.min.js → ipfs.js} +7 -10
  45. package/dist/ipns.d.ts +1 -1
  46. package/dist/ipns.d.ts.map +1 -1
  47. package/dist/ipns.js +64 -0
  48. package/dist/ipns.js.map +1 -0
  49. package/dist/pubsub/pub-pull.d.ts +3 -3
  50. package/dist/pubsub/pub-pull.d.ts.map +1 -1
  51. package/dist/pubsub/pubsub-types.d.ts +3 -3
  52. package/dist/pubsub/pubsub-types.d.ts.map +1 -1
  53. package/dist/pubsub/snap-push.d.ts +4 -4
  54. package/dist/pubsub/snap-push.d.ts.map +1 -1
  55. package/dist/pubsub/ucan.d.ts +1 -1
  56. package/dist/pubsub/ucan.d.ts.map +1 -1
  57. package/dist/pubsub.d.ts +4 -4
  58. package/dist/pubsub.d.ts.map +1 -1
  59. package/dist/{pubsub.min.js → pubsub.js} +7 -10
  60. package/dist/query/attr-helpers.d.ts +5 -0
  61. package/dist/query/attr-helpers.d.ts.map +1 -0
  62. package/dist/query/basic.d.ts +85 -21
  63. package/dist/query/basic.d.ts.map +1 -1
  64. package/dist/query/divergences.d.ts +5 -5
  65. package/dist/query/divergences.d.ts.map +1 -1
  66. package/dist/query/entity-collection.d.ts +19 -0
  67. package/dist/query/entity-collection.d.ts.map +1 -0
  68. package/dist/query/matchers.d.ts +1 -1
  69. package/dist/query/matchers.d.ts.map +1 -1
  70. package/dist/query/memoized.d.ts +66 -0
  71. package/dist/query/memoized.d.ts.map +1 -0
  72. package/dist/query/situations.d.ts +2 -1
  73. package/dist/query/situations.d.ts.map +1 -1
  74. package/dist/query/subscribable.d.ts +111 -0
  75. package/dist/query/subscribable.d.ts.map +1 -0
  76. package/dist/query/types.d.ts +54 -14
  77. package/dist/query/types.d.ts.map +1 -1
  78. package/dist/query.d.ts +9 -5
  79. package/dist/query.d.ts.map +1 -1
  80. package/dist/{query.min.js → query.js} +51 -32
  81. package/dist/retrieve/index.d.ts +1 -1
  82. package/dist/retrieve/index.d.ts.map +1 -1
  83. package/dist/retrieve/update-thread.d.ts +3 -3
  84. package/dist/retrieve/update-thread.d.ts.map +1 -1
  85. package/dist/retrieve.d.ts +1 -1
  86. package/dist/retrieve.d.ts.map +1 -1
  87. package/dist/retrieve.js +14 -0
  88. package/dist/thread/basic.d.ts +15 -19
  89. package/dist/thread/basic.d.ts.map +1 -1
  90. package/dist/thread/filters.d.ts +8 -10
  91. package/dist/thread/filters.d.ts.map +1 -1
  92. package/dist/thread/indexes.d.ts +56 -0
  93. package/dist/thread/indexes.d.ts.map +1 -0
  94. package/dist/thread/mapped.d.ts +40 -11
  95. package/dist/thread/mapped.d.ts.map +1 -1
  96. package/dist/thread/utils.d.ts +5 -5
  97. package/dist/thread/utils.d.ts.map +1 -1
  98. package/dist/thread/writeable.d.ts +2 -2
  99. package/dist/thread/writeable.d.ts.map +1 -1
  100. package/dist/thread.d.ts +6 -5
  101. package/dist/thread.d.ts.map +1 -1
  102. package/dist/{thread.min.js → thread.js} +9 -6
  103. package/dist/types/typescript-utils.d.ts +6 -5
  104. package/dist/types/typescript-utils.d.ts.map +1 -1
  105. package/dist/types.d.ts +1 -1
  106. package/dist/types.d.ts.map +1 -1
  107. package/dist/{types.min.js → types.js} +3 -4
  108. package/dist/utils/debug-name.d.ts +13 -0
  109. package/dist/utils/debug-name.d.ts.map +1 -0
  110. package/dist/utils.d.ts +1 -1
  111. package/dist/utils.d.ts.map +1 -1
  112. package/dist/utils.js +9 -0
  113. package/package.json +32 -23
  114. package/src/applog/applog-helpers.ts +155 -0
  115. package/src/applog/applog-utils.test.ts +108 -0
  116. package/src/applog/applog-utils.ts +507 -0
  117. package/src/applog/datom-types.ts +148 -0
  118. package/src/applog.ts +3 -0
  119. package/src/blockstore/index.ts +36 -0
  120. package/src/blockstore.ts +1 -0
  121. package/src/index.ts +8 -0
  122. package/src/ipfs/car.ts +291 -0
  123. package/src/ipfs/fetch-snapshot-chain.ts +135 -0
  124. package/src/ipfs/ipfs-utils.ts +132 -0
  125. package/src/ipfs.ts +3 -0
  126. package/src/ipns/ipns-record.ts +115 -0
  127. package/src/ipns.ts +1 -0
  128. package/src/pubsub/UCAN Specs Overview.md +217 -0
  129. package/src/pubsub/connector.ts +9 -0
  130. package/src/pubsub/pub-pull.ts +31 -0
  131. package/src/pubsub/pubsub-types.ts +90 -0
  132. package/src/pubsub/snap-push.ts +277 -0
  133. package/src/pubsub/ucan-example.ts +61 -0
  134. package/src/pubsub/ucan.ts +56 -0
  135. package/src/pubsub.ts +4 -0
  136. package/src/query/attr-helpers.ts +5 -0
  137. package/src/query/basic.ts +1245 -0
  138. package/src/query/divergences.ts +50 -0
  139. package/src/query/entity-collection.ts +131 -0
  140. package/src/query/liveFilterAndMap.test.ts +102 -0
  141. package/src/query/matchers.ts +8 -0
  142. package/src/query/memoized.test.ts +151 -0
  143. package/src/query/memoized.ts +180 -0
  144. package/src/query/query-steps.ts +4 -0
  145. package/src/query/query.test.ts +538 -0
  146. package/src/query/situations.ts +261 -0
  147. package/src/query/subscribable.test.ts +245 -0
  148. package/src/query/subscribable.ts +234 -0
  149. package/src/query/types.ts +155 -0
  150. package/src/query/withoutDeleted.test.ts +204 -0
  151. package/src/query.ts +9 -0
  152. package/src/retrieve/index.ts +1 -0
  153. package/src/retrieve/update-thread.ts +248 -0
  154. package/src/retrieve.ts +1 -0
  155. package/src/test/perf/query.1m.perf.test.ts +94 -0
  156. package/src/test/perf/query.perf.test.ts +389 -0
  157. package/src/test/perf/query.realdata.perf.test.ts +182 -0
  158. package/src/thread/basic.ts +209 -0
  159. package/src/thread/filters.ts +227 -0
  160. package/src/thread/indexes.ts +250 -0
  161. package/src/thread/joinThreads.test.ts +304 -0
  162. package/src/thread/mapped.ts +226 -0
  163. package/src/thread/utils.ts +144 -0
  164. package/src/thread/writeable.ts +163 -0
  165. package/src/thread.ts +6 -0
  166. package/src/types/typescript-utils.ts +64 -0
  167. package/src/types.ts +1 -0
  168. package/src/utils/debug-name.ts +54 -0
  169. package/src/utils.ts +4 -0
  170. package/dist/chunk-2Y2PYHGR.min.js +0 -65
  171. package/dist/chunk-2Y2PYHGR.min.js.map +0 -1
  172. package/dist/chunk-5MMGBK2U.min.js +0 -1
  173. package/dist/chunk-7IDQIMQO.min.js +0 -1
  174. package/dist/chunk-BRC7LSM6.min.js.map +0 -1
  175. package/dist/chunk-COXXILXC.min.js +0 -512
  176. package/dist/chunk-COXXILXC.min.js.map +0 -1
  177. package/dist/chunk-GDX2OO7L.min.js +0 -9080
  178. package/dist/chunk-GDX2OO7L.min.js.map +0 -1
  179. package/dist/chunk-H3VQJP56.min.js.map +0 -1
  180. package/dist/chunk-HYMC7W6S.min.js +0 -1549
  181. package/dist/chunk-HYMC7W6S.min.js.map +0 -1
  182. package/dist/chunk-KEHU7HGZ.min.js +0 -5216
  183. package/dist/chunk-KEHU7HGZ.min.js.map +0 -1
  184. package/dist/chunk-KXMTKPF4.min.js.map +0 -1
  185. package/dist/chunk-PHITDXZT.min.js +0 -36
  186. package/dist/chunk-QO2KMGDN.min.js +0 -3771
  187. package/dist/chunk-QO2KMGDN.min.js.map +0 -1
  188. package/dist/chunk-QPGEBDMJ.min.js.map +0 -1
  189. package/dist/chunk-WXLCBTHX.min.js +0 -1606
  190. package/dist/chunk-WXLCBTHX.min.js.map +0 -1
  191. package/dist/ipns.min.js +0 -6419
  192. package/dist/ipns.min.js.map +0 -1
  193. package/dist/mobx/mobx-utils.d.ts +0 -82
  194. package/dist/mobx/mobx-utils.d.ts.map +0 -1
  195. package/dist/mobx.d.ts +0 -2
  196. package/dist/mobx.d.ts.map +0 -1
  197. package/dist/mobx.min.js +0 -141
  198. package/dist/retrieve.min.js +0 -17
  199. package/dist/types.min.js.map +0 -1
  200. package/dist/utils.min.js +0 -10
  201. package/dist/utils.min.js.map +0 -1
  202. /package/dist/{applog.min.js.map → applog.js.map} +0 -0
  203. /package/dist/{chunk-5MMGBK2U.min.js.map → chunk-7Z5YDQKK.js.map} +0 -0
  204. /package/dist/{chunk-7IDQIMQO.min.js.map → chunk-E46VTKTZ.js.map} +0 -0
  205. /package/dist/{chunk-PHITDXZT.min.js.map → index.js.map} +0 -0
  206. /package/dist/{index.min.js.map → ipfs.js.map} +0 -0
  207. /package/dist/{ipfs.min.js.map → pubsub.js.map} +0 -0
  208. /package/dist/{mobx.min.js.map → query.js.map} +0 -0
  209. /package/dist/{pubsub.min.js.map → retrieve.js.map} +0 -0
  210. /package/dist/{query.min.js.map → thread.js.map} +0 -0
  211. /package/dist/{retrieve.min.js.map → types.js.map} +0 -0
  212. /package/dist/{thread.min.js.map → utils.js.map} +0 -0
@@ -1,1606 +0,0 @@
1
- import {
2
- keepTruthy
3
- } from "./chunk-QPGEBDMJ.min.js";
4
- import {
5
- lastWriteWins
6
- } from "./chunk-COXXILXC.min.js";
7
- import {
8
- CID as CID2,
9
- areCidsEqual,
10
- decode as decode3,
11
- encodeBlockOriginal,
12
- ensureTsPvAndFinalizeApplog,
13
- g,
14
- getLogsFromThread,
15
- prepareForPub,
16
- rollingFilter,
17
- src_exports,
18
- wrapper_default
19
- } from "./chunk-GDX2OO7L.min.js";
20
- import {
21
- CID,
22
- Token,
23
- Type,
24
- decode,
25
- decode2,
26
- encode,
27
- makeCborEncoders
28
- } from "./chunk-QO2KMGDN.min.js";
29
- import {
30
- __commonJS,
31
- __toESM
32
- } from "./chunk-PHITDXZT.min.js";
33
-
34
- // ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js
35
- var require_encode = __commonJS({
36
- "../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js"(exports, module) {
37
- "use strict";
38
- module.exports = encode3;
39
- var MSB = 128;
40
- var REST = 127;
41
- var MSBALL = ~REST;
42
- var INT = Math.pow(2, 31);
43
- function encode3(num, out, offset) {
44
- if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
45
- encode3.bytes = 0;
46
- throw new RangeError("Could not encode varint");
47
- }
48
- out = out || [];
49
- offset = offset || 0;
50
- var oldOffset = offset;
51
- while (num >= INT) {
52
- out[offset++] = num & 255 | MSB;
53
- num /= 128;
54
- }
55
- while (num & MSBALL) {
56
- out[offset++] = num & 255 | MSB;
57
- num >>>= 7;
58
- }
59
- out[offset] = num | 0;
60
- encode3.bytes = offset - oldOffset + 1;
61
- return out;
62
- }
63
- }
64
- });
65
-
66
- // ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js
67
- var require_decode = __commonJS({
68
- "../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js"(exports, module) {
69
- "use strict";
70
- module.exports = read;
71
- var MSB = 128;
72
- var REST = 127;
73
- function read(buf, offset) {
74
- var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
75
- do {
76
- if (counter >= l || shift > 49) {
77
- read.bytes = 0;
78
- throw new RangeError("Could not decode varint");
79
- }
80
- b = buf[counter++];
81
- res += shift < 28 ? (b & REST) << shift : (b & REST) * Math.pow(2, shift);
82
- shift += 7;
83
- } while (b >= MSB);
84
- read.bytes = counter - offset;
85
- return res;
86
- }
87
- }
88
- });
89
-
90
- // ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js
91
- var require_length = __commonJS({
92
- "../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js"(exports, module) {
93
- "use strict";
94
- var N1 = Math.pow(2, 7);
95
- var N2 = Math.pow(2, 14);
96
- var N3 = Math.pow(2, 21);
97
- var N4 = Math.pow(2, 28);
98
- var N5 = Math.pow(2, 35);
99
- var N6 = Math.pow(2, 42);
100
- var N7 = Math.pow(2, 49);
101
- var N8 = Math.pow(2, 56);
102
- var N9 = Math.pow(2, 63);
103
- module.exports = function(value) {
104
- return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
105
- };
106
- }
107
- });
108
-
109
- // ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js
110
- var require_varint = __commonJS({
111
- "../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js"(exports, module) {
112
- "use strict";
113
- module.exports = {
114
- encode: require_encode(),
115
- decode: require_decode(),
116
- encodingLength: require_length()
117
- };
118
- }
119
- });
120
-
121
- // ../../../node_modules/.pnpm/@ipld+dag-cbor@9.2.5/node_modules/@ipld/dag-cbor/src/index.js
122
- var CID_CBOR_TAG = 42;
123
- function toByteView(buf) {
124
- if (buf instanceof ArrayBuffer) {
125
- return new Uint8Array(buf, 0, buf.byteLength);
126
- }
127
- return buf;
128
- }
129
- function cidEncoder(obj) {
130
- if (obj.asCID !== obj && obj["/"] !== obj.bytes) {
131
- return null;
132
- }
133
- const cid = CID.asCID(obj);
134
- if (!cid) {
135
- return null;
136
- }
137
- const bytes = new Uint8Array(cid.bytes.byteLength + 1);
138
- bytes.set(cid.bytes, 1);
139
- return [
140
- new Token(Type.tag, CID_CBOR_TAG),
141
- new Token(Type.bytes, bytes)
142
- ];
143
- }
144
- function undefinedEncoder() {
145
- throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded");
146
- }
147
- function numberEncoder(num) {
148
- if (Number.isNaN(num)) {
149
- throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");
150
- }
151
- if (num === Infinity || num === -Infinity) {
152
- throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");
153
- }
154
- return null;
155
- }
156
- function mapEncoder(map) {
157
- for (const key of map.keys()) {
158
- if (typeof key !== "string" || key.length === 0) {
159
- throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");
160
- }
161
- }
162
- return null;
163
- }
164
- var _encodeOptions = {
165
- float64: true,
166
- typeEncoders: {
167
- Map: mapEncoder,
168
- Object: cidEncoder,
169
- undefined: undefinedEncoder,
170
- number: numberEncoder
171
- }
172
- };
173
- var encodeOptions = {
174
- ..._encodeOptions,
175
- typeEncoders: {
176
- ..._encodeOptions.typeEncoders
177
- }
178
- };
179
- function cidDecoder(bytes) {
180
- if (bytes[0] !== 0) {
181
- throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");
182
- }
183
- return CID.decode(bytes.subarray(1));
184
- }
185
- var _decodeOptions = {
186
- allowIndefinite: false,
187
- coerceUndefinedToNull: true,
188
- allowNaN: false,
189
- allowInfinity: false,
190
- allowBigInt: true,
191
- // this will lead to BigInt for ints outside of
192
- // safe-integer range, which may surprise users
193
- strict: true,
194
- useMaps: false,
195
- rejectDuplicateMapKeys: true,
196
- /** @type {import('cborg').TagDecoder[]} */
197
- tags: []
198
- };
199
- _decodeOptions.tags[CID_CBOR_TAG] = cidDecoder;
200
- var decodeOptions = {
201
- ..._decodeOptions,
202
- tags: _decodeOptions.tags.slice()
203
- };
204
- var encode2 = (node) => encode(node, _encodeOptions);
205
- var decode4 = (data) => decode(toByteView(data), _decodeOptions);
206
-
207
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/decoder-common.js
208
- var import_varint = __toESM(require_varint(), 1);
209
- var CIDV0_BYTES = {
210
- SHA2_256: 18,
211
- LENGTH: 32,
212
- DAG_PB: 112
213
- };
214
- var V2_HEADER_LENGTH = (
215
- /* characteristics */
216
- 16 + 8 + 8 + 8
217
- );
218
- function decodeVarint(bytes, seeker) {
219
- if (!bytes.length) {
220
- throw new Error("Unexpected end of data");
221
- }
222
- const i = import_varint.default.decode(bytes);
223
- seeker.seek(
224
- /** @type {number} */
225
- import_varint.default.decode.bytes
226
- );
227
- return i;
228
- }
229
- function decodeV2Header(bytes) {
230
- const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
231
- let offset = 0;
232
- const header = {
233
- version: 2,
234
- /** @type {[bigint, bigint]} */
235
- characteristics: [
236
- dv.getBigUint64(offset, true),
237
- dv.getBigUint64(offset += 8, true)
238
- ],
239
- dataOffset: Number(dv.getBigUint64(offset += 8, true)),
240
- dataSize: Number(dv.getBigUint64(offset += 8, true)),
241
- indexOffset: Number(dv.getBigUint64(offset += 8, true))
242
- };
243
- return header;
244
- }
245
- function getMultihashLength(bytes) {
246
- import_varint.default.decode(bytes);
247
- const codeLength = (
248
- /** @type {number} */
249
- import_varint.default.decode.bytes
250
- );
251
- const length = import_varint.default.decode(bytes.subarray(import_varint.default.decode.bytes));
252
- const lengthLength = (
253
- /** @type {number} */
254
- import_varint.default.decode.bytes
255
- );
256
- const mhLength = codeLength + lengthLength + length;
257
- return mhLength;
258
- }
259
-
260
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/header-validator.js
261
- var Kinds = {
262
- Null: (
263
- /**
264
- * @param obj
265
- * @returns {undefined|null}
266
- */
267
- (obj) => obj === null ? obj : void 0
268
- ),
269
- Int: (
270
- /**
271
- * @param obj
272
- * @returns {undefined|number}
273
- */
274
- (obj) => Number.isInteger(obj) ? obj : void 0
275
- ),
276
- Float: (
277
- /**
278
- * @param obj
279
- * @returns {undefined|number}
280
- */
281
- (obj) => typeof obj === "number" && Number.isFinite(obj) ? obj : void 0
282
- ),
283
- String: (
284
- /**
285
- * @param obj
286
- * @returns {undefined|string}
287
- */
288
- (obj) => typeof obj === "string" ? obj : void 0
289
- ),
290
- Bool: (
291
- /**
292
- * @param obj
293
- * @returns {undefined|boolean}
294
- */
295
- (obj) => typeof obj === "boolean" ? obj : void 0
296
- ),
297
- Bytes: (
298
- /**
299
- * @param obj
300
- * @returns {undefined|Uint8Array}
301
- */
302
- (obj) => obj instanceof Uint8Array ? obj : void 0
303
- ),
304
- Link: (
305
- /**
306
- * @param obj
307
- * @returns {undefined|object}
308
- */
309
- (obj) => obj !== null && typeof obj === "object" && obj.asCID === obj ? obj : void 0
310
- ),
311
- List: (
312
- /**
313
- * @param obj
314
- * @returns {undefined|Array<any>}
315
- */
316
- (obj) => Array.isArray(obj) ? obj : void 0
317
- ),
318
- Map: (
319
- /**
320
- * @param obj
321
- * @returns {undefined|object}
322
- */
323
- (obj) => obj !== null && typeof obj === "object" && obj.asCID !== obj && !Array.isArray(obj) && !(obj instanceof Uint8Array) ? obj : void 0
324
- )
325
- };
326
- var Types = {
327
- "CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)": Kinds.Link,
328
- "CarV1HeaderOrV2Pragma > roots (anon)": (
329
- /**
330
- * @param obj
331
- * @returns {undefined|any}
332
- */
333
- (obj) => {
334
- if (Kinds.List(obj) === void 0) {
335
- return void 0;
336
- }
337
- for (let i = 0; i < obj.length; i++) {
338
- let v = obj[i];
339
- v = Types["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v);
340
- if (v === void 0) {
341
- return void 0;
342
- }
343
- if (v !== obj[i]) {
344
- const ret = obj.slice(0, i);
345
- for (let j = i; j < obj.length; j++) {
346
- let v2 = obj[j];
347
- v2 = Types["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v2);
348
- if (v2 === void 0) {
349
- return void 0;
350
- }
351
- ret.push(v2);
352
- }
353
- return ret;
354
- }
355
- }
356
- return obj;
357
- }
358
- ),
359
- Int: Kinds.Int,
360
- CarV1HeaderOrV2Pragma: (
361
- /**
362
- * @param obj
363
- * @returns {undefined|any}
364
- */
365
- (obj) => {
366
- if (Kinds.Map(obj) === void 0) {
367
- return void 0;
368
- }
369
- const entries = Object.entries(obj);
370
- let ret = obj;
371
- let requiredCount = 1;
372
- for (let i = 0; i < entries.length; i++) {
373
- const [key, value] = entries[i];
374
- switch (key) {
375
- case "roots":
376
- {
377
- const v = Types["CarV1HeaderOrV2Pragma > roots (anon)"](obj[key]);
378
- if (v === void 0) {
379
- return void 0;
380
- }
381
- if (v !== value || ret !== obj) {
382
- if (ret === obj) {
383
- ret = {};
384
- for (let j = 0; j < i; j++) {
385
- ret[entries[j][0]] = entries[j][1];
386
- }
387
- }
388
- ret.roots = v;
389
- }
390
- }
391
- break;
392
- case "version":
393
- {
394
- requiredCount--;
395
- const v = Types.Int(obj[key]);
396
- if (v === void 0) {
397
- return void 0;
398
- }
399
- if (v !== value || ret !== obj) {
400
- if (ret === obj) {
401
- ret = {};
402
- for (let j = 0; j < i; j++) {
403
- ret[entries[j][0]] = entries[j][1];
404
- }
405
- }
406
- ret.version = v;
407
- }
408
- }
409
- break;
410
- default:
411
- return void 0;
412
- }
413
- }
414
- if (requiredCount > 0) {
415
- return void 0;
416
- }
417
- return ret;
418
- }
419
- )
420
- };
421
- var Reprs = {
422
- "CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)": Kinds.Link,
423
- "CarV1HeaderOrV2Pragma > roots (anon)": (
424
- /**
425
- * @param obj
426
- * @returns {undefined|any}
427
- */
428
- (obj) => {
429
- if (Kinds.List(obj) === void 0) {
430
- return void 0;
431
- }
432
- for (let i = 0; i < obj.length; i++) {
433
- let v = obj[i];
434
- v = Reprs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v);
435
- if (v === void 0) {
436
- return void 0;
437
- }
438
- if (v !== obj[i]) {
439
- const ret = obj.slice(0, i);
440
- for (let j = i; j < obj.length; j++) {
441
- let v2 = obj[j];
442
- v2 = Reprs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v2);
443
- if (v2 === void 0) {
444
- return void 0;
445
- }
446
- ret.push(v2);
447
- }
448
- return ret;
449
- }
450
- }
451
- return obj;
452
- }
453
- ),
454
- Int: Kinds.Int,
455
- CarV1HeaderOrV2Pragma: (
456
- /**
457
- * @param obj
458
- * @returns {undefined|any}
459
- */
460
- (obj) => {
461
- if (Kinds.Map(obj) === void 0) {
462
- return void 0;
463
- }
464
- const entries = Object.entries(obj);
465
- let ret = obj;
466
- let requiredCount = 1;
467
- for (let i = 0; i < entries.length; i++) {
468
- const [key, value] = entries[i];
469
- switch (key) {
470
- case "roots":
471
- {
472
- const v = Reprs["CarV1HeaderOrV2Pragma > roots (anon)"](value);
473
- if (v === void 0) {
474
- return void 0;
475
- }
476
- if (v !== value || ret !== obj) {
477
- if (ret === obj) {
478
- ret = {};
479
- for (let j = 0; j < i; j++) {
480
- ret[entries[j][0]] = entries[j][1];
481
- }
482
- }
483
- ret.roots = v;
484
- }
485
- }
486
- break;
487
- case "version":
488
- {
489
- requiredCount--;
490
- const v = Reprs.Int(value);
491
- if (v === void 0) {
492
- return void 0;
493
- }
494
- if (v !== value || ret !== obj) {
495
- if (ret === obj) {
496
- ret = {};
497
- for (let j = 0; j < i; j++) {
498
- ret[entries[j][0]] = entries[j][1];
499
- }
500
- }
501
- ret.version = v;
502
- }
503
- }
504
- break;
505
- default:
506
- return void 0;
507
- }
508
- }
509
- if (requiredCount > 0) {
510
- return void 0;
511
- }
512
- return ret;
513
- }
514
- )
515
- };
516
- var CarV1HeaderOrV2Pragma = {
517
- toTyped: Types.CarV1HeaderOrV2Pragma,
518
- toRepresentation: Reprs.CarV1HeaderOrV2Pragma
519
- };
520
-
521
- // ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/length.js
522
- var cborEncoders = makeCborEncoders();
523
-
524
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/buffer-writer.js
525
- var import_varint2 = __toESM(require_varint(), 1);
526
- var headerPreludeTokens = [
527
- new Token(Type.map, 2),
528
- new Token(Type.string, "version"),
529
- new Token(Type.uint, 1),
530
- new Token(Type.string, "roots")
531
- ];
532
- var CID_TAG = new Token(Type.tag, 42);
533
-
534
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/decoder.js
535
- async function readHeader(reader, strictVersion) {
536
- const length = decodeVarint(await reader.upTo(8), reader);
537
- if (length === 0) {
538
- throw new Error("Invalid CAR header (zero length)");
539
- }
540
- const header = await reader.exactly(length, true);
541
- const block = decode4(header);
542
- if (CarV1HeaderOrV2Pragma.toTyped(block) === void 0) {
543
- throw new Error("Invalid CAR header format");
544
- }
545
- if (block.version !== 1 && block.version !== 2 || strictVersion !== void 0 && block.version !== strictVersion) {
546
- throw new Error(`Invalid CAR version: ${block.version}${strictVersion !== void 0 ? ` (expected ${strictVersion})` : ""}`);
547
- }
548
- if (block.version === 1) {
549
- if (!Array.isArray(block.roots)) {
550
- throw new Error("Invalid CAR header format");
551
- }
552
- return block;
553
- }
554
- if (block.roots !== void 0) {
555
- throw new Error("Invalid CAR header format");
556
- }
557
- const v2Header = decodeV2Header(await reader.exactly(V2_HEADER_LENGTH, true));
558
- reader.seek(v2Header.dataOffset - reader.pos);
559
- const v1Header = await readHeader(reader, 1);
560
- return Object.assign(v1Header, v2Header);
561
- }
562
- async function readCid(reader) {
563
- const first = await reader.exactly(2, false);
564
- if (first[0] === CIDV0_BYTES.SHA2_256 && first[1] === CIDV0_BYTES.LENGTH) {
565
- const bytes2 = await reader.exactly(34, true);
566
- const multihash2 = decode2(bytes2);
567
- return CID.create(0, CIDV0_BYTES.DAG_PB, multihash2);
568
- }
569
- const version = decodeVarint(await reader.upTo(8), reader);
570
- if (version !== 1) {
571
- throw new Error(`Unexpected CID version (${version})`);
572
- }
573
- const codec = decodeVarint(await reader.upTo(8), reader);
574
- const bytes = await reader.exactly(getMultihashLength(await reader.upTo(8)), true);
575
- const multihash = decode2(bytes);
576
- return CID.create(version, codec, multihash);
577
- }
578
- async function readBlockHead(reader) {
579
- const start = reader.pos;
580
- let length = decodeVarint(await reader.upTo(8), reader);
581
- if (length === 0) {
582
- throw new Error("Invalid CAR section (zero length)");
583
- }
584
- length += reader.pos - start;
585
- const cid = await readCid(reader);
586
- const blockLength = length - Number(reader.pos - start);
587
- return { cid, length, blockLength };
588
- }
589
- async function readBlock(reader) {
590
- const { cid, blockLength } = await readBlockHead(reader);
591
- const bytes = await reader.exactly(blockLength, true);
592
- return { bytes, cid };
593
- }
594
- async function readBlockIndex(reader) {
595
- const offset = reader.pos;
596
- const { cid, length, blockLength } = await readBlockHead(reader);
597
- const index = { cid, length, blockLength, offset, blockOffset: reader.pos };
598
- reader.seek(index.blockLength);
599
- return index;
600
- }
601
- function createDecoder(reader) {
602
- const headerPromise = (async () => {
603
- const header = await readHeader(reader);
604
- if (header.version === 2) {
605
- const v1length = reader.pos - header.dataOffset;
606
- reader = limitReader(reader, header.dataSize - v1length);
607
- }
608
- return header;
609
- })();
610
- return {
611
- header: () => headerPromise,
612
- async *blocks() {
613
- await headerPromise;
614
- while ((await reader.upTo(8)).length > 0) {
615
- yield await readBlock(reader);
616
- }
617
- },
618
- async *blocksIndex() {
619
- await headerPromise;
620
- while ((await reader.upTo(8)).length > 0) {
621
- yield await readBlockIndex(reader);
622
- }
623
- }
624
- };
625
- }
626
- function bytesReader(bytes) {
627
- let pos = 0;
628
- return {
629
- async upTo(length) {
630
- const out = bytes.subarray(pos, pos + Math.min(length, bytes.length - pos));
631
- return out;
632
- },
633
- async exactly(length, seek = false) {
634
- if (length > bytes.length - pos) {
635
- throw new Error("Unexpected end of data");
636
- }
637
- const out = bytes.subarray(pos, pos + length);
638
- if (seek) {
639
- pos += length;
640
- }
641
- return out;
642
- },
643
- seek(length) {
644
- pos += length;
645
- },
646
- get pos() {
647
- return pos;
648
- }
649
- };
650
- }
651
- function chunkReader(readChunk) {
652
- let pos = 0;
653
- let have = 0;
654
- let offset = 0;
655
- let currentChunk = new Uint8Array(0);
656
- const read = async (length) => {
657
- have = currentChunk.length - offset;
658
- const bufa = (
659
- /** @type {Uint8Array<ArrayBufferLike>[]} */
660
- [currentChunk.subarray(offset)]
661
- );
662
- while (have < length) {
663
- const chunk = await readChunk();
664
- if (chunk == null) {
665
- break;
666
- }
667
- if (have < 0) {
668
- if (chunk.length > have) {
669
- bufa.push(chunk.subarray(-have));
670
- }
671
- } else {
672
- bufa.push(chunk);
673
- }
674
- have += chunk.length;
675
- }
676
- currentChunk = new Uint8Array(bufa.reduce((p, c) => p + c.length, 0));
677
- let off = 0;
678
- for (const b of bufa) {
679
- currentChunk.set(b, off);
680
- off += b.length;
681
- }
682
- offset = 0;
683
- };
684
- return {
685
- async upTo(length) {
686
- if (currentChunk.length - offset < length) {
687
- await read(length);
688
- }
689
- return currentChunk.subarray(offset, offset + Math.min(currentChunk.length - offset, length));
690
- },
691
- async exactly(length, seek = false) {
692
- if (currentChunk.length - offset < length) {
693
- await read(length);
694
- }
695
- if (currentChunk.length - offset < length) {
696
- throw new Error("Unexpected end of data");
697
- }
698
- const out = currentChunk.subarray(offset, offset + length);
699
- if (seek) {
700
- pos += length;
701
- offset += length;
702
- }
703
- return out;
704
- },
705
- seek(length) {
706
- pos += length;
707
- offset += length;
708
- },
709
- get pos() {
710
- return pos;
711
- }
712
- };
713
- }
714
- function asyncIterableReader(asyncIterable) {
715
- const iterator = asyncIterable[Symbol.asyncIterator]();
716
- async function readChunk() {
717
- const next = await iterator.next();
718
- if (next.done) {
719
- return null;
720
- }
721
- return next.value;
722
- }
723
- return chunkReader(readChunk);
724
- }
725
- function limitReader(reader, byteLimit) {
726
- let bytesRead = 0;
727
- return {
728
- async upTo(length) {
729
- let bytes = await reader.upTo(length);
730
- if (bytes.length + bytesRead > byteLimit) {
731
- bytes = bytes.subarray(0, byteLimit - bytesRead);
732
- }
733
- return bytes;
734
- },
735
- async exactly(length, seek = false) {
736
- const bytes = await reader.exactly(length, seek);
737
- if (bytes.length + bytesRead > byteLimit) {
738
- throw new Error("Unexpected end of data");
739
- }
740
- if (seek) {
741
- bytesRead += length;
742
- }
743
- return bytes;
744
- },
745
- seek(length) {
746
- bytesRead += length;
747
- reader.seek(length);
748
- },
749
- get pos() {
750
- return reader.pos;
751
- }
752
- };
753
- }
754
-
755
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/reader-browser.js
756
- var CarReader = class {
757
- /**
758
- * @constructs CarReader
759
- * @param {CarHeader|CarV2Header} header
760
- * @param {Block[]} blocks
761
- */
762
- constructor(header, blocks) {
763
- this._header = header;
764
- this._blocks = blocks;
765
- this._keys = blocks.map((b) => b.cid.toString());
766
- }
767
- /**
768
- * @property
769
- * @memberof CarReader
770
- * @instance
771
- */
772
- get version() {
773
- return this._header.version;
774
- }
775
- /**
776
- * Get the list of roots defined by the CAR referenced by this reader. May be
777
- * zero or more `CID`s.
778
- *
779
- * @function
780
- * @memberof CarReader
781
- * @instance
782
- * @async
783
- * @returns {Promise<CID[]>}
784
- */
785
- async getRoots() {
786
- return this._header.roots;
787
- }
788
- /**
789
- * Check whether a given `CID` exists within the CAR referenced by this
790
- * reader.
791
- *
792
- * @function
793
- * @memberof CarReader
794
- * @instance
795
- * @async
796
- * @param {CID} key
797
- * @returns {Promise<boolean>}
798
- */
799
- async has(key) {
800
- return this._keys.indexOf(key.toString()) > -1;
801
- }
802
- /**
803
- * Fetch a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) from the CAR
804
- * referenced by this reader matching the provided `CID`. In the case where
805
- * the provided `CID` doesn't exist within the CAR, `undefined` will be
806
- * returned.
807
- *
808
- * @function
809
- * @memberof CarReader
810
- * @instance
811
- * @async
812
- * @param {CID} key
813
- * @returns {Promise<Block | undefined>}
814
- */
815
- async get(key) {
816
- const index = this._keys.indexOf(key.toString());
817
- return index > -1 ? this._blocks[index] : void 0;
818
- }
819
- /**
820
- * Returns a `BlockIterator` (`AsyncIterable<Block>`) that iterates over all
821
- * of the `Block`s (`{ cid:CID, bytes:Uint8Array }` pairs) contained within
822
- * the CAR referenced by this reader.
823
- *
824
- * @function
825
- * @memberof CarReader
826
- * @instance
827
- * @async
828
- * @generator
829
- * @returns {AsyncGenerator<Block>}
830
- */
831
- async *blocks() {
832
- for (const block of this._blocks) {
833
- yield block;
834
- }
835
- }
836
- /**
837
- * Returns a `CIDIterator` (`AsyncIterable<CID>`) that iterates over all of
838
- * the `CID`s contained within the CAR referenced by this reader.
839
- *
840
- * @function
841
- * @memberof CarReader
842
- * @instance
843
- * @async
844
- * @generator
845
- * @returns {AsyncGenerator<CID>}
846
- */
847
- async *cids() {
848
- for (const block of this._blocks) {
849
- yield block.cid;
850
- }
851
- }
852
- /**
853
- * Instantiate a {@link CarReader} from a `Uint8Array` blob. This performs a
854
- * decode fully in memory and maintains the decoded state in memory for full
855
- * access to the data via the `CarReader` API.
856
- *
857
- * @async
858
- * @static
859
- * @memberof CarReader
860
- * @param {Uint8Array} bytes
861
- * @returns {Promise<CarReader>}
862
- */
863
- static async fromBytes(bytes) {
864
- if (!(bytes instanceof Uint8Array)) {
865
- throw new TypeError("fromBytes() requires a Uint8Array");
866
- }
867
- return decodeReaderComplete(bytesReader(bytes));
868
- }
869
- /**
870
- * Instantiate a {@link CarReader} from a `AsyncIterable<Uint8Array>`, such as
871
- * a [modern Node.js stream](https://nodejs.org/api/stream.html#stream_streams_compatibility_with_async_generators_and_async_iterators).
872
- * This performs a decode fully in memory and maintains the decoded state in
873
- * memory for full access to the data via the `CarReader` API.
874
- *
875
- * Care should be taken for large archives; this API may not be appropriate
876
- * where memory is a concern or the archive is potentially larger than the
877
- * amount of memory that the runtime can handle.
878
- *
879
- * @async
880
- * @static
881
- * @memberof CarReader
882
- * @param {AsyncIterable<Uint8Array>} asyncIterable
883
- * @returns {Promise<CarReader>}
884
- */
885
- static async fromIterable(asyncIterable) {
886
- if (!asyncIterable || !(typeof asyncIterable[Symbol.asyncIterator] === "function")) {
887
- throw new TypeError("fromIterable() requires an async iterable");
888
- }
889
- return decodeReaderComplete(asyncIterableReader(asyncIterable));
890
- }
891
- };
892
- async function decodeReaderComplete(reader) {
893
- const decoder = createDecoder(reader);
894
- const header = await decoder.header();
895
- const blocks = [];
896
- for await (const block of decoder.blocks()) {
897
- blocks.push(block);
898
- }
899
- return new CarReader(header, blocks);
900
- }
901
-
902
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/encoder.js
903
- var import_varint3 = __toESM(require_varint(), 1);
904
- var CAR_V1_VERSION = 1;
905
- function createHeader(roots) {
906
- const headerBytes = encode2({ version: CAR_V1_VERSION, roots });
907
- const varintBytes = import_varint3.default.encode(headerBytes.length);
908
- const header = new Uint8Array(varintBytes.length + headerBytes.length);
909
- header.set(varintBytes, 0);
910
- header.set(headerBytes, varintBytes.length);
911
- return header;
912
- }
913
- function createEncoder(writer) {
914
- return {
915
- /**
916
- * @param {CID[]} roots
917
- * @returns {Promise<void>}
918
- */
919
- async setRoots(roots) {
920
- const bytes = createHeader(roots);
921
- await writer.write(bytes);
922
- },
923
- /**
924
- * @param {Block} block
925
- * @returns {Promise<void>}
926
- */
927
- async writeBlock(block) {
928
- const { cid, bytes } = block;
929
- await writer.write(new Uint8Array(import_varint3.default.encode(cid.bytes.length + bytes.length)));
930
- await writer.write(cid.bytes);
931
- if (bytes.length) {
932
- await writer.write(bytes);
933
- }
934
- },
935
- /**
936
- * @returns {Promise<void>}
937
- */
938
- async close() {
939
- await writer.end();
940
- },
941
- /**
942
- * @returns {number}
943
- */
944
- version() {
945
- return CAR_V1_VERSION;
946
- }
947
- };
948
- }
949
-
950
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/iterator-channel.js
951
- function noop() {
952
- }
953
- function create() {
954
- const chunkQueue = [];
955
- let drainer = null;
956
- let drainerResolver = noop;
957
- let ended = false;
958
- let outWait = null;
959
- let outWaitResolver = noop;
960
- const makeDrainer = () => {
961
- if (!drainer) {
962
- drainer = new Promise((resolve) => {
963
- drainerResolver = () => {
964
- drainer = null;
965
- drainerResolver = noop;
966
- resolve();
967
- };
968
- });
969
- }
970
- return drainer;
971
- };
972
- const writer = {
973
- /**
974
- * @param {T} chunk
975
- * @returns {Promise<void>}
976
- */
977
- write(chunk) {
978
- chunkQueue.push(chunk);
979
- const drainer2 = makeDrainer();
980
- outWaitResolver();
981
- return drainer2;
982
- },
983
- async end() {
984
- ended = true;
985
- const drainer2 = makeDrainer();
986
- outWaitResolver();
987
- await drainer2;
988
- }
989
- };
990
- const iterator = {
991
- /** @returns {Promise<IteratorResult<T>>} */
992
- async next() {
993
- const chunk = chunkQueue.shift();
994
- if (chunk) {
995
- if (chunkQueue.length === 0) {
996
- drainerResolver();
997
- }
998
- return { done: false, value: chunk };
999
- }
1000
- if (ended) {
1001
- drainerResolver();
1002
- return { done: true, value: void 0 };
1003
- }
1004
- if (!outWait) {
1005
- outWait = new Promise((resolve) => {
1006
- outWaitResolver = () => {
1007
- outWait = null;
1008
- outWaitResolver = noop;
1009
- return resolve(iterator.next());
1010
- };
1011
- });
1012
- }
1013
- return outWait;
1014
- }
1015
- };
1016
- return { writer, iterator };
1017
- }
1018
-
1019
- // ../../../node_modules/.pnpm/@ipld+car@5.4.2/node_modules/@ipld/car/src/writer-browser.js
1020
- var CarWriter = class _CarWriter {
1021
- /**
1022
- * @param {CID[]} roots
1023
- * @param {CarEncoder} encoder
1024
- */
1025
- constructor(roots, encoder) {
1026
- this._encoder = encoder;
1027
- this._mutex = encoder.setRoots(roots);
1028
- this._ended = false;
1029
- }
1030
- /**
1031
- * Write a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) to the archive.
1032
- *
1033
- * @function
1034
- * @memberof CarWriter
1035
- * @instance
1036
- * @async
1037
- * @param {Block} block - A `{ cid:CID, bytes:Uint8Array }` pair.
1038
- * @returns {Promise<void>} The returned promise will only resolve once the
1039
- * bytes this block generates are written to the `out` iterable.
1040
- */
1041
- async put(block) {
1042
- if (!(block.bytes instanceof Uint8Array) || !block.cid) {
1043
- throw new TypeError("Can only write {cid, bytes} objects");
1044
- }
1045
- if (this._ended) {
1046
- throw new Error("Already closed");
1047
- }
1048
- const cid = CID.asCID(block.cid);
1049
- if (!cid) {
1050
- throw new TypeError("Can only write {cid, bytes} objects");
1051
- }
1052
- this._mutex = this._mutex.then(() => this._encoder.writeBlock({ cid, bytes: block.bytes }));
1053
- return this._mutex;
1054
- }
1055
- /**
1056
- * Finalise the CAR archive and signal that the `out` iterable should end once
1057
- * any remaining bytes are written.
1058
- *
1059
- * @function
1060
- * @memberof CarWriter
1061
- * @instance
1062
- * @async
1063
- * @returns {Promise<void>}
1064
- */
1065
- async close() {
1066
- if (this._ended) {
1067
- throw new Error("Already closed");
1068
- }
1069
- await this._mutex;
1070
- this._ended = true;
1071
- return this._encoder.close();
1072
- }
1073
- /**
1074
- * Returns the version number of the CAR file being written
1075
- *
1076
- * @returns {number}
1077
- */
1078
- version() {
1079
- return this._encoder.version();
1080
- }
1081
- /**
1082
- * Create a new CAR writer "channel" which consists of a
1083
- * `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }` pair.
1084
- *
1085
- * @async
1086
- * @static
1087
- * @memberof CarWriter
1088
- * @param {CID[] | CID | void} roots
1089
- * @returns {WriterChannel} The channel takes the form of
1090
- * `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }`.
1091
- */
1092
- static create(roots) {
1093
- roots = toRoots(roots);
1094
- const { encoder, iterator } = encodeWriter();
1095
- const writer = new _CarWriter(roots, encoder);
1096
- const out = new CarWriterOut(iterator);
1097
- return { writer, out };
1098
- }
1099
- /**
1100
- * Create a new CAR appender "channel" which consists of a
1101
- * `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }` pair.
1102
- * This appender does not consider roots and does not produce a CAR header.
1103
- * It is designed to append blocks to an _existing_ CAR archive. It is
1104
- * expected that `out` will be concatenated onto the end of an existing
1105
- * archive that already has a properly formatted header.
1106
- *
1107
- * @async
1108
- * @static
1109
- * @memberof CarWriter
1110
- * @returns {WriterChannel} The channel takes the form of
1111
- * `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }`.
1112
- */
1113
- static createAppender() {
1114
- const { encoder, iterator } = encodeWriter();
1115
- encoder.setRoots = () => Promise.resolve();
1116
- const writer = new _CarWriter([], encoder);
1117
- const out = new CarWriterOut(iterator);
1118
- return { writer, out };
1119
- }
1120
- /**
1121
- * Update the list of roots in the header of an existing CAR as represented
1122
- * in a Uint8Array.
1123
- *
1124
- * This operation is an _overwrite_, the total length of the CAR will not be
1125
- * modified. A rejection will occur if the new header will not be the same
1126
- * length as the existing header, in which case the CAR will not be modified.
1127
- * It is the responsibility of the user to ensure that the roots being
1128
- * replaced encode as the same length as the new roots.
1129
- *
1130
- * The byte array passed in an argument will be modified and also returned
1131
- * upon successful modification.
1132
- *
1133
- * @async
1134
- * @static
1135
- * @memberof CarWriter
1136
- * @param {Uint8Array} bytes
1137
- * @param {CID[]} roots - A new list of roots to replace the existing list in
1138
- * the CAR header. The new header must take up the same number of bytes as the
1139
- * existing header, so the roots should collectively be the same byte length
1140
- * as the existing roots.
1141
- * @returns {Promise<Uint8Array>}
1142
- */
1143
- static async updateRootsInBytes(bytes, roots) {
1144
- const reader = bytesReader(bytes);
1145
- await readHeader(reader);
1146
- const newHeader = createHeader(roots);
1147
- if (Number(reader.pos) !== newHeader.length) {
1148
- throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${reader.pos} bytes, new header is ${newHeader.length} bytes)`);
1149
- }
1150
- bytes.set(newHeader, 0);
1151
- return bytes;
1152
- }
1153
- };
1154
- var CarWriterOut = class {
1155
- /**
1156
- * @param {AsyncIterator<Uint8Array>} iterator
1157
- */
1158
- constructor(iterator) {
1159
- this._iterator = iterator;
1160
- }
1161
- [Symbol.asyncIterator]() {
1162
- if (this._iterating) {
1163
- throw new Error("Multiple iterator not supported");
1164
- }
1165
- this._iterating = true;
1166
- return this._iterator;
1167
- }
1168
- };
1169
- function encodeWriter() {
1170
- const iw = create();
1171
- const { writer, iterator } = iw;
1172
- const encoder = createEncoder(writer);
1173
- return { encoder, iterator };
1174
- }
1175
- function toRoots(roots) {
1176
- if (roots === void 0) {
1177
- return [];
1178
- }
1179
- if (!Array.isArray(roots)) {
1180
- const cid = CID.asCID(roots);
1181
- if (!cid) {
1182
- throw new TypeError("roots must be a single CID or an array of CIDs");
1183
- }
1184
- return [cid];
1185
- }
1186
- const _roots = [];
1187
- for (const root of roots) {
1188
- const _root = CID.asCID(root);
1189
- if (!_root) {
1190
- throw new TypeError("roots must be a single CID or an array of CIDs");
1191
- }
1192
- _roots.push(_root);
1193
- }
1194
- return _roots;
1195
- }
1196
-
1197
- // src/ipfs/car.ts
1198
- var { WARN, LOG, DEBUG, VERBOSE, ERROR } = g.setup(g.INFO);
1199
- async function decodePubFromCar(car) {
1200
- const decoded = await getBlocksOfCar(car);
1201
- return await decodePubFromBlocks(decoded);
1202
- }
1203
- async function decodePubFromBlocks({ rootCID, blockStore }, _recursionTrace = [], stopAtCID) {
1204
- if (!rootCID || !blockStore) {
1205
- throw ERROR("Empty roots/blocks", { rootCID, blockStore });
1206
- }
1207
- let allApplogs = [];
1208
- let firstInfo = null;
1209
- let currentCID = rootCID;
1210
- const visited = /* @__PURE__ */ new Set();
1211
- let applogsCID = null;
1212
- while (currentCID) {
1213
- const cidStr = currentCID.toString();
1214
- if (visited.has(cidStr)) {
1215
- throw ERROR("[decodePubFromBlocks] pub chain has a loop", {
1216
- currentCID: cidStr,
1217
- visited: [...visited]
1218
- });
1219
- }
1220
- visited.add(cidStr);
1221
- const root = await getDecodedBlock(blockStore, currentCID);
1222
- VERBOSE(`[decodePubFromBlocks] root:`, cidStr, root, { blockStore });
1223
- if (!root) {
1224
- throw ERROR("[decodePubFromBlocks] root not found in blockStore", { blockStore, currentCID: cidStr });
1225
- }
1226
- let pubLogsArray;
1227
- if (root?.info) {
1228
- if (!applogsCID) applogsCID = root.applogs;
1229
- const applogsBlock = await getDecodedBlock(blockStore, root.applogs);
1230
- pubLogsArray = await unchunkApplogsBlock(applogsBlock, blockStore);
1231
- if (!firstInfo) {
1232
- firstInfo = await getDecodedBlock(blockStore, root.info);
1233
- DEBUG(`new format - infoLogs`, firstInfo.logs.map((l) => ({ [l.toString()]: l })));
1234
- }
1235
- } else {
1236
- pubLogsArray = root.applogs;
1237
- }
1238
- const resolveLogFromCidLink = async (cidOrLink) => {
1239
- const cid = cidOrLink;
1240
- const applog = await getDecodedBlock(blockStore, cid);
1241
- if (!applog) {
1242
- ERROR(`Could not find applog CID in pub blocks:`, cid.toString(), { cid, root, blockStore });
1243
- throw new Error(`Could not find applog CID in pub blocks: ${cid.toString()}`);
1244
- }
1245
- if (applog.pv instanceof CID2) applog.pv = applog.pv.toV1().toString();
1246
- return {
1247
- ...applog,
1248
- cid: cid.toV1().toString()
1249
- };
1250
- };
1251
- const snapshotApplogs = await Promise.all(pubLogsArray.map(resolveLogFromCidLink));
1252
- allApplogs = allApplogs.concat(snapshotApplogs);
1253
- if (!root.prev) {
1254
- break;
1255
- }
1256
- if (stopAtCID && areCidsEqual(root.prev, stopAtCID)) {
1257
- DEBUG("[decodePubFromBlocks] stopping at stopAtCID:", stopAtCID.toString());
1258
- break;
1259
- }
1260
- const prevBytes = await blockStore.get(root.prev);
1261
- if (!prevBytes) {
1262
- throw ERROR("[decodePubFromBlocks] prev snapshot missing from blockStore", {
1263
- currentCID: cidStr,
1264
- prev: root.prev.toString(),
1265
- stopAtCID: stopAtCID?.toString(),
1266
- visited: [...visited]
1267
- });
1268
- }
1269
- currentCID = root.prev;
1270
- }
1271
- const result = {
1272
- cid: rootCID,
1273
- info: firstInfo ? {
1274
- ...firstInfo,
1275
- logs: await Promise.all(firstInfo.logs.map(async (cidOrLink) => {
1276
- const cid = cidOrLink;
1277
- const applog = await getDecodedBlock(blockStore, cid);
1278
- if (!applog) {
1279
- ERROR(`Could not find info log CID in pub blocks:`, cid.toString(), { cid, blockStore });
1280
- throw new Error(`Could not find info log CID in pub blocks: ${cid.toString()}`);
1281
- }
1282
- if (applog.pv instanceof CID2) applog.pv = applog.pv.toV1().toString();
1283
- return {
1284
- ...applog,
1285
- cid: cid.toV1().toString()
1286
- };
1287
- }))
1288
- } : null,
1289
- applogsCID,
1290
- applogs: allApplogs
1291
- };
1292
- DEBUG("[decodePubFromBlocks] result:", result, { rootCID: rootCID.toString(), blockStore, applogs: allApplogs });
1293
- return result;
1294
- }
1295
- async function getBlocksOfCar(car) {
1296
- const rootsFromCar = await car.getRoots();
1297
- const roots = rootsFromCar.map((c) => (typeof c.toV1 === "function" ? c : CID2.decode(c.bytes)).toV1().toString());
1298
- const blocks = /* @__PURE__ */ new Map();
1299
- for await (const { cid: cidFromCarblocks, bytes } of car.blocks()) {
1300
- const cid = typeof cidFromCarblocks.toV1 === "function" ? cidFromCarblocks : CID2.decode(cidFromCarblocks.bytes);
1301
- VERBOSE({ cidFromCarblocks, cid });
1302
- blocks.set(cid.toV1().toString(), bytes);
1303
- }
1304
- if (roots.length !== 1) {
1305
- WARN("Unexpected roots count:", roots);
1306
- }
1307
- return {
1308
- rootCID: CID2.parse(roots[0]),
1309
- blockStore: {
1310
- get: (cid) => blocks.get(cid.toV1().toString())
1311
- }
1312
- };
1313
- }
1314
- async function getDecodedBlock(blockStore, cid) {
1315
- try {
1316
- var blob = await blockStore.get(cid);
1317
- if (!blob) {
1318
- WARN("returning null");
1319
- return null;
1320
- }
1321
- } catch (err) {
1322
- if (err.message === "Not Found") return null;
1323
- throw err;
1324
- }
1325
- return decode3(blob);
1326
- }
1327
- async function makeCarOut(roots, blocks) {
1328
- const { writer, out } = CarWriter.create(Array.isArray(roots) ? roots : [roots]);
1329
- VERBOSE(`Writing ${blocks.length} blocks to CAR`, { roots, blocks });
1330
- blocks.forEach((b) => writer.put(b));
1331
- writer.close();
1332
- return out;
1333
- }
1334
- async function makeCarBlob(roots, blocks) {
1335
- const carOut = await makeCarOut(roots, blocks);
1336
- const chunks = [];
1337
- for await (const chunk of carOut) {
1338
- chunks.push(chunk);
1339
- }
1340
- const blob = new Blob(chunks);
1341
- return blob;
1342
- }
1343
- async function carFromBlob(blob) {
1344
- return CarReader.fromBytes(new Uint8Array(await blob.arrayBuffer()));
1345
- }
1346
- function extractCids(value) {
1347
- if (value instanceof CID2) return [value];
1348
- if (Array.isArray(value)) return value.flatMap(extractCids);
1349
- if (value && typeof value === "object") return Object.values(value).flatMap(extractCids);
1350
- return [];
1351
- }
1352
- var MAX_COLLECT_BLOCKS = 1e6;
1353
- async function collectDagBlocks(startCID, blockStore) {
1354
- const visited = /* @__PURE__ */ new Set();
1355
- const blocks = [];
1356
- const queue = [startCID];
1357
- while (queue.length > 0) {
1358
- if (blocks.length >= MAX_COLLECT_BLOCKS) {
1359
- WARN(`[collectDagBlocks] hit ${MAX_COLLECT_BLOCKS} block limit, returning partial result`);
1360
- break;
1361
- }
1362
- const cid = queue.shift();
1363
- const cidStr = cid.toString();
1364
- if (visited.has(cidStr)) continue;
1365
- visited.add(cidStr);
1366
- let bytes;
1367
- try {
1368
- bytes = await blockStore.get(cid);
1369
- } catch {
1370
- WARN(`[collectDagBlocks] block not found: ${cidStr}, stopping this branch`);
1371
- continue;
1372
- }
1373
- if (!bytes) {
1374
- WARN(`[collectDagBlocks] block not found: ${cidStr}, stopping this branch`);
1375
- continue;
1376
- }
1377
- blocks.push({ cid, bytes });
1378
- if (blocks.length % 1e3 === 0) {
1379
- LOG(`[collectDagBlocks] collected ${blocks.length} blocks...`);
1380
- }
1381
- try {
1382
- const decoded = decode3(bytes);
1383
- const childCids = extractCids(decoded);
1384
- for (const child of childCids) {
1385
- if (!visited.has(child.toString())) {
1386
- queue.push(child);
1387
- }
1388
- }
1389
- } catch {
1390
- }
1391
- }
1392
- DEBUG(`[collectDagBlocks] collected ${blocks.length} blocks from ${startCID.toString()}`);
1393
- return blocks;
1394
- }
1395
- function streamReaderToIterable(bodyReader) {
1396
- return (async function* () {
1397
- while (true) {
1398
- const { done, value } = await bodyReader.read();
1399
- VERBOSE(`[car] chunk`, { done, value });
1400
- if (done) {
1401
- break;
1402
- }
1403
- yield value;
1404
- }
1405
- })();
1406
- }
1407
-
1408
- // src/pubsub/snap-push.ts
1409
- var { WARN: WARN2, LOG: LOG2, DEBUG: DEBUG2, VERBOSE: VERBOSE2, ERROR: ERROR2 } = g.setup(g.INFO);
1410
- async function prepareSnapshotForPush(agent, appThread, threadToPublish, share, prevSnapCID, prevCounter) {
1411
- if (prevCounter !== null && !prevSnapCID) {
1412
- throw ERROR2("[prepareSnapshotForPush] prevCounter provided without prevSnapCID");
1413
- }
1414
- let logsToPublish = getLogsFromThread(threadToPublish);
1415
- DEBUG2(`[preparePubForPush] Collected ${logsToPublish.length} logs :`, {
1416
- logsToPublish,
1417
- threadOrLogsCount: threadToPublish.nameAndSizeUntracked || `[${threadToPublish.length}]`
1418
- });
1419
- const { sharedAgents, sharedKeyMap, sharedKey, pubCounter } = share ?? {};
1420
- const getExistingOrNewLog = (thread, share2, ag, at, vl) => {
1421
- let logInQuestion = rollingFilter(lastWriteWins(thread), { en: share2.id, at }).latestLog;
1422
- if (!logInQuestion && vl !== void 0) {
1423
- logInQuestion = ensureTsPvAndFinalizeApplog({ ag, en: share2.id, at, vl }, thread);
1424
- }
1425
- return logInQuestion;
1426
- };
1427
- const shareNameLog = getExistingOrNewLog(appThread, share, agent.ag, "share/name", share.name);
1428
- const shareCounterLog = getExistingOrNewLog(appThread, share, agent.ag, "share/counter", `${agent.did}<::>${pubCounter}`);
1429
- const encryptApplog = async (applog, keyToUse) => {
1430
- const { log: eachLog, cid } = prepareForPub(applog);
1431
- const enc = new TextEncoder();
1432
- const stringified = wrapper_default(eachLog);
1433
- const stringifiedEncodedAppLogPayload = enc.encode(stringified);
1434
- VERBOSE2("[odd]", { eachLog, stringified, stringifiedEncodedAppLogPayload });
1435
- try {
1436
- const encPayload = await agent.crypto?.aes.encrypt(stringifiedEncodedAppLogPayload, keyToUse, "AES-GCM");
1437
- VERBOSE2("[odd] encrypted length:", stringifiedEncodedAppLogPayload.length, { encPayload });
1438
- return encPayload;
1439
- } catch (err) {
1440
- throw ERROR2("FAILED TO ENC payload length:", stringifiedEncodedAppLogPayload.length, { err });
1441
- }
1442
- };
1443
- let maybeEncryptedApplogs;
1444
- const encryptedApplogs = [];
1445
- const agentSharedKeyLogs = [];
1446
- if (sharedAgents) {
1447
- if (!sharedKey || !sharedKeyMap) {
1448
- throw ERROR2("sharedAgents but no Keys/Map", { sharedAgents, sharedKeyMap, sharedKey });
1449
- }
1450
- VERBOSE2("encrypting", { sharedAgents, sharedKeyMap });
1451
- for (const [eachAgent, eachEncKey] of Array.from(sharedKeyMap.entries())) {
1452
- VERBOSE2("adding key", { eachAgent, eachEncKey });
1453
- agentSharedKeyLogs.push({
1454
- ag: agent.ag,
1455
- en: eachAgent,
1456
- at: "share/sharedKey",
1457
- vl: eachEncKey
1458
- // these are encrypted with the derived key from the local agent private and remote agent public keys
1459
- });
1460
- }
1461
- const CIDlist = [];
1462
- const pubCIDmap = {};
1463
- for (const eachLog of logsToPublish) {
1464
- VERBOSE2("[crypto] encrypting ", { eachLog, sharedKey });
1465
- const encPayload = await encryptApplog(eachLog, sharedKey);
1466
- DEBUG2("[crypto] encrypted ", { eachLog, encPayload, sharedKey });
1467
- encryptedApplogs.push({ enc: encPayload });
1468
- }
1469
- maybeEncryptedApplogs = encryptedApplogs;
1470
- } else {
1471
- maybeEncryptedApplogs = logsToPublish;
1472
- }
1473
- DEBUG2("adding all agent info and shareAtoms", {
1474
- share,
1475
- agent,
1476
- logsToPublish,
1477
- // threadToPublish, - very verbose
1478
- agentSharedKeyLogs
1479
- });
1480
- const infoLogs = [
1481
- ...rollingFilter(lastWriteWins(appThread), {
1482
- // TODO: use static filter for performance
1483
- en: agent.ag,
1484
- at: ["agent/ecdh", "agent/jwkd", "agent/appAgent"]
1485
- }).applogs,
1486
- ...shareNameLog ? [shareNameLog] : [],
1487
- ...shareCounterLog ? [shareCounterLog] : [],
1488
- ...agentSharedKeyLogs
1489
- ];
1490
- DEBUG2(`[prepareSnapshotForPush] info logs:`, infoLogs);
1491
- if (!infoLogs.find(({ at }) => at === "agent/appAgent")) throw ERROR2(`[prepareSnapshotForPush] appThread missing agent/appAgent log`);
1492
- const applogsToEncode = keepTruthy(maybeEncryptedApplogs);
1493
- const infologsToEncode = keepTruthy(infoLogs);
1494
- if (!applogsToEncode.length) {
1495
- throw ERROR2("no valid applogs", { agent, maybeEncryptedApplogs, infoLogs, applogsToEncode, infologsToEncode, prevSnapCID });
1496
- }
1497
- if (!infologsToEncode.length) {
1498
- throw ERROR2("no valid infologs", { agent, maybeEncryptedApplogs, infoLogs, applogsToEncode, infologsToEncode, prevSnapCID });
1499
- }
1500
- const encodedSnapshot = await encodeSnapshotAsCar(agent, applogsToEncode, infologsToEncode, prevSnapCID, prevCounter);
1501
- DEBUG2("inPrepareSnapshotForPush", { encodedSnapshot });
1502
- return encodedSnapshot;
1503
- }
1504
- async function encodeSnapshotAsCar(agent, applogs, infoLogs, prevSnapCID, prevCounter) {
1505
- DEBUG2(`[encodeSnapshotAsCar] encoding`, { agent, applogs, infoLogs });
1506
- const { cids: infoLogCids, encodedApplogs: encodedInfoLogs } = await encodeApplogsAsIPLD(infoLogs);
1507
- const { cids: applogCids, encodedApplogs } = await encodeApplogsAsIPLD(applogs);
1508
- let blocks = encodedApplogs.concat(encodedInfoLogs);
1509
- const infoLogsWrap = await encodeBlockOriginal({ logs: infoLogCids });
1510
- blocks.push(infoLogsWrap);
1511
- const { rootCID: chunkRootCID, blocks: chunkBlocks } = await chunkApplogs(applogCids);
1512
- blocks = blocks.concat(chunkBlocks);
1513
- const infoSignature = await agent.sign(infoLogsWrap.cid.bytes);
1514
- const applogsSignature = await agent.sign(chunkRootCID.bytes);
1515
- const root = {
1516
- info: infoLogsWrap.cid,
1517
- applogs: chunkRootCID,
1518
- infoSignature,
1519
- applogsSignature,
1520
- prev: prevSnapCID,
1521
- prevCounter: !prevSnapCID ? 0 : prevCounter !== null ? prevCounter + 1 : null
1522
- };
1523
- DEBUG2("[encodeSnapshotAsCar] encoding root", { root, logCids: applogCids, infoLogCids });
1524
- const encodedRoot = await encodeBlockOriginal(root);
1525
- blocks.push(encodedRoot);
1526
- DEBUG2("[encodeSnapshotAsCar] => root", { encodedRoot });
1527
- return {
1528
- cid: encodedRoot.cid,
1529
- blob: await makeCarBlob(encodedRoot.cid, blocks),
1530
- // TODO: create CarBuilder (incl .encodeAndAdd({...}))
1531
- blocks,
1532
- infoLogCids,
1533
- applogCids
1534
- };
1535
- }
1536
- async function chunkApplogs(applogCids, size = 1e4) {
1537
- if (!applogCids.length) throw ERROR2(`[chunkApplogs] called with empty array`);
1538
- const chunks = [];
1539
- for (let i = 0; i < applogCids.length; i += size) {
1540
- const chunk = await encodeBlockOriginal({ logs: applogCids.slice(i, Math.min(i + applogCids.length, i + size)) });
1541
- chunks.push(chunk);
1542
- }
1543
- if (chunks.length === 1) return { rootCID: chunks[0].cid, blocks: chunks };
1544
- const root = await encodeBlockOriginal({ chunks: chunks.map((chunk) => chunk.cid) });
1545
- const blocks = [root, ...chunks];
1546
- DEBUG2(`[chunkApplogs] ${applogCids.length} logs chunked into ${chunks.length}`, { applogCids, root, blocks, chunks, dagJson: src_exports });
1547
- return { rootCID: root.cid, blocks, chunks };
1548
- }
1549
- async function unchunkApplogsBlock(block, blockStore) {
1550
- if (isSnapBlockChunks(block)) {
1551
- return (await Promise.all(
1552
- block.chunks.map(async (chunkCid) => {
1553
- const block2 = await getDecodedBlock(blockStore, chunkCid);
1554
- if (!block2.logs) throw ERROR2(`Weird chunk`, block2);
1555
- return block2.logs;
1556
- })
1557
- )).flat();
1558
- } else {
1559
- return block.logs;
1560
- }
1561
- }
1562
- function isSnapBlockChunks(block) {
1563
- return block.chunks;
1564
- }
1565
- async function encodeSnapshotApplogsAsCar(applogs) {
1566
- const encoded = await encodeApplogsAsIPLD(applogs);
1567
- if (!encoded) throw ERROR2("invalid applogs cannot continue", { applogs, encoded });
1568
- const { cids, encodedApplogs } = encoded;
1569
- const root = { applogs: cids };
1570
- const encodedRoot = await encodeBlockOriginal(root);
1571
- DEBUG2("[encodeSnapshotApplogsAsCar] encoded root", { cids, encodedRoot });
1572
- return await makeCarBlob(encodedRoot.cid, [encodedRoot, ...encodedApplogs]);
1573
- }
1574
- async function encodeApplogsAsIPLD(applogs) {
1575
- DEBUG2({ applogs });
1576
- const validApplogs = applogs.filter((eachLog) => !!eachLog);
1577
- DEBUG2({ validApplogs });
1578
- if (!validApplogs.length) throw ERROR2("no valid applogs");
1579
- const preppedLogs = validApplogs.map((log) => prepareForPub(log).log);
1580
- const encodedApplogs = await Promise.all(preppedLogs.map(encodeBlockOriginal));
1581
- DEBUG2("[encodeApplogsAsIpld] encoded applogs", { preppedLogs, encodedApplogs });
1582
- const cids = encodedApplogs.map((b) => {
1583
- if (!b.cid) throw ERROR2(`[publish] no cid for encoded log:`, b);
1584
- return b.cid;
1585
- });
1586
- return { cids, encodedApplogs };
1587
- }
1588
-
1589
- export {
1590
- prepareSnapshotForPush,
1591
- encodeSnapshotAsCar,
1592
- chunkApplogs,
1593
- unchunkApplogsBlock,
1594
- isSnapBlockChunks,
1595
- encodeSnapshotApplogsAsCar,
1596
- decodePubFromCar,
1597
- decodePubFromBlocks,
1598
- getBlocksOfCar,
1599
- getDecodedBlock,
1600
- makeCarOut,
1601
- makeCarBlob,
1602
- carFromBlob,
1603
- collectDagBlocks,
1604
- streamReaderToIterable
1605
- };
1606
- //# sourceMappingURL=chunk-WXLCBTHX.min.js.map