@nlabs/reaktor 0.10.10 → 1.2.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 (422) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1296 -110
  3. package/lib/actions/apps.d.ts +2 -3
  4. package/lib/actions/apps.d.ts.map +1 -1
  5. package/lib/actions/apps.js +126 -126
  6. package/lib/actions/connections.d.ts +4 -4
  7. package/lib/actions/connections.d.ts.map +1 -1
  8. package/lib/actions/connections.js +80 -14
  9. package/lib/actions/content.d.ts +1 -1
  10. package/lib/actions/content.d.ts.map +1 -1
  11. package/lib/actions/content.js +92 -119
  12. package/lib/actions/conversations.d.ts +4 -3
  13. package/lib/actions/conversations.d.ts.map +1 -1
  14. package/lib/actions/conversations.js +84 -80
  15. package/lib/actions/crud.d.ts +59 -0
  16. package/lib/actions/crud.d.ts.map +1 -0
  17. package/lib/actions/crud.js +413 -0
  18. package/lib/actions/dynamodb.js +2 -2
  19. package/lib/actions/email.js +1 -1
  20. package/lib/actions/files.d.ts +3 -3
  21. package/lib/actions/files.d.ts.map +1 -1
  22. package/lib/actions/files.js +9 -19
  23. package/lib/actions/groups.d.ts +11 -7
  24. package/lib/actions/groups.d.ts.map +1 -1
  25. package/lib/actions/groups.js +103 -90
  26. package/lib/actions/images.d.ts +9 -8
  27. package/lib/actions/images.d.ts.map +1 -1
  28. package/lib/actions/images.js +487 -268
  29. package/lib/actions/index.d.ts +1 -0
  30. package/lib/actions/index.d.ts.map +1 -1
  31. package/lib/actions/index.js +2 -1
  32. package/lib/actions/ios.js +8 -8
  33. package/lib/actions/locations.d.ts +1 -0
  34. package/lib/actions/locations.d.ts.map +1 -1
  35. package/lib/actions/locations.js +102 -68
  36. package/lib/actions/messages.d.ts.map +1 -1
  37. package/lib/actions/messages.js +124 -30
  38. package/lib/actions/notifications.d.ts +2 -2
  39. package/lib/actions/notifications.d.ts.map +1 -1
  40. package/lib/actions/notifications.js +6 -6
  41. package/lib/actions/payments.d.ts +3 -0
  42. package/lib/actions/payments.d.ts.map +1 -1
  43. package/lib/actions/payments.js +207 -5
  44. package/lib/actions/personas.d.ts +35 -0
  45. package/lib/actions/personas.d.ts.map +1 -0
  46. package/lib/actions/personas.js +615 -0
  47. package/lib/actions/posts.d.ts +14 -9
  48. package/lib/actions/posts.d.ts.map +1 -1
  49. package/lib/actions/posts.js +398 -390
  50. package/lib/actions/query.d.ts +24 -0
  51. package/lib/actions/query.d.ts.map +1 -0
  52. package/lib/actions/query.js +97 -0
  53. package/lib/actions/reactions.d.ts +16 -3
  54. package/lib/actions/reactions.d.ts.map +1 -1
  55. package/lib/actions/reactions.js +532 -162
  56. package/lib/actions/s3.d.ts +8 -1
  57. package/lib/actions/s3.d.ts.map +1 -1
  58. package/lib/actions/s3.js +54 -33
  59. package/lib/actions/search.d.ts +9 -0
  60. package/lib/actions/search.d.ts.map +1 -1
  61. package/lib/actions/search.js +59 -43
  62. package/lib/actions/sms.js +1 -1
  63. package/lib/actions/statistics.d.ts.map +1 -1
  64. package/lib/actions/statistics.js +5 -14
  65. package/lib/actions/subscriptions.d.ts +11 -2
  66. package/lib/actions/subscriptions.d.ts.map +1 -1
  67. package/lib/actions/subscriptions.js +399 -105
  68. package/lib/actions/tags.d.ts +23 -12
  69. package/lib/actions/tags.d.ts.map +1 -1
  70. package/lib/actions/tags.js +197 -148
  71. package/lib/actions/users.d.ts +21 -25
  72. package/lib/actions/users.d.ts.map +1 -1
  73. package/lib/actions/users.js +352 -217
  74. package/lib/actions/videos.d.ts +28 -8
  75. package/lib/actions/videos.d.ts.map +1 -1
  76. package/lib/actions/videos.js +852 -77
  77. package/lib/actions/websockets.d.ts +1 -1
  78. package/lib/actions/websockets.d.ts.map +1 -1
  79. package/lib/actions/websockets.js +6 -6
  80. package/lib/adapters/arangoAdapter.d.ts.map +1 -1
  81. package/lib/adapters/arangoAdapter.js +3 -5
  82. package/lib/adapters/contentAdapter.d.ts.map +1 -1
  83. package/lib/adapters/contentAdapter.js +13 -21
  84. package/lib/adapters/fileAdapter.d.ts.map +1 -1
  85. package/lib/adapters/fileAdapter.js +4 -5
  86. package/lib/adapters/imageAdapter.d.ts.map +1 -1
  87. package/lib/adapters/imageAdapter.js +3 -5
  88. package/lib/adapters/messageAdapter.d.ts.map +1 -1
  89. package/lib/adapters/messageAdapter.js +24 -5
  90. package/lib/adapters/postAdapter.d.ts.map +1 -1
  91. package/lib/adapters/postAdapter.js +35 -6
  92. package/lib/adapters/reaktorAdapter.d.ts.map +1 -1
  93. package/lib/adapters/reaktorAdapter.js +7 -7
  94. package/lib/adapters/tagAdapter.d.ts.map +1 -1
  95. package/lib/adapters/tagAdapter.js +2 -3
  96. package/lib/adapters/userAdapter.d.ts +1 -0
  97. package/lib/adapters/userAdapter.d.ts.map +1 -1
  98. package/lib/adapters/userAdapter.js +52 -19
  99. package/lib/config.d.ts +1 -0
  100. package/lib/config.d.ts.map +1 -1
  101. package/lib/config.js +14 -17
  102. package/lib/constants/collections.d.ts +71 -0
  103. package/lib/constants/collections.d.ts.map +1 -0
  104. package/lib/constants/collections.js +63 -0
  105. package/lib/handlers/graphqlHandler.d.ts +33 -2
  106. package/lib/handlers/graphqlHandler.d.ts.map +1 -1
  107. package/lib/handlers/graphqlHandler.js +85 -17
  108. package/lib/index.d.ts +6 -2
  109. package/lib/index.d.ts.map +1 -1
  110. package/lib/index.js +7 -2
  111. package/lib/lambdas/actions/websockets.d.ts +7 -5
  112. package/lib/lambdas/actions/websockets.d.ts.map +1 -1
  113. package/lib/lambdas/actions/websockets.js +82 -62
  114. package/lib/lambdas/connection.d.ts +30 -4
  115. package/lib/lambdas/connection.d.ts.map +1 -1
  116. package/lib/lambdas/connection.js +248 -31
  117. package/lib/lambdas/utils/websocket.d.ts +22 -4
  118. package/lib/lambdas/utils/websocket.d.ts.map +1 -1
  119. package/lib/lambdas/utils/websocket.js +41 -49
  120. package/lib/mocks/image.d.ts.map +1 -1
  121. package/lib/mocks/image.js +3 -2
  122. package/lib/mocks/user.d.ts +1 -1
  123. package/lib/mocks/user.d.ts.map +1 -1
  124. package/lib/mocks/user.js +6 -11
  125. package/lib/mocks/video.d.ts.map +1 -1
  126. package/lib/mocks/video.js +3 -2
  127. package/lib/mutations/{content.d.ts → content/content.d.ts} +1 -1
  128. package/lib/mutations/content/content.d.ts.map +1 -0
  129. package/lib/mutations/content/content.js +27 -0
  130. package/lib/mutations/events/events.d.ts +3 -0
  131. package/lib/mutations/events/events.d.ts.map +1 -0
  132. package/lib/mutations/events/events.js +225 -0
  133. package/lib/mutations/groups/groups.d.ts +2 -0
  134. package/lib/mutations/groups/groups.d.ts.map +1 -0
  135. package/lib/mutations/groups/groups.js +50 -0
  136. package/lib/mutations/images/images.d.ts +2 -0
  137. package/lib/mutations/images/images.d.ts.map +1 -0
  138. package/lib/mutations/images/images.js +31 -0
  139. package/lib/mutations/index.d.ts +16 -11
  140. package/lib/mutations/index.d.ts.map +1 -1
  141. package/lib/mutations/index.js +133 -24
  142. package/lib/mutations/{locations.d.ts → locations/locations.d.ts} +1 -1
  143. package/lib/mutations/locations/locations.d.ts.map +1 -0
  144. package/lib/mutations/locations/locations.js +22 -0
  145. package/lib/mutations/messages/messages.d.ts +2 -0
  146. package/lib/mutations/messages/messages.d.ts.map +1 -0
  147. package/lib/mutations/messages/messages.js +67 -0
  148. package/lib/mutations/personas/personas.d.ts +3 -0
  149. package/lib/mutations/personas/personas.d.ts.map +1 -0
  150. package/lib/mutations/personas/personas.js +110 -0
  151. package/lib/mutations/{posts.d.ts → posts/posts.d.ts} +1 -1
  152. package/lib/mutations/posts/posts.d.ts.map +1 -0
  153. package/lib/mutations/posts/posts.js +31 -0
  154. package/lib/mutations/reactions/reactions.d.ts +2 -0
  155. package/lib/mutations/reactions/reactions.d.ts.map +1 -0
  156. package/lib/mutations/reactions/reactions.js +88 -0
  157. package/lib/mutations/{statistics.d.ts → statistics/statistics.d.ts} +1 -1
  158. package/lib/mutations/statistics/statistics.d.ts.map +1 -0
  159. package/lib/mutations/statistics/statistics.js +17 -0
  160. package/lib/mutations/{subscriptions.d.ts → subscriptions/subscriptions.d.ts} +1 -1
  161. package/lib/mutations/subscriptions/subscriptions.d.ts.map +1 -0
  162. package/lib/mutations/subscriptions/subscriptions.js +41 -0
  163. package/lib/mutations/tags/tags.d.ts +2 -0
  164. package/lib/mutations/tags/tags.d.ts.map +1 -0
  165. package/lib/mutations/tags/tags.js +115 -0
  166. package/lib/mutations/users/users.d.ts.map +1 -0
  167. package/lib/mutations/users/users.js +165 -0
  168. package/lib/mutations/videos/videos.d.ts +2 -0
  169. package/lib/mutations/videos/videos.d.ts.map +1 -0
  170. package/lib/mutations/videos/videos.js +98 -0
  171. package/lib/objectTypes/app.d.ts.map +1 -1
  172. package/lib/objectTypes/app.js +53 -29
  173. package/lib/objectTypes/bankAccount.d.ts.map +1 -1
  174. package/lib/objectTypes/bankAccount.js +30 -17
  175. package/lib/objectTypes/connection.d.ts.map +1 -1
  176. package/lib/objectTypes/connection.js +8 -6
  177. package/lib/objectTypes/content.d.ts.map +1 -1
  178. package/lib/objectTypes/content.js +38 -21
  179. package/lib/objectTypes/conversation.d.ts.map +1 -1
  180. package/lib/objectTypes/conversation.js +35 -15
  181. package/lib/objectTypes/creditCard.d.ts +1 -1
  182. package/lib/objectTypes/creditCard.d.ts.map +1 -1
  183. package/lib/objectTypes/creditCard.js +21 -26
  184. package/lib/objectTypes/document.d.ts.map +1 -1
  185. package/lib/objectTypes/document.js +8 -5
  186. package/lib/objectTypes/error.d.ts.map +1 -1
  187. package/lib/objectTypes/error.js +10 -7
  188. package/lib/objectTypes/event.d.ts +5 -0
  189. package/lib/objectTypes/event.d.ts.map +1 -0
  190. package/lib/objectTypes/event.js +265 -0
  191. package/lib/objectTypes/external.d.ts.map +1 -1
  192. package/lib/objectTypes/external.js +18 -11
  193. package/lib/objectTypes/file.d.ts.map +1 -1
  194. package/lib/objectTypes/file.js +38 -21
  195. package/lib/objectTypes/filter.d.ts.map +1 -1
  196. package/lib/objectTypes/filter.js +8 -6
  197. package/lib/objectTypes/group.d.ts.map +1 -1
  198. package/lib/objectTypes/group.js +68 -25
  199. package/lib/objectTypes/iapSubscription.d.ts.map +1 -1
  200. package/lib/objectTypes/iapSubscription.js +6 -5
  201. package/lib/objectTypes/image.d.ts.map +1 -1
  202. package/lib/objectTypes/image.js +138 -29
  203. package/lib/objectTypes/index.d.ts +3 -2
  204. package/lib/objectTypes/index.d.ts.map +1 -1
  205. package/lib/objectTypes/index.js +4 -3
  206. package/lib/objectTypes/location.d.ts.map +1 -1
  207. package/lib/objectTypes/location.js +55 -24
  208. package/lib/objectTypes/message.d.ts.map +1 -1
  209. package/lib/objectTypes/message.js +81 -27
  210. package/lib/objectTypes/passcode.d.ts.map +1 -1
  211. package/lib/objectTypes/passcode.js +4 -5
  212. package/lib/objectTypes/persona.d.ts +4 -0
  213. package/lib/objectTypes/persona.d.ts.map +1 -0
  214. package/lib/objectTypes/persona.js +250 -0
  215. package/lib/objectTypes/plan.d.ts.map +1 -1
  216. package/lib/objectTypes/plan.js +57 -21
  217. package/lib/objectTypes/post.d.ts.map +1 -1
  218. package/lib/objectTypes/post.js +89 -27
  219. package/lib/objectTypes/query.d.ts +10 -0
  220. package/lib/objectTypes/query.d.ts.map +1 -0
  221. package/lib/objectTypes/query.js +176 -0
  222. package/lib/objectTypes/reaction.d.ts.map +1 -1
  223. package/lib/objectTypes/reaction.js +28 -8
  224. package/lib/objectTypes/relation.d.ts.map +1 -1
  225. package/lib/objectTypes/relation.js +5 -6
  226. package/lib/objectTypes/search.d.ts.map +1 -1
  227. package/lib/objectTypes/search.js +16 -10
  228. package/lib/objectTypes/statistics.d.ts.map +1 -1
  229. package/lib/objectTypes/statistics.js +4 -4
  230. package/lib/objectTypes/subscription.d.ts.map +1 -1
  231. package/lib/objectTypes/subscription.js +69 -28
  232. package/lib/objectTypes/tag.d.ts.map +1 -1
  233. package/lib/objectTypes/tag.js +24 -11
  234. package/lib/objectTypes/user.d.ts.map +1 -1
  235. package/lib/objectTypes/user.js +296 -65
  236. package/lib/objectTypes/video.d.ts +10 -0
  237. package/lib/objectTypes/video.d.ts.map +1 -0
  238. package/lib/objectTypes/video.js +383 -0
  239. package/lib/queries/{content.d.ts → content/content.d.ts} +1 -1
  240. package/lib/queries/content/content.d.ts.map +1 -0
  241. package/lib/queries/content/content.js +55 -0
  242. package/lib/queries/events/events.d.ts +3 -0
  243. package/lib/queries/events/events.d.ts.map +1 -0
  244. package/lib/queries/events/events.js +113 -0
  245. package/lib/queries/groups/groups.d.ts +2 -0
  246. package/lib/queries/groups/groups.d.ts.map +1 -0
  247. package/lib/queries/groups/groups.js +49 -0
  248. package/lib/queries/images/images.d.ts +2 -0
  249. package/lib/queries/images/images.d.ts.map +1 -0
  250. package/lib/queries/images/images.js +98 -0
  251. package/lib/queries/index.d.ts +17 -10
  252. package/lib/queries/index.d.ts.map +1 -1
  253. package/lib/queries/index.js +147 -22
  254. package/lib/queries/{locations.d.ts → locations/locations.d.ts} +1 -1
  255. package/lib/queries/locations/locations.d.ts.map +1 -0
  256. package/lib/queries/locations/locations.js +37 -0
  257. package/lib/queries/messages/messages.d.ts +2 -0
  258. package/lib/queries/messages/messages.d.ts.map +1 -0
  259. package/lib/queries/messages/messages.js +66 -0
  260. package/lib/queries/personas/personas.d.ts +2 -0
  261. package/lib/queries/personas/personas.d.ts.map +1 -0
  262. package/lib/queries/personas/personas.js +66 -0
  263. package/lib/queries/{posts.d.ts → posts/posts.d.ts} +1 -1
  264. package/lib/queries/posts/posts.d.ts.map +1 -0
  265. package/lib/queries/posts/posts.js +157 -0
  266. package/lib/queries/query/query.d.ts +3 -0
  267. package/lib/queries/query/query.d.ts.map +1 -0
  268. package/lib/queries/query/query.js +52 -0
  269. package/lib/queries/reactions/reactions.d.ts +2 -0
  270. package/lib/queries/reactions/reactions.d.ts.map +1 -0
  271. package/lib/queries/reactions/reactions.js +94 -0
  272. package/lib/queries/{statistics.d.ts → statistics/statistics.d.ts} +1 -1
  273. package/lib/queries/statistics/statistics.d.ts.map +1 -0
  274. package/lib/queries/statistics/statistics.js +17 -0
  275. package/lib/queries/subscriptions/subscriptions.d.ts +2 -0
  276. package/lib/queries/subscriptions/subscriptions.d.ts.map +1 -0
  277. package/lib/queries/subscriptions/subscriptions.js +48 -0
  278. package/lib/queries/{tags.d.ts → tags/tags.d.ts} +1 -1
  279. package/lib/queries/tags/tags.d.ts.map +1 -0
  280. package/lib/queries/tags/tags.js +55 -0
  281. package/lib/queries/users/users.d.ts.map +1 -0
  282. package/lib/queries/users/users.js +56 -0
  283. package/lib/queries/videos/videos.d.ts +2 -0
  284. package/lib/queries/videos/videos.d.ts.map +1 -0
  285. package/lib/queries/videos/videos.js +58 -0
  286. package/lib/templates/email/welcome.d.ts +1 -1
  287. package/lib/templates/email/welcome.js +2 -2
  288. package/lib/templates/sms/welcome.d.ts +1 -1
  289. package/lib/templates/sms/welcome.js +2 -2
  290. package/lib/types/arangodb.types.d.ts +42 -1
  291. package/lib/types/arangodb.types.d.ts.map +1 -1
  292. package/lib/types/arangodb.types.js +1 -1
  293. package/lib/types/connections.types.d.ts +7 -0
  294. package/lib/types/connections.types.d.ts.map +1 -1
  295. package/lib/types/connections.types.js +5 -2
  296. package/lib/types/conversations.types.d.ts +1 -0
  297. package/lib/types/conversations.types.d.ts.map +1 -1
  298. package/lib/types/conversations.types.js +1 -1
  299. package/lib/types/images.types.d.ts +11 -1
  300. package/lib/types/images.types.d.ts.map +1 -1
  301. package/lib/types/images.types.js +1 -1
  302. package/lib/types/index.d.ts +1 -1
  303. package/lib/types/index.js +2 -2
  304. package/lib/types/locations.types.d.ts +1 -0
  305. package/lib/types/locations.types.d.ts.map +1 -1
  306. package/lib/types/locations.types.js +1 -1
  307. package/lib/types/messages.types.d.ts +4 -1
  308. package/lib/types/messages.types.d.ts.map +1 -1
  309. package/lib/types/messages.types.js +1 -1
  310. package/lib/types/payments.types.d.ts +6 -0
  311. package/lib/types/payments.types.d.ts.map +1 -1
  312. package/lib/types/payments.types.js +1 -1
  313. package/lib/types/personas.types.d.ts +33 -0
  314. package/lib/types/personas.types.d.ts.map +1 -0
  315. package/lib/types/personas.types.js +3 -0
  316. package/lib/types/posts.types.d.ts +5 -1
  317. package/lib/types/posts.types.d.ts.map +1 -1
  318. package/lib/types/posts.types.js +1 -1
  319. package/lib/types/users.types.d.ts +24 -12
  320. package/lib/types/users.types.d.ts.map +1 -1
  321. package/lib/types/users.types.js +1 -1
  322. package/lib/types/videos.types.d.ts +38 -0
  323. package/lib/types/videos.types.d.ts.map +1 -1
  324. package/lib/types/videos.types.js +1 -1
  325. package/lib/types/websockets.types.d.ts +21 -0
  326. package/lib/types/websockets.types.d.ts.map +1 -1
  327. package/lib/types/websockets.types.js +1 -1
  328. package/lib/upload.d.ts +12 -0
  329. package/lib/upload.d.ts.map +1 -0
  330. package/lib/upload.js +177 -0
  331. package/lib/utils/aqlHelpers.d.ts +56 -0
  332. package/lib/utils/aqlHelpers.d.ts.map +1 -0
  333. package/lib/utils/aqlHelpers.js +205 -0
  334. package/lib/utils/arangodbUtils.js +2 -2
  335. package/lib/utils/authUtils.d.ts +1 -1
  336. package/lib/utils/authUtils.d.ts.map +1 -1
  337. package/lib/utils/authUtils.js +8 -4
  338. package/lib/utils/awsUtils.d.ts +6 -0
  339. package/lib/utils/awsUtils.d.ts.map +1 -0
  340. package/lib/utils/awsUtils.js +23 -0
  341. package/lib/utils/collectionRegistry.d.ts +58 -0
  342. package/lib/utils/collectionRegistry.d.ts.map +1 -0
  343. package/lib/utils/collectionRegistry.js +160 -0
  344. package/lib/utils/dbI18n.example.js +4 -4
  345. package/lib/utils/index.d.ts +1 -0
  346. package/lib/utils/index.d.ts.map +1 -1
  347. package/lib/utils/index.js +2 -1
  348. package/lib/utils/queryBuilder.d.ts +31 -0
  349. package/lib/utils/queryBuilder.d.ts.map +1 -0
  350. package/lib/utils/queryBuilder.js +245 -0
  351. package/lib/utils/schemaUtils.d.ts +6 -0
  352. package/lib/utils/schemaUtils.d.ts.map +1 -0
  353. package/lib/utils/schemaUtils.js +96 -0
  354. package/lib/utils/sessionUtils.d.ts +8 -1
  355. package/lib/utils/sessionUtils.d.ts.map +1 -1
  356. package/lib/utils/sessionUtils.js +4 -2
  357. package/lib/utils/stripeUtils.d.ts +1 -1
  358. package/lib/utils/stripeUtils.js +2 -2
  359. package/lib/utils/testUtils.d.ts +3 -7
  360. package/lib/utils/testUtils.d.ts.map +1 -1
  361. package/lib/utils/testUtils.js +10 -2
  362. package/lib/utils/translationQueue.example.js +4 -4
  363. package/lib/videoProcessing.d.ts +29 -0
  364. package/lib/videoProcessing.d.ts.map +1 -0
  365. package/lib/videoProcessing.js +66 -0
  366. package/package.json +69 -42
  367. package/lib/actions/profiles.d.ts +0 -5
  368. package/lib/actions/profiles.d.ts.map +0 -1
  369. package/lib/actions/profiles.js +0 -58
  370. package/lib/mutations/content.d.ts.map +0 -1
  371. package/lib/mutations/content.js +0 -27
  372. package/lib/mutations/locations.d.ts.map +0 -1
  373. package/lib/mutations/locations.js +0 -22
  374. package/lib/mutations/messages.d.ts +0 -3
  375. package/lib/mutations/messages.d.ts.map +0 -1
  376. package/lib/mutations/messages.js +0 -75
  377. package/lib/mutations/posts.d.ts.map +0 -1
  378. package/lib/mutations/posts.js +0 -31
  379. package/lib/mutations/profiles.d.ts +0 -3
  380. package/lib/mutations/profiles.d.ts.map +0 -1
  381. package/lib/mutations/profiles.js +0 -78
  382. package/lib/mutations/reactions.d.ts +0 -3
  383. package/lib/mutations/reactions.d.ts.map +0 -1
  384. package/lib/mutations/reactions.js +0 -29
  385. package/lib/mutations/statistics.d.ts.map +0 -1
  386. package/lib/mutations/statistics.js +0 -17
  387. package/lib/mutations/subscriptions.d.ts.map +0 -1
  388. package/lib/mutations/subscriptions.js +0 -38
  389. package/lib/mutations/tags.d.ts +0 -3
  390. package/lib/mutations/tags.d.ts.map +0 -1
  391. package/lib/mutations/tags.js +0 -109
  392. package/lib/mutations/users.d.ts.map +0 -1
  393. package/lib/mutations/users.js +0 -129
  394. package/lib/objectTypes/profile.d.ts +0 -4
  395. package/lib/objectTypes/profile.d.ts.map +0 -1
  396. package/lib/objectTypes/profile.js +0 -68
  397. package/lib/queries/content.d.ts.map +0 -1
  398. package/lib/queries/content.js +0 -50
  399. package/lib/queries/locations.d.ts.map +0 -1
  400. package/lib/queries/locations.js +0 -23
  401. package/lib/queries/messages.d.ts +0 -3
  402. package/lib/queries/messages.d.ts.map +0 -1
  403. package/lib/queries/messages.js +0 -35
  404. package/lib/queries/posts.d.ts.map +0 -1
  405. package/lib/queries/posts.js +0 -154
  406. package/lib/queries/reactions.d.ts +0 -3
  407. package/lib/queries/reactions.d.ts.map +0 -1
  408. package/lib/queries/reactions.js +0 -34
  409. package/lib/queries/statistics.d.ts.map +0 -1
  410. package/lib/queries/statistics.js +0 -17
  411. package/lib/queries/subscriptions.d.ts +0 -3
  412. package/lib/queries/subscriptions.d.ts.map +0 -1
  413. package/lib/queries/subscriptions.js +0 -21
  414. package/lib/queries/tags.d.ts.map +0 -1
  415. package/lib/queries/tags.js +0 -56
  416. package/lib/queries/users.d.ts.map +0 -1
  417. package/lib/queries/users.js +0 -39
  418. package/lib/types/profiles.types.d.ts +0 -21
  419. package/lib/types/profiles.types.d.ts.map +0 -1
  420. package/lib/types/profiles.types.js +0 -3
  421. /package/lib/mutations/{users.d.ts → users/users.d.ts} +0 -0
  422. /package/lib/queries/{users.d.ts → users/users.d.ts} +0 -0
package/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  Reaktor
2
2
  =======
3
3
 
4
- A simple skeleton to start you off on your ReactJS project. Uses a Flux framework and Falcor for data.
4
+ A powerful GraphQL API framework built with TypeScript, ArangoDB, and AWS Lambda. Reaktor provides a complete backend solution for social platforms with user management, posts, messaging, reactions, and more.
5
+
6
+ ## Features
7
+
8
+ - **GraphQL API** - Built with graphql-compose for type-safe schema composition
9
+ - **ArangoDB** - High-performance multi-model database with graph capabilities
10
+ - **TypeScript** - Full type safety throughout the codebase
11
+ - **Modular Architecture** - Clean separation of concerns with actions, adapters, and utilities
12
+ - **Zod Validation** - Runtime type checking and data validation
13
+ - **JWT Authentication** - Secure session management
14
+ - **AWS Lambda Ready** - Serverless deployment support
15
+ - **Comprehensive Testing** - Jest-based testing with utilities
16
+ - **Internationalization** - Database-driven i18n system
5
17
 
6
18
  Peer Dependencies
7
19
  ----------------
@@ -20,10 +32,92 @@ Getting Started
20
32
 
21
33
  ```shell
22
34
  $ npm install # Install Node modules listed in ./package.json (may take a while the first time)
23
- $ npm install -g nodemon # Install Nodemon
24
- $ gulp # Compile and launch
35
+ $ npm run build # Compile TypeScript
36
+ $ npm test # Run tests
37
+ ```
38
+
39
+ For detailed setup instructions, see [Development Guide](./docs/DEVELOPMENT.md).
40
+
41
+ ## Architecture
42
+
43
+ Reaktor follows a clean, layered architecture designed for maintainability and scalability:
44
+
45
+ ### New Modular Structure
46
+
47
+ The codebase has been refactored to follow modern patterns:
48
+
49
+ - **Shared Utilities**: Common functionality extracted into reusable utility functions
50
+ - **Single-Responsibility Functions**: Actions are broken down into focused, composable functions
51
+ - **Type Safety**: Comprehensive TypeScript types and Zod validation throughout
52
+ - **Consistent Error Handling**: Standardized error logging and exception handling
53
+ - **Constants Over Magic Strings**: Centralized constants for collections, edges, and enums
54
+
55
+ ### Query Builder System
56
+
57
+ Reaktor provides a flexible query system built on ArangoDB's AQL:
58
+
59
+ - **Composable Queries**: Build complex queries from simple building blocks
60
+ - **Type-Safe Parameters**: All queries use parameterization to prevent injection attacks
61
+ - **Flexible Filtering**: Filter by any field including custom properties
62
+ - **Advanced Operators**: Support for comparison, string, and array operators
63
+ - **Nested Conditions**: Complex AND/OR logic for sophisticated queries
64
+
65
+ See [Query System Documentation](./docs/QUERY_SYSTEM.md) for detailed examples.
66
+
67
+ ### Refactored Action Pattern
68
+
69
+ Actions now follow a consistent, maintainable pattern:
70
+
71
+ ```typescript
72
+ export const addPost = async (context: ApiContext, input: PostInputType): Promise<PostType> => {
73
+ // Validate and parse input
74
+ const parsedPost = parseAndPreparePost(input, context.session.userId);
75
+
76
+ // Perform database operation
77
+ const savedPost = await insertPost(context, parsedPost);
78
+
79
+ // Handle related operations
80
+ return await handleTagsForPost(context, savedPost, input.tags);
81
+ };
25
82
  ```
26
83
 
84
+ **Benefits**:
85
+ - Easier to test and maintain
86
+ - Clear separation of concerns
87
+ - Reusable helper functions
88
+ - Consistent error handling
89
+
90
+ ### Layer Architecture
91
+
92
+ ```
93
+ ┌─────────────────────────────────────────────────────────────┐
94
+ │ GraphQL Layer │
95
+ │ (queries/, mutations/, objectTypes/) │
96
+ └────────────────┬────────────────────────────────────────────┘
97
+ │
98
+ ┌────────────────▼────────────────────────────────────────────┐
99
+ │ Actions Layer │
100
+ │ (actions/) - Domain-specific business logic │
101
+ └────────────────┬────────────────────────────────────────────┘
102
+ │
103
+ ┌────────────────▼────────────────────────────────────────────┐
104
+ │ Adapters Layer │
105
+ │ (adapters/) - Data transformation & validation │
106
+ └────────────────┬────────────────────────────────────────────┘
107
+ │
108
+ ┌────────────────▼────────────────────────────────────────────┐
109
+ │ Utilities Layer │
110
+ │ (utils/) - Shared helpers & database utilities │
111
+ └────────────────┬────────────────────────────────────────────┘
112
+ │
113
+ ┌────────────────▼────────────────────────────────────────────┐
114
+ │ ArangoDB Database │
115
+ │ Collections & Edges - Document and graph storage │
116
+ └─────────────────────────────────────────────────────────────┘
117
+ ```
118
+
119
+ For comprehensive architecture documentation, see [Architecture Guide](./docs/ARCHITECTURE.md).
120
+
27
121
  Usage
28
122
  -----
29
123
 
@@ -50,171 +144,1263 @@ Get a copy of the latest database data from the production database and save to
50
144
 
51
145
  ### Configuration
52
146
 
53
- Basic project configuration can be found in `~/src/config.js`. Here you'll be able to redefine your src and dist directories, as well as tweak what ports Webpack and WebpackDevServer run on.
147
+ Basic project configuration can be found in `~/src/config.ts`. The configuration system supports environment-based settings and can be customized via environment variables.
148
+
149
+ #### Required Environment Variables
150
+
151
+ - `SESSION_SECRET` - **Required** - Secret key used for JWT token signing and verification. This must be set for authentication to work.
152
+
153
+ **Example:**
154
+ ```bash
155
+ export SESSION_SECRET="your-secret-key-here"
156
+ ```
157
+
158
+ #### ArangoDB Configuration
159
+
160
+ The ArangoDB connection can be configured using the following environment variables:
161
+
162
+ - `ARANGODB_URL` - The ArangoDB server URL (default: `http://localhost`)
163
+ - `ARANGODB_PORT` - The ArangoDB server port (default: `8529`)
164
+ - `ARANGODB_DATABASE` - The database name (default: `reaktor`)
165
+ - `ARANGODB_USERNAME` - The database username (default: `root`)
166
+ - `ARANGODB_PASSWORD` - The database password (default: `password`)
167
+
168
+ **Example:**
169
+ ```bash
170
+ export SESSION_SECRET="your-secret-key-here"
171
+ export ARANGODB_URL="http://my-arango-server"
172
+ export ARANGODB_PORT="8530"
173
+ export ARANGODB_DATABASE="my-database"
174
+ export ARANGODB_USERNAME="myuser"
175
+ export ARANGODB_PASSWORD="mypassword"
176
+ ```
177
+
178
+ The configuration is environment-aware and supports `local`, `development`, `test`, and `production` environments. The active environment is determined by the `NODE_ENV` or `stage` environment variable.
179
+
180
+ #### Programmatic Configuration
181
+
182
+ You can also override configuration programmatically using the `Config.set()` method:
183
+
184
+ ```typescript
185
+ import {Config} from '@nlabs/reaktor';
186
+
187
+ Config.set({
188
+ arangodb: {
189
+ url: 'http://custom-server',
190
+ port: '8530',
191
+ database: 'custom-db'
192
+ }
193
+ }, 'development');
194
+ ```
54
195
 
55
196
  Structure
56
197
  ---------
57
198
 
58
- The folder structure provided is only meant to serve as a guide, it is by no means prescriptive. It is something that has worked very well for me and my team, but use only what makes sense to you.
199
+ Reaktor follows a modular, domain-driven structure optimized for GraphQL API development:
59
200
 
60
201
  ```
61
- .
62
- ├── bin # Build/Start scripts
63
- ├── build # All build-related configuration
64
- │ ├── webpack # Environment-specific configuration files for Webpack
65
- | ├── config.js # Project configuration settings
66
- | ├── karma.js # Karma configuration settings
67
- └── src # Application source code
68
- ├── components # React Components
69
- ├── containers # Components that provide context (e.g. Redux Providers)
70
- ├── layouts # Components that dictate major page structure
71
- ├── reducers # Redux reducers
72
- ├── routes # Application route definitions
73
- ├── stores # Redux store configuration
74
- ├── utils # Utilities
75
- ├── views # Components that live at a route
76
- └── index.js # Application bootstrap and rendering
202
+ └── src
203
+ ├── actions/ # Business logic for each domain (refactored & modular)
204
+ │ ├── users.ts # User management actions
205
+ │ ├── posts.ts # Post management actions
206
+ │ ├── groups.ts # Group management actions
207
+ │ ├── reactions.ts # Reaction handling
208
+ │ └── ... # Other domain actions
209
+ ├── adapters/ # Data transformation and parsing with Zod
210
+ │ ├── userAdapter.ts # User data validation
211
+ │ ├── postAdapter.ts # Post data validation
212
+ │ └── ... # Other adapters
213
+ ├── handlers/ # Request handlers
214
+ │ └── graphqlHandler.ts # GraphQL request processing
215
+ ├── mutations/ # GraphQL mutations
216
+ │ ├── users.ts # User mutations
217
+ │ ├── posts.ts # Post mutations
218
+ │ └── ... # Other mutations
219
+ ├── objectTypes/ # GraphQL type definitions
220
+ │ ├── user.ts # User type schema
221
+ │ ├── post.ts # Post type schema
222
+ │ └── ... # Other type definitions
223
+ ├── queries/ # GraphQL query resolvers
224
+ │ ├── users/ # User queries
225
+ │ ├── posts/ # Post queries
226
+ │ └── ... # Other queries
227
+ ├── types/ # TypeScript type definitions
228
+ │ ├── users.types.ts # User interfaces
229
+ │ ├── posts.types.ts # Post interfaces
230
+ │ └── ... # Other type definitions
231
+ ├── utils/ # Shared utilities (EXPANDED)
232
+ │ ├── arangodbUtils.ts # Database connection & helpers
233
+ │ ├── sessionUtils.ts # JWT authentication
234
+ │ ├── analyticsUtils.ts # Error logging & monitoring
235
+ │ ├── schemaUtils.ts # GraphQL schema utilities
236
+ │ ├── testUtils.ts # Testing helpers
237
+ │ └── ... # Other utilities
238
+ ├── config.ts # Environment configuration
239
+ └── index.ts # Main entry point
77
240
  ```
78
241
 
79
- ### Components vs. Views vs. Layouts
242
+ ### Key Directories
80
243
 
81
- **TL;DR:** They're all components.
244
+ - **actions/**: Domain-specific business logic with single-responsibility functions
245
+ - **adapters/**: Zod-based validation and data transformation layer
246
+ - **handlers/**: Request entry points (GraphQL, Lambda)
247
+ - **mutations/**: GraphQL mutation resolvers
248
+ - **queries/**: GraphQL query resolvers organized by domain
249
+ - **objectTypes/**: GraphQL type schemas with graphql-compose
250
+ - **types/**: TypeScript interfaces and type definitions
251
+ - **utils/**: Shared utilities for database, auth, logging, etc.
82
252
 
83
- This distinction may not be important for you, but as an explanation: A **Layout** is something that describes an entire page structure, such as a fixed navigation, viewport, sidebar, and footer. Most applications will probably only have one layout, but keeping these components separate makes their intent clear. **Views** are components that live at routes, and are generally rendered within a **Layout**. What this ends up meaning is that, with this structure, nearly everything inside of **Components** ends up being a dumb component.
253
+ ## Flexible Query System
84
254
 
85
- Webpack
86
- -------
255
+ Reaktor includes a powerful, flexible query system that allows you to search and filter any collection by any property, including custom document fields.
87
256
 
88
- ### Configuration
89
- The webpack compiler configuration is located in `~/build/webpack`. When the webpack dev server runs, only the client compiler will be used. When webpack itself is run to compile to disk, both the client and server configurations will be used. Settings that are bundle agnostic should be defined in `~/src/config.js` and imported where needed.
257
+ ### Basic Query
258
+
259
+ ```typescript
260
+ // Get posts by filters
261
+ const aqlQry = aql`
262
+ FOR p IN posts
263
+ FILTER p.type == ${'event'}
264
+ FILTER p.privacy == ${'public'}
265
+ SORT p.added DESC
266
+ LIMIT 0, 20
267
+ RETURN p
268
+ `;
269
+ ```
270
+
271
+ ### Advanced Filtering
272
+
273
+ **Nested Conditions (OR/AND):**
274
+ ```typescript
275
+ const aqlQry = aql`
276
+ FOR p IN posts
277
+ FILTER p.type == 'post'
278
+ FILTER (p.userId == ${userId} OR p.privacy == 'public')
279
+ SORT p.added DESC
280
+ LIMIT 0, 20
281
+ RETURN p
282
+ `;
283
+ ```
284
+
285
+ **Custom Properties:**
286
+ ```typescript
287
+ const aqlQry = aql`
288
+ FOR p IN posts
289
+ FILTER p.customStatus == 'active'
290
+ FILTER p.customPriority > 5
291
+ RETURN p
292
+ `;
293
+ ```
294
+
295
+ **Available Operators:**
296
+ - `==` - Equal
297
+ - `!=` - Not equal
298
+ - `>` - Greater than
299
+ - `>=` - Greater than or equal
300
+ - `<` - Less than
301
+ - `<=` - Less than or equal
302
+ - `LIKE` - Pattern matching (use with wildcards)
303
+ - `CONTAINS` - String contains
304
+ - `IN` - Value in array
305
+ - `NOT IN` - Value not in array
306
+
307
+ ### Multi-Collection Search
308
+
309
+ Search across multiple collections:
310
+
311
+ ```typescript
312
+ import {searchContent} from './src/actions/search.js';
313
+
314
+ const searchResults = await searchContent(context, {
315
+ query: 'nodejs conference',
316
+ collections: ['posts', 'users', 'groups'],
317
+ limit: { from: 0, to: 50 }
318
+ });
319
+ ```
320
+
321
+ ### GraphQL Query
322
+
323
+ ```graphql
324
+ query {
325
+ posts(
326
+ type: "event"
327
+ privacy: "public"
328
+ from: 0
329
+ to: 20
330
+ sort: "added"
331
+ direction: "DESC"
332
+ ) {
333
+ _key
334
+ content
335
+ type
336
+ privacy
337
+ added
338
+ user {
339
+ name
340
+ avatar
341
+ }
342
+ }
343
+ }
344
+ ```
345
+
346
+ For complete query system documentation, see [Query System Guide](./docs/QUERY_SYSTEM.md).
347
+
348
+ ## Architecture Patterns
349
+
350
+ ### Shared AQL Helpers
351
+
352
+ Common AQL query patterns are implemented as reusable functions in action files:
90
353
 
91
- ### Vendor Bundle
92
- You can redefine which packages to treat as vendor dependencies by editing `vendor_dependencies` in `~/config/index.js`. These default to:
354
+ ```typescript
355
+ // Example: Building distance queries
356
+ const buildDistanceQuery = (lat: number, lng: number): string =>
357
+ `LET distance = DISTANCE(
358
+ ${lat},
359
+ ${lng},
360
+ NOT_NULL(p.latitude, 0),
361
+ NOT_NULL(p.longitude, 0))
362
+ `;
93
363
 
94
- ```js
95
- [
96
- 'arkhamjs',
97
- 'history',
98
- 'react',
99
- 'react-router',
100
- 'venomcss',
101
- ]
364
+ // Example: Building reaction count queries
365
+ const buildReactionCountQuery = (reactionName: string): string =>
366
+ `LET ${reactionName}Count = FIRST(
367
+ FOR post, r IN INBOUND p._id hasReaction
368
+ FILTER r.name == "${reactionName}"
369
+ COLLECT WITH COUNT INTO count
370
+ RETURN count
371
+ )`;
102
372
  ```
103
373
 
104
- ### Aliases
105
- As mentioned in features, the default Webpack configuration provides some globals and aliases to make your life easier. These can be used as such:
374
+ ### Error Handling
106
375
 
107
- ```js
108
- import MyComponent from '../../components/my-component'; // without alias
109
- import MyComponent from 'components/my-component'; // with alias
376
+ All actions use consistent error handling:
110
377
 
111
- // Available aliases:
112
- actions => '~/src/actions'
113
- components => '~/src/components'
114
- constants => '~/src/constants'
115
- containers => '~/src/containers'
116
- layouts => '~/src/layouts'
117
- reducers => '~/src/reducers'
118
- routes => '~/src/routes'
119
- services => '~/src/services'
120
- styles => '~/src/styles'
121
- utils => '~/src/utils'
122
- views => '~/src/views'
378
+ ```typescript
379
+ import { logError, logException } from './src/utils/analyticsUtils.js';
380
+
381
+ try {
382
+ // Database operation
383
+ const result = await performDatabaseOperation();
384
+ return result;
385
+ } catch (error) {
386
+ logError({
387
+ action: 'functionName',
388
+ category: 'domain',
389
+ label: ErrorTypes.DATABASE_ERROR
390
+ }, error, context);
391
+ throw error;
392
+ }
123
393
  ```
124
394
 
125
- ### Globals
395
+ ### Constants
396
+
397
+ Use constants instead of magic strings:
126
398
 
127
- #### `__DEV__`
128
- True when `process.env.NODE_ENV` is `development`
399
+ ```typescript
400
+ // Collection names
401
+ const COLLECTIONS = {
402
+ POSTS: 'posts',
403
+ USERS: 'users',
404
+ GROUPS: 'groups'
405
+ } as const;
129
406
 
130
- #### `__PROD__`
131
- True when `process.env.NODE_ENV` is `production`
407
+ // Edge names
408
+ const EDGES = {
409
+ HAS_REACTION: 'hasReaction',
410
+ HAS_CONNECTION: 'hasConnection',
411
+ IS_TAGGED: 'isTagged'
412
+ } as const;
132
413
 
133
- #### `__DEBUG__`
134
- True when the compiler is run with `--debug` (any environment).
414
+ // Privacy levels
415
+ export const PrivacyLevel = {
416
+ PUBLIC: 'public',
417
+ PRIVATE: 'private',
418
+ GROUP: 'group'
419
+ } as const;
420
+
421
+ // Use in queries
422
+ const aqlQry = aql`
423
+ FOR p IN ${COLLECTIONS.POSTS}
424
+ FOR r IN INBOUND p._id ${EDGES.HAS_REACTION}
425
+ FILTER r.name == 'like'
426
+ RETURN p
427
+ `;
428
+ ```
135
429
 
136
- Styles
137
- ------
430
+ ### Modular Functions
138
431
 
139
- All `.scss` imports will be run through the sass-loader, extracted during production builds, and ignored during server builds. If you're requiring styles from a base styles directory (useful for generic, app-wide styles) in your JS, you can make use of the `styles` alias, e.g.:
432
+ Functions are now single-responsibility and composable:
140
433
 
141
- ```js
142
- // ~/src/components/some/nested/component/index.jsx
143
- import `styles/core.scss`;
434
+ ```typescript
435
+ // Before: One large function
436
+ export const addPost = async (context, input) => {
437
+ // 100+ lines of mixed logic
438
+ };
439
+
440
+ // After: Composed of smaller functions
441
+ export const addPost = async (context: ApiContext, input: PostInputType): Promise<PostType> => {
442
+ const parsedPost = parseAndPreparePost(input, context.session.userId);
443
+ const savedPost = await insertPost(context, parsedPost);
444
+ return await handleTagsForPost(context, savedPost, input.tags);
445
+ };
144
446
  ```
145
447
 
146
- Furthermore, this `styles` directory is aliased for sass imports, which further eliminates manual directory traversing. An example nested `.scss` file:
448
+ ## Migration Guide
449
+
450
+ ### From Old to New Structure
147
451
 
148
- ```scss
149
- // current path: ~/src/styles/some/nested/style.scss
150
- // what used to be this:
151
- @import '../../base';
452
+ The refactoring maintains backward compatibility while introducing better patterns and utilities.
152
453
 
153
- // can now be this:
154
- @import 'base';
454
+ **Old way (manual query building):**
455
+ ```typescript
456
+ // Manual string concatenation (avoid this)
457
+ const aqlQry = `FOR p IN posts
458
+ FILTER p.type == "${type}" && p.privacy == "public"
459
+ RETURN p`;
155
460
  ```
156
461
 
462
+ **New way (parameterized queries):**
463
+ ```typescript
464
+ // Use AQL template literals for safety
465
+ import {aql} from 'arangojs';
466
+
467
+ const aqlQry = aql`
468
+ FOR p IN posts
469
+ FILTER p.type == ${type}
470
+ FILTER p.privacy == 'public'
471
+ RETURN p
472
+ `;
473
+ ```
474
+
475
+ **Using helper functions:**
476
+ ```typescript
477
+ // Leverage existing action functions
478
+ import {getPostsByLatest} from './src/actions/posts.js';
479
+
480
+ const results = await getPostsByLatest(context, {
481
+ type: type,
482
+ privacy: 'public',
483
+ from: 0,
484
+ to: 20
485
+ });
486
+ ```
487
+
488
+ ### Breaking Changes
489
+
490
+ **None!** All existing functions maintain backward compatibility. The refactoring improves internal structure without changing public APIs.
491
+
492
+ ### Best Practices
493
+
494
+ 1. **Use parameterized queries**: Always use `aql` template literals
495
+ 2. **Leverage adapters**: Parse data with Zod schemas for validation
496
+ 3. **Use constants**: Define collection/edge names as constants
497
+ 4. **Error handling**: Use `logError()` and `logException()` consistently
498
+ 5. **Type safety**: Specify TypeScript types for all functions
499
+
157
500
  Database
158
501
  -------
159
- - Install the latest MacOS [binary](https://www.arangodb.com/download/macosx/) into the Applications directory.
160
- - Create the database `reaktor`.
161
- - Run the gulp import task to import the latest data into your local database.
502
+ - Install the latest [ArangoDB binary](https://www.arangodb.com/download/) for your platform.
503
+ - Create the database `reaktor` (for development) and `reaktor-test` (for testing).
504
+ - Configure connection in `.env` file (see Configuration section above).
162
505
 
163
- ```
164
- gulp db:get:s3
506
+ **Environment setup:**
507
+ ```bash
508
+ # In .env file
509
+ ARANGODB_URL=http://localhost
510
+ ARANGODB_PORT=8529
511
+ ARANGODB_DATABASE=reaktor
512
+ ARANGODB_USERNAME=root
513
+ ARANGODB_PASSWORD=password
165
514
  ```
166
515
 
167
516
  Testing
168
517
  -------
169
518
 
170
- To add a unit test, simply create `.spec.js` file anywhere in `~/test`. All imports will be relative to the "~/src" directory. The entry point for Karma uses webpack's custom require to load all these files, and Jasmine will be available to you within your test without the need to import them.
519
+ Reaktor uses Jest for testing with comprehensive test utilities.
171
520
 
172
- Utilities
173
- ---------
521
+ ### Running Tests
522
+
523
+ ```bash
524
+ # Run all tests
525
+ npm test
526
+
527
+ # Run tests in watch mode
528
+ npm test -- --watch
529
+
530
+ # Run specific test file
531
+ npm test -- src/actions/users.test.ts
532
+ ```
533
+
534
+ ### Writing Tests
535
+
536
+ Use the provided test utilities for consistent test data:
537
+
538
+ ```typescript
539
+ import {describe, it, expect, beforeAll} from '@jest/globals';
540
+ import {createMockContext, createMockUser} from '../utils/testUtils.js';
541
+ import {addUser, getUser} from './users.js';
542
+
543
+ describe('User Actions', () => {
544
+ let context;
545
+
546
+ beforeAll(() => {
547
+ context = createMockContext();
548
+ });
549
+
550
+ it('should create and retrieve a user', async () => {
551
+ const userData = createMockUser({email: 'test@example.com'});
552
+ const created = await addUser(context, userData);
553
+
554
+ expect(created.email).toBe('test@example.com');
555
+
556
+ const retrieved = await getUser(context, created._key);
557
+ expect(retrieved?._key).toBe(created._key);
558
+ });
559
+ });
560
+ ```
561
+
562
+ See [Test Utilities Guide](./TEST_UTILITIES_GUIDE.md) for detailed documentation on test helpers.
563
+
564
+ ## Available Action Functions
565
+
566
+ All action functions have been refactored for better modularity and maintainability. Common patterns are now extracted into shared utilities.
567
+
568
+ ### Posts
569
+
570
+ ```typescript
571
+ import {
572
+ addPost,
573
+ updatePost,
574
+ deletePost,
575
+ getPost,
576
+ getPostsByLatest,
577
+ getPostsByReactions,
578
+ getPostsByTags,
579
+ getPostsByUser,
580
+ getPostsByArea
581
+ } from './src/actions/posts.js';
582
+
583
+ // Add a post
584
+ const newPost = await addPost(context, {
585
+ content: 'Hello World',
586
+ type: 'post',
587
+ privacy: 'public',
588
+ tags: [{name: 'nodejs'}]
589
+ });
590
+
591
+ // Get posts by user
592
+ const userPosts = await getPostsByUser(context, userId, {
593
+ from: 0,
594
+ to: 20
595
+ });
174
596
 
175
- This boilerplate comes with two simple utilities (thanks to [StevenLangbroek](https://github.com/StevenLangbroek)) to help speed up your Redux development process. In `~/client/utils` you'll find exports for `createConstants` and `createReducer`. The former is pretty much an even lazier `keyMirror`, so if you _really_ hate typing out those constants you may want to give it a shot. Check it out:
597
+ // Get posts by location
598
+ const nearbyPosts = await getPostsByArea(context, {
599
+ latitude: 37.7749,
600
+ longitude: -122.4194,
601
+ radius: 50, // km
602
+ from: 0,
603
+ to: 20
604
+ });
605
+ ```
606
+
607
+ ### Reactions
608
+
609
+ ```typescript
610
+ import {
611
+ addReaction,
612
+ deleteReaction,
613
+ getReactionCount,
614
+ getReactionsByItem,
615
+ hasReaction
616
+ } from './src/actions/reactions.js';
617
+
618
+ // Add a reaction
619
+ await addReaction(context, 'posts/123', {
620
+ name: 'like',
621
+ value: '1'
622
+ });
623
+
624
+ // Get reaction counts
625
+ const counts = await getReactionCount(context, 'posts/123', {
626
+ reactionName: 'like'
627
+ });
628
+
629
+ // Check if user has reacted
630
+ const liked = await hasReaction(context, 'posts/123', 'like');
631
+ ```
632
+
633
+ ### Users
634
+
635
+ ```typescript
636
+ import {
637
+ getUser,
638
+ getUserList,
639
+ addUser,
640
+ updateUser,
641
+ signIn,
642
+ signOut,
643
+ getUsersByLatest,
644
+ getUsersByTags,
645
+ getSessionUser
646
+ } from './src/actions/users.js';
647
+
648
+ // Get users with filters
649
+ const users = await getUserList(context, {
650
+ from: 0,
651
+ to: 20
652
+ });
653
+
654
+ // Sign in
655
+ const authResult = await signIn(context, {
656
+ email: 'user@example.com',
657
+ password: 'password123'
658
+ });
659
+
660
+ // Get current user from session
661
+ const currentUser = await getSessionUser(context, authToken);
662
+ ```
176
663
 
177
- ```js
178
- import { createConstants } from 'utils';
664
+ ### Groups
179
665
 
180
- export default createConstants(
181
- 'TODO_CREATE',
182
- 'TODO_DESTROY',
183
- 'TODO_TOGGLE_COMPLETE'
184
- );
666
+ ```typescript
667
+ import {
668
+ getGroupList,
669
+ getGroupListByUser,
670
+ getGroupListByTags,
671
+ getGroupById,
672
+ addGroup,
673
+ updateGroup,
674
+ deleteGroup
675
+ } from './src/actions/groups.js';
676
+
677
+ // Get groups
678
+ const groups = await getGroupList(context, {
679
+ from: 0,
680
+ to: 20
681
+ });
682
+
683
+ // Get user's groups
684
+ const userGroups = await getGroupListByUser(context, userId, {
685
+ from: 0,
686
+ to: 20
687
+ });
688
+ ```
689
+
690
+ ### Tags
691
+
692
+ ```typescript
693
+ import {
694
+ getTags,
695
+ getTagsByItem,
696
+ addTag,
697
+ addTagToItem,
698
+ updateTag,
699
+ deleteTag,
700
+ extractTags
701
+ } from './src/actions/tags.js';
702
+
703
+ // Add tags to an item
704
+ await addTagToItem(context, 'posts/123', [
705
+ {name: 'nodejs'},
706
+ {name: 'javascript'}
707
+ ]);
708
+
709
+ // Extract tags from text
710
+ const extractedTags = await extractTags(context, 'Learning #nodejs and #graphql');
185
711
  ```
186
712
 
187
- The other utility, `create-reducer`, is designed to expedite creating reducers when they're defined via an object map rather than switch statements. As an example, what once looked like this:
713
+ ### Messages & Conversations
714
+
715
+ ```typescript
716
+ import {
717
+ getConversations,
718
+ getConversation,
719
+ addDirectConversation,
720
+ addUserToConversation
721
+ } from './src/actions/conversations.js';
722
+
723
+ // Get user's conversations
724
+ const conversations = await getConversations(context, {
725
+ from: 0,
726
+ to: 20
727
+ });
728
+
729
+ // Start a direct conversation
730
+ const conversation = await addDirectConversation(context, {
731
+ userId: otherUserId,
732
+ content: 'Hello!'
733
+ });
734
+ ```
735
+
736
+ *See individual action files in `src/actions/` for complete API documentation and available options.*
737
+
738
+ GraphQL Schema Utilities
739
+ ------------------------
740
+
741
+ The `src/utils/schemaUtils.ts` file provides utilities for working with GraphQL schemas programmatically. These utilities help generate custom GraphQL schema definitions from existing Reaktor types.
188
742
 
189
- ```js
190
- import { TODO_CREATE } from 'constants/todo';
743
+ ### `composeSchemaFromTypes(types: any[]): string`
191
744
 
192
- const initialState = [];
193
- const handlers = {
194
- [TODO_CREATE] : (state, payload) => { ... }
745
+ Composes a GraphQL schema string from an array of GraphQL types that support the `toSDL()` method.
746
+
747
+ **Parameters:**
748
+ - `types` - Array of GraphQL types with `toSDL()` method
749
+
750
+ **Returns:** A string containing the concatenated GraphQL schema definitions
751
+
752
+ **Example:**
753
+ ```typescript
754
+ import {composeSchemaFromTypes} from 'utils/schemaUtils';
755
+ import {UserType, PostType} from './types';
756
+
757
+ const schema = composeSchemaFromTypes([UserType, PostType]);
758
+ console.log(schema);
759
+ // Output: "type User { ... }\ntype Post { ... }"
760
+ ```
761
+
762
+ ### `getReaktorMutationFields(fieldNames: string[]): string`
763
+
764
+ Extracts and formats GraphQL mutation field definitions from the Reaktor user mutations schema.
765
+
766
+ **Parameters:**
767
+ - `fieldNames` - Array of mutation field names to extract
768
+
769
+ **Returns:** A formatted string containing the GraphQL field definitions with arguments and return types
770
+
771
+ **Example:**
772
+ ```typescript
773
+ import {getReaktorMutationFields} from 'utils/schemaUtils';
774
+
775
+ const fields = getReaktorMutationFields(['signIn', 'signUp']);
776
+ console.log(fields);
777
+ // Output:
778
+ // signIn(email: String!, password: String!): AuthResponse
779
+ // signUp(email: String!, password: String!, username: String): User
780
+ ```
781
+
782
+ ### `getReaktorQueryFields(fieldNames: string[]): string`
783
+
784
+ Extracts and formats GraphQL query field definitions from the Reaktor user queries schema.
785
+
786
+ **Parameters:**
787
+ - `fieldNames` - Array of query field names to extract
788
+
789
+ **Returns:** A formatted string containing the GraphQL field definitions with arguments and return types
790
+
791
+ **Example:**
792
+ ```typescript
793
+ import {getReaktorQueryFields} from 'utils/schemaUtils';
794
+
795
+ const fields = getReaktorQueryFields(['getUser', 'listPosts']);
796
+ console.log(fields);
797
+ // Output:
798
+ // getUser(id: ID!): User
799
+ // listPosts(limit: Int, offset: Int): [Post]
800
+ ```
801
+
802
+ ### `buildCustomMutations(fieldNames: string[]): string`
803
+
804
+ Builds a complete GraphQL Mutation type definition from selected Reaktor mutation fields.
805
+
806
+ **Parameters:**
807
+ - `fieldNames` - Array of mutation field names to include in the type
808
+
809
+ **Returns:** A complete GraphQL Mutation type definition as a string
810
+
811
+ **Example:**
812
+ ```typescript
813
+ import {buildCustomMutations} from 'utils/schemaUtils';
814
+
815
+ const mutationType = buildCustomMutations(['signIn', 'signUp']);
816
+ console.log(mutationType);
817
+ // Output:
818
+ // type Mutation {
819
+ // signIn(email: String!, password: String!): AuthResponse
820
+ // signUp(email: String!, password: String!, username: String): User
821
+ // }
822
+ ```
823
+
824
+ ### `buildCustomQueries(fieldNames: string[]): string`
825
+
826
+ Builds a complete GraphQL Query type definition from selected Reaktor query fields.
827
+
828
+ **Parameters:**
829
+ - `fieldNames` - Array of query field names to include in the type
830
+
831
+ **Returns:** A complete GraphQL Query type definition as a string
832
+
833
+ **Example:**
834
+ ```typescript
835
+ import {buildCustomQueries} from 'utils/schemaUtils';
836
+
837
+ const queryType = buildCustomQueries(['getUser', 'listPosts']);
838
+ console.log(queryType);
839
+ // Output:
840
+ // type Query {
841
+ // getUser(id: ID!): User
842
+ // listPosts(limit: Int, offset: Int): [Post]
843
+ // }
844
+ ```
845
+
846
+ These utilities are particularly useful when you need to generate custom GraphQL schemas programmatically, such as for API documentation, schema stitching, or creating federated GraphQL services.
847
+
848
+ ## GraphQL Handler Usage
849
+
850
+ ### Using `createGraphqlHandler`
851
+
852
+ The `createGraphqlHandler` function is the main entry point for handling GraphQL requests in Reaktor. It builds the GraphQL context, applies middleware, and executes queries/mutations using your composed schema.
853
+
854
+ Source of truth:
855
+ - Implementation: [`src/handlers/graphqlHandler.ts`](./src/handlers/graphqlHandler.ts)
856
+ - Architecture notes: [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)
857
+
858
+ #### Example Usage
859
+
860
+ ```typescript
861
+ import {createGraphqlHandler} from './src/handlers/graphqlHandler.js';
862
+
863
+ // Create a handler instance with default Reaktor schema
864
+ const handler = createGraphqlHandler({
865
+ context: {}
866
+ });
867
+
868
+ // Use in an AWS Lambda or Express route
869
+ export const lambdaHandler = async (event) => {
870
+ return await handler(event);
195
871
  };
872
+ ```
873
+
874
+ #### Custom Composer / Extensions
875
+
876
+ ```typescript
877
+ import {SchemaComposer} from 'graphql-compose';
878
+ import {createGraphqlHandler} from './src/handlers/graphqlHandler.js';
879
+
880
+ const appComposer = new SchemaComposer();
881
+
882
+ const handler = createGraphqlHandler({
883
+ composer: appComposer,
884
+ context: {},
885
+ extraQueries: {
886
+ appHealth: {
887
+ type: 'Boolean!',
888
+ resolve: () => true
889
+ }
890
+ },
891
+ extraMutations: {},
892
+ middleware: []
893
+ });
894
+ ```
895
+
896
+ #### How Context Works
897
+ - The handler builds a context object for each request, including config, session, and request data.
898
+ - This context is passed to all resolvers as the third argument.
899
+ - You can customize context by passing initial values with `createGraphqlHandler({context})`.
900
+
901
+ #### Typical Integration
902
+ - For AWS Lambda: export the handler and wire it to API Gateway events.
903
+ - For Express: call the handler with the request event object.
904
+
905
+ See [`src/handlers/graphqlHandler.ts`](./src/handlers/graphqlHandler.ts) for implementation details.
906
+
907
+ ## Available Action Functions
908
+
909
+ Below is a list of available functions for each main action group. These can be used in resolvers, business logic, or for direct API calls.
910
+
911
+ ### Users
912
+ - createToken
913
+ - getUserOptional
914
+ - parseUserOptions
915
+ - addUser
916
+ - updateUser
917
+ - forgotPassword
918
+ - resetPassword
919
+ - confirmCode
920
+ - deleteUser
921
+ - deactivateUser
922
+ - getDisplayName
923
+ - getSessionUser
924
+ - getUser
925
+ - getUsers
926
+ - getUsersByReactions
927
+ - getUsersByTags
928
+ - getUsersByLatest
929
+ - getUsersByConnection
930
+ - refreshSession
931
+ - signIn
932
+ - signOut
933
+ - getActiveUserCount
934
+ - getUserByToken
935
+
936
+ ### Groups
937
+ - getGroupList
938
+ - getGroupListByUser
939
+ - getGroupListByTags
940
+ - getGroupById
941
+ - getGroupDetails
942
+ - createGroupEdge
943
+ - addGroup
944
+ - updateGroup
945
+ - deleteGroup
946
+ - getGroupsByReaction
947
+ - isGrouped
948
+
949
+ ### Posts
950
+ - parsePostOptions
951
+ - getPostOptional
952
+ - getPost
953
+ - getPostsByArea
954
+ - getPostsByLatest
955
+ - getPostsByReactions
956
+ - getPostsByTags
957
+ - getPostsByUser
958
+ - getPostComments
959
+ - addPost
960
+ - updatePost
961
+ - deletePost
962
+ - createPostEdge
963
+
964
+ ### Tags
965
+ - getTags
966
+ - getTagsByItem
967
+ - getTag
968
+ - getTagsByName
969
+ - addTag
970
+ - addTagToItem
971
+ - updateTag
972
+ - deleteTag
973
+ - deleteTagFromEdge
974
+ - deleteTagFromItem
975
+ - extractTags
976
+ - updateTagsInItem
977
+
978
+ ### Conversations
979
+ - parseConversationOptions
980
+ - getConversations
981
+ - getDirectConversation
982
+ - addDirectConversation
983
+ - getConnectionUsers
984
+ - getConversationUsers
985
+ - getConversation
986
+ - updateConversation
987
+ - addUserToConversation
988
+ - deleteUserFromConversation
989
+
990
+ ### Reactions
991
+ - parseReactionOptions
992
+ - addReaction
993
+ - deleteReaction
994
+ - deleteReactionByItem
995
+ - updateReaction
996
+ - getReactionCount
997
+ - getReactionCountByUser
998
+ - getGroupUsersByReaction
999
+ - getReactionsByItem
1000
+ - getItemsByReaction
1001
+ - hasReaction
1002
+
1003
+ ### Notifications
1004
+ - getApnProvider
1005
+ - pushNotification
1006
+ - clearBadges
1007
+
1008
+ ### Images
1009
+ - parseImageOptions
1010
+ - getImageOptional
1011
+ - getImagesByUser
1012
+ - getImageCountByItem
1013
+ - getImagesByItem
1014
+ - getImagesByGroup
1015
+ - getImagesByReactions
1016
+ - getImage
1017
+ - getPathUserImages
1018
+ - getAppImageUrl
1019
+ - getImageUrl
1020
+ - resizeSaveImage
1021
+ - addImage
1022
+ - addImageEdge
1023
+ - updateImage
1024
+ - deleteImage
1025
+
1026
+ ## Flexible Query System
1027
+
1028
+ Reaktor provides a comprehensive, flexible search and filtering system that allows querying any collection by any property, including custom document properties. This system is built with security, performance, and type safety in mind.
1029
+
1030
+ ### Overview
1031
+
1032
+ The flexible query system consists of:
1033
+ - **Query Builder** (`src/utils/queryBuilder.ts`) - Type-safe query construction
1034
+ - **AQL Helpers** (`src/utils/aqlHelpers.ts`) - Secure AQL generation utilities
1035
+ - **Query Actions** (`src/actions/query.ts`) - Business logic for executing queries
1036
+ - **GraphQL Resolvers** (`src/queries/query/query.ts`) - GraphQL API endpoints
1037
+
1038
+ ### Features
1039
+
1040
+ - ✅ Dynamic filter construction for any collection
1041
+ - ✅ Multiple comparison operators: `==`, `!=`, `>`, `>=`, `<`, `<=`, `LIKE`, `IN`, `NOT IN`, `CONTAINS`
1042
+ - ✅ Nested AND/OR conditions
1043
+ - ✅ Custom property filtering (for documents with dynamic fields)
1044
+ - ✅ Full-text search across multiple collections
1045
+ - ✅ Sorting and pagination
1046
+ - ✅ Type-safe filter definitions
1047
+ - ✅ AQL injection prevention
1048
+ - ✅ Aggregation operations (COUNT, SUM, AVG, MIN, MAX)
1049
+
1050
+ ### Basic Query Example
1051
+
1052
+ ```typescript
1053
+ import {executeQuery} from '@nlabs/reaktor';
1054
+
1055
+ // Find all active posts from the last 24 hours
1056
+ const results = await executeQuery(context, {
1057
+ collection: 'posts',
1058
+ filters: {
1059
+ logic: 'AND',
1060
+ conditions: [
1061
+ { field: 'status', operator: '==', value: 'active' },
1062
+ { field: 'added', operator: '>', value: Date.now() - 86400000 }
1063
+ ]
1064
+ },
1065
+ sort: [{ field: 'added', direction: 'DESC' }],
1066
+ limit: { from: 0, to: 20 }
1067
+ });
1068
+ ```
196
1069
 
197
- export default function todo (state = initialState, action) {
198
- const handler = handlers[action.type];
1070
+ ### GraphQL Query Example
199
1071
 
200
- return handler ? handler(state, action.payload) : state;
1072
+ ```graphql
1073
+ query {
1074
+ query {
1075
+ query(options: {
1076
+ collection: "posts",
1077
+ filters: {
1078
+ logic: "AND",
1079
+ conditions: [
1080
+ { field: "status", operator: "==", value: "published" },
1081
+ { field: "type", operator: "IN", value: ["article", "blog"] }
1082
+ ]
1083
+ },
1084
+ sort: [{ field: "added", direction: "DESC" }],
1085
+ limit: { from: 0, to: 10 }
1086
+ })
1087
+ }
201
1088
  }
202
1089
  ```
203
1090
 
204
- Can now look like this:
1091
+ ### Available Operators
1092
+
1093
+ #### Comparison Operators
1094
+ - `==` - Equal to
1095
+ - `!=` - Not equal to
1096
+ - `>` - Greater than
1097
+ - `>=` - Greater than or equal to
1098
+ - `<` - Less than
1099
+ - `<=` - Less than or equal to
205
1100
 
206
- ```js
207
- import { TODO_CREATE } from 'constants/todo';
208
- import { createReducer } from 'utils';
1101
+ #### String Operators
1102
+ - `LIKE` - Pattern matching (supports wildcards with `%`)
1103
+ - `CONTAINS` - Contains substring (case-insensitive by default)
209
1104
 
210
- const initialState = [];
1105
+ #### Array Operators
1106
+ - `IN` - Value exists in array
1107
+ - `NOT IN` - Value does not exist in array
211
1108
 
212
- export default createReducer(initialState, {
213
- [TODO_CREATE] : (state, payload) => { ... }
1109
+ ### Complex Filter Example
1110
+
1111
+ ```typescript
1112
+ // Find posts that are either:
1113
+ // - Events happening in the next week
1114
+ // - Articles published in the last month
1115
+ const results = await executeQuery(context, {
1116
+ collection: 'posts',
1117
+ filters: {
1118
+ logic: 'OR',
1119
+ conditions: [
1120
+ {
1121
+ logic: 'AND',
1122
+ conditions: [
1123
+ { field: 'type', operator: '==', value: 'event' },
1124
+ { field: 'eventDate', operator: '>', value: Date.now() },
1125
+ { field: 'eventDate', operator: '<', value: Date.now() + 7 * 86400000 }
1126
+ ]
1127
+ },
1128
+ {
1129
+ logic: 'AND',
1130
+ conditions: [
1131
+ { field: 'type', operator: '==', value: 'article' },
1132
+ { field: 'publishedAt', operator: '>', value: Date.now() - 30 * 86400000 }
1133
+ ]
1134
+ }
1135
+ ]
1136
+ },
1137
+ sort: [{ field: 'added', direction: 'DESC' }],
1138
+ limit: { from: 0, to: 50 }
214
1139
  });
215
1140
  ```
216
1141
 
217
- Troubleshooting
218
- ---------------
1142
+ ### Multi-Collection Search
1143
+
1144
+ Search across multiple collections with a single query:
1145
+
1146
+ ```typescript
1147
+ import {executeSearch} from '@nlabs/reaktor';
1148
+
1149
+ const searchResults = await executeSearch(context, {
1150
+ collections: ['posts', 'users', 'groups'],
1151
+ query: 'nodejs',
1152
+ searchFields: ['name', 'content', 'description'],
1153
+ filters: {
1154
+ logic: 'AND',
1155
+ conditions: [
1156
+ { field: 'status', operator: '==', value: 'active' }
1157
+ ]
1158
+ },
1159
+ limit: { from: 0, to: 50 }
1160
+ });
1161
+ ```
1162
+
1163
+ ### Aggregation Operations
1164
+
1165
+ Perform aggregations on any collection:
1166
+
1167
+ ```typescript
1168
+ import {executeAggregation} from '@nlabs/reaktor';
1169
+
1170
+ // Count active users
1171
+ const userCount = await executeAggregation(context, {
1172
+ collection: 'users',
1173
+ type: 'COUNT',
1174
+ filters: {
1175
+ logic: 'AND',
1176
+ conditions: [
1177
+ { field: 'status', operator: '==', value: 'active' }
1178
+ ]
1179
+ }
1180
+ });
1181
+
1182
+ // Calculate total revenue
1183
+ const totalRevenue = await executeAggregation(context, {
1184
+ collection: 'payments',
1185
+ type: 'SUM',
1186
+ field: 'amount',
1187
+ filters: {
1188
+ logic: 'AND',
1189
+ conditions: [
1190
+ { field: 'status', operator: '==', value: 'completed' }
1191
+ ]
1192
+ }
1193
+ });
1194
+
1195
+ // Get average rating
1196
+ const avgRating = await executeAggregation(context, {
1197
+ collection: 'reviews',
1198
+ type: 'AVG',
1199
+ field: 'rating'
1200
+ });
1201
+ ```
1202
+
1203
+ ### Custom Property Filtering
1204
+
1205
+ Query documents with dynamic/custom fields:
1206
+
1207
+ ```typescript
1208
+ const results = await executeQuery(context, {
1209
+ collection: 'posts',
1210
+ filters: {
1211
+ logic: 'AND',
1212
+ conditions: [
1213
+ { field: 'type', operator: '==', value: 'event' },
1214
+ { field: 'customField.status', operator: '==', value: 'confirmed' },
1215
+ { field: 'customField.capacity', operator: '>=', value: 100 }
1216
+ ]
1217
+ },
1218
+ includeCustomFields: true
1219
+ });
1220
+ ```
1221
+
1222
+ ### Field Selection
1223
+
1224
+ Return only specific fields to optimize performance:
1225
+
1226
+ ```typescript
1227
+ const results = await executeQuery(context, {
1228
+ collection: 'users',
1229
+ fields: ['_id', 'name', 'email', 'status'],
1230
+ filters: {
1231
+ logic: 'AND',
1232
+ conditions: [
1233
+ { field: 'status', operator: '==', value: 'active' }
1234
+ ]
1235
+ }
1236
+ });
1237
+ ```
1238
+
1239
+ ### Performance Tips
1240
+
1241
+ 1. **Use Indexes** - Ensure your ArangoDB collections have appropriate indexes for frequently filtered fields
1242
+ 2. **Limit Results** - Always use pagination to avoid loading large datasets
1243
+ 3. **Select Fields** - Use the `fields` parameter to return only needed data
1244
+ 4. **Filter Early** - Apply filters before sorting for better performance
1245
+ 5. **Avoid LIKE** - Use CONTAINS or full-text search when possible
1246
+
1247
+ ```typescript
1248
+ // Good - Efficient with indexes
1249
+ {
1250
+ collection: 'posts',
1251
+ filters: {
1252
+ logic: 'AND',
1253
+ conditions: [
1254
+ { field: 'status', operator: '==', value: 'active' },
1255
+ { field: 'added', operator: '>', value: timestamp }
1256
+ ]
1257
+ },
1258
+ fields: ['_id', 'title', 'added'],
1259
+ limit: { from: 0, to: 20 }
1260
+ }
1261
+
1262
+ // Avoid - Slower without proper indexes
1263
+ {
1264
+ collection: 'posts',
1265
+ filters: {
1266
+ logic: 'AND',
1267
+ conditions: [
1268
+ { field: 'content', operator: 'LIKE', value: '%search%' }
1269
+ ]
1270
+ }
1271
+ }
1272
+ ```
1273
+
1274
+ ### Error Handling
1275
+
1276
+ All query functions throw descriptive errors:
1277
+
1278
+ ```typescript
1279
+ try {
1280
+ const results = await executeQuery(context, options);
1281
+ } catch (error) {
1282
+ // Error types:
1283
+ // - Invalid collection name
1284
+ // - Invalid field name
1285
+ // - Invalid operator
1286
+ // - Database connection error
1287
+ // - Query execution error
1288
+ console.error('Query failed:', error.message);
1289
+ }
1290
+ ```
1291
+
1292
+ ### Common Use Cases
1293
+
1294
+ #### 1. Search Users by Multiple Criteria
1295
+ ```typescript
1296
+ const users = await executeQuery(context, {
1297
+ collection: 'users',
1298
+ filters: {
1299
+ logic: 'AND',
1300
+ conditions: [
1301
+ { field: 'status', operator: '==', value: 'active' },
1302
+ { field: 'age', operator: '>=', value: 18 },
1303
+ { field: 'role', operator: 'IN', value: ['admin', 'moderator'] }
1304
+ ]
1305
+ }
1306
+ });
1307
+ ```
1308
+
1309
+ #### 2. Find Recent Posts with Tags
1310
+ ```typescript
1311
+ const posts = await executeQuery(context, {
1312
+ collection: 'posts',
1313
+ filters: {
1314
+ logic: 'AND',
1315
+ conditions: [
1316
+ { field: 'added', operator: '>', value: Date.now() - 7 * 86400000 },
1317
+ { field: 'tags', operator: 'CONTAINS', value: 'javascript' }
1318
+ ]
1319
+ },
1320
+ sort: [{ field: 'added', direction: 'DESC' }],
1321
+ limit: { from: 0, to: 10 }
1322
+ });
1323
+ ```
1324
+
1325
+ #### 3. Case-Insensitive Email Search
1326
+ ```typescript
1327
+ const users = await executeQuery(context, {
1328
+ collection: 'users',
1329
+ filters: {
1330
+ logic: 'AND',
1331
+ conditions: [
1332
+ {
1333
+ field: 'email',
1334
+ operator: 'CONTAINS',
1335
+ value: 'example.com',
1336
+ caseSensitive: false
1337
+ }
1338
+ ]
1339
+ }
1340
+ });
1341
+ ```
1342
+
1343
+ ### API Reference
1344
+
1345
+ #### `executeQuery(context, options)`
1346
+ Execute a flexible query on any collection.
1347
+
1348
+ **Parameters:**
1349
+ - `context: ApiContext` - API context with session and database info
1350
+ - `options: QueryOptions` - Query configuration
1351
+
1352
+ **Returns:** `Promise<any[]>` - Array of matching documents
1353
+
1354
+ #### `executeSearch(context, options)`
1355
+ Perform multi-collection search.
1356
+
1357
+ **Parameters:**
1358
+ - `context: ApiContext` - API context
1359
+ - `options: SearchOptions` - Search configuration
1360
+
1361
+ **Returns:** `Promise<any[]>` - Array of search results
1362
+
1363
+ #### `executeAggregation(context, options)`
1364
+ Execute aggregation operations.
1365
+
1366
+ **Parameters:**
1367
+ - `context: ApiContext` - API context
1368
+ - `options: AggregationOptions` - Aggregation configuration
1369
+
1370
+ **Returns:** `Promise<any>` - Aggregation result
1371
+
1372
+ For more details, see the TypeScript definitions in `src/types/arangodb.types.ts`.
1373
+
1374
+ Refer to the respective files in `src/actions/` for full function signatures and usage details.
1375
+
1376
+ ## Documentation
1377
+
1378
+ For comprehensive guides and detailed documentation, see:
1379
+
1380
+ - **[Architecture Guide](./docs/ARCHITECTURE.md)** - System overview, data flow, security model, and extension points
1381
+ - **[Query System Guide](./docs/QUERY_SYSTEM.md)** - Complete query system documentation with examples and best practices
1382
+ - **[Development Guide](./docs/DEVELOPMENT.md)** - Setup instructions, coding patterns, and contribution guidelines
1383
+ - **[Database i18n Guide](./DATABASE_I18N_GUIDE.md)** - Internationalization system documentation
1384
+ - **[Test Utilities Guide](./TEST_UTILITIES_GUIDE.md)** - Testing patterns and helper functions
1385
+
1386
+ ## Additional Resources
1387
+
1388
+ - [ArangoDB Documentation](https://www.arangodb.com/docs/)
1389
+ - [GraphQL Compose Documentation](https://graphql-compose.github.io/)
1390
+ - [TypeScript Handbook](https://www.typescriptlang.org/docs/)
1391
+ - [Zod Documentation](https://zod.dev/)
1392
+
1393
+ ## Contributing
1394
+
1395
+ 1. Fork the repository
1396
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
1397
+ 3. Follow the coding conventions in [Development Guide](./docs/DEVELOPMENT.md)
1398
+ 4. Write tests for new functionality
1399
+ 5. Ensure all tests pass (`npm test`)
1400
+ 6. Commit your changes (`git commit -m 'Add amazing feature'`)
1401
+ 7. Push to the branch (`git push origin feature/amazing-feature`)
1402
+ 8. Open a Pull Request
1403
+
1404
+ ## License
219
1405
 
220
- Nothing yet. Having an issue? Report it and I'll get to it as soon as possible!
1406
+ See the LICENSE file for license rights and limitations (Apache-2.0).