@mx-space/api-client 1.0.0 → 1.0.1

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.
Files changed (432) hide show
  1. package/LICENSE +661 -0
  2. package/esm/adaptors/axios.d.ts +4 -0
  3. package/esm/adaptors/axios.js +37 -0
  4. package/esm/adaptors/axios.js.map +1 -0
  5. package/esm/adaptors/ky.d.ts +23 -0
  6. package/esm/adaptors/ky.js +62 -0
  7. package/esm/adaptors/ky.js.map +1 -0
  8. package/esm/adaptors/umi-request.d.ts +4 -0
  9. package/esm/adaptors/umi-request.js +31 -0
  10. package/esm/adaptors/umi-request.js.map +1 -0
  11. package/esm/controllers/aggregate.d.ts +64 -0
  12. package/esm/controllers/aggregate.js +42 -0
  13. package/esm/controllers/aggregate.js.map +1 -0
  14. package/esm/controllers/base.d.ts +43 -0
  15. package/esm/controllers/base.js +27 -0
  16. package/esm/controllers/base.js.map +1 -0
  17. package/esm/controllers/category.d.ts +114 -0
  18. package/esm/controllers/category.js +68 -0
  19. package/esm/controllers/category.js.map +1 -0
  20. package/esm/controllers/comment.d.ts +81 -0
  21. package/esm/controllers/comment.js +47 -0
  22. package/esm/controllers/comment.js.map +1 -0
  23. package/esm/controllers/index.d.ts +18 -0
  24. package/esm/controllers/index.js +55 -0
  25. package/esm/controllers/index.js.map +1 -0
  26. package/esm/controllers/link.d.ts +20 -0
  27. package/esm/controllers/link.js +21 -0
  28. package/esm/controllers/link.js.map +1 -0
  29. package/esm/controllers/note.d.ts +123 -0
  30. package/esm/controllers/note.js +68 -0
  31. package/esm/controllers/note.js.map +1 -0
  32. package/esm/controllers/page.d.ts +59 -0
  33. package/esm/controllers/page.js +42 -0
  34. package/esm/controllers/page.js.map +1 -0
  35. package/esm/controllers/post.d.ts +72 -0
  36. package/esm/controllers/post.js +52 -0
  37. package/esm/controllers/post.js.map +1 -0
  38. package/esm/controllers/project.d.ts +15 -0
  39. package/esm/controllers/project.js +12 -0
  40. package/esm/controllers/project.js.map +1 -0
  41. package/esm/controllers/recently.d.ts +61 -0
  42. package/esm/controllers/recently.js +31 -0
  43. package/esm/controllers/recently.js.map +1 -0
  44. package/esm/controllers/say.d.ts +37 -0
  45. package/esm/controllers/say.js +21 -0
  46. package/esm/controllers/say.js.map +1 -0
  47. package/esm/controllers/search.d.ts +247 -0
  48. package/esm/controllers/search.js +28 -0
  49. package/esm/controllers/search.js.map +1 -0
  50. package/esm/controllers/severless.d.ts +24 -0
  51. package/esm/controllers/severless.js +16 -0
  52. package/esm/controllers/severless.js.map +1 -0
  53. package/esm/controllers/snippet.d.ts +24 -0
  54. package/esm/controllers/snippet.js +19 -0
  55. package/esm/controllers/snippet.js.map +1 -0
  56. package/esm/controllers/topic.d.ts +26 -0
  57. package/esm/controllers/topic.js +18 -0
  58. package/esm/controllers/topic.js.map +1 -0
  59. package/esm/controllers/user.d.ts +70 -0
  60. package/esm/controllers/user.js +40 -0
  61. package/esm/controllers/user.js.map +1 -0
  62. package/esm/core/attach-request.d.ts +2 -0
  63. package/esm/core/attach-request.js +36 -0
  64. package/esm/core/attach-request.js.map +1 -0
  65. package/esm/core/client.d.ts +29 -0
  66. package/esm/core/client.js +186 -0
  67. package/esm/core/client.js.map +1 -0
  68. package/esm/core/error.d.ts +6 -0
  69. package/esm/core/error.js +9 -0
  70. package/esm/core/error.js.map +1 -0
  71. package/esm/core/index.d.ts +2 -0
  72. package/esm/core/index.js +3 -0
  73. package/esm/core/index.js.map +1 -0
  74. package/esm/dtos/comment.d.ts +6 -0
  75. package/esm/dtos/comment.js +3 -0
  76. package/esm/dtos/comment.js.map +1 -0
  77. package/esm/index.d.ts +7 -0
  78. package/esm/index.js +8 -0
  79. package/esm/index.js.map +1 -0
  80. package/esm/interfaces/adapter.d.ts +14 -0
  81. package/esm/interfaces/adapter.js +2 -0
  82. package/esm/interfaces/adapter.js.map +1 -0
  83. package/esm/interfaces/client.d.ts +13 -0
  84. package/esm/interfaces/client.js +2 -0
  85. package/esm/interfaces/client.js.map +1 -0
  86. package/esm/interfaces/controller.d.ts +4 -0
  87. package/esm/interfaces/controller.js +2 -0
  88. package/esm/interfaces/controller.js.map +1 -0
  89. package/esm/interfaces/instance.d.ts +7 -0
  90. package/esm/interfaces/instance.js +2 -0
  91. package/esm/interfaces/instance.js.map +1 -0
  92. package/esm/interfaces/options.d.ts +1 -0
  93. package/esm/interfaces/options.js +2 -0
  94. package/esm/interfaces/options.js.map +1 -0
  95. package/esm/interfaces/params.d.ts +4 -0
  96. package/esm/interfaces/params.js +2 -0
  97. package/esm/interfaces/params.js.map +1 -0
  98. package/esm/interfaces/request.d.ts +43 -0
  99. package/esm/interfaces/request.js +2 -0
  100. package/esm/interfaces/request.js.map +1 -0
  101. package/esm/interfaces/types.d.ts +2 -0
  102. package/esm/interfaces/types.js +2 -0
  103. package/esm/interfaces/types.js.map +1 -0
  104. package/esm/models/aggregate.d.ts +53 -0
  105. package/esm/models/aggregate.js +6 -0
  106. package/esm/models/aggregate.js.map +1 -0
  107. package/esm/models/base.d.ts +41 -0
  108. package/esm/models/base.js +2 -0
  109. package/esm/models/base.js.map +1 -0
  110. package/esm/models/category.d.ts +22 -0
  111. package/esm/models/category.js +6 -0
  112. package/esm/models/category.js.map +1 -0
  113. package/esm/models/comment.d.ts +37 -0
  114. package/esm/models/comment.js +13 -0
  115. package/esm/models/comment.js.map +1 -0
  116. package/esm/models/index.d.ts +14 -0
  117. package/esm/models/index.js +15 -0
  118. package/esm/models/index.js.map +1 -0
  119. package/esm/models/link.d.ts +22 -0
  120. package/esm/models/link.js +14 -0
  121. package/esm/models/link.js.map +1 -0
  122. package/esm/models/note.d.ts +38 -0
  123. package/esm/models/note.js +2 -0
  124. package/esm/models/note.js.map +1 -0
  125. package/esm/models/page.d.ts +14 -0
  126. package/esm/models/page.js +7 -0
  127. package/esm/models/page.js.map +1 -0
  128. package/esm/models/post.d.ts +17 -0
  129. package/esm/models/post.js +2 -0
  130. package/esm/models/post.js.map +1 -0
  131. package/esm/models/project.d.ts +11 -0
  132. package/esm/models/project.js +2 -0
  133. package/esm/models/project.js.map +1 -0
  134. package/esm/models/recently.d.ts +20 -0
  135. package/esm/models/recently.js +7 -0
  136. package/esm/models/recently.js.map +1 -0
  137. package/esm/models/say.d.ts +6 -0
  138. package/esm/models/say.js +2 -0
  139. package/esm/models/say.js.map +1 -0
  140. package/esm/models/setting.d.ts +66 -0
  141. package/esm/models/setting.js +2 -0
  142. package/esm/models/setting.js.map +1 -0
  143. package/esm/models/snippet.d.ts +18 -0
  144. package/esm/models/snippet.js +8 -0
  145. package/esm/models/snippet.js.map +1 -0
  146. package/esm/models/topic.d.ts +8 -0
  147. package/esm/models/topic.js +2 -0
  148. package/esm/models/topic.js.map +1 -0
  149. package/esm/models/user.d.ts +21 -0
  150. package/esm/models/user.js +2 -0
  151. package/esm/models/user.js.map +1 -0
  152. package/esm/utils/auto-bind.d.ts +4 -0
  153. package/esm/utils/auto-bind.js +36 -0
  154. package/esm/utils/auto-bind.js.map +1 -0
  155. package/esm/utils/camelcase-keys.d.ts +6 -0
  156. package/esm/utils/camelcase-keys.js +23 -0
  157. package/esm/utils/camelcase-keys.js.map +1 -0
  158. package/esm/utils/index.d.ts +5 -0
  159. package/esm/utils/index.js +43 -0
  160. package/esm/utils/index.js.map +1 -0
  161. package/esm/utils/path.d.ts +1 -0
  162. package/esm/utils/path.js +7 -0
  163. package/esm/utils/path.js.map +1 -0
  164. package/esm/vitest.config.d.ts +2 -0
  165. package/esm/vitest.config.js +12 -0
  166. package/esm/vitest.config.js.map +1 -0
  167. package/lib/adaptors/axios.d.ts +4 -0
  168. package/lib/adaptors/axios.js +43 -0
  169. package/lib/adaptors/axios.js.map +1 -0
  170. package/lib/adaptors/ky.d.ts +23 -0
  171. package/lib/adaptors/ky.js +69 -0
  172. package/lib/adaptors/ky.js.map +1 -0
  173. package/lib/adaptors/umi-request.d.ts +4 -0
  174. package/lib/adaptors/umi-request.js +34 -0
  175. package/lib/adaptors/umi-request.js.map +1 -0
  176. package/lib/controllers/aggregate.d.ts +64 -0
  177. package/lib/controllers/aggregate.js +46 -0
  178. package/lib/controllers/aggregate.js.map +1 -0
  179. package/lib/controllers/base.d.ts +43 -0
  180. package/lib/controllers/base.js +31 -0
  181. package/lib/controllers/base.js.map +1 -0
  182. package/lib/controllers/category.d.ts +114 -0
  183. package/lib/controllers/category.js +72 -0
  184. package/lib/controllers/category.js.map +1 -0
  185. package/lib/controllers/comment.d.ts +81 -0
  186. package/lib/controllers/comment.js +51 -0
  187. package/lib/controllers/comment.js.map +1 -0
  188. package/lib/controllers/index.d.ts +18 -0
  189. package/lib/controllers/index.js +72 -0
  190. package/lib/controllers/index.js.map +1 -0
  191. package/lib/controllers/link.d.ts +20 -0
  192. package/lib/controllers/link.js +25 -0
  193. package/lib/controllers/link.js.map +1 -0
  194. package/lib/controllers/note.d.ts +123 -0
  195. package/lib/controllers/note.js +72 -0
  196. package/lib/controllers/note.js.map +1 -0
  197. package/lib/controllers/page.d.ts +59 -0
  198. package/lib/controllers/page.js +46 -0
  199. package/lib/controllers/page.js.map +1 -0
  200. package/lib/controllers/post.d.ts +72 -0
  201. package/lib/controllers/post.js +56 -0
  202. package/lib/controllers/post.js.map +1 -0
  203. package/lib/controllers/project.d.ts +15 -0
  204. package/lib/controllers/project.js +16 -0
  205. package/lib/controllers/project.js.map +1 -0
  206. package/lib/controllers/recently.d.ts +61 -0
  207. package/lib/controllers/recently.js +35 -0
  208. package/lib/controllers/recently.js.map +1 -0
  209. package/lib/controllers/say.d.ts +37 -0
  210. package/lib/controllers/say.js +25 -0
  211. package/lib/controllers/say.js.map +1 -0
  212. package/lib/controllers/search.d.ts +247 -0
  213. package/lib/controllers/search.js +32 -0
  214. package/lib/controllers/search.js.map +1 -0
  215. package/lib/controllers/severless.d.ts +24 -0
  216. package/lib/controllers/severless.js +20 -0
  217. package/lib/controllers/severless.js.map +1 -0
  218. package/lib/controllers/snippet.d.ts +24 -0
  219. package/lib/controllers/snippet.js +23 -0
  220. package/lib/controllers/snippet.js.map +1 -0
  221. package/lib/controllers/topic.d.ts +26 -0
  222. package/lib/controllers/topic.js +22 -0
  223. package/lib/controllers/topic.js.map +1 -0
  224. package/lib/controllers/user.d.ts +70 -0
  225. package/lib/controllers/user.js +44 -0
  226. package/lib/controllers/user.js.map +1 -0
  227. package/lib/core/attach-request.d.ts +2 -0
  228. package/lib/core/attach-request.js +40 -0
  229. package/lib/core/attach-request.js.map +1 -0
  230. package/lib/core/client.d.ts +29 -0
  231. package/lib/core/client.js +190 -0
  232. package/lib/core/client.js.map +1 -0
  233. package/lib/core/error.d.ts +6 -0
  234. package/lib/core/error.js +13 -0
  235. package/lib/core/error.js.map +1 -0
  236. package/lib/core/index.d.ts +2 -0
  237. package/lib/core/index.js +19 -0
  238. package/lib/core/index.js.map +1 -0
  239. package/lib/dtos/comment.d.ts +6 -0
  240. package/lib/dtos/comment.js +7 -0
  241. package/lib/dtos/comment.js.map +1 -0
  242. package/lib/index.d.ts +7 -0
  243. package/lib/index.js +28 -0
  244. package/lib/index.js.map +1 -0
  245. package/lib/interfaces/adapter.d.ts +14 -0
  246. package/lib/interfaces/adapter.js +3 -0
  247. package/lib/interfaces/adapter.js.map +1 -0
  248. package/lib/interfaces/client.d.ts +13 -0
  249. package/lib/interfaces/client.js +3 -0
  250. package/lib/interfaces/client.js.map +1 -0
  251. package/lib/interfaces/controller.d.ts +4 -0
  252. package/lib/interfaces/controller.js +3 -0
  253. package/lib/interfaces/controller.js.map +1 -0
  254. package/lib/interfaces/instance.d.ts +7 -0
  255. package/lib/interfaces/instance.js +3 -0
  256. package/lib/interfaces/instance.js.map +1 -0
  257. package/lib/interfaces/options.d.ts +1 -0
  258. package/lib/interfaces/options.js +3 -0
  259. package/lib/interfaces/options.js.map +1 -0
  260. package/lib/interfaces/params.d.ts +4 -0
  261. package/lib/interfaces/params.js +3 -0
  262. package/lib/interfaces/params.js.map +1 -0
  263. package/lib/interfaces/request.d.ts +43 -0
  264. package/lib/interfaces/request.js +3 -0
  265. package/lib/interfaces/request.js.map +1 -0
  266. package/lib/interfaces/types.d.ts +2 -0
  267. package/lib/interfaces/types.js +3 -0
  268. package/lib/interfaces/types.js.map +1 -0
  269. package/lib/models/aggregate.d.ts +53 -0
  270. package/lib/models/aggregate.js +9 -0
  271. package/lib/models/aggregate.js.map +1 -0
  272. package/lib/models/base.d.ts +41 -0
  273. package/lib/models/base.js +3 -0
  274. package/lib/models/base.js.map +1 -0
  275. package/lib/models/category.d.ts +22 -0
  276. package/lib/models/category.js +9 -0
  277. package/lib/models/category.js.map +1 -0
  278. package/lib/models/comment.d.ts +37 -0
  279. package/lib/models/comment.js +16 -0
  280. package/lib/models/comment.js.map +1 -0
  281. package/lib/models/index.d.ts +14 -0
  282. package/lib/models/index.js +31 -0
  283. package/lib/models/index.js.map +1 -0
  284. package/lib/models/link.d.ts +22 -0
  285. package/lib/models/link.js +17 -0
  286. package/lib/models/link.js.map +1 -0
  287. package/lib/models/note.d.ts +38 -0
  288. package/lib/models/note.js +3 -0
  289. package/lib/models/note.js.map +1 -0
  290. package/lib/models/page.d.ts +14 -0
  291. package/lib/models/page.js +10 -0
  292. package/lib/models/page.js.map +1 -0
  293. package/lib/models/post.d.ts +17 -0
  294. package/lib/models/post.js +3 -0
  295. package/lib/models/post.js.map +1 -0
  296. package/lib/models/project.d.ts +11 -0
  297. package/lib/models/project.js +3 -0
  298. package/lib/models/project.js.map +1 -0
  299. package/lib/models/recently.d.ts +20 -0
  300. package/lib/models/recently.js +10 -0
  301. package/lib/models/recently.js.map +1 -0
  302. package/lib/models/say.d.ts +6 -0
  303. package/lib/models/say.js +3 -0
  304. package/lib/models/say.js.map +1 -0
  305. package/lib/models/setting.d.ts +66 -0
  306. package/lib/models/setting.js +3 -0
  307. package/lib/models/setting.js.map +1 -0
  308. package/lib/models/snippet.d.ts +18 -0
  309. package/lib/models/snippet.js +11 -0
  310. package/lib/models/snippet.js.map +1 -0
  311. package/lib/models/topic.d.ts +8 -0
  312. package/lib/models/topic.js +3 -0
  313. package/lib/models/topic.js.map +1 -0
  314. package/lib/models/user.d.ts +21 -0
  315. package/lib/models/user.js +3 -0
  316. package/lib/models/user.js.map +1 -0
  317. package/lib/utils/auto-bind.d.ts +4 -0
  318. package/lib/utils/auto-bind.js +40 -0
  319. package/lib/utils/auto-bind.js.map +1 -0
  320. package/lib/utils/camelcase-keys.d.ts +6 -0
  321. package/lib/utils/camelcase-keys.js +28 -0
  322. package/lib/utils/camelcase-keys.js.map +1 -0
  323. package/lib/utils/index.d.ts +5 -0
  324. package/lib/utils/index.js +50 -0
  325. package/lib/utils/index.js.map +1 -0
  326. package/lib/utils/path.d.ts +1 -0
  327. package/lib/utils/path.js +11 -0
  328. package/lib/utils/path.js.map +1 -0
  329. package/lib/vitest.config.d.ts +2 -0
  330. package/lib/vitest.config.js +17 -0
  331. package/lib/vitest.config.js.map +1 -0
  332. package/package.json +25 -12
  333. package/types/adaptors/axios.d.ts +4 -0
  334. package/types/adaptors/ky.d.ts +23 -0
  335. package/types/adaptors/umi-request.d.ts +4 -0
  336. package/types/controllers/aggregate.d.ts +64 -0
  337. package/types/controllers/base.d.ts +43 -0
  338. package/types/controllers/category.d.ts +114 -0
  339. package/types/controllers/comment.d.ts +81 -0
  340. package/types/controllers/index.d.ts +18 -0
  341. package/types/controllers/link.d.ts +20 -0
  342. package/types/controllers/note.d.ts +123 -0
  343. package/types/controllers/page.d.ts +59 -0
  344. package/types/controllers/post.d.ts +72 -0
  345. package/types/controllers/project.d.ts +15 -0
  346. package/types/controllers/recently.d.ts +61 -0
  347. package/types/controllers/say.d.ts +37 -0
  348. package/types/controllers/search.d.ts +247 -0
  349. package/types/controllers/severless.d.ts +24 -0
  350. package/types/controllers/snippet.d.ts +24 -0
  351. package/types/controllers/topic.d.ts +26 -0
  352. package/types/controllers/user.d.ts +70 -0
  353. package/types/core/attach-request.d.ts +2 -0
  354. package/types/core/client.d.ts +29 -0
  355. package/types/core/error.d.ts +6 -0
  356. package/types/core/index.d.ts +2 -0
  357. package/types/dtos/comment.d.ts +6 -0
  358. package/types/index.d.ts +7 -0
  359. package/types/interfaces/adapter.d.ts +14 -0
  360. package/types/interfaces/client.d.ts +13 -0
  361. package/types/interfaces/controller.d.ts +4 -0
  362. package/types/interfaces/instance.d.ts +7 -0
  363. package/types/interfaces/options.d.ts +1 -0
  364. package/types/interfaces/params.d.ts +4 -0
  365. package/types/interfaces/request.d.ts +43 -0
  366. package/types/interfaces/types.d.ts +2 -0
  367. package/types/models/aggregate.d.ts +53 -0
  368. package/types/models/base.d.ts +41 -0
  369. package/types/models/category.d.ts +22 -0
  370. package/types/models/comment.d.ts +37 -0
  371. package/types/models/index.d.ts +14 -0
  372. package/types/models/link.d.ts +22 -0
  373. package/types/models/note.d.ts +38 -0
  374. package/types/models/page.d.ts +14 -0
  375. package/types/models/post.d.ts +17 -0
  376. package/types/models/project.d.ts +11 -0
  377. package/types/models/recently.d.ts +20 -0
  378. package/types/models/say.d.ts +6 -0
  379. package/types/models/setting.d.ts +66 -0
  380. package/types/models/snippet.d.ts +18 -0
  381. package/types/models/topic.d.ts +8 -0
  382. package/types/models/user.d.ts +21 -0
  383. package/types/utils/auto-bind.d.ts +4 -0
  384. package/types/utils/camelcase-keys.d.ts +6 -0
  385. package/types/utils/index.d.ts +5 -0
  386. package/types/utils/path.d.ts +1 -0
  387. package/types/vitest.config.d.ts +2 -0
  388. package/__tests__/adaptors/axios.spec.ts +0 -7
  389. package/__tests__/adaptors/ky.spec.ts +0 -9
  390. package/__tests__/adaptors/umi-request.spec.ts +0 -7
  391. package/__tests__/contronllers/aggregate.test.ts +0 -389
  392. package/__tests__/contronllers/category.test.ts +0 -284
  393. package/__tests__/contronllers/comment.test.ts +0 -113
  394. package/__tests__/contronllers/link.test.ts +0 -95
  395. package/__tests__/contronllers/note.test.ts +0 -120
  396. package/__tests__/contronllers/page.test.ts +0 -49
  397. package/__tests__/contronllers/post.test.ts +0 -77
  398. package/__tests__/contronllers/recently.test.ts +0 -49
  399. package/__tests__/contronllers/say.test.ts +0 -106
  400. package/__tests__/contronllers/search.test.ts +0 -81
  401. package/__tests__/contronllers/serverless.test.ts +0 -19
  402. package/__tests__/contronllers/snippet.test.ts +0 -38
  403. package/__tests__/contronllers/topic.test.ts +0 -17
  404. package/__tests__/contronllers/user.test.ts +0 -59
  405. package/__tests__/core/client.test.ts +0 -293
  406. package/__tests__/helpers/adaptor-test.ts +0 -108
  407. package/__tests__/helpers/e2e-mock-server.ts +0 -22
  408. package/__tests__/helpers/global-fetch.ts +0 -39
  409. package/__tests__/helpers/instance.ts +0 -11
  410. package/__tests__/helpers/response.ts +0 -76
  411. package/__tests__/mock/algolia.json +0 -446
  412. package/__tests__/utils/auto-bind.spec.ts +0 -27
  413. package/__tests__/utils/camelcase-keys.spec.ts +0 -86
  414. package/__tests__/utils/index.test.ts +0 -33
  415. package/__tests__/utils/path.spec.ts +0 -8
  416. package/adaptors/axios.ts +0 -44
  417. package/adaptors/ky.ts +0 -76
  418. package/adaptors/umi-request.ts +0 -38
  419. package/core/attach-request.ts +0 -43
  420. package/core/client.ts +0 -252
  421. package/core/error.ts +0 -10
  422. package/core/index.ts +0 -2
  423. package/coverage/lcov-report/__tests__/helpers/adaptor-test.ts.html +0 -405
  424. package/coverage/lcov-report/__tests__/helpers/e2e-mock-server.ts.html +0 -150
  425. package/coverage/lcov-report/__tests__/helpers/index.html +0 -236
  426. package/coverage/lcov-report/__tests__/helpers/instance.ts.html +0 -120
  427. package/coverage/lcov-report/__tests__/helpers/response.ts.html +0 -231
  428. package/rollup.config.js +0 -150
  429. package/utils/auto-bind.ts +0 -48
  430. package/utils/camelcase-keys.ts +0 -26
  431. package/utils/index.ts +0 -53
  432. package/utils/path.ts +0 -6
@@ -1,19 +0,0 @@
1
- import { mockRequestInstance } from '~/__tests__/helpers/instance'
2
- import { mockResponse } from '~/__tests__/helpers/response'
3
- import { ServerlessController } from '~/controllers'
4
-
5
- describe('test Snippet client', () => {
6
- const client = mockRequestInstance(ServerlessController)
7
-
8
- test('GET /:reference/:name', async () => {
9
- const mocked = mockResponse('/serverless/api/ping', { message: 'pong' })
10
-
11
- const data = await client.serverless.getByReferenceAndName<{}>(
12
- 'api',
13
- 'ping',
14
- )
15
-
16
- expect(data).toEqual(mocked)
17
- expect(data.$raw.data).toEqual(mocked)
18
- })
19
- })
@@ -1,38 +0,0 @@
1
- import { mockRequestInstance } from '~/__tests__/helpers/instance'
2
- import { mockResponse } from '~/__tests__/helpers/response'
3
- import { SnippetController } from '~/controllers'
4
-
5
- describe('test Snippet client', () => {
6
- const client = mockRequestInstance(SnippetController)
7
-
8
- // test('GET /:id', async () => {
9
- // const mocked = mockResponse('/snippets/61a0cac4b4aefa000fcc1822', {
10
- // id: '61a0cac4b4aefa000fcc1822',
11
- // type: 'json',
12
- // private: true,
13
- // reference: 'theme',
14
- // raw: '{}',
15
- // name: 'config',
16
- // created: '2021-11-26T11:53:40.863Z',
17
- // updated: '2021-11-26T11:53:40.863Z',
18
- // })
19
-
20
- // const data = await client.snippet.getById('61a0cac4b4aefa000fcc1822')
21
-
22
- // expect(data).toEqual(mocked)
23
- // expect(data.$raw.data).toEqual(mocked)
24
- // expect(data.raw).toEqual('{}')
25
- // })
26
-
27
- test('GET /:reference/:name', async () => {
28
- const mocked = mockResponse('/snippets/theme/config', {})
29
-
30
- const data = await client.snippet.getByReferenceAndName<{}>(
31
- 'theme',
32
- 'config',
33
- )
34
-
35
- expect(data).toEqual(mocked)
36
- expect(data.$raw.data).toEqual(mocked)
37
- })
38
- })
@@ -1,17 +0,0 @@
1
- import camelcaseKeys from 'camelcase-keys'
2
-
3
- import { mockRequestInstance } from '~/__tests__/helpers/instance'
4
- import { mockResponse } from '~/__tests__/helpers/response'
5
- import { TopicController } from '~/controllers/topic'
6
-
7
- describe('test topic client', () => {
8
- const client = mockRequestInstance(TopicController)
9
-
10
- test('GET /topics/slug/:slug', async () => {
11
- const mocked = mockResponse('/topics/slug/111', {
12
- name: 'name-topic',
13
- })
14
- const data = await client.topic.getTopicBySlug('111')
15
- expect(data).toEqual(camelcaseKeys(mocked))
16
- })
17
- })
@@ -1,59 +0,0 @@
1
- import camelcaseKeys from 'camelcase-keys'
2
-
3
- import { mockRequestInstance } from '~/__tests__/helpers/instance'
4
- import { mockResponse } from '~/__tests__/helpers/response'
5
- import { UserController } from '~/controllers'
6
-
7
- describe('test user client', () => {
8
- const client = mockRequestInstance(UserController)
9
-
10
- test('GET /master', async () => {
11
- const mocked = mockResponse('/master', {
12
- id: '5ea4fe632507ba128f4c938c',
13
- introduce: '这是我的小世界呀',
14
- mail: 'i@innei.ren',
15
- url: 'https://innei.ren',
16
- name: 'Innei',
17
- social_ids: {
18
- bili_id: 26578164,
19
- netease_id: 84302804,
20
- github: 'Innei',
21
- },
22
- username: 'Innei',
23
- created: '2020-04-26T03:22:11.784Z',
24
- modified: '2020-11-13T09:38:49.014Z',
25
- last_login_time: '2021-11-17T13:42:48.209Z',
26
- avatar: 'https://cdn.innei.ren/avatar.png',
27
- })
28
- const data = await client.user.getMasterInfo()
29
- expect(data.id).toEqual(mocked.id)
30
- expect(data).toEqual(camelcaseKeys(mocked, { deep: true }))
31
- expect(data.$raw.data).toEqual(mocked)
32
- })
33
-
34
- test('POST /login', async () => {
35
- const mocked = mockResponse(
36
- '/master/login',
37
- {
38
- id: '5ea4fe632507ba128f4c938c',
39
- },
40
- 'post',
41
- )
42
- const data = await client.user.login('test', 'test')
43
- expect(data.id).toEqual(mocked.id)
44
- expect(data.$raw.data).toEqual(mocked)
45
- })
46
-
47
- test('GET /check_logged', async () => {
48
- const mocked = mockResponse('/check_logged?token=bearer token', {
49
- isGuest: true,
50
- })
51
- const data = await client.user.checkTokenValid('token')
52
- expect(data).toEqual(mocked)
53
- })
54
-
55
- it('should call `master.xx` work', () => {
56
- expect(client.master.getMasterInfo).toBeInstanceOf(Function)
57
- expect(client.master).toEqual(client.user)
58
- })
59
- })
@@ -1,293 +0,0 @@
1
- import { AxiosError, AxiosResponse } from 'axios'
2
- import { vi } from 'vitest'
3
-
4
- import { axiosAdaptor } from '~/adaptors/axios'
5
- import { umiAdaptor } from '~/adaptors/umi-request'
6
- import {
7
- NoteController,
8
- PostController,
9
- allContollerNames,
10
- allControllers,
11
- } from '~/controllers'
12
- import { RequestError, createClient } from '~/core'
13
- import { IRequestAdapter } from '~/interfaces/adapter'
14
- import { ClientOptions } from '~/interfaces/client'
15
-
16
- const { spyOn } = vi
17
-
18
- // axios wrapper test
19
- const generateClient = <
20
- Response = AxiosResponse<unknown>,
21
- AdaptorType extends IRequestAdapter = typeof axiosAdaptor,
22
- >(
23
- adapter?: AdaptorType,
24
- options?: ClientOptions,
25
- ) =>
26
- createClient(adapter ?? axiosAdaptor)<Response>(
27
- 'http://127.0.0.1:2323',
28
- options,
29
- )
30
- describe('test client', () => {
31
- it('should create new client with axios', () => {
32
- const client = generateClient()
33
- expect(client).toBeDefined()
34
- })
35
-
36
- describe('client `get` method', () => {
37
- test('case 1', async () => {
38
- spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
39
- if (url === 'http://127.0.0.1:2323/a/a?foo=bar') {
40
- return Promise.resolve({ data: { ok: 1 } })
41
- }
42
-
43
- return Promise.resolve({ data: null })
44
- })
45
-
46
- const client = generateClient()
47
- const data = await client.proxy.a.a.get({ params: { foo: 'bar' } })
48
-
49
- expect(data).toStrictEqual({ ok: 1 })
50
- })
51
-
52
- test('case 2', async () => {
53
- spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
54
- if (url === 'http://127.0.0.1:2323/a/a') {
55
- return Promise.resolve({ data: { ok: 1 } })
56
- }
57
-
58
- return Promise.resolve({ data: null })
59
- })
60
-
61
- const client = generateClient()
62
- const data = await client.proxy.a.a.get()
63
-
64
- expect(data).toStrictEqual({ ok: 1 })
65
-
66
- {
67
- spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
68
- if (url === 'http://127.0.0.1:2323/a/b') {
69
- return Promise.resolve({ data: { ok: 1 } })
70
- }
71
-
72
- return Promise.resolve({ data: null })
73
- })
74
-
75
- const client = generateClient()
76
- const data = await client.proxy.a.b.get()
77
-
78
- expect(data).toStrictEqual({ ok: 1 })
79
- }
80
- })
81
- })
82
-
83
- it('should throw error if not inject other client', () => {
84
- const client = generateClient()
85
- allContollerNames.forEach((name) => {
86
- expect(() => (client as any)[name].name).toThrow(
87
- `${
88
- name.charAt(0).toUpperCase() + name.slice(1)
89
- } Client not inject yet, please inject with client.injectClients(...)`,
90
- )
91
- })
92
- })
93
-
94
- it('should work if inject client', () => {
95
- const client = generateClient()
96
-
97
- client.injectControllers(allControllers)
98
- allContollerNames.forEach((name) => {
99
- expect(() => (client as any)[name].name).toBeDefined()
100
- })
101
- })
102
-
103
- it('should inject single client worked', () => {
104
- const client = generateClient()
105
-
106
- client.injectControllers(PostController)
107
- expect(client.post.name).toBeDefined()
108
- })
109
-
110
- it('should inject multi client worked', () => {
111
- const client = generateClient()
112
-
113
- client.injectControllers(PostController, NoteController)
114
- expect(client.post.name).toBeDefined()
115
- expect(client.note.name).toBeDefined()
116
- })
117
-
118
- it('should inject controller when init', () => {
119
- const client = createClient(axiosAdaptor)('http://127.0.0.1:2323', {
120
- controllers: [PostController, NoteController],
121
- })
122
- expect(client.post.name).toBeDefined()
123
- expect(client.note.name).toBeDefined()
124
- })
125
-
126
- it('should infer response wrapper type', async () => {
127
- const client = generateClient<AxiosResponse>(axiosAdaptor)
128
- client.injectControllers(PostController)
129
- spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
130
- if (url === 'http://127.0.0.1:2323/posts/latest') {
131
- return Promise.resolve({ data: { ok: 1 }, status: 200 })
132
- }
133
-
134
- return Promise.resolve({ data: null })
135
- })
136
-
137
- const data = await client.post.getLatest()
138
-
139
- expect(data.$raw.status).toBe(200)
140
- })
141
-
142
- it('should infer axios instance type', async () => {
143
- const client = generateClient<AxiosResponse>(axiosAdaptor)
144
- spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
145
- if (url === 'http://127.0.0.1:2323/a') {
146
- return Promise.resolve({ data: { ok: 1 }, status: 200 })
147
- }
148
-
149
- return Promise.resolve({ data: null })
150
- })
151
- expect(client.instance.default).toBe(axiosAdaptor.default)
152
- const res = await client.proxy.a.get()
153
- expect(res.$raw.status).toBe(200)
154
-
155
- {
156
- spyOn(umiAdaptor, 'get').mockImplementation((url) => {
157
- if (url === 'http://127.0.0.1:2323/a') {
158
- return Promise.resolve({
159
- data: { ok: 1 },
160
- response: { status: 200, body: {} },
161
- })
162
- }
163
-
164
- return Promise.resolve({ data: null })
165
- })
166
- const client2 = createClient(umiAdaptor)('http://127.0.0.1:2323')
167
- expect(client2.instance.default).toBe(umiAdaptor.default)
168
- const res = await client2.proxy.a.get()
169
- expect(res.$raw.response.status).toBe(200)
170
- expect(res.$raw.response.body).toStrictEqual({})
171
- }
172
- })
173
-
174
- it('should resolve joint path call toString()', () => {
175
- const client = generateClient()
176
- {
177
- const path = client.proxy.foo.bar.toString()
178
- expect(path).toBe('/foo/bar')
179
- }
180
-
181
- {
182
- const path = client.proxy.foo.bar.toString(true)
183
- expect(path).toBe('http://127.0.0.1:2323/foo/bar')
184
- }
185
- })
186
-
187
- it('should do not json convert case if payload is string or other primitive type', async () => {
188
- const client = generateClient<AxiosResponse>(axiosAdaptor)
189
- spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
190
- if (url === 'http://127.0.0.1:2323/a') {
191
- return Promise.resolve({ data: 'foo', status: 200 })
192
- }
193
-
194
- return Promise.resolve({ data: null })
195
- })
196
-
197
- const data = await client.proxy.a.get()
198
- expect(data).toBe('foo')
199
- })
200
-
201
- it('should throw exception with custom message and code', async () => {
202
- const client = generateClient<AxiosResponse>(axiosAdaptor, {
203
- // @ts-ignore
204
- getCodeMessageFromException: (e: AxiosError) => {
205
- return {
206
- code: e.response?.status,
207
- message: e.message,
208
- }
209
- },
210
- })
211
- spyOn(axiosAdaptor, 'get').mockImplementation(() => {
212
- return Promise.reject(
213
- new AxiosError(
214
- 'not found',
215
- 'NOT_FOUND',
216
- {},
217
- {},
218
- {
219
- status: 404,
220
- config: {},
221
- data: {},
222
- headers: {},
223
- statusText: 'not found',
224
- },
225
- ),
226
- )
227
- })
228
-
229
- try {
230
- await client.proxy.a.get()
231
- } catch (er: any) {
232
- expect(er).toBeInstanceOf(RequestError)
233
- expect(er.status).toBe(404)
234
- }
235
- })
236
-
237
- it('should throw custom exception', async () => {
238
- class MyRequestError extends Error {
239
- constructor(
240
- message: string,
241
- public status: number,
242
- public path: string,
243
- public raw: any,
244
- ) {
245
- super(message)
246
- }
247
-
248
- toResponse() {
249
- return {
250
- status: this.status,
251
- }
252
- }
253
- }
254
-
255
- const client = generateClient<AxiosResponse>(axiosAdaptor, {
256
- // @ts-ignore
257
- customThrowResponseError(err) {
258
- return new MyRequestError(
259
- err.message,
260
- err.response?.status,
261
- err.path,
262
- err.raw,
263
- )
264
- },
265
- })
266
-
267
- spyOn(axiosAdaptor, 'get').mockImplementation(() => {
268
- return Promise.reject(
269
- new AxiosError(
270
- 'not found',
271
- 'NOT_FOUND',
272
- {},
273
- {},
274
- {
275
- status: 404,
276
- config: {},
277
- data: {},
278
- headers: {},
279
- statusText: 'not found',
280
- },
281
- ),
282
- )
283
- })
284
-
285
- try {
286
- await client.proxy.a.get()
287
- } catch (er: any) {
288
- expect(er).toBeInstanceOf(MyRequestError)
289
- expect(er.toResponse).toBeDefined()
290
- expect(er.status).toBe(404)
291
- }
292
- })
293
- })
@@ -1,108 +0,0 @@
1
- import { allControllers } from '~/controllers'
2
- import { HTTPClient, RequestError, createClient } from '~/core'
3
- import { IRequestAdapter } from '~/interfaces/adapter'
4
-
5
- import { createMockServer } from './e2e-mock-server'
6
-
7
- export const testAdaptor = (adaptor: IRequestAdapter) => {
8
- let client: HTTPClient
9
- const { app, close, port } = createMockServer()
10
-
11
- afterAll(() => {
12
- close()
13
- })
14
-
15
- beforeAll(() => {
16
- client = createClient(adaptor)(`http://localhost:${port}`)
17
- client.injectControllers(allControllers)
18
- })
19
- test('get', async () => {
20
- app.get('/posts/1', (req, res) => {
21
- res.send({
22
- id: '1',
23
- category_id: '11',
24
- })
25
- })
26
- const res = await client.post.getPost('1')
27
-
28
- expect(res).toStrictEqual({
29
- id: '1',
30
- categoryId: '11',
31
- })
32
-
33
- expect(res.$raw.data.category_id).toEqual('11')
34
- })
35
-
36
- test('post', async () => {
37
- app.post('/comments/1', (req, res) => {
38
- const { body } = req
39
-
40
- res.send({
41
- ...body,
42
- })
43
- })
44
- const dto = {
45
- text: 'hello',
46
- author: 'test',
47
- mail: '1@ee.com',
48
- }
49
- const res = await client.comment.comment('1', dto)
50
-
51
- expect(res).toStrictEqual(dto)
52
- })
53
-
54
- test('get with search query', async () => {
55
- app.get('/search/post', (req, res) => {
56
- if (req.query.keyword) {
57
- return res.send({ result: 1 })
58
- }
59
- res.send(null)
60
- })
61
-
62
- const res = await client.search.search('post', 'keyword')
63
- expect(res).toStrictEqual({ result: 1 })
64
- })
65
-
66
- test('rawResponse rawRequest should defined', async () => {
67
- app.get('/search/post', (req, res) => {
68
- if (req.query.keyword) {
69
- return res.send({ result: 1 })
70
- }
71
- res.send(null)
72
- })
73
-
74
- const res = await client.search.search('post', 'keyword')
75
- expect(res.$raw).toBeDefined()
76
- expect(res.$raw.data).toBeDefined()
77
- })
78
-
79
- it('should error catch', async () => {
80
- app.get('/error', (req, res) => {
81
- res.status(500).send({
82
- message: 'error message',
83
- })
84
- })
85
- await expect(client.proxy.error.get()).rejects.toThrowError(RequestError)
86
- })
87
-
88
- it('should use number as path', async () => {
89
- app.get('/1/1', (req, res) => {
90
- res.send({ data: 1, foo_bar: 'foo' })
91
- })
92
-
93
- const res = await client.proxy(1)(1).get<{ data: number; fooBar: string }>()
94
-
95
- expect(res).toStrictEqual({ data: 1, fooBar: 'foo' })
96
- expect(res.$raw.data).toStrictEqual({ data: 1, foo_bar: 'foo' })
97
- expect(res.$request).toBeDefined()
98
- })
99
-
100
- it('should get string payload', async () => {
101
- app.get('/string', (req, res) => {
102
- res.send('x')
103
- })
104
-
105
- const res = await client.proxy('string').get<string>()
106
- expect(res).toStrictEqual('x')
107
- })
108
- }
@@ -1,22 +0,0 @@
1
- import cors from 'cors'
2
- import express from 'express'
3
- import { AddressInfo } from 'net'
4
-
5
- type Express = ReturnType<typeof express>
6
- export const createMockServer = (options: { port?: number } = {}) => {
7
- const { port = 0 } = options
8
-
9
- const app: Express = express()
10
- app.use(express.json())
11
- app.use(cors())
12
- const server = app.listen(port)
13
-
14
- return {
15
- app,
16
- port: (server.address() as AddressInfo).port,
17
- server,
18
- close() {
19
- server.close()
20
- },
21
- }
22
- }
@@ -1,39 +0,0 @@
1
- // @ts-nocheck
2
-
3
- /* eslint-disable */
4
- import AbortController from 'abort-controller'
5
- import fetch, { Headers, Request, Response } from 'node-fetch'
6
-
7
- const TEN_MEGABYTES = 1000 * 1000 * 10
8
-
9
- if (!globalThis.fetch) {
10
- globalThis.fetch = (url, options) =>
11
- fetch(url, { highWaterMark: TEN_MEGABYTES, ...options })
12
- }
13
-
14
- if (!globalThis.Headers) {
15
- globalThis.Headers = Headers
16
- }
17
-
18
- if (!globalThis.Request) {
19
- globalThis.Request = Request
20
- }
21
-
22
- if (!globalThis.Response) {
23
- globalThis.Response = Response
24
- }
25
-
26
- if (!globalThis.AbortController) {
27
- globalThis.AbortController = AbortController
28
- }
29
-
30
- if (!globalThis.ReadableStream) {
31
- try {
32
- // eslint-disable-next-line node/file-extension-in-import, node/no-unsupported-features/es-syntax
33
- globalThis.ReadableStream = await import(
34
- 'web-streams-polyfill/ponyfill/es2018'
35
- )
36
- } catch {}
37
- }
38
-
39
- export {}
@@ -1,11 +0,0 @@
1
- import { axiosAdaptor } from '~/adaptors/axios'
2
- import { HTTPClient, createClient } from '~/core'
3
- import { IController } from '~/interfaces/controller'
4
-
5
- export const mockRequestInstance = (
6
- injectController: new (client: HTTPClient) => IController,
7
- ) => {
8
- const client = createClient(axiosAdaptor)('https://api.innei.ren/v2')
9
- client.injectControllers(injectController)
10
- return client
11
- }
@@ -1,76 +0,0 @@
1
- import { isEqual } from 'lodash'
2
- import { URLSearchParams } from 'url'
3
- import { vi } from 'vitest'
4
-
5
- import { axiosAdaptor } from '~/adaptors/axios'
6
-
7
- const { spyOn } = vi
8
-
9
- export const buildResponseDataWrapper = (data: any) => ({ data })
10
-
11
- export const mockResponse = <T>(
12
- path: string,
13
- data: T,
14
- method = 'get',
15
- requestBody?: any,
16
- ) => {
17
- const exceptUrlObject = new URL(
18
- path.startsWith('http')
19
- ? path
20
- : `https://example.com/${path.replace(/^\//, '')}`,
21
- )
22
- // @ts-ignore
23
- spyOn(axiosAdaptor, method).mockImplementation(
24
- // @ts-ignore
25
- async (requestUrl: string, options: any) => {
26
- const requestUrlObject = new URL(requestUrl)
27
-
28
- if (requestBody) {
29
- const { data } = options || {}
30
- if (!isEqual(requestBody, data)) {
31
- throw new Error(
32
- `body not equal, got: ${JSON.stringify(
33
- data,
34
- )} except: ${JSON.stringify(requestBody)}`,
35
- )
36
- }
37
- }
38
-
39
- if (
40
- requestUrlObject.pathname.endsWith(exceptUrlObject.pathname) &&
41
- (exceptUrlObject.search
42
- ? isSearchEqual(
43
- exceptUrlObject.searchParams,
44
- requestUrlObject.searchParams,
45
- )
46
- : true)
47
- ) {
48
- return buildResponseDataWrapper(data)
49
- } else {
50
- return buildResponseDataWrapper({
51
- error: 1,
52
- requestPath: requestUrlObject.pathname + requestUrlObject.search,
53
- expectPath: path,
54
- })
55
- }
56
- },
57
- )
58
-
59
- return data
60
- }
61
-
62
- const isSearchEqual = (a: URLSearchParams, b: URLSearchParams) => {
63
- const keys = Array.from(a.keys()).sort()
64
- if (keys.toString() !== Array.from(b.keys()).sort().toString()) {
65
- return false
66
- }
67
- return keys.every((key) => {
68
- const res = a.get(key) === b.get(key)
69
- if (!res) {
70
- console.log(
71
- `key ${key} not equal, receive ${a.get(key)} want ${b.get(key)}`,
72
- )
73
- }
74
- return res
75
- })
76
- }