@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
@@ -0,0 +1,13 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npx npm-check-updates:*)",
5
+ "Bash(npm install:*)",
6
+ "Bash(git mv:*)",
7
+ "Bash(npm run test:init:*)",
8
+ "Bash(ls:*)",
9
+ "Bash(node:*)",
10
+ "Bash(HIVE_SRC=$PWD/hive node -e \"\nconst tsx = require\\(''tsx/cjs/api''\\);\nprocess.env.HIVE_SRC = ''$PWD/hive'';\ntsx.require\\(''./.hive/src/app.ts'', __filename\\);\n\")"
11
+ ]
12
+ }
13
+ }
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const { spawn } = require('child_process');
3
4
 
4
- const execa = require('execa');
5
5
  const mkdirp = require('mkdirp');
6
6
 
7
7
  const execCommand = async (command, options = {}, outputFileSrc = null) => {
@@ -20,29 +20,29 @@ const execCommand = async (command, options = {}, outputFileSrc = null) => {
20
20
 
21
21
  return commandPart;
22
22
  });
23
-
24
- // commandParts = command.split(' ').filter((part) => !!part.trim());
25
23
  }
26
24
 
27
25
  const commandName = commandParts.shift();
28
26
  const commandArguments = commandParts;
29
27
 
30
- const process = execa(commandName, commandArguments, {
28
+ const child = spawn(commandName, commandArguments, {
31
29
  stdio: outputFileSrc ? 'pipe' : 'inherit',
32
30
  ...options,
33
31
  });
34
32
 
35
33
  if (outputFileSrc) {
36
- console.log('writing to outputFileSrc', outputFileSrc);
37
34
  const dir = path.dirname(outputFileSrc);
38
-
39
35
  await mkdirp(dir);
40
- console.log(dir, fs.existsSync(dir));
41
-
42
- process.stdout.pipe(fs.createWriteStream(outputFileSrc, { flags: 'a+' }));
36
+ child.stdout.pipe(fs.createWriteStream(outputFileSrc, { flags: 'a+' }));
43
37
  }
44
38
 
45
- return process;
39
+ return new Promise((resolve, reject) => {
40
+ child.on('close', (code) => {
41
+ if (code === 0) resolve();
42
+ else reject(new Error(`Command "${command}" failed with exit code ${code}`));
43
+ });
44
+ child.on('error', reject);
45
+ });
46
46
  };
47
47
 
48
48
  module.exports = execCommand;
@@ -5,9 +5,9 @@ const inquirer = require('inquirer');
5
5
 
6
6
  module.exports = async () => {
7
7
  if (!process.env.PROJECT_ID) {
8
- let projectConfigPath = path.resolve(process.env.HIVE_SRC, './hive.config.js');
9
-
10
- if (fs.existsSync(projectConfigPath)) {
8
+ let projectConfigPath = [path.resolve(process.env.HIVE_SRC, './hive.config.ts'), path.resolve(process.env.HIVE_SRC, './hive.config.js')].find(p => fs.existsSync(p));
9
+
10
+ if (projectConfigPath) {
11
11
  const config = require(projectConfigPath);
12
12
  if (config.projectId) {
13
13
  process.env.PROJECT_ID = config.projectId;
@@ -71,7 +71,7 @@ async function mergeDirectories(sourceDir1, sourceDir2, targetDir) {
71
71
  }
72
72
 
73
73
  module.exports = async ({ hiveSrc, outDir }) => {
74
- await mergeDirectories(path.resolve(__dirname, './../../starter'), hiveSrc, outDir);
74
+ await mergeDirectories(path.resolve(__dirname, './../../framework'), hiveSrc, outDir);
75
75
 
76
76
  console.log('Merged resources');
77
77
  }
package/cli/hive.js CHANGED
@@ -7,41 +7,76 @@ const inquirer = require('inquirer');
7
7
  const mergeDirs = require('./helpers/mergeDirs');
8
8
  const execCommand = require('./helpers/execCommand');
9
9
  const downloadDirectory = require('./helpers/downloadDirectory');
10
- const { isDockerInstalled, startMongo, startRedis } = require('./helpers/docker');
11
- const { ensureEnvConfig, hashCode } = require('./helpers/envCheck');
12
- const { findAvailablePort } = require('./helpers/findPort');
13
10
  const axios = require('axios');
11
+ const tsx = require('tsx/cjs/api');
14
12
  const fs = require('fs');
15
- const { spawn } = require('child_process');
16
-
17
- const hivePackage = require('../package.json');
18
-
19
- let appPackage = {
20
- "name": "my-hive-app",
21
- "version": "1.0.0",
22
- "description": "Hive App",
23
- "main": "src/app.js",
24
- "scripts": {
25
- "prepare": "hive prepare ./src",
26
- "dev": "hive prepare ./src && HIVE_SRC=$PWD/src npm -C .hive run dev",
27
- "start": "hive prepare ./src && HIVE_SRC=$PWD/src npm -C .hive run start",
28
- "deploy-local": "hive build-local && hive deploy"
29
- },
30
- "keywords": [],
31
- "author": "",
32
- "license": "ISC",
33
- "dependencies": {
34
- "@paralect/hive": hivePackage.version,
35
- },
36
- "devDependencies": {
37
- "nodemon": "^3.1.4"
13
+
14
+ program
15
+ .version(require('../package.json').version, '-v, --version');
16
+
17
+ function generateDbTypesFile(hiveSrc, frameworkDir, hiveProjectDir) {
18
+ // Write to .hive/src/_generated/ (NOT $HIVE_SRC) to avoid triggering tsx watcher
19
+ const generatedDir = path.resolve(hiveProjectDir, 'src', '_generated');
20
+
21
+ if (!fs.existsSync(generatedDir)) {
22
+ fs.mkdirSync(generatedDir, { recursive: true });
23
+ }
24
+
25
+ // Scan for schema files in user resources and framework resources
26
+ const schemas = [];
27
+ const scanDirs = [
28
+ { dir: path.resolve(hiveSrc, 'resources'), isUser: true },
29
+ { dir: path.resolve(frameworkDir, 'src', 'resources'), isUser: false },
30
+ ];
31
+
32
+ for (const { dir: resourcesDir, isUser } of scanDirs) {
33
+ if (!fs.existsSync(resourcesDir)) continue;
34
+
35
+ for (const resourceName of fs.readdirSync(resourcesDir)) {
36
+ const resourcePath = path.resolve(resourcesDir, resourceName);
37
+ if (!fs.statSync(resourcePath).isDirectory()) continue;
38
+
39
+ for (const file of fs.readdirSync(resourcePath)) {
40
+ if ((file.endsWith('.schema.ts') || file.endsWith('.schema.js')) && !file.includes('extends.schema')) {
41
+ const name = file.replace('.schema.ts', '').replace('.schema.js', '');
42
+ // Skip if already found (user schemas override framework)
43
+ if (!schemas.find(s => s.name === name)) {
44
+ schemas.push({ name, resourceName, isUser });
45
+ }
46
+ }
47
+ }
48
+ }
38
49
  }
50
+
51
+ // User schemas use @/ (hive/*), framework schemas use @hive/ (.hive/src/*)
52
+ const imports = schemas.map(
53
+ (s) => `import type ${s.name}Schema from '${s.isUser ? '@' : '@hive'}/resources/${s.resourceName}/${s.name}.schema';`
54
+ );
55
+
56
+ const entries = schemas.map(
57
+ (s) => ` ${s.name}: MongoService<z.infer<typeof ${s.name}Schema>>;`
58
+ );
59
+
60
+ const content = `// Auto-generated by Hive — do not edit manually
61
+ import type { z } from 'zod';
62
+ import type MongoService from '@hive/lib/node-mongo/src/mongo-service';
63
+ ${imports.join('\n')}
64
+
65
+ export interface DbServices {
66
+ ${entries.join('\n')}
67
+ }
68
+ `;
69
+
70
+ fs.writeFileSync(path.resolve(generatedDir, 'db.types.ts'), content);
71
+ console.log('[hive] Generated db.types.ts');
39
72
  }
40
73
 
41
74
  program
42
75
  .command('init [projectName]')
43
76
  .description('Initialize a new Hive project')
44
- .action(async (projectName) => {
77
+ .option('--skip-install', 'Skip npm install')
78
+ .option('--link', 'Use local file:.. dependency for @paralect/hive (for development)')
79
+ .action(async (projectName, options) => {
45
80
  try {
46
81
  let name = projectName;
47
82
 
@@ -58,41 +93,47 @@ program
58
93
  }
59
94
 
60
95
  const projectDir = path.resolve(process.cwd(), name);
96
+ const hiveVersion = require('../package.json').version;
61
97
 
62
98
  console.log(`\n🐝 Creating Hive project: ${name}\n`);
63
99
 
64
- await execCommand(`mkdir -p ${projectDir}/src/resources`);
65
- await execCommand(`mkdir -p ${projectDir}/src/middlewares`);
66
- await execCommand(`mkdir -p ${projectDir}/src/services`);
67
- await execCommand(`mkdir -p ${projectDir}/src/scheduler/handlers`);
100
+ const filesDir = path.resolve(__dirname, '../starter');
101
+ await execCommand(`cp -r ${filesDir}/. ${projectDir}/`);
68
102
 
69
- fs.writeFileSync(
70
- path.join(projectDir, 'package.json'),
71
- JSON.stringify({
72
- name,
73
- ...appPackage
103
+ // Rename .env.example to .env (stored as .example to avoid gitignore)
104
+ const envExample = path.join(projectDir, 'hive', 'config', '.env.example');
105
+ const envFile = path.join(projectDir, 'hive', 'config', '.env');
106
+ if (fs.existsSync(envExample)) {
107
+ fs.renameSync(envExample, envFile);
108
+ }
74
109
 
75
- }, null, 2)
76
- );
110
+ const templateFiles = ['package.json'];
111
+ const replacements = {
112
+ '{{PROJECT_NAME}}': name,
113
+ '{{HIVE_DEP}}': options.link ? `file:${path.relative(projectDir, path.resolve(__dirname, '..'))}` : `^${hiveVersion}`,
114
+ };
115
+
116
+ for (const file of templateFiles) {
117
+ const filePath = path.join(projectDir, file);
118
+ let content = fs.readFileSync(filePath, 'utf-8');
119
+ for (const [key, value] of Object.entries(replacements)) {
120
+ content = content.replaceAll(key, value);
121
+ }
122
+ fs.writeFileSync(filePath, content);
123
+ }
77
124
 
78
- const redisDb = hashCode(name) % 16;
79
- const appConfigDir = path.join(projectDir, 'src', 'app-config');
80
- await execCommand(`mkdir -p ${appConfigDir}`);
81
- fs.writeFileSync(
82
- path.join(appConfigDir, '.env'),
83
- `MONGODB_URI=mongodb://localhost:27027/${name}\nREDIS_URI=redis://localhost:6389/${redisDb}\nPORT=3001\nNODE_ENV=development\n`
84
- );
125
+ const projectPkgPath = path.join(projectDir, 'package.json');
126
+ const projectPkg = JSON.parse(fs.readFileSync(projectPkgPath, 'utf-8'));
127
+ fs.writeFileSync(projectPkgPath, JSON.stringify(projectPkg, null, 2));
85
128
 
86
- fs.writeFileSync(
87
- path.join(projectDir, '.gitignore'),
88
- `node_modules\n.hive\n.env\nsrc/app-config/.env\n`
89
- );
129
+ await execCommand(`cp -r ${path.resolve(__dirname, '..')}/framework/.cursor ${projectDir}/`);
90
130
 
91
- await execCommand(`cp -r ${path.resolve(__dirname, '..')}/starter/.cursor ${projectDir}/`);
131
+ if (!options.skipInstall) {
132
+ await execCommand(`npm install`, { cwd: projectDir });
133
+ }
92
134
 
93
135
  console.log(`✅ Project created!\n`);
94
136
  console.log(`Next steps:\n`);
95
- console.log(` cd ${name}`);
96
137
  console.log(` hive run ./src\n`);
97
138
  console.log(`Start building with AI commands:`);
98
139
  console.log(` add-resource tasks`);
@@ -102,62 +143,21 @@ program
102
143
  }
103
144
  });
104
145
 
105
- program
106
- .command('infra-docker')
107
- .description('Start shared MongoDB and Redis containers for local development')
108
- .action(async () => {
109
- try {
110
- if (!isDockerInstalled()) {
111
- console.error('Docker is not installed or not running. Please install Docker first.');
112
- process.exit(1);
113
- }
114
-
115
- console.log('\nStarting Hive infrastructure...\n');
116
-
117
- await startMongo();
118
- await startRedis();
119
-
120
- console.log('\n✅ Infrastructure ready!\n');
121
- console.log('Connection URIs:');
122
- console.log(' MongoDB: mongodb://localhost:27027/<your-db-name>');
123
- console.log(' Redis: redis://localhost:6389/<db-number>\n');
124
- console.log('These containers are shared across all Hive projects.');
125
- console.log('Each project uses a unique database name for isolation.\n');
126
- } catch (error) {
127
- console.error('An error occurred:', error.message);
128
- }
129
- });
130
-
131
146
  program
132
147
  .command('run [dirPath]')
133
148
  .description('Run Hive server')
134
149
  .action(async (dirPath = '.') => {
135
150
  try {
136
- const hiveSrc = path.resolve(process.cwd(), dirPath);
137
- const projectDir = path.resolve(hiveSrc, '..');
138
- const hiveProjectDir = path.resolve(projectDir, '.hive');
139
-
140
- // Ensure env config exists in hive_src/app-config/.env
141
- await ensureEnvConfig(hiveSrc);
142
-
143
- // Find available port
144
- const defaultPort = parseInt(process.env.PORT) || 3001;
145
- const port = await findAvailablePort(defaultPort);
146
- if (port !== defaultPort) {
147
- console.log(` Port ${defaultPort} in use, using ${port} instead\n`);
148
- }
151
+ process.env.HIVE_SRC = path.resolve(process.cwd(), dirPath);
149
152
 
153
+ const hiveProjectDir = path.resolve(process.env.HIVE_SRC, `../.hive`);
150
154
  await execCommand(`mkdir -p ${hiveProjectDir}`);
151
- await execCommand(`rsync -a --exclude node_modules ${path.resolve(__dirname, '..')}/starter/ ${hiveProjectDir}/`);
155
+ await execCommand(`cp -r ${path.resolve(__dirname, '..')}/framework/ ${hiveProjectDir}`);
152
156
 
153
- const child = spawn('npx', ['tsx', '--watch', '--import', './register.mjs', 'src/app.js'], {
154
- cwd: hiveProjectDir,
155
- stdio: 'inherit',
156
- env: { ...process.env, HIVE_SRC: hiveSrc, PORT: String(port) }
157
- });
157
+ // Generate types before starting the server
158
+ generateDbTypesFile(process.env.HIVE_SRC, path.resolve(__dirname, '..', 'framework'), hiveProjectDir);
158
159
 
159
- child.on('error', (err) => console.error('Failed to start:', err.message));
160
- child.on('close', (code) => process.exit(code));
160
+ tsx.require(`${hiveProjectDir}/src/app.ts`, __filename); // TSX doesn't work inside node_moduels
161
161
  } catch (error) {
162
162
  console.error('An error occurred:', error.message);
163
163
  }
@@ -168,15 +168,15 @@ program
168
168
  .description('Prepare Hive server')
169
169
  .action(async (dirPath = '.') => {
170
170
  try {
171
- const hiveSrc = path.resolve(process.cwd(), dirPath);
172
- const projectDir = path.resolve(hiveSrc, '..');
173
- const hiveProjectDir = path.resolve(projectDir, '.hive');
174
-
175
- // Ensure env config exists in hive_src/app-config/.env
176
- await ensureEnvConfig(hiveSrc);
171
+ process.env.HIVE_SRC = path.resolve(process.cwd(), dirPath);
172
+ const hiveProjectDir = path.resolve(process.env.HIVE_SRC, `../.hive`);
177
173
 
178
174
  await execCommand(`mkdir -p ${hiveProjectDir}`);
179
- await execCommand(`rsync -a --exclude node_modules ${path.resolve(__dirname, '..')}/starter/ ${hiveProjectDir}/`);
175
+ await execCommand(`cp -r ${path.resolve(__dirname, '..')}/framework/. ${hiveProjectDir}`);
176
+ await execCommand(`npm install --prefix ${hiveProjectDir}`);
177
+
178
+ // Generate db.types.ts from discovered schemas
179
+ generateDbTypesFile(process.env.HIVE_SRC, path.resolve(__dirname, '..', 'framework'), hiveProjectDir);
180
180
  } catch (error) {
181
181
  console.error('An error occurred:', error.message);
182
182
  }
@@ -36,7 +36,7 @@ When creating a service, use these go-to libraries:
36
36
  ## Template
37
37
 
38
38
  ```javascript
39
- import config from 'app-config';
39
+ import config from 'config';
40
40
 
41
41
  // Initialize client here
42
42
 
@@ -52,7 +52,7 @@ export default {
52
52
  ### `add-service slack sendChannelMessage, replyToThread`
53
53
 
54
54
  ```javascript
55
- import config from 'app-config';
55
+ import config from 'config';
56
56
  import { WebClient } from '@slack/web-api';
57
57
 
58
58
  const client = new WebClient(config.slack.botToken);
@@ -73,7 +73,7 @@ export default {
73
73
  ### `add-service stripe createCustomer, createPaymentIntent, listInvoices`
74
74
 
75
75
  ```javascript
76
- import config from 'app-config';
76
+ import config from 'config';
77
77
  import Stripe from 'stripe';
78
78
 
79
79
  const client = new Stripe(config.stripe.secretKey);
@@ -102,7 +102,7 @@ export default {
102
102
  ### `add-service openai chat, generateImage`
103
103
 
104
104
  ```javascript
105
- import config from 'app-config';
105
+ import config from 'config';
106
106
  import OpenAI from 'openai';
107
107
 
108
108
  const client = new OpenAI({ apiKey: config.openai.apiKey });
@@ -125,7 +125,7 @@ export default {
125
125
  ### `add-service sendgrid sendEmail, sendTemplateEmail`
126
126
 
127
127
  ```javascript
128
- import config from 'app-config';
128
+ import config from 'config';
129
129
  import sgMail from '@sendgrid/mail';
130
130
 
131
131
  sgMail.setApiKey(config.sendgrid.apiKey);
@@ -144,7 +144,7 @@ export default {
144
144
  ### `add-service s3 upload, getSignedUrl, delete`
145
145
 
146
146
  ```javascript
147
- import config from 'app-config';
147
+ import config from 'config';
148
148
  import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
149
149
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
150
150
 
@@ -39,7 +39,7 @@ src/resources/{name}/
39
39
 
40
40
  ```javascript
41
41
  import db from 'db'; // Database
42
- import config from 'app-config'; // Config
42
+ import config from 'config'; // Config
43
43
  import { z } from 'zod'; // Validation
44
44
  ```
45
45
 
@@ -15,7 +15,7 @@ Location: `/src/services/{name}.js`
15
15
  ## API Client Template
16
16
 
17
17
  ```javascript
18
- import config from 'app-config';
18
+ import config from 'config';
19
19
  import axios from 'axios';
20
20
 
21
21
  const client = axios.create({
@@ -41,7 +41,7 @@ export default {
41
41
  ## SDK Wrapper Template
42
42
 
43
43
  ```javascript
44
- import config from 'app-config';
44
+ import config from 'config';
45
45
  import { WebClient } from '@slack/web-api';
46
46
 
47
47
  const client = new WebClient(config.slack.botToken);
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ docker compose up --build
@@ -58,7 +58,7 @@ function generateProjectStructure(resources) {
58
58
  resource.schemas.forEach((schema) => {
59
59
  const schemaCode = convertJsonToJs(schema);
60
60
  fs.writeFileSync(
61
- path.join(schemaDir, `${schema.name.toLowerCase()}.schema.js`),
61
+ path.join(schemaDir, `${schema.name.toLowerCase()}.schema.ts`),
62
62
  schemaCode
63
63
  );
64
64
  });
@@ -71,7 +71,7 @@ function generateProjectStructure(resources) {
71
71
  resource.endpoints.forEach((endpoint) => {
72
72
  const endpointCode = createEndpointCode(endpoint);
73
73
  fs.writeFileSync(
74
- path.join(endpointDir, `${endpoint.name}.js`),
74
+ path.join(endpointDir, `${endpoint.name}.ts`),
75
75
  endpointCode
76
76
  );
77
77
  });
@@ -84,7 +84,7 @@ function generateProjectStructure(resources) {
84
84
  resource.handlers.forEach((handler) => {
85
85
  const handlerCode = handler.handler;
86
86
  fs.writeFileSync(
87
- path.join(handlerDir, `${handler.name}.js`),
87
+ path.join(handlerDir, `${handler.name}.ts`),
88
88
  handlerCode
89
89
  );
90
90
  });
@@ -96,7 +96,7 @@ function generateProjectStructure(resources) {
96
96
  mkdirRecursive(methodDir);
97
97
  resource.methods.forEach((method) => {
98
98
  const methodCode = method.handler;
99
- fs.writeFileSync(path.join(methodDir, `${method.name}.js`), methodCode);
99
+ fs.writeFileSync(path.join(methodDir, `${method.name}.ts`), methodCode);
100
100
  });
101
101
  }
102
102
  });