pups-client 0.5.0 → 0.6.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/README.md +2 -2
- package/dist/feed.d.ts +25 -9
- package/dist/feed.d.ts.map +1 -1
- package/dist/feed.js +92 -40
- package/dist/feed.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mentions.d.ts +2 -2
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +7 -5
- package/dist/mentions.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/feed.ts +111 -45
- package/src/index.ts +3 -1
- package/src/mentions.ts +9 -5
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -152,11 +152,11 @@ for await (const item of feed.posts()) console.log(item.id) // newest firs
|
|
|
152
152
|
const feeds = await session.listFeeds() // the feeds registered in host-meta.json
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
- **Archives
|
|
155
|
+
- **Archives** ([RFC-13](https://github.com/bigwide-net/RFCs/blob/main/RFC-13-JSON-Feed-Archives.md)). Every post goes into the newest archive, `feed.000000.json`, `feed.000001.json`, … in the feed directory, 20 posts each, linked with `next_url`; posts never move. The feed file holds a copy of the newest 30 posts and points to the newest archive with `_archive.archive_url`, and names the archive template and size; archives point back with `_archive.updates_url` and carry their `_archive.number`. Feeds written before RFC-13, with these fields in `_pups`, are read as before and moved to `_archive` on their next write. `session.feed(name, { maxItems, archiveSize, maxBytes })` changes the sizes. Archives are optional in RFC-7: with `{ startArchives: false }`, a feed without archives stays a plain feed file with the newest posts; a feed that has archives always keeps them.
|
|
156
156
|
- **Concurrency.** Every change is a read-modify-write with ETags, repeated when another app or the owner wrote in between. The archive is always written before the feed file, so no post is ever lost, and the next post repairs a feed file that an interrupted post didn't reach.
|
|
157
157
|
- **Post URLs.** `addPost()` returns `url`, the post's archive URL plus `#<id>`. It never changes, so it can be the `source` of an RFC-4 webmention. If the site has a homepage that shows single posts, such as webpup, `host-meta.json` declares their URLs with the property `https://bigwide.net/ns/post-url-template` (`POST_URL_TEMPLATE`), e.g. `https://tim.example/p/{feed}/post/{index}`. Posts of a feed with archives then get the URL of their page as `url`, unless the app sets one; `editPost()` adds it to older posts that have none. Show `post.item.url` as the post's link; `session.feed(name, { postUrls: false })` turns this off.
|
|
158
158
|
- **Comments on your feed.** If the server has a `comment_endpoint` (RFC-6 "Built-in receiver"), `feed.enableComments({ policy, tos })` opens the feed for RFC-4 comments: it writes `_submissions` into the feed file, with the endpoint as `url`, a `comments` policy and `republish: "no"`, and the server puts the comments into the owner's inbox. `feed.disableComments()` removes it, `feed.comments(doc)` tells whether comments go to this server (`pups`), another service (`other`) or nowhere (`off`). Archives don't copy `_submissions`: the feed file alone decides. Single posts are closed with `_commenting: { allowComments: false }`.
|
|
159
|
-
- **Indexes.** Every post gets an index, `
|
|
159
|
+
- **Indexes.** Every post gets an index, `_archive.index` (also `PostResult.index`, or `itemIndex(item)`): 0 for the first post, then counting up, never changed and never given out again, with the counter `_archive.next_index` in the newest archive. Readers can number the posts and load only the archives they need. A feed written before indexes existed is indexed on its next post, or with `feed.assignIndexes()`; posts of apps that don't know indexes get theirs on the next post.
|
|
160
160
|
- Errors: `not_pups_controlled` for feeds without the marker, `invalid_feed` for files that aren't JSON Feeds, `not_found` for a missing feed or post.
|
|
161
161
|
|
|
162
162
|
### Mentions and submissions
|
package/dist/feed.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare const FEED_REL = "https://bigwide.net/ns/feed";
|
|
|
10
10
|
export declare const POST_URL_TEMPLATE = "https://bigwide.net/ns/post-url-template";
|
|
11
11
|
/** The `about` of the `_pups` object: RFC-7. Not its final location; readers must not rely on it. */
|
|
12
12
|
export declare const PUPS_FEED_SPEC = "https://github.com/bigwide-net/RFCs/blob/main/RFC-7-Feed-Publishing-with-PUPS.md";
|
|
13
|
+
/** The `about` of the `_archive` object: RFC-13 (JSON Feed Archives). Not its final location either. */
|
|
14
|
+
export declare const ARCHIVE_SPEC = "https://github.com/bigwide-net/RFCs/blob/main/RFC-13-JSON-Feed-Archives.md";
|
|
13
15
|
export interface FeedAuthor {
|
|
14
16
|
name?: string;
|
|
15
17
|
url?: string;
|
|
@@ -41,26 +43,39 @@ export interface FeedItem {
|
|
|
41
43
|
tags?: string[];
|
|
42
44
|
language?: string;
|
|
43
45
|
attachments?: FeedAttachment[];
|
|
44
|
-
/** The item's `
|
|
45
|
-
|
|
46
|
+
/** The item's `_archive` object, with its index (RFC-13 "Indexes"). */
|
|
47
|
+
_archive?: ItemArchive;
|
|
46
48
|
[field: string]: unknown;
|
|
47
49
|
}
|
|
48
|
-
/** The `
|
|
49
|
-
export interface
|
|
50
|
-
/** The item's index: 0 for a feed's first item, then counting up; never changed, never used again (RFC-
|
|
50
|
+
/** The `_archive` object of an item (RFC-13). */
|
|
51
|
+
export interface ItemArchive {
|
|
52
|
+
/** The item's index: 0 for a feed's first item, then counting up; never changed, never used again (RFC-13 "Indexes"). */
|
|
51
53
|
index?: number;
|
|
52
54
|
[field: string]: unknown;
|
|
53
55
|
}
|
|
54
|
-
/** The `_pups`
|
|
56
|
+
/** @deprecated The index moved from `_pups` to `_archive` (RFC-13): use ItemArchive. */
|
|
57
|
+
export type ItemMarker = ItemArchive;
|
|
58
|
+
/** The `_pups` object of a feed file or archive: the marker of RFC-7. */
|
|
55
59
|
export interface PupsMarker {
|
|
56
60
|
about?: string;
|
|
57
61
|
pupsControlled?: boolean;
|
|
62
|
+
[field: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/** The `_archive` object of a feed file or archive (RFC-13). */
|
|
65
|
+
export interface ArchiveFields {
|
|
66
|
+
about?: string;
|
|
58
67
|
/** In the feed file: the public URL of the newest archive. */
|
|
59
68
|
archive_url?: string;
|
|
69
|
+
/** In the feed file: the URL of every archive, with `{number}` for its six-digit number. */
|
|
70
|
+
archive_template?: string;
|
|
71
|
+
/** In the feed file: the most items an archive holds. */
|
|
72
|
+
archive_size?: number;
|
|
60
73
|
/** In an archive: the public URL of the feed file, which readers poll. */
|
|
61
74
|
updates_url?: string;
|
|
75
|
+
/** In an archive: its number, from 0 for the oldest. */
|
|
76
|
+
number?: number;
|
|
62
77
|
/**
|
|
63
|
-
* The index the next new item gets (RFC-
|
|
78
|
+
* The index the next new item gets (RFC-13 "Indexes"). Valid in the newest archive, or in the feed file of a feed
|
|
64
79
|
* without archives.
|
|
65
80
|
*/
|
|
66
81
|
next_index?: number;
|
|
@@ -83,6 +98,7 @@ export interface FeedDocument {
|
|
|
83
98
|
hubs?: unknown[];
|
|
84
99
|
items: FeedItem[];
|
|
85
100
|
_pups?: PupsMarker;
|
|
101
|
+
_archive?: ArchiveFields;
|
|
86
102
|
[field: string]: unknown;
|
|
87
103
|
}
|
|
88
104
|
/**
|
|
@@ -261,7 +277,7 @@ type WithMentions = Signal & {
|
|
|
261
277
|
};
|
|
262
278
|
/** The scopes an app needs to write a feed: the feed file and the feed directory (RFC-7 "Server requirements"). */
|
|
263
279
|
export declare function feedScopes(name?: string): Scope[];
|
|
264
|
-
/** The index of an item (RFC-
|
|
280
|
+
/** The index of an item (RFC-13 "Indexes"), also from `_pups` of earlier drafts, or undefined if it has none. */
|
|
265
281
|
export declare function itemIndex(item: FeedItem): number | undefined;
|
|
266
282
|
/**
|
|
267
283
|
* A feed on the owner's domain, maintained according to RFC-7: the main feed `/feed.json`, or a named feed
|
|
@@ -374,7 +390,7 @@ export declare class PupsFeed {
|
|
|
374
390
|
*/
|
|
375
391
|
getPost(id: string, options?: Signal): Promise<PostResult | undefined>;
|
|
376
392
|
/**
|
|
377
|
-
* All posts, newest first: the archives from `
|
|
393
|
+
* All posts, newest first: the archives from `_archive.archive_url` along `next_url` (for a feed without archives,
|
|
378
394
|
* the feed file and its `next_url` chain). Each post is returned once.
|
|
379
395
|
*/
|
|
380
396
|
posts(options?: Signal): AsyncGenerator<FeedItem>;
|
package/dist/feed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACvG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAGrD,mGAAmG;AACnG,eAAO,MAAM,QAAQ,gCAAgC,CAAA;AAErD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6CAA6C,CAAA;AAE3E,qGAAqG;AACrG,eAAO,MAAM,cAAc,qFAAqF,CAAA;
|
|
1
|
+
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACvG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAGrD,mGAAmG;AACnG,eAAO,MAAM,QAAQ,gCAAgC,CAAA;AAErD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6CAA6C,CAAA;AAE3E,qGAAqG;AACrG,eAAO,MAAM,cAAc,qFAAqF,CAAA;AAEhH,wGAAwG;AACxG,eAAO,MAAM,YAAY,+EAA+E,CAAA;AAuBxG,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CACz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,GAAG,SAAS,CAAC,CAAC,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IA2B9K;;;;;;OAMG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAY,GAAG;QAAE,WAAW,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;KAAE,CAAC;IAmC9K;;;;OAIG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAMxG;;;;;;;OAOG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,MAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAQnE;;;;;;;;;;OAUG;IACH,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,OAAO,GAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CA2gBlJ;AAED,wFAAwF;AACxF,wBAAsB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,MAAM,GAAG,WAAgB,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAgB7G"}
|
package/dist/feed.js
CHANGED
|
@@ -12,6 +12,8 @@ export const FEED_REL = 'https://bigwide.net/ns/feed';
|
|
|
12
12
|
export const POST_URL_TEMPLATE = 'https://bigwide.net/ns/post-url-template';
|
|
13
13
|
/** The `about` of the `_pups` object: RFC-7. Not its final location; readers must not rely on it. */
|
|
14
14
|
export const PUPS_FEED_SPEC = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-7-Feed-Publishing-with-PUPS.md';
|
|
15
|
+
/** The `about` of the `_archive` object: RFC-13 (JSON Feed Archives). Not its final location either. */
|
|
16
|
+
export const ARCHIVE_SPEC = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-13-JSON-Feed-Archives.md';
|
|
15
17
|
const RFC1_URL = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-1-Source-for-JSON-Feeds.md';
|
|
16
18
|
const RFC4_URL = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-4-Feed-Submissions.md';
|
|
17
19
|
const JSON_FEED_VERSION = 'https://jsonfeed.org/version/1.1';
|
|
@@ -19,14 +21,14 @@ const FEED_CONTENT_TYPE = 'application/feed+json';
|
|
|
19
21
|
const maxArchiveNumber = 999_999;
|
|
20
22
|
/** The feed file keeps at least this many items, also when `maxBytes` is exceeded (RFC-7 "Size in bytes"). */
|
|
21
23
|
const minFeedItems = 10;
|
|
22
|
-
const mainComment = `This feed is maintained by apps through a Personal Upload Server (PUPS), following ${PUPS_FEED_SPEC}. It contains the newest items. If it has
|
|
23
|
-
const archiveComment = (feedUrl) => `This is an archive of ${feedUrl}, maintained by apps through a Personal Upload Server (PUPS), following ${PUPS_FEED_SPEC}. New items appear in the feed at
|
|
24
|
+
const mainComment = `This feed is maintained by apps through a Personal Upload Server (PUPS), following ${PUPS_FEED_SPEC}. It contains the newest items. If it has _archive.archive_url, all items are in the archives, starting with the one there.`;
|
|
25
|
+
const archiveComment = (feedUrl) => `This is an archive of ${feedUrl}, maintained by apps through a Personal Upload Server (PUPS), following ${PUPS_FEED_SPEC}. New items appear in the feed at _archive.updates_url, older ones are in the archive at next_url.`;
|
|
24
26
|
/** Feed names (RFC-7 "Named feeds"): 1 to 40 lowercase letters, digits and `-`, not starting or ending with `-`. */
|
|
25
27
|
const feedNamePattern = /^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/;
|
|
26
28
|
/** The main feed's media directories in `/feed/`, which therefore can't be feed names. */
|
|
27
29
|
const mainMediaFolders = ['images', 'media'];
|
|
28
30
|
/** Top-level fields that are fixed or managed by RFC-7, and can't be set through `create()` or `updateSettings()`. */
|
|
29
|
-
const reservedFields = new Set(['version', 'home_page_url', 'feed_url', 'user_comment', 'next_url', 'items', 'hubs', '_pups', 'icon', 'favicon']);
|
|
31
|
+
const reservedFields = new Set(['version', 'home_page_url', 'feed_url', 'user_comment', 'next_url', 'items', 'hubs', '_pups', '_archive', 'icon', 'favicon']);
|
|
30
32
|
/** The scopes an app needs to write a feed: the feed file and the feed directory (RFC-7 "Server requirements"). */
|
|
31
33
|
export function feedScopes(name) {
|
|
32
34
|
const { path, directory } = feedPaths(name);
|
|
@@ -57,12 +59,42 @@ function mergeItems(existing, incoming) {
|
|
|
57
59
|
const present = new Set(existing.map(item => item.id));
|
|
58
60
|
return [...incoming.filter(item => !present.has(item.id)), ...existing.map(item => byId.get(item.id) ?? item)];
|
|
59
61
|
}
|
|
60
|
-
/** The index of an item (RFC-
|
|
62
|
+
/** The index of an item (RFC-13 "Indexes"), also from `_pups` of earlier drafts, or undefined if it has none. */
|
|
61
63
|
export function itemIndex(item) {
|
|
62
|
-
const index = isObject(item._pups) ? item._pups.index : undefined;
|
|
64
|
+
const index = isObject(item._archive) && item._archive.index !== undefined ? item._archive.index : isObject(item._pups) ? item._pups.index : undefined;
|
|
63
65
|
return typeof index == 'number' && Number.isSafeInteger(index) && index >= 0 ? index : undefined;
|
|
64
66
|
}
|
|
65
|
-
const withIndex = (item, index) => ({ ...item,
|
|
67
|
+
const withIndex = (item, index) => ({ ...item, _archive: { ...isObject(item._archive) ? item._archive : {}, index } });
|
|
68
|
+
/** The fields of RFC-13 that earlier drafts of RFC-7 kept in `_pups`. */
|
|
69
|
+
const legacyArchiveFields = ['archive_url', 'updates_url', 'next_index'];
|
|
70
|
+
/**
|
|
71
|
+
* Moves the fields that earlier drafts kept in `_pups` into `_archive` (RFC-13 "Earlier drafts"), in the file and its
|
|
72
|
+
* items, where `_archive` doesn't have them already. Changes `doc`.
|
|
73
|
+
*/
|
|
74
|
+
function upgradeArchiveFields(doc) {
|
|
75
|
+
const move = (from, to, keys) => {
|
|
76
|
+
for (const key of keys)
|
|
77
|
+
if (key in from) {
|
|
78
|
+
if (to[key] === undefined)
|
|
79
|
+
to[key] = from[key];
|
|
80
|
+
delete from[key];
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
if (isObject(doc._pups) && legacyArchiveFields.some(key => key in doc._pups)) {
|
|
84
|
+
const archive = { about: ARCHIVE_SPEC, ...isObject(doc._archive) ? doc._archive : {} };
|
|
85
|
+
move(doc._pups, archive, legacyArchiveFields);
|
|
86
|
+
doc._archive = archive;
|
|
87
|
+
}
|
|
88
|
+
for (const item of doc.items)
|
|
89
|
+
if (isObject(item._pups) && 'index' in item._pups) {
|
|
90
|
+
const archive = isObject(item._archive) ? item._archive : {};
|
|
91
|
+
move(item._pups, archive, ['index']);
|
|
92
|
+
item._archive = archive;
|
|
93
|
+
if (!Object.keys(item._pups).length)
|
|
94
|
+
delete item._pups;
|
|
95
|
+
}
|
|
96
|
+
return doc;
|
|
97
|
+
}
|
|
66
98
|
/** A post URL template (RFC-6 "Post URLs"): an https URL with `{index}` or `{id}`. */
|
|
67
99
|
function validTemplate(template) {
|
|
68
100
|
if (typeof template != 'string' || !/\{(index|id)\}/.test(template))
|
|
@@ -74,9 +106,9 @@ function validTemplate(template) {
|
|
|
74
106
|
return false;
|
|
75
107
|
}
|
|
76
108
|
}
|
|
77
|
-
/** The counter `
|
|
109
|
+
/** The counter `_archive.next_index` of a file, if it has a valid one. */
|
|
78
110
|
function counterOf(doc) {
|
|
79
|
-
const next = doc.
|
|
111
|
+
const next = doc._archive?.next_index;
|
|
80
112
|
return typeof next == 'number' && Number.isSafeInteger(next) && next >= 0 ? next : undefined;
|
|
81
113
|
}
|
|
82
114
|
/** The next free index: above every index of `items`, and at least each of `counters`. */
|
|
@@ -364,21 +396,21 @@ export class PupsFeed {
|
|
|
364
396
|
if (firstAttempt && main.doc.items.some(i => i.id == item.id))
|
|
365
397
|
throw new PupsError('invalid_request', `The feed already has an item with the id "${item.id}".`);
|
|
366
398
|
firstAttempt = false;
|
|
367
|
-
const doc = { ...main.doc,
|
|
368
|
-
const hasArchives = this.#archiveNumber(doc.
|
|
399
|
+
const doc = { ...main.doc, _archive: { ...main.doc._archive } };
|
|
400
|
+
const hasArchives = this.#archiveNumber(doc._archive.archive_url) !== undefined;
|
|
369
401
|
if (!hasArchives && !this.#archivesWanted) {
|
|
370
402
|
// A feed without archives: the feed file is all there is, and holds the counter (RFC-7 "Posting").
|
|
371
403
|
archiveUrl = this.url;
|
|
372
404
|
const indexed = indexItems(doc.items, nextFree(doc.items, counterOf(doc)));
|
|
373
405
|
stored = withIndex(item, indexed.next);
|
|
374
|
-
doc.
|
|
406
|
+
doc._archive.next_index = indexed.next + 1;
|
|
375
407
|
await this.#writeMain({ ...doc, items: this.#newestItems([stored], indexed.items, doc) }, main.etag, signal);
|
|
376
408
|
return;
|
|
377
409
|
}
|
|
378
410
|
if (!hasArchives) {
|
|
379
411
|
const started = await this.#startArchives(main, signal);
|
|
380
412
|
if (started) {
|
|
381
|
-
doc.
|
|
413
|
+
doc._archive.archive_url = started.url;
|
|
382
414
|
doc.items = started.items;
|
|
383
415
|
}
|
|
384
416
|
}
|
|
@@ -386,12 +418,12 @@ export class PupsFeed {
|
|
|
386
418
|
const added = await this.#addToArchive(main, doc, item, signal, template);
|
|
387
419
|
archiveUrl = added.url;
|
|
388
420
|
stored = added.item;
|
|
389
|
-
doc.
|
|
421
|
+
doc._archive.archive_url = added.url;
|
|
390
422
|
if (!hasArchives) {
|
|
391
423
|
// The old chain of a handed-over feed now continues behind the oldest archive, and the newest archive
|
|
392
424
|
// holds the counter.
|
|
393
425
|
delete doc.next_url;
|
|
394
|
-
delete doc.
|
|
426
|
+
delete doc._archive.next_index;
|
|
395
427
|
}
|
|
396
428
|
doc.items = this.#newestItems(added.recent, doc.items, doc);
|
|
397
429
|
await this.#writeMain(doc, main.etag, signal);
|
|
@@ -407,11 +439,11 @@ export class PupsFeed {
|
|
|
407
439
|
const signal = options.signal;
|
|
408
440
|
await this.#transaction(async () => {
|
|
409
441
|
const main = await this.#readControlled(this.path, signal);
|
|
410
|
-
const newest = this.#archiveNumber(main.doc.
|
|
442
|
+
const newest = this.#archiveNumber(main.doc._archive?.archive_url);
|
|
411
443
|
if (newest === undefined) {
|
|
412
444
|
const indexed = indexItems(main.doc.items, nextFree(main.doc.items, counterOf(main.doc)));
|
|
413
445
|
if (indexed.changed || counterOf(main.doc) !== indexed.next)
|
|
414
|
-
await this.#writeMain({ ...main.doc, items: indexed.items,
|
|
446
|
+
await this.#writeMain({ ...main.doc, items: indexed.items, _archive: { ...main.doc._archive, next_index: indexed.next } }, main.etag, signal);
|
|
415
447
|
return;
|
|
416
448
|
}
|
|
417
449
|
const archive = await this.#readArchive(this.#archivePath(newest), signal);
|
|
@@ -429,7 +461,7 @@ export class PupsFeed {
|
|
|
429
461
|
return found && this.#result(found.file.doc.items[found.index], this.#session.publicUrl(found.file.path));
|
|
430
462
|
}
|
|
431
463
|
/**
|
|
432
|
-
* All posts, newest first: the archives from `
|
|
464
|
+
* All posts, newest first: the archives from `_archive.archive_url` along `next_url` (for a feed without archives,
|
|
433
465
|
* the feed file and its `next_url` chain). Each post is returned once.
|
|
434
466
|
*/
|
|
435
467
|
async *posts(options = {}) {
|
|
@@ -472,7 +504,7 @@ export class PupsFeed {
|
|
|
472
504
|
if (oldIndex !== undefined)
|
|
473
505
|
item = withIndex(item, oldIndex);
|
|
474
506
|
// A post of a feed with archives that never had a url may get one (RFC-7 "Post URLs").
|
|
475
|
-
if (oldIndex !== undefined && !old.url && !item.url && this.#archiveNumber(main.doc.
|
|
507
|
+
if (oldIndex !== undefined && !old.url && !item.url && this.#archiveNumber(main.doc._archive?.archive_url) !== undefined)
|
|
476
508
|
item = this.#withPostUrl(item, oldIndex, await this.#postUrlTemplate(signal));
|
|
477
509
|
if (file != main)
|
|
478
510
|
await this.#writeArchive(file, replaceAt(file.doc.items, index, item), signal);
|
|
@@ -618,7 +650,7 @@ export class PupsFeed {
|
|
|
618
650
|
}
|
|
619
651
|
if (!isFeedDocument(doc))
|
|
620
652
|
throw new PupsError('invalid_feed', `${path} is not a JSON Feed.`);
|
|
621
|
-
return { path, doc, etag: file.etag };
|
|
653
|
+
return { path, doc: upgradeArchiveFields(doc), etag: file.etag };
|
|
622
654
|
}
|
|
623
655
|
/** Reads a file that must exist and carry the `_pups` marker. */
|
|
624
656
|
async #readControlled(path, signal) {
|
|
@@ -630,13 +662,13 @@ export class PupsFeed {
|
|
|
630
662
|
return loaded;
|
|
631
663
|
}
|
|
632
664
|
/**
|
|
633
|
-
* The files that hold all items: the archives from `
|
|
665
|
+
* The files that hold all items: the archives from `_archive.archive_url` along `next_url`, as far as they are files
|
|
634
666
|
* on this server. A feed without archives yet (handed over, not posted to) holds its items in the feed file and
|
|
635
667
|
* the pages its `next_url` names.
|
|
636
668
|
*/
|
|
637
669
|
async *#chain(main, signal) {
|
|
638
670
|
const visited = new Set([main.path]);
|
|
639
|
-
const archive = main.doc.
|
|
671
|
+
const archive = main.doc._archive?.archive_url;
|
|
640
672
|
let file = main;
|
|
641
673
|
let next = archive && this.#archiveNumber(archive) !== undefined ? archive : undefined;
|
|
642
674
|
if (next)
|
|
@@ -694,8 +726,8 @@ export class PupsFeed {
|
|
|
694
726
|
}
|
|
695
727
|
/**
|
|
696
728
|
* Writes the feed file. Sets the fixed fields, so that a feed the owner handed over gets them on its first write,
|
|
697
|
-
* and upgrades JSON Feed 1.0 (RFC-7 "Handing over an existing feed").
|
|
698
|
-
*
|
|
729
|
+
* and upgrades JSON Feed 1.0 (RFC-7 "Handing over an existing feed"). A feed with archives gets the archive template
|
|
730
|
+
* and size of RFC-13, and its optional `next_url` is kept equal to `archive_url` (RFC-7 "Reading").
|
|
699
731
|
*/
|
|
700
732
|
async #writeMain(doc, etag, signal) {
|
|
701
733
|
const { author, ...rest } = doc;
|
|
@@ -708,14 +740,27 @@ export class PupsFeed {
|
|
|
708
740
|
};
|
|
709
741
|
if (author !== undefined && fixed.authors === undefined)
|
|
710
742
|
fixed.authors = [author];
|
|
711
|
-
|
|
712
|
-
|
|
743
|
+
const archiveUrl = fixed._archive?.archive_url;
|
|
744
|
+
if (fixed._archive)
|
|
745
|
+
fixed._archive = { about: ARCHIVE_SPEC, ...fixed._archive };
|
|
746
|
+
if (this.#archiveNumber(archiveUrl) !== undefined) {
|
|
747
|
+
fixed._archive = { ...fixed._archive, archive_template: this.#archiveTemplate(), archive_size: this.#archiveSize };
|
|
748
|
+
if (fixed.next_url !== undefined)
|
|
749
|
+
fixed.next_url = archiveUrl;
|
|
750
|
+
}
|
|
713
751
|
await this.#session.replace(this.path, serialize(fixed), etag, { contentType: FEED_CONTENT_TYPE, signal });
|
|
714
752
|
return fixed;
|
|
715
753
|
}
|
|
716
|
-
/**
|
|
754
|
+
/**
|
|
755
|
+
* Writes an archive with `items`, and with the counter `next_index` if given. An archive of an earlier draft gets its
|
|
756
|
+
* `_archive` fields and comment of RFC-13 (`number`, `updates_url`).
|
|
757
|
+
*/
|
|
717
758
|
async #writeArchive(archive, items, signal, nextIndex) {
|
|
718
|
-
const
|
|
759
|
+
const n = this.#archiveNumber(this.#session.publicUrl(archive.path));
|
|
760
|
+
const fields = { about: ARCHIVE_SPEC, ...archive.doc._archive, updates_url: this.url, ...n === undefined ? {} : { number: n } };
|
|
761
|
+
if (nextIndex !== undefined)
|
|
762
|
+
fields.next_index = nextIndex;
|
|
763
|
+
const doc = { ...archive.doc, user_comment: archiveComment(this.url), items, _archive: fields };
|
|
719
764
|
await this.#session.replace(archive.path, serialize(doc), archive.etag, { contentType: FEED_CONTENT_TYPE, signal });
|
|
720
765
|
}
|
|
721
766
|
/**
|
|
@@ -738,6 +783,10 @@ export class PupsFeed {
|
|
|
738
783
|
#archiveUrl(n) {
|
|
739
784
|
return this.#session.publicUrl(this.#archivePath(n));
|
|
740
785
|
}
|
|
786
|
+
/** `_archive.archive_template` (RFC-13): the archive URL with `{number}` for the number. */
|
|
787
|
+
#archiveTemplate() {
|
|
788
|
+
return this.#archiveUrl(0).replace(/000000\.json$/, '{number}.json');
|
|
789
|
+
}
|
|
741
790
|
/** The number of the archive at `url`, or undefined if `url` is not an archive file of this feed. */
|
|
742
791
|
#archiveNumber(url) {
|
|
743
792
|
const path = url && pathFromPublicUrl(this.#session.server, url);
|
|
@@ -747,12 +796,11 @@ export class PupsFeed {
|
|
|
747
796
|
return match ? Number(match[1]) : undefined;
|
|
748
797
|
}
|
|
749
798
|
/**
|
|
750
|
-
* A new archive with the feed fields of the feed file (RFC-
|
|
751
|
-
* accepts comments is said by its feed file alone.
|
|
799
|
+
* A new archive with the feed fields of the feed file (RFC-13 "Feed fields of an archive"), except `_submissions`:
|
|
800
|
+
* whether a feed accepts comments is said by its feed file alone.
|
|
752
801
|
*/
|
|
753
802
|
#newArchive(n, main, items, nextUrl, nextIndex) {
|
|
754
|
-
const { items: _items, next_url: _next, user_comment: _comment, hubs: _hubs, author: _author, _pups, _submissions: _s, ...fields } = main;
|
|
755
|
-
const { archive_url: _archive, next_index: _counter, ...marker } = _pups ?? {};
|
|
803
|
+
const { items: _items, next_url: _next, user_comment: _comment, hubs: _hubs, author: _author, _pups, _archive, _submissions: _s, ...fields } = main;
|
|
756
804
|
const podcast = fields._podcast;
|
|
757
805
|
if (isObject(podcast) && 'liveItems' in podcast) {
|
|
758
806
|
const { liveItems: _live, ...rest } = podcast;
|
|
@@ -766,7 +814,8 @@ export class PupsFeed {
|
|
|
766
814
|
user_comment: archiveComment(this.url),
|
|
767
815
|
...nextUrl ? { next_url: nextUrl } : {},
|
|
768
816
|
items,
|
|
769
|
-
_pups: { about: PUPS_FEED_SPEC, ...
|
|
817
|
+
_pups: { about: PUPS_FEED_SPEC, ..._pups, pupsControlled: true },
|
|
818
|
+
_archive: { about: ARCHIVE_SPEC, updates_url: this.url, number: n, ...nextIndex === undefined ? {} : { next_index: nextIndex } },
|
|
770
819
|
};
|
|
771
820
|
}
|
|
772
821
|
async #createArchive(n, main, items, nextUrl, signal, nextIndex) {
|
|
@@ -813,7 +862,7 @@ export class PupsFeed {
|
|
|
813
862
|
const existing = await this.#readArchive(this.#archivePath(n), signal);
|
|
814
863
|
const ids = new Set(items.map(item => item.id));
|
|
815
864
|
if (!existing || existing == 'foreign' || !existing.doc.items.every(item => ids.has(item.id)))
|
|
816
|
-
throw new PupsError('conflict', `${this.#archivePath(n)} exists already, but ${this.path} has no archive_url. Remove the file, or set
|
|
865
|
+
throw new PupsError('conflict', `${this.#archivePath(n)} exists already, but ${this.path} has no archive_url. Remove the file, or set _archive.archive_url (RFC-7, Starting the archives).`);
|
|
817
866
|
await this.#writeArchive(existing, items, signal, nextIndex);
|
|
818
867
|
}
|
|
819
868
|
url = this.#archiveUrl(n);
|
|
@@ -866,7 +915,7 @@ export class PupsFeed {
|
|
|
866
915
|
*/
|
|
867
916
|
async #addToArchive(main, doc, item, signal, template) {
|
|
868
917
|
const place = (index) => this.#withPostUrl(withIndex(item, index), index, template);
|
|
869
|
-
const newest = this.#archiveNumber(doc.
|
|
918
|
+
const newest = this.#archiveNumber(doc._archive?.archive_url);
|
|
870
919
|
let previous = [];
|
|
871
920
|
// The index for the item if it goes into a new archive.
|
|
872
921
|
let next = nextFree(doc.items, newest === undefined ? counterOf(doc) : undefined);
|
|
@@ -961,13 +1010,16 @@ export class PupsFeed {
|
|
|
961
1010
|
this.#setMarkdown(item, markdown);
|
|
962
1011
|
if (item.content_html === undefined && item.content_text === undefined)
|
|
963
1012
|
throw new PupsError('invalid_request', 'A post needs content_html, content_text or markdown (JSON Feed requires content).');
|
|
964
|
-
// The index is given out when the item is added (RFC-
|
|
965
|
-
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
968
|
-
|
|
1013
|
+
// The index is given out when the item is added (RFC-13 "Indexes").
|
|
1014
|
+
for (const key of ['_archive', '_pups']) {
|
|
1015
|
+
const value = item[key];
|
|
1016
|
+
if (!isObject(value))
|
|
1017
|
+
continue;
|
|
1018
|
+
const { index: _index, ...rest } = value;
|
|
1019
|
+
if (Object.keys(rest).length)
|
|
1020
|
+
item[key] = rest;
|
|
969
1021
|
else
|
|
970
|
-
delete item
|
|
1022
|
+
delete item[key];
|
|
971
1023
|
}
|
|
972
1024
|
return item;
|
|
973
1025
|
}
|