Skip to content

Commit bdf65df

Browse files
committed
Polish backfill public API docs
Replace the package README's VitePress-only installation block with plain Markdown, document the new public API surface with since tags, and mark exported option and result properties as readonly. Export the request-budget error class so callers can identify it when it escapes traversal internals. Assisted-by: Codex:gpt-5
1 parent 0ad8d5d commit bdf65df

5 files changed

Lines changed: 42 additions & 36 deletions

File tree

packages/backfill/README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,14 @@ or `OrderedCollectionPage`.
2727
Installation
2828
------------
2929

30-
::: code-group
31-
32-
~~~~ sh [Deno]
30+
~~~~ sh
3331
deno add jsr:@fedify/backfill
32+
npm add @fedify/backfill
33+
pnpm add @fedify/backfill
34+
yarn add @fedify/backfill
35+
bun add @fedify/backfill
3436
~~~~
3537

36-
~~~~ sh [npm]
37-
npm add @fedify/backfill
38-
~~~~
39-
40-
~~~~ sh [pnpm]
41-
pnpm add @fedify/backfill
42-
~~~~
43-
44-
~~~~ sh [Yarn]
45-
yarn add @fedify/backfill
46-
~~~~
47-
48-
~~~~ sh [Bun]
49-
bun add @fedify/backfill
50-
~~~~
51-
52-
:::
53-
5438

5539
Usage
5640
-----

packages/backfill/src/backfill.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { deepStrictEqual, ok, rejects, strictEqual } from "node:assert/strict";
22
import test, { describe } from "node:test";
3-
import { backfill, type BackfillContext } from "./mod.ts";
3+
import { backfill, type BackfillContext, MaxRequestsExceeded } from "./mod.ts";
44
import { Collection, Create, Note } from "@fedify/vocab";
55

66
async function collect(
@@ -14,6 +14,7 @@ async function collect(
1414
describe("backfill", () => {
1515
test("package exports backfill", () => {
1616
strictEqual(typeof backfill, "function");
17+
strictEqual(typeof MaxRequestsExceeded, "function");
1718
});
1819

1920
test("context missing yields nothing", async () => {

packages/backfill/src/backfill.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import type {
1414
BackfillOptions,
1515
} from "./types.ts";
1616

17-
class MaxRequestsExceeded extends Error {}
17+
/**
18+
* Thrown when backfill traversal exceeds the configured request budget.
19+
*
20+
* @since 2.3.0
21+
*/
22+
export class MaxRequestsExceeded extends Error {}
1823

1924
interface RequestBudget {
2025
readonly signal?: AbortSignal;
@@ -26,6 +31,8 @@ interface RequestBudget {
2631
*
2732
* The seed object is not yielded by default, but its ID is treated as already
2833
* seen so it will not be yielded again if the collection contains it.
34+
*
35+
* @since 2.3.0
2936
*/
3037
export async function* backfill<
3138
TObject extends APObject = APObject,

packages/backfill/src/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @module
88
*/
9-
export { backfill } from "./backfill.ts";
9+
export { backfill, MaxRequestsExceeded } from "./backfill.ts";
1010
export type {
1111
BackfillContext,
1212
BackfillDocumentLoader,

packages/backfill/src/types.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@ import type { Object as APObject } from "@fedify/vocab";
22

33
/**
44
* Backfill traversal strategy used to discover the returned object.
5+
*
6+
* @since 2.3.0
57
*/
68
export type BackfillStrategy = "context-posts";
79

810
/**
911
* Source relation that produced a backfilled object.
12+
*
13+
* @since 2.3.0
1014
*/
1115
export type BackfillOrigin = "context" | "collection";
1216

1317
/**
1418
* Options passed to {@link BackfillDocumentLoader}.
19+
*
20+
* @since 2.3.0
1521
*/
1622
export interface BackfillDocumentLoaderOptions {
1723
/**
1824
* Cancellation signal for the current dereference operation.
1925
*/
20-
signal?: AbortSignal;
26+
readonly signal?: AbortSignal;
2127
}
2228

2329
/**
2430
* Dereferences an ActivityPub object or collection IRI.
31+
*
32+
* @since 2.3.0
2533
*/
2634
export type BackfillDocumentLoader = (
2735
iri: URL,
@@ -30,83 +38,89 @@ export type BackfillDocumentLoader = (
3038

3139
/**
3240
* Dependencies used by backfill traversal.
41+
*
42+
* @since 2.3.0
3343
*/
3444
export interface BackfillContext {
3545
/**
3646
* Dereferences context collections and collection item IRIs.
3747
*/
38-
documentLoader: BackfillDocumentLoader;
48+
readonly documentLoader: BackfillDocumentLoader;
3949
}
4050

4151
/**
4252
* Controls direct context collection backfill traversal.
53+
*
54+
* @since 2.3.0
4355
*/
4456
export interface BackfillOptions<
4557
TObject extends APObject = APObject,
4658
> {
4759
/**
4860
* Maximum number of items to yield. Skipped duplicates do not count.
4961
*/
50-
maxItems?: number;
62+
readonly maxItems?: number;
5163

5264
/**
5365
* Maximum traversal depth. This is reserved for future reply-tree traversal;
5466
*/
55-
maxDepth?: number;
67+
readonly maxDepth?: number;
5668

5769
/**
5870
* Maximum number of calls to {@link BackfillContext.documentLoader}.
5971
*
6072
* Dereferencing the note context, collection item IRIs, and future page IRIs
6173
* all count as requests. Embedded collection items do not count.
6274
*/
63-
maxRequests?: number;
75+
readonly maxRequests?: number;
6476

6577
/**
6678
* Delay between `documentLoader` requests.
6779
*
6880
* When a callback is provided, `iteration` is the zero-based request index.
6981
*/
70-
interval?:
82+
readonly interval?:
7183
| Temporal.DurationLike
7284
| string
7385
| ((iteration: number) => Temporal.DurationLike | string);
7486

7587
/**
7688
* Cancels traversal before requests and before yields.
7789
*/
78-
signal?: AbortSignal;
90+
readonly signal?: AbortSignal;
7991
}
8092

8193
/**
8294
* A single object discovered by backfill traversal.
95+
*
96+
* @since 2.3.0
8397
*/
8498
export interface BackfillItem<
8599
TObject extends APObject = APObject,
86100
> {
87101
/**
88102
* The discovered ActivityPub object.
89103
*/
90-
object: TObject;
104+
readonly object: TObject;
91105

92106
/**
93107
* The object's ActivityPub ID, when present.
94108
*/
95-
id?: URL;
109+
readonly id?: URL;
96110

97111
/**
98112
* The traversal strategy that produced this item.
99113
*/
100-
strategy: BackfillStrategy;
114+
readonly strategy: BackfillStrategy;
101115

102116
/**
103117
* The source relation that produced this item.
104118
*/
105-
origin: BackfillOrigin;
119+
readonly origin: BackfillOrigin;
106120

107121
/**
108122
* Traversal depth. Direct context collection items are depth 0; deeper
109123
* values are reserved for future reply-tree traversal.
110124
*/
111-
depth?: number;
125+
readonly depth?: number;
112126
}

0 commit comments

Comments
 (0)