tangled
alpha
login
or
join now
besaid.zone
/
leaflet-loader-astro
9
fork
atom
leaflet.pub astro loader
9
fork
atom
overview
issues
pulls
pipelines
adjust types
nulfrost
7 months ago
7d8fd04a
d81cda80
+62
-17
3 changed files
expand all
collapse all
unified
split
src
leaflet-live-loader.ts
types.ts
utils.ts
+20
-11
src/leaflet-live-loader.ts
···
5
5
import {
6
6
getLeafletDocuments,
7
7
getSingleLeafletDocument,
8
8
+
leafletDocumentRecordToView,
8
9
resolveMiniDoc,
9
10
uriToRkey,
10
11
} from "./utils.js";
11
12
import type {
12
13
CollectionFilter,
13
14
EntryFilter,
14
14
-
LeafletRecord,
15
15
+
LeafletDocumentRecord,
16
16
+
LeafletDocumentView,
15
17
LeafletLoaderOptions,
16
18
} from "./types.js";
17
19
···
35
37
36
38
export function leafletLiveLoader(
37
39
options: LeafletLoaderOptions,
38
38
-
): LiveLoader<LeafletRecord, EntryFilter, CollectionFilter, LiveLoaderError> {
40
40
+
): LiveLoader<
41
41
+
LeafletDocumentView,
42
42
+
EntryFilter,
43
43
+
CollectionFilter,
44
44
+
LiveLoaderError
45
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
78
-
data: {
79
79
-
id,
80
80
-
...document,
81
81
-
},
85
85
+
data: leafletDocumentRecordToView({
86
86
+
uri: document.uri,
87
87
+
cid: document.cid,
88
88
+
value: document.value as unknown as LeafletDocumentRecord,
89
89
+
}),
82
90
};
83
91
}),
84
92
};
···
110
118
});
111
119
112
120
return {
113
113
-
id: filter?.id,
114
114
-
data: {
115
115
-
id: filter?.id,
116
116
-
...document,
117
117
-
},
121
121
+
id: filter.id,
122
122
+
data: leafletDocumentRecordToView({
123
123
+
uri: document.uri,
124
124
+
cid: document.cid?.toString() ?? "",
125
125
+
value: document.value as unknown as LeafletDocumentRecord,
126
126
+
}),
118
127
};
119
128
} catch {
120
129
return {
+19
-5
src/types.ts
···
7
7
repo: string;
8
8
}
9
9
10
10
-
export interface LeafletRecord {
11
11
-
id: string;
12
12
-
uri: string;
13
13
-
cid?: string;
14
14
-
value: unknown;
10
10
+
export interface LeafletDocumentRecord {
11
11
+
$type: "pub.leaflet.document";
12
12
+
pages: { [x: string]: unknown };
13
13
+
title: string;
14
14
+
author: string;
15
15
+
description: string;
16
16
+
publication: string;
17
17
+
publishedAt: string;
18
18
+
}
19
19
+
20
20
+
export interface LeafletDocumentView {
21
21
+
rkey: string;
22
22
+
cid: string;
23
23
+
title: string;
24
24
+
pages: { [x: string]: unknown };
25
25
+
description: string;
26
26
+
author: string;
27
27
+
publication: string;
28
28
+
publishedAt: string;
15
29
}
16
30
17
31
export interface MiniDoc {
+23
-1
src/utils.ts
···
1
1
-
import type { Agent } from "@atproto/api";
2
1
import type {
3
2
GetLeafletDocumentsParams,
4
3
GetSingleLeafletDocumentParams,
4
4
+
LeafletDocumentRecord,
5
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
82
+
83
83
+
export function leafletDocumentRecordToView({
84
84
+
uri,
85
85
+
cid,
86
86
+
value,
87
87
+
}: {
88
88
+
uri: string;
89
89
+
cid: string;
90
90
+
value: LeafletDocumentRecord;
91
91
+
}): LeafletDocumentView {
92
92
+
return {
93
93
+
rkey: uriToRkey(uri),
94
94
+
cid,
95
95
+
title: value.title,
96
96
+
pages: value.pages,
97
97
+
description: value.description,
98
98
+
author: value.author,
99
99
+
publication: value.publication,
100
100
+
publishedAt: value.publishedAt,
101
101
+
};
102
102
+
}