@mix-space-lts/api-client 2.4.2 → 2.4.3

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/dist/index.cjs ADDED
@@ -0,0 +1,1340 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ //#region utils/index.ts
4
+ const isPlainObject = (obj) => isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]" && Object.getPrototypeOf(obj) === Object.prototype;
5
+ const sortOrderToNumber = (order) => {
6
+ return {
7
+ asc: 1,
8
+ desc: -1
9
+ }[order] || 1;
10
+ };
11
+ const isObject = (obj) => obj && typeof obj === "object";
12
+ const destructureData = (payload) => {
13
+ if (typeof payload !== "object") return payload;
14
+ if (payload === null) return payload;
15
+ const data = payload.data;
16
+ if (isPlainObject(data) && Object.keys(payload).length === 1) {
17
+ const d = Object.assign({}, data);
18
+ attachRawFromOneToAnthor(payload, d);
19
+ return d;
20
+ }
21
+ return payload;
22
+ };
23
+ const attachRawFromOneToAnthor = (from, to) => {
24
+ if (!from || !isObject(to)) return;
25
+ [
26
+ "$raw",
27
+ "$request",
28
+ "$serialized"
29
+ ].forEach((key) => {
30
+ from[key] && Object.defineProperty(to, key, {
31
+ get() {
32
+ return from[key];
33
+ },
34
+ enumerable: false
35
+ });
36
+ });
37
+ };
38
+
39
+ //#endregion
40
+ //#region utils/camelcase-keys.ts
41
+ /**
42
+ * A simple camelCase function that only handles strings, but not handling symbol, date, or other complex case.
43
+ * If you need to handle more complex cases, please use camelcase-keys package.
44
+ */
45
+ const camelcaseKeys = (obj) => {
46
+ if (Array.isArray(obj)) return obj.map((x) => camelcaseKeys(x));
47
+ if (isPlainObject(obj)) return Object.keys(obj).reduce((result, key) => {
48
+ const nextKey = isMongoId(key) ? key : camelcase(key);
49
+ result[nextKey] = camelcaseKeys(obj[key]);
50
+ return result;
51
+ }, {});
52
+ return obj;
53
+ };
54
+ function camelcase(str) {
55
+ return str.replace(/^_+/, "").replaceAll(/([_-][a-z])/gi, ($1) => {
56
+ return $1.toUpperCase().replace("-", "").replace("_", "");
57
+ });
58
+ }
59
+ const isMongoId = (id) => id.length === 24 && /^[\dA-F]{24}$/i.test(id);
60
+
61
+ //#endregion
62
+ //#region utils/path.ts
63
+ const resolveFullPath = (endpoint, path) => {
64
+ if (!path.startsWith("/")) path = `/${path}`;
65
+ return `${endpoint}${path}`;
66
+ };
67
+
68
+ //#endregion
69
+ //#region utils/auto-bind.ts
70
+ const getAllProperties = (object) => {
71
+ const properties = /* @__PURE__ */ new Set();
72
+ do
73
+ for (const key of Reflect.ownKeys(object)) properties.add([object, key]);
74
+ while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
75
+ return properties;
76
+ };
77
+ function autoBind(self, { include, exclude } = {}) {
78
+ const filter = (key) => {
79
+ const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
80
+ if (include) return include.some(match);
81
+ if (exclude) return !exclude.some(match);
82
+ return true;
83
+ };
84
+ for (const [object, key] of getAllProperties(self.constructor.prototype)) {
85
+ if (key === "constructor" || !filter(key)) continue;
86
+ const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
87
+ if (descriptor && typeof descriptor.value === "function") self[key] = self[key].bind(self);
88
+ }
89
+ return self;
90
+ }
91
+
92
+ //#endregion
93
+ //#region controllers/ack.ts
94
+ /**
95
+ * @support core >= 4.4.0
96
+ */
97
+ var AckController = class {
98
+ constructor(client) {
99
+ this.client = client;
100
+ this.base = "ack";
101
+ this.name = "ack";
102
+ autoBind(this);
103
+ }
104
+ get proxy() {
105
+ return this.client.proxy(this.base);
106
+ }
107
+ read(type, id) {
108
+ return this.proxy.post({ data: {
109
+ type: "read",
110
+ payload: {
111
+ type,
112
+ id
113
+ }
114
+ } });
115
+ }
116
+ };
117
+
118
+ //#endregion
119
+ //#region controllers/activity.ts
120
+ /**
121
+ * @support core >= 4.3.0
122
+ */
123
+ var ActivityController = class {
124
+ constructor(client) {
125
+ this.client = client;
126
+ this.base = "activity";
127
+ this.name = "activity";
128
+ autoBind(this);
129
+ }
130
+ get proxy() {
131
+ return this.client.proxy(this.base);
132
+ }
133
+ likeIt(type, id) {
134
+ return this.proxy.like.post({ data: {
135
+ type: type.toLowerCase(),
136
+ id
137
+ } });
138
+ }
139
+ /**
140
+ *
141
+ * @support core >= 5.0.0
142
+ */
143
+ getPresence(roomName) {
144
+ return this.proxy.presence.get({ params: { room_name: roomName } });
145
+ }
146
+ /**
147
+ *
148
+ * @support core >= 5.0.0
149
+ */
150
+ updatePresence({ identity, position, roomName, sid, ts, displayName, readerId }) {
151
+ return this.proxy.presence.update.post({ data: {
152
+ identity,
153
+ position,
154
+ ts: ts || Date.now(),
155
+ roomName,
156
+ sid,
157
+ readerId,
158
+ displayName
159
+ } });
160
+ }
161
+ async getRoomsInfo() {
162
+ return this.proxy.rooms.get();
163
+ }
164
+ async getRecentActivities() {
165
+ return this.proxy.recent.get();
166
+ }
167
+ async getLastYearPublication() {
168
+ return this.proxy(`last-year`).publication.get();
169
+ }
170
+ };
171
+
172
+ //#endregion
173
+ //#region controllers/aggregate.ts
174
+ var AggregateController = class {
175
+ constructor(client) {
176
+ this.client = client;
177
+ this.base = "aggregate";
178
+ this.name = "aggregate";
179
+ autoBind(this);
180
+ }
181
+ get proxy() {
182
+ return this.client.proxy(this.base);
183
+ }
184
+ /**
185
+ * 获取聚合数据
186
+ */
187
+ getAggregateData(theme) {
188
+ return this.proxy.get({ params: { theme } });
189
+ }
190
+ /**
191
+ * 获取最新发布的内容
192
+ */
193
+ getTop(size = 5) {
194
+ return this.proxy.top.get({ params: { size } });
195
+ }
196
+ getTimeline(options) {
197
+ const { sort, type, year } = options || {};
198
+ return this.proxy.timeline.get({ params: {
199
+ sort: sort && sortOrderToNumber(sort),
200
+ type,
201
+ year
202
+ } });
203
+ }
204
+ getLatest(options) {
205
+ const { limit, types, combined } = options || {};
206
+ return this.proxy.latest.get({ params: {
207
+ limit,
208
+ types: types?.join(","),
209
+ combined
210
+ } });
211
+ }
212
+ /**
213
+ * 获取聚合数据统计
214
+ */
215
+ getStat() {
216
+ return this.proxy.stat.get();
217
+ }
218
+ };
219
+
220
+ //#endregion
221
+ //#region controllers/ai.ts
222
+ /**
223
+ * @support core >= 5.6.0
224
+ */
225
+ var AIController = class {
226
+ constructor(client) {
227
+ this.client = client;
228
+ this.base = "ai";
229
+ this.name = "ai";
230
+ autoBind(this);
231
+ }
232
+ get proxy() {
233
+ return this.client.proxy(this.base);
234
+ }
235
+ async getSummary({ articleId, lang = "zh-CN", onlyDb }) {
236
+ return this.proxy.summaries.article(articleId).get({ params: {
237
+ lang,
238
+ onlyDb
239
+ } });
240
+ }
241
+ async generateSummary(articleId, lang = "zh-CN", token = "") {
242
+ return this.proxy.summaries.generate.post({
243
+ params: { token },
244
+ data: {
245
+ lang,
246
+ refId: articleId
247
+ }
248
+ });
249
+ }
250
+ /**
251
+ * Core >= 8.3.0
252
+ * @param articleId
253
+ */
254
+ async getDeepReading(articleId) {
255
+ return this.proxy("deep-readings").article(articleId).get();
256
+ }
257
+ /**
258
+ * Get translation for an article
259
+ * @support core >= 9.4.0
260
+ */
261
+ async getTranslation({ articleId, lang }) {
262
+ return this.proxy.translations.article(articleId).get({ params: { lang } });
263
+ }
264
+ /**
265
+ * Get available translation languages for an article
266
+ * @support core >= 9.4.0
267
+ */
268
+ async getAvailableLanguages(articleId) {
269
+ return this.proxy.translations.article(articleId).languages.get();
270
+ }
271
+ /**
272
+ * Get URL for streaming summary generation (SSE)
273
+ *
274
+ * @see AISummaryStreamEvent for event types
275
+ * @support core >= 9.4.0
276
+ */
277
+ getSummaryGenerateUrl({ articleId, lang }) {
278
+ const baseUrl = this.client.endpoint;
279
+ const params = new URLSearchParams();
280
+ if (lang) params.set("lang", lang);
281
+ const query = params.toString();
282
+ return `${baseUrl}/${this.base}/summaries/article/${articleId}/generate${query ? `?${query}` : ""}`;
283
+ }
284
+ /**
285
+ * Stream summary generation using fetch
286
+ *
287
+ * @see AISummaryStreamEvent for event types
288
+ * @support core >= 9.4.0
289
+ */
290
+ async streamSummaryGenerate({ articleId, lang }, fetchOptions) {
291
+ const url = this.getSummaryGenerateUrl({
292
+ articleId,
293
+ lang
294
+ });
295
+ return fetch(url, {
296
+ ...fetchOptions,
297
+ headers: {
298
+ Accept: "text/event-stream",
299
+ ...fetchOptions?.headers
300
+ }
301
+ });
302
+ }
303
+ /**
304
+ * Get URL for streaming translation generation (SSE)
305
+ *
306
+ * @see AITranslationStreamEvent for event types
307
+ * @support core >= 9.4.0
308
+ */
309
+ getTranslationGenerateUrl({ articleId, lang }) {
310
+ const baseUrl = this.client.endpoint;
311
+ const params = new URLSearchParams();
312
+ params.set("lang", lang);
313
+ return `${baseUrl}/${this.base}/translations/article/${articleId}/generate?${params.toString()}`;
314
+ }
315
+ /**
316
+ * Stream translation generation using fetch
317
+ *
318
+ * @see AITranslationStreamEvent for event types
319
+ * @support core >= 9.4.0
320
+ */
321
+ async streamTranslationGenerate({ articleId, lang }, fetchOptions) {
322
+ const url = this.getTranslationGenerateUrl({
323
+ articleId,
324
+ lang
325
+ });
326
+ return fetch(url, {
327
+ ...fetchOptions,
328
+ headers: {
329
+ Accept: "text/event-stream",
330
+ ...fetchOptions?.headers
331
+ }
332
+ });
333
+ }
334
+ };
335
+
336
+ //#endregion
337
+ //#region core/error.ts
338
+ var RequestError = class extends Error {
339
+ constructor(message, status, path, raw) {
340
+ super(message);
341
+ this.status = status;
342
+ this.path = path;
343
+ this.raw = raw;
344
+ }
345
+ };
346
+
347
+ //#endregion
348
+ //#region models/category.ts
349
+ let CategoryType = /* @__PURE__ */ function(CategoryType) {
350
+ CategoryType[CategoryType["Category"] = 0] = "Category";
351
+ CategoryType[CategoryType["Tag"] = 1] = "Tag";
352
+ return CategoryType;
353
+ }({});
354
+
355
+ //#endregion
356
+ //#region controllers/category.ts
357
+ var CategoryController = class {
358
+ constructor(client) {
359
+ this.client = client;
360
+ this.name = "category";
361
+ this.base = "categories";
362
+ autoBind(this);
363
+ }
364
+ get proxy() {
365
+ return this.client.proxy(this.base);
366
+ }
367
+ getAllCategories() {
368
+ return this.proxy.get({ params: { type: CategoryType.Category } });
369
+ }
370
+ getAllTags() {
371
+ return this.proxy.get({ params: { type: CategoryType.Tag } });
372
+ }
373
+ async getCategoryDetail(ids) {
374
+ if (typeof ids === "string") {
375
+ const data = await this.proxy.get({ params: { ids } });
376
+ const result = Object.values(data.entries)[0];
377
+ attachRawFromOneToAnthor(data, result);
378
+ return result;
379
+ } else if (Array.isArray(ids)) {
380
+ const data = await this.proxy.get({ params: { ids: ids.join(",") } });
381
+ const entries = data?.entries;
382
+ if (!entries) throw new RequestError("data structure error", 500, data.$request.path, data);
383
+ const map = new Map(Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]));
384
+ attachRawFromOneToAnthor(data, map);
385
+ return map;
386
+ }
387
+ }
388
+ async getCategoryByIdOrSlug(idOrSlug) {
389
+ return destructureData(await this.proxy(idOrSlug).get());
390
+ }
391
+ async getTagByName(name) {
392
+ return await this.proxy(name).get({ params: { tag: 1 } });
393
+ }
394
+ };
395
+
396
+ //#endregion
397
+ //#region controllers/comment.ts
398
+ var CommentController = class {
399
+ constructor(client) {
400
+ this.client = client;
401
+ this.base = "comments";
402
+ this.name = "comment";
403
+ autoBind(this);
404
+ }
405
+ get proxy() {
406
+ return this.client.proxy(this.base);
407
+ }
408
+ /**
409
+ * 根据 comment id 获取评论,包括子评论
410
+ */
411
+ getById(id) {
412
+ return this.proxy(id).get();
413
+ }
414
+ /**
415
+ * 获取文章的评论列表
416
+ * @param refId 文章 Id
417
+ */
418
+ getByRefId(refId, pagination = {}) {
419
+ const { page, size } = pagination;
420
+ return this.proxy.ref(refId).get({ params: {
421
+ page: page || 1,
422
+ size: size || 10
423
+ } });
424
+ }
425
+ getThreadReplies(rootCommentId, params = {}) {
426
+ return this.proxy.thread(rootCommentId).get({ params });
427
+ }
428
+ /**
429
+ * 评论
430
+ */
431
+ guestComment(refId, data) {
432
+ return this.proxy.guest(refId).post({ data });
433
+ }
434
+ /**
435
+ * 回复评论
436
+ */
437
+ guestReply(commentId, data) {
438
+ return this.proxy.guest.reply(commentId).post({ data });
439
+ }
440
+ readerComment(refId, data) {
441
+ return this.proxy.reader(refId).post({ data });
442
+ }
443
+ readerReply(commentId, data) {
444
+ return this.proxy.reader.reply(commentId).post({ data });
445
+ }
446
+ };
447
+
448
+ //#endregion
449
+ //#region controllers/base.ts
450
+ var BaseCrudController = class {
451
+ constructor(client) {
452
+ this.client = client;
453
+ autoBind(this);
454
+ }
455
+ get proxy() {
456
+ return this.client.proxy(this.base);
457
+ }
458
+ getById(id) {
459
+ return this.proxy(id).get();
460
+ }
461
+ getAll() {
462
+ return this.proxy.all.get();
463
+ }
464
+ /**
465
+ * 带分页的查询
466
+ * @param page
467
+ * @param perPage
468
+ */
469
+ getAllPaginated(page, perPage, sortOption) {
470
+ return this.proxy.get({ params: {
471
+ page,
472
+ size: perPage,
473
+ ...sortOption
474
+ } });
475
+ }
476
+ };
477
+
478
+ //#endregion
479
+ //#region controllers/link.ts
480
+ var LinkController = class extends BaseCrudController {
481
+ constructor(client) {
482
+ super(client);
483
+ this.client = client;
484
+ this.name = ["link", "friend"];
485
+ this.base = "links";
486
+ autoBind(this);
487
+ }
488
+ async canApplyLink() {
489
+ const { can } = await this.proxy.audit.get();
490
+ return can;
491
+ }
492
+ async applyLink(data) {
493
+ return await this.proxy.audit.post({ data });
494
+ }
495
+ };
496
+
497
+ //#endregion
498
+ //#region controllers/note.ts
499
+ var NoteController = class {
500
+ constructor(client) {
501
+ this.client = client;
502
+ this.base = "notes";
503
+ this.name = "note";
504
+ autoBind(this);
505
+ }
506
+ get proxy() {
507
+ return this.client.proxy(this.base);
508
+ }
509
+ /**
510
+ * 最新日记
511
+ */
512
+ getLatest() {
513
+ return this.proxy.latest.get();
514
+ }
515
+ getNoteById(...rest) {
516
+ const [id, password = void 0, singleResult = false] = rest;
517
+ if (typeof id === "number") return this.proxy.nid(id.toString()).get({ params: {
518
+ password,
519
+ single: singleResult ? "1" : void 0
520
+ } });
521
+ else return this.proxy(id).get();
522
+ }
523
+ /**
524
+ * 根据 nid 获取日记,支持翻译参数
525
+ * @param nid 日记编号
526
+ * @param options 可选参数:password, single, lang
527
+ */
528
+ getNoteByNid(nid, options) {
529
+ const { password, single, lang, prefer } = options || {};
530
+ return this.proxy.nid(nid.toString()).get({ params: {
531
+ password,
532
+ single: single ? "1" : void 0,
533
+ lang,
534
+ prefer
535
+ } });
536
+ }
537
+ getNoteBySlugDate(year, month, day, slug, options) {
538
+ const { password, single, lang, prefer } = options || {};
539
+ return this.proxy(year.toString())(month.toString())(day.toString())(slug).get({ params: {
540
+ password,
541
+ single: single ? "1" : void 0,
542
+ lang,
543
+ prefer
544
+ } });
545
+ }
546
+ /**
547
+ * 日记列表分页
548
+ */
549
+ getList(page = 1, perPage = 10, options = {}) {
550
+ const { select, sortBy, sortOrder, year, lang, withSummary } = options;
551
+ return this.proxy.get({ params: {
552
+ page,
553
+ size: perPage,
554
+ select: select?.join(" "),
555
+ sortBy,
556
+ sortOrder,
557
+ year,
558
+ lang,
559
+ withSummary: withSummary ? "1" : void 0
560
+ } });
561
+ }
562
+ /**
563
+ * 获取当前日记的上下各 n / 2 篇日记
564
+ * @param id 当前日记 ID
565
+ * @param size 返回数量,默认 5
566
+ * @param options 可选参数,包含 lang 用于获取翻译版本
567
+ */
568
+ getMiddleList(id, size = 5, options) {
569
+ const { lang } = options || {};
570
+ return this.proxy.list(id).get({ params: {
571
+ size,
572
+ lang
573
+ } });
574
+ }
575
+ /**
576
+ * 获取专栏内的所有日记
577
+ * @param topicId 专栏 ID
578
+ * @param page 页码,默认 1
579
+ * @param size 每页数量,默认 10
580
+ * @param options 可选参数,包含排序选项和 lang 用于获取翻译版本
581
+ */
582
+ getNoteByTopicId(topicId, page = 1, size = 10, options = {}) {
583
+ const { lang, ...sortOptions } = options;
584
+ return this.proxy.topics(topicId).get({ params: {
585
+ page,
586
+ size,
587
+ lang,
588
+ ...sortOptions
589
+ } });
590
+ }
591
+ };
592
+
593
+ //#endregion
594
+ //#region controllers/owner.ts
595
+ var UserController = class {
596
+ constructor(client) {
597
+ this.client = client;
598
+ this.base = "owner";
599
+ this.name = ["owner"];
600
+ autoBind(this);
601
+ }
602
+ get proxy() {
603
+ return this.client.proxy(this.base);
604
+ }
605
+ get authProxy() {
606
+ return this.client.proxy("auth");
607
+ }
608
+ normalizeToken(token) {
609
+ const normalized = token?.trim();
610
+ if (!normalized) return;
611
+ return normalized.replace(/^bearer\s+/i, "");
612
+ }
613
+ /**
614
+ * @deprecated Use `getOwnerInfo()` instead.
615
+ */
616
+ getMasterInfo() {
617
+ return this.getOwnerInfo();
618
+ }
619
+ getOwnerInfo() {
620
+ return this.proxy.get();
621
+ }
622
+ login(username, password, options) {
623
+ return this.authProxy("sign-in").username.post({ data: {
624
+ username,
625
+ password,
626
+ ...options
627
+ } });
628
+ }
629
+ logout() {
630
+ return this.authProxy("sign-out").post();
631
+ }
632
+ /**
633
+ * Better Auth raw session (`/auth/get-session`).
634
+ */
635
+ getAuthSession(options) {
636
+ return this.authProxy("get-session").get({ params: options });
637
+ }
638
+ /**
639
+ * Core session summary (`/auth/session`).
640
+ */
641
+ getSession() {
642
+ return this.authProxy.session.get();
643
+ }
644
+ getProviders() {
645
+ return this.authProxy.providers.get();
646
+ }
647
+ getAllowLoginMethods() {
648
+ return this.proxy("allow-login").get();
649
+ }
650
+ listSessions() {
651
+ return this.authProxy("list-sessions").get();
652
+ }
653
+ revokeSession(token) {
654
+ return this.authProxy("revoke-session").post({ data: { token } });
655
+ }
656
+ revokeSessions() {
657
+ return this.authProxy("revoke-sessions").post();
658
+ }
659
+ revokeOtherSessions() {
660
+ return this.authProxy("revoke-other-sessions").post();
661
+ }
662
+ checkTokenValid(token) {
663
+ const normalized = this.normalizeToken(token);
664
+ return this.proxy.check_logged.get({ params: normalized ? { token: normalized } : void 0 });
665
+ }
666
+ };
667
+
668
+ //#endregion
669
+ //#region controllers/page.ts
670
+ var PageController = class {
671
+ constructor(client) {
672
+ this.client = client;
673
+ this.base = "pages";
674
+ this.name = "page";
675
+ autoBind(this);
676
+ }
677
+ get proxy() {
678
+ return this.client.proxy(this.base);
679
+ }
680
+ /**
681
+ * 页面列表
682
+ */
683
+ getList(page = 1, perPage = 10, options = {}) {
684
+ const { select, sortBy, sortOrder } = options;
685
+ return this.proxy.get({ params: {
686
+ page,
687
+ size: perPage,
688
+ select: select?.join(" "),
689
+ sortBy,
690
+ sortOrder
691
+ } });
692
+ }
693
+ /**
694
+ * 页面详情
695
+ */
696
+ getById(id) {
697
+ return this.proxy(id).get();
698
+ }
699
+ /**
700
+ * 根据路径获取页面
701
+ * @param slug 路径
702
+ * @returns
703
+ */
704
+ getBySlug(slug, options) {
705
+ return this.proxy.slug(slug).get({ params: options?.prefer ? { prefer: options.prefer } : void 0 });
706
+ }
707
+ };
708
+
709
+ //#endregion
710
+ //#region controllers/post.ts
711
+ var PostController = class {
712
+ constructor(client) {
713
+ this.client = client;
714
+ this.base = "posts";
715
+ this.name = "post";
716
+ autoBind(this);
717
+ }
718
+ get proxy() {
719
+ return this.client.proxy(this.base);
720
+ }
721
+ /**
722
+ * 获取文章列表分页
723
+ * @param page
724
+ * @param perPage
725
+ * @param options 可选参数,包含 lang 用于获取翻译版本
726
+ * @returns 当传入 lang 时,返回的文章可能包含 isTranslated 和 translationMeta 字段
727
+ */
728
+ getList(page = 1, perPage = 10, options = {}) {
729
+ const { select, sortBy, sortOrder, year, truncate, lang } = options;
730
+ return this.proxy.get({ params: {
731
+ page,
732
+ size: perPage,
733
+ select: select?.join(" "),
734
+ sortBy,
735
+ sortOrder,
736
+ year,
737
+ truncate,
738
+ lang
739
+ } });
740
+ }
741
+ getPost(idOrCategoryName, slug, options) {
742
+ if (arguments.length == 1) return this.proxy(idOrCategoryName).get();
743
+ else {
744
+ const params = {};
745
+ if (options?.lang) params.lang = options.lang;
746
+ if (options?.prefer) params.prefer = options.prefer;
747
+ return this.proxy(idOrCategoryName)(slug).get({ params: Object.keys(params).length ? params : void 0 });
748
+ }
749
+ }
750
+ /**
751
+ * 获取最新的文章
752
+ */
753
+ getLatest() {
754
+ return this.proxy.latest.get();
755
+ }
756
+ getFullUrl(slug) {
757
+ return this.proxy("get-url")(slug).get();
758
+ }
759
+ };
760
+
761
+ //#endregion
762
+ //#region controllers/project.ts
763
+ var ProjectController = class extends BaseCrudController {
764
+ constructor(client) {
765
+ super(client);
766
+ this.client = client;
767
+ this.base = "projects";
768
+ this.name = "project";
769
+ autoBind(this);
770
+ }
771
+ };
772
+
773
+ //#endregion
774
+ //#region controllers/recently.ts
775
+ let RecentlyAttitudeResultEnum = /* @__PURE__ */ function(RecentlyAttitudeResultEnum) {
776
+ RecentlyAttitudeResultEnum[RecentlyAttitudeResultEnum["Inc"] = 1] = "Inc";
777
+ RecentlyAttitudeResultEnum[RecentlyAttitudeResultEnum["Dec"] = -1] = "Dec";
778
+ return RecentlyAttitudeResultEnum;
779
+ }({});
780
+ let RecentlyAttitudeEnum = /* @__PURE__ */ function(RecentlyAttitudeEnum) {
781
+ RecentlyAttitudeEnum[RecentlyAttitudeEnum["Up"] = 0] = "Up";
782
+ RecentlyAttitudeEnum[RecentlyAttitudeEnum["Down"] = 1] = "Down";
783
+ return RecentlyAttitudeEnum;
784
+ }({});
785
+ var RecentlyController = class {
786
+ constructor(client) {
787
+ this.client = client;
788
+ this.base = "recently";
789
+ this.name = ["recently", "shorthand"];
790
+ autoBind(this);
791
+ }
792
+ get proxy() {
793
+ return this.client.proxy(this.base);
794
+ }
795
+ /**
796
+ * 获取最新一条
797
+ */
798
+ getLatestOne() {
799
+ return this.proxy.latest.get();
800
+ }
801
+ getAll() {
802
+ return this.proxy.all.get();
803
+ }
804
+ getList({ before, after, size } = {}) {
805
+ return this.proxy.get({ params: {
806
+ before,
807
+ after,
808
+ size
809
+ } });
810
+ }
811
+ getById(id) {
812
+ return this.proxy(id).get();
813
+ }
814
+ /** 表态:点赞,点踩 */
815
+ attitude(id, attitude) {
816
+ return this.proxy.attitude(id).get({ params: { attitude } });
817
+ }
818
+ };
819
+
820
+ //#endregion
821
+ //#region controllers/say.ts
822
+ var SayController = class extends BaseCrudController {
823
+ constructor(client) {
824
+ super(client);
825
+ this.client = client;
826
+ this.base = "says";
827
+ this.name = "say";
828
+ autoBind(this);
829
+ }
830
+ get proxy() {
831
+ return this.client.proxy(this.base);
832
+ }
833
+ /**
834
+ * 获取随机一条
835
+ */
836
+ getRandom() {
837
+ return this.proxy.random.get();
838
+ }
839
+ };
840
+
841
+ //#endregion
842
+ //#region controllers/search.ts
843
+ var SearchController = class {
844
+ constructor(client) {
845
+ this.client = client;
846
+ this.base = "search";
847
+ this.name = "search";
848
+ autoBind(this);
849
+ }
850
+ get proxy() {
851
+ return this.client.proxy(this.base);
852
+ }
853
+ search(type, keyword, options = {}) {
854
+ return this.proxy(type).get({ params: {
855
+ keyword,
856
+ ...options
857
+ } });
858
+ }
859
+ /**
860
+ * 从 algolya 搜索
861
+ * https://www.algolia.com/doc/api-reference/api-methods/search/
862
+ * @param keyword
863
+ * @param options
864
+ * @returns
865
+ */
866
+ searchByAlgolia(keyword, options) {
867
+ return this.proxy("algolia").get({ params: {
868
+ keyword,
869
+ ...options
870
+ } });
871
+ }
872
+ };
873
+
874
+ //#endregion
875
+ //#region controllers/severless.ts
876
+ var ServerlessController = class {
877
+ constructor(client) {
878
+ this.client = client;
879
+ this.base = "serverless";
880
+ this.name = "serverless";
881
+ autoBind(this);
882
+ }
883
+ get proxy() {
884
+ return this.client.proxy(this.base);
885
+ }
886
+ getByReferenceAndName(reference, name) {
887
+ return this.proxy(reference)(name).get();
888
+ }
889
+ };
890
+
891
+ //#endregion
892
+ //#region controllers/snippet.ts
893
+ var SnippetController = class {
894
+ constructor(client) {
895
+ this.client = client;
896
+ this.base = "snippets";
897
+ this.name = "snippet";
898
+ autoBind(this);
899
+ }
900
+ get proxy() {
901
+ return this.client.proxy(this.base);
902
+ }
903
+ getByReferenceAndName(reference, name) {
904
+ return this.proxy(reference)(name).get();
905
+ }
906
+ };
907
+
908
+ //#endregion
909
+ //#region controllers/subscribe.ts
910
+ var SubscribeController = class {
911
+ constructor(client) {
912
+ this.client = client;
913
+ this.base = "subscribe";
914
+ this.name = "subscribe";
915
+ autoBind(this);
916
+ }
917
+ get proxy() {
918
+ return this.client.proxy(this.base);
919
+ }
920
+ /**
921
+ * 检查开启状态
922
+ */
923
+ check() {
924
+ return this.proxy.status.get();
925
+ }
926
+ subscribe(email, types) {
927
+ return this.proxy.post({ data: {
928
+ email,
929
+ types
930
+ } });
931
+ }
932
+ unsubscribe(email, cancelToken) {
933
+ return this.proxy.unsubscribe.get({ params: {
934
+ email,
935
+ cancelToken
936
+ } });
937
+ }
938
+ };
939
+
940
+ //#endregion
941
+ //#region controllers/topic.ts
942
+ var TopicController = class extends BaseCrudController {
943
+ constructor(client) {
944
+ super(client);
945
+ this.client = client;
946
+ this.base = "topics";
947
+ this.name = "topic";
948
+ autoBind(this);
949
+ }
950
+ get proxy() {
951
+ return this.client.proxy(this.base);
952
+ }
953
+ getTopicBySlug(slug) {
954
+ return this.proxy.slug(slug).get();
955
+ }
956
+ };
957
+
958
+ //#endregion
959
+ //#region controllers/index.ts
960
+ const allControllers = [
961
+ AckController,
962
+ ActivityController,
963
+ AggregateController,
964
+ AIController,
965
+ CategoryController,
966
+ CommentController,
967
+ LinkController,
968
+ NoteController,
969
+ PageController,
970
+ PostController,
971
+ ProjectController,
972
+ RecentlyController,
973
+ SayController,
974
+ SearchController,
975
+ ServerlessController,
976
+ SnippetController,
977
+ SubscribeController,
978
+ TopicController,
979
+ UserController
980
+ ];
981
+ const allControllerNames = [
982
+ "ai",
983
+ "ack",
984
+ "activity",
985
+ "aggregate",
986
+ "category",
987
+ "comment",
988
+ "link",
989
+ "note",
990
+ "page",
991
+ "post",
992
+ "project",
993
+ "topic",
994
+ "recently",
995
+ "say",
996
+ "search",
997
+ "snippet",
998
+ "serverless",
999
+ "subscribe",
1000
+ "owner",
1001
+ "friend",
1002
+ "shorthand"
1003
+ ];
1004
+
1005
+ //#endregion
1006
+ //#region core/attach-request.ts
1007
+ function attachRequestMethod(target) {
1008
+ Object.defineProperty(target, "$$get", { value(url, options) {
1009
+ const { params = {}, ...rest } = options;
1010
+ const qs = handleSearchParams(params);
1011
+ return target.instance.get(`${url}${qs ? String(`?${qs}`) : ""}`, rest);
1012
+ } });
1013
+ [
1014
+ "put",
1015
+ "post",
1016
+ "patch",
1017
+ "delete"
1018
+ ].forEach((method) => {
1019
+ Object.defineProperty(target, `$$${method}`, { value(path, options) {
1020
+ return target.instance[method](path, options);
1021
+ } });
1022
+ });
1023
+ }
1024
+ function handleSearchParams(obj) {
1025
+ if (!obj && typeof obj !== "object") throw new TypeError("params must be object.");
1026
+ if (obj instanceof URLSearchParams) return obj.toString();
1027
+ const search = new URLSearchParams();
1028
+ Object.entries(obj).forEach(([k, v]) => {
1029
+ if (typeof v === "undefined" || Object.prototype.toString.call(v) === "[object Null]") return;
1030
+ search.set(k, v);
1031
+ });
1032
+ return search.toString();
1033
+ }
1034
+
1035
+ //#endregion
1036
+ //#region core/client.ts
1037
+ const methodPrefix = "_$";
1038
+ var HTTPClient = class {
1039
+ constructor(_endpoint, _adaptor, options = {}) {
1040
+ this._endpoint = _endpoint;
1041
+ this._adaptor = _adaptor;
1042
+ this.options = options;
1043
+ this._endpoint = _endpoint.replace(/\/*$/, "");
1044
+ this._proxy = this.buildRoute(this)();
1045
+ options.transformResponse || (options.transformResponse = (data) => camelcaseKeys(data));
1046
+ options.getDataFromResponse || (options.getDataFromResponse = (res) => res.data);
1047
+ this.initGetClient();
1048
+ attachRequestMethod(this);
1049
+ }
1050
+ initGetClient() {
1051
+ for (const name of allControllerNames) Object.defineProperty(this, name, {
1052
+ get() {
1053
+ const client = Reflect.get(this, `${methodPrefix}${name}`);
1054
+ if (!client) throw new ReferenceError(`${name.charAt(0).toUpperCase() + name.slice(1)} Client not inject yet, please inject with client.injectClients(...)`);
1055
+ return client;
1056
+ },
1057
+ configurable: false,
1058
+ enumerable: false
1059
+ });
1060
+ }
1061
+ injectControllers(Controller, ...rest) {
1062
+ Controller = Array.isArray(Controller) ? Controller : [Controller, ...rest];
1063
+ for (const Client of Controller) {
1064
+ const cl = new Client(this);
1065
+ if (Array.isArray(cl.name)) for (const name of cl.name) attach.call(this, name, cl);
1066
+ else attach.call(this, cl.name, cl);
1067
+ }
1068
+ function attach(name, cl) {
1069
+ Object.defineProperty(this, `${methodPrefix}${name.toLowerCase()}`, {
1070
+ get() {
1071
+ return cl;
1072
+ },
1073
+ enumerable: false,
1074
+ configurable: false
1075
+ });
1076
+ }
1077
+ }
1078
+ get endpoint() {
1079
+ return this._endpoint;
1080
+ }
1081
+ get instance() {
1082
+ return this._adaptor;
1083
+ }
1084
+ request(options) {
1085
+ return this[`$$${String(options.method || "get").toLowerCase()}`](options.url, options);
1086
+ }
1087
+ get proxy() {
1088
+ return this._proxy;
1089
+ }
1090
+ buildRoute(manager) {
1091
+ const noop = () => {};
1092
+ const methods = [
1093
+ "get",
1094
+ "post",
1095
+ "delete",
1096
+ "patch",
1097
+ "put"
1098
+ ];
1099
+ const reflectors = [
1100
+ "toString",
1101
+ "valueOf",
1102
+ "inspect",
1103
+ "constructor",
1104
+ Symbol.toPrimitive
1105
+ ];
1106
+ const that = this;
1107
+ return () => {
1108
+ const route = [""];
1109
+ const handler = {
1110
+ get(target, name) {
1111
+ if (reflectors.includes(name)) return (withBase) => {
1112
+ if (withBase) {
1113
+ const path = resolveFullPath(that.endpoint, route.join("/"));
1114
+ route.length = 0;
1115
+ return path;
1116
+ } else {
1117
+ const path = route.join("/");
1118
+ route.length = 0;
1119
+ return path.startsWith("/") ? path : `/${path}`;
1120
+ }
1121
+ };
1122
+ if (methods.includes(name)) return async (options) => {
1123
+ const url = resolveFullPath(that.endpoint, route.join("/"));
1124
+ route.length = 0;
1125
+ let res;
1126
+ try {
1127
+ res = await manager.request({
1128
+ method: name,
1129
+ ...options,
1130
+ url
1131
+ });
1132
+ } catch (error) {
1133
+ let message = error.message;
1134
+ let code = error.code || error.status || error.statusCode || error.response?.status || error.response?.statusCode || error.response?.code || 500;
1135
+ if (that.options.getCodeMessageFromException) {
1136
+ const errorInfo = that.options.getCodeMessageFromException(error);
1137
+ message = errorInfo.message || message;
1138
+ code = errorInfo.code || code;
1139
+ }
1140
+ throw that.options.customThrowResponseError ? that.options.customThrowResponseError(error) : new RequestError(message, code, url, error);
1141
+ }
1142
+ const data = that.options.getDataFromResponse(res);
1143
+ if (!data) return null;
1144
+ const cameledObject = (Array.isArray(data) || isPlainObject(data)) && that.options.transformResponse ? that.options.transformResponse(data) : data;
1145
+ let nextObject = cameledObject;
1146
+ if (cameledObject && typeof cameledObject === "object") {
1147
+ nextObject = Array.isArray(cameledObject) ? [...cameledObject] : { ...cameledObject };
1148
+ Object.defineProperty(nextObject, "$raw", {
1149
+ get() {
1150
+ return res;
1151
+ },
1152
+ enumerable: false,
1153
+ configurable: false
1154
+ });
1155
+ Object.defineProperty(nextObject, "$request", {
1156
+ get() {
1157
+ return {
1158
+ url,
1159
+ method: name,
1160
+ options
1161
+ };
1162
+ },
1163
+ enumerable: false
1164
+ });
1165
+ Object.defineProperty(nextObject, "$serialized", { get() {
1166
+ return cameledObject;
1167
+ } });
1168
+ }
1169
+ return nextObject;
1170
+ };
1171
+ route.push(name);
1172
+ return new Proxy(noop, handler);
1173
+ },
1174
+ apply(target, _, args) {
1175
+ route.push(...args.filter((x) => x !== null));
1176
+ return new Proxy(noop, handler);
1177
+ }
1178
+ };
1179
+ return new Proxy(noop, handler);
1180
+ };
1181
+ }
1182
+ };
1183
+ function createClient(adapter) {
1184
+ return (endpoint, options) => {
1185
+ const client = new HTTPClient(endpoint, adapter, options);
1186
+ const { controllers } = options || {};
1187
+ if (controllers) client.injectControllers(controllers);
1188
+ return client;
1189
+ };
1190
+ }
1191
+
1192
+ //#endregion
1193
+ //#region models/aggregate.ts
1194
+ let TimelineType = /* @__PURE__ */ function(TimelineType) {
1195
+ TimelineType[TimelineType["Post"] = 0] = "Post";
1196
+ TimelineType[TimelineType["Note"] = 1] = "Note";
1197
+ return TimelineType;
1198
+ }({});
1199
+
1200
+ //#endregion
1201
+ //#region ../../apps/core/src/constants/db.constant.ts
1202
+ const NOTE_COLLECTION_NAME = "notes";
1203
+ const PAGE_COLLECTION_NAME = "pages";
1204
+ const POST_COLLECTION_NAME = "posts";
1205
+ const RECENTLY_COLLECTION_NAME = "recentlies";
1206
+ let CollectionRefTypes = /* @__PURE__ */ function(CollectionRefTypes) {
1207
+ CollectionRefTypes[CollectionRefTypes["Post"] = POST_COLLECTION_NAME] = "Post";
1208
+ CollectionRefTypes[CollectionRefTypes["Note"] = NOTE_COLLECTION_NAME] = "Note";
1209
+ CollectionRefTypes[CollectionRefTypes["Page"] = PAGE_COLLECTION_NAME] = "Page";
1210
+ CollectionRefTypes[CollectionRefTypes["Recently"] = RECENTLY_COLLECTION_NAME] = "Recently";
1211
+ return CollectionRefTypes;
1212
+ }({});
1213
+
1214
+ //#endregion
1215
+ //#region models/comment.ts
1216
+ let CommentState = /* @__PURE__ */ function(CommentState) {
1217
+ CommentState[CommentState["Unread"] = 0] = "Unread";
1218
+ CommentState[CommentState["Read"] = 1] = "Read";
1219
+ CommentState[CommentState["Junk"] = 2] = "Junk";
1220
+ return CommentState;
1221
+ }({});
1222
+
1223
+ //#endregion
1224
+ //#region models/link.ts
1225
+ let LinkType = /* @__PURE__ */ function(LinkType) {
1226
+ LinkType[LinkType["Friend"] = 0] = "Friend";
1227
+ LinkType[LinkType["Collection"] = 1] = "Collection";
1228
+ return LinkType;
1229
+ }({});
1230
+ let LinkState = /* @__PURE__ */ function(LinkState) {
1231
+ LinkState[LinkState["Pass"] = 0] = "Pass";
1232
+ LinkState[LinkState["Audit"] = 1] = "Audit";
1233
+ LinkState[LinkState["Outdate"] = 2] = "Outdate";
1234
+ LinkState[LinkState["Banned"] = 3] = "Banned";
1235
+ LinkState[LinkState["Reject"] = 4] = "Reject";
1236
+ return LinkState;
1237
+ }({});
1238
+
1239
+ //#endregion
1240
+ //#region models/page.ts
1241
+ let EnumPageType = /* @__PURE__ */ function(EnumPageType) {
1242
+ EnumPageType["md"] = "md";
1243
+ EnumPageType["html"] = "html";
1244
+ EnumPageType["frame"] = "frame";
1245
+ return EnumPageType;
1246
+ }({});
1247
+
1248
+ //#endregion
1249
+ //#region models/recently.ts
1250
+ let RecentlyRefTypes = /* @__PURE__ */ function(RecentlyRefTypes) {
1251
+ RecentlyRefTypes["Post"] = "Post";
1252
+ RecentlyRefTypes["Note"] = "Note";
1253
+ RecentlyRefTypes["Page"] = "Page";
1254
+ return RecentlyRefTypes;
1255
+ }({});
1256
+ let RecentlyTypeEnum = /* @__PURE__ */ function(RecentlyTypeEnum) {
1257
+ RecentlyTypeEnum["Text"] = "text";
1258
+ RecentlyTypeEnum["Book"] = "book";
1259
+ RecentlyTypeEnum["Media"] = "media";
1260
+ RecentlyTypeEnum["Music"] = "music";
1261
+ RecentlyTypeEnum["Github"] = "github";
1262
+ RecentlyTypeEnum["Link"] = "link";
1263
+ RecentlyTypeEnum["Academic"] = "academic";
1264
+ RecentlyTypeEnum["Code"] = "code";
1265
+ return RecentlyTypeEnum;
1266
+ }({});
1267
+
1268
+ //#endregion
1269
+ //#region models/snippet.ts
1270
+ let SnippetType = /* @__PURE__ */ function(SnippetType) {
1271
+ SnippetType["JSON"] = "json";
1272
+ SnippetType["Function"] = "function";
1273
+ SnippetType["Text"] = "text";
1274
+ SnippetType["YAML"] = "yaml";
1275
+ return SnippetType;
1276
+ }({});
1277
+
1278
+ //#endregion
1279
+ //#region ../../apps/core/src/modules/subscribe/subscribe.constant.ts
1280
+ const SubscribePostCreateBit = 1;
1281
+ const SubscribeNoteCreateBit = 2;
1282
+ const SubscribeSayCreateBit = 4;
1283
+ const SubscribeRecentCreateBit = 8;
1284
+ const SubscribeAllBit = 15;
1285
+ const SubscribeTypeToBitMap = {
1286
+ post_c: SubscribePostCreateBit,
1287
+ note_c: SubscribeNoteCreateBit,
1288
+ say_c: SubscribeSayCreateBit,
1289
+ recently_c: SubscribeRecentCreateBit,
1290
+ all: SubscribeAllBit
1291
+ };
1292
+
1293
+ //#endregion
1294
+ //#region index.ts
1295
+ var api_client_default = createClient;
1296
+
1297
+ //#endregion
1298
+ exports.AIController = AIController;
1299
+ exports.AckController = AckController;
1300
+ exports.ActivityController = ActivityController;
1301
+ exports.AggregateController = AggregateController;
1302
+ exports.CategoryController = CategoryController;
1303
+ exports.CategoryType = CategoryType;
1304
+ exports.CollectionRefTypes = CollectionRefTypes;
1305
+ exports.CommentController = CommentController;
1306
+ exports.CommentState = CommentState;
1307
+ exports.EnumPageType = EnumPageType;
1308
+ exports.LinkController = LinkController;
1309
+ exports.LinkState = LinkState;
1310
+ exports.LinkType = LinkType;
1311
+ exports.NoteController = NoteController;
1312
+ exports.PageController = PageController;
1313
+ exports.PostController = PostController;
1314
+ exports.ProjectController = ProjectController;
1315
+ exports.RecentlyAttitudeEnum = RecentlyAttitudeEnum;
1316
+ exports.RecentlyAttitudeResultEnum = RecentlyAttitudeResultEnum;
1317
+ exports.RecentlyController = RecentlyController;
1318
+ exports.RecentlyRefTypes = RecentlyRefTypes;
1319
+ exports.RecentlyTypeEnum = RecentlyTypeEnum;
1320
+ exports.RequestError = RequestError;
1321
+ exports.SayController = SayController;
1322
+ exports.SearchController = SearchController;
1323
+ exports.ServerlessController = ServerlessController;
1324
+ exports.SnippetController = SnippetController;
1325
+ exports.SnippetType = SnippetType;
1326
+ exports.SubscribeAllBit = SubscribeAllBit;
1327
+ exports.SubscribeController = SubscribeController;
1328
+ exports.SubscribeNoteCreateBit = SubscribeNoteCreateBit;
1329
+ exports.SubscribePostCreateBit = SubscribePostCreateBit;
1330
+ exports.SubscribeRecentCreateBit = SubscribeRecentCreateBit;
1331
+ exports.SubscribeSayCreateBit = SubscribeSayCreateBit;
1332
+ exports.SubscribeTypeToBitMap = SubscribeTypeToBitMap;
1333
+ exports.TimelineType = TimelineType;
1334
+ exports.TopicController = TopicController;
1335
+ exports.UserController = UserController;
1336
+ exports.allControllerNames = allControllerNames;
1337
+ exports.allControllers = allControllers;
1338
+ exports.createClient = createClient;
1339
+ exports.default = api_client_default;
1340
+ exports.simpleCamelcaseKeys = camelcaseKeys;