@effect-app/infra 4.0.0-beta.31 → 4.0.0-beta.310

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 (473) hide show
  1. package/CHANGELOG.md +2361 -0
  2. package/_check.sh +1 -1
  3. package/dist/CUPS.d.ts +29 -10
  4. package/dist/CUPS.d.ts.map +1 -1
  5. package/dist/CUPS.js +35 -14
  6. package/dist/ClusterCosmos.d.ts +64 -0
  7. package/dist/ClusterCosmos.d.ts.map +1 -0
  8. package/dist/ClusterCosmos.js +547 -0
  9. package/dist/ClusterServiceBus.d.ts +67 -0
  10. package/dist/ClusterServiceBus.d.ts.map +1 -0
  11. package/dist/ClusterServiceBus.js +82 -0
  12. package/dist/ContextProvider.d.ts +34 -0
  13. package/dist/ContextProvider.d.ts.map +1 -0
  14. package/dist/ContextProvider.js +40 -0
  15. package/dist/Emailer/Sendgrid.d.ts +110 -146
  16. package/dist/Emailer/Sendgrid.d.ts.map +1 -1
  17. package/dist/Emailer/Sendgrid.js +24 -19
  18. package/dist/Emailer/fake.d.ts +1 -1
  19. package/dist/Emailer/fake.d.ts.map +1 -1
  20. package/dist/Emailer/fake.js +4 -4
  21. package/dist/MainFiberSet.d.ts +12 -8
  22. package/dist/MainFiberSet.d.ts.map +1 -1
  23. package/dist/MainFiberSet.js +23 -7
  24. package/dist/QueueMaker/errors.d.ts +4 -2
  25. package/dist/QueueMaker/errors.d.ts.map +1 -1
  26. package/dist/QueueMaker/errors.js +4 -2
  27. package/dist/{adapters/SQL → SQL}/Model.d.ts +31 -42
  28. package/dist/SQL/Model.d.ts.map +1 -0
  29. package/dist/SQL/Model.js +469 -0
  30. package/dist/SQL.d.ts.map +1 -0
  31. package/dist/{adapters/SQL.js → SQL.js} +1 -1
  32. package/dist/Store/Cosmos/query.d.ts +14 -3
  33. package/dist/Store/Cosmos/query.d.ts.map +1 -1
  34. package/dist/Store/Cosmos/query.js +179 -41
  35. package/dist/Store/Cosmos.d.ts +2 -2
  36. package/dist/Store/Cosmos.d.ts.map +1 -1
  37. package/dist/Store/Cosmos.js +385 -254
  38. package/dist/Store/Disk.d.ts +4 -4
  39. package/dist/Store/Disk.d.ts.map +1 -1
  40. package/dist/Store/Disk.js +79 -39
  41. package/dist/Store/Memory.d.ts +5 -9
  42. package/dist/Store/Memory.d.ts.map +1 -1
  43. package/dist/Store/Memory.js +324 -67
  44. package/dist/Store/SQL/Pg.d.ts +4 -0
  45. package/dist/Store/SQL/Pg.d.ts.map +1 -0
  46. package/dist/Store/SQL/Pg.js +253 -0
  47. package/dist/Store/SQL/query.d.ts +49 -0
  48. package/dist/Store/SQL/query.d.ts.map +1 -0
  49. package/dist/Store/SQL/query.js +527 -0
  50. package/dist/Store/SQL.d.ts +21 -0
  51. package/dist/Store/SQL.d.ts.map +1 -0
  52. package/dist/Store/SQL.js +472 -0
  53. package/dist/Store/codeFilter.d.ts +4 -4
  54. package/dist/Store/codeFilter.d.ts.map +1 -1
  55. package/dist/Store/codeFilter.js +6 -4
  56. package/dist/Store/index.d.ts +6 -4
  57. package/dist/Store/index.d.ts.map +1 -1
  58. package/dist/Store/index.js +18 -5
  59. package/dist/Store/utils.d.ts +5 -2
  60. package/dist/Store/utils.d.ts.map +1 -1
  61. package/dist/Store/utils.js +9 -5
  62. package/dist/WorkflowEngineCosmos.d.ts +29 -0
  63. package/dist/WorkflowEngineCosmos.d.ts.map +1 -0
  64. package/dist/WorkflowEngineCosmos.js +542 -0
  65. package/dist/WorkflowEngineSqlite.d.ts +24 -0
  66. package/dist/WorkflowEngineSqlite.d.ts.map +1 -0
  67. package/dist/WorkflowEngineSqlite.js +550 -0
  68. package/dist/arbs.d.ts +1 -1
  69. package/dist/arbs.d.ts.map +1 -1
  70. package/dist/arbs.js +5 -3
  71. package/dist/codec.d.ts.map +1 -0
  72. package/dist/codec.js +5 -0
  73. package/dist/{adapters/cosmos-client.d.ts → cosmos-client.d.ts} +4 -2
  74. package/dist/cosmos-client.d.ts.map +1 -0
  75. package/dist/cosmos-client.js +11 -0
  76. package/dist/errorReporter.d.ts +6 -4
  77. package/dist/errorReporter.d.ts.map +1 -1
  78. package/dist/errorReporter.js +23 -27
  79. package/dist/fileUtil.d.ts +1 -1
  80. package/dist/fileUtil.d.ts.map +1 -1
  81. package/dist/fileUtil.js +2 -2
  82. package/dist/index.d.ts +2 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3 -2
  85. package/dist/internal/RequestContextMiddleware.d.ts +5 -0
  86. package/dist/internal/RequestContextMiddleware.d.ts.map +1 -0
  87. package/dist/internal/RequestContextMiddleware.js +45 -0
  88. package/dist/internal/auth.d.ts +53 -0
  89. package/dist/internal/auth.d.ts.map +1 -0
  90. package/dist/internal/auth.js +180 -0
  91. package/dist/internal/events.d.ts +11 -0
  92. package/dist/internal/events.d.ts.map +1 -0
  93. package/dist/internal/events.js +49 -0
  94. package/dist/internal/health.d.ts.map +1 -0
  95. package/dist/internal/health.js +5 -0
  96. package/dist/{api/layerUtils.d.ts → layerUtils.d.ts} +14 -6
  97. package/dist/layerUtils.d.ts.map +1 -0
  98. package/dist/layerUtils.js +17 -0
  99. package/dist/logger/jsonLogger.d.ts +1 -1
  100. package/dist/logger/jsonLogger.d.ts.map +1 -1
  101. package/dist/logger/jsonLogger.js +5 -3
  102. package/dist/logger/logFmtLogger.d.ts +1 -1
  103. package/dist/logger/logFmtLogger.d.ts.map +1 -1
  104. package/dist/logger/logFmtLogger.js +3 -3
  105. package/dist/logger/shared.d.ts +2 -2
  106. package/dist/logger/shared.d.ts.map +1 -1
  107. package/dist/logger/shared.js +5 -5
  108. package/dist/logger.d.ts.map +1 -1
  109. package/dist/middlewares.d.ts.map +1 -0
  110. package/dist/{api/middlewares.js → middlewares.js} +1 -1
  111. package/dist/{adapters/mongo-client.d.ts → mongo-client.d.ts} +3 -2
  112. package/dist/mongo-client.d.ts.map +1 -0
  113. package/dist/mongo-client.js +15 -0
  114. package/dist/otel.d.ts +75 -0
  115. package/dist/otel.d.ts.map +1 -0
  116. package/dist/otel.js +84 -0
  117. package/dist/rateLimit.d.ts +11 -3
  118. package/dist/rateLimit.d.ts.map +1 -1
  119. package/dist/rateLimit.js +7 -12
  120. package/dist/{adapters/redis-client.d.ts → redis-client.d.ts} +5 -2
  121. package/dist/redis-client.d.ts.map +1 -0
  122. package/dist/redis-client.js +98 -0
  123. package/dist/{api/reportError.d.ts → reportError.d.ts} +1 -1
  124. package/dist/reportError.d.ts.map +1 -0
  125. package/dist/reportError.js +28 -0
  126. package/dist/{api/routing → routing}/middleware/RouterMiddleware.d.ts +4 -3
  127. package/dist/routing/middleware/RouterMiddleware.d.ts.map +1 -0
  128. package/dist/{api/routing → routing}/middleware/RouterMiddleware.js +1 -1
  129. package/dist/routing/middleware/middleware.d.ts +48 -0
  130. package/dist/routing/middleware/middleware.d.ts.map +1 -0
  131. package/dist/routing/middleware/middleware.js +152 -0
  132. package/dist/{api/routing → routing}/middleware.d.ts +0 -1
  133. package/dist/routing/middleware.d.ts.map +1 -0
  134. package/dist/{api/routing → routing}/middleware.js +1 -2
  135. package/dist/routing/schema/jwt.d.ts.map +1 -0
  136. package/dist/routing/schema/jwt.js +13 -0
  137. package/dist/routing/tsort.d.ts.map +1 -0
  138. package/dist/routing/tsort.js +51 -0
  139. package/dist/{api/routing → routing}/utils.d.ts +3 -3
  140. package/dist/routing/utils.d.ts.map +1 -0
  141. package/dist/routing/utils.js +45 -0
  142. package/dist/routing.d.ts +182 -0
  143. package/dist/routing.d.ts.map +1 -0
  144. package/dist/routing.js +256 -0
  145. package/dist/test.d.ts +2 -2
  146. package/dist/test.d.ts.map +1 -1
  147. package/dist/test.js +2 -2
  148. package/dist/util.d.ts.map +1 -0
  149. package/dist/util.js +14 -0
  150. package/docs/cluster-storage.md +26 -0
  151. package/docs/workflow-engine.md +262 -0
  152. package/examples/query.ts +47 -39
  153. package/package.json +38 -352
  154. package/src/CUPS.ts +53 -14
  155. package/src/ClusterCosmos.ts +1118 -0
  156. package/src/ClusterServiceBus.ts +242 -0
  157. package/src/{api/ContextProvider.ts → ContextProvider.ts} +20 -17
  158. package/src/Emailer/Sendgrid.ts +83 -60
  159. package/src/Emailer/fake.ts +4 -4
  160. package/src/MainFiberSet.ts +32 -13
  161. package/src/QueueMaker/errors.ts +3 -1
  162. package/src/{adapters/SQL → SQL}/Model.ts +42 -41
  163. package/src/SQL.ts +1 -0
  164. package/src/Store/Cosmos/query.ts +218 -54
  165. package/src/Store/Cosmos.ts +529 -365
  166. package/src/Store/Disk.ts +112 -70
  167. package/src/Store/Memory.ts +365 -99
  168. package/src/Store/SQL/Pg.ts +389 -0
  169. package/src/Store/SQL/query.ts +603 -0
  170. package/src/Store/SQL.ts +766 -0
  171. package/src/Store/codeFilter.ts +8 -6
  172. package/src/Store/index.ts +25 -10
  173. package/src/Store/utils.ts +32 -25
  174. package/src/WorkflowEngineCosmos.ts +749 -0
  175. package/src/WorkflowEngineSqlite.ts +813 -0
  176. package/src/arbs.ts +5 -3
  177. package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
  178. package/src/errorReporter.ts +68 -78
  179. package/src/fileUtil.ts +1 -1
  180. package/src/index.ts +2 -1
  181. package/src/{api/internal → internal}/RequestContextMiddleware.ts +23 -6
  182. package/src/internal/auth.ts +272 -0
  183. package/src/{api/internal → internal}/events.ts +22 -13
  184. package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
  185. package/src/logger/jsonLogger.ts +5 -3
  186. package/src/logger/logFmtLogger.ts +3 -3
  187. package/src/logger/shared.ts +5 -4
  188. package/src/middlewares.ts +10 -0
  189. package/src/{adapters/mongo-client.ts → mongo-client.ts} +4 -2
  190. package/src/otel.ts +177 -0
  191. package/src/rateLimit.ts +34 -23
  192. package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
  193. package/src/{api/reportError.ts → reportError.ts} +3 -2
  194. package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
  195. package/src/routing/middleware/middleware.ts +196 -0
  196. package/src/routing/middleware.ts +4 -0
  197. package/src/{api/routing → routing}/schema/jwt.ts +2 -1
  198. package/src/{api/routing → routing}/utils.ts +2 -1
  199. package/src/routing.ts +823 -0
  200. package/src/test.ts +4 -4
  201. package/src/vitest.ts +1 -1
  202. package/test/auth.test.ts +101 -0
  203. package/test/cluster-cosmos.test.ts +612 -0
  204. package/test/cluster-servicebus.test.ts +180 -0
  205. package/test/cluster-sqlite.test.ts +205 -0
  206. package/test/contextProvider.test.ts +15 -12
  207. package/test/controller.test.ts +28 -32
  208. package/test/cosmos-query.test.ts +228 -0
  209. package/test/dist/auth.test.d.ts.map +1 -0
  210. package/test/dist/cluster-cosmos.test.d.ts.map +1 -0
  211. package/test/dist/cluster-servicebus.test.d.ts.map +1 -0
  212. package/test/dist/cluster-sqlite.test.d.ts.map +1 -0
  213. package/test/dist/contextProvider.test.d.ts.map +1 -1
  214. package/test/dist/controller.test.d.ts.map +1 -1
  215. package/test/dist/cosmos-query.test.d.ts.map +1 -0
  216. package/test/dist/fixtures.d.ts +29 -11
  217. package/test/dist/fixtures.d.ts.map +1 -1
  218. package/test/dist/fixtures.js +17 -10
  219. package/test/dist/query.test.d.ts.map +1 -1
  220. package/test/dist/rawQuery.test.d.ts.map +1 -1
  221. package/test/dist/repository-ext.test.d.ts.map +1 -0
  222. package/test/dist/requires.test.d.ts.map +1 -1
  223. package/test/dist/router-generator.test.d.ts.map +1 -0
  224. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  225. package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
  226. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  227. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  228. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  229. package/test/dist/sql-store.test.d.ts.map +1 -0
  230. package/test/dist/workflow-engine-cosmos.test.d.ts.map +1 -0
  231. package/test/dist/workflow-engine-sqlite.test.d.ts.map +1 -0
  232. package/test/fixtures.ts +16 -9
  233. package/test/layerUtils.test.ts +2 -2
  234. package/test/query.test.ts +1130 -41
  235. package/test/rawQuery.test.ts +340 -22
  236. package/test/repository-ext.test.ts +426 -0
  237. package/test/requires.test.ts +10 -5
  238. package/test/router-generator.test.ts +187 -0
  239. package/test/routing-interruptibility.test.ts +66 -0
  240. package/test/rpc-context-map-streaming.test.ts +262 -0
  241. package/test/rpc-e2e-invalidation.test.ts +418 -0
  242. package/test/rpc-multi-middleware.test.ts +85 -10
  243. package/test/rpc-stream-fullstack.test.ts +304 -0
  244. package/test/sql-store.test.ts +1711 -0
  245. package/test/validateSample.test.ts +26 -14
  246. package/test/workflow-engine-cosmos.test.ts +345 -0
  247. package/test/workflow-engine-sqlite.test.ts +297 -0
  248. package/tsconfig.examples.json +1 -1
  249. package/tsconfig.json +9 -2
  250. package/tsconfig.src.json +35 -35
  251. package/tsconfig.test.json +2 -2
  252. package/dist/Emailer/service.d.ts +0 -55
  253. package/dist/Emailer/service.d.ts.map +0 -1
  254. package/dist/Emailer/service.js +0 -6
  255. package/dist/Emailer.d.ts +0 -2
  256. package/dist/Emailer.d.ts.map +0 -1
  257. package/dist/Emailer.js +0 -2
  258. package/dist/Model/Repository/ext.d.ts +0 -41
  259. package/dist/Model/Repository/ext.d.ts.map +0 -1
  260. package/dist/Model/Repository/ext.js +0 -65
  261. package/dist/Model/Repository/internal/internal.d.ts +0 -59
  262. package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
  263. package/dist/Model/Repository/internal/internal.js +0 -316
  264. package/dist/Model/Repository/legacy.d.ts +0 -19
  265. package/dist/Model/Repository/legacy.d.ts.map +0 -1
  266. package/dist/Model/Repository/legacy.js +0 -2
  267. package/dist/Model/Repository/makeRepo.d.ts +0 -49
  268. package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
  269. package/dist/Model/Repository/makeRepo.js +0 -24
  270. package/dist/Model/Repository/service.d.ts +0 -89
  271. package/dist/Model/Repository/service.d.ts.map +0 -1
  272. package/dist/Model/Repository/service.js +0 -2
  273. package/dist/Model/Repository/validation.d.ts +0 -42
  274. package/dist/Model/Repository/validation.d.ts.map +0 -1
  275. package/dist/Model/Repository/validation.js +0 -32
  276. package/dist/Model/Repository.d.ts +0 -6
  277. package/dist/Model/Repository.d.ts.map +0 -1
  278. package/dist/Model/Repository.js +0 -6
  279. package/dist/Model/dsl.d.ts +0 -32
  280. package/dist/Model/dsl.d.ts.map +0 -1
  281. package/dist/Model/dsl.js +0 -44
  282. package/dist/Model/filter/filterApi.d.ts +0 -30
  283. package/dist/Model/filter/filterApi.d.ts.map +0 -1
  284. package/dist/Model/filter/filterApi.js +0 -2
  285. package/dist/Model/filter/types/errors.d.ts +0 -29
  286. package/dist/Model/filter/types/errors.d.ts.map +0 -1
  287. package/dist/Model/filter/types/errors.js +0 -2
  288. package/dist/Model/filter/types/fields.d.ts +0 -15
  289. package/dist/Model/filter/types/fields.d.ts.map +0 -1
  290. package/dist/Model/filter/types/fields.js +0 -2
  291. package/dist/Model/filter/types/path/common.d.ts +0 -316
  292. package/dist/Model/filter/types/path/common.d.ts.map +0 -1
  293. package/dist/Model/filter/types/path/common.js +0 -2
  294. package/dist/Model/filter/types/path/eager.d.ts +0 -95
  295. package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
  296. package/dist/Model/filter/types/path/eager.js +0 -31
  297. package/dist/Model/filter/types/path/index.d.ts +0 -4
  298. package/dist/Model/filter/types/path/index.d.ts.map +0 -1
  299. package/dist/Model/filter/types/path/index.js +0 -3
  300. package/dist/Model/filter/types/utils.d.ts +0 -79
  301. package/dist/Model/filter/types/utils.d.ts.map +0 -1
  302. package/dist/Model/filter/types/utils.js +0 -2
  303. package/dist/Model/filter/types/validator.d.ts +0 -30
  304. package/dist/Model/filter/types/validator.d.ts.map +0 -1
  305. package/dist/Model/filter/types/validator.js +0 -2
  306. package/dist/Model/filter/types.d.ts +0 -5
  307. package/dist/Model/filter/types.d.ts.map +0 -1
  308. package/dist/Model/filter/types.js +0 -7
  309. package/dist/Model/query/dsl.d.ts +0 -248
  310. package/dist/Model/query/dsl.d.ts.map +0 -1
  311. package/dist/Model/query/dsl.js +0 -104
  312. package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
  313. package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
  314. package/dist/Model/query/new-kid-interpreter.js +0 -165
  315. package/dist/Model/query.d.ts +0 -15
  316. package/dist/Model/query.d.ts.map +0 -1
  317. package/dist/Model/query.js +0 -3
  318. package/dist/Model.d.ts +0 -4
  319. package/dist/Model.d.ts.map +0 -1
  320. package/dist/Model.js +0 -4
  321. package/dist/Operations.d.ts +0 -55
  322. package/dist/Operations.d.ts.map +0 -1
  323. package/dist/Operations.js +0 -102
  324. package/dist/OperationsRepo.d.ts +0 -41
  325. package/dist/OperationsRepo.d.ts.map +0 -1
  326. package/dist/OperationsRepo.js +0 -14
  327. package/dist/QueueMaker/SQLQueue.d.ts +0 -16
  328. package/dist/QueueMaker/SQLQueue.d.ts.map +0 -1
  329. package/dist/QueueMaker/SQLQueue.js +0 -130
  330. package/dist/QueueMaker/memQueue.d.ts +0 -11
  331. package/dist/QueueMaker/memQueue.d.ts.map +0 -1
  332. package/dist/QueueMaker/memQueue.js +0 -76
  333. package/dist/QueueMaker/sbqueue.d.ts +0 -12
  334. package/dist/QueueMaker/sbqueue.d.ts.map +0 -1
  335. package/dist/QueueMaker/sbqueue.js +0 -91
  336. package/dist/QueueMaker/service.d.ts +0 -11
  337. package/dist/QueueMaker/service.d.ts.map +0 -1
  338. package/dist/QueueMaker/service.js +0 -4
  339. package/dist/RequestContext.d.ts +0 -63
  340. package/dist/RequestContext.d.ts.map +0 -1
  341. package/dist/RequestContext.js +0 -49
  342. package/dist/RequestFiberSet.d.ts +0 -36
  343. package/dist/RequestFiberSet.d.ts.map +0 -1
  344. package/dist/RequestFiberSet.js +0 -78
  345. package/dist/Store/ContextMapContainer.d.ts +0 -14
  346. package/dist/Store/ContextMapContainer.d.ts.map +0 -1
  347. package/dist/Store/ContextMapContainer.js +0 -16
  348. package/dist/Store/service.d.ts +0 -108
  349. package/dist/Store/service.d.ts.map +0 -1
  350. package/dist/Store/service.js +0 -71
  351. package/dist/Store.d.ts +0 -2
  352. package/dist/Store.d.ts.map +0 -1
  353. package/dist/Store.js +0 -2
  354. package/dist/adapters/SQL/Model.d.ts.map +0 -1
  355. package/dist/adapters/SQL/Model.js +0 -478
  356. package/dist/adapters/SQL.d.ts.map +0 -1
  357. package/dist/adapters/ServiceBus.d.ts +0 -58
  358. package/dist/adapters/ServiceBus.d.ts.map +0 -1
  359. package/dist/adapters/ServiceBus.js +0 -99
  360. package/dist/adapters/cosmos-client.d.ts.map +0 -1
  361. package/dist/adapters/cosmos-client.js +0 -9
  362. package/dist/adapters/index.d.ts +0 -2
  363. package/dist/adapters/index.d.ts.map +0 -1
  364. package/dist/adapters/index.js +0 -2
  365. package/dist/adapters/logger.d.ts +0 -9
  366. package/dist/adapters/logger.d.ts.map +0 -1
  367. package/dist/adapters/logger.js +0 -3
  368. package/dist/adapters/memQueue.d.ts +0 -13
  369. package/dist/adapters/memQueue.d.ts.map +0 -1
  370. package/dist/adapters/memQueue.js +0 -20
  371. package/dist/adapters/mongo-client.d.ts.map +0 -1
  372. package/dist/adapters/mongo-client.js +0 -13
  373. package/dist/adapters/redis-client.d.ts.map +0 -1
  374. package/dist/adapters/redis-client.js +0 -94
  375. package/dist/api/ContextProvider.d.ts +0 -31
  376. package/dist/api/ContextProvider.d.ts.map +0 -1
  377. package/dist/api/ContextProvider.js +0 -38
  378. package/dist/api/codec.d.ts.map +0 -1
  379. package/dist/api/codec.js +0 -5
  380. package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
  381. package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
  382. package/dist/api/internal/RequestContextMiddleware.js +0 -35
  383. package/dist/api/internal/auth.d.ts +0 -15
  384. package/dist/api/internal/auth.d.ts.map +0 -1
  385. package/dist/api/internal/auth.js +0 -47
  386. package/dist/api/internal/events.d.ts +0 -9
  387. package/dist/api/internal/events.d.ts.map +0 -1
  388. package/dist/api/internal/events.js +0 -42
  389. package/dist/api/internal/health.d.ts.map +0 -1
  390. package/dist/api/internal/health.js +0 -5
  391. package/dist/api/layerUtils.d.ts.map +0 -1
  392. package/dist/api/layerUtils.js +0 -16
  393. package/dist/api/middlewares.d.ts.map +0 -1
  394. package/dist/api/reportError.d.ts.map +0 -1
  395. package/dist/api/reportError.js +0 -27
  396. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
  397. package/dist/api/routing/middleware/middleware.d.ts +0 -9
  398. package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
  399. package/dist/api/routing/middleware/middleware.js +0 -92
  400. package/dist/api/routing/middleware.d.ts.map +0 -1
  401. package/dist/api/routing/schema/jwt.d.ts.map +0 -1
  402. package/dist/api/routing/schema/jwt.js +0 -12
  403. package/dist/api/routing/tsort.d.ts.map +0 -1
  404. package/dist/api/routing/tsort.js +0 -51
  405. package/dist/api/routing/utils.d.ts.map +0 -1
  406. package/dist/api/routing/utils.js +0 -44
  407. package/dist/api/routing.d.ts +0 -138
  408. package/dist/api/routing.d.ts.map +0 -1
  409. package/dist/api/routing.js +0 -166
  410. package/dist/api/setupRequest.d.ts +0 -12
  411. package/dist/api/setupRequest.d.ts.map +0 -1
  412. package/dist/api/setupRequest.js +0 -44
  413. package/dist/api/util.d.ts.map +0 -1
  414. package/dist/api/util.js +0 -14
  415. package/eslint.config.mjs +0 -24
  416. package/src/Emailer/service.ts +0 -52
  417. package/src/Emailer.ts +0 -1
  418. package/src/Model/Repository/ext.ts +0 -283
  419. package/src/Model/Repository/internal/internal.ts +0 -577
  420. package/src/Model/Repository/legacy.ts +0 -27
  421. package/src/Model/Repository/makeRepo.ts +0 -139
  422. package/src/Model/Repository/service.ts +0 -627
  423. package/src/Model/Repository/validation.ts +0 -31
  424. package/src/Model/Repository.ts +0 -5
  425. package/src/Model/dsl.ts +0 -128
  426. package/src/Model/filter/filterApi.ts +0 -60
  427. package/src/Model/filter/types/errors.ts +0 -47
  428. package/src/Model/filter/types/fields.ts +0 -50
  429. package/src/Model/filter/types/path/common.ts +0 -404
  430. package/src/Model/filter/types/path/eager.ts +0 -298
  431. package/src/Model/filter/types/path/index.ts +0 -4
  432. package/src/Model/filter/types/utils.ts +0 -128
  433. package/src/Model/filter/types/validator.ts +0 -46
  434. package/src/Model/filter/types.ts +0 -6
  435. package/src/Model/query/dsl.ts +0 -2110
  436. package/src/Model/query/new-kid-interpreter.ts +0 -210
  437. package/src/Model/query.ts +0 -13
  438. package/src/Model.ts +0 -3
  439. package/src/Operations.ts +0 -235
  440. package/src/OperationsRepo.ts +0 -16
  441. package/src/QueueMaker/SQLQueue.ts +0 -189
  442. package/src/QueueMaker/memQueue.ts +0 -130
  443. package/src/QueueMaker/sbqueue.ts +0 -137
  444. package/src/QueueMaker/service.ts +0 -17
  445. package/src/RequestContext.ts +0 -63
  446. package/src/RequestFiberSet.ts +0 -105
  447. package/src/Store/ContextMapContainer.ts +0 -20
  448. package/src/Store/index.test.ts.bak +0 -112
  449. package/src/Store/service.ts +0 -184
  450. package/src/Store.ts +0 -1
  451. package/src/adapters/SQL.ts +0 -1
  452. package/src/adapters/ServiceBus.ts +0 -209
  453. package/src/adapters/index.ts +0 -0
  454. package/src/adapters/logger.ts +0 -3
  455. package/src/adapters/memQueue.ts +0 -21
  456. package/src/api/internal/auth.ts +0 -68
  457. package/src/api/middlewares.ts +0 -10
  458. package/src/api/routing/middleware/middleware.ts +0 -128
  459. package/src/api/routing/middleware.ts +0 -6
  460. package/src/api/routing.ts +0 -598
  461. package/src/api/setupRequest.ts +0 -84
  462. package/tsconfig.json.bak +0 -12
  463. /package/dist/{adapters/SQL.d.ts → SQL.d.ts} +0 -0
  464. /package/dist/{api/codec.d.ts → codec.d.ts} +0 -0
  465. /package/dist/{api/internal → internal}/health.d.ts +0 -0
  466. /package/dist/{api/middlewares.d.ts → middlewares.d.ts} +0 -0
  467. /package/dist/{api/routing → routing}/schema/jwt.d.ts +0 -0
  468. /package/dist/{api/routing → routing}/tsort.d.ts +0 -0
  469. /package/dist/{api/util.d.ts → util.d.ts} +0 -0
  470. /package/src/{api/codec.ts → codec.ts} +0 -0
  471. /package/src/{api/internal → internal}/health.ts +0 -0
  472. /package/src/{api/routing → routing}/tsort.ts +0 -0
  473. /package/src/{api/util.ts → util.ts} +0 -0
package/src/routing.ts ADDED
@@ -0,0 +1,823 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ import * as Array from "effect-app/Array"
6
+ import type { NonEmptyReadonlyArray } from "effect-app/Array"
7
+ import { getMeta } from "effect-app/client"
8
+ import * as Config from "effect-app/Config"
9
+ import * as DataDependencies from "effect-app/DataDependencies"
10
+ import * as Effect from "effect-app/Effect"
11
+ import { type HttpHeaders } from "effect-app/http"
12
+ import * as Layer from "effect-app/Layer"
13
+ import { Invalidation } from "effect-app/rpc"
14
+ import { type GetEffectContext, type GetEffectError, type RpcContextMap } from "effect-app/rpc/RpcContextMap"
15
+ import * as S from "effect-app/Schema"
16
+ import { type TypeTestId } from "effect-app/TypeTest"
17
+ import { typedKeysOf, typedValuesOf } from "effect-app/utils"
18
+ import * as Predicate from "effect/Predicate"
19
+ import * as Ref from "effect/Ref"
20
+ import type * as Scope from "effect/Scope"
21
+ import * as Stream from "effect/Stream"
22
+ import { Rpc, RpcGroup, type RpcSerialization, RpcServer } from "effect/unstable/rpc"
23
+ import { type LayerUtils } from "./layerUtils.ts"
24
+ import { RequestType as RequestTypeAnnotation } from "./routing/middleware.ts"
25
+
26
+ export * from "./routing/middleware.ts"
27
+
28
+ export const applyRequestTypeInterruptibility = <A, E, R>(
29
+ requestType: "command" | "query",
30
+ effect: Effect.Effect<A, E, R>
31
+ ) => requestType === "command" ? Rpc.uninterruptible(effect) : effect
32
+
33
+ // it's the result of extending S.Req setting success, config
34
+ // it's a schema plus some metadata
35
+ export type AnyRequestModule = S.Top & {
36
+ _tag: string // unique identifier for the request module
37
+ type: "command" | "query"
38
+ stream: boolean
39
+ config: any // ?
40
+ success: S.Top // validates the success response
41
+ error: S.Top // validates the failure response
42
+ }
43
+
44
+ // builder pattern for adding actions to a router until all actions are added
45
+ export interface AddAction<Actions extends AnyRequestModule, Accum extends Record<string, any> = {}> {
46
+ accum: Accum
47
+ add<A extends Handler<Actions, any, any>>(
48
+ a: A
49
+ ): A extends Handler<infer M extends AnyRequestModule, any, any> ? Exclude<Actions, M> extends never ?
50
+ & Accum
51
+ & { [K in M["_tag"]]: A }
52
+ :
53
+ & AddAction<
54
+ Exclude<Actions, M>,
55
+ & Accum
56
+ & { [K in M["_tag"]]: A }
57
+ >
58
+ & Accum
59
+ & { [K in M["_tag"]]: A }
60
+ : never
61
+ }
62
+
63
+ // note:
64
+ // "d" stands for decoded i.e. the Type
65
+ // "raw" stands for encoded i.e. the Encoded
66
+ const RequestTypes = {
67
+ DECODED: "d",
68
+ RAW: "raw"
69
+ } as const
70
+ type RequestType = typeof RequestTypes[keyof typeof RequestTypes]
71
+
72
+ type GetSuccess<T> = T extends { success: S.Top } ? T["success"] : typeof S.Void
73
+ type GetFailure<T extends { error?: S.Top }> = T["error"] extends never ? typeof S.Never : T["error"]
74
+
75
+ type GetSuccessShape<Action extends { success?: S.Top }, RT extends RequestType> = {
76
+ d: GetSuccess<Action>["Type"]
77
+ raw: GetSuccess<Action>["Encoded"]
78
+ }[RT]
79
+
80
+ interface HandlerBase<Action extends AnyRequestModule, RT extends RequestType, A, E, R> {
81
+ new(): {}
82
+ _tag: RT
83
+ stack: string
84
+ handler: (
85
+ req: Action["Type"],
86
+ headers: HttpHeaders.Headers
87
+ ) => Effect.Effect<A, E, R> | Stream.Stream<A, E, R>
88
+ }
89
+
90
+ export interface Handler<Action extends AnyRequestModule, RT extends RequestType, R> extends
91
+ HandlerBase<
92
+ Action,
93
+ RT,
94
+ GetSuccessShape<Action, RT>,
95
+ GetFailure<Action>["Type"] | S.SchemaError,
96
+ R
97
+ >
98
+ {}
99
+
100
+ type AnyHandler<Action extends AnyRequestModule> = Handler<
101
+ Action,
102
+ RequestType,
103
+ any // R
104
+ >
105
+
106
+ // a Resource is typically the whole module with all the exported sh*t
107
+ // this helper retrieves only the entities (classes) which are built by extending S.Req
108
+ type FilterRequestModules<T> = {
109
+ [K in keyof T as T[K] extends AnyRequestModule ? K : never]: T[K]
110
+ }
111
+
112
+ type RpcRouteR<
113
+ T extends [any, (req: any, headers: HttpHeaders.Headers) => Effect.Effect<any, any, any>]
114
+ > = T extends [
115
+ any,
116
+ (...args: any[]) => Effect.Effect<any, any, infer R>
117
+ ] ? R
118
+ : never
119
+
120
+ type EffectMatch<
121
+ Resource extends Record<string, any>,
122
+ RequestContextMap extends Record<string, any>,
123
+ RT extends RequestType,
124
+ Key extends keyof Resource
125
+ > = <A extends GetSuccessShape<Resource[Key], RT>, R2 = never, E = never>(
126
+ f: (req: Resource[Key]["Type"]) => Effect.Effect<A, E, R2>
127
+ ) => Handler<
128
+ Resource[Key],
129
+ RT,
130
+ Exclude<
131
+ Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
132
+ Scope.Scope
133
+ >
134
+ >
135
+
136
+ type StreamMatch<
137
+ Resource extends Record<string, any>,
138
+ RequestContextMap extends Record<string, any>,
139
+ RT extends RequestType,
140
+ Key extends keyof Resource
141
+ > = <A extends GetSuccessShape<Resource[Key], RT>, R2 = never, E = never>(
142
+ f: (req: Resource[Key]["Type"]) => Stream.Stream<A, E, R2>
143
+ ) => Handler<
144
+ Resource[Key],
145
+ RT,
146
+ Exclude<
147
+ Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
148
+ Scope.Scope
149
+ >
150
+ >
151
+
152
+ // Stream resources only accept Stream / Effect<Stream> handlers; non-stream resources
153
+ // only accept Effect handlers. Discriminated by the request module's `stream` flag.
154
+ type Match<
155
+ Resource extends Record<string, any>,
156
+ RequestContextMap extends Record<string, any>,
157
+ RT extends RequestType,
158
+ Key extends keyof Resource
159
+ > = Resource[Key] extends { stream: true } ? StreamMatch<Resource, RequestContextMap, RT, Key>
160
+ : EffectMatch<Resource, RequestContextMap, RT, Key>
161
+
162
+ export type RouteMatcher<
163
+ RequestContextMap extends Record<string, any>,
164
+ Resource extends Record<string, any>
165
+ > = {
166
+ // use Resource as Key over using Keys, so that the Go To on X.Action remain in tact in Controllers files
167
+ /**
168
+ * Requires the Type shape
169
+ */
170
+ [Key in keyof FilterRequestModules<Resource>]:
171
+ & Match<Resource, RequestContextMap, typeof RequestTypes.DECODED, Key>
172
+ & {
173
+ success: Resource[Key]["success"]
174
+ successRaw: S.Codec<Resource[Key]["success"]["Encoded"]>
175
+ error: Resource[Key]["error"]
176
+ /**
177
+ * Requires the Encoded shape (e.g directly undecoded from DB, so that we don't do multiple Decode/Encode)
178
+ */
179
+ raw: Match<Resource, RequestContextMap, typeof RequestTypes.RAW, Key>
180
+ }
181
+ }
182
+
183
+ export const skipOnProd = Effect
184
+ .gen(function*() {
185
+ const env = yield* Config.string("env")
186
+ return env !== "prod"
187
+ })
188
+ .pipe(Effect.orDie)
189
+
190
+ // Type helpers to extract middleware information from a resource's request classes.
191
+ type MiddlewareOf<M extends Record<string, any>> = Exclude<
192
+ { [K in keyof M]: M[K] extends { readonly middleware?: infer MW } ? NonNullable<MW> : never }[keyof M],
193
+ never
194
+ >
195
+ type ProvidesOf<MW> = MW extends { readonly provides: infer P } ? P : never
196
+ type RequestContextMapOf<MW> = MW extends {
197
+ requestContextMap: infer RCM extends Record<string, RpcContextMap.Any>
198
+ } ? RCM
199
+ : Record<string, never>
200
+ type LayerNormalize<L> = L extends Layer.Layer<any, infer E, infer R> ? Layer.Layer<never, E, R>
201
+ : Layer.Layer<never, never, never>
202
+ type LayerSuccess<L> = L extends Layer.Layer<infer A, any, any> ? A : never
203
+
204
+ /**
205
+ * Middleware tags are typically passed to `makeRpcClient` as the class value, so
206
+ * the captured `MW` is a constructor type. Layers carry the *instance* type as
207
+ * their success channel. Bridge the two so the constraint compares like-with-like.
208
+ *
209
+ * Effect middleware classes declare `new(_: never): Shape` which the standard
210
+ * `T extends abstract new (...args: any) => infer I` form sometimes fails to
211
+ * narrow. Use the `prototype` member instead — it is always the instance type.
212
+ */
213
+ type MWService<MW> = MW extends { readonly prototype: infer P } ? P : MW
214
+
215
+ /**
216
+ * Type-level guard: emits a structural mismatch on `Resource` when the middleware
217
+ * service identifier extracted from the resource's request classes is not provided
218
+ * by the layer passed to `makeRouter`. When `MW` is `never` (no middleware on the
219
+ * resource) or already a subtype of the layer's success, this resolves to `unknown`
220
+ * and intersects harmlessly with `Resource`.
221
+ */
222
+ type EnsureMiddlewareProvided<Live, MW> = [MW] extends [never] ? unknown
223
+ : [MWService<MW>] extends [LayerSuccess<Live>] ? unknown
224
+ : {
225
+ readonly __middlewareNotProvidedByRouterLayer: {
226
+ readonly expected: MWService<MW>
227
+ readonly providedByLayer: LayerSuccess<Live>
228
+ }
229
+ }
230
+
231
+ // Safe wrappers that check the constraint before calling GetEffectContext/GetEffectError.
232
+ // These avoid TypeScript constraint errors when the RC map type is deferred (generic).
233
+ type SafeGetEffectContext<RCM, Config> = RCM extends Record<string, RpcContextMap.Any> ? GetEffectContext<RCM, Config>
234
+ : never
235
+ type SafeGetEffectError<RCM, Config> = RCM extends Record<string, RpcContextMap.Any> ? GetEffectError<RCM, Config>
236
+ : never
237
+
238
+ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer<any, never, never>>(
239
+ middlewareLive?: Live
240
+ ) => {
241
+ type ResourceMWDefault = LayerNormalize<Live>
242
+
243
+ /**
244
+ * Create a Router for specified resource.
245
+ * Middleware schema/tag is read from the request classes (stored via `makeRpcClient`).
246
+ * The middleware **Live** layer is the one passed to `makeRouter`.
247
+ * If `check` is provided, the router will only be created if the effect succeeds with true.
248
+ */
249
+ function matchFor<
250
+ const Resource extends Record<string, any>,
251
+ MW = MiddlewareOf<Resource>
252
+ >(
253
+ rsc: Resource & EnsureMiddlewareProvided<Live, MW>,
254
+ options?: { check?: Effect.Effect<boolean> }
255
+ ) {
256
+ // MW is a defaulted type parameter so TypeScript evaluates MiddlewareOf<Resource>
257
+ // eagerly at each call site, producing a concrete type instead of a deferred conditional.
258
+ type ResourceRequestContextMap = RequestContextMapOf<MW>
259
+ type ResourceContextProviderA = ProvidesOf<MW>
260
+
261
+ type HandlerContext<Action extends AnyRequestModule> =
262
+ | SafeGetEffectContext<ResourceRequestContextMap, Action["config"]>
263
+ | ResourceContextProviderA
264
+
265
+ type HandlerWithInputGen<
266
+ Action extends AnyRequestModule,
267
+ RT extends RequestType
268
+ > = (
269
+ req: Action["Type"]
270
+ ) => Generator<
271
+ Effect.Effect<
272
+ any,
273
+ GetFailure<Action>["Type"] | S.SchemaError,
274
+ // the actual implementation of the handler may just require the dynamic context provided by the middleware
275
+ // and the per request context provided by the context provider
276
+ HandlerContext<Action>
277
+ >,
278
+ GetSuccessShape<Action, RT>,
279
+ never
280
+ >
281
+
282
+ type HandlerWithInputEff<
283
+ Action extends AnyRequestModule,
284
+ RT extends RequestType
285
+ > = (
286
+ req: Action["Type"]
287
+ ) => Effect.Effect<
288
+ GetSuccessShape<Action, RT>,
289
+ GetFailure<Action>["Type"] | S.SchemaError,
290
+ // the actual implementation of the handler may just require the dynamic context provided by the middleware
291
+ // and the per request context provided by the context provider
292
+ HandlerContext<Action>
293
+ >
294
+
295
+ type HandlerWithInputStream<
296
+ Action extends AnyRequestModule,
297
+ RT extends RequestType
298
+ > = (
299
+ req: Action["Type"]
300
+ ) => Stream.Stream<
301
+ GetSuccessShape<Action, RT>,
302
+ GetFailure<Action>["Type"] | S.SchemaError,
303
+ HandlerContext<Action>
304
+ >
305
+
306
+ // Stream resources only accept `(req) => Stream`; non-stream only Effect / Generator.
307
+ type Handlers<Action extends AnyRequestModule, RT extends RequestType> = Action extends { stream: true }
308
+ ? HandlerWithInputStream<Action, RT>
309
+ : HandlerWithInputGen<Action, RT> | HandlerWithInputEff<Action, RT>
310
+
311
+ type HandlersDecoded<Action extends AnyRequestModule> = Handlers<Action, typeof RequestTypes.DECODED>
312
+
313
+ type HandlersRaw<Action extends AnyRequestModule> = Action extends { stream: true }
314
+ ? { raw: HandlerWithInputStream<Action, typeof RequestTypes.RAW> }
315
+ :
316
+ | { raw: HandlerWithInputGen<Action, typeof RequestTypes.RAW> }
317
+ | { raw: HandlerWithInputEff<Action, typeof RequestTypes.RAW> }
318
+
319
+ type AnyHandlers<Action extends AnyRequestModule> = HandlersRaw<Action> | HandlersDecoded<Action>
320
+
321
+ const meta = getMeta(rsc)
322
+
323
+ type RequestModules = FilterRequestModules<Resource>
324
+ const requestModules = typedKeysOf(rsc).reduce((acc, cur) => {
325
+ if (Predicate.isObjectKeyword(rsc[cur]) && rsc[cur]["success"]) {
326
+ acc[cur as keyof RequestModules] = rsc[cur]
327
+ }
328
+ return acc
329
+ }, {} as RequestModules)
330
+
331
+ const routeMatcher = typedKeysOf(requestModules).reduce(
332
+ (prev, cur) => {
333
+ ;(prev as any)[cur] = Object.assign((handlerImpl: any) => {
334
+ // handlerImpl is the actual handler implementation
335
+ if (handlerImpl[Symbol.toStringTag] === "GeneratorFunction") handlerImpl = Effect.fnUntraced(handlerImpl)
336
+ const stack = new Error().stack?.split("\n").slice(2).join("\n")
337
+ // oxlint-disable-next-line typescript/no-extraneous-class
338
+ return class {
339
+ static request = rsc[cur]
340
+ static stack = stack
341
+ static _tag = RequestTypes.DECODED
342
+ static handler = handlerImpl
343
+ }
344
+ }, {
345
+ success: rsc[cur].success,
346
+ successRaw: S.toEncoded(rsc[cur].success),
347
+ error: rsc[cur].error,
348
+ raw: // "Raw" variations are for when you don't want to decode just to encode it again on the response
349
+ // e.g for direct projection from DB
350
+ // but more importantly, to skip Effectful decoders, like to resolve relationships from the database or remote client.
351
+ (handlerImpl: any) => {
352
+ if (handlerImpl[Symbol.toStringTag] === "GeneratorFunction") handlerImpl = Effect.fnUntraced(handlerImpl)
353
+ const stack = new Error().stack?.split("\n").slice(2).join("\n")
354
+ // oxlint-disable-next-line typescript/no-extraneous-class
355
+ return class {
356
+ static request = rsc[cur]
357
+ static stack = stack
358
+ static _tag = RequestTypes.RAW
359
+ static handler = handlerImpl
360
+ }
361
+ }
362
+ })
363
+ return prev
364
+ },
365
+ {} as RouteMatcher<ResourceRequestContextMap, Resource>
366
+ )
367
+
368
+ const router3: <
369
+ const Impl extends {
370
+ [K in keyof FilterRequestModules<Resource>]: AnyHandlers<Resource[K]>
371
+ }
372
+ >(
373
+ impl: Impl
374
+ ) => {
375
+ [K in keyof Impl & keyof FilterRequestModules<Resource>]: Handler<
376
+ FilterRequestModules<Resource>[K],
377
+ Impl[K] extends { raw: any } ? typeof RequestTypes.RAW : typeof RequestTypes.DECODED,
378
+ Exclude<
379
+ Exclude<
380
+ // retrieves context R from the actual implementation of the handler
381
+ Impl[K] extends { raw: any }
382
+ ? Impl[K]["raw"] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
383
+ : Impl[K]["raw"] extends (...args: any[]) => Stream.Stream<any, any, infer R> ? R
384
+ : Impl[K]["raw"] extends (...args: any[]) => Generator<
385
+ Effect.Effect<any, any, infer R>
386
+ > ? R
387
+ : never
388
+ : Impl[K] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
389
+ : Impl[K] extends (...args: any[]) => Stream.Stream<any, any, infer R> ? R
390
+ : Impl[K] extends (...args: any[]) => Generator<
391
+ Effect.Effect<any, any, infer R>
392
+ > ? R
393
+ : never,
394
+ | SafeGetEffectContext<ResourceRequestContextMap, Resource[K]["config"]>
395
+ | ResourceContextProviderA
396
+ >,
397
+ Scope.Scope
398
+ >
399
+ >
400
+ } = (impl: Record<keyof RequestModules, any>) =>
401
+ typedKeysOf(impl).reduce((acc, cur) => {
402
+ acc[cur] = "raw" in impl[cur] ? routeMatcher[cur].raw(impl[cur].raw) : routeMatcher[cur](impl[cur])
403
+ return acc
404
+ }, {} as any)
405
+
406
+ const makeRoutes = <
407
+ MakeE,
408
+ MakeR,
409
+ THandlers extends {
410
+ // important to keep them separate via | for type checking!!
411
+ [K in keyof RequestModules]: AnyHandler<Resource[K]>
412
+ },
413
+ MakeDependencies extends NonEmptyReadonlyArray<Layer.Any> | never[]
414
+ >(
415
+ dependencies: MakeDependencies,
416
+ make: (
417
+ match: any
418
+ ) =>
419
+ | Effect.Effect<THandlers, MakeE, MakeR>
420
+ | Generator<Effect.Effect<any, MakeE, MakeR>, THandlers>
421
+ ) => {
422
+ const dependenciesL = (dependencies ? Layer.mergeAll(...dependencies as any) : Layer.empty) as Layer.Layer<
423
+ LayerUtils.GetLayersSuccess<MakeDependencies>,
424
+ LayerUtils.GetLayersError<MakeDependencies>,
425
+ LayerUtils.GetLayersContext<MakeDependencies>
426
+ >
427
+
428
+ const layer = Effect
429
+ .gen(function*() {
430
+ const finalMake = ((make as any)[Symbol.toStringTag] === "GeneratorFunction"
431
+ ? Effect.fnUntraced(make as any)(router3) as any
432
+ : make(router3) as any) as Effect.Effect<THandlers, MakeE, MakeR>
433
+
434
+ const controllers = yield* finalMake
435
+
436
+ // Read the middleware from the resource's request classes at runtime
437
+ const mw = meta.middleware as any
438
+
439
+ // return make.pipe(Effect.map((c) => controllers(c, dependencies)))
440
+ const mapped = typedKeysOf(requestModules).reduce((acc, cur) => {
441
+ const handler = controllers[cur as keyof typeof controllers]
442
+ const resource = rsc[cur]
443
+
444
+ acc[cur] = [
445
+ handler._tag === RequestTypes.RAW
446
+ ? class extends (resource as any) {
447
+ static success = S.toEncoded(resource.success)
448
+ } as any
449
+ : resource,
450
+ (payload: any, headers: any) => {
451
+ const result: any = handler.handler(payload, headers)
452
+
453
+ if (resource.stream) {
454
+ // Wrap stream items as { _tag: "value", value } and append a final
455
+ // { _tag: "done", metadata } chunk carrying accumulated invalidation keys.
456
+ // V2: on failure, convert to { _tag: "error", error, metadata } chunk so
457
+ // clients can invalidate queries even when the stream fails.
458
+ const keysRef = Ref.makeUnsafe<ReadonlyArray<Invalidation.InvalidationKey>>([])
459
+ const invalidationSet = Invalidation.makeInvalidationSet(keysRef)
460
+ const metadata = (keys: ReadonlyArray<Invalidation.InvalidationKey>) =>
461
+ Effect.map(
462
+ DataDependencies.getDataDependencyRecorder.pipe(Effect.flatMap((_) => _.drain)),
463
+ (dataDependencies) => Invalidation.makeMetaData(keys, dataDependencies)
464
+ )
465
+ return Stream
466
+ .concat(
467
+ (result as Stream.Stream<any, any, any>).pipe(
468
+ Stream.map((item: any) => ({ _tag: "value" as const, value: item })),
469
+ Stream.provideService(Invalidation.InvalidationSet, invalidationSet),
470
+ // V3: after each value chunk, drain accumulated keys and emit a "metadata"
471
+ // chunk if any keys were collected since the last drain. This lets clients
472
+ // invalidate queries mid-stream without waiting for the "done" chunk.
473
+ Stream.flatMap((valueChunk: any) =>
474
+ Stream
475
+ .fromEffect(
476
+ Ref.getAndSet(keysRef, []).pipe(
477
+ Effect.flatMap((keys) =>
478
+ metadata(keys).pipe(
479
+ Effect.map((meta) =>
480
+ Array.isReadonlyArrayNonEmpty(keys)
481
+ || DataDependencies.isNonEmpty(meta.dataDependencies.reads)
482
+ || DataDependencies.isNonEmpty(meta.dataDependencies.writes)
483
+ ? [
484
+ valueChunk,
485
+ { _tag: "metadata" as const, metadata: meta }
486
+ ]
487
+ : [valueChunk]
488
+ )
489
+ )
490
+ )
491
+ )
492
+ )
493
+ .pipe(Stream.flatMap(Stream.fromIterable))
494
+ ),
495
+ // V2: catch stream failures and embed them in the stream as an error chunk
496
+ Stream.catch((err: any) =>
497
+ Stream.fromEffect(
498
+ Ref.get(keysRef).pipe(
499
+ Effect.flatMap((keys) =>
500
+ metadata(keys).pipe(
501
+ Effect.flatMap((meta) =>
502
+ Effect.fail({
503
+ _tag: "error" as const,
504
+ error: err,
505
+ metadata: meta
506
+ })
507
+ )
508
+ )
509
+ )
510
+ )
511
+ )
512
+ )
513
+ ),
514
+ Stream.fromEffect(
515
+ Ref.get(keysRef).pipe(
516
+ Effect.flatMap((keys) =>
517
+ metadata(keys).pipe(
518
+ Effect.map((meta) => ({ _tag: "done" as const, metadata: meta }))
519
+ )
520
+ )
521
+ )
522
+ )
523
+ )
524
+ .pipe(
525
+ Stream.provideService(Invalidation.InvalidationSet, invalidationSet),
526
+ // A fresh recorder per request when none is provided (e.g. no request-context
527
+ // middleware), so the metadata drain above always has one. Inherits an existing
528
+ // request-scoped recorder otherwise.
529
+ DataDependencies.ensureDataDependencyRecorderStream
530
+ )
531
+ }
532
+
533
+ let effect = Effect
534
+ .annotateCurrentSpan({
535
+ "rpc.system": "effect-app",
536
+ "rpc.service": meta.moduleName,
537
+ "rpc.method": resource._tag,
538
+ "code.function.name": resource._tag,
539
+ "code.namespace": meta.moduleName,
540
+ "app.rpc.type": resource.type
541
+ })
542
+ .pipe(Effect.andThen(result as Effect.Effect<unknown, unknown, unknown>))
543
+
544
+ // Commands: provide a request-scoped `InvalidationSet` and wrap both
545
+ // success (`CommandResponseWithMetaData`) and handler-thrown failure
546
+ // (`CommandFailureWithMetaData`) so the client receives accumulated
547
+ // invalidation keys on either path. Middleware-thrown errors bypass the
548
+ // wrap (they fail the outer effect before reaching this `.catch`) and
549
+ // flow raw on the Cause; client decodes them via the rpc's
550
+ // `middlewares[*].error` failure-union channel.
551
+ if (resource.type === "command") {
552
+ const keysRef = Ref.makeUnsafe<ReadonlyArray<Invalidation.InvalidationKey>>([])
553
+ const invalidationSet = Invalidation.makeInvalidationSet(keysRef)
554
+ effect = effect.pipe(
555
+ Effect.provideService(Invalidation.InvalidationSet, invalidationSet),
556
+ Effect.flatMap((value) =>
557
+ Ref.get(keysRef).pipe(
558
+ Effect.flatMap((keys) =>
559
+ DataDependencies.getDataDependencyRecorder.pipe(
560
+ Effect.flatMap((_) => _.get),
561
+ Effect.map((dataDependencies) =>
562
+ ({
563
+ payload: value,
564
+ metadata: Invalidation.makeMetaData(keys, dataDependencies)
565
+ }) as any
566
+ )
567
+ )
568
+ )
569
+ )
570
+ ),
571
+ Effect.catch((err: any) =>
572
+ Ref.get(keysRef).pipe(
573
+ Effect.flatMap((keys) =>
574
+ DataDependencies.getDataDependencyRecorder.pipe(
575
+ Effect.flatMap((_) => _.get),
576
+ Effect.flatMap((dataDependencies) =>
577
+ Effect.fail({
578
+ _tag: "CommandFailureWithMetaData" as const,
579
+ error: err,
580
+ metadata: Invalidation.makeMetaData(keys, dataDependencies)
581
+ })
582
+ )
583
+ )
584
+ )
585
+ )
586
+ )
587
+ )
588
+ } else {
589
+ effect = effect.pipe(
590
+ Effect.flatMap((value) =>
591
+ DataDependencies.getDataDependencyRecorder.pipe(
592
+ Effect.flatMap((_) => _.get),
593
+ Effect.map((dataDependencies) => ({ payload: value, metadata: { dataDependencies } }) as any)
594
+ )
595
+ )
596
+ )
597
+ }
598
+
599
+ return applyRequestTypeInterruptibility(
600
+ resource.type,
601
+ effect.pipe(DataDependencies.ensureDataDependencyRecorder)
602
+ )
603
+ }
604
+ ] as const
605
+ return acc
606
+ }, {} as any) as {
607
+ [K in keyof RequestModules]: [
608
+ Resource[K],
609
+ (
610
+ req: any,
611
+ headers: HttpHeaders.Headers
612
+ ) => Effect.Effect<
613
+ Effect.Success<ReturnType<THandlers[K]["handler"]>>,
614
+ | Effect.Error<ReturnType<THandlers[K]["handler"]>>
615
+ | SafeGetEffectError<ResourceRequestContextMap, Resource[K]["config"]>,
616
+ Exclude<
617
+ Effect.Services<ReturnType<THandlers[K]["handler"]>>,
618
+ ResourceContextProviderA | SafeGetEffectContext<ResourceRequestContextMap, Resource[K]["config"]>
619
+ >
620
+ >
621
+ ]
622
+ }
623
+
624
+ const rpcs = RpcGroup
625
+ .make(
626
+ ...typedValuesOf(mapped).map(([resource]) => {
627
+ const isStream = resource.stream
628
+ const isCommand = resource.type === "command"
629
+ return (isCommand
630
+ ? isStream
631
+ ? Invalidation.makeStreamRpc(resource._tag, {
632
+ payload: resource,
633
+ success: resource.success,
634
+ error: resource.error,
635
+ stream: true as const
636
+ })
637
+ : Invalidation.makeCommandRpc(resource._tag, {
638
+ payload: resource,
639
+ success: resource.success,
640
+ error: resource.error
641
+ })
642
+ : Rpc.make(resource._tag, {
643
+ payload: resource,
644
+ success: isStream ? resource.success : Invalidation.QueryResponseWithMetaData(resource.success),
645
+ error: resource.error,
646
+ stream: isStream
647
+ }))
648
+ .annotate(mw.requestContext, resource.config ?? {})
649
+ .annotate(RequestTypeAnnotation, resource.type)
650
+ })
651
+ )
652
+ .prefix(`${meta.moduleName}.`)
653
+ .middleware(mw)
654
+
655
+ const rpc = rpcs
656
+ .toLayer(Effect.gen(function*() {
657
+ return typedValuesOf(mapped).reduce((acc, [resource, handler]) => {
658
+ acc[`${meta.moduleName}.${resource._tag}`] = handler
659
+ return acc
660
+ }, {} as Record<string, any>) as any // TODO
661
+ })) as unknown as Layer.Layer<
662
+ { [K in keyof RequestModules]: Rpc.Handler<K> },
663
+ MakeE,
664
+ RpcRouteR<typeof mapped[keyof typeof mapped]>
665
+ >
666
+
667
+ return RpcServer
668
+ .layerHttp({
669
+ group: rpcs,
670
+ path: ("/rpc/" + meta.moduleName) as `/${typeof meta.moduleName}`,
671
+ protocol: "http"
672
+ })
673
+ .pipe(Layer.provide(rpc))
674
+ })
675
+ .pipe(Layer.unwrap)
676
+
677
+ const routes = layer.pipe(
678
+ Layer.provide([
679
+ dependenciesL,
680
+ (middlewareLive ?? Layer.empty) as Layer.Layer<any, any, any>
681
+ ])
682
+ )
683
+
684
+ const check = options?.check
685
+ return check
686
+ ? Effect
687
+ .gen(function*() {
688
+ if (!(yield* check)) {
689
+ yield* Effect.logWarning(`Skipping router for module ${meta.moduleName}`)
690
+ return Layer.empty
691
+ }
692
+ return routes
693
+ })
694
+ .pipe(Layer.unwrap)
695
+ : routes
696
+ }
697
+
698
+ const effect: {
699
+ // Multiple times duplicated the "good" overload, so that errors will only mention the last overload when failing
700
+ <
701
+ const Make extends {
702
+ dependencies?: ReadonlyArray<Layer.Any>
703
+ effect: (match: typeof router3) => Generator<
704
+ Effect.Effect<
705
+ any,
706
+ any,
707
+ any
708
+ >,
709
+ { [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
710
+ >
711
+ /** @deprecated */
712
+ readonly ಠ_ಠ: never
713
+ }
714
+ >(
715
+ make: Make
716
+ ):
717
+ & Layer.Layer<
718
+ never,
719
+ | MakeErrors<Make>
720
+ | MakeDepsE<Make>
721
+ | Layer.Error<ResourceMWDefault>,
722
+ | MakeDepsIn<Make>
723
+ | Layer.Services<ResourceMWDefault>
724
+ | Exclude<
725
+ MakeContext<Make>,
726
+ MakeDepsOut<Make>
727
+ >
728
+ | RpcSerialization.RpcSerialization
729
+ >
730
+ & {
731
+ // just for type testing purposes
732
+ [TypeTestId]: Make
733
+ }
734
+ <
735
+ const Make extends {
736
+ dependencies?: ReadonlyArray<Layer.Any>
737
+ // v4: generators yield Yieldable with asEffect()
738
+ effect: (match: typeof router3) => Generator<
739
+ Effect.Effect<any, any, any>,
740
+ { [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
741
+ >
742
+ }
743
+ >(
744
+ make: Make
745
+ ):
746
+ & Layer.Layer<
747
+ never,
748
+ | MakeErrors<Make>
749
+ | MakeDepsE<Make>
750
+ | Layer.Error<ResourceMWDefault>,
751
+ | MakeDepsIn<Make>
752
+ | Layer.Services<ResourceMWDefault>
753
+ | Exclude<
754
+ MakeContext<Make>,
755
+ MakeDepsOut<Make>
756
+ >
757
+ | RpcSerialization.RpcSerialization
758
+ >
759
+ & {
760
+ // just for type testing purposes
761
+ readonly [TypeTestId]: Make
762
+ }
763
+ } =
764
+ ((make: { dependencies: any; effect: any }) =>
765
+ Object.assign(makeRoutes(make.dependencies, make.effect), { make })) as any
766
+
767
+ return effect
768
+ }
769
+
770
+ function matchAll<
771
+ T extends {
772
+ [key: string]: Layer.Layer<never, any, any>
773
+ }
774
+ >(
775
+ handlers: T
776
+ ) {
777
+ const routers = typedValuesOf(handlers)
778
+
779
+ return Layer.mergeAll(...routers as [any]) as unknown as Layer.Layer<
780
+ never,
781
+ Layer.Error<typeof handlers[keyof typeof handlers]>,
782
+ Layer.Services<typeof handlers[keyof typeof handlers]>
783
+ >
784
+ }
785
+
786
+ return {
787
+ matchAll,
788
+ Router: matchFor
789
+ }
790
+ }
791
+
792
+ export type MakeDeps<Make> = Make extends { readonly dependencies: ReadonlyArray<Layer.Any> }
793
+ ? Make["dependencies"][number]
794
+ : never
795
+
796
+ export type MakeErrors<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, infer E, any> } ? E
797
+ : Make extends { readonly effect: (_: any) => Effect.Effect<any, never, any> } ? never
798
+ : */
799
+ // v4: generators yield Effect values
800
+ Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, never, any>, any> } ? never
801
+ : Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, infer E, any>, any> } ? E
802
+ : never
803
+
804
+ export type MakeContext<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, any, infer R> } ? R
805
+ : Make extends { readonly effect: (_: any) => Effect.Effect<any, any, never> } ? never
806
+ : */
807
+ // v4: generators yield Effect values
808
+ Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, any, never>, any> } ? never
809
+ : Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, any, infer R>, any> } ? R
810
+ : never
811
+
812
+ export type MakeHandlers<Make, _Handlers extends Record<string, any>> = /*Make extends
813
+ { readonly effect: (_: any) => Effect.Effect<{ [K in keyof Handlers]: AnyHandler<Handlers[K]> }, any, any> }
814
+ ? Effect.Success<ReturnType<Make["effect"]>>
815
+ : */
816
+ Make extends { readonly effect: (_: any) => Generator<any, infer S> } ? S
817
+ : never
818
+
819
+ export type MakeDepsE<Make> = Layer.Error<MakeDeps<Make>>
820
+
821
+ export type MakeDepsIn<Make> = Layer.Services<MakeDeps<Make>>
822
+
823
+ export type MakeDepsOut<Make> = Layer.Success<MakeDeps<Make>>