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