@mantajs/core 0.1.7 → 0.2.0-beta.0

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 (566) hide show
  1. package/dist/adapters/auth-mock.d.ts +44 -0
  2. package/dist/adapters/auth-mock.d.ts.map +1 -0
  3. package/dist/adapters/auth-mock.js +160 -0
  4. package/dist/adapters/auth-mock.js.map +1 -0
  5. package/dist/adapters/cache-memory.d.ts +11 -0
  6. package/dist/adapters/cache-memory.d.ts.map +1 -0
  7. package/dist/adapters/cache-memory.js +32 -0
  8. package/dist/adapters/cache-memory.js.map +1 -0
  9. package/dist/adapters/database-memory.d.ts +24 -0
  10. package/dist/adapters/database-memory.d.ts.map +1 -0
  11. package/dist/adapters/database-memory.js +141 -0
  12. package/dist/adapters/database-memory.js.map +1 -0
  13. package/dist/adapters/eventbus-memory.d.ts +37 -0
  14. package/dist/adapters/eventbus-memory.d.ts.map +1 -0
  15. package/dist/adapters/eventbus-memory.js +166 -0
  16. package/dist/adapters/eventbus-memory.js.map +1 -0
  17. package/dist/adapters/file-memory.d.ts +24 -0
  18. package/dist/adapters/file-memory.d.ts.map +1 -0
  19. package/dist/adapters/file-memory.js +77 -0
  20. package/dist/adapters/file-memory.js.map +1 -0
  21. package/dist/adapters/http-memory.d.ts +23 -0
  22. package/dist/adapters/http-memory.d.ts.map +1 -0
  23. package/dist/adapters/http-memory.js +149 -0
  24. package/dist/adapters/http-memory.js.map +1 -0
  25. package/dist/adapters/index.d.ts +14 -0
  26. package/dist/adapters/index.d.ts.map +1 -0
  27. package/dist/adapters/index.js +15 -0
  28. package/dist/adapters/index.js.map +1 -0
  29. package/dist/adapters/job-scheduler-memory.d.ts +20 -0
  30. package/dist/adapters/job-scheduler-memory.d.ts.map +1 -0
  31. package/dist/adapters/job-scheduler-memory.js +103 -0
  32. package/dist/adapters/job-scheduler-memory.js.map +1 -0
  33. package/dist/adapters/locking-memory.d.ts +20 -0
  34. package/dist/adapters/locking-memory.d.ts.map +1 -0
  35. package/dist/adapters/locking-memory.js +85 -0
  36. package/dist/adapters/locking-memory.js.map +1 -0
  37. package/dist/adapters/logger-test.d.ts +30 -0
  38. package/dist/adapters/logger-test.d.ts.map +1 -0
  39. package/dist/adapters/logger-test.js +77 -0
  40. package/dist/adapters/logger-test.js.map +1 -0
  41. package/dist/adapters/notification-memory.d.ts +27 -0
  42. package/dist/adapters/notification-memory.d.ts.map +1 -0
  43. package/dist/adapters/notification-memory.js +69 -0
  44. package/dist/adapters/notification-memory.js.map +1 -0
  45. package/dist/adapters/relational-query-memory.d.ts +47 -0
  46. package/dist/adapters/relational-query-memory.d.ts.map +1 -0
  47. package/dist/adapters/relational-query-memory.js +263 -0
  48. package/dist/adapters/relational-query-memory.js.map +1 -0
  49. package/dist/adapters/repository-factory-memory.d.ts +17 -0
  50. package/dist/adapters/repository-factory-memory.d.ts.map +1 -0
  51. package/dist/adapters/repository-factory-memory.js +32 -0
  52. package/dist/adapters/repository-factory-memory.js.map +1 -0
  53. package/dist/adapters/repository-memory.d.ts +30 -0
  54. package/dist/adapters/repository-memory.d.ts.map +1 -0
  55. package/dist/adapters/repository-memory.js +183 -0
  56. package/dist/adapters/repository-memory.js.map +1 -0
  57. package/dist/ai/index.d.ts +53 -0
  58. package/dist/ai/index.d.ts.map +1 -0
  59. package/dist/ai/index.js +48 -0
  60. package/dist/ai/index.js.map +1 -0
  61. package/dist/app/index.d.ts +97 -0
  62. package/dist/app/index.d.ts.map +1 -0
  63. package/dist/app/index.js +217 -0
  64. package/dist/app/index.js.map +1 -0
  65. package/dist/app/request-context.d.ts +35 -0
  66. package/dist/app/request-context.d.ts.map +1 -0
  67. package/dist/app/request-context.js +32 -0
  68. package/dist/app/request-context.js.map +1 -0
  69. package/dist/auth/auth-module-service.d.ts +62 -0
  70. package/dist/auth/auth-module-service.d.ts.map +1 -0
  71. package/dist/auth/auth-module-service.js +210 -0
  72. package/dist/auth/auth-module-service.js.map +1 -0
  73. package/dist/auth/index.d.ts +7 -0
  74. package/dist/auth/index.d.ts.map +1 -0
  75. package/dist/auth/index.js +5 -0
  76. package/dist/auth/index.js.map +1 -0
  77. package/dist/auth/middleware.d.ts +19 -0
  78. package/dist/auth/middleware.d.ts.map +1 -0
  79. package/dist/auth/middleware.js +61 -0
  80. package/dist/auth/middleware.js.map +1 -0
  81. package/dist/auth/models/auth-identity.d.ts +11 -0
  82. package/dist/auth/models/auth-identity.d.ts.map +1 -0
  83. package/dist/auth/models/auth-identity.js +12 -0
  84. package/dist/auth/models/auth-identity.js.map +1 -0
  85. package/dist/auth/providers/emailpass.d.ts +7 -0
  86. package/dist/auth/providers/emailpass.d.ts.map +1 -0
  87. package/dist/auth/providers/emailpass.js +94 -0
  88. package/dist/auth/providers/emailpass.js.map +1 -0
  89. package/dist/auth/providers/types.d.ts +66 -0
  90. package/dist/auth/providers/types.d.ts.map +1 -0
  91. package/dist/auth/providers/types.js +3 -0
  92. package/dist/auth/providers/types.js.map +1 -0
  93. package/dist/auth/types.d.ts +36 -0
  94. package/dist/auth/types.d.ts.map +1 -0
  95. package/dist/auth/types.js +3 -0
  96. package/dist/auth/types.js.map +1 -0
  97. package/dist/command/define-command-graph.d.ts +63 -0
  98. package/dist/command/define-command-graph.d.ts.map +1 -0
  99. package/dist/command/define-command-graph.js +80 -0
  100. package/dist/command/define-command-graph.js.map +1 -0
  101. package/dist/command/dml-to-zod.d.ts +34 -0
  102. package/dist/command/dml-to-zod.d.ts.map +1 -0
  103. package/dist/command/dml-to-zod.js +140 -0
  104. package/dist/command/dml-to-zod.js.map +1 -0
  105. package/dist/command/generate-entity-commands.d.ts +68 -0
  106. package/dist/command/generate-entity-commands.d.ts.map +1 -0
  107. package/dist/command/generate-entity-commands.js +350 -0
  108. package/dist/command/generate-entity-commands.js.map +1 -0
  109. package/dist/command/index.d.ts +54 -0
  110. package/dist/command/index.d.ts.map +1 -0
  111. package/dist/command/index.js +338 -0
  112. package/dist/command/index.js.map +1 -0
  113. package/dist/command/types.d.ts +131 -0
  114. package/dist/command/types.d.ts.map +1 -0
  115. package/dist/command/types.js +2 -0
  116. package/dist/command/types.js.map +1 -0
  117. package/dist/config/built-in-presets.d.ts +20 -0
  118. package/dist/config/built-in-presets.d.ts.map +1 -0
  119. package/dist/config/built-in-presets.js +70 -0
  120. package/dist/config/built-in-presets.js.map +1 -0
  121. package/dist/config/config-manager.d.ts +117 -0
  122. package/dist/config/config-manager.d.ts.map +1 -0
  123. package/dist/config/config-manager.js +245 -0
  124. package/dist/config/config-manager.js.map +1 -0
  125. package/dist/config/define-config.d.ts +20 -0
  126. package/dist/config/define-config.d.ts.map +1 -0
  127. package/dist/config/define-config.js +64 -0
  128. package/dist/config/define-config.js.map +1 -0
  129. package/dist/config/feature-flags.d.ts +48 -0
  130. package/dist/config/feature-flags.d.ts.map +1 -0
  131. package/dist/config/feature-flags.js +97 -0
  132. package/dist/config/feature-flags.js.map +1 -0
  133. package/dist/config/index.d.ts +9 -0
  134. package/dist/config/index.d.ts.map +1 -0
  135. package/dist/config/index.js +8 -0
  136. package/dist/config/index.js.map +1 -0
  137. package/dist/config/presets.d.ts +38 -0
  138. package/dist/config/presets.d.ts.map +1 -0
  139. package/dist/config/presets.js +29 -0
  140. package/dist/config/presets.js.map +1 -0
  141. package/dist/config/types.d.ts +707 -0
  142. package/dist/config/types.d.ts.map +1 -0
  143. package/dist/config/types.js +112 -0
  144. package/dist/config/types.js.map +1 -0
  145. package/dist/context/index.d.ts +95 -0
  146. package/dist/context/index.d.ts.map +1 -0
  147. package/dist/context/index.js +26 -0
  148. package/dist/context/index.js.map +1 -0
  149. package/dist/context/registry.d.ts +32 -0
  150. package/dist/context/registry.d.ts.map +1 -0
  151. package/dist/context/registry.js +142 -0
  152. package/dist/context/registry.js.map +1 -0
  153. package/dist/db/index.d.ts +2 -0
  154. package/dist/db/index.d.ts.map +1 -0
  155. package/dist/db/index.js +4 -0
  156. package/dist/db/index.js.map +1 -0
  157. package/dist/db/schema.d.ts +839 -0
  158. package/dist/db/schema.d.ts.map +1 -0
  159. package/dist/db/schema.js +106 -0
  160. package/dist/db/schema.js.map +1 -0
  161. package/dist/dml/entity.d.ts +132 -0
  162. package/dist/dml/entity.d.ts.map +1 -0
  163. package/dist/dml/entity.js +110 -0
  164. package/dist/dml/entity.js.map +1 -0
  165. package/dist/dml/from-zod.d.ts +13 -0
  166. package/dist/dml/from-zod.d.ts.map +1 -0
  167. package/dist/dml/from-zod.js +81 -0
  168. package/dist/dml/from-zod.js.map +1 -0
  169. package/dist/dml/generator/index.d.ts +62 -0
  170. package/dist/dml/generator/index.d.ts.map +1 -0
  171. package/dist/dml/generator/index.js +208 -0
  172. package/dist/dml/generator/index.js.map +1 -0
  173. package/dist/dml/index.d.ts +11 -0
  174. package/dist/dml/index.d.ts.map +1 -0
  175. package/dist/dml/index.js +13 -0
  176. package/dist/dml/index.js.map +1 -0
  177. package/dist/dml/infer.d.ts +36 -0
  178. package/dist/dml/infer.d.ts.map +1 -0
  179. package/dist/dml/infer.js +5 -0
  180. package/dist/dml/infer.js.map +1 -0
  181. package/dist/dml/model.d.ts +58 -0
  182. package/dist/dml/model.d.ts.map +1 -0
  183. package/dist/dml/model.js +95 -0
  184. package/dist/dml/model.js.map +1 -0
  185. package/dist/dml/modifiers.d.ts +9 -0
  186. package/dist/dml/modifiers.d.ts.map +1 -0
  187. package/dist/dml/modifiers.js +25 -0
  188. package/dist/dml/modifiers.js.map +1 -0
  189. package/dist/dml/properties/array.d.ts +7 -0
  190. package/dist/dml/properties/array.d.ts.map +1 -0
  191. package/dist/dml/properties/array.js +5 -0
  192. package/dist/dml/properties/array.js.map +1 -0
  193. package/dist/dml/properties/autoincrement.d.ts +7 -0
  194. package/dist/dml/properties/autoincrement.d.ts.map +1 -0
  195. package/dist/dml/properties/autoincrement.js +5 -0
  196. package/dist/dml/properties/autoincrement.js.map +1 -0
  197. package/dist/dml/properties/base.d.ts +124 -0
  198. package/dist/dml/properties/base.d.ts.map +1 -0
  199. package/dist/dml/properties/base.js +76 -0
  200. package/dist/dml/properties/base.js.map +1 -0
  201. package/dist/dml/properties/big-number.d.ts +7 -0
  202. package/dist/dml/properties/big-number.d.ts.map +1 -0
  203. package/dist/dml/properties/big-number.js +5 -0
  204. package/dist/dml/properties/big-number.js.map +1 -0
  205. package/dist/dml/properties/boolean.d.ts +7 -0
  206. package/dist/dml/properties/boolean.d.ts.map +1 -0
  207. package/dist/dml/properties/boolean.js +5 -0
  208. package/dist/dml/properties/boolean.js.map +1 -0
  209. package/dist/dml/properties/computed.d.ts +9 -0
  210. package/dist/dml/properties/computed.d.ts.map +1 -0
  211. package/dist/dml/properties/computed.js +22 -0
  212. package/dist/dml/properties/computed.js.map +1 -0
  213. package/dist/dml/properties/date-time.d.ts +7 -0
  214. package/dist/dml/properties/date-time.d.ts.map +1 -0
  215. package/dist/dml/properties/date-time.js +5 -0
  216. package/dist/dml/properties/date-time.js.map +1 -0
  217. package/dist/dml/properties/enum.d.ts +12 -0
  218. package/dist/dml/properties/enum.d.ts.map +1 -0
  219. package/dist/dml/properties/enum.js +14 -0
  220. package/dist/dml/properties/enum.js.map +1 -0
  221. package/dist/dml/properties/float.d.ts +7 -0
  222. package/dist/dml/properties/float.d.ts.map +1 -0
  223. package/dist/dml/properties/float.js +5 -0
  224. package/dist/dml/properties/float.js.map +1 -0
  225. package/dist/dml/properties/index.d.ts +15 -0
  226. package/dist/dml/properties/index.d.ts.map +1 -0
  227. package/dist/dml/properties/index.js +15 -0
  228. package/dist/dml/properties/index.js.map +1 -0
  229. package/dist/dml/properties/json.d.ts +7 -0
  230. package/dist/dml/properties/json.d.ts.map +1 -0
  231. package/dist/dml/properties/json.js +6 -0
  232. package/dist/dml/properties/json.js.map +1 -0
  233. package/dist/dml/properties/nullable.d.ts +23 -0
  234. package/dist/dml/properties/nullable.d.ts.map +1 -0
  235. package/dist/dml/properties/nullable.js +46 -0
  236. package/dist/dml/properties/nullable.js.map +1 -0
  237. package/dist/dml/properties/number.d.ts +10 -0
  238. package/dist/dml/properties/number.d.ts.map +1 -0
  239. package/dist/dml/properties/number.js +13 -0
  240. package/dist/dml/properties/number.js.map +1 -0
  241. package/dist/dml/properties/primary-key.d.ts +14 -0
  242. package/dist/dml/properties/primary-key.d.ts.map +1 -0
  243. package/dist/dml/properties/primary-key.js +23 -0
  244. package/dist/dml/properties/primary-key.js.map +1 -0
  245. package/dist/dml/properties/text.d.ts +15 -0
  246. package/dist/dml/properties/text.d.ts.map +1 -0
  247. package/dist/dml/properties/text.js +19 -0
  248. package/dist/dml/properties/text.js.map +1 -0
  249. package/dist/dml/relations/belongs-to.d.ts +20 -0
  250. package/dist/dml/relations/belongs-to.d.ts.map +1 -0
  251. package/dist/dml/relations/belongs-to.js +29 -0
  252. package/dist/dml/relations/belongs-to.js.map +1 -0
  253. package/dist/dml/relations/has-many.d.ts +16 -0
  254. package/dist/dml/relations/has-many.d.ts.map +1 -0
  255. package/dist/dml/relations/has-many.js +25 -0
  256. package/dist/dml/relations/has-many.js.map +1 -0
  257. package/dist/dml/relations/has-one.d.ts +26 -0
  258. package/dist/dml/relations/has-one.d.ts.map +1 -0
  259. package/dist/dml/relations/has-one.js +46 -0
  260. package/dist/dml/relations/has-one.js.map +1 -0
  261. package/dist/dml/relations/many-to-many.d.ts +9 -0
  262. package/dist/dml/relations/many-to-many.d.ts.map +1 -0
  263. package/dist/dml/relations/many-to-many.js +11 -0
  264. package/dist/dml/relations/many-to-many.js.map +1 -0
  265. package/dist/errors/manta-error.d.ts +68 -0
  266. package/dist/errors/manta-error.d.ts.map +1 -0
  267. package/dist/errors/manta-error.js +80 -0
  268. package/dist/errors/manta-error.js.map +1 -0
  269. package/dist/events/index.d.ts +3 -0
  270. package/dist/events/index.d.ts.map +1 -0
  271. package/dist/events/index.js +3 -0
  272. package/dist/events/index.js.map +1 -0
  273. package/dist/events/message-aggregator.d.ts +25 -0
  274. package/dist/events/message-aggregator.d.ts.map +1 -0
  275. package/dist/events/message-aggregator.js +35 -0
  276. package/dist/events/message-aggregator.js.map +1 -0
  277. package/dist/events/types.d.ts +42 -0
  278. package/dist/events/types.d.ts.map +1 -0
  279. package/dist/events/types.js +3 -0
  280. package/dist/events/types.js.map +1 -0
  281. package/dist/index.d.ts +55 -0
  282. package/dist/index.d.ts.map +1 -0
  283. package/dist/index.js +53 -0
  284. package/dist/index.js.map +1 -0
  285. package/dist/job/index.d.ts +52 -0
  286. package/dist/job/index.d.ts.map +1 -0
  287. package/dist/job/index.js +31 -0
  288. package/dist/job/index.js.map +1 -0
  289. package/dist/link/index.d.ts +97 -0
  290. package/dist/link/index.d.ts.map +1 -0
  291. package/dist/link/index.js +185 -0
  292. package/dist/link/index.js.map +1 -0
  293. package/dist/middleware/define-middleware.d.ts +54 -0
  294. package/dist/middleware/define-middleware.d.ts.map +1 -0
  295. package/dist/middleware/define-middleware.js +40 -0
  296. package/dist/middleware/define-middleware.js.map +1 -0
  297. package/dist/middleware/index.d.ts +56 -0
  298. package/dist/middleware/index.d.ts.map +1 -0
  299. package/dist/middleware/index.js +50 -0
  300. package/dist/middleware/index.js.map +1 -0
  301. package/dist/module/index.d.ts +56 -0
  302. package/dist/module/index.d.ts.map +1 -0
  303. package/dist/module/index.js +52 -0
  304. package/dist/module/index.js.map +1 -0
  305. package/dist/module/versioning.d.ts +27 -0
  306. package/dist/module/versioning.d.ts.map +1 -0
  307. package/dist/module/versioning.js +64 -0
  308. package/dist/module/versioning.js.map +1 -0
  309. package/dist/naming.d.ts +39 -0
  310. package/dist/naming.d.ts.map +1 -0
  311. package/dist/naming.js +95 -0
  312. package/dist/naming.js.map +1 -0
  313. package/dist/ports/analytics.d.ts +7 -0
  314. package/dist/ports/analytics.d.ts.map +1 -0
  315. package/dist/ports/analytics.js +3 -0
  316. package/dist/ports/analytics.js.map +1 -0
  317. package/dist/ports/auth.d.ts +27 -0
  318. package/dist/ports/auth.d.ts.map +1 -0
  319. package/dist/ports/auth.js +3 -0
  320. package/dist/ports/auth.js.map +1 -0
  321. package/dist/ports/cache.d.ts +35 -0
  322. package/dist/ports/cache.d.ts.map +1 -0
  323. package/dist/ports/cache.js +3 -0
  324. package/dist/ports/cache.js.map +1 -0
  325. package/dist/ports/database.d.ts +40 -0
  326. package/dist/ports/database.d.ts.map +1 -0
  327. package/dist/ports/database.js +3 -0
  328. package/dist/ports/database.js.map +1 -0
  329. package/dist/ports/event-bus.d.ts +85 -0
  330. package/dist/ports/event-bus.d.ts.map +1 -0
  331. package/dist/ports/event-bus.js +3 -0
  332. package/dist/ports/event-bus.js.map +1 -0
  333. package/dist/ports/file.d.ts +62 -0
  334. package/dist/ports/file.d.ts.map +1 -0
  335. package/dist/ports/file.js +3 -0
  336. package/dist/ports/file.js.map +1 -0
  337. package/dist/ports/http.d.ts +20 -0
  338. package/dist/ports/http.d.ts.map +1 -0
  339. package/dist/ports/http.js +3 -0
  340. package/dist/ports/http.js.map +1 -0
  341. package/dist/ports/in-memory-progress-channel.d.ts +9 -0
  342. package/dist/ports/in-memory-progress-channel.d.ts.map +1 -0
  343. package/dist/ports/in-memory-progress-channel.js +19 -0
  344. package/dist/ports/in-memory-progress-channel.js.map +1 -0
  345. package/dist/ports/in-memory-queue.d.ts +24 -0
  346. package/dist/ports/in-memory-queue.d.ts.map +1 -0
  347. package/dist/ports/in-memory-queue.js +63 -0
  348. package/dist/ports/in-memory-queue.js.map +1 -0
  349. package/dist/ports/index.d.ts +27 -0
  350. package/dist/ports/index.d.ts.map +1 -0
  351. package/dist/ports/index.js +6 -0
  352. package/dist/ports/index.js.map +1 -0
  353. package/dist/ports/job-scheduler.d.ts +42 -0
  354. package/dist/ports/job-scheduler.d.ts.map +1 -0
  355. package/dist/ports/job-scheduler.js +3 -0
  356. package/dist/ports/job-scheduler.js.map +1 -0
  357. package/dist/ports/locking.d.ts +43 -0
  358. package/dist/ports/locking.d.ts.map +1 -0
  359. package/dist/ports/locking.js +3 -0
  360. package/dist/ports/locking.js.map +1 -0
  361. package/dist/ports/logger.d.ts +65 -0
  362. package/dist/ports/logger.d.ts.map +1 -0
  363. package/dist/ports/logger.js +3 -0
  364. package/dist/ports/logger.js.map +1 -0
  365. package/dist/ports/notification.d.ts +71 -0
  366. package/dist/ports/notification.d.ts.map +1 -0
  367. package/dist/ports/notification.js +3 -0
  368. package/dist/ports/notification.js.map +1 -0
  369. package/dist/ports/progress-channel.d.ts +46 -0
  370. package/dist/ports/progress-channel.d.ts.map +1 -0
  371. package/dist/ports/progress-channel.js +6 -0
  372. package/dist/ports/progress-channel.js.map +1 -0
  373. package/dist/ports/queue.d.ts +21 -0
  374. package/dist/ports/queue.d.ts.map +1 -0
  375. package/dist/ports/queue.js +15 -0
  376. package/dist/ports/queue.js.map +1 -0
  377. package/dist/ports/relational-query.d.ts +37 -0
  378. package/dist/ports/relational-query.d.ts.map +1 -0
  379. package/dist/ports/relational-query.js +3 -0
  380. package/dist/ports/relational-query.js.map +1 -0
  381. package/dist/ports/repository-factory.d.ts +21 -0
  382. package/dist/ports/repository-factory.d.ts.map +1 -0
  383. package/dist/ports/repository-factory.js +4 -0
  384. package/dist/ports/repository-factory.js.map +1 -0
  385. package/dist/ports/repository.d.ts +73 -0
  386. package/dist/ports/repository.d.ts.map +1 -0
  387. package/dist/ports/repository.js +3 -0
  388. package/dist/ports/repository.js.map +1 -0
  389. package/dist/ports/schema-generator.d.ts +15 -0
  390. package/dist/ports/schema-generator.d.ts.map +1 -0
  391. package/dist/ports/schema-generator.js +4 -0
  392. package/dist/ports/schema-generator.js.map +1 -0
  393. package/dist/ports/search.d.ts +7 -0
  394. package/dist/ports/search.d.ts.map +1 -0
  395. package/dist/ports/search.js +3 -0
  396. package/dist/ports/search.js.map +1 -0
  397. package/dist/ports/types.d.ts +112 -0
  398. package/dist/ports/types.d.ts.map +1 -0
  399. package/dist/ports/types.js +26 -0
  400. package/dist/ports/types.js.map +1 -0
  401. package/dist/ports/workflow-store.d.ts +111 -0
  402. package/dist/ports/workflow-store.d.ts.map +1 -0
  403. package/dist/ports/workflow-store.js +5 -0
  404. package/dist/ports/workflow-store.js.map +1 -0
  405. package/dist/query/define-query-graph.d.ts +55 -0
  406. package/dist/query/define-query-graph.d.ts.map +1 -0
  407. package/dist/query/define-query-graph.js +59 -0
  408. package/dist/query/define-query-graph.js.map +1 -0
  409. package/dist/query/define-query.d.ts +79 -0
  410. package/dist/query/define-query.d.ts.map +1 -0
  411. package/dist/query/define-query.js +77 -0
  412. package/dist/query/define-query.js.map +1 -0
  413. package/dist/query/extend-query-graph.d.ts +36 -0
  414. package/dist/query/extend-query-graph.d.ts.map +1 -0
  415. package/dist/query/extend-query-graph.js +34 -0
  416. package/dist/query/extend-query-graph.js.map +1 -0
  417. package/dist/query/index.d.ts +181 -0
  418. package/dist/query/index.d.ts.map +1 -0
  419. package/dist/query/index.js +288 -0
  420. package/dist/query/index.js.map +1 -0
  421. package/dist/service/define.d.ts +97 -0
  422. package/dist/service/define.d.ts.map +1 -0
  423. package/dist/service/define.js +45 -0
  424. package/dist/service/define.js.map +1 -0
  425. package/dist/service/index.d.ts +52 -0
  426. package/dist/service/index.d.ts.map +1 -0
  427. package/dist/service/index.js +281 -0
  428. package/dist/service/index.js.map +1 -0
  429. package/dist/service/instantiate.d.ts +15 -0
  430. package/dist/service/instantiate.d.ts.map +1 -0
  431. package/dist/service/instantiate.js +143 -0
  432. package/dist/service/instantiate.js.map +1 -0
  433. package/dist/service/snapshot-repository.d.ts +31 -0
  434. package/dist/service/snapshot-repository.d.ts.map +1 -0
  435. package/dist/service/snapshot-repository.js +114 -0
  436. package/dist/service/snapshot-repository.js.map +1 -0
  437. package/dist/service/types.d.ts +39 -0
  438. package/dist/service/types.d.ts.map +1 -0
  439. package/dist/service/types.js +3 -0
  440. package/dist/service/types.js.map +1 -0
  441. package/dist/strict-mode/index.d.ts +42 -0
  442. package/dist/strict-mode/index.d.ts.map +1 -0
  443. package/dist/strict-mode/index.js +84 -0
  444. package/dist/strict-mode/index.js.map +1 -0
  445. package/dist/subscriber/index.d.ts +117 -0
  446. package/dist/subscriber/index.d.ts.map +1 -0
  447. package/dist/subscriber/index.js +76 -0
  448. package/dist/subscriber/index.js.map +1 -0
  449. package/dist/testing/relational-query-suite.d.ts +22 -0
  450. package/dist/testing/relational-query-suite.d.ts.map +1 -0
  451. package/dist/testing/relational-query-suite.js +233 -0
  452. package/dist/testing/relational-query-suite.js.map +1 -0
  453. package/dist/user/auto-routes.d.ts +32 -0
  454. package/dist/user/auto-routes.d.ts.map +1 -0
  455. package/dist/user/auto-routes.js +424 -0
  456. package/dist/user/auto-routes.js.map +1 -0
  457. package/dist/user/define-user.d.ts +54 -0
  458. package/dist/user/define-user.d.ts.map +1 -0
  459. package/dist/user/define-user.js +103 -0
  460. package/dist/user/define-user.js.map +1 -0
  461. package/dist/user/index.d.ts +7 -0
  462. package/dist/user/index.d.ts.map +1 -0
  463. package/dist/user/index.js +5 -0
  464. package/dist/user/index.js.map +1 -0
  465. package/dist/user/models/user.d.ts +15 -0
  466. package/dist/user/models/user.d.ts.map +1 -0
  467. package/dist/user/models/user.js +16 -0
  468. package/dist/user/models/user.js.map +1 -0
  469. package/dist/user/user-module-service.d.ts +55 -0
  470. package/dist/user/user-module-service.d.ts.map +1 -0
  471. package/dist/user/user-module-service.js +100 -0
  472. package/dist/user/user-module-service.js.map +1 -0
  473. package/dist/workflows/ai-step.d.ts +2 -0
  474. package/dist/workflows/ai-step.d.ts.map +1 -0
  475. package/dist/workflows/ai-step.js +54 -0
  476. package/dist/workflows/ai-step.js.map +1 -0
  477. package/dist/workflows/create-step.d.ts +16 -0
  478. package/dist/workflows/create-step.d.ts.map +1 -0
  479. package/dist/workflows/create-step.js +194 -0
  480. package/dist/workflows/create-step.js.map +1 -0
  481. package/dist/workflows/create-workflow.d.ts +16 -0
  482. package/dist/workflows/create-workflow.d.ts.map +1 -0
  483. package/dist/workflows/create-workflow.js +21 -0
  484. package/dist/workflows/create-workflow.js.map +1 -0
  485. package/dist/workflows/define-workflow.d.ts +55 -0
  486. package/dist/workflows/define-workflow.d.ts.map +1 -0
  487. package/dist/workflows/define-workflow.js +72 -0
  488. package/dist/workflows/define-workflow.js.map +1 -0
  489. package/dist/workflows/emit-event-step.d.ts +17 -0
  490. package/dist/workflows/emit-event-step.d.ts.map +1 -0
  491. package/dist/workflows/emit-event-step.js +46 -0
  492. package/dist/workflows/emit-event-step.js.map +1 -0
  493. package/dist/workflows/for-each.d.ts +6 -0
  494. package/dist/workflows/for-each.d.ts.map +1 -0
  495. package/dist/workflows/for-each.js +79 -0
  496. package/dist/workflows/for-each.js.map +1 -0
  497. package/dist/workflows/index.d.ts +15 -0
  498. package/dist/workflows/index.d.ts.map +1 -0
  499. package/dist/workflows/index.js +12 -0
  500. package/dist/workflows/index.js.map +1 -0
  501. package/dist/workflows/manager.d.ts +99 -0
  502. package/dist/workflows/manager.d.ts.map +1 -0
  503. package/dist/workflows/manager.js +450 -0
  504. package/dist/workflows/manager.js.map +1 -0
  505. package/dist/workflows/orphan-reaper.d.ts +50 -0
  506. package/dist/workflows/orphan-reaper.d.ts.map +1 -0
  507. package/dist/workflows/orphan-reaper.js +69 -0
  508. package/dist/workflows/orphan-reaper.js.map +1 -0
  509. package/dist/workflows/progress-helper.d.ts +20 -0
  510. package/dist/workflows/progress-helper.d.ts.map +1 -0
  511. package/dist/workflows/progress-helper.js +48 -0
  512. package/dist/workflows/progress-helper.js.map +1 -0
  513. package/dist/workflows/step.d.ts +103 -0
  514. package/dist/workflows/step.d.ts.map +1 -0
  515. package/dist/workflows/step.js +949 -0
  516. package/dist/workflows/step.js.map +1 -0
  517. package/dist/workflows/types.d.ts +215 -0
  518. package/dist/workflows/types.d.ts.map +1 -0
  519. package/dist/workflows/types.js +9 -0
  520. package/dist/workflows/types.js.map +1 -0
  521. package/dist/workflows/yield.d.ts +12 -0
  522. package/dist/workflows/yield.d.ts.map +1 -0
  523. package/dist/workflows/yield.js +29 -0
  524. package/dist/workflows/yield.js.map +1 -0
  525. package/docs/00-overview.md +254 -0
  526. package/docs/01-getting-started.md +224 -0
  527. package/docs/02-models.md +163 -0
  528. package/docs/03-services.md +208 -0
  529. package/docs/04-users.md +165 -0
  530. package/docs/05-commands.md +501 -0
  531. package/docs/06-queries.md +342 -0
  532. package/docs/07-events.md +248 -0
  533. package/docs/08-links.md +182 -0
  534. package/docs/09-agents.md +142 -0
  535. package/docs/10-spa.md +327 -0
  536. package/docs/11-config.md +481 -0
  537. package/docs/12-constraints.md +183 -0
  538. package/docs/13-testing.md +345 -0
  539. package/docs/14-adapters.md +204 -0
  540. package/docs/15-hosts.md +163 -0
  541. package/docs/16-reference.md +274 -0
  542. package/docs/17-dashboard.md +619 -0
  543. package/docs/AGENT.md +501 -0
  544. package/package.json +49 -52
  545. package/.medusa/server/src/admin/index.js +0 -5493
  546. package/.medusa/server/src/admin/index.mjs +0 -5491
  547. package/.medusa/server/src/api/admin/companies/[id]/route.js +0 -39
  548. package/.medusa/server/src/api/admin/companies/middlewares.js +0 -41
  549. package/.medusa/server/src/api/admin/companies/route.js +0 -37
  550. package/.medusa/server/src/api/admin/companies/validators.js +0 -29
  551. package/.medusa/server/src/api/admin/employees/middlewares.js +0 -15
  552. package/.medusa/server/src/api/admin/employees/route.js +0 -21
  553. package/.medusa/server/src/api/middlewares.js +0 -9
  554. package/.medusa/server/src/index.js +0 -5
  555. package/.medusa/server/src/modules/company/index.js +0 -13
  556. package/.medusa/server/src/modules/company/migrations/Migration20260126141741.js +0 -26
  557. package/.medusa/server/src/modules/company/models/company.js +0 -24
  558. package/.medusa/server/src/modules/company/models/employee.js +0 -15
  559. package/.medusa/server/src/modules/company/models/index.js +0 -11
  560. package/.medusa/server/src/modules/company/service.js +0 -11
  561. package/.medusa/server/src/workflows/create-company.js +0 -10
  562. package/.medusa/server/src/workflows/delete-company.js +0 -10
  563. package/.medusa/server/src/workflows/steps/create-company.js +0 -16
  564. package/.medusa/server/src/workflows/steps/delete-company.js +0 -30
  565. package/.medusa/server/src/workflows/steps/update-company.js +0 -30
  566. package/.medusa/server/src/workflows/update-company.js +0 -10
@@ -0,0 +1,342 @@
1
+ # Queries — defineQuery() & defineQueryGraph()
2
+
3
+ Queries are the CQRS read side. They expose data as GET endpoints. Two primitives:
4
+
5
+ - `defineQuery()` — named query with custom handler (specific reads)
6
+ - `defineQueryGraph()` — expose the query graph to frontend (flexible reads)
7
+
8
+ ## defineQuery()
9
+
10
+ ```typescript
11
+ // src/queries/admin/list-products.ts
12
+ import { z } from 'zod'
13
+
14
+ export default defineQuery({
15
+ name: 'list-products',
16
+ description: 'List products with filtering',
17
+ input: z.object({
18
+ status: z.string().optional(),
19
+ ...listParams(),
20
+ }),
21
+ handler: async (input, { query, log, auth, headers }) => {
22
+ return query.graph({
23
+ entity: 'product',
24
+ filters: input.status ? { status: input.status } : undefined,
25
+ pagination: { take: input.limit, skip: input.offset },
26
+ })
27
+ },
28
+ })
29
+ ```
30
+
31
+ ### Signature
32
+
33
+ ```typescript
34
+ defineQuery({
35
+ name: string, // Query name (becomes the endpoint)
36
+ description: string, // For docs and AI tool discovery
37
+ input: z.ZodType, // Zod schema for input validation
38
+ handler: (input, ctx) => Promise<output>,
39
+ })
40
+ ```
41
+
42
+ ### Handler context
43
+
44
+ ```typescript
45
+ {
46
+ query: QueryService, // query.graph() for cross-module joins
47
+ log: ILoggerPort, // Structured logging
48
+ auth: AuthContext | null, // Authenticated user
49
+ headers: Record<string, string | undefined>, // Raw request headers
50
+ }
51
+ ```
52
+
53
+ **No `app` access** — queries are forced to use `query.graph()` for reads. This ensures consistent access control.
54
+
55
+ ### Routing
56
+
57
+ The folder name = the context:
58
+ ```
59
+ src/queries/admin/list-products.ts → GET /api/admin/list-products
60
+ src/queries/store/get-catalog.ts → GET /api/store/get-catalog
61
+ ```
62
+
63
+ Query parameters are passed as URL query string:
64
+ ```
65
+ GET /api/admin/list-products?status=active&limit=10&offset=0
66
+ ```
67
+
68
+ ### Input helpers
69
+
70
+ ```typescript
71
+ import { listParams, retrieveParams } from '@mantajs/sdk'
72
+
73
+ // listParams() adds: limit, offset, sort, order, search
74
+ z.object({
75
+ category: z.string().optional(),
76
+ ...listParams(), // { limit: 20, offset: 0, sort?, order: 'desc', search? }
77
+ })
78
+
79
+ // retrieveParams() adds: id, fields
80
+ z.object({
81
+ ...retrieveParams(), // { id: string, fields?: string[] }
82
+ })
83
+ ```
84
+
85
+ ### Auth in queries
86
+
87
+ ```typescript
88
+ handler: async (input, { query, auth }) => {
89
+ // auth.id — user ID
90
+ // auth.type — context ('admin', 'customer')
91
+ // auth.email — user email
92
+
93
+ // Example: only return MY orders
94
+ return query.graph({
95
+ entity: 'order',
96
+ filters: { customer_id: auth!.id },
97
+ })
98
+ }
99
+ ```
100
+
101
+ ## defineQueryGraph()
102
+
103
+ Exposes the query graph to the frontend. The frontend can compose arbitrary queries.
104
+
105
+ ### Wildcard — full access (admin/AI)
106
+
107
+ ```typescript
108
+ // src/queries/admin/graph.ts
109
+ export default defineQueryGraph('*')
110
+ ```
111
+
112
+ Creates `POST /api/admin/graph`. The frontend can query any entity with any filters, relations, pagination.
113
+
114
+ ### Scoped — per-entity access with row-level filtering
115
+
116
+ ```typescript
117
+ // src/queries/store/graph.ts
118
+ export default defineQueryGraph({
119
+ product: true, // all products, no filter
120
+ category: true, // all categories
121
+ order: (auth) => ({ customer_id: auth.id }), // only MY orders
122
+ customer: (auth) => ({ id: auth.id }), // only MY profile
123
+ })
124
+ ```
125
+
126
+ Creates `POST /api/store/graph` with access control:
127
+
128
+ | Entity | Access | Behavior |
129
+ |--------|--------|----------|
130
+ | Listed as `true` | All rows | No filter applied |
131
+ | Listed as function | Scoped rows | Function returns filters merged with user query |
132
+ | Not listed | Blocked | 403 Forbidden |
133
+ | Listed in `relations` but not allowed | Stripped | Warning logged in backend console |
134
+
135
+ ### Frontend usage
136
+
137
+ ```typescript
138
+ // Using @mantajs/sdk
139
+ const { data } = useGraphQuery({
140
+ entity: 'product',
141
+ filters: { status: 'active' },
142
+ relations: ['inventory_item'],
143
+ pagination: { limit: 20 },
144
+ sort: { field: 'created_at', order: 'desc' },
145
+ })
146
+ ```
147
+
148
+ ### Graph query body
149
+
150
+ ```json
151
+ POST /api/admin/graph
152
+ {
153
+ "entity": "product",
154
+ "filters": { "status": "active" },
155
+ "pagination": { "limit": 20, "offset": 0 },
156
+ "sort": { "field": "created_at", "order": "desc" },
157
+ "relations": ["inventory_item", "category"],
158
+ "fields": ["id", "title", "price", "status"]
159
+ }
160
+ ```
161
+
162
+ ### When to use defineQuery vs defineQueryGraph
163
+
164
+ | Use case | Primitive | Why |
165
+ |----------|-----------|-----|
166
+ | Admin dashboard | `defineQueryGraph('*')` | Admin sees everything, AI needs full access |
167
+ | Storefront public catalog | `defineQueryGraph({ product: true })` | Frontend composes queries freely, scoped |
168
+ | Storefront orders | `defineQuery` or scoped graph | Need row-level filtering by customer |
169
+ | Complex aggregation | `defineQuery` | Custom handler with business logic |
170
+ | API for third parties | `defineQuery` | Fixed contract, no graph exposure |
171
+
172
+ ## extendQueryGraph() — external entity resolvers
173
+
174
+ `extendQueryGraph()` plugs a **module-level resolver** into the query engine. It's how modules that own [external entities](./02-models.md#external-entities) (PostHog, Stripe, etc.) translate a Manta query graph request into a call to the third-party backend.
175
+
176
+ Unlike `defineQueryGraph()` — which controls **access per context** — `extendQueryGraph()` adds **new resolution paths** to the engine itself. When any entity listed in `owns` is queried (via `query.graph()`, `useGraphQuery`, or an AI tool), the engine routes the query to your resolver instead of hitting the local database.
177
+
178
+ ```typescript
179
+ // src/modules/posthog/queries/graph.ts
180
+ export default extendQueryGraph({
181
+ owns: ['PostHogEvent', 'PostHogPerson', 'PostHogInsight'],
182
+
183
+ async resolve(query, { app, logger }) {
184
+ // `query` is the Manta GraphQueryConfig: entity, filters, pagination, sort, fields...
185
+ // Translate it into a HogQL / REST call against PostHog, then return normalized rows.
186
+ const rows = await fetchFromPostHog(query)
187
+ return rows
188
+ },
189
+
190
+ // Optional: whitelist the filters your backend can honour. Unsupported filters
191
+ // will throw a clear error so the caller (or AI) can adapt its query.
192
+ supportedFilters: {
193
+ PostHogEvent: ['distinct_id', 'event', 'timestamp'],
194
+ PostHogPerson: ['id', 'email'],
195
+ },
196
+ })
197
+ ```
198
+
199
+ ### Signature
200
+
201
+ ```typescript
202
+ extendQueryGraph({
203
+ owns: string[], // Entity names this module resolves
204
+ resolve: (query, ctx) => Promise<Row[]>,
205
+ supportedFilters?: Record<string, string[]>,
206
+ })
207
+ ```
208
+
209
+ ### Resolver context
210
+
211
+ ```typescript
212
+ {
213
+ app: MantaApp, // Resolve plugin config, secrets, infra
214
+ logger: ILoggerPort, // Structured logging
215
+ }
216
+ ```
217
+
218
+ ### Rules
219
+
220
+ - File location: `src/modules/{module}/queries/graph.ts` (module-scoped — NOT in `src/queries/`).
221
+ - `owns` must be non-empty and list entities declared with `.external()` in the same module.
222
+ - `resolve` must return normalized rows whose shape matches the entity's `defineModel()` schema (keys == field names). The engine then applies relation hydration + access control as usual.
223
+ - Omit `supportedFilters` to accept everything (use at your own risk — the resolver is fully on the hook for validation).
224
+ - Local entities are still resolved by the database; only entities listed in `owns` are routed to the extension.
225
+
226
+ ### Relationship with defineLink
227
+
228
+ External entities linked to local ones via `defineLink()` are hydrated transparently: when a query requests `{ entity: 'product', relations: ['posthog_event'] }`, the engine first hits Drizzle for products, then calls the PostHog extension's `resolve()` with the event query — both halves merge in the final result.
229
+
230
+ ## Relation field syntax in query.graph()
231
+
232
+ The `fields` parameter in `query.graph()` supports a dot notation to eagerly load related entities:
233
+
234
+ ```typescript
235
+ // Load all product fields + all linked inventory items
236
+ return query.graph({
237
+ entity: 'product',
238
+ fields: ['*', 'inventory_items.*'],
239
+ })
240
+ ```
241
+
242
+ ### How it works
243
+
244
+ - `'*'` — all columns of the root entity
245
+ - `'relation.*'` — eagerly load all columns of the linked entity (uses the relation alias from `defineLink`)
246
+
247
+ ### M:N links
248
+
249
+ For many-to-many links, the relation field syntax loads through the pivot table and flattens results:
250
+
251
+ ```typescript
252
+ // Load customers with their addresses
253
+ return query.graph({
254
+ entity: 'customer',
255
+ fields: ['*', 'addresses.*'],
256
+ })
257
+ ```
258
+
259
+ If the link has extra columns (e.g., `type`, `is_default`), those pivot columns are merged into each target entity:
260
+
261
+ ```json
262
+ {
263
+ "id": "cust_123",
264
+ "name": "Alice",
265
+ "addresses": [
266
+ { "id": "addr_1", "street": "123 Main", "type": "shipping", "is_default": true },
267
+ { "id": "addr_2", "street": "456 Oak", "type": "billing", "is_default": false }
268
+ ]
269
+ }
270
+ ```
271
+
272
+ ### Relation pagination with relPagination
273
+
274
+ Use `relPagination` to paginate relation results independently from the root entity:
275
+
276
+ ```typescript
277
+ return query.graph({
278
+ entity: 'customer',
279
+ fields: ['*', 'orders.*'],
280
+ relPagination: {
281
+ orders: { take: 5, skip: 0 },
282
+ },
283
+ })
284
+ ```
285
+
286
+ This limits the eagerly loaded `orders` to 5 per customer, without affecting the root pagination.
287
+
288
+ ### Pagination limits and large result sets
289
+
290
+ `pagination.limit` defaults to **100** when unspecified. There is **no hard cap** — callers may request any limit — but the Drizzle relational query adapter will log a warning when `limit > 10000` for a single page, since paginating by offset across large result sets is inefficient.
291
+
292
+ ```typescript
293
+ // OK: small page
294
+ query.graph({ entity: 'order', pagination: { limit: 100, offset: 200 } })
295
+
296
+ // Warning logged: "DrizzleRelationalQuery: limit=15000 exceeds recommended
297
+ // maximum (10000) for entity 'order'. Consider cursor pagination."
298
+ query.graph({ entity: 'order', pagination: { limit: 15000 } })
299
+ ```
300
+
301
+ **Why the warning exists**: offset pagination scans all preceding rows on every page, so cost grows linearly with `offset`. For result sets > 10k, switch to keyset (cursor) pagination:
302
+
303
+ ```typescript
304
+ // Keyset: filter by the last seen id, constant time per page
305
+ query.graph({
306
+ entity: 'order',
307
+ filters: lastId ? { id: { $gt: lastId } } : undefined,
308
+ sort: { id: 'asc' },
309
+ pagination: { limit: 100 },
310
+ })
311
+ ```
312
+
313
+ **Counting large result sets**: `graphAndCount()` computes the exact count by default. For very large tables (> 100k rows), an exact count can be as expensive as the main query. A `countMode: 'exact' | 'capped' | 'estimated'` option is planned — see BACKLOG BC-F30 for the decision rationale. Until then, prefer `graph()` + infinite scrolling over `graphAndCount()` + paginated UIs on large tables.
314
+
315
+ ## Typed returns with generics
316
+
317
+ `query.graph()` and `query.graphAndCount()` accept an entity type parameter for end-to-end type safety:
318
+
319
+ ```typescript
320
+ // When codegen has run, the entity name is narrowed and the return type is inferred
321
+ const products = await query.graph({ entity: 'product' })
322
+ // => InferEntityResult<'product'>[] — fully typed with DML fields
323
+
324
+ const [orders, count] = await query.graphAndCount({ entity: 'order' })
325
+ // => [InferEntityResult<'order'>[], number]
326
+ ```
327
+
328
+ ### How it works
329
+
330
+ - **`EntityName`** — when codegen has populated `EntityRegistry`, this is a union of known entity names (e.g. `'product' | 'order'`). Without codegen, falls back to `string`.
331
+ - **`InferEntityResult<E>`** — resolves to the DML-inferred shape when `E` is a known registry key, otherwise `Record<string, unknown>`.
332
+ - **`GraphQueryConfig<E>`** — the `entity` field is typed as `E`, giving autocomplete on entity names.
333
+
334
+ This means `as any[]` casts on query results are no longer needed. The type flows from `defineModel` through codegen into query results.
335
+
336
+ ### Without codegen (development / tests)
337
+
338
+ If `EntityRegistry` is empty (no codegen), everything still works — `EntityName` is `string` and results are `Record<string, unknown>`. No breaking change.
339
+
340
+ ## No defineQueryGraph = no useGraphQuery
341
+
342
+ If you don't create a `graph.ts` in a context, `useGraphQuery()` from the SDK will receive a 404. The query graph must be explicitly enabled per context.
@@ -0,0 +1,248 @@
1
+ # Events & Workflows — defineSubscriber(), defineJob() & defineWorkflow()
2
+
3
+ ## Events in Manta
4
+
5
+ Events are the communication layer between modules. They decouple the "what happened" (command) from the "what should happen next" (subscriber).
6
+
7
+ ### Auto-generated events
8
+
9
+ Every CRUD operation emits events automatically:
10
+
11
+ | Operation | Event name | Data |
12
+ |-----------|-----------|------|
13
+ | `createProducts(data)` | `product.created` | `{ id }` |
14
+ | `updateProducts(data)` | `product.updated` | `{ id }` |
15
+ | `deleteProducts(ids)` | `product.deleted` | `{ id }` |
16
+
17
+ The event name is derived from the entity name: `Product` → `product.created`.
18
+
19
+ ### Manual events
20
+
21
+ In commands: `step.emit('event.name', data)` — buffered until workflow commits.
22
+
23
+ ## defineSubscriber()
24
+
25
+ ```typescript
26
+ export default defineSubscriber({
27
+ event: 'product.created',
28
+ handler: async (event, { command, log }) => {
29
+ const { id, sku } = event.data as { id: string; sku: string }
30
+ log.info(`Product created: ${sku}`)
31
+ await command.initializeInventory({ productId: id })
32
+ },
33
+ })
34
+ ```
35
+
36
+ **Signature:**
37
+ - `event` — Event name (string) or array of event names
38
+ - `handler` — `async (event, { command, log }) => void`
39
+ - `event` — `Message<T>` with `eventName`, `data`, `metadata`
40
+ - `command` — CQRS command callables (with autocomplete from codegen)
41
+ - `log` — Logger instance
42
+
43
+ ### Typed event data
44
+
45
+ Use the generic parameter to type `event.data`:
46
+
47
+ ```typescript
48
+ interface ProductCreatedEvent {
49
+ id: string
50
+ sku: string
51
+ title: string
52
+ price: number
53
+ }
54
+
55
+ export default defineSubscriber<ProductCreatedEvent>({
56
+ event: 'product.created',
57
+ handler: async (event, { command, log }) => {
58
+ event.data.sku // TS knows this is string
59
+ },
60
+ })
61
+ ```
62
+
63
+ ### Multiple events
64
+
65
+ ```typescript
66
+ export default defineSubscriber({
67
+ event: ['product.created', 'product.updated'],
68
+ handler: async (event, { log }) => {
69
+ log.info(`Product changed: ${event.eventName}`)
70
+ },
71
+ })
72
+ ```
73
+
74
+ ### Idempotency (at-least-once)
75
+
76
+ Events can be delivered more than once (at-least-once guarantee). Use `makeIdempotent()` to deduplicate:
77
+
78
+ ```typescript
79
+ export default defineSubscriber({
80
+ event: 'order.created',
81
+ handler: makeIdempotent(
82
+ cache, // ICachePort instance
83
+ async (event, { command, log }) => {
84
+ // Only executed once per unique event
85
+ await command.sendConfirmationEmail({ email: event.data.email })
86
+ },
87
+ {
88
+ keyFn: (event) => `order-confirm:${event.data.id}`, // Custom dedup key
89
+ ttl: 24 * 3600 * 1000, // 24 hours (default)
90
+ },
91
+ ),
92
+ })
93
+ ```
94
+
95
+ ### Delivery guarantees
96
+
97
+ - **At-least-once** — Events may be delivered more than once
98
+ - **No ordering** — In production (queue), events arrive in any order
99
+ - **Fire-and-forget** — Subscriber errors don't block the emitter
100
+ - **No compensation** — Subscribers cannot roll back
101
+
102
+ ## defineJob()
103
+
104
+ ```typescript
105
+ // Positional form (preferred)
106
+ export default defineJob('cleanup-draft-products', '0 * * * *', async ({ command, log }) => {
107
+ const result = await command.cleanupDraftProducts({ olderThanDays: 1 })
108
+ log.info(`Cleanup: ${result.deleted} draft products removed`)
109
+ return result
110
+ })
111
+ ```
112
+
113
+ Or using the config object form:
114
+
115
+ ```typescript
116
+ export default defineJob({
117
+ name: 'cleanup-draft-products',
118
+ schedule: '0 * * * *', // Every hour
119
+ handler: async ({ command, log }) => {
120
+ const result = await command.cleanupDraftProducts({ olderThanDays: 1 })
121
+ log.info(`Cleanup: ${result.deleted} draft products removed`)
122
+ return result
123
+ },
124
+ })
125
+ ```
126
+
127
+ **Signature (positional):** `defineJob(name, schedule, handler)`
128
+ **Signature (config):** `defineJob({ name, schedule, handler })`
129
+
130
+ - `name` — Unique job identifier
131
+ - `schedule` — Cron expression (5-field standard)
132
+ - `handler` — `async ({ command, log }) => TResult`
133
+ - `command` — CQRS command callables (same scope as subscribers)
134
+ - `log` — Logger instance
135
+
136
+ Jobs receive `{ command, log }` — the same scope as subscribers. Every mutation goes through a command (compensation, retry, audit trail). Jobs do NOT have direct access to `app` or module services.
137
+
138
+ ### Cron format
139
+
140
+ ```
141
+ ┌───────────── minute (0-59)
142
+ │ ┌───────────── hour (0-23)
143
+ │ │ ┌───────────── day of month (1-31)
144
+ │ │ │ ┌───────────── month (1-12)
145
+ │ │ │ │ ┌───────────── day of week (0-7, 0=Sun)
146
+ │ │ │ │ │
147
+ * * * * *
148
+ ```
149
+
150
+ Examples:
151
+ - `* * * * *` — Every minute
152
+ - `0 * * * *` — Every hour
153
+ - `0 0 * * *` — Every day at midnight
154
+ - `0 9 * * 1` — Every Monday at 9am
155
+ - `*/5 * * * *` — Every 5 minutes
156
+
157
+ ### Job locking
158
+
159
+ Concurrent job executions are automatically skipped via `ILockingPort`. If a job is already running, the next invocation returns immediately without executing.
160
+
161
+ ## Emitting events
162
+
163
+ In **commands**, events are buffered: `step.emit('event.name', data)` — only emitted if the workflow succeeds.
164
+
165
+ In **subscribers and jobs**, use commands to perform mutations. Events from auto-generated CRUD (e.g., `product.created`) are emitted automatically when commands call service methods.
166
+
167
+ ## defineWorkflow() — Intra-module business logic
168
+
169
+ A workflow is a compensable operation scoped to a single module. It orchestrates multiple entity services within the same module — pure business logic with no auth context.
170
+
171
+ ```typescript
172
+ // src/modules/catalog/workflows/categorize-product.ts
173
+ export default defineWorkflow({
174
+ name: 'categorize-product',
175
+ input: z.object({
176
+ productId: z.string(),
177
+ categoryId: z.string(),
178
+ }),
179
+ workflow: async (input, { step, log }) => {
180
+ const product = await step.service.catalog.retrieveProduct(input.productId)
181
+ await step.service.catalog.update(input.productId, { category_id: input.categoryId })
182
+ await step.emit('product.categorized', { id: product.id, categoryId: input.categoryId })
183
+ log.info(`Product ${product.id} categorized`)
184
+ return { productId: product.id }
185
+ },
186
+ })
187
+ ```
188
+
189
+ **Signature:** `defineWorkflow({ name, input, workflow })`
190
+
191
+ - `name` — Unique workflow identifier (kebab-case)
192
+ - `input` — Zod schema (validates input)
193
+ - `workflow` — `async (input, { step, log }) => TResult`
194
+ - `step` — Scoped step proxy (only this module's services)
195
+ - `log` — Logger instance
196
+
197
+ ### Key differences from defineCommand
198
+
199
+ | | defineCommand | defineWorkflow |
200
+ |---|---|---|
201
+ | **Location** | `src/commands/{ctx}/` | `src/modules/{mod}/workflows/` |
202
+ | **Context** | `{ step, log, auth, headers }` | `{ step, log }` |
203
+ | **Scope** | Any module | One module only |
204
+ | **HTTP endpoint** | Yes (`POST /api/...`) | No |
205
+ | **Auth** | Yes (`auth` param) | No |
206
+ | **Called from** | HTTP, CLI, sub-command | Commands via `step.workflow.MODULE.NAME()` |
207
+ | **Compensation** | Yes | Yes |
208
+
209
+ ### Calling workflows from commands
210
+
211
+ ```typescript
212
+ // src/commands/admin/create-and-categorize.ts
213
+ export default defineCommand({
214
+ name: 'create-and-categorize',
215
+ input: z.object({ title: z.string(), categoryId: z.string() }),
216
+ workflow: async (input, { step, auth }) => {
217
+ const product = await step.service.catalog.create({ title: input.title })
218
+ await step.workflow.catalog.categorizeProduct({
219
+ productId: product.id,
220
+ categoryId: input.categoryId,
221
+ })
222
+ return product
223
+ },
224
+ })
225
+ ```
226
+
227
+ The workflow runs within the command's compensation chain. If any step fails, all completed steps (including those inside the workflow) compensate in reverse order.
228
+
229
+ ## File locations
230
+
231
+ ```
232
+ src/subscribers/{name}.ts # defineSubscriber()
233
+ src/jobs/{name}.ts # defineJob()
234
+ src/modules/{mod}/workflows/{name}.ts # defineWorkflow()
235
+ ```
236
+
237
+ ## Validation errors
238
+
239
+ | Error | Cause | Fix |
240
+ |-------|-------|-----|
241
+ | `Subscriber event must be non-empty` | Empty event string | Set `event: 'product.created'` |
242
+ | `Subscriber handler must be a function` | handler is not async function | Set `handler: async (event, { command, log }) => {...}` |
243
+ | `Job name is required` | Missing name | Add `name: 'my-job'` |
244
+ | `Job schedule (cron expression) is required` | Missing schedule | Add `schedule: '0 * * * *'` |
245
+ | `Job handler must be a function` | handler is not function | Set `handler: async ({ command, log }) => {...}` |
246
+ | `Workflow name is required` | Missing name | Add `name: 'my-workflow'` |
247
+ | `Workflow "X" requires an input Zod schema` | Missing input | Add `input: z.object({})` |
248
+ | `Workflow "X" workflow must be an async function` | workflow is not a function | Add `workflow: async (input, { step, log }) => {...}` |