mm-share-lib 0.0.13 → 0.0.15

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 (344) hide show
  1. package/.eslintrc.js +25 -25
  2. package/.prettierrc +3 -3
  3. package/README.md +73 -73
  4. package/index.ts +1 -1
  5. package/nest-cli.json +8 -8
  6. package/package.json +91 -91
  7. package/src/constant/entity-state.constant.ts +4 -4
  8. package/src/constant/index.ts +1 -1
  9. package/src/dto/index.ts +2 -2
  10. package/src/exception/bad-request-error.exception.spec.ts +24 -24
  11. package/src/exception/bad-request-error.exception.ts +8 -8
  12. package/src/exception/base.exception.ts +36 -36
  13. package/src/exception/conflict-error.exception.spec.ts +23 -23
  14. package/src/exception/conflict-error.exception.ts +8 -8
  15. package/src/exception/forbidden-error.exception.spec.ts +23 -23
  16. package/src/exception/forbidden-error.exception.ts +8 -8
  17. package/src/exception/index.ts +7 -7
  18. package/src/exception/internal-server-error.exception.spec.ts +23 -23
  19. package/src/exception/internal-server-error.exception.ts +12 -12
  20. package/src/exception/not-found-error.exception.spec.ts +23 -23
  21. package/src/exception/not-found-error.exception.ts +8 -8
  22. package/src/exception/unauthorized-error.exception.spec.ts +23 -23
  23. package/src/exception/unauthorized-error.exception.ts +12 -12
  24. package/src/filter/http-exception.filter.ts +23 -23
  25. package/src/filter/index.ts +1 -1
  26. package/src/filter/rpc-exception.filter.ts +15 -15
  27. package/src/generic/entity/entity.generic.ts +34 -34
  28. package/src/generic/entity/index.ts +1 -1
  29. package/src/generic/index.ts +2 -2
  30. package/src/generic/service/index.ts +1 -1
  31. package/src/generic/service/service.generic.ts +112 -112
  32. package/src/lib/datasource-mapper/datasource-mapper.ts +38 -0
  33. package/src/lib/datasource-mapper/index.ts +1 -0
  34. package/src/lib/index.ts +1 -0
  35. package/src/lib/search-engine/interface/index.ts +1 -1
  36. package/src/lib/search-engine/interface/search-document.interface.ts +13 -13
  37. package/src/lib/search-engine/interface/transform-service.interface.ts +10 -10
  38. package/src/lib/search-engine/typesense/service/client.service.ts +37 -24
  39. package/src/setup/index.ts +1 -1
  40. package/src/util/app.utils.ts +18 -18
  41. package/src/util/date.util.spec.ts +49 -49
  42. package/src/util/date.util.ts +10 -10
  43. package/src/util/generator.util.spec.ts +79 -79
  44. package/src/util/generator.util.ts +34 -34
  45. package/src/util/index.ts +4 -4
  46. package/test/app.e2e-spec.ts +24 -24
  47. package/test/jest-e2e.json +9 -9
  48. package/tsconfig.build.json +4 -4
  49. package/tsconfig.json +22 -21
  50. package/dist/index.d.ts +0 -1
  51. package/dist/index.js +0 -18
  52. package/dist/index.js.map +0 -1
  53. package/dist/src/auth/apple/apple.module.d.ts +0 -2
  54. package/dist/src/auth/apple/apple.module.js +0 -22
  55. package/dist/src/auth/apple/apple.module.js.map +0 -1
  56. package/dist/src/auth/apple/apple.service.d.ts +0 -9
  57. package/dist/src/auth/apple/apple.service.js +0 -38
  58. package/dist/src/auth/apple/apple.service.js.map +0 -1
  59. package/dist/src/auth/apple/dto/apple-login.dto.d.ts +0 -5
  60. package/dist/src/auth/apple/dto/apple-login.dto.js +0 -33
  61. package/dist/src/auth/apple/dto/apple-login.dto.js.map +0 -1
  62. package/dist/src/auth/apple/dto/index.d.ts +0 -1
  63. package/dist/src/auth/apple/dto/index.js +0 -18
  64. package/dist/src/auth/apple/dto/index.js.map +0 -1
  65. package/dist/src/auth/apple/index.d.ts +0 -3
  66. package/dist/src/auth/apple/index.js +0 -20
  67. package/dist/src/auth/apple/index.js.map +0 -1
  68. package/dist/src/auth/config/apple.config.d.ts +0 -3
  69. package/dist/src/auth/config/apple.config.js +0 -29
  70. package/dist/src/auth/config/apple.config.js.map +0 -1
  71. package/dist/src/auth/config/auth.config.d.ts +0 -3
  72. package/dist/src/auth/config/auth.config.js +0 -42
  73. package/dist/src/auth/config/auth.config.js.map +0 -1
  74. package/dist/src/auth/config/facebook.config.d.ts +0 -3
  75. package/dist/src/auth/config/facebook.config.js +0 -34
  76. package/dist/src/auth/config/facebook.config.js.map +0 -1
  77. package/dist/src/auth/config/file.config.d.ts +0 -3
  78. package/dist/src/auth/config/file.config.js +0 -66
  79. package/dist/src/auth/config/file.config.js.map +0 -1
  80. package/dist/src/auth/config/google.config.d.ts +0 -3
  81. package/dist/src/auth/config/google.config.js +0 -34
  82. package/dist/src/auth/config/google.config.js.map +0 -1
  83. package/dist/src/auth/config/index.d.ts +0 -6
  84. package/dist/src/auth/config/index.js +0 -23
  85. package/dist/src/auth/config/index.js.map +0 -1
  86. package/dist/src/auth/config/twitter.config.d.ts +0 -8
  87. package/dist/src/auth/config/twitter.config.js +0 -34
  88. package/dist/src/auth/config/twitter.config.js.map +0 -1
  89. package/dist/src/auth/facebook/dto/facebook-login.dto.d.ts +0 -3
  90. package/dist/src/auth/facebook/dto/facebook-login.dto.js +0 -23
  91. package/dist/src/auth/facebook/dto/facebook-login.dto.js.map +0 -1
  92. package/dist/src/auth/facebook/dto/index.d.ts +0 -1
  93. package/dist/src/auth/facebook/dto/index.js +0 -18
  94. package/dist/src/auth/facebook/dto/index.js.map +0 -1
  95. package/dist/src/auth/facebook/facebook.module.d.ts +0 -2
  96. package/dist/src/auth/facebook/facebook.module.js +0 -23
  97. package/dist/src/auth/facebook/facebook.module.js.map +0 -1
  98. package/dist/src/auth/facebook/facebook.service.d.ts +0 -10
  99. package/dist/src/auth/facebook/facebook.service.js +0 -50
  100. package/dist/src/auth/facebook/facebook.service.js.map +0 -1
  101. package/dist/src/auth/facebook/index.d.ts +0 -4
  102. package/dist/src/auth/facebook/index.js +0 -21
  103. package/dist/src/auth/facebook/index.js.map +0 -1
  104. package/dist/src/auth/facebook/interface/facebook.interface.d.ts +0 -6
  105. package/dist/src/auth/facebook/interface/facebook.interface.js +0 -3
  106. package/dist/src/auth/facebook/interface/facebook.interface.js.map +0 -1
  107. package/dist/src/auth/facebook/interface/index.d.ts +0 -1
  108. package/dist/src/auth/facebook/interface/index.js +0 -18
  109. package/dist/src/auth/facebook/interface/index.js.map +0 -1
  110. package/dist/src/auth/google/dto/google-login.dto.d.ts +0 -3
  111. package/dist/src/auth/google/dto/google-login.dto.js +0 -23
  112. package/dist/src/auth/google/dto/google-login.dto.js.map +0 -1
  113. package/dist/src/auth/google/dto/index.d.ts +0 -1
  114. package/dist/src/auth/google/dto/index.js +0 -18
  115. package/dist/src/auth/google/dto/index.js.map +0 -1
  116. package/dist/src/auth/google/google.module.d.ts +0 -2
  117. package/dist/src/auth/google/google.module.js +0 -22
  118. package/dist/src/auth/google/google.module.js.map +0 -1
  119. package/dist/src/auth/google/google.service.d.ts +0 -10
  120. package/dist/src/auth/google/google.service.js +0 -49
  121. package/dist/src/auth/google/google.service.js.map +0 -1
  122. package/dist/src/auth/google/index.d.ts +0 -3
  123. package/dist/src/auth/google/index.js +0 -20
  124. package/dist/src/auth/google/index.js.map +0 -1
  125. package/dist/src/auth/index.d.ts +0 -5
  126. package/dist/src/auth/index.js +0 -22
  127. package/dist/src/auth/index.js.map +0 -1
  128. package/dist/src/auth/twitter/dto/index.d.ts +0 -1
  129. package/dist/src/auth/twitter/dto/index.js +0 -18
  130. package/dist/src/auth/twitter/dto/index.js.map +0 -1
  131. package/dist/src/auth/twitter/dto/twitter-login.dto.d.ts +0 -4
  132. package/dist/src/auth/twitter/dto/twitter-login.dto.js +0 -28
  133. package/dist/src/auth/twitter/dto/twitter-login.dto.js.map +0 -1
  134. package/dist/src/auth/twitter/index.d.ts +0 -3
  135. package/dist/src/auth/twitter/index.js +0 -20
  136. package/dist/src/auth/twitter/index.js.map +0 -1
  137. package/dist/src/auth/twitter/twitter.module.d.ts +0 -2
  138. package/dist/src/auth/twitter/twitter.module.js +0 -23
  139. package/dist/src/auth/twitter/twitter.module.js.map +0 -1
  140. package/dist/src/auth/twitter/twitter.service.d.ts +0 -9
  141. package/dist/src/auth/twitter/twitter.service.js +0 -49
  142. package/dist/src/auth/twitter/twitter.service.js.map +0 -1
  143. package/dist/src/config/index.d.ts +0 -1
  144. package/dist/src/config/index.js +0 -18
  145. package/dist/src/config/index.js.map +0 -1
  146. package/dist/src/config/type.config.d.ts +0 -79
  147. package/dist/src/config/type.config.js +0 -3
  148. package/dist/src/config/type.config.js.map +0 -1
  149. package/dist/src/constant/entity-state.constant.d.ts +0 -4
  150. package/dist/src/constant/entity-state.constant.js +0 -9
  151. package/dist/src/constant/entity-state.constant.js.map +0 -1
  152. package/dist/src/constant/index.d.ts +0 -1
  153. package/dist/src/constant/index.js +0 -18
  154. package/dist/src/constant/index.js.map +0 -1
  155. package/dist/src/dto/base-filter.dto.d.ts +0 -4
  156. package/dist/src/dto/base-filter.dto.js +0 -11
  157. package/dist/src/dto/base-filter.dto.js.map +0 -1
  158. package/dist/src/dto/index.d.ts +0 -2
  159. package/dist/src/dto/index.js +0 -19
  160. package/dist/src/dto/index.js.map +0 -1
  161. package/dist/src/dto/pagination.dto.d.ts +0 -5
  162. package/dist/src/dto/pagination.dto.js +0 -37
  163. package/dist/src/dto/pagination.dto.js.map +0 -1
  164. package/dist/src/exception/bad-request-error.exception.d.ts +0 -4
  165. package/dist/src/exception/bad-request-error.exception.js +0 -12
  166. package/dist/src/exception/bad-request-error.exception.js.map +0 -1
  167. package/dist/src/exception/base.exception.d.ts +0 -21
  168. package/dist/src/exception/base.exception.js +0 -16
  169. package/dist/src/exception/base.exception.js.map +0 -1
  170. package/dist/src/exception/conflict-error.exception.d.ts +0 -4
  171. package/dist/src/exception/conflict-error.exception.js +0 -12
  172. package/dist/src/exception/conflict-error.exception.js.map +0 -1
  173. package/dist/src/exception/forbidden-error.exception.d.ts +0 -4
  174. package/dist/src/exception/forbidden-error.exception.js +0 -12
  175. package/dist/src/exception/forbidden-error.exception.js.map +0 -1
  176. package/dist/src/exception/index.d.ts +0 -7
  177. package/dist/src/exception/index.js +0 -24
  178. package/dist/src/exception/index.js.map +0 -1
  179. package/dist/src/exception/internal-server-error.exception.d.ts +0 -4
  180. package/dist/src/exception/internal-server-error.exception.js +0 -12
  181. package/dist/src/exception/internal-server-error.exception.js.map +0 -1
  182. package/dist/src/exception/not-found-error.exception.d.ts +0 -4
  183. package/dist/src/exception/not-found-error.exception.js +0 -12
  184. package/dist/src/exception/not-found-error.exception.js.map +0 -1
  185. package/dist/src/exception/unauthorized-error.exception.d.ts +0 -4
  186. package/dist/src/exception/unauthorized-error.exception.js +0 -12
  187. package/dist/src/exception/unauthorized-error.exception.js.map +0 -1
  188. package/dist/src/filter/http-exception.filter.d.ts +0 -4
  189. package/dist/src/filter/http-exception.filter.js +0 -27
  190. package/dist/src/filter/http-exception.filter.js.map +0 -1
  191. package/dist/src/filter/index.d.ts +0 -1
  192. package/dist/src/filter/index.js +0 -18
  193. package/dist/src/filter/index.js.map +0 -1
  194. package/dist/src/filter/rpc-exception.filter.d.ts +0 -6
  195. package/dist/src/filter/rpc-exception.filter.js +0 -21
  196. package/dist/src/filter/rpc-exception.filter.js.map +0 -1
  197. package/dist/src/generic/entity/entity.generic.d.ts +0 -10
  198. package/dist/src/generic/entity/entity.generic.js +0 -48
  199. package/dist/src/generic/entity/entity.generic.js.map +0 -1
  200. package/dist/src/generic/entity/index.d.ts +0 -1
  201. package/dist/src/generic/entity/index.js +0 -18
  202. package/dist/src/generic/entity/index.js.map +0 -1
  203. package/dist/src/generic/index.d.ts +0 -2
  204. package/dist/src/generic/index.js +0 -19
  205. package/dist/src/generic/index.js.map +0 -1
  206. package/dist/src/generic/service/index.d.ts +0 -1
  207. package/dist/src/generic/service/index.js +0 -18
  208. package/dist/src/generic/service/index.js.map +0 -1
  209. package/dist/src/generic/service/service.generic.d.ts +0 -18
  210. package/dist/src/generic/service/service.generic.js +0 -85
  211. package/dist/src/generic/service/service.generic.js.map +0 -1
  212. package/dist/src/index.d.ts +0 -11
  213. package/dist/src/index.js +0 -28
  214. package/dist/src/index.js.map +0 -1
  215. package/dist/src/interface/index.d.ts +0 -1
  216. package/dist/src/interface/index.js +0 -18
  217. package/dist/src/interface/index.js.map +0 -1
  218. package/dist/src/interface/social.interface.d.ts +0 -6
  219. package/dist/src/interface/social.interface.js +0 -3
  220. package/dist/src/interface/social.interface.js.map +0 -1
  221. package/dist/src/lib/index.d.ts +0 -4
  222. package/dist/src/lib/index.js +0 -21
  223. package/dist/src/lib/index.js.map +0 -1
  224. package/dist/src/lib/mailer/config/index.d.ts +0 -1
  225. package/dist/src/lib/mailer/config/index.js +0 -18
  226. package/dist/src/lib/mailer/config/index.js.map +0 -1
  227. package/dist/src/lib/mailer/config/mailer.config.d.ts +0 -3
  228. package/dist/src/lib/mailer/config/mailer.config.js +0 -72
  229. package/dist/src/lib/mailer/config/mailer.config.js.map +0 -1
  230. package/dist/src/lib/mailer/index.d.ts +0 -2
  231. package/dist/src/lib/mailer/index.js +0 -19
  232. package/dist/src/lib/mailer/index.js.map +0 -1
  233. package/dist/src/lib/mailer/mailer.module.d.ts +0 -2
  234. package/dist/src/lib/mailer/mailer.module.js +0 -20
  235. package/dist/src/lib/mailer/mailer.module.js.map +0 -1
  236. package/dist/src/lib/mailer/mailer.service.d.ts +0 -12
  237. package/dist/src/lib/mailer/mailer.service.js +0 -66
  238. package/dist/src/lib/mailer/mailer.service.js.map +0 -1
  239. package/dist/src/lib/redis/index.d.ts +0 -2
  240. package/dist/src/lib/redis/index.js +0 -7
  241. package/dist/src/lib/redis/index.js.map +0 -1
  242. package/dist/src/lib/search-engine/document/base.document.d.ts +0 -3
  243. package/dist/src/lib/search-engine/document/base.document.js +0 -7
  244. package/dist/src/lib/search-engine/document/base.document.js.map +0 -1
  245. package/dist/src/lib/search-engine/document/index.d.ts +0 -1
  246. package/dist/src/lib/search-engine/document/index.js +0 -18
  247. package/dist/src/lib/search-engine/document/index.js.map +0 -1
  248. package/dist/src/lib/search-engine/index.d.ts +0 -3
  249. package/dist/src/lib/search-engine/index.js +0 -20
  250. package/dist/src/lib/search-engine/index.js.map +0 -1
  251. package/dist/src/lib/search-engine/interface/index.d.ts +0 -2
  252. package/dist/src/lib/search-engine/interface/index.js +0 -19
  253. package/dist/src/lib/search-engine/interface/index.js.map +0 -1
  254. package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +0 -4
  255. package/dist/src/lib/search-engine/interface/search-document.interface.js +0 -3
  256. package/dist/src/lib/search-engine/interface/search-document.interface.js.map +0 -1
  257. package/dist/src/lib/search-engine/interface/transform-service.interface.d.ts +0 -6
  258. package/dist/src/lib/search-engine/interface/transform-service.interface.js +0 -3
  259. package/dist/src/lib/search-engine/interface/transform-service.interface.js.map +0 -1
  260. package/dist/src/lib/search-engine/typesense/collection/index.d.ts +0 -1
  261. package/dist/src/lib/search-engine/typesense/collection/index.js +0 -18
  262. package/dist/src/lib/search-engine/typesense/collection/index.js.map +0 -1
  263. package/dist/src/lib/search-engine/typesense/document/index.d.ts +0 -1
  264. package/dist/src/lib/search-engine/typesense/document/index.js +0 -18
  265. package/dist/src/lib/search-engine/typesense/document/index.js.map +0 -1
  266. package/dist/src/lib/search-engine/typesense/index.d.ts +0 -4
  267. package/dist/src/lib/search-engine/typesense/index.js +0 -21
  268. package/dist/src/lib/search-engine/typesense/index.js.map +0 -1
  269. package/dist/src/lib/search-engine/typesense/metadata/index.d.ts +0 -2
  270. package/dist/src/lib/search-engine/typesense/metadata/index.js +0 -19
  271. package/dist/src/lib/search-engine/typesense/metadata/index.js.map +0 -1
  272. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.d.ts +0 -13
  273. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js +0 -3
  274. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js.map +0 -1
  275. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.d.ts +0 -10
  276. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js +0 -33
  277. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js.map +0 -1
  278. package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +0 -34
  279. package/dist/src/lib/search-engine/typesense/service/client.service.js +0 -200
  280. package/dist/src/lib/search-engine/typesense/service/client.service.js.map +0 -1
  281. package/dist/src/lib/search-engine/typesense/service/index.d.ts +0 -1
  282. package/dist/src/lib/search-engine/typesense/service/index.js +0 -18
  283. package/dist/src/lib/search-engine/typesense/service/index.js.map +0 -1
  284. package/dist/src/lib/search-engine/typesense/typesense-module.interface.d.ts +0 -27
  285. package/dist/src/lib/search-engine/typesense/typesense-module.interface.js +0 -3
  286. package/dist/src/lib/search-engine/typesense/typesense-module.interface.js.map +0 -1
  287. package/dist/src/lib/search-engine/typesense/typesense.constants.d.ts +0 -1
  288. package/dist/src/lib/search-engine/typesense/typesense.constants.js +0 -5
  289. package/dist/src/lib/search-engine/typesense/typesense.constants.js.map +0 -1
  290. package/dist/src/lib/search-engine/typesense/typesense.module.d.ts +0 -8
  291. package/dist/src/lib/search-engine/typesense/typesense.module.js +0 -68
  292. package/dist/src/lib/search-engine/typesense/typesense.module.js.map +0 -1
  293. package/dist/src/lib/search-engine/typesense/typesense.module.test.d.ts +0 -1
  294. package/dist/src/lib/search-engine/typesense/typesense.module.test.js +0 -89
  295. package/dist/src/lib/search-engine/typesense/typesense.module.test.js.map +0 -1
  296. package/dist/src/lib/search-engine/typesense/typesense.providers.d.ts +0 -4
  297. package/dist/src/lib/search-engine/typesense/typesense.providers.js +0 -40
  298. package/dist/src/lib/search-engine/typesense/typesense.providers.js.map +0 -1
  299. package/dist/src/lib/storage/index.d.ts +0 -2
  300. package/dist/src/lib/storage/index.js +0 -7
  301. package/dist/src/lib/storage/index.js.map +0 -1
  302. package/dist/src/response/base-entity.response.d.ts +0 -3
  303. package/dist/src/response/base-entity.response.js +0 -23
  304. package/dist/src/response/base-entity.response.js.map +0 -1
  305. package/dist/src/response/index.d.ts +0 -2
  306. package/dist/src/response/index.js +0 -19
  307. package/dist/src/response/index.js.map +0 -1
  308. package/dist/src/response/login.response.d.ts +0 -0
  309. package/dist/src/response/login.response.js +0 -1
  310. package/dist/src/response/login.response.js.map +0 -1
  311. package/dist/src/response/pagination.response.d.ts +0 -17
  312. package/dist/src/response/pagination.response.js +0 -68
  313. package/dist/src/response/pagination.response.js.map +0 -1
  314. package/dist/src/setup/index.d.ts +0 -1
  315. package/dist/src/setup/index.js +0 -18
  316. package/dist/src/setup/index.js.map +0 -1
  317. package/dist/src/setup/microservice.setup.d.ts +0 -2
  318. package/dist/src/setup/microservice.setup.js +0 -25
  319. package/dist/src/setup/microservice.setup.js.map +0 -1
  320. package/dist/src/setup/swagger.setup.d.ts +0 -0
  321. package/dist/src/setup/swagger.setup.js +0 -1
  322. package/dist/src/setup/swagger.setup.js.map +0 -1
  323. package/dist/src/type/index.d.ts +0 -1
  324. package/dist/src/type/index.js +0 -18
  325. package/dist/src/type/index.js.map +0 -1
  326. package/dist/src/type/unknown.type.d.ts +0 -1
  327. package/dist/src/type/unknown.type.js +0 -3
  328. package/dist/src/type/unknown.type.js.map +0 -1
  329. package/dist/src/util/app.utils.d.ts +0 -4
  330. package/dist/src/util/app.utils.js +0 -21
  331. package/dist/src/util/app.utils.js.map +0 -1
  332. package/dist/src/util/date.util.d.ts +0 -2
  333. package/dist/src/util/date.util.js +0 -14
  334. package/dist/src/util/date.util.js.map +0 -1
  335. package/dist/src/util/generator.util.d.ts +0 -4
  336. package/dist/src/util/generator.util.js +0 -29
  337. package/dist/src/util/generator.util.js.map +0 -1
  338. package/dist/src/util/index.d.ts +0 -4
  339. package/dist/src/util/index.js +0 -21
  340. package/dist/src/util/index.js.map +0 -1
  341. package/dist/src/util/validate-config.d.ts +0 -2
  342. package/dist/src/util/validate-config.js +0 -19
  343. package/dist/src/util/validate-config.js.map +0 -1
  344. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -1,112 +1,112 @@
1
- import {
2
- Repository,
3
- Connection,
4
- EntityManager,
5
- SelectQueryBuilder,
6
- } from 'typeorm';
7
- import { EntityGeneric } from '../entity';
8
- import { PaginationDto, BaseFilterDto } from '../../dto';
9
- import { EntityStateConstant } from '../../constant';
10
- import { PaginationResponse } from '../../response';
11
-
12
- export abstract class ServiceGeneric<
13
- Entity extends EntityGeneric,
14
- CustomRepository extends Repository<Entity>,
15
- > {
16
- protected readonly entityName: string;
17
- protected readonly loggable: boolean = false;
18
- protected repository: CustomRepository;
19
- protected connection: Connection;
20
- constructor(
21
- protected readonly connectionOrManager: Connection | EntityManager,
22
- repositoryType: { new (connection: Connection): CustomRepository },
23
- ) {
24
- if (connectionOrManager instanceof EntityManager) {
25
- this.connection = connectionOrManager.connection;
26
- } else {
27
- this.connection = connectionOrManager;
28
- }
29
- this.repository = this.connection.getCustomRepository(repositoryType);
30
- }
31
-
32
- async create(entity: Entity): Promise<Entity> {
33
- return this.repository.save(entity);
34
- }
35
-
36
- async update(entity: Entity): Promise<Entity> {
37
- return this.repository.save(entity);
38
- }
39
-
40
- async getListWithPagination(
41
- paginationDto: PaginationDto,
42
- callback?: (query: SelectQueryBuilder<Entity>) => void,
43
- ): Promise<PaginationResponse<Entity>> {
44
- const { limit = 25, offset = 0 } = paginationDto;
45
- const query = this.repository.createQueryBuilder(this.entityName);
46
- query.limit(limit);
47
- query.offset(offset);
48
- query.where(`${this.entityName}.state != :state`, {
49
- state: EntityStateConstant.Archived,
50
- });
51
- const defaultSelectable = ['createdAt', 'updatedAt'];
52
- query.orderBy(`${this.entityName}.updatedAt`, 'DESC');
53
- const selection = defaultSelectable.map(
54
- (column: string) => `${this.entityName}.${column}`,
55
- );
56
- query.addSelect(selection);
57
- if (callback != null) {
58
- callback(query);
59
- }
60
- const entities = await query.getMany();
61
- const total = await query.getCount();
62
- const response = new PaginationResponse(entities, total, limit, offset);
63
- return response;
64
- }
65
-
66
- async getAutocompleteWithPagination(
67
- paginationDto: PaginationDto,
68
- filter: BaseFilterDto,
69
- callback?: (query: SelectQueryBuilder<Entity>) => void,
70
- ): Promise<PaginationResponse<Entity>> {
71
- const { limit = 25, offset = 0 } = paginationDto;
72
- const query = this.repository.createQueryBuilder(this.entityName);
73
- query.limit(limit);
74
- query.offset(offset);
75
- query.where(`${this.entityName}.state != :state`, {
76
- state: EntityStateConstant.Archived,
77
- });
78
- const defaultSelectable = ['createdAt', 'updatedAt'];
79
- query.orderBy(`${this.entityName}.updatedAt`, 'DESC');
80
- const selection = defaultSelectable.map(
81
- (column: string) => `${this.entityName}.${column}`,
82
- );
83
- query.addSelect(selection);
84
- if (callback != null) {
85
- callback(query);
86
- }
87
- const { excludeIds = [], includeIds = [] } = { ...filter };
88
- // Exclude some ids from the list.
89
- if (excludeIds?.length > 0) {
90
- query.andWhere(`${this.entityName}.id NOT IN (:ids)`, {
91
- ids: excludeIds,
92
- });
93
- }
94
- let entities = await query.getMany();
95
- const total = await query.getCount();
96
- // Include some ids to the list.
97
- const allIds: number[] = [];
98
- for (const id of includeIds) {
99
- const entity = entities.filter((entity: Entity) => entity.id === id);
100
- if (entity.length == 0) {
101
- allIds.push(id);
102
- }
103
- }
104
- if (allIds.length > 0) {
105
- query.where(`${this.entityName}.id IN (:ids)`, { ids: allIds });
106
- const data = await query.getMany();
107
- entities = data.concat(entities);
108
- }
109
- const response = new PaginationResponse(entities, total, limit, offset);
110
- return response;
111
- }
112
- }
1
+ import {
2
+ Repository,
3
+ Connection,
4
+ EntityManager,
5
+ SelectQueryBuilder,
6
+ } from 'typeorm';
7
+ import { EntityGeneric } from '../entity';
8
+ import { PaginationDto, BaseFilterDto } from '../../dto';
9
+ import { EntityStateConstant } from '../../constant';
10
+ import { PaginationResponse } from '../../response';
11
+
12
+ export abstract class ServiceGeneric<
13
+ Entity extends EntityGeneric,
14
+ CustomRepository extends Repository<Entity>,
15
+ > {
16
+ protected readonly entityName: string;
17
+ protected readonly loggable: boolean = false;
18
+ protected repository: CustomRepository;
19
+ protected connection: Connection;
20
+ constructor(
21
+ protected readonly connectionOrManager: Connection | EntityManager,
22
+ repositoryType: { new (connection: Connection): CustomRepository },
23
+ ) {
24
+ if (connectionOrManager instanceof EntityManager) {
25
+ this.connection = connectionOrManager.connection;
26
+ } else {
27
+ this.connection = connectionOrManager;
28
+ }
29
+ this.repository = this.connection.getCustomRepository(repositoryType);
30
+ }
31
+
32
+ async create(entity: Entity): Promise<Entity> {
33
+ return this.repository.save(entity);
34
+ }
35
+
36
+ async update(entity: Entity): Promise<Entity> {
37
+ return this.repository.save(entity);
38
+ }
39
+
40
+ async getListWithPagination(
41
+ paginationDto: PaginationDto,
42
+ callback?: (query: SelectQueryBuilder<Entity>) => void,
43
+ ): Promise<PaginationResponse<Entity>> {
44
+ const { limit = 25, offset = 0 } = paginationDto;
45
+ const query = this.repository.createQueryBuilder(this.entityName);
46
+ query.limit(limit);
47
+ query.offset(offset);
48
+ query.where(`${this.entityName}.state != :state`, {
49
+ state: EntityStateConstant.Archived,
50
+ });
51
+ const defaultSelectable = ['createdAt', 'updatedAt'];
52
+ query.orderBy(`${this.entityName}.updatedAt`, 'DESC');
53
+ const selection = defaultSelectable.map(
54
+ (column: string) => `${this.entityName}.${column}`,
55
+ );
56
+ query.addSelect(selection);
57
+ if (callback != null) {
58
+ callback(query);
59
+ }
60
+ const entities = await query.getMany();
61
+ const total = await query.getCount();
62
+ const response = new PaginationResponse(entities, total, limit, offset);
63
+ return response;
64
+ }
65
+
66
+ async getAutocompleteWithPagination(
67
+ paginationDto: PaginationDto,
68
+ filter: BaseFilterDto,
69
+ callback?: (query: SelectQueryBuilder<Entity>) => void,
70
+ ): Promise<PaginationResponse<Entity>> {
71
+ const { limit = 25, offset = 0 } = paginationDto;
72
+ const query = this.repository.createQueryBuilder(this.entityName);
73
+ query.limit(limit);
74
+ query.offset(offset);
75
+ query.where(`${this.entityName}.state != :state`, {
76
+ state: EntityStateConstant.Archived,
77
+ });
78
+ const defaultSelectable = ['createdAt', 'updatedAt'];
79
+ query.orderBy(`${this.entityName}.updatedAt`, 'DESC');
80
+ const selection = defaultSelectable.map(
81
+ (column: string) => `${this.entityName}.${column}`,
82
+ );
83
+ query.addSelect(selection);
84
+ if (callback != null) {
85
+ callback(query);
86
+ }
87
+ const { excludeIds = [], includeIds = [] } = { ...filter };
88
+ // Exclude some ids from the list.
89
+ if (excludeIds?.length > 0) {
90
+ query.andWhere(`${this.entityName}.id NOT IN (:ids)`, {
91
+ ids: excludeIds,
92
+ });
93
+ }
94
+ let entities = await query.getMany();
95
+ const total = await query.getCount();
96
+ // Include some ids to the list.
97
+ const allIds: number[] = [];
98
+ for (const id of includeIds) {
99
+ const entity = entities.filter((entity: Entity) => entity.id === id);
100
+ if (entity.length == 0) {
101
+ allIds.push(id);
102
+ }
103
+ }
104
+ if (allIds.length > 0) {
105
+ query.where(`${this.entityName}.id IN (:ids)`, { ids: allIds });
106
+ const data = await query.getMany();
107
+ entities = data.concat(entities);
108
+ }
109
+ const response = new PaginationResponse(entities, total, limit, offset);
110
+ return response;
111
+ }
112
+ }
@@ -0,0 +1,38 @@
1
+ import { DataSource } from 'typeorm';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { DatabaseConfig } from '../../config';
4
+
5
+ export class DataSourceManager {
6
+ private static instance: DataSourceManager;
7
+
8
+ private dataSources: { [key: string]: DataSource };
9
+
10
+ private constructor(private configService: ConfigService<DatabaseConfig>) {
11
+ this.dataSources = {};
12
+ }
13
+
14
+ public static getInstance(): DataSourceManager {
15
+ if (!DataSourceManager.instance) {
16
+ DataSourceManager.instance = new DataSourceManager();
17
+ }
18
+
19
+ return DataSourceManager.instance;
20
+ }
21
+
22
+ async getDBDataSource(dataSourceName: string): Promise<DataSource> {
23
+ if (this.dataSources[dataSourceName]) {
24
+ const dataSource = this.dataSources[dataSourceName];
25
+ return dataSource.isInitialized
26
+ ? dataSource
27
+ : await dataSource.initialize();
28
+ }
29
+
30
+ const newDataSource = new DataSource({
31
+ /** connection info */
32
+ } as any);
33
+
34
+ this.dataSources[dataSourceName] = newDataSource;
35
+
36
+ return await newDataSource.initialize();
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ export * from './datasource-mapper';
package/src/lib/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from './search-engine';
2
2
  export * from './mailer';
3
3
  export * from './redis';
4
4
  export * from './storage';
5
+ export * from './datasource-mapper';
@@ -1,2 +1,2 @@
1
- export * from './search-document.interface';
1
+ export * from './search-document.interface';
2
2
  export * from './transform-service.interface';
@@ -1,13 +1,13 @@
1
- import {
2
- SearchOptions,
3
- SearchParams,
4
- SearchResponse,
5
- DocumentSchema,
6
- } from 'typesense/lib/Typesense/Documents';
7
-
8
- export interface SearchDocumentService<Document extends DocumentSchema> {
9
- searchDocument(
10
- searchParameters: SearchParams,
11
- options: SearchOptions,
12
- ): Promise<SearchResponse<Document>>;
13
- }
1
+ import {
2
+ SearchOptions,
3
+ SearchParams,
4
+ SearchResponse,
5
+ DocumentSchema,
6
+ } from 'typesense/lib/Typesense/Documents';
7
+
8
+ export interface SearchDocumentService<Document extends DocumentSchema> {
9
+ searchDocument(
10
+ searchParameters: SearchParams,
11
+ options: SearchOptions,
12
+ ): Promise<SearchResponse<Document>>;
13
+ }
@@ -1,10 +1,10 @@
1
- import { EntityGeneric } from '../../../generic';
2
- import { BaseDocument } from '../document';
3
-
4
- export interface TransformerService<
5
- T extends EntityGeneric,
6
- Document extends BaseDocument,
7
- > {
8
- transform(data: T): Document;
9
- transforms(datas: T[]): Document[];
10
- }
1
+ import { EntityGeneric } from '../../../generic';
2
+ import { BaseDocument } from '../document';
3
+
4
+ export interface TransformerService<
5
+ T extends EntityGeneric,
6
+ Document extends BaseDocument,
7
+ > {
8
+ transform(data: T): Document;
9
+ transforms(datas: T[]): Document[];
10
+ }
@@ -3,16 +3,17 @@ import { Logger, Type } from '@nestjs/common';
3
3
  import { plainToClass } from 'class-transformer';
4
4
  import { CollectionCreateSchema } from '../collection';
5
5
  import {
6
- SearchParams,
7
- SearchOptions,
8
- SearchResponse,
9
6
  DeleteResponse,
10
7
  ImportResponse,
8
+ SearchOptions,
9
+ SearchParams,
10
+ SearchResponse,
11
11
  } from '../document';
12
12
  import { BaseDocument } from '../../document';
13
13
  import { SearchDocumentService } from '../../interface';
14
14
  import { EntityGeneric } from '../../../../generic';
15
15
  import { PaginationResponse } from '../../../../response';
16
+ import { BaseFilterDto } from '../../../../dto';
16
17
 
17
18
  export abstract class ClientService<
18
19
  Document extends BaseDocument,
@@ -23,6 +24,7 @@ export abstract class ClientService<
23
24
  protected readonly entity: Type<Entity>;
24
25
  protected abstract cache_s: number;
25
26
  protected readonly skipCheckSchema: boolean = false;
27
+
26
28
  constructor(
27
29
  protected readonly client: Client,
28
30
  protected readonly schema: CollectionCreateSchema,
@@ -33,31 +35,42 @@ export abstract class ClientService<
33
35
  }
34
36
  }
35
37
 
36
- // searchDocument(searchParameters: SearchParams, options: SearchOptions) {
37
- // const {
38
- // per_page = 25,
39
- // filter_by,
40
- // archived = false,
41
- // } = { ...searchParameters };
42
- // searchParameters.per_page = per_page;
43
- // return this.client.collections(this?.schema?.name || this.prefix).documents().search(searchParameters, options);
44
- // }
38
+ getCollectionName(): string {
39
+ return this?.schema?.name || this.prefix;
40
+ }
45
41
 
46
42
  async searchDocument(
47
43
  searchParameters: SearchParams,
48
44
  options: SearchOptions,
45
+ filter?: BaseFilterDto,
46
+ ): Promise<SearchResponse<any>> {
47
+ return this.searchDocumentByCollection(
48
+ this.getCollectionName(),
49
+ searchParameters,
50
+ options,
51
+ filter,
52
+ );
53
+ }
54
+
55
+ async searchDocumentByCollection(
56
+ collection: string,
57
+ searchParameters: SearchParams,
58
+ options: SearchOptions,
59
+ filter?: BaseFilterDto,
49
60
  ): Promise<SearchResponse<any>> {
50
61
  try {
51
- const { includeIds = [], per_page = 25 } = { ...searchParameters };
62
+ const { per_page = 25 } = searchParameters;
52
63
  // TODO: should be support with include/exclude ids.
64
+ const { includeIds = [] } = filter;
53
65
  const includeDocuments = [];
66
+
54
67
  if (includeIds.length > 0) {
55
68
  const includeOpts = {
56
69
  ...searchParameters,
57
70
  filter_by: `id:=[${includeIds.join(', ')}]`,
58
71
  };
59
72
  const includeDocs = await this.client
60
- .collections(this?.schema?.name || this.prefix)
73
+ .collections(collection)
61
74
  .documents()
62
75
  .search(includeOpts, options);
63
76
  if (includeDocs?.hits?.length > 0) {
@@ -73,7 +86,7 @@ export abstract class ClientService<
73
86
  includeDocuments.push(...includeDocs?.hits);
74
87
  }
75
88
  const documents = await this.client
76
- .collections(this?.schema?.name || this.prefix)
89
+ .collections(collection)
77
90
  .documents()
78
91
  .search(searchParameters, options);
79
92
  if (includeDocuments.length > 0) {
@@ -108,7 +121,7 @@ export abstract class ClientService<
108
121
  if (data.length > 0) {
109
122
  try {
110
123
  return this.client
111
- .collections(this?.schema?.name || this.prefix)
124
+ .collections(this.getCollectionName())
112
125
  .documents()
113
126
  .import(data, { action: 'upsert' });
114
127
  } catch (error) {
@@ -123,7 +136,7 @@ export abstract class ClientService<
123
136
  filter_by: `${key}:!=[${data.join(', ')}]`,
124
137
  };
125
138
  return await this.client
126
- .collections(this?.schema?.name || this.prefix)
139
+ .collections(this.getCollectionName())
127
140
  .documents()
128
141
  .delete(deleteParameters);
129
142
  }
@@ -131,14 +144,14 @@ export abstract class ClientService<
131
144
 
132
145
  async insertIndex(data: Document): Promise<any> {
133
146
  return this.client
134
- .collections(this?.schema?.name || this.prefix)
147
+ .collections(this.getCollectionName())
135
148
  .documents()
136
149
  .create(data, { action: 'upsert' });
137
150
  }
138
151
 
139
152
  async updateIndex(data: Document): Promise<any> {
140
153
  return this.client
141
- .collections(this?.schema?.name || this.prefix)
154
+ .collections(this.getCollectionName())
142
155
  .documents()
143
156
  .upsert(data, { action: 'upsert' });
144
157
  }
@@ -146,12 +159,12 @@ export abstract class ClientService<
146
159
  updateDocumentById = async (data: Document) => {
147
160
  if (data?.id) {
148
161
  const exist = await this.client
149
- .collections(this?.schema?.name || this.prefix)
162
+ .collections(this.getCollectionName())
150
163
  .documents(data.id)
151
164
  .retrieve();
152
165
  if (exist) {
153
166
  return this.client
154
- .collections(this?.schema?.name || this.prefix)
167
+ .collections(this.getCollectionName())
155
168
  .documents(data.id)
156
169
  .update(data);
157
170
  }
@@ -164,14 +177,14 @@ export abstract class ClientService<
164
177
 
165
178
  async deleteIndex(data: Document): Promise<DeleteResponse> {
166
179
  return this.client
167
- .collections(this?.schema?.name || this.prefix)
180
+ .collections(this.getCollectionName())
168
181
  .documents()
169
182
  .delete({ filter_by: `id: ${data.id}` });
170
183
  }
171
184
 
172
185
  async deleteBatchIndex(ids: string[]): Promise<DeleteResponse> {
173
186
  return this.client
174
- .collections(this?.schema?.name || this.prefix)
187
+ .collections(this.getCollectionName())
175
188
  .documents()
176
189
  .delete({ filter_by: `id: [${ids.join(',')}]` });
177
190
  }
@@ -181,7 +194,7 @@ export abstract class ClientService<
181
194
  value: number,
182
195
  ): Promise<DeleteResponse> {
183
196
  return this.client
184
- .collections(this?.schema?.name || this.prefix)
197
+ .collections(this.getCollectionName())
185
198
  .documents()
186
199
  .delete({ filter_by: `${key}:=${value}` });
187
200
  }
@@ -1 +1 @@
1
- export * from './microservice.setup';
1
+ export * from './microservice.setup';
@@ -1,18 +1,18 @@
1
- import type { INestApplication } from '@nestjs/common';
2
-
3
- export class AppUtils {
4
- public static killAppWithGrace = (app: INestApplication) => {
5
- process.on('SIGINT', async () => {
6
- setTimeout(() => process.exit(1), 5000);
7
- await app.close();
8
- process.exit(0);
9
- });
10
-
11
- // kill -15
12
- process.on('SIGTERM', async () => {
13
- setTimeout(() => process.exit(1), 5000);
14
- await app.close();
15
- process.exit(0);
16
- });
17
- };
18
- }
1
+ import type { INestApplication } from '@nestjs/common';
2
+
3
+ export class AppUtils {
4
+ public static killAppWithGrace = (app: INestApplication) => {
5
+ process.on('SIGINT', async () => {
6
+ setTimeout(() => process.exit(1), 5000);
7
+ await app.close();
8
+ process.exit(0);
9
+ });
10
+
11
+ // kill -15
12
+ process.on('SIGTERM', async () => {
13
+ setTimeout(() => process.exit(1), 5000);
14
+ await app.close();
15
+ process.exit(0);
16
+ });
17
+ };
18
+ }
@@ -1,49 +1,49 @@
1
- import dayjs from 'dayjs';
2
- import { addSecond, isExpired } from './date.util';
3
-
4
- describe('Utility Functions', () => {
5
- test('addSecond should return a Date object with the specified duration added', () => {
6
- // Arrange
7
- const duration = 10;
8
-
9
- // Act
10
- const result = addSecond(duration);
11
-
12
- // Assert
13
- const expectedDate = dayjs().add(duration, 'seconds').toDate();
14
- expect(result).toEqual(expectedDate);
15
- });
16
-
17
- test('isExpired should return true for a past date', () => {
18
- // Arrange
19
- const pastDate = dayjs().subtract(1, 'day').toDate();
20
-
21
- // Act
22
- const result = isExpired(pastDate);
23
-
24
- // Assert
25
- expect(result).toBe(true);
26
- });
27
-
28
- test('isExpired should return false for a future date', () => {
29
- // Arrange
30
- const futureDate = dayjs().add(1, 'day').toDate();
31
-
32
- // Act
33
- const result = isExpired(futureDate);
34
-
35
- // Assert
36
- expect(result).toBe(false);
37
- });
38
-
39
- test('isExpired should return false for the current date', () => {
40
- // Arrange
41
- const currentDate = dayjs().toDate();
42
-
43
- // Act
44
- const result = isExpired(currentDate);
45
-
46
- // Assert
47
- expect(result).toBe(false);
48
- });
49
- });
1
+ import dayjs from 'dayjs';
2
+ import { addSecond, isExpired } from './date.util';
3
+
4
+ describe('Utility Functions', () => {
5
+ test('addSecond should return a Date object with the specified duration added', () => {
6
+ // Arrange
7
+ const duration = 10;
8
+
9
+ // Act
10
+ const result = addSecond(duration);
11
+
12
+ // Assert
13
+ const expectedDate = dayjs().add(duration, 'seconds').toDate();
14
+ expect(result).toEqual(expectedDate);
15
+ });
16
+
17
+ test('isExpired should return true for a past date', () => {
18
+ // Arrange
19
+ const pastDate = dayjs().subtract(1, 'day').toDate();
20
+
21
+ // Act
22
+ const result = isExpired(pastDate);
23
+
24
+ // Assert
25
+ expect(result).toBe(true);
26
+ });
27
+
28
+ test('isExpired should return false for a future date', () => {
29
+ // Arrange
30
+ const futureDate = dayjs().add(1, 'day').toDate();
31
+
32
+ // Act
33
+ const result = isExpired(futureDate);
34
+
35
+ // Assert
36
+ expect(result).toBe(false);
37
+ });
38
+
39
+ test('isExpired should return false for the current date', () => {
40
+ // Arrange
41
+ const currentDate = dayjs().toDate();
42
+
43
+ // Act
44
+ const result = isExpired(currentDate);
45
+
46
+ // Assert
47
+ expect(result).toBe(false);
48
+ });
49
+ });
@@ -1,10 +1,10 @@
1
- import dayjs from 'dayjs';
2
-
3
- export const addSecond = (duration: number): Date => {
4
- return dayjs().add(duration, 'seconds').toDate();
5
- };
6
-
7
- export const isExpired = (date: Date): boolean => {
8
- const currentDate = dayjs();
9
- return dayjs(date).isBefore(currentDate);
10
- };
1
+ import dayjs from 'dayjs';
2
+
3
+ export const addSecond = (duration: number): Date => {
4
+ return dayjs().add(duration, 'seconds').toDate();
5
+ };
6
+
7
+ export const isExpired = (date: Date): boolean => {
8
+ const currentDate = dayjs();
9
+ return dayjs(date).isBefore(currentDate);
10
+ };