@fedify/backfill 2.3.0-dev.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.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright 2024–2026 Hong Minhee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ <!-- deno-fmt-ignore-file -->
2
+
3
+ @fedify/backfill: ActivityPub backfill for Fedify
4
+ =================================================
5
+
6
+ [![JSR][JSR badge]][JSR]
7
+ [![npm][npm badge]][npm]
8
+ [![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]
9
+
10
+ *This package is available since Fedify 2.3.0.*
11
+
12
+ This package provides ActivityPub conversation backfill support for the
13
+ [Fedify] ecosystem. It can retrieve post-like objects from a seed object's
14
+ context collection, following the direct [FEP-f228] path where the
15
+ context dereferences to a `Collection`, `OrderedCollection`, `CollectionPage`,
16
+ or `OrderedCollectionPage`. It can also use an opt-in reply-tree strategy to
17
+ walk `inReplyTo` ancestors and `replies` descendants when context collections
18
+ are unavailable or incomplete.
19
+
20
+ [JSR badge]: https://jsr.io/badges/@fedify/backfill
21
+ [JSR]: https://jsr.io/@fedify/backfill
22
+ [npm badge]: https://img.shields.io/npm/v/@fedify/backfill?logo=npm
23
+ [npm]: https://www.npmjs.com/package/@fedify/backfill
24
+ [@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
25
+ [@fedify@hollo.social]: https://hollo.social/@fedify
26
+ [Fedify]: https://fedify.dev/
27
+ [FEP-f228]: https://w3id.org/fep/f228
28
+
29
+
30
+ Installation
31
+ ------------
32
+
33
+ ~~~~ sh
34
+ deno add jsr:@fedify/backfill
35
+ npm add @fedify/backfill
36
+ pnpm add @fedify/backfill
37
+ yarn add @fedify/backfill
38
+ bun add @fedify/backfill
39
+ ~~~~
40
+
41
+
42
+ Usage
43
+ -----
44
+
45
+ The `backfill()` function accepts a backfill context, a seed object, and
46
+ traversal options:
47
+
48
+ ~~~~ typescript
49
+ import { backfill } from "@fedify/backfill";
50
+ import { lookupObject } from "@fedify/vocab";
51
+
52
+ const documentLoader = (iri: URL, options?: { signal?: AbortSignal }) =>
53
+ lookupObject(iri, { signal: options?.signal });
54
+
55
+ for await (
56
+ const item of backfill({ documentLoader }, note, {
57
+ maxItems: 20,
58
+ maxRequests: 50,
59
+ })
60
+ ) {
61
+ console.log(item.id?.href);
62
+ }
63
+ ~~~~
64
+
65
+ The seed object itself is not yielded. If it appears in the discovered
66
+ collection, it is skipped by ID.
67
+
68
+ Configured strategies run in order. They share `maxItems`, `maxRequests`,
69
+ abort state, and object ID deduplication; if two strategies discover the same
70
+ object, the first strategy keeps its `BackfillItem` metadata.
71
+
72
+ By default, `backfill()` uses the `context-auto` strategy. In this mode,
73
+ collection items are treated as backfillable objects by default. If an item is
74
+ recognized as a supported `Create` activity, `backfill()` extracts the
75
+ activity's object instead.
76
+
77
+ To accept only post-like objects directly contained in the context collection,
78
+ use the `context-objects` strategy:
79
+
80
+ ~~~~ typescript
81
+ for await (
82
+ const item of backfill({ documentLoader }, note, {
83
+ strategies: ["context-objects"],
84
+ })
85
+ ) {
86
+ console.log(item.object);
87
+ }
88
+ ~~~~
89
+
90
+ To read only FEP-f228 activity collections, enable the `context-activities`
91
+ strategy:
92
+
93
+ ~~~~ typescript
94
+ for await (
95
+ const item of backfill({ documentLoader }, note, {
96
+ strategies: ["context-activities"],
97
+ })
98
+ ) {
99
+ console.log(item.object);
100
+ }
101
+ ~~~~
102
+
103
+ The `context-activities` strategy currently supports `Create` activities and
104
+ yields the activity's object, not the activity itself.
105
+
106
+ To combine the FEP-f228 context collection path with traditional reply-tree
107
+ crawling, add the `reply-tree` strategy after `context-auto`:
108
+
109
+ ~~~~ typescript
110
+ for await (
111
+ const item of backfill({ documentLoader }, note, {
112
+ strategies: ["context-auto", "reply-tree"],
113
+ maxDepth: 4,
114
+ })
115
+ ) {
116
+ console.log(item.origin, item.depth, item.object);
117
+ }
118
+ ~~~~
119
+
120
+ The `reply-tree` strategy walks `inReplyTo` ancestors and `replies`
121
+ descendants. It yields discovered post-like objects only; it does not extract
122
+ objects from Activity wrappers. Immediate parents and direct replies have
123
+ depth 1, their next-level parents or replies have depth 2, and so on.
124
+ Reply-tree traversal defaults to a maximum depth of 10; set `maxDepth` to use a
125
+ different limit.
126
+
127
+
128
+ Traversal controls
129
+ ------------------
130
+
131
+ All configured strategies share the same traversal controls:
132
+
133
+ - `maxItems` limits the number of yielded objects. Skipped duplicates do
134
+ not count.
135
+ - `maxRequests` limits calls to `documentLoader`. Embedded objects and
136
+ collections do not count.
137
+ - `maxDepth` limits reply-tree traversal and defaults to 10. It does not
138
+ limit context collection items.
139
+ - `interval` adds a delay between loader requests. Its callback receives
140
+ the zero-based request index.
141
+ - `signal` cancels traversal and is forwarded to `documentLoader`.
142
+
143
+ An `interval` string requires the global `Temporal` API or a polyfill.
144
+ `Temporal.DurationLike` objects work without the global API.
145
+
146
+ If the seed has no context, or its context resolves to a non-collection,
147
+ context strategies yield nothing. Loader failures are skipped unless
148
+ traversal is aborted.
149
+
150
+ Dereferenced documents are cached in memory for one `backfill()` traversal.
151
+ Applications that need persistent or shared caching can provide it through
152
+ the `documentLoader`.