@mx-space/api-client 3.0.0 → 3.3.0

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 CHANGED
@@ -33,7 +33,6 @@ const attachRawFromOneToAnthor = (from, to) => {
33
33
  });
34
34
  });
35
35
  };
36
-
37
36
  //#endregion
38
37
  //#region utils/camelcase-keys.ts
39
38
  /**
@@ -55,14 +54,12 @@ function camelcase(str) {
55
54
  });
56
55
  }
57
56
  const isMongoId = (id) => id.length === 24 && /^[\dA-F]{24}$/i.test(id);
58
-
59
57
  //#endregion
60
58
  //#region utils/path.ts
61
59
  const resolveFullPath = (endpoint, path) => {
62
60
  if (!path.startsWith("/")) path = `/${path}`;
63
61
  return `${endpoint}${path}`;
64
62
  };
65
-
66
63
  //#endregion
67
64
  //#region utils/auto-bind.ts
68
65
  const getAllProperties = (object) => {
@@ -86,7 +83,6 @@ function autoBind(self, { include, exclude } = {}) {
86
83
  }
87
84
  return self;
88
85
  }
89
-
90
86
  //#endregion
91
87
  //#region controllers/ack.ts
92
88
  /**
@@ -112,7 +108,6 @@ var AckController = class {
112
108
  } });
113
109
  }
114
110
  };
115
-
116
111
  //#endregion
117
112
  //#region controllers/activity.ts
118
113
  /**
@@ -139,7 +134,17 @@ var ActivityController = class {
139
134
  * @support core >= 5.0.0
140
135
  */
141
136
  getPresence(roomName) {
142
- return this.proxy.presence.get({ params: { room_name: roomName } });
137
+ return this.proxy.presence.get({
138
+ params: { room_name: roomName },
139
+ transformResponse: (data) => {
140
+ const payload = data;
141
+ return {
142
+ ...camelcaseKeys(Object.fromEntries(Object.entries(payload).filter(([key]) => key !== "data" && key !== "readers"))),
143
+ data: Object.fromEntries(Object.entries(payload.data ?? {}).map(([identity, value]) => [identity, camelcaseKeys(value)])),
144
+ readers: Object.fromEntries(Object.entries(payload.readers ?? {}).map(([id, value]) => [id, camelcaseKeys(value)]))
145
+ };
146
+ }
147
+ });
143
148
  }
144
149
  /**
145
150
  *
@@ -166,7 +171,6 @@ var ActivityController = class {
166
171
  return this.proxy(`last-year`).publication.get();
167
172
  }
168
173
  };
169
-
170
174
  //#endregion
171
175
  //#region controllers/aggregate.ts
172
176
  var AggregateController = class {
@@ -217,7 +221,6 @@ var AggregateController = class {
217
221
  return this.proxy.stat.get();
218
222
  }
219
223
  };
220
-
221
224
  //#endregion
222
225
  //#region controllers/ai.ts
223
226
  /**
@@ -333,7 +336,6 @@ var AIController = class {
333
336
  });
334
337
  }
335
338
  };
336
-
337
339
  //#endregion
338
340
  //#region core/error.ts
339
341
  var RequestError = class extends Error {
@@ -344,7 +346,6 @@ var RequestError = class extends Error {
344
346
  this.raw = raw;
345
347
  }
346
348
  };
347
-
348
349
  //#endregion
349
350
  //#region models/category.ts
350
351
  let CategoryType = /* @__PURE__ */ function(CategoryType) {
@@ -352,7 +353,6 @@ let CategoryType = /* @__PURE__ */ function(CategoryType) {
352
353
  CategoryType[CategoryType["Tag"] = 1] = "Tag";
353
354
  return CategoryType;
354
355
  }({});
355
-
356
356
  //#endregion
357
357
  //#region controllers/category.ts
358
358
  var CategoryController = class {
@@ -366,10 +366,10 @@ var CategoryController = class {
366
366
  return this.client.proxy(this.base);
367
367
  }
368
368
  getAllCategories() {
369
- return this.proxy.get({ params: { type: CategoryType.Category } });
369
+ return this.proxy.get({ params: { type: 0 } });
370
370
  }
371
371
  getAllTags() {
372
- return this.proxy.get({ params: { type: CategoryType.Tag } });
372
+ return this.proxy.get({ params: { type: 1 } });
373
373
  }
374
374
  async getCategoryDetail(ids) {
375
375
  if (typeof ids === "string") {
@@ -393,7 +393,6 @@ var CategoryController = class {
393
393
  return await this.proxy(name).get({ params: { tag: 1 } });
394
394
  }
395
395
  };
396
-
397
396
  //#endregion
398
397
  //#region controllers/comment.ts
399
398
  var CommentController = class {
@@ -416,11 +415,13 @@ var CommentController = class {
416
415
  * 获取文章的评论列表
417
416
  * @param refId 文章 Id
418
417
  */
419
- getByRefId(refId, pagination = {}) {
420
- const { page, size } = pagination;
418
+ getByRefId(refId, params = {}) {
419
+ const { page, size, sort, around } = params;
421
420
  return this.proxy.ref(refId).get({ params: {
422
421
  page: page || 1,
423
- size: size || 10
422
+ size: size || 10,
423
+ ...sort ? { sort } : {},
424
+ ...around ? { around } : {}
424
425
  } });
425
426
  }
426
427
  getThreadReplies(rootCommentId, params = {}) {
@@ -445,7 +446,6 @@ var CommentController = class {
445
446
  return this.proxy.reader.reply(commentId).post({ data });
446
447
  }
447
448
  };
448
-
449
449
  //#endregion
450
450
  //#region controllers/base.ts
451
451
  var BaseCrudController = class {
@@ -475,7 +475,6 @@ var BaseCrudController = class {
475
475
  } });
476
476
  }
477
477
  };
478
-
479
478
  //#endregion
480
479
  //#region controllers/link.ts
481
480
  var LinkController = class extends BaseCrudController {
@@ -494,7 +493,6 @@ var LinkController = class extends BaseCrudController {
494
493
  return await this.proxy.audit.post({ data });
495
494
  }
496
495
  };
497
-
498
496
  //#endregion
499
497
  //#region controllers/note.ts
500
498
  var NoteController = class {
@@ -590,7 +588,6 @@ var NoteController = class {
590
588
  } });
591
589
  }
592
590
  };
593
-
594
591
  //#endregion
595
592
  //#region controllers/owner.ts
596
593
  var UserController = class {
@@ -665,7 +662,6 @@ var UserController = class {
665
662
  return this.proxy.check_logged.get({ params: normalized ? { token: normalized } : void 0 });
666
663
  }
667
664
  };
668
-
669
665
  //#endregion
670
666
  //#region controllers/page.ts
671
667
  var PageController = class {
@@ -706,7 +702,6 @@ var PageController = class {
706
702
  return this.proxy.slug(slug).get({ params: options?.prefer ? { prefer: options.prefer } : void 0 });
707
703
  }
708
704
  };
709
-
710
705
  //#endregion
711
706
  //#region controllers/post.ts
712
707
  var PostController = class {
@@ -758,7 +753,6 @@ var PostController = class {
758
753
  return this.proxy("get-url")(slug).get();
759
754
  }
760
755
  };
761
-
762
756
  //#endregion
763
757
  //#region controllers/project.ts
764
758
  var ProjectController = class extends BaseCrudController {
@@ -770,7 +764,6 @@ var ProjectController = class extends BaseCrudController {
770
764
  autoBind(this);
771
765
  }
772
766
  };
773
-
774
767
  //#endregion
775
768
  //#region controllers/recently.ts
776
769
  let RecentlyAttitudeResultEnum = /* @__PURE__ */ function(RecentlyAttitudeResultEnum) {
@@ -817,7 +810,6 @@ var RecentlyController = class {
817
810
  return this.proxy.attitude(id).get({ params: { attitude } });
818
811
  }
819
812
  };
820
-
821
813
  //#endregion
822
814
  //#region controllers/say.ts
823
815
  var SayController = class extends BaseCrudController {
@@ -838,7 +830,6 @@ var SayController = class extends BaseCrudController {
838
830
  return this.proxy.random.get();
839
831
  }
840
832
  };
841
-
842
833
  //#endregion
843
834
  //#region controllers/search.ts
844
835
  var SearchController = class {
@@ -857,21 +848,13 @@ var SearchController = class {
857
848
  ...options
858
849
  } });
859
850
  }
860
- /**
861
- * algolya 搜索
862
- * https://www.algolia.com/doc/api-reference/api-methods/search/
863
- * @param keyword
864
- * @param options
865
- * @returns
866
- */
867
- searchByAlgolia(keyword, options) {
868
- return this.proxy("algolia").get({ params: {
851
+ searchAll(keyword, options) {
852
+ return this.proxy.get({ params: {
869
853
  keyword,
870
854
  ...options
871
855
  } });
872
856
  }
873
857
  };
874
-
875
858
  //#endregion
876
859
  //#region controllers/severless.ts
877
860
  var ServerlessController = class {
@@ -888,7 +871,6 @@ var ServerlessController = class {
888
871
  return this.proxy(reference)(name).get();
889
872
  }
890
873
  };
891
-
892
874
  //#endregion
893
875
  //#region controllers/snippet.ts
894
876
  var SnippetController = class {
@@ -905,7 +887,6 @@ var SnippetController = class {
905
887
  return this.proxy(reference)(name).get();
906
888
  }
907
889
  };
908
-
909
890
  //#endregion
910
891
  //#region controllers/subscribe.ts
911
892
  var SubscribeController = class {
@@ -937,7 +918,6 @@ var SubscribeController = class {
937
918
  } });
938
919
  }
939
920
  };
940
-
941
921
  //#endregion
942
922
  //#region controllers/topic.ts
943
923
  var TopicController = class extends BaseCrudController {
@@ -955,7 +935,6 @@ var TopicController = class extends BaseCrudController {
955
935
  return this.proxy.slug(slug).get();
956
936
  }
957
937
  };
958
-
959
938
  //#endregion
960
939
  //#region controllers/index.ts
961
940
  const allControllers = [
@@ -1002,7 +981,6 @@ const allControllerNames = [
1002
981
  "friend",
1003
982
  "shorthand"
1004
983
  ];
1005
-
1006
984
  //#endregion
1007
985
  //#region core/attach-request.ts
1008
986
  function attachRequestMethod(target) {
@@ -1032,7 +1010,6 @@ function handleSearchParams(obj) {
1032
1010
  });
1033
1011
  return search.toString();
1034
1012
  }
1035
-
1036
1013
  //#endregion
1037
1014
  //#region core/client.ts
1038
1015
  const methodPrefix = "_$";
@@ -1120,14 +1097,15 @@ var HTTPClient = class {
1120
1097
  return path.startsWith("/") ? path : `/${path}`;
1121
1098
  }
1122
1099
  };
1123
- if (methods.includes(name)) return async (options) => {
1100
+ if (methods.includes(name)) return async (options = {}) => {
1124
1101
  const url = resolveFullPath(that.endpoint, route.join("/"));
1125
1102
  route.length = 0;
1103
+ const { transformResponse: perRequestTransformResponse, ...requestOptions } = options;
1126
1104
  let res;
1127
1105
  try {
1128
1106
  res = await manager.request({
1129
1107
  method: name,
1130
- ...options,
1108
+ ...requestOptions,
1131
1109
  url
1132
1110
  });
1133
1111
  } catch (error) {
@@ -1142,7 +1120,8 @@ var HTTPClient = class {
1142
1120
  }
1143
1121
  const data = that.options.getDataFromResponse(res);
1144
1122
  if (!data) return null;
1145
- const cameledObject = (Array.isArray(data) || isPlainObject(data)) && that.options.transformResponse ? that.options.transformResponse(data) : data;
1123
+ const responseTransformer = perRequestTransformResponse === void 0 ? that.options.transformResponse : perRequestTransformResponse || void 0;
1124
+ const cameledObject = (Array.isArray(data) || isPlainObject(data)) && responseTransformer ? responseTransformer(data) : data;
1146
1125
  let nextObject = cameledObject;
1147
1126
  if (cameledObject && typeof cameledObject === "object") {
1148
1127
  nextObject = Array.isArray(cameledObject) ? [...cameledObject] : { ...cameledObject };
@@ -1189,7 +1168,6 @@ function createClient(adapter) {
1189
1168
  return client;
1190
1169
  };
1191
1170
  }
1192
-
1193
1171
  //#endregion
1194
1172
  //#region models/aggregate.ts
1195
1173
  let TimelineType = /* @__PURE__ */ function(TimelineType) {
@@ -1197,7 +1175,6 @@ let TimelineType = /* @__PURE__ */ function(TimelineType) {
1197
1175
  TimelineType[TimelineType["Note"] = 1] = "Note";
1198
1176
  return TimelineType;
1199
1177
  }({});
1200
-
1201
1178
  //#endregion
1202
1179
  //#region ../../apps/core/src/constants/db.constant.ts
1203
1180
  const NOTE_COLLECTION_NAME = "notes";
@@ -1211,7 +1188,6 @@ let CollectionRefTypes = /* @__PURE__ */ function(CollectionRefTypes) {
1211
1188
  CollectionRefTypes[CollectionRefTypes["Recently"] = RECENTLY_COLLECTION_NAME] = "Recently";
1212
1189
  return CollectionRefTypes;
1213
1190
  }({});
1214
-
1215
1191
  //#endregion
1216
1192
  //#region models/comment.ts
1217
1193
  let CommentState = /* @__PURE__ */ function(CommentState) {
@@ -1220,7 +1196,6 @@ let CommentState = /* @__PURE__ */ function(CommentState) {
1220
1196
  CommentState[CommentState["Junk"] = 2] = "Junk";
1221
1197
  return CommentState;
1222
1198
  }({});
1223
-
1224
1199
  //#endregion
1225
1200
  //#region models/link.ts
1226
1201
  let LinkType = /* @__PURE__ */ function(LinkType) {
@@ -1236,7 +1211,6 @@ let LinkState = /* @__PURE__ */ function(LinkState) {
1236
1211
  LinkState[LinkState["Reject"] = 4] = "Reject";
1237
1212
  return LinkState;
1238
1213
  }({});
1239
-
1240
1214
  //#endregion
1241
1215
  //#region models/page.ts
1242
1216
  let EnumPageType = /* @__PURE__ */ function(EnumPageType) {
@@ -1245,7 +1219,6 @@ let EnumPageType = /* @__PURE__ */ function(EnumPageType) {
1245
1219
  EnumPageType["frame"] = "frame";
1246
1220
  return EnumPageType;
1247
1221
  }({});
1248
-
1249
1222
  //#endregion
1250
1223
  //#region models/recently.ts
1251
1224
  let RecentlyRefTypes = /* @__PURE__ */ function(RecentlyRefTypes) {
@@ -1265,7 +1238,6 @@ let RecentlyTypeEnum = /* @__PURE__ */ function(RecentlyTypeEnum) {
1265
1238
  RecentlyTypeEnum["Code"] = "code";
1266
1239
  return RecentlyTypeEnum;
1267
1240
  }({});
1268
-
1269
1241
  //#endregion
1270
1242
  //#region models/snippet.ts
1271
1243
  let SnippetType = /* @__PURE__ */ function(SnippetType) {
@@ -1275,7 +1247,6 @@ let SnippetType = /* @__PURE__ */ function(SnippetType) {
1275
1247
  SnippetType["YAML"] = "yaml";
1276
1248
  return SnippetType;
1277
1249
  }({});
1278
-
1279
1250
  //#endregion
1280
1251
  //#region ../../apps/core/src/modules/subscribe/subscribe.constant.ts
1281
1252
  const SubscribePostCreateBit = 1;
@@ -1284,16 +1255,14 @@ const SubscribeSayCreateBit = 4;
1284
1255
  const SubscribeRecentCreateBit = 8;
1285
1256
  const SubscribeAllBit = 15;
1286
1257
  const SubscribeTypeToBitMap = {
1287
- post_c: SubscribePostCreateBit,
1288
- note_c: SubscribeNoteCreateBit,
1289
- say_c: SubscribeSayCreateBit,
1290
- recently_c: SubscribeRecentCreateBit,
1291
- all: SubscribeAllBit
1258
+ post_c: 1,
1259
+ note_c: 2,
1260
+ say_c: 4,
1261
+ recently_c: 8,
1262
+ all: 15
1292
1263
  };
1293
-
1294
1264
  //#endregion
1295
1265
  //#region index.ts
1296
1266
  var api_client_default = createClient;
1297
-
1298
1267
  //#endregion
1299
- 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 };
1268
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mx-space/api-client",
3
- "version": "3.0.0",
3
+ "version": "3.3.0",
4
4
  "description": "A api client for mx-space server@next",
5
5
  "type": "module",
6
6
  "engines": {
@@ -53,15 +53,15 @@
53
53
  "@types/cors": "2.8.19",
54
54
  "@types/express": "5.0.6",
55
55
  "abort-controller": "3.0.0",
56
- "axios": "^1.13.3",
56
+ "axios": "^1.15.0",
57
57
  "camelcase-keys": "^10.0.2",
58
58
  "cors": "2.8.6",
59
- "es-toolkit": "1.45.0",
60
- "express": "4.21.2",
59
+ "es-toolkit": "1.45.1",
60
+ "express": "5.2.1",
61
61
  "form-data": "4.0.5",
62
- "tsdown": "0.21.0-beta.2",
62
+ "tsdown": "0.21.9",
63
63
  "umi-request": "1.4.0",
64
- "vite": "^7.3.1",
65
- "vitest": "4.0.18"
64
+ "vite": "^8.0.8",
65
+ "vitest": "4.1.4"
66
66
  }
67
67
  }