-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyuque.tea
418 lines (359 loc) · 10.6 KB
/
yuque.tea
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
import YuqueUtil;
module Yuque {
prop basePath = "/api/v2";
type @domain = string
type @authToken = string
model Config {
authToken: string,
domain: string
}
init(config: Config) {
@authToken = config.authToken;
@domain = config.domain;
}
api get(path: string, params: object): object {
protocol = 'https';
method = 'GET';
pathname = `${__module.basePath}${path}`;
query = YuqueUtil.toQuery({
...params
});
headers = {
host = @domain,
x-auth-token = @authToken,
user-agent = "tea/nodejs",
};
} returns {
var result = YuqueUtil.readJSON(__response);
return result;
}
api post(path: string, data: object): object {
method = 'POST';
pathname = `${__module.basePath}${path}`;
headers = {
host = @domain,
x-auth-token = @authToken,
user-agent = "tea/nodejs"
};
body = YuqueUtil.toJSONString(data);
} returns {
var result = YuqueUtil.readJSON(__response);
return result;
}
api put(path: string, data: object): object {
method = 'PUT';
pathname = `${__module.basePath}${path}`;
headers = {
host = @domain,
x-auth-token = @authToken,
user-agent = "tea/nodejs"
};
body = YuqueUtil.toJSONString(data);
} returns {
var result = YuqueUtil.readJSON(__response);
return result;
}
api destroy(path: string, data: object): object {
method = 'DELETE';
pathname = `${__module.basePath}${path}`;
headers = {
host = @domain,
x-auth-token = @authToken,
user-agent = "tea/nodejs"
};
body = YuqueUtil.toJSONString(data);
} returns {
var result = YuqueUtil.readJSON(__response);
return result;
}
model HelloResponse = {
data: Hello
};
model Hello = {
message: string
}
async function hello(): HelloResponse {
return get('/hello', {});
}
// model Document = {
// id: number,
// title: string,
// slug: string,
// body: string,
// likes_count: number,
// created_at: string,
// updated_at: string,
// }
// function createDocument(repoid: string, doc: Document): Document {
// return post<Document>(`/repos/${repoid}/docs`, doc);
// }
model User = {
id: number(description="用户编号"),
type: string(description="类型 [User - 用户, Group - 团队]"),
login: string(description="用户个人路径"),
name: string(description="昵称"),
description: string(description="描述"),
avatarUrl: string(name="avatar_url", description="头像 URL"),
createdAt: string(name="created_at", description="创建时间"),
updatedAt: string(name="updated_at", description="更新时间")
}
model UserResponse {
data: User
}
/**
* 获取单个用户信息
* @param login 用户个人路径
*/
async function getUserById(login: string): UserResponse {
return get(`/users/${login}`, {});
}
/**
* 获取认证的用户的个人信息
*/
async function getUser(): UserResponse {
return get(`/user`, {});
}
model Group = {
id?: string,
login: string,
name: string,
avatarUrl?: string(name="avatar_url"),
ownerId: string(name="owner_id"),
description: string,
createdAt: string(name="created_at", description="创建时间"),
updatedAt: string(name="updated_at", description="更新时间")
}
model GroupsResponse {
data: [ Group ]
}
/**
* 获取某个用户的加入的组织列表
* @param login 用户个人路径
*/
async function getGroupsByUser(login: string): GroupsResponse {
return get(`/users/${login}/groups`, {});
}
model UsersResponse {
data: [ User ]
}
/**
* 获取公开组织列表
*/
async function getGroups(): UsersResponse {
return get(`/groups`, {});
}
model GroupResponse {
data: Group
}
/**
* 创建 Group
*/
async function createGroup(group: Group): GroupResponse {
return post(`/groups`, group);
}
model GroupDetailResponse = {
abilities: {
read: boolean,
update: boolean,
destroy: boolean,
groupUser: {
create: boolean,
update: boolean,
destroy: boolean
}(name="group_user"),
repo: {
create: boolean,
update: boolean,
destroy: boolean
}
},
data: [ Group ]
}
/**
* 获取公开组织列表
*/
async function getGroup(groupid: string): GroupDetailResponse {
return get(`/groups/${groupid}`, {});
}
/**
* 更新团队信息
*/
async function updateGroup(groupid: string, params: object): GroupResponse {
return put(`/groups/${groupid}`, params);
}
/**
* 删除团队
*/
async function destryGroup(groupid: string): object {
return destroy(`/groups/${groupid}`, {});
}
model GroupUser = {
id: number(description="成员编号"),
groupId: number(name="group_id", description="团队 id"),
userId: number(name="user_id", description="成员 id"),
role: number(description="角色,0 为管理员,1 为成员"),
user: User(description="用户详细信息"),
createdAt: string(name="created_at", description="创建时间"),
updatedAt: string(name="updated_at", description="更新时间")
}
model GroupUsersResponse {
data: [ GroupUser ]
}
/**
* 获取组织成员信息
*/
async function getGroupMembers(groupid: string): GroupUsersResponse {
return get(`/groups/${groupid}/users`, {});
}
model GroupUserResponse {
data: GroupUser
}
/**
* 更新或创建团队成员
*/
async function updateGroupMember(groupid: string, userid: string, params: object): GroupUserResponse {
return put(`/groups/${groupid}/users/${userid}`, params);
}
/**
* 删除团队成员
*/
async function destroyGroupMember(groupid: string, userid: string): object {
return destroy(`/groups/${groupid}/users/${userid}`, {});
}
model Book = {
id: number(description="仓库编号"),
type: string(description="类型 [Book - 文档]"),
slug: string(description="仓库路径"),
name: string(description="名称"),
namespace: string(description="仓库完整路径 user.login/book.slug"),
userId: number(name="user_id", description="所属的团队/用户编号"),
user: User(description="<UserSerializer>"),
description: string(description="介绍"),
creatorId: number(name="creator_id", description="创建人 User Id"),
public: number(description="公开状态 [1 - 公开, 0 - 私密]"),
likesCount: number(name="likes_count", description="喜欢数量"),
watchesCount: number(name="watches_count", description="订阅数量"),
createdAt: string(name="created_at", description="创建时间"),
updatedAt: string(name="updated_at", description="更新时间")
}
model BooksResponse {
data: [ Book ]
}
/**
* 获取一个用户/团队下的知识库
*/
async function getBooksByUser(userid: string, params: object): BooksResponse {
return get(`/users/${userid}/repos`, params);
}
/**
* 在用户/团队下创建知识库
*/
async function createBook(userid: string, params: object): BooksResponse {
return post(`/groups/${userid}/repos`, params);
}
model BookResponse {
data: Book
}
/**
* 获取一个知识库详情
*/
async function getBook(namespace: string): BookResponse {
return get(`/repos/${namespace}`, {});
}
/**
* 更新知识库
*/
async function updateBook(namespace: string, params: object): BookResponse {
return put(`/repos/${namespace}`, params);
}
/**
* 删除知识库
*/
async function destroyBook(namespace: string): object {
return destroy(`/repos/${namespace}`, {});
}
model BookToc = {
title: string(description="标题"),
slug: string(description="路径"),
depth: number(description="层级"),
}
model BookTocsResponse {
data: [ BookToc ]
}
/**
* 获取一个知识库的目录
*/
async function getBookToc(namespace: string): BookTocsResponse {
return get(`/repos/${namespace}/toc`, {});
}
model SearchQuery = {
query: string,
type?: string
}
/**
* FIXME: 如何传递 query
* 搜索知识库
*/
async function searchBook(params: SearchQuery): BooksResponse {
return get(`/search/repos`, params);
}
model Doc {
id: number(description="文档编号"),
slug: string(description="文档路径"),
title: string(description="标题"),
bookId: number(name="book_id", description="仓库编号,就是 repo_id"),
book: Book(description="仓库信息 <BookSerializer>,就是 repo 信息"),
userId: number(name="user_id", description="用户/团队编号"),
user: User(description="用户/团队信息 <UserSerializer>"),
format: string(description="描述了正文的格式 [lake , markdown]"),
body: string(description="正文 Markdown 源代码"),
bodyDraft: string(name="body_draft", description="草稿 Markdown 源代码"),
bodyHtml: string(name="body_html", description="转换过后的正文 HTML"),
bodyLake: string(name="body_lake", description="语雀 lake 格式的文档内容"),
creatorId: number(name="creator_id", description="文档创建人 User Id"),
public: number(description="公开级别 [0 - 私密, 1 - 公开]"),
status: number(description="状态 [0 - 草稿, 1 - 发布]"),
likesCount: number(name="likes_count", description="赞数量"),
commentsCount: number(name="comments_count", description="评论数量"),
contentUpdatedAt: string(name="content_updated_at", description="文档内容更新时间"),
deletedAt: string(name="deleted_at", description="删除时间,未删除为 null"),
createdAt: string(name="created_at", description="创建时间"),
updatedAt: string(name="updated_at", description="更新时间"),
}
model DocsResponse {
data: [ Doc ]
}
model DocResponse {
data: Doc
}
/**
* 获取知识库下文档列表
*/
async function getDocs(namespace: string): DocsResponse {
return get(`/repos/${namespace}/docs`, {});
}
/**
* 获取单篇文档详情
*/
async function getDoc(namespace: string, slug: string): DocResponse {
return get(`/repos/${namespace}/docs/${slug}`, {});
}
/**
* 创建文档
*/
async function createDoc(namespace: string, params: object): DocResponse {
return post(`/repos/${namespace}/docs`, params);
}
/**
* 更新文档
*/
async function updateDoc(namespace: string, slug: string, params: object): DocResponse {
return put(`/repos/${namespace}/docs/${slug}`, params);
}
/**
* 删除文档
*/
async function destroyDoc(namespace: string, slug: string): object {
return destroy(`/repos/${namespace}/docs/${slug}`, {});
}
}