-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.ts
122 lines (106 loc) · 3.59 KB
/
query.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import type { LexXrpcQuery } from "@atproto/lexicon";
import type { OpenAPIV3_1 } from "openapi-types";
import { convertObject, convertProperty } from "./object.ts";
import { calculateTag, isEmptyObject } from "../utils.ts";
export function convertQuery(
id: string,
name: string,
query: LexXrpcQuery,
): OpenAPIV3_1.OperationObject {
const get = {
tags: [calculateTag(id)],
...(query.description && { summary: query.description }),
operationId: id,
...(authenticatedEndpoints.has(id) && { security: [{ Bearer: [] }] }),
} as OpenAPIV3_1.OperationObject<"GET">;
if (query.parameters && !isEmptyObject(query.parameters.properties)) {
const properties = query.parameters.properties;
const required = new Set(query.parameters.required ?? []);
const parameters = [] as OpenAPIV3_1.ParameterObject[];
for (const [name, property] of Object.entries(properties)) {
const parameter: OpenAPIV3_1.ParameterObject = {
name,
in: "query",
...(property.description && { description: property.description }),
required: required.has(name),
// @ts-ignore FIXME: We know this will never be an ArraySchemaObject
// but TypeScript doesn't. Probably just gotta break out the inner parts
// of convertProperty more.
schema: convertProperty(id, name, property),
};
parameters.push(parameter);
}
get.parameters = parameters;
}
const responses = {} as OpenAPIV3_1.ResponsesObject;
if (query.output) {
const output = query.output;
const mediaType = {} as OpenAPIV3_1.MediaTypeObject;
if (output.schema) {
const schema = output.schema;
mediaType.schema = schema.type === "object"
? convertObject(id, name, schema)
: convertProperty(id, name, schema);
}
responses["200"] = {
description: "OK",
content: {
[query.output.encoding]: mediaType,
},
};
}
responses["400"] = {
description: "Bad Request",
};
if (authenticatedEndpoints.has(id)) {
responses["401"] = {
description: "Unauthorized",
};
}
get.responses = responses;
return get;
}
/**
* Building this by hand because this is documented ...no where?
*/
const authenticatedEndpoints = new Set([
"app.bsky.actor.getPreferences",
"app.bsky.actor.getProfile",
"app.bsky.actor.getProfiles",
"app.bsky.actor.getSuggestions",
"app.bsky.actor.searchActors",
"app.bsky.actor.searchActorsTypeahead",
"app.bsky.feed.getActorFeeds",
"app.bsky.feed.getAuthorFeed",
"app.bsky.feed.getFeed",
"app.bsky.feed.getFeedGenerator",
"app.bsky.feed.getFeedGenerators",
"app.bsky.feed.getLikes",
"app.bsky.feed.getPostThread",
"app.bsky.feed.getPosts",
"app.bsky.feed.getRepostedBy",
"app.bsky.feed.getTimeline",
"app.bsky.graph.getBlocks",
"app.bsky.graph.getFollowers",
"app.bsky.graph.getFollows",
"app.bsky.graph.getList",
"app.bsky.graph.getListMutes",
"app.bsky.graph.getLists",
"app.bsky.graph.getMutes",
"app.bsky.notification.getUnreadCount",
"app.bsky.notification.listNotifications",
"app.bsky.notification.updateSeen",
"app.bsky.unspecced.getPopular",
"app.bsky.unspecced.getPopularFeedGenerators",
"com.atproto.admin.getInviteCodes",
"com.atproto.admin.getModerationAction",
"com.atproto.admin.getModerationActions",
"com.atproto.admin.getModerationReport",
"com.atproto.admin.getModerationReports",
"com.atproto.admin.getRecord",
"com.atproto.admin.getRepo",
"com.atproto.admin.searchRepos",
"com.atproto.server.getAccountInviteCodes",
"com.atproto.server.getSession",
"com.atproto.server.listAppPasswords",
]);