@paralect/hive 0.1.50-alpha.3 → 0.1.50

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 (294) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/cli/helpers/execCommand.js +10 -10
  3. package/cli/helpers/isProjectInit.js +3 -3
  4. package/cli/helpers/mergeDirs.js +1 -1
  5. package/cli/hive.js +105 -105
  6. package/{test-app → framework}/.cursor/commands/add-service.md +6 -6
  7. package/{test-app → framework}/.cursor/skills/hive-overview/SKILL.md +1 -1
  8. package/{test-app → framework}/.cursor/skills/hive-service/SKILL.md +2 -2
  9. package/framework/bin/start.sh +2 -0
  10. package/{.hive/bootstrap-hive.js → framework/bootstrap-hive.ts} +4 -4
  11. package/{.hive → framework}/package-lock.json +212 -156
  12. package/framework/package.json +42 -0
  13. package/{.hive/src/app.js → framework/src/app.ts} +1 -1
  14. package/{.hive/src/bullMqBus.js → framework/src/bullMqBus.ts} +1 -1
  15. package/{.hive/src/bullMqWrapper.js → framework/src/bullMqWrapper.ts} +1 -1
  16. package/{.hive/src/app-config/index.js → framework/src/config/index.ts} +7 -7
  17. package/{.hive/src/db.js → framework/src/db.ts} +21 -6
  18. package/framework/src/endpoint.ts +132 -0
  19. package/framework/src/helpers/generateDbTypes.ts +47 -0
  20. package/{.hive/src/helpers/getMiddlewares.js → framework/src/helpers/getMiddlewares.ts} +1 -1
  21. package/{.hive/src/helpers/getResourceEndpoints.js → framework/src/helpers/getResourceEndpoints.ts} +8 -8
  22. package/{.hive/src/helpers/getResources.js → framework/src/helpers/getResources.ts} +1 -1
  23. package/{.hive/src/helpers/getSchemas.js → framework/src/helpers/getSchemas.ts} +13 -13
  24. package/framework/src/index.ts +3 -0
  25. package/{.hive/src/ioEmitter.js → framework/src/ioEmitter.ts} +1 -1
  26. package/{.hive/src/lib/node-mongo/src/mongo-query-service.js → framework/src/lib/node-mongo/src/mongo-query-service.ts} +18 -7
  27. package/{.hive/src/lib/node-mongo/src/mongo-service.js → framework/src/lib/node-mongo/src/mongo-service.ts} +17 -9
  28. package/{starter/src/logger.js → framework/src/logger.ts} +4 -3
  29. package/{.hive/src/migrations/migrations-log/migration-log.schema.js → framework/src/migrations/migrations-log/migration-log.schema.ts} +1 -1
  30. package/{.hive/src/migrations/migrations-log/migration-log.service.js → framework/src/migrations/migrations-log/migration-log.service.ts} +1 -1
  31. package/{.hive/src/migrations/migrations.schema.js → framework/src/migrations/migrations.schema.ts} +1 -1
  32. package/{.hive/src/resources/_dev/endpoints/triggerSchedulerHandler.js → framework/src/resources/_dev/endpoints/triggerSchedulerHandler.ts} +2 -1
  33. package/framework/src/resources/health/endpoints/get.ts +14 -0
  34. package/{.hive/src/resources/schemaMappings/schemaMappings.schema.js → framework/src/resources/schemaMappings/schemaMappings.schema.ts} +1 -1
  35. package/{.hive/src/routes/index.js → framework/src/routes/index.ts} +23 -27
  36. package/framework/src/schema.ts +3 -0
  37. package/{.hive/src/services/emailService.js → framework/src/services/emailService.ts} +1 -1
  38. package/{.hive/src/socketIo.js → framework/src/socketIo.ts} +1 -1
  39. package/{.hive → framework}/tsconfig.json +17 -13
  40. package/package.json +43 -51
  41. package/starter/hive/autoMap/schemaMappings.json +1 -0
  42. package/starter/hive/config/.env.example +11 -0
  43. package/starter/hive/config/app.ts +19 -0
  44. package/{.hive/src/services/setCookie.js → starter/hive/helpers/setCookie.ts} +1 -2
  45. package/starter/hive/middlewares/_global.ts +9 -0
  46. package/{.hive/src/middlewares/attachUser.js → starter/hive/middlewares/attachUser.ts} +2 -2
  47. package/{.hive/src/middlewares/shouldExist.js → starter/hive/middlewares/shouldExist.ts} +1 -1
  48. package/{.hive/src/middlewares/shouldNotExist.js → starter/hive/middlewares/shouldNotExist.ts} +1 -1
  49. package/starter/hive/resources/files/endpoints/upload.ts +25 -0
  50. package/starter/hive/resources/files/files.schema.ts +20 -0
  51. package/{.hive/src/resources/tokens/methods/storeToken.js → starter/hive/resources/tokens/methods/storeToken.ts} +3 -3
  52. package/{.hive/src/resources/tokens/tokens.schema.js → starter/hive/resources/tokens/tokens.schema.ts} +1 -2
  53. package/starter/hive/resources/users/endpoints/getCurrentUser.ts +12 -0
  54. package/starter/hive/resources/users/endpoints/getUserProfile.ts +17 -0
  55. package/{.hive/src/resources/users/users.schema.js → starter/hive/resources/users/users.schema.ts} +1 -2
  56. package/starter/hive/services/cloudStorage.ts +102 -0
  57. package/starter/package.json +9 -98
  58. package/starter/tsconfig.json +16 -20
  59. package/.cursor/commands/deslop.md +0 -12
  60. package/.hive/.cursor/commands/add-service.md +0 -188
  61. package/.hive/.cursor/skills/hive-overview/SKILL.md +0 -50
  62. package/.hive/.cursor/skills/hive-service/SKILL.md +0 -90
  63. package/.hive/bin/start.sh +0 -2
  64. package/.hive/package.json +0 -98
  65. package/.hive/src/logger.js +0 -43
  66. package/.hive/src/middlewares/global/tryToAttachUser.js +0 -33
  67. package/.hive/src/resources/health/endpoints/get.js +0 -19
  68. package/.hive/src/resources/tokens/methods/setToken.js +0 -8
  69. package/.hive/src/resources/users/endpoints/getCurrentUser.js +0 -14
  70. package/.hive/src/resources/users/endpoints/getUserProfile.js +0 -19
  71. package/.hive/src/resources/users/methods/ensureUserCreated.js +0 -68
  72. package/.hive/src/security.util.js +0 -38
  73. package/.hive/src/services/globalTest.js +0 -0
  74. package/cli/helpers/docker.js +0 -59
  75. package/cli/helpers/envCheck.js +0 -127
  76. package/cli/helpers/findPort.js +0 -32
  77. package/starter/.babelrc +0 -6
  78. package/starter/.cursor/commands/add-endpoint.md +0 -262
  79. package/starter/.cursor/commands/add-handler.md +0 -137
  80. package/starter/.cursor/commands/add-middleware.md +0 -95
  81. package/starter/.cursor/commands/add-resource.md +0 -71
  82. package/starter/.cursor/commands/add-scheduler.md +0 -138
  83. package/starter/.cursor/commands/add-service.md +0 -188
  84. package/starter/.cursor/skills/hive-auth/SKILL.md +0 -134
  85. package/starter/.cursor/skills/hive-database/SKILL.md +0 -103
  86. package/starter/.cursor/skills/hive-endpoint/SKILL.md +0 -103
  87. package/starter/.cursor/skills/hive-handler/SKILL.md +0 -88
  88. package/starter/.cursor/skills/hive-mapping/SKILL.md +0 -85
  89. package/starter/.cursor/skills/hive-middleware/SKILL.md +0 -104
  90. package/starter/.cursor/skills/hive-overview/SKILL.md +0 -50
  91. package/starter/.cursor/skills/hive-scheduler/SKILL.md +0 -94
  92. package/starter/.cursor/skills/hive-schema/SKILL.md +0 -73
  93. package/starter/.cursor/skills/hive-service/SKILL.md +0 -90
  94. package/starter/.dockerignore +0 -1
  95. package/starter/Dockerfile +0 -22
  96. package/starter/Dockerfile.dev +0 -33
  97. package/starter/Dockerfile.prod +0 -29
  98. package/starter/README.md +0 -11
  99. package/starter/bin/deploy.sh +0 -5
  100. package/starter/bin/start.sh +0 -2
  101. package/starter/bootstrap-hive.js +0 -118
  102. package/starter/deploy/api/Chart.yaml +0 -6
  103. package/starter/deploy/api/staging.yaml +0 -3
  104. package/starter/deploy/api/templates/deployment.yaml +0 -44
  105. package/starter/deploy/api/templates/ingress.yaml +0 -26
  106. package/starter/deploy/api/templates/service.yaml +0 -14
  107. package/starter/deploy/script/Dockerfile +0 -39
  108. package/starter/deploy/script/package-lock.json +0 -1499
  109. package/starter/deploy/script/package.json +0 -12
  110. package/starter/deploy/script/src/config.js +0 -48
  111. package/starter/deploy/script/src/index.js +0 -108
  112. package/starter/deploy/script/src/util.js +0 -19
  113. package/starter/initial-data.json +0 -176
  114. package/starter/loader.mjs +0 -40
  115. package/starter/package-lock.json +0 -13492
  116. package/starter/register.mjs +0 -6
  117. package/starter/ship_logo.png +0 -0
  118. package/starter/src/app-config/app.js +0 -3
  119. package/starter/src/app-config/assertEnv.js +0 -15
  120. package/starter/src/app-config/index.js +0 -65
  121. package/starter/src/app.js +0 -65
  122. package/starter/src/assets/emails/components/header.mjml +0 -13
  123. package/starter/src/assets/emails/dist/.gitkeep +0 -0
  124. package/starter/src/assets/emails/signup-welcome.mjml +0 -34
  125. package/starter/src/assets/emails/styles/index.mjml +0 -77
  126. package/starter/src/autoMap/addHandlers.js +0 -142
  127. package/starter/src/autoMap/getDependentFields.js +0 -37
  128. package/starter/src/autoMap/mapSchema.js +0 -99
  129. package/starter/src/autoMap/schemaMappings.js +0 -13
  130. package/starter/src/autoMap/schemaMappings.json +0 -3
  131. package/starter/src/bullMqBus.js +0 -21
  132. package/starter/src/bullMqWrapper.js +0 -23
  133. package/starter/src/db.js +0 -53
  134. package/starter/src/emails/MyEmailComponent.jsx +0 -14
  135. package/starter/src/emails/compiled/MyEmailComponent.js +0 -6
  136. package/starter/src/emails/compiled/compiled/MyEmailComponent.js +0 -6
  137. package/starter/src/emails/compiled/compiled/compiled/MyEmailComponent.js +0 -6
  138. package/starter/src/emails/compiled/compiled/compiled/compiled/MyEmailComponent.js +0 -6
  139. package/starter/src/helpers/db/ifUpdated.js +0 -22
  140. package/starter/src/helpers/esm.js +0 -56
  141. package/starter/src/helpers/getMiddlewares.js +0 -41
  142. package/starter/src/helpers/getResourceEndpoints.js +0 -31
  143. package/starter/src/helpers/getResources.js +0 -35
  144. package/starter/src/helpers/getSchemas.js +0 -53
  145. package/starter/src/helpers/importHandlers.js +0 -20
  146. package/starter/src/helpers/isZodArray.js +0 -13
  147. package/starter/src/helpers/prettierFormat.js +0 -8
  148. package/starter/src/helpers/schema/db.schema.js +0 -9
  149. package/starter/src/helpers/schema/pagination.schema.js +0 -14
  150. package/starter/src/ioEmitter.js +0 -9
  151. package/starter/src/jsconfig.json +0 -5
  152. package/starter/src/lib/node-mongo/.github/workflows/npm-publish.yml +0 -32
  153. package/starter/src/lib/node-mongo/API.md +0 -654
  154. package/starter/src/lib/node-mongo/CHANGELOG.md +0 -98
  155. package/starter/src/lib/node-mongo/README.md +0 -97
  156. package/starter/src/lib/node-mongo/package-lock.json +0 -3682
  157. package/starter/src/lib/node-mongo/package.json +0 -74
  158. package/starter/src/lib/node-mongo/src/index.js +0 -64
  159. package/starter/src/lib/node-mongo/src/mongo-query-service.js +0 -78
  160. package/starter/src/lib/node-mongo/src/mongo-service-error.js +0 -15
  161. package/starter/src/lib/node-mongo/src/mongo-service.js +0 -303
  162. package/starter/src/middlewares/attachUser.js +0 -41
  163. package/starter/src/middlewares/global/extractUserTokens.js +0 -15
  164. package/starter/src/middlewares/global/tryToAttachUser.js +0 -33
  165. package/starter/src/middlewares/isAuthorized.js +0 -18
  166. package/starter/src/middlewares/shouldExist.js +0 -37
  167. package/starter/src/middlewares/shouldNotExist.js +0 -19
  168. package/starter/src/middlewares/uploadFile.js +0 -5
  169. package/starter/src/middlewares/validate.js +0 -32
  170. package/starter/src/migrations/migration.js +0 -8
  171. package/starter/src/migrations/migration.service.js +0 -76
  172. package/starter/src/migrations/migrations/1.js +0 -22
  173. package/starter/src/migrations/migrations-log/migration-log.schema.js +0 -13
  174. package/starter/src/migrations/migrations-log/migration-log.service.js +0 -50
  175. package/starter/src/migrations/migrations.schema.js +0 -6
  176. package/starter/src/migrations/migrator.js +0 -75
  177. package/starter/src/migrator.js +0 -3
  178. package/starter/src/resources/_dev/endpoints/triggerSchedulerHandler.js +0 -32
  179. package/starter/src/resources/health/endpoints/get.js +0 -19
  180. package/starter/src/resources/schemaMappings/schemaMappings.schema.js +0 -6
  181. package/starter/src/resources/tokens/methods/generateSecureToken.js +0 -9
  182. package/starter/src/resources/tokens/methods/setToken.js +0 -8
  183. package/starter/src/resources/tokens/methods/storeToken.js +0 -35
  184. package/starter/src/resources/tokens/tokens.schema.js +0 -11
  185. package/starter/src/resources/users/endpoints/getCurrentUser.js +0 -14
  186. package/starter/src/resources/users/endpoints/getUserProfile.js +0 -19
  187. package/starter/src/resources/users/handlers/test.js +0 -1
  188. package/starter/src/resources/users/methods/ensureUserCreated.js +0 -68
  189. package/starter/src/resources/users/users.schema.js +0 -16
  190. package/starter/src/routes/index.js +0 -172
  191. package/starter/src/routes/middlewares/attachCustomErrors.js +0 -28
  192. package/starter/src/routes/middlewares/routeErrorHandler.js +0 -27
  193. package/starter/src/scheduler.js +0 -35
  194. package/starter/src/security.util.js +0 -38
  195. package/starter/src/services/emailService.js +0 -15
  196. package/starter/src/services/globalTest.js +0 -0
  197. package/starter/src/services/setCookie.js +0 -21
  198. package/starter/src/socketIo.js +0 -99
  199. package/test-app/.cursor/commands/add-endpoint.md +0 -262
  200. package/test-app/.cursor/commands/add-handler.md +0 -137
  201. package/test-app/.cursor/commands/add-middleware.md +0 -95
  202. package/test-app/.cursor/commands/add-resource.md +0 -71
  203. package/test-app/.cursor/commands/add-scheduler.md +0 -138
  204. package/test-app/.cursor/skills/hive-auth/SKILL.md +0 -134
  205. package/test-app/.cursor/skills/hive-database/SKILL.md +0 -103
  206. package/test-app/.cursor/skills/hive-endpoint/SKILL.md +0 -103
  207. package/test-app/.cursor/skills/hive-handler/SKILL.md +0 -88
  208. package/test-app/.cursor/skills/hive-mapping/SKILL.md +0 -85
  209. package/test-app/.cursor/skills/hive-middleware/SKILL.md +0 -104
  210. package/test-app/.cursor/skills/hive-scheduler/SKILL.md +0 -94
  211. package/test-app/.cursor/skills/hive-schema/SKILL.md +0 -73
  212. package/test-app/package-lock.json +0 -462
  213. package/test-app/package.json +0 -25
  214. package/test-app/src/resources/tasks/tasks.schema.js +0 -2
  215. /package/{.hive → framework}/.babelrc +0 -0
  216. /package/{.hive → framework}/.cursor/commands/add-endpoint.md +0 -0
  217. /package/{.hive → framework}/.cursor/commands/add-handler.md +0 -0
  218. /package/{.hive → framework}/.cursor/commands/add-middleware.md +0 -0
  219. /package/{.hive → framework}/.cursor/commands/add-resource.md +0 -0
  220. /package/{.hive → framework}/.cursor/commands/add-scheduler.md +0 -0
  221. /package/{.hive → framework}/.cursor/skills/hive-auth/SKILL.md +0 -0
  222. /package/{.hive → framework}/.cursor/skills/hive-database/SKILL.md +0 -0
  223. /package/{.hive → framework}/.cursor/skills/hive-endpoint/SKILL.md +0 -0
  224. /package/{.hive → framework}/.cursor/skills/hive-handler/SKILL.md +0 -0
  225. /package/{.hive → framework}/.cursor/skills/hive-mapping/SKILL.md +0 -0
  226. /package/{.hive → framework}/.cursor/skills/hive-middleware/SKILL.md +0 -0
  227. /package/{.hive → framework}/.cursor/skills/hive-scheduler/SKILL.md +0 -0
  228. /package/{.hive → framework}/.cursor/skills/hive-schema/SKILL.md +0 -0
  229. /package/{.hive → framework}/.dockerignore +0 -0
  230. /package/{.hive → framework}/Dockerfile +0 -0
  231. /package/{.hive → framework}/Dockerfile.dev +0 -0
  232. /package/{.hive → framework}/Dockerfile.prod +0 -0
  233. /package/{.hive → framework}/README.md +0 -0
  234. /package/{.hive → framework}/bin/deploy.sh +0 -0
  235. /package/{.hive → framework}/deploy/api/Chart.yaml +0 -0
  236. /package/{.hive → framework}/deploy/api/staging.yaml +0 -0
  237. /package/{.hive → framework}/deploy/api/templates/deployment.yaml +0 -0
  238. /package/{.hive → framework}/deploy/api/templates/ingress.yaml +0 -0
  239. /package/{.hive → framework}/deploy/api/templates/service.yaml +0 -0
  240. /package/{.hive → framework}/deploy/script/Dockerfile +0 -0
  241. /package/{.hive → framework}/deploy/script/package-lock.json +0 -0
  242. /package/{.hive → framework}/deploy/script/package.json +0 -0
  243. /package/{.hive/deploy/script/src/config.js → framework/deploy/script/src/config.ts} +0 -0
  244. /package/{.hive/deploy/script/src/index.js → framework/deploy/script/src/index.ts} +0 -0
  245. /package/{.hive/deploy/script/src/util.js → framework/deploy/script/src/util.ts} +0 -0
  246. /package/{.hive → framework}/initial-data.json +0 -0
  247. /package/{.hive → framework}/ship_logo.png +0 -0
  248. /package/{.hive → framework}/src/assets/emails/components/header.mjml +0 -0
  249. /package/{.hive → framework}/src/assets/emails/dist/.gitkeep +0 -0
  250. /package/{.hive → framework}/src/assets/emails/signup-welcome.mjml +0 -0
  251. /package/{.hive → framework}/src/assets/emails/styles/index.mjml +0 -0
  252. /package/{.hive/src/autoMap/addHandlers.js → framework/src/autoMap/addHandlers.ts} +0 -0
  253. /package/{.hive/src/autoMap/getDependentFields.js → framework/src/autoMap/getDependentFields.ts} +0 -0
  254. /package/{.hive/src/autoMap/mapSchema.js → framework/src/autoMap/mapSchema.ts} +0 -0
  255. /package/{.hive → framework}/src/autoMap/schemaMappings.json +0 -0
  256. /package/{.hive/src/autoMap/schemaMappings.js → framework/src/autoMap/schemaMappings.ts} +0 -0
  257. /package/{.hive/src/helpers/schema/db.schema.js → framework/src/common/schema/db.schema.ts} +0 -0
  258. /package/{.hive/src/helpers/schema/pagination.schema.js → framework/src/common/schema/pagination.schema.ts} +0 -0
  259. /package/{.hive/src/app-config/app.js → framework/src/config/app.ts} +0 -0
  260. /package/{.hive/src/app-config/assertEnv.js → framework/src/config/assertEnv.ts} +0 -0
  261. /package/{.hive/src/emails/MyEmailComponent.jsx → framework/src/emails/MyEmailComponent.tsx} +0 -0
  262. /package/{.hive/src/emails/compiled/MyEmailComponent.js → framework/src/emails/compiled/MyEmailComponent.ts} +0 -0
  263. /package/{.hive/src/emails/compiled/compiled/MyEmailComponent.js → framework/src/emails/compiled/compiled/MyEmailComponent.ts} +0 -0
  264. /package/{.hive/src/helpers/db/ifUpdated.js → framework/src/helpers/db/ifUpdated.ts} +0 -0
  265. /package/{.hive/src/helpers/importHandlers.js → framework/src/helpers/importHandlers.ts} +0 -0
  266. /package/{.hive/src/helpers/isZodArray.js → framework/src/helpers/isZodArray.ts} +0 -0
  267. /package/{.hive/src/helpers/prettierFormat.js → framework/src/helpers/prettierFormat.ts} +0 -0
  268. /package/{.hive → framework}/src/jsconfig.json +0 -0
  269. /package/{.hive → framework}/src/lib/node-mongo/.github/workflows/npm-publish.yml +0 -0
  270. /package/{.hive → framework}/src/lib/node-mongo/API.md +0 -0
  271. /package/{.hive → framework}/src/lib/node-mongo/CHANGELOG.md +0 -0
  272. /package/{.hive → framework}/src/lib/node-mongo/README.md +0 -0
  273. /package/{.hive → framework}/src/lib/node-mongo/package-lock.json +0 -0
  274. /package/{.hive → framework}/src/lib/node-mongo/package.json +0 -0
  275. /package/{.hive/src/lib/node-mongo/src/index.js → framework/src/lib/node-mongo/src/index.ts} +0 -0
  276. /package/{.hive/src/lib/node-mongo/src/mongo-service-error.js → framework/src/lib/node-mongo/src/mongo-service-error.ts} +0 -0
  277. /package/{.hive/src/middlewares/allowNoAuth.js → framework/src/middlewares/allowNoAuth.ts} +0 -0
  278. /package/{.hive/src/middlewares/global/extractUserTokens.js → framework/src/middlewares/global/extractUserTokens.ts} +0 -0
  279. /package/{.hive/src/middlewares/validate.js → framework/src/middlewares/validate.ts} +0 -0
  280. /package/{.hive/src/migrations/migration.service.js → framework/src/migrations/migration.service.ts} +0 -0
  281. /package/{.hive/src/migrations/migration.js → framework/src/migrations/migration.ts} +0 -0
  282. /package/{.hive/src/migrations/migrations/1.js → framework/src/migrations/migrations/1.ts} +0 -0
  283. /package/{.hive/src/migrations/migrator.js → framework/src/migrations/migrator.ts} +0 -0
  284. /package/{.hive/src/migrator.js → framework/src/migrator.ts} +0 -0
  285. /package/{.hive/src/routes/middlewares/attachCustomErrors.js → framework/src/routes/middlewares/attachCustomErrors.ts} +0 -0
  286. /package/{.hive/src/routes/middlewares/routeErrorHandler.js → framework/src/routes/middlewares/routeErrorHandler.ts} +0 -0
  287. /package/{.hive/src/scheduler/handlers/sendDailyReport.example.js → framework/src/scheduler/handlers/sendDailyReport.example.ts} +0 -0
  288. /package/{.hive/src/scheduler.js → framework/src/scheduler.ts} +0 -0
  289. /package/starter/{src/middlewares/allowNoAuth.js → hive/middlewares/allowNoAuth.ts} +0 -0
  290. /package/{.hive/src/middlewares/isAuthorized.js → starter/hive/middlewares/isAuthorized.ts} +0 -0
  291. /package/{.hive/src/middlewares/uploadFile.js → starter/hive/middlewares/uploadFile.ts} +0 -0
  292. /package/{.hive/src/resources/tokens/methods/generateSecureToken.js → starter/hive/resources/tokens/methods/generateSecureToken.ts} +0 -0
  293. /package/{.hive/src/resources/users/handlers/test.js → starter/hive/resources/users/handlers/test.ts} +0 -0
  294. /package/starter/{src/scheduler/handlers/sendDailyReport.example.js → hive/scheduler/handlers/dailyExample.ts} +0 -0
@@ -1,6 +0,0 @@
1
- import { register } from 'node:module';
2
- import { pathToFileURL } from 'node:url';
3
-
4
- console.log('[register] Registering custom loader...');
5
- register('./loader.mjs', pathToFileURL('./'));
6
- console.log('[register] Custom loader registered');
Binary file
@@ -1,3 +0,0 @@
1
- export default {
2
- // myVar: process.env.MY_VAR
3
- };
@@ -1,15 +0,0 @@
1
- import _ from 'lodash';
2
-
3
- export default (envs = []) => {
4
- let missingEnvs = [];
5
-
6
- _.each(envs, envName => {
7
- if (!process.env[envName]) {
8
- missingEnvs.push(envName);
9
- }
10
- });
11
-
12
- if (!_.isEmpty(missingEnvs)) {
13
- throw Error(`Missing env variables: ${missingEnvs.join(', ')}`)
14
- }
15
- };
@@ -1,65 +0,0 @@
1
- import _ from 'lodash';
2
- import fs from "fs";
3
- import dotenv from "dotenv";
4
- import appConfig from "./app.js";
5
- import { getDirname } from '#hive/helpers/esm';
6
-
7
- const __dirname = getDirname(import.meta.url);
8
-
9
- dotenv.config({ path: `${__dirname}/.env` });
10
- dotenv.config({ path: `${__dirname}/.env.app` });
11
-
12
- console.log('process.env.HIVE_SRC', process.env.HIVE_SRC)
13
-
14
- if (process.env.HIVE_SRC) {
15
- dotenv.config({
16
- path: `${process.env.HIVE_SRC}/app-config/.env`,
17
- });
18
-
19
- dotenv.config({
20
- path: `${process.env.HIVE_SRC}/app-config/.env.app`,
21
- });
22
- }
23
-
24
- const env = process.env.APP_ENV || "development";
25
-
26
- let config = {
27
- async init() {
28
- if (process.env.HIVE_SRC) {
29
- let pluginConfigPath = `${process.env.HIVE_SRC}/app-config/app.js`;
30
-
31
- if (fs.existsSync(pluginConfigPath)) {
32
- const { default: pluginConfig } = await (import(pluginConfigPath))
33
- _.extend(config, pluginConfig);
34
- }
35
- }
36
- },
37
-
38
- _hive: {},
39
- env,
40
- port: process.env.PORT || 3001,
41
- domain:
42
- env === "production" ? "https://api.yourapp.com" : process.env.DOMAIN || "",
43
- isDev: env === "development",
44
- mongoUri: process.env.MONGODB_URI,
45
- redis: {
46
- url: process.env.REDIS_URI,
47
- },
48
- smtp: {
49
- host: process.env.SMTP_SERVER,
50
- port: process.env.SMTP_PORT,
51
- secure: true,
52
- auth: {
53
- user: process.env.SMTP_USER,
54
- pass: process.env.SMTP_KEY,
55
- },
56
- },
57
- ...appConfig,
58
- assert(configKey) {
59
- if (!config[configKey]) {
60
- throw Error(`Config [${configKey}] is missing`);
61
- }
62
- },
63
- };
64
-
65
- export default config;
@@ -1,65 +0,0 @@
1
- // Module resolution:
2
- // #hive/... → .hive/src/... (framework code, via package.json imports)
3
- // #root/... → HIVE_SRC/... (user code, via custom loader)
4
-
5
- import Koa from "koa";
6
- import http from "http";
7
- import config from "#hive/app-config";
8
- import logger from "#hive/logger";
9
- import cors from "@koa/cors";
10
- import helmet from "koa-helmet";
11
- import qs from "koa-qs";
12
- import bodyParser from "koa-bodyparser";
13
-
14
- import requestLogger from "koa-logger";
15
- import db from "#hive/db";
16
- import socketIo from "#hive/socketIo";
17
- import mount from "koa-mount";
18
- import get from "#hive/resources/health/endpoints/get";
19
-
20
- const main = async () => {
21
- await config.init();
22
- await db.init();
23
-
24
- const routes = (await import("#hive/routes")).default;
25
- const scheduler = (await import("./scheduler")).default;
26
-
27
- process.on("unhandledRejection", (reason, p) => {
28
- console.trace(reason.stack);
29
- logger.error(reason.stack);
30
- });
31
-
32
- const app = new Koa();
33
-
34
- app.use(cors({ credentials: true }));
35
- app.use(helmet());
36
-
37
- qs(app);
38
-
39
- app.use(bodyParser({
40
- enableTypes: ["json", "form", "text"],
41
-
42
- formLimit: config._hive.bodyParser?.formLimit || "10mb",
43
- textLimit: config._hive.bodyParser?.textLimit || "10mb",
44
- jsonLimit: config._hive.bodyParser?.jsonLimit || "10mb",
45
- }));
46
-
47
- app.use(mount("/health", get.handler));
48
- app.use(requestLogger());
49
-
50
- await routes(app);
51
-
52
- const server = http.createServer(app.callback());
53
-
54
- server.listen(config.port, () => {
55
- console.log(`Api server listening on ${config.port}, in ${process.env.NODE_ENV} mode and ${process.env.APP_ENV} environment`);
56
- });
57
-
58
- await scheduler();
59
-
60
- await socketIo(server);
61
- };
62
-
63
- main();
64
-
65
- export default main;
@@ -1,13 +0,0 @@
1
- <mj-section background-color="#ffffff" padding-bottom="0px" padding-top="0">
2
- <mj-column vertical-align="top" width="100%">
3
- <mj-text
4
- align="center"
5
- font-size="30px"
6
- font-weight="bold"
7
- font-family="Trebuchet MS, Arial, sans-serif"
8
- color="#55299a"
9
- >
10
- Ship
11
- </mj-text>
12
- </mj-column>
13
- </mj-section>
File without changes
@@ -1,34 +0,0 @@
1
- <mjml>
2
- <mj-head>
3
- <mj-include path="./styles/index.mjml" />
4
- </mj-head>
5
-
6
- <mj-body>
7
- <mj-include path="./components/header.mjml" />
8
-
9
- <mj-section mj-class="main-section">
10
- <mj-column vertical-align="middle" width="100%">
11
- <mj-text mj-class="big-text"> Hi, there. </mj-text>
12
-
13
- <mj-text mj-class="text">
14
- Thanks for checking out Ship, we hope our products can make your
15
- routine life a little more enjoyable.
16
- </mj-text>
17
-
18
- <mj-button mj-class="btn" href="{{verifyEmailUrl}}">
19
- Verify Your Email
20
- </mj-button>
21
- </mj-column>
22
- </mj-section>
23
-
24
- <mj-section mj-class="bottom-section">
25
- <mj-column vertical-align="middle" width="70%">
26
- <mj-text mj-class="small-text"> INTERESTING FACT </mj-text>
27
-
28
- <mj-text mj-class="tiny-text">
29
- It took more than three years to build the Titanic.
30
- </mj-text>
31
- </mj-column>
32
- </mj-section>
33
- </mj-body>
34
- </mjml>
@@ -1,77 +0,0 @@
1
- <mj-attributes>
2
- <mj-class
3
- name="big-text"
4
- align="center"
5
- font-weight="bold"
6
- font-family="Trebuchet MS, Arial, sans-serif"
7
- color="#3b1d6c"
8
- font-size="30px"
9
- padding-left="25px"
10
- padding-right="25px"
11
- />
12
-
13
- <mj-class
14
- name="text"
15
- align="center"
16
- color="#000"
17
- font-size="18px"
18
- font-family="Century Gothic, Arial, sans-serif"
19
- padding-left="25px"
20
- padding-right="25px"
21
- line-height="26px"
22
- />
23
-
24
- <mj-class
25
- name="small-text"
26
- align="center"
27
- font-weight="bold"
28
- font-family="Trebuchet MS, Arial, sans-serif"
29
- color="#3b1d6c"
30
- font-size="15px"
31
- padding-left="25px"
32
- padding-right="25px"
33
- />
34
-
35
- <mj-class
36
- name="tiny-text"
37
- align="center"
38
- color="#000"
39
- font-size="15px"
40
- font-family="Verdana, Arial, sans-serif"
41
- line-height="20px"
42
- />
43
-
44
- <mj-class
45
- name="btn"
46
- align="center"
47
- font-size="22px"
48
- background-color="#4c258b"
49
- border-radius="4px"
50
- color="#fff"
51
- font-family="open Sans Helvetica, Arial, sans-serif"
52
- />
53
-
54
- <mj-class
55
- name="main-section"
56
- background-color="#cccccc"
57
- vertical-align="top"
58
- padding-bottom="20px"
59
- padding-top="0"
60
- />
61
-
62
- <mj-class
63
- name="main-section-image"
64
- background-color="#cccccc"
65
- vertical-align="top"
66
- padding-bottom="0"
67
- padding-top="0"
68
- />
69
-
70
- <mj-class
71
- name="bottom-section"
72
- background-color="#ffffff"
73
- vertical-align="top"
74
- padding-bottom="20px"
75
- padding-top="20px"
76
- />
77
- </mj-attributes>
@@ -1,142 +0,0 @@
1
- import _ from "lodash";
2
- import db from "#hive/db";
3
- import ifUpdated from "#hive/helpers/db/ifUpdated";
4
- import schemaMappings from "./schemaMappings";
5
- import getDependentFields from './getDependentFields';
6
- import isZodArray from "#hive/helpers/isZodArray";
7
-
8
- const updatedSchemaMappings = (() => {
9
- const result = {};
10
- const schemaNames = Object.keys(schemaMappings);
11
- schemaNames.forEach((schemaName) => {
12
- const dependentFieldNames = Object.keys(schemaMappings[schemaName]);
13
- const schema = db.schemas[schemaName];
14
- dependentFieldNames.forEach((dependentFieldName) => {
15
- const dependentFields = getDependentFields(schema, dependentFieldName);
16
- if (!_.isEmpty(dependentFields)) {
17
- result[schemaName] = result[schemaName] || {};
18
- result[schemaName][dependentFieldName] = {
19
- schema: schemaMappings[schemaName][dependentFieldName].schema,
20
- dependentFields,
21
- };
22
- }
23
- });
24
-
25
- });
26
- return result;
27
- })();
28
-
29
- const getToUpdate = async ({ doc, schemaName }) => {
30
- const dependentFieldNames = Object.keys(updatedSchemaMappings[schemaName]);
31
- const toUpdate = {};
32
- await Promise.all(
33
- dependentFieldNames.map(async (dependentFieldName) => {
34
- const { schema: dependentSchemaName } =
35
- updatedSchemaMappings[schemaName][dependentFieldName];
36
- const { dependentFields } =
37
- updatedSchemaMappings[schemaName][dependentFieldName];
38
- if (!_.isEmpty(doc[dependentFieldName])) {
39
- if (_.isArray(doc[dependentFieldName])) {
40
- toUpdate[dependentFieldName] = (
41
- await db.services[dependentSchemaName].find(
42
- {
43
- _id: { $in: _.uniq(_.map(doc[dependentFieldName], "_id")) },
44
- },
45
- {
46
- fields: dependentFields,
47
- }
48
- )
49
- ).results;
50
- } else {
51
- toUpdate[dependentFieldName] = await db.services[
52
- dependentSchemaName
53
- ].findOne(
54
- {
55
- _id: doc[dependentFieldName]._id,
56
- },
57
- {
58
- fields: dependentFields,
59
- }
60
- );
61
- }
62
- }
63
- })
64
- );
65
- return toUpdate;
66
- };
67
-
68
- const populateOnCreate = ({ schemaName }) => {
69
- db.services[schemaName]._options.onBeforeCreated = async ({ docs }) => {
70
- const res = await Promise.all(
71
- docs.map(async (doc) => {
72
- const toUpdate = await getToUpdate({ schemaName, doc });
73
- return {
74
- ...doc,
75
- ...toUpdate,
76
- };
77
- })
78
- );
79
- return res;
80
- };
81
- };
82
-
83
- // const addOnEntityCreatedHandler = ({ schemaName }) => {
84
- // db.services[schemaName].on('created', async ({ doc }) => {
85
- // const toUpdate = await getToUpdate({ schemaName, doc });
86
- // if (!_.isEmpty(toUpdate)) {
87
- // await db.services[schemaName].atomic.update(
88
- // { _id: doc._id },
89
- // { $set: toUpdate }
90
- // );
91
- // }
92
- // });
93
- // };
94
-
95
- const addOnDependentEntitiesUpdatedHandlers = ({ schemaName }) => {
96
- const dependentFieldNames = Object.keys(schemaMappings[schemaName]);
97
- dependentFieldNames.forEach((dependentFieldName) => {
98
- const dependentFieldSchemaName =
99
- schemaMappings[schemaName][dependentFieldName].schema;
100
- const schema = db.schemas[schemaName];
101
- const dependentFields = getDependentFields(schema, dependentFieldName);
102
- db.services[dependentFieldSchemaName].on(
103
- "updated",
104
- ifUpdated(dependentFields, async ({ doc }) => {
105
- const toUpdate = _.pick(doc, ["_id", ...dependentFields]);
106
- if (isZodArray(schema.shape[dependentFieldName])) {
107
- db.services[schemaName].atomic.update(
108
- { [`${dependentFieldName}._id`]: doc._id },
109
- {
110
- $set: {
111
- [`${dependentFieldName}.$`]: toUpdate,
112
- },
113
- },
114
- {
115
- multi: true,
116
- }
117
- );
118
- } else {
119
- db.services[schemaName].atomic.update(
120
- { [`${dependentFieldName}._id`]: doc._id },
121
- {
122
- $set: {
123
- [`${dependentFieldName}`]: toUpdate,
124
- },
125
- },
126
- {
127
- multi: true,
128
- }
129
- );
130
- }
131
- })
132
- );
133
- });
134
- };
135
- export default async () => {
136
- const schemaNames = Object.keys(updatedSchemaMappings);
137
- schemaNames.forEach((schemaName) => {
138
- // addOnEntityCreatedHandler({ schemaName });
139
- populateOnCreate({ schemaName });
140
- addOnDependentEntitiesUpdatedHandlers({ schemaName });
141
- });
142
- };
@@ -1,37 +0,0 @@
1
- import _ from 'lodash';
2
- import { z } from 'zod';
3
- import isZodArray from "#hive/helpers/isZodArray";
4
-
5
- const getZodKeys = schema => {
6
- // make sure schema is not null or undefined
7
- if (schema === null || schema === undefined) return [];
8
- // check if schema is nullable or optional
9
- if (schema instanceof z.ZodNullable || schema instanceof z.ZodOptional) return getZodKeys(schema.unwrap());
10
- // check if schema is an array
11
- if (isZodArray(schema)) return getZodKeys(schema.element);
12
- // check if schema is an object
13
- if (schema instanceof z.ZodObject) {
14
- // get key/value pairs from schema
15
- const entries = Object.entries(schema.shape);
16
- // loop through key/value pairs
17
- return entries.flatMap(([key, value]) => {
18
- // get nested keys
19
- const nested = value instanceof z.ZodType ? getZodKeys(value).map(subKey => `${key}.${subKey}`) : [];
20
- // return nested keys
21
- return nested.length ? nested : key;
22
- });
23
- }
24
- // return empty array
25
- return [];
26
- };
27
-
28
- export default (schema, dependentFieldName) => {
29
- let targetSchema = schema.shape[dependentFieldName];
30
- let zodKeys = getZodKeys(targetSchema);
31
-
32
- zodKeys = _.uniq(zodKeys.map(key => key.split('.')[0]));
33
-
34
- return zodKeys.filter(
35
- (key) => !_.includes(['_id', 'createdOn', 'updatedOn'], key)
36
- );
37
- };
@@ -1,99 +0,0 @@
1
- import _ from "lodash";
2
- import db from "#hive/db";
3
-
4
- import schemaMappings from "./schemaMappings";
5
- import getDependentFields from './getDependentFields';
6
- import isZodArray from "#hive/helpers/isZodArray";
7
-
8
- const schemaMappingService = db.services.schemaMappings;
9
-
10
- const zodSchemaToSchemaMappings = () => {
11
- const newSchemaMappings = {};
12
-
13
- Object.keys(schemaMappings).forEach((schemaName) => {
14
- const schema = db.schemas[schemaName];
15
-
16
- newSchemaMappings[schemaName] = {};
17
-
18
- Object.keys(schemaMappings[schemaName]).forEach((fieldName) => {
19
- newSchemaMappings[schemaName][fieldName] = {
20
- schema: schemaMappings[schemaName][fieldName].schema,
21
- fields: getDependentFields(schema, fieldName),
22
- };
23
- });
24
- });
25
- console.log('newSchemaMappings', newSchemaMappings)
26
- return newSchemaMappings;
27
- };
28
-
29
-
30
- export default async () => {
31
- const prevSchema = await schemaMappingService.findOne({});
32
- const prevSchemaMappings = prevSchema?.mappings;
33
- if (!prevSchemaMappings) {
34
- const initialSchemaMappings = zodSchemaToSchemaMappings();
35
- schemaMappingService.create({ mappings: initialSchemaMappings });
36
- } else {
37
- const schemaNames = Object.keys(schemaMappings);
38
- await Promise.all(
39
- schemaNames.map(async (schemaName) => {
40
- const schema = db.schemas[schemaName];
41
-
42
- const fieldNames = Object.keys(schemaMappings[schemaName]);
43
- await Promise.all(
44
- fieldNames.map(async (fieldName) => {
45
- const dependentFields = getDependentFields(schema, fieldName);
46
- const prevSchema = (prevSchemaMappings[schemaName] &&
47
- prevSchemaMappings[schemaName][fieldName]) || { fields: [] };
48
- const { fields: prevDependentFields } = prevSchema;
49
- if (
50
- _.difference(dependentFields, prevDependentFields).length !== 0
51
- ) {
52
- console.log(`Mapping schema changes: ${schemaName}.${fieldName}`);
53
- const uniqueDependentEntityIds = await db.services[
54
- schemaName
55
- ].distinct(`${fieldName}._id`);
56
- const { results: uniqueDependentEntities } = await db.services[
57
- schemaMappings[schemaName][fieldName].schema
58
- ].find(
59
- {
60
- _id: { $in: uniqueDependentEntityIds },
61
- },
62
- { fields: ["_id", ...dependentFields] }
63
- );
64
- await Promise.all(
65
- uniqueDependentEntities.map(async (entity) => {
66
- if (isZodArray(schema.shape[fieldName])) {
67
- await db.services[schemaName].atomic.update(
68
- { [`${fieldName}._id`]: entity._id },
69
- {
70
- $set: { [`${fieldName}.$`]: entity },
71
- },
72
- {
73
- multi: true,
74
- }
75
- );
76
- } else {
77
- await db.services[schemaName].atomic.update(
78
- { [`${fieldName}._id`]: entity._id },
79
- {
80
- $set: { [`${fieldName}`]: entity },
81
- },
82
- {
83
- multi: true,
84
- }
85
- );
86
- }
87
- })
88
- );
89
- }
90
- })
91
- );
92
- })
93
- );
94
- schemaMappingService.atomic.update(
95
- { _id: prevSchema._id },
96
- { $set: { mappings: zodSchemaToSchemaMappings() } }
97
- );
98
- }
99
- };
@@ -1,13 +0,0 @@
1
- import fs from 'fs';
2
-
3
- let schemaMappings = {};
4
-
5
- if (fs.existsSync('./schemaMappings.json')) {
6
- schemaMappings = JSON.parse(fs.readFileSync('./schemaMappings.json', 'utf8') || '{}');
7
- }
8
-
9
- if (process.env.HIVE_SRC && fs.existsSync(`${process.env.HIVE_SRC}/autoMap/schemaMappings.json`)) {
10
- schemaMappings = JSON.parse(fs.readFileSync(`${process.env.HIVE_SRC}/autoMap/schemaMappings.json`, 'utf8') || '{}');
11
- }
12
-
13
- export default schemaMappings;
@@ -1,3 +0,0 @@
1
- {
2
-
3
- }
@@ -1,21 +0,0 @@
1
- import config from '#hive/app-config';
2
- import bullMq from './bullMq';
3
- const queue = bullMq.Queue(`database-${config.env}`);
4
-
5
- let handlers = {};
6
-
7
- export default {
8
- on(eventName, handler) {
9
- console.log('registering', eventName);
10
-
11
- handlers[eventName] = handlers[eventName] || [];
12
- handlers[eventName].push(handler);
13
- },
14
- emit(eventName, data) {
15
- queue.add(eventName, data);
16
- }
17
- };
18
-
19
- bullMq.Worker(`database-${config.env}`, async ({ name: eventName, data }) => {
20
- await Promise.all((handlers[eventName] || []).map(h => h(data)));
21
- });
@@ -1,23 +0,0 @@
1
- import config from '#hive/app-config';
2
- import { Queue, Worker } from 'bullMq';
3
-
4
- let connectionOpts = {
5
- host: config.redis.url.split('@')[1].split(':')[0],
6
- port: config.redis.url.split('@')[1].split(':')[1],
7
- username: 'default',
8
- password: config.redis.url.split(':')[2].split('@')[0],
9
- };
10
-
11
- export default {
12
- Queue(queueName) {
13
- return new Queue(queueName, {
14
- connection: connectionOpts,
15
- });
16
- },
17
- Worker(queueName, workerFn, options = {}) {
18
- return new Worker(queueName, workerFn, {
19
- ...options,
20
- connection: connectionOpts,
21
- });
22
- },
23
- };
package/starter/src/db.js DELETED
@@ -1,53 +0,0 @@
1
- import fs from "fs";
2
- import _ from "lodash";
3
- import getSchemas from "#hive/helpers/getSchemas";
4
- import getResources from "#hive/helpers/getResources";
5
- import importHandlers from "#hive/helpers/importHandlers";
6
-
7
- import config from "#hive/app-config";
8
- import { connect } from "#hive/lib/node-mongo/src/index.js";
9
-
10
- const db = connect(config.mongoUri);
11
-
12
- db.services = {};
13
- db.schemas = {};
14
-
15
- db.init = async () => {
16
- const schemaPaths = await getSchemas();
17
-
18
- await Promise.all(_.map(
19
- schemaPaths,
20
- async ({ file: schemaFile, resourceName, name: schemaName }) => {
21
- let { default: schema, secureFields = [] } = (await import(schemaFile));
22
-
23
- if (process.env.HIVE_SRC) {
24
- let extendSchemaPath = `${process.env.HIVE_SRC}/resources/${resourceName}/${schemaName}.extends.schema.js`;
25
- if (fs.existsSync(extendSchemaPath)) {
26
- let extendsSchema = (await import(extendSchemaPath)).default;
27
- schema = schema.append(extendsSchema);
28
- }
29
- }
30
- db.schemas[schemaName] = schema;
31
-
32
- db.services[schemaName] = db.createService(`${resourceName}`, {
33
- validate: (obj) => {
34
- return { value: schema.parse(obj) };
35
- },
36
- secureFields: secureFields,
37
- });
38
- }
39
- ));
40
-
41
- const resourcePaths = await getResources();
42
-
43
- setTimeout(async () => {
44
- for (const { name } of resourcePaths) {
45
- await importHandlers(name);
46
- }
47
- }, 0);
48
-
49
- (await import("#hive/autoMap/addHandlers")).default();
50
- (await import("#hive/autoMap/mapSchema")).default();
51
- };
52
-
53
- export default db;