@peerbit/blocks 4.1.9 → 4.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.
@@ -5,12 +5,15 @@ import { DirectStream } from "@peerbit/stream";
5
5
  import {} from "@peerbit/stream";
6
6
  import { createRequestTransportContext, } from "@peerbit/stream-interface";
7
7
  import { AnyBlockStore } from "./any-blockstore.js";
8
- import { BlockMessage, RemoteBlocks } from "./remote.js";
8
+ import { BlockMessage, BlockRequest, BlockResponse, RemoteBlocks } from "./remote.js";
9
9
  export class DirectBlock extends DirectStream {
10
10
  remoteBlocks;
11
11
  onDataFn;
12
12
  onPeerConnectedFn;
13
13
  constructor(components, options) {
14
+ if (options?.directory && options.localStore) {
15
+ throw new Error("DirectBlock options cannot include both directory and localStore");
16
+ }
14
17
  super(components, ["/peerbit/direct-block/1.0.0"], {
15
18
  messageProcessingConcurrency: options?.messageProcessingConcurrency || 10,
16
19
  canRelayMessage: options?.canRelayMessage ?? true,
@@ -18,8 +21,23 @@ export class DirectBlock extends DirectStream {
18
21
  dialer: false,
19
22
  pruner: false,
20
23
  },
24
+ rustCore: options?.rustCore,
21
25
  });
26
+ const blockExchange = this.rustCore?.blockExchange;
22
27
  const defaultResolveProviders = () => {
28
+ if (blockExchange) {
29
+ const negotiated = [...this.peers.keys()];
30
+ const connected = [];
31
+ for (const conn of this.components.connectionManager.getConnections()) {
32
+ try {
33
+ connected.push(getPublicKeyFromPeerId(conn.remotePeer).hashcode());
34
+ }
35
+ catch {
36
+ // ignore unexpected key types
37
+ }
38
+ }
39
+ return blockExchange.defaultProviderCandidates(negotiated, connected, this.publicKeyHash);
40
+ }
23
41
  const out = [];
24
42
  const push = (hash) => {
25
43
  if (!hash)
@@ -53,8 +71,8 @@ export class DirectBlock extends DirectStream {
53
71
  return out;
54
72
  };
55
73
  this.remoteBlocks = new RemoteBlocks({
56
- local: new AnyBlockStore(createStore(options?.directory)),
57
- publish: (message, options) => this.publish(serialize(message), options),
74
+ local: new AnyBlockStore(options?.localStore ?? createStore(options?.directory)),
75
+ publish: (message, options) => this.publish(this.encodeBlockMessage(message), options),
58
76
  localTimeout: options?.localTimeout || 1000,
59
77
  messageProcessingConcurrency: options?.messageProcessingConcurrency || 10,
60
78
  waitFor: this.waitFor.bind(this),
@@ -65,32 +83,95 @@ export class DirectBlock extends DirectStream {
65
83
  onPut: options?.onPut,
66
84
  providerCache: options?.providerCache,
67
85
  requeryOnReachable: options?.requeryOnReachable,
86
+ rust: blockExchange
87
+ ? {
88
+ exchange: blockExchange,
89
+ publishRaw: (payload, options) => this.publish(payload, options),
90
+ }
91
+ : undefined,
68
92
  });
69
93
  this.onDataFn = (data) => {
70
- data.detail?.data?.length &&
71
- data.detail?.data.length > 0 &&
72
- this.remoteBlocks.onMessage(deserialize(data.detail.data, BlockMessage), {
73
- from: data.detail.header.signatures?.publicKeys[0]?.hashcode(),
74
- transport: createRequestTransportContext(data.detail),
75
- });
94
+ if (!(data.detail?.data?.length && data.detail.data.length > 0)) {
95
+ return;
96
+ }
97
+ let message;
98
+ try {
99
+ message = this.decodeBlockMessage(data.detail.data);
100
+ }
101
+ catch {
102
+ // Drop undecodable frames instead of letting the throw escape
103
+ // the 'data' listener (an uncaughtException in Node). The TS
104
+ // borsh decoder tolerates malformed frames lossily and fails
105
+ // later inside handleFetchRequest, which is caught; the native
106
+ // decoder throws on e.g. non-UTF-8 cid bytes, so match the
107
+ // tolerant behaviour here.
108
+ return;
109
+ }
110
+ this.remoteBlocks.onMessage(message, {
111
+ from: data.detail.header.signatures?.publicKeys[0]?.hashcode(),
112
+ transport: createRequestTransportContext(data.detail),
113
+ });
76
114
  };
77
115
  this.onPeerConnectedFn = (evt) => this.remoteBlocks.onReachable(evt.detail);
78
116
  }
117
+ encodeBlockMessage(message) {
118
+ const blockExchange = this.rustCore?.blockExchange;
119
+ if (blockExchange) {
120
+ if (message instanceof BlockRequest) {
121
+ return blockExchange.encodeBlockRequest(message.cid);
122
+ }
123
+ if (message instanceof BlockResponse) {
124
+ return blockExchange.encodeBlockResponse(message.cid, message.bytes);
125
+ }
126
+ }
127
+ return serialize(message);
128
+ }
129
+ decodeBlockMessage(bytes) {
130
+ const blockExchange = this.rustCore?.blockExchange;
131
+ if (blockExchange) {
132
+ const decoded = blockExchange.decodeBlockMessage(bytes);
133
+ return decoded.type === "request"
134
+ ? new BlockRequest(decoded.cid)
135
+ : new BlockResponse(decoded.cid, decoded.bytes);
136
+ }
137
+ return deserialize(bytes, BlockMessage);
138
+ }
139
+ getNativeLogBlockStoreHandle() {
140
+ return this.remoteBlocks.getNativeLogBlockStoreHandle();
141
+ }
79
142
  async put(bytes) {
80
143
  return this.remoteBlocks.put(bytes);
81
144
  }
145
+ async putMany(blocks) {
146
+ return this.remoteBlocks.putMany(blocks);
147
+ }
148
+ async putKnown(cid, bytes) {
149
+ return this.remoteBlocks.putKnown(cid, bytes);
150
+ }
151
+ async putKnownMany(blocks) {
152
+ return this.remoteBlocks.putKnownMany(blocks);
153
+ }
82
154
  async has(cid) {
83
155
  return this.remoteBlocks.has(cid);
84
156
  }
157
+ async hasMany(cids) {
158
+ return this.remoteBlocks.hasMany(cids);
159
+ }
85
160
  async get(cid, options) {
86
161
  return this.remoteBlocks.get(cid, options);
87
162
  }
163
+ async getMany(cids, options) {
164
+ return this.remoteBlocks.getMany(cids, options);
165
+ }
88
166
  hintProviders(cid, providers) {
89
167
  this.remoteBlocks.hintProviders(cid, providers);
90
168
  }
91
169
  async rm(cid) {
92
170
  return this.remoteBlocks.rm(cid);
93
171
  }
172
+ async rmMany(cids) {
173
+ return this.remoteBlocks.rmMany(cids);
174
+ }
94
175
  async *iterator() {
95
176
  for await (const [key, value] of this.remoteBlocks.iterator()) {
96
177
  yield [key, value];
@@ -1 +1 @@
1
- {"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAA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,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,YAAY,EAAE,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC;IAClD,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;CACD"}
@@ -1,9 +1,8 @@
1
1
  import { type GetOptions, type Blocks as IBlocks } from "@peerbit/blocks-interface";
2
2
  import { PublicSignKey } from "@peerbit/crypto";
3
- import { type PublishOptions } from "@peerbit/stream";
3
+ import { type PublishOptions, type RustBlockExchange } from "@peerbit/stream";
4
4
  import { type RequestTransportContext, type PeerRefs, type WaitForAnyOpts, type WaitForPeersFn, type WaitForPresentOpts } from "@peerbit/stream-interface";
5
5
  import { type Block } from "multiformats/block";
6
- import { AnyBlockStore } from "./any-blockstore.js";
7
6
  import type { BlockStore } from "./interface.js";
8
7
  export declare const logger: import("@libp2p/interface").Logger;
9
8
  export declare class BlockMessage {
@@ -23,7 +22,7 @@ type BlockMessageContext = {
23
22
  };
24
23
  export declare class RemoteBlocks implements IBlocks {
25
24
  readonly options: {
26
- local: AnyBlockStore;
25
+ local: BlockStore;
27
26
  localTimeout?: number;
28
27
  messageProcessingConcurrency?: number;
29
28
  publicKey: PublicSignKey;
@@ -79,22 +78,37 @@ export declare class RemoteBlocks implements IBlocks {
79
78
  requeryOnReachable?: number;
80
79
  publish: (data: BlockRequest | BlockResponse, options: PublishOptions) => Promise<Uint8Array | undefined | void>;
81
80
  waitFor: WaitForPeersFn;
81
+ /**
82
+ * Native block-exchange components (rust-core mode). When set, the
83
+ * provider caches/decisions and eager-block bookkeeping run in the
84
+ * native core; `publishRaw` additionally enables serving natively
85
+ * stored blocks as wasm-serialized payloads that never surface the
86
+ * block bytes to JS.
87
+ */
88
+ rust?: {
89
+ exchange: RustBlockExchange;
90
+ publishRaw?: (payload: Uint8Array, options: PublishOptions) => Promise<Uint8Array | undefined | void>;
91
+ };
82
92
  };
83
93
  localStore: BlockStore;
84
94
  private _responseHandler?;
85
95
  private _resolvers;
86
96
  private _blockCache?;
87
97
  private _providerCache?;
98
+ private _rustProviderCache?;
99
+ private readonly rustExchange?;
88
100
  private readonly publicKeyHash;
89
101
  private readonly maxProviderHintsPerCid;
90
102
  private readonly maxRequeryOnReachable;
91
103
  private _loadFetchQueue;
92
104
  private _readFromPeersPromises;
105
+ private _deferredStoredNotificationCids?;
106
+ private _deferredStoredNotificationTimer?;
93
107
  _open: boolean;
94
108
  private _events;
95
109
  private closeController;
96
110
  constructor(options: {
97
- local: AnyBlockStore;
111
+ local: BlockStore;
98
112
  localTimeout?: number;
99
113
  messageProcessingConcurrency?: number;
100
114
  publicKey: PublicSignKey;
@@ -150,20 +164,50 @@ export declare class RemoteBlocks implements IBlocks {
150
164
  requeryOnReachable?: number;
151
165
  publish: (data: BlockRequest | BlockResponse, options: PublishOptions) => Promise<Uint8Array | undefined | void>;
152
166
  waitFor: WaitForPeersFn;
167
+ /**
168
+ * Native block-exchange components (rust-core mode). When set, the
169
+ * provider caches/decisions and eager-block bookkeeping run in the
170
+ * native core; `publishRaw` additionally enables serving natively
171
+ * stored blocks as wasm-serialized payloads that never surface the
172
+ * block bytes to JS.
173
+ */
174
+ rust?: {
175
+ exchange: RustBlockExchange;
176
+ publishRaw?: (payload: Uint8Array, options: PublishOptions) => Promise<Uint8Array | undefined | void>;
177
+ };
153
178
  });
179
+ getNativeLogBlockStoreHandle(): unknown;
154
180
  private normalizeProviderHints;
155
181
  private rememberProvider;
156
182
  private rememberProviderHints;
183
+ private getCachedProviders;
157
184
  private pickRequestBatch;
158
185
  private resolveRemoteProviders;
159
186
  put(bytes: Uint8Array | {
160
187
  block: Block<any, any, any, any>;
161
188
  cid: string;
162
189
  }): Promise<string>;
190
+ putMany(blocks: Array<Uint8Array | {
191
+ block: Block<any, any, any, any>;
192
+ cid: string;
193
+ }>): Promise<string[]>;
194
+ putKnown(cid: string, bytes: Uint8Array): Promise<string>;
195
+ putKnownMany(blocks: Array<readonly [cid: string, bytes: Uint8Array]>): Promise<string[]>;
196
+ hasNotifyStoredHook(): boolean;
197
+ notifyStored(cid: string): Promise<void> | void;
198
+ notifyStoredMany(cids: string[]): Promise<void> | void;
199
+ notifyStoredDeferred(cid: string): void;
200
+ notifyStoredManyDeferred(cids: string[]): void;
201
+ private flushDeferredStoredNotifications;
202
+ private notifyPut;
203
+ private notifyPuts;
163
204
  has(cid: string): Promise<boolean>;
205
+ hasMany(cids: string[]): Promise<boolean[]>;
164
206
  get(cid: string, options?: GetOptions | undefined): Promise<Uint8Array | undefined>;
207
+ getMany(cids: string[], options?: GetOptions | undefined): Promise<Array<Uint8Array | undefined>>;
165
208
  hintProviders(cid: string, providers: string[]): void;
166
209
  rm(cid: string): Promise<void>;
210
+ rmMany(cids: string[]): Promise<void>;
167
211
  iterator(): AsyncGenerator<[string, Uint8Array], void, void>;
168
212
  start(): Promise<void>;
169
213
  onMessage(data: BlockMessage, context?: BlockMessageContext): any;
@@ -1 +1 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,UAAU,EACf,KAAK,MAAM,IAAI,OAAO,EAKtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,KAAK,cAAc,EAA4B,MAAM,iBAAiB,CAAC;AAChF,OAAO,EACN,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EAEb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,KAAK,KAAK,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M,EAAE,SAAS,EAAE,MAAM,EAAE;IAQxC,EAAE,CAAC,GAAG,EAAE,MAAM;IAId,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;IAIpB,QAAQ,IAAI,cAAc,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;IAM7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,mBAAmB;IAG3D,WAAW,CAAC,SAAS,EAAE,aAAa;YAMtB,kBAAkB;YAqFlB,cAAc;IA4P5B,OAAO,CAAC,mBAAmB;IA6CrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB3B,OAAO,CACN,IAAI,EAAE,QAAQ,EACd,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc,GAC3C,OAAO,CAAC,MAAM,EAAE,CAAC;IAId,IAAI;IAIV,IAAI,MAAM,yCAMT;IAED,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAGvC"}
@@ -38,13 +38,12 @@ import { checkDecodeBlock, cidifyString, codecCodes, stringifyCid, } from "@peer
38
38
  import { Cache } from "@peerbit/cache";
39
39
  import { PublicSignKey } from "@peerbit/crypto";
40
40
  import { logger as loggerFn } from "@peerbit/logger";
41
- import { dontThrowIfDeliveryError } from "@peerbit/stream";
41
+ import { dontThrowIfDeliveryError, } from "@peerbit/stream";
42
42
  import { SilentDelivery, } from "@peerbit/stream-interface";
43
43
  import { AbortError } from "@peerbit/time";
44
44
  import { CID } from "multiformats";
45
45
  import {} from "multiformats/block";
46
46
  import PQueue from "p-queue";
47
- import { AnyBlockStore } from "./any-blockstore.js";
48
47
  export const logger = loggerFn("peerbit:transport:blocks");
49
48
  const warn = logger.newScope("warn");
50
49
  export class BlockMessage {
@@ -123,11 +122,15 @@ export class RemoteBlocks {
123
122
  _resolvers;
124
123
  _blockCache;
125
124
  _providerCache;
125
+ _rustProviderCache;
126
+ rustExchange;
126
127
  publicKeyHash;
127
128
  maxProviderHintsPerCid;
128
129
  maxRequeryOnReachable;
129
130
  _loadFetchQueue;
130
131
  _readFromPeersPromises;
132
+ _deferredStoredNotificationCids;
133
+ _deferredStoredNotificationTimer;
131
134
  _open = false;
132
135
  _events = new TypedEventEmitter();
133
136
  closeController = new AbortController();
@@ -135,31 +138,42 @@ export class RemoteBlocks {
135
138
  this.options = options;
136
139
  const localTimeout = options?.localTimeout || 1000;
137
140
  this.publicKeyHash = options.publicKey.hashcode();
141
+ this.rustExchange = options.rust?.exchange;
138
142
  this._loadFetchQueue = new PQueue({
139
143
  concurrency: options?.messageProcessingConcurrency || 10,
140
144
  });
141
145
  this.localStore = options?.local;
142
146
  this._resolvers = new Map();
143
147
  this._readFromPeersPromises = new Map();
144
- this._blockCache = options?.eagerBlocks
145
- ? new Cache({
146
- max: typeof options.eagerBlocks === "boolean"
147
- ? 1e3
148
- : (options.eagerBlocks.cacheSize ?? 1e3),
149
- ttl: 1e4,
150
- })
151
- : undefined;
148
+ if (options?.eagerBlocks) {
149
+ const eagerBlocksMax = typeof options.eagerBlocks === "boolean"
150
+ ? 1e3
151
+ : (options.eagerBlocks.cacheSize ?? 1e3);
152
+ this._blockCache = this.rustExchange
153
+ ? this.rustExchange.createEagerCache({ max: eagerBlocksMax, ttl: 1e4 })
154
+ : new Cache({ max: eagerBlocksMax, ttl: 1e4 });
155
+ }
152
156
  const providerCache = options.providerCache === false
153
157
  ? undefined
154
158
  : typeof options.providerCache === "object"
155
159
  ? options.providerCache
156
160
  : {};
157
- this._providerCache = providerCache
158
- ? new Cache({
159
- max: providerCache.maxEntries ?? 2048,
160
- ttl: providerCache.ttlMs ?? 10 * 60 * 1000,
161
- })
162
- : undefined;
161
+ if (providerCache) {
162
+ if (this.rustExchange) {
163
+ this._rustProviderCache = this.rustExchange.createProviderCache({
164
+ me: this.publicKeyHash,
165
+ maxEntries: providerCache.maxEntries ?? 2048,
166
+ ttlMs: providerCache.ttlMs ?? 10 * 60 * 1000,
167
+ maxProvidersPerCid: providerCache.maxProvidersPerCid ?? 8,
168
+ });
169
+ }
170
+ else {
171
+ this._providerCache = new Cache({
172
+ max: providerCache.maxEntries ?? 2048,
173
+ ttl: providerCache.ttlMs ?? 10 * 60 * 1000,
174
+ });
175
+ }
176
+ }
163
177
  this.maxProviderHintsPerCid = providerCache?.maxProvidersPerCid ?? 8;
164
178
  this.maxRequeryOnReachable = options.requeryOnReachable ?? 4;
165
179
  this._responseHandler = async (message, context) => {
@@ -199,9 +213,15 @@ export class RemoteBlocks {
199
213
  }
200
214
  };
201
215
  }
216
+ getNativeLogBlockStoreHandle() {
217
+ return this.localStore.getNativeLogBlockStoreHandle?.();
218
+ }
202
219
  normalizeProviderHints(providers, limit = this.maxProviderHintsPerCid || 8) {
203
220
  if (!providers || providers.length === 0)
204
221
  return [];
222
+ if (this.rustExchange) {
223
+ return this.rustExchange.normalizeProviderHints(providers, this.publicKeyHash, limit);
224
+ }
205
225
  const out = [];
206
226
  for (const p of providers) {
207
227
  if (!p)
@@ -218,6 +238,10 @@ export class RemoteBlocks {
218
238
  return out;
219
239
  }
220
240
  rememberProvider(cidString, providerHash) {
241
+ if (this._rustProviderCache) {
242
+ this._rustProviderCache.rememberProvider(cidString, providerHash);
243
+ return;
244
+ }
221
245
  if (!this._providerCache)
222
246
  return;
223
247
  if (!providerHash || providerHash === this.publicKeyHash)
@@ -236,6 +260,10 @@ export class RemoteBlocks {
236
260
  this._providerCache.add(cidString, next);
237
261
  }
238
262
  rememberProviderHints(cidString, providers) {
263
+ if (this._rustProviderCache) {
264
+ this._rustProviderCache.rememberHints(cidString, providers);
265
+ return;
266
+ }
239
267
  if (!this._providerCache)
240
268
  return;
241
269
  const normalized = this.normalizeProviderHints(providers);
@@ -243,7 +271,15 @@ export class RemoteBlocks {
243
271
  return;
244
272
  this._providerCache.add(cidString, normalized);
245
273
  }
274
+ getCachedProviders(cidString) {
275
+ return this._rustProviderCache
276
+ ? this._rustProviderCache.get(cidString)
277
+ : (this._providerCache?.get(cidString) ?? undefined);
278
+ }
246
279
  pickRequestBatch(providers, attempt) {
280
+ if (this.rustExchange) {
281
+ return this.rustExchange.pickRequestBatch(providers, this.publicKeyHash, attempt);
282
+ }
247
283
  if (providers.length <= 1) {
248
284
  return providers;
249
285
  }
@@ -259,7 +295,7 @@ export class RemoteBlocks {
259
295
  // Priority:
260
296
  // 1. cached providers (from previous reads)
261
297
  // 2. resolveProviders hook (e.g. program-level replicators, DHT, tracker)
262
- const cached = this.normalizeProviderHints(this._providerCache?.get(cidString) ?? undefined);
298
+ const cached = this.normalizeProviderHints(this.getCachedProviders(cidString));
263
299
  if (!this.options.resolveProviders)
264
300
  return cached;
265
301
  if (cached.length > 0 && !options?.refresh)
@@ -281,17 +317,130 @@ export class RemoteBlocks {
281
317
  throw new Error("Local store not set");
282
318
  }
283
319
  const cid = await this.localStore.put(bytes);
320
+ await this.notifyPut(cid);
321
+ return cid;
322
+ }
323
+ async putMany(blocks) {
324
+ if (!this.localStore) {
325
+ throw new Error("Local store not set");
326
+ }
327
+ const cids = await this.localStore.putMany(blocks);
328
+ await this.notifyPuts(cids);
329
+ return cids;
330
+ }
331
+ async putKnown(cid, bytes) {
332
+ if (!this.localStore) {
333
+ throw new Error("Local store not set");
334
+ }
335
+ const storedCid = await this.localStore.putKnown(cid, bytes);
336
+ await this.notifyPut(storedCid);
337
+ return storedCid;
338
+ }
339
+ async putKnownMany(blocks) {
340
+ if (!this.localStore) {
341
+ throw new Error("Local store not set");
342
+ }
343
+ const cids = await this.localStore.putKnownMany(blocks);
344
+ await this.notifyPuts(cids);
345
+ return cids;
346
+ }
347
+ hasNotifyStoredHook() {
348
+ return !!this.options.onPut;
349
+ }
350
+ notifyStored(cid) {
351
+ return this.notifyPut(cid);
352
+ }
353
+ notifyStoredMany(cids) {
354
+ return this.notifyPuts(cids);
355
+ }
356
+ notifyStoredDeferred(cid) {
357
+ this.notifyStoredManyDeferred([cid]);
358
+ }
359
+ notifyStoredManyDeferred(cids) {
360
+ if (!this.options.onPut || cids.length === 0) {
361
+ return;
362
+ }
363
+ let pending = this._deferredStoredNotificationCids;
364
+ if (!pending) {
365
+ pending = new Set();
366
+ this._deferredStoredNotificationCids = pending;
367
+ }
368
+ for (const cid of cids) {
369
+ if (cid) {
370
+ pending.add(cid);
371
+ }
372
+ }
373
+ if (pending.size === 0 || this._deferredStoredNotificationTimer) {
374
+ return;
375
+ }
376
+ this._deferredStoredNotificationTimer = setTimeout(() => {
377
+ this._deferredStoredNotificationTimer = undefined;
378
+ const flushed = this.flushDeferredStoredNotifications();
379
+ if (flushed && typeof flushed.catch === "function") {
380
+ flushed.catch(() => undefined);
381
+ }
382
+ }, 0);
383
+ }
384
+ flushDeferredStoredNotifications() {
385
+ const pending = this._deferredStoredNotificationCids;
386
+ if (!pending || pending.size === 0) {
387
+ return;
388
+ }
389
+ this._deferredStoredNotificationCids = undefined;
390
+ const waits = [];
391
+ for (const cid of pending) {
392
+ try {
393
+ const result = this.notifyStored(cid);
394
+ if (result && typeof result.then === "function") {
395
+ waits.push(result);
396
+ }
397
+ }
398
+ catch {
399
+ // ignore best-effort hooks
400
+ }
401
+ }
402
+ if (waits.length > 0) {
403
+ return Promise.all(waits).then(() => undefined);
404
+ }
405
+ }
406
+ notifyPut(cid) {
407
+ const onPut = this.options.onPut;
408
+ if (!onPut) {
409
+ return;
410
+ }
284
411
  try {
285
- await this.options.onPut?.(cid);
412
+ const result = onPut(cid);
413
+ if (result && typeof result.then === "function") {
414
+ return result.catch(() => undefined);
415
+ }
286
416
  }
287
417
  catch {
288
418
  // ignore best-effort hooks
289
419
  }
290
- return cid;
420
+ }
421
+ notifyPuts(cids) {
422
+ const onPut = this.options.onPut;
423
+ if (!onPut || cids.length === 0) {
424
+ return;
425
+ }
426
+ if (cids.length === 1) {
427
+ return this.notifyPut(cids[0]);
428
+ }
429
+ return Promise.all(cids.map(async (cid) => {
430
+ try {
431
+ await onPut(cid);
432
+ }
433
+ catch {
434
+ // ignore best-effort hooks
435
+ }
436
+ })).then(() => undefined);
291
437
  }
292
438
  async has(cid) {
293
439
  return this.localStore.has(cid);
294
440
  }
441
+ async hasMany(cids) {
442
+ return this.localStore.hasMany(cids);
443
+ }
295
444
  async get(cid, options) {
296
445
  let value = this.localStore
297
446
  ? await this.localStore.get(cid, options)
@@ -309,6 +458,12 @@ export class RemoteBlocks {
309
458
  }
310
459
  return value;
311
460
  }
461
+ async getMany(cids, options) {
462
+ if (!options?.remote) {
463
+ return this.localStore.getMany(cids, options);
464
+ }
465
+ return Promise.all(cids.map((cid) => this.get(cid, options)));
466
+ }
312
467
  hintProviders(cid, providers) {
313
468
  const cidString = stringifyCid(cid);
314
469
  this.rememberProviderHints(cidString, providers);
@@ -317,6 +472,9 @@ export class RemoteBlocks {
317
472
  async rm(cid) {
318
473
  await this.localStore?.rm(cid);
319
474
  }
475
+ async rmMany(cids) {
476
+ await this.localStore?.rmMany(cids);
477
+ }
320
478
  async *iterator() {
321
479
  for await (const [key, value] of this.localStore.iterator()) {
322
480
  yield [key, value];
@@ -341,6 +499,20 @@ export class RemoteBlocks {
341
499
  return;
342
500
  }
343
501
  const cid = stringifyCid(request.cid);
502
+ const publishRaw = this.options.rust?.publishRaw;
503
+ if (publishRaw) {
504
+ // Native-store-served response: the borsh BlockResponse payload is
505
+ // serialized inside wasm straight from the native log block store,
506
+ // so the block bytes never materialize as a JS value.
507
+ const payload = this.localStore.getBlockResponsePayload?.(cid);
508
+ if (payload) {
509
+ const responsePublishOptions = context?.transport
510
+ ? context.transport.withResponseOptions({ to: [from] })
511
+ : { to: [from] };
512
+ await publishRaw(payload, responsePublishOptions).catch(dontThrowIfDeliveryError);
513
+ return;
514
+ }
515
+ }
344
516
  let bytes = await this.localStore.get(cid, {
345
517
  remote: {
346
518
  timeout: localTimeout,
@@ -657,6 +829,11 @@ export class RemoteBlocks {
657
829
  // Dont listen for more incoming messages
658
830
  // Wait for processing request
659
831
  this.closeController.abort();
832
+ if (this._deferredStoredNotificationTimer) {
833
+ clearTimeout(this._deferredStoredNotificationTimer);
834
+ this._deferredStoredNotificationTimer = undefined;
835
+ }
836
+ await this.flushDeferredStoredNotifications();
660
837
  this._loadFetchQueue.clear();
661
838
  await this._loadFetchQueue.onIdle(); // wait for pending
662
839
  await this.localStore?.stop();
@@ -664,6 +841,7 @@ export class RemoteBlocks {
664
841
  this._resolvers.clear();
665
842
  this._blockCache?.clear();
666
843
  this._providerCache?.clear();
844
+ this._rustProviderCache?.clear();
667
845
  this._open = false;
668
846
  // we dont cleanup subscription because we dont know if someone else is sbuscribing also
669
847
  }