Skip to content

Commit 5af159a

Browse files
chore: fmt
1 parent 5fdadce commit 5af159a

File tree

35 files changed

+759
-701
lines changed

35 files changed

+759
-701
lines changed

chai-global.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ if (
4646

4747
const now = () => Date.now();
4848

49-
const intervalMsRaw =
50-
process.env.PEERBIT_MOCHA_LOG_INTERVAL_MS ?? "30000";
49+
const intervalMsRaw = process.env.PEERBIT_MOCHA_LOG_INTERVAL_MS ?? "30000";
5150
const intervalMs = Number(intervalMsRaw);
5251
let interval;
5352
if (Number.isFinite(intervalMs) && intervalMs > 0) {

docs/modules/program/document-store/document-store.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ export class Channel extends Program<ChannelArgs> {
206206
},
207207
});
208208

209-
await this.reactions.open({
210-
type: Reaction,
211-
replicate: properties?.replicate,
209+
await this.reactions.open({
210+
type: Reaction,
211+
replicate: properties?.replicate,
212212

213-
// we don't provide an index here, which means we will index all fields of Reaction
214-
});
215-
}
213+
// we don't provide an index here, which means we will index all fields of Reaction
214+
});
216215
}
216+
}
217217
/// [definition]
218218

219219
/// [insert]

packages/clients/canonical/client/src/auto.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export type CanonicalOpenAdapter<
4848
}): Promise<CanonicalOpenResult<T>>;
4949
};
5050

51-
export const getProgramVariant = (program: Program<any>): string | undefined => {
51+
export const getProgramVariant = (
52+
program: Program<any>,
53+
): string | undefined => {
5254
if (!program || typeof program !== "object") return undefined;
5355
try {
5456
const schema = getSchema((program as any).constructor);

packages/clients/canonical/client/src/peerbit.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ export class PeerbitCanonicalClient {
282282
);
283283
if (!adapter) {
284284
const knownVariants = state.adapters
285-
.flatMap((candidate) =>
286-
candidate.variants ?? (candidate.variant ? [candidate.variant] : []),
285+
.flatMap(
286+
(candidate) =>
287+
candidate.variants ??
288+
(candidate.variant ? [candidate.variant] : []),
287289
)
288290
.filter((x): x is string => typeof x === "string" && x.length > 0);
289291
throw new Error(
@@ -293,7 +295,10 @@ export class PeerbitCanonicalClient {
293295
);
294296
}
295297

296-
const key = adapter.getKey?.(program as any, openOptions as OpenOptions<any>);
298+
const key = adapter.getKey?.(
299+
program as any,
300+
openOptions as OpenOptions<any>,
301+
);
297302
if (adapter.getKey && key === undefined) {
298303
throw new Error(
299304
`Canonical adapter '${adapter.name}' requires a cache key (adapter.getKey returned undefined)`,
@@ -328,14 +333,14 @@ export class PeerbitCanonicalClient {
328333
}
329334
}
330335

331-
const peer = this as any as ProgramClient;
332-
const openPromise = (async () => {
333-
const result = await adapter.open({
334-
program: program as any,
335-
options: openOptions as OpenOptions<any>,
336-
peer,
337-
client: this.canonical,
338-
});
336+
const peer = this as any as ProgramClient;
337+
const openPromise = (async () => {
338+
const result = await adapter.open({
339+
program: program as any,
340+
options: openOptions as OpenOptions<any>,
341+
peer,
342+
client: this.canonical,
343+
});
339344

340345
let managed: any;
341346
managed = createManagedProxy(result.proxy as any, {

packages/clients/test-utils/src/session.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { yamux } from "@chainsafe/libp2p-yamux";
22
import { DirectBlock } from "@peerbit/blocks";
33
import { keychain } from "@peerbit/keychain";
44
import {
5-
listenFast,
65
TestSession as SSession,
6+
listenFast,
77
transportsFast,
88
} from "@peerbit/libp2p-test-utils";
99
import { type ProgramClient } from "@peerbit/program";
@@ -119,7 +119,10 @@ export class TestSession {
119119
* Uses TCP-only transport (no WebRTC/WebSockets/circuit-relay) and disables
120120
* the libp2p relay service by default.
121121
*/
122-
static async connectedMock(n: number, options?: CreateOptions | CreateOptions[]) {
122+
static async connectedMock(
123+
n: number,
124+
options?: CreateOptions | CreateOptions[],
125+
) {
123126
const session = await TestSession.disconnectedMock(n, options);
124127
await session.connect();
125128
// TODO types
@@ -135,7 +138,9 @@ export class TestSession {
135138
n: number,
136139
options?: CreateOptions | CreateOptions[],
137140
) {
138-
const applyMockDefaults = (o?: CreateOptions): CreateOptions | undefined => {
141+
const applyMockDefaults = (
142+
o?: CreateOptions,
143+
): CreateOptions | undefined => {
139144
if (!o) {
140145
return {
141146
libp2p: {

packages/programs/data/document/document/benchmark/document-put.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,3 @@ try {
140140
await store.drop();
141141
await session.stop();
142142
}
143-

packages/programs/data/document/document/src/like.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type * as indexerTypes from "@peerbit/indexer-interface";
1111
import type { Program } from "@peerbit/program";
1212
import type { SharedLogLike } from "@peerbit/shared-log";
1313
import type { PeerRefs } from "@peerbit/stream-interface";
14+
import type { CountEstimate } from "./program.js";
1415
import type {
1516
GetOptions,
1617
QueryOptions,
@@ -21,7 +22,6 @@ import type {
2122
WithContext,
2223
WithIndexedContext,
2324
} from "./search.js";
24-
import type { CountEstimate } from "./program.js";
2525

2626
export type DocumentsLikeQuery =
2727
| SearchRequest

packages/programs/data/document/document/src/search.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,26 +4255,26 @@ export class DocumentIndex<
42554255
}
42564256
};
42574257

4258-
return {
4259-
close,
4260-
next,
4261-
done: doneFn,
4262-
pending: async () => {
4263-
try {
4264-
await fetchPromise;
4265-
// In push-update mode, remotes will stream new results proactively.
4266-
// After the iterator has been primed (`first === true`), calling
4267-
// `fetchAtLeast(1)` from `pending()` can double-count by pulling from
4268-
// the remote iterator while we also have pushed results buffered locally.
4269-
//
4270-
// We still need to prime the iterator at least once so `pending()` is meaningful
4271-
// even before the first `next(...)` call.
4272-
if (!done && keepRemoteAlive && (!pushUpdates || !first)) {
4273-
await fetchAtLeast(1);
4274-
}
4275-
} catch (error) {
4276-
warn("Failed to refresh iterator pending state", error);
4258+
return {
4259+
close,
4260+
next,
4261+
done: doneFn,
4262+
pending: async () => {
4263+
try {
4264+
await fetchPromise;
4265+
// In push-update mode, remotes will stream new results proactively.
4266+
// After the iterator has been primed (`first === true`), calling
4267+
// `fetchAtLeast(1)` from `pending()` can double-count by pulling from
4268+
// the remote iterator while we also have pushed results buffered locally.
4269+
//
4270+
// We still need to prime the iterator at least once so `pending()` is meaningful
4271+
// even before the first `next(...)` call.
4272+
if (!done && keepRemoteAlive && (!pushUpdates || !first)) {
4273+
await fetchAtLeast(1);
42774274
}
4275+
} catch (error) {
4276+
warn("Failed to refresh iterator pending state", error);
4277+
}
42784278

42794279
let total = 0;
42804280
for (const buffer of peerBufferMap.values()) {

packages/programs/data/document/document/test/index.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ import {
6666
PutOperation,
6767
PutWithKeyOperation,
6868
} from "../src/operation.js";
69-
import { Documents, type CountEstimate, type SetupOptions } from "../src/program.js";
69+
import {
70+
type CountEstimate,
71+
Documents,
72+
type SetupOptions,
73+
} from "../src/program.js";
7074
import {
7175
type CanRead,
7276
DocumentIndex,
@@ -7116,15 +7120,15 @@ describe("index", () => {
71167120

71177121
const expectedCount = Math.round(count / 2);
71187122

7119-
// The estimator is probabilistic; use the provided 95% margin, scaled
7120-
// up to ~99.9% to avoid CI flakes while still detecting regressions.
7121-
const assertWithinMargin = (result: CountEstimate) => {
7122-
expect(result.errorMargin).to.not.be.undefined;
7123-
const margin = Math.max(0.15, result.errorMargin! * (3.29 / 1.96));
7124-
expect(result.estimate).to.be.within(
7125-
expectedCount * (1 - margin),
7126-
expectedCount * (1 + margin),
7127-
);
7123+
// The estimator is probabilistic; use the provided 95% margin, scaled
7124+
// up to ~99.9% to avoid CI flakes while still detecting regressions.
7125+
const assertWithinMargin = (result: CountEstimate) => {
7126+
expect(result.errorMargin).to.not.be.undefined;
7127+
const margin = Math.max(0.15, result.errorMargin! * (3.29 / 1.96));
7128+
expect(result.estimate).to.be.within(
7129+
expectedCount * (1 - margin),
7130+
expectedCount * (1 + margin),
7131+
);
71287132
};
71297133
assertWithinMargin(approxCount1);
71307134
assertWithinMargin(approxCount2);

packages/programs/data/document/proxy/src/host.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import { Documents } from "@peerbit/document";
1515
import * as indexerTypes from "@peerbit/indexer-interface";
1616
import type { SharedLogService } from "@peerbit/shared-log-proxy";
1717
import { createSharedLogService } from "@peerbit/shared-log-proxy/host";
18-
import {
19-
DocumentsChange,
20-
DocumentsCountRequest,
21-
DocumentsGetRequest,
22-
DocumentsIndexPutRequest,
18+
import {
19+
DocumentsChange,
20+
DocumentsCountRequest,
21+
DocumentsGetRequest,
22+
DocumentsIndexPutRequest,
2323
DocumentsPutWithContextRequest,
2424
DocumentsRemoteOptions,
2525
DocumentsService,
@@ -389,20 +389,22 @@ export const documentModule: CanonicalModule = {
389389
request.context,
390390
);
391391
await (acquired.program.index as any).index.put(wrapped);
392-
},
393-
count: async (request: DocumentsCountRequest) => {
394-
const approximate = request?.approximate !== false;
395-
if (approximate) {
396-
const { estimate } = await acquired.program.count({ approximate: true });
397-
return BigInt(estimate);
398-
}
399-
const count = await acquired.program.index.getSize();
400-
return BigInt(count);
401-
},
402-
indexSize: async () => {
403-
const size = await acquired.program.index.getSize();
404-
return BigInt(size);
405-
},
392+
},
393+
count: async (request: DocumentsCountRequest) => {
394+
const approximate = request?.approximate !== false;
395+
if (approximate) {
396+
const { estimate } = await acquired.program.count({
397+
approximate: true,
398+
});
399+
return BigInt(estimate);
400+
}
401+
const count = await acquired.program.index.getSize();
402+
return BigInt(count);
403+
},
404+
indexSize: async () => {
405+
const size = await acquired.program.index.getSize();
406+
return BigInt(size);
407+
},
406408
waitFor: async (request: DocumentsWaitForRequest) => {
407409
const requestId = request.requestId;
408410
const controller = requestId ? new AbortController() : undefined;

0 commit comments

Comments
 (0)