+20
-11
src/leaflet-live-loader.ts
+20
-11
src/leaflet-live-loader.ts
···
5
5
import {
6
6
getLeafletDocuments,
7
7
getSingleLeafletDocument,
8
+
leafletDocumentRecordToView,
8
9
resolveMiniDoc,
9
10
uriToRkey,
10
11
} from "./utils.js";
11
12
import type {
12
13
CollectionFilter,
13
14
EntryFilter,
14
-
LeafletRecord,
15
+
LeafletDocumentRecord,
16
+
LeafletDocumentView,
15
17
LeafletLoaderOptions,
16
18
} from "./types.js";
17
19
···
35
37
36
38
export function leafletLiveLoader(
37
39
options: LeafletLoaderOptions,
38
-
): LiveLoader<LeafletRecord, EntryFilter, CollectionFilter, LiveLoaderError> {
40
+
): LiveLoader<
41
+
LeafletDocumentView,
42
+
EntryFilter,
43
+
CollectionFilter,
44
+
LiveLoaderError
45
+
> {
39
46
const { repo } = options;
40
47
41
48
if (!repo || typeof repo !== "string") {
···
75
82
const id = uriToRkey(document.uri);
76
83
return {
77
84
id,
78
-
data: {
79
-
id,
80
-
...document,
81
-
},
85
+
data: leafletDocumentRecordToView({
86
+
uri: document.uri,
87
+
cid: document.cid,
88
+
value: document.value as unknown as LeafletDocumentRecord,
89
+
}),
82
90
};
83
91
}),
84
92
};
···
110
118
});
111
119
112
120
return {
113
-
id: filter?.id,
114
-
data: {
115
-
id: filter?.id,
116
-
...document,
117
-
},
121
+
id: filter.id,
122
+
data: leafletDocumentRecordToView({
123
+
uri: document.uri,
124
+
cid: document.cid?.toString() ?? "",
125
+
value: document.value as unknown as LeafletDocumentRecord,
126
+
}),
118
127
};
119
128
} catch {
120
129
return {
+19
-5
src/types.ts
+19
-5
src/types.ts
···
7
7
repo: string;
8
8
}
9
9
10
-
export interface LeafletRecord {
11
-
id: string;
12
-
uri: string;
13
-
cid?: string;
14
-
value: unknown;
10
+
export interface LeafletDocumentRecord {
11
+
$type: "pub.leaflet.document";
12
+
pages: { [x: string]: unknown };
13
+
title: string;
14
+
author: string;
15
+
description: string;
16
+
publication: string;
17
+
publishedAt: string;
18
+
}
19
+
20
+
export interface LeafletDocumentView {
21
+
rkey: string;
22
+
cid: string;
23
+
title: string;
24
+
pages: { [x: string]: unknown };
25
+
description: string;
26
+
author: string;
27
+
publication: string;
28
+
publishedAt: string;
15
29
}
16
30
17
31
export interface MiniDoc {
+23
-1
src/utils.ts
+23
-1
src/utils.ts
···
1
-
import type { Agent } from "@atproto/api";
2
1
import type {
3
2
GetLeafletDocumentsParams,
4
3
GetSingleLeafletDocumentParams,
4
+
LeafletDocumentRecord,
5
+
LeafletDocumentView,
5
6
MiniDoc,
6
7
} from "./types.js";
7
8
import { LiveLoaderError } from "./leaflet-live-loader.js";
···
78
79
79
80
return response?.data;
80
81
}
82
+
83
+
export function leafletDocumentRecordToView({
84
+
uri,
85
+
cid,
86
+
value,
87
+
}: {
88
+
uri: string;
89
+
cid: string;
90
+
value: LeafletDocumentRecord;
91
+
}): LeafletDocumentView {
92
+
return {
93
+
rkey: uriToRkey(uri),
94
+
cid,
95
+
title: value.title,
96
+
pages: value.pages,
97
+
description: value.description,
98
+
author: value.author,
99
+
publication: value.publication,
100
+
publishedAt: value.publishedAt,
101
+
};
102
+
}