@effect-app/infra 4.0.0-beta.26 → 4.0.0-beta.260

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 (503) hide show
  1. package/CHANGELOG.md +1966 -0
  2. package/_check.sh +1 -1
  3. package/dist/CUPS.d.ts +30 -11
  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 +487 -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 +111 -147
  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 +2 -2
  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 -9
  22. package/dist/MainFiberSet.d.ts.map +1 -1
  23. package/dist/MainFiberSet.js +10 -6
  24. package/dist/QueueMaker/SQLQueue.d.ts +8 -9
  25. package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
  26. package/dist/QueueMaker/SQLQueue.js +138 -120
  27. package/dist/QueueMaker/errors.d.ts +5 -3
  28. package/dist/QueueMaker/errors.d.ts.map +1 -1
  29. package/dist/QueueMaker/errors.js +4 -2
  30. package/dist/QueueMaker/memQueue.d.ts +10 -6
  31. package/dist/QueueMaker/memQueue.d.ts.map +1 -1
  32. package/dist/QueueMaker/memQueue.js +84 -68
  33. package/dist/QueueMaker/sbqueue.d.ts +9 -5
  34. package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
  35. package/dist/QueueMaker/sbqueue.js +60 -58
  36. package/dist/RequestFiberSet.d.ts +10 -7
  37. package/dist/RequestFiberSet.d.ts.map +1 -1
  38. package/dist/RequestFiberSet.js +13 -8
  39. package/dist/SQL/Model.d.ts +468 -0
  40. package/dist/SQL/Model.d.ts.map +1 -0
  41. package/dist/SQL/Model.js +469 -0
  42. package/dist/SQL.d.ts +2 -0
  43. package/dist/SQL.d.ts.map +1 -0
  44. package/dist/{adapters/SQL.js → SQL.js} +1 -1
  45. package/dist/ServiceBus.d.ts +61 -0
  46. package/dist/ServiceBus.d.ts.map +1 -0
  47. package/dist/ServiceBus.js +108 -0
  48. package/dist/Store/Cosmos/query.d.ts +15 -4
  49. package/dist/Store/Cosmos/query.d.ts.map +1 -1
  50. package/dist/Store/Cosmos/query.js +179 -41
  51. package/dist/Store/Cosmos.d.ts +3 -3
  52. package/dist/Store/Cosmos.d.ts.map +1 -1
  53. package/dist/Store/Cosmos.js +344 -246
  54. package/dist/Store/Disk.d.ts +5 -5
  55. package/dist/Store/Disk.d.ts.map +1 -1
  56. package/dist/Store/Disk.js +78 -38
  57. package/dist/Store/Memory.d.ts +7 -10
  58. package/dist/Store/Memory.d.ts.map +1 -1
  59. package/dist/Store/Memory.js +326 -66
  60. package/dist/Store/SQL/Pg.d.ts +4 -0
  61. package/dist/Store/SQL/Pg.d.ts.map +1 -0
  62. package/dist/Store/SQL/Pg.js +232 -0
  63. package/dist/Store/SQL/query.d.ts +49 -0
  64. package/dist/Store/SQL/query.d.ts.map +1 -0
  65. package/dist/Store/SQL/query.js +527 -0
  66. package/dist/Store/SQL.d.ts +21 -0
  67. package/dist/Store/SQL.d.ts.map +1 -0
  68. package/dist/Store/SQL.js +449 -0
  69. package/dist/Store/codeFilter.d.ts +5 -5
  70. package/dist/Store/codeFilter.d.ts.map +1 -1
  71. package/dist/Store/codeFilter.js +6 -3
  72. package/dist/Store/index.d.ts +7 -5
  73. package/dist/Store/index.d.ts.map +1 -1
  74. package/dist/Store/index.js +18 -5
  75. package/dist/Store/utils.d.ts +4 -3
  76. package/dist/Store/utils.d.ts.map +1 -1
  77. package/dist/Store/utils.js +5 -5
  78. package/dist/WorkflowEngineCosmos.d.ts +29 -0
  79. package/dist/WorkflowEngineCosmos.d.ts.map +1 -0
  80. package/dist/WorkflowEngineCosmos.js +521 -0
  81. package/dist/WorkflowEngineSqlite.d.ts +24 -0
  82. package/dist/WorkflowEngineSqlite.d.ts.map +1 -0
  83. package/dist/WorkflowEngineSqlite.js +550 -0
  84. package/dist/arbs.d.ts +2 -2
  85. package/dist/arbs.d.ts.map +1 -1
  86. package/dist/arbs.js +5 -3
  87. package/dist/codec.d.ts +5 -0
  88. package/dist/codec.d.ts.map +1 -0
  89. package/dist/codec.js +5 -0
  90. package/dist/cosmos-client.d.ts +16 -0
  91. package/dist/cosmos-client.d.ts.map +1 -0
  92. package/dist/cosmos-client.js +11 -0
  93. package/dist/errorReporter.d.ts +7 -5
  94. package/dist/errorReporter.d.ts.map +1 -1
  95. package/dist/errorReporter.js +23 -27
  96. package/dist/errors.d.ts +1 -1
  97. package/dist/fileUtil.d.ts +2 -2
  98. package/dist/fileUtil.d.ts.map +1 -1
  99. package/dist/fileUtil.js +2 -2
  100. package/dist/index.d.ts +3 -2
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +3 -2
  103. package/dist/internal/RequestContextMiddleware.d.ts +5 -0
  104. package/dist/internal/RequestContextMiddleware.d.ts.map +1 -0
  105. package/dist/internal/RequestContextMiddleware.js +45 -0
  106. package/dist/internal/auth.d.ts +53 -0
  107. package/dist/internal/auth.d.ts.map +1 -0
  108. package/dist/internal/auth.js +180 -0
  109. package/dist/internal/events.d.ts +11 -0
  110. package/dist/internal/events.d.ts.map +1 -0
  111. package/dist/internal/events.js +49 -0
  112. package/dist/internal/health.d.ts +3 -0
  113. package/dist/internal/health.d.ts.map +1 -0
  114. package/dist/internal/health.js +5 -0
  115. package/dist/layerUtils.d.ts +32 -0
  116. package/dist/layerUtils.d.ts.map +1 -0
  117. package/dist/layerUtils.js +17 -0
  118. package/dist/logger/jsonLogger.d.ts +2 -2
  119. package/dist/logger/jsonLogger.d.ts.map +1 -1
  120. package/dist/logger/jsonLogger.js +5 -3
  121. package/dist/logger/logFmtLogger.d.ts +2 -2
  122. package/dist/logger/logFmtLogger.d.ts.map +1 -1
  123. package/dist/logger/logFmtLogger.js +3 -3
  124. package/dist/logger/shared.d.ts +3 -3
  125. package/dist/logger/shared.d.ts.map +1 -1
  126. package/dist/logger/shared.js +5 -5
  127. package/dist/logger.d.ts +1 -1
  128. package/dist/logger.d.ts.map +1 -1
  129. package/dist/memQueue.d.ts +15 -0
  130. package/dist/memQueue.d.ts.map +1 -0
  131. package/dist/memQueue.js +21 -0
  132. package/dist/middlewares.d.ts +10 -0
  133. package/dist/middlewares.d.ts.map +1 -0
  134. package/dist/{api/middlewares.js → middlewares.js} +1 -1
  135. package/dist/mongo-client.d.ts +11 -0
  136. package/dist/mongo-client.d.ts.map +1 -0
  137. package/dist/mongo-client.js +15 -0
  138. package/dist/otel.d.ts +75 -0
  139. package/dist/otel.d.ts.map +1 -0
  140. package/dist/otel.js +65 -0
  141. package/dist/rateLimit.d.ts +12 -4
  142. package/dist/rateLimit.d.ts.map +1 -1
  143. package/dist/rateLimit.js +7 -12
  144. package/dist/redis-client.d.ts +42 -0
  145. package/dist/redis-client.d.ts.map +1 -0
  146. package/dist/redis-client.js +98 -0
  147. package/dist/reportError.d.ts +4 -0
  148. package/dist/reportError.d.ts.map +1 -0
  149. package/dist/reportError.js +28 -0
  150. package/dist/routing/middleware/RouterMiddleware.d.ts +16 -0
  151. package/dist/routing/middleware/RouterMiddleware.d.ts.map +1 -0
  152. package/dist/{api/routing → routing}/middleware/RouterMiddleware.js +1 -1
  153. package/dist/routing/middleware/middleware.d.ts +48 -0
  154. package/dist/routing/middleware/middleware.d.ts.map +1 -0
  155. package/dist/routing/middleware/middleware.js +128 -0
  156. package/dist/routing/middleware.d.ts +3 -0
  157. package/dist/routing/middleware.d.ts.map +1 -0
  158. package/dist/{api/routing → routing}/middleware.js +1 -2
  159. package/dist/routing/schema/jwt.d.ts +4 -0
  160. package/dist/routing/schema/jwt.d.ts.map +1 -0
  161. package/dist/routing/schema/jwt.js +13 -0
  162. package/dist/routing/tsort.d.ts +8 -0
  163. package/dist/routing/tsort.d.ts.map +1 -0
  164. package/dist/routing/tsort.js +51 -0
  165. package/dist/routing/utils.d.ts +19 -0
  166. package/dist/routing/utils.d.ts.map +1 -0
  167. package/dist/routing/utils.js +45 -0
  168. package/dist/routing.d.ts +184 -0
  169. package/dist/routing.d.ts.map +1 -0
  170. package/dist/routing.js +236 -0
  171. package/dist/test.d.ts +3 -3
  172. package/dist/test.d.ts.map +1 -1
  173. package/dist/test.js +2 -2
  174. package/dist/util.d.ts +3 -0
  175. package/dist/util.d.ts.map +1 -0
  176. package/dist/util.js +14 -0
  177. package/dist/vitest.d.ts +1 -1
  178. package/docs/cluster-storage.md +26 -0
  179. package/docs/workflow-engine.md +262 -0
  180. package/examples/query.ts +47 -39
  181. package/package.json +31 -345
  182. package/run.sh +1 -0
  183. package/src/CUPS.ts +52 -13
  184. package/src/ClusterCosmos.ts +954 -0
  185. package/src/ClusterServiceBus.ts +242 -0
  186. package/src/{api/ContextProvider.ts → ContextProvider.ts} +19 -16
  187. package/src/Emailer/Sendgrid.ts +82 -59
  188. package/src/Emailer/fake.ts +3 -3
  189. package/src/MainFiberSet.ts +12 -10
  190. package/src/QueueMaker/SQLQueue.ts +153 -156
  191. package/src/QueueMaker/errors.ts +3 -1
  192. package/src/QueueMaker/memQueue.ts +113 -107
  193. package/src/QueueMaker/sbqueue.ts +78 -90
  194. package/src/RequestFiberSet.ts +13 -8
  195. package/src/{adapters/SQL → SQL}/Model.ts +42 -41
  196. package/src/ServiceBus.ts +219 -0
  197. package/src/Store/Cosmos/query.ts +216 -52
  198. package/src/Store/Cosmos.ts +493 -353
  199. package/src/Store/Disk.ts +109 -69
  200. package/src/Store/Memory.ts +365 -96
  201. package/src/Store/SQL/Pg.ts +363 -0
  202. package/src/Store/SQL/query.ts +603 -0
  203. package/src/Store/SQL.ts +735 -0
  204. package/src/Store/codeFilter.ts +8 -5
  205. package/src/Store/index.ts +21 -6
  206. package/src/Store/utils.ts +26 -24
  207. package/src/WorkflowEngineCosmos.ts +719 -0
  208. package/src/WorkflowEngineSqlite.ts +813 -0
  209. package/src/arbs.ts +5 -3
  210. package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
  211. package/src/errorReporter.ts +66 -76
  212. package/src/fileUtil.ts +1 -1
  213. package/src/index.ts +2 -1
  214. package/src/{api/internal → internal}/RequestContextMiddleware.ts +23 -6
  215. package/src/internal/auth.ts +272 -0
  216. package/src/{api/internal → internal}/events.ts +22 -13
  217. package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
  218. package/src/logger/jsonLogger.ts +4 -2
  219. package/src/logger/logFmtLogger.ts +2 -2
  220. package/src/logger/shared.ts +5 -4
  221. package/src/{adapters/memQueue.ts → memQueue.ts} +5 -4
  222. package/src/{adapters/mongo-client.ts → mongo-client.ts} +4 -2
  223. package/src/otel.ts +152 -0
  224. package/src/rateLimit.ts +34 -23
  225. package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
  226. package/src/{api/reportError.ts → reportError.ts} +3 -2
  227. package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
  228. package/src/{api/routing → routing}/middleware/middleware.ts +62 -17
  229. package/src/routing/middleware.ts +4 -0
  230. package/src/{api/routing → routing}/schema/jwt.ts +2 -1
  231. package/src/{api/routing → routing}/utils.ts +2 -1
  232. package/src/routing.ts +768 -0
  233. package/src/test.ts +2 -2
  234. package/test/auth.test.ts +101 -0
  235. package/test/cluster-cosmos.test.ts +503 -0
  236. package/test/cluster-servicebus.test.ts +180 -0
  237. package/test/contextProvider.test.ts +15 -12
  238. package/test/controller.test.ts +28 -32
  239. package/test/cosmos-query.test.ts +159 -0
  240. package/test/dist/_check-agg-infer.test-d.d.ts +2 -0
  241. package/test/dist/_check-agg-infer.test-d.d.ts.map +1 -0
  242. package/test/dist/_check-agg-infer.test-d.js +19 -0
  243. package/test/dist/_check-proj-infer.test-d.d.ts +2 -0
  244. package/test/dist/_check-proj-infer.test-d.d.ts.map +1 -0
  245. package/test/dist/_check-proj-infer.test-d.js +16 -0
  246. package/test/dist/_check-tighten.test-d.d.ts +2 -0
  247. package/test/dist/_check-tighten.test-d.d.ts.map +1 -0
  248. package/test/dist/_check-tighten.test-d.js +21 -0
  249. package/test/dist/auth.test.d.ts.map +1 -0
  250. package/test/dist/cluster-cosmos.test.d.ts.map +1 -0
  251. package/test/dist/cluster-servicebus.test.d.ts.map +1 -0
  252. package/test/dist/contextProvider.test.d.ts.map +1 -1
  253. package/test/dist/controller.test.d.ts.map +1 -1
  254. package/test/dist/cosmos-query.test.d.ts.map +1 -0
  255. package/test/dist/date-query.test.d.ts.map +1 -0
  256. package/test/dist/fixtures.d.ts +30 -12
  257. package/test/dist/fixtures.d.ts.map +1 -1
  258. package/test/dist/fixtures.js +17 -10
  259. package/test/dist/query.test.d.ts.map +1 -1
  260. package/test/dist/rawQuery.test.d.ts.map +1 -1
  261. package/test/dist/repository-ext.test.d.ts.map +1 -0
  262. package/test/dist/requires.test.d.ts.map +1 -1
  263. package/test/dist/router-generator.test.d.ts.map +1 -0
  264. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  265. package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
  266. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  267. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  268. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  269. package/test/dist/sql-store.test.d.ts.map +1 -0
  270. package/test/dist/workflow-engine-cosmos.test.d.ts.map +1 -0
  271. package/test/dist/workflow-engine-sqlite.test.d.ts.map +1 -0
  272. package/test/fixtures.ts +16 -9
  273. package/test/layerUtils.test.ts +2 -2
  274. package/test/query.test.ts +905 -40
  275. package/test/rawQuery.test.ts +340 -22
  276. package/test/repository-ext.test.ts +62 -0
  277. package/test/requires.test.ts +10 -5
  278. package/test/router-generator.test.ts +187 -0
  279. package/test/routing-interruptibility.test.ts +66 -0
  280. package/test/rpc-context-map-streaming.test.ts +262 -0
  281. package/test/rpc-e2e-invalidation.test.ts +256 -0
  282. package/test/rpc-multi-middleware.test.ts +85 -10
  283. package/test/rpc-stream-fullstack.test.ts +304 -0
  284. package/test/sql-store.test.ts +1711 -0
  285. package/test/validateSample.test.ts +26 -14
  286. package/test/workflow-engine-cosmos.test.ts +354 -0
  287. package/test/workflow-engine-sqlite.test.ts +299 -0
  288. package/tsconfig.examples.json +1 -1
  289. package/tsconfig.json +2 -1
  290. package/tsconfig.json.bak +2 -2
  291. package/tsconfig.src.json +35 -35
  292. package/tsconfig.test.json +2 -2
  293. package/dist/Emailer/service.d.ts +0 -55
  294. package/dist/Emailer/service.d.ts.map +0 -1
  295. package/dist/Emailer/service.js +0 -6
  296. package/dist/Emailer.d.ts +0 -2
  297. package/dist/Emailer.d.ts.map +0 -1
  298. package/dist/Emailer.js +0 -2
  299. package/dist/Model/Repository/ext.d.ts +0 -41
  300. package/dist/Model/Repository/ext.d.ts.map +0 -1
  301. package/dist/Model/Repository/ext.js +0 -65
  302. package/dist/Model/Repository/internal/internal.d.ts +0 -59
  303. package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
  304. package/dist/Model/Repository/internal/internal.js +0 -316
  305. package/dist/Model/Repository/legacy.d.ts +0 -19
  306. package/dist/Model/Repository/legacy.d.ts.map +0 -1
  307. package/dist/Model/Repository/legacy.js +0 -2
  308. package/dist/Model/Repository/makeRepo.d.ts +0 -49
  309. package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
  310. package/dist/Model/Repository/makeRepo.js +0 -24
  311. package/dist/Model/Repository/service.d.ts +0 -89
  312. package/dist/Model/Repository/service.d.ts.map +0 -1
  313. package/dist/Model/Repository/service.js +0 -2
  314. package/dist/Model/Repository/validation.d.ts +0 -42
  315. package/dist/Model/Repository/validation.d.ts.map +0 -1
  316. package/dist/Model/Repository/validation.js +0 -32
  317. package/dist/Model/Repository.d.ts +0 -6
  318. package/dist/Model/Repository.d.ts.map +0 -1
  319. package/dist/Model/Repository.js +0 -6
  320. package/dist/Model/dsl.d.ts +0 -32
  321. package/dist/Model/dsl.d.ts.map +0 -1
  322. package/dist/Model/dsl.js +0 -44
  323. package/dist/Model/filter/filterApi.d.ts +0 -30
  324. package/dist/Model/filter/filterApi.d.ts.map +0 -1
  325. package/dist/Model/filter/filterApi.js +0 -2
  326. package/dist/Model/filter/types/errors.d.ts +0 -29
  327. package/dist/Model/filter/types/errors.d.ts.map +0 -1
  328. package/dist/Model/filter/types/errors.js +0 -2
  329. package/dist/Model/filter/types/fields.d.ts +0 -15
  330. package/dist/Model/filter/types/fields.d.ts.map +0 -1
  331. package/dist/Model/filter/types/fields.js +0 -2
  332. package/dist/Model/filter/types/path/common.d.ts +0 -316
  333. package/dist/Model/filter/types/path/common.d.ts.map +0 -1
  334. package/dist/Model/filter/types/path/common.js +0 -2
  335. package/dist/Model/filter/types/path/eager.d.ts +0 -95
  336. package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
  337. package/dist/Model/filter/types/path/eager.js +0 -31
  338. package/dist/Model/filter/types/path/index.d.ts +0 -4
  339. package/dist/Model/filter/types/path/index.d.ts.map +0 -1
  340. package/dist/Model/filter/types/path/index.js +0 -3
  341. package/dist/Model/filter/types/utils.d.ts +0 -79
  342. package/dist/Model/filter/types/utils.d.ts.map +0 -1
  343. package/dist/Model/filter/types/utils.js +0 -2
  344. package/dist/Model/filter/types/validator.d.ts +0 -30
  345. package/dist/Model/filter/types/validator.d.ts.map +0 -1
  346. package/dist/Model/filter/types/validator.js +0 -2
  347. package/dist/Model/filter/types.d.ts +0 -5
  348. package/dist/Model/filter/types.d.ts.map +0 -1
  349. package/dist/Model/filter/types.js +0 -7
  350. package/dist/Model/query/dsl.d.ts +0 -248
  351. package/dist/Model/query/dsl.d.ts.map +0 -1
  352. package/dist/Model/query/dsl.js +0 -104
  353. package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
  354. package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
  355. package/dist/Model/query/new-kid-interpreter.js +0 -165
  356. package/dist/Model/query.d.ts +0 -15
  357. package/dist/Model/query.d.ts.map +0 -1
  358. package/dist/Model/query.js +0 -3
  359. package/dist/Model.d.ts +0 -4
  360. package/dist/Model.d.ts.map +0 -1
  361. package/dist/Model.js +0 -4
  362. package/dist/Operations.d.ts +0 -55
  363. package/dist/Operations.d.ts.map +0 -1
  364. package/dist/Operations.js +0 -102
  365. package/dist/OperationsRepo.d.ts +0 -41
  366. package/dist/OperationsRepo.d.ts.map +0 -1
  367. package/dist/OperationsRepo.js +0 -14
  368. package/dist/QueueMaker/service.d.ts +0 -11
  369. package/dist/QueueMaker/service.d.ts.map +0 -1
  370. package/dist/QueueMaker/service.js +0 -4
  371. package/dist/RequestContext.d.ts +0 -63
  372. package/dist/RequestContext.d.ts.map +0 -1
  373. package/dist/RequestContext.js +0 -49
  374. package/dist/Store/ContextMapContainer.d.ts +0 -14
  375. package/dist/Store/ContextMapContainer.d.ts.map +0 -1
  376. package/dist/Store/ContextMapContainer.js +0 -16
  377. package/dist/Store/service.d.ts +0 -108
  378. package/dist/Store/service.d.ts.map +0 -1
  379. package/dist/Store/service.js +0 -71
  380. package/dist/Store.d.ts +0 -2
  381. package/dist/Store.d.ts.map +0 -1
  382. package/dist/Store.js +0 -2
  383. package/dist/adapters/SQL/Model.d.ts +0 -479
  384. package/dist/adapters/SQL/Model.d.ts.map +0 -1
  385. package/dist/adapters/SQL/Model.js +0 -478
  386. package/dist/adapters/SQL.d.ts +0 -2
  387. package/dist/adapters/SQL.d.ts.map +0 -1
  388. package/dist/adapters/ServiceBus.d.ts +0 -58
  389. package/dist/adapters/ServiceBus.d.ts.map +0 -1
  390. package/dist/adapters/ServiceBus.js +0 -99
  391. package/dist/adapters/cosmos-client.d.ts +0 -14
  392. package/dist/adapters/cosmos-client.d.ts.map +0 -1
  393. package/dist/adapters/cosmos-client.js +0 -9
  394. package/dist/adapters/index.d.ts +0 -2
  395. package/dist/adapters/index.d.ts.map +0 -1
  396. package/dist/adapters/index.js +0 -2
  397. package/dist/adapters/logger.d.ts +0 -9
  398. package/dist/adapters/logger.d.ts.map +0 -1
  399. package/dist/adapters/logger.js +0 -3
  400. package/dist/adapters/memQueue.d.ts +0 -13
  401. package/dist/adapters/memQueue.d.ts.map +0 -1
  402. package/dist/adapters/memQueue.js +0 -20
  403. package/dist/adapters/mongo-client.d.ts +0 -10
  404. package/dist/adapters/mongo-client.d.ts.map +0 -1
  405. package/dist/adapters/mongo-client.js +0 -13
  406. package/dist/adapters/redis-client.d.ts +0 -39
  407. package/dist/adapters/redis-client.d.ts.map +0 -1
  408. package/dist/adapters/redis-client.js +0 -94
  409. package/dist/api/ContextProvider.d.ts +0 -31
  410. package/dist/api/ContextProvider.d.ts.map +0 -1
  411. package/dist/api/ContextProvider.js +0 -38
  412. package/dist/api/codec.d.ts +0 -5
  413. package/dist/api/codec.d.ts.map +0 -1
  414. package/dist/api/codec.js +0 -5
  415. package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
  416. package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
  417. package/dist/api/internal/RequestContextMiddleware.js +0 -35
  418. package/dist/api/internal/auth.d.ts +0 -15
  419. package/dist/api/internal/auth.d.ts.map +0 -1
  420. package/dist/api/internal/auth.js +0 -47
  421. package/dist/api/internal/events.d.ts +0 -9
  422. package/dist/api/internal/events.d.ts.map +0 -1
  423. package/dist/api/internal/events.js +0 -42
  424. package/dist/api/internal/health.d.ts +0 -3
  425. package/dist/api/internal/health.d.ts.map +0 -1
  426. package/dist/api/internal/health.js +0 -5
  427. package/dist/api/layerUtils.d.ts +0 -24
  428. package/dist/api/layerUtils.d.ts.map +0 -1
  429. package/dist/api/layerUtils.js +0 -16
  430. package/dist/api/middlewares.d.ts +0 -10
  431. package/dist/api/middlewares.d.ts.map +0 -1
  432. package/dist/api/reportError.d.ts +0 -4
  433. package/dist/api/reportError.d.ts.map +0 -1
  434. package/dist/api/reportError.js +0 -27
  435. package/dist/api/routing/middleware/RouterMiddleware.d.ts +0 -15
  436. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
  437. package/dist/api/routing/middleware/middleware.d.ts +0 -9
  438. package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
  439. package/dist/api/routing/middleware/middleware.js +0 -92
  440. package/dist/api/routing/middleware.d.ts +0 -4
  441. package/dist/api/routing/middleware.d.ts.map +0 -1
  442. package/dist/api/routing/schema/jwt.d.ts +0 -4
  443. package/dist/api/routing/schema/jwt.d.ts.map +0 -1
  444. package/dist/api/routing/schema/jwt.js +0 -12
  445. package/dist/api/routing/tsort.d.ts +0 -8
  446. package/dist/api/routing/tsort.d.ts.map +0 -1
  447. package/dist/api/routing/tsort.js +0 -51
  448. package/dist/api/routing/utils.d.ts +0 -19
  449. package/dist/api/routing/utils.d.ts.map +0 -1
  450. package/dist/api/routing/utils.js +0 -44
  451. package/dist/api/routing.d.ts +0 -138
  452. package/dist/api/routing.d.ts.map +0 -1
  453. package/dist/api/routing.js +0 -166
  454. package/dist/api/setupRequest.d.ts +0 -12
  455. package/dist/api/setupRequest.d.ts.map +0 -1
  456. package/dist/api/setupRequest.js +0 -44
  457. package/dist/api/util.d.ts +0 -3
  458. package/dist/api/util.d.ts.map +0 -1
  459. package/dist/api/util.js +0 -14
  460. package/eslint.config.mjs +0 -24
  461. package/src/Emailer/service.ts +0 -52
  462. package/src/Emailer.ts +0 -1
  463. package/src/Model/Repository/ext.ts +0 -283
  464. package/src/Model/Repository/internal/internal.ts +0 -577
  465. package/src/Model/Repository/legacy.ts +0 -27
  466. package/src/Model/Repository/makeRepo.ts +0 -139
  467. package/src/Model/Repository/service.ts +0 -627
  468. package/src/Model/Repository/validation.ts +0 -31
  469. package/src/Model/Repository.ts +0 -5
  470. package/src/Model/dsl.ts +0 -128
  471. package/src/Model/filter/filterApi.ts +0 -60
  472. package/src/Model/filter/types/errors.ts +0 -47
  473. package/src/Model/filter/types/fields.ts +0 -50
  474. package/src/Model/filter/types/path/common.ts +0 -404
  475. package/src/Model/filter/types/path/eager.ts +0 -298
  476. package/src/Model/filter/types/path/index.ts +0 -4
  477. package/src/Model/filter/types/utils.ts +0 -128
  478. package/src/Model/filter/types/validator.ts +0 -46
  479. package/src/Model/filter/types.ts +0 -6
  480. package/src/Model/query/dsl.ts +0 -2110
  481. package/src/Model/query/new-kid-interpreter.ts +0 -210
  482. package/src/Model/query.ts +0 -13
  483. package/src/Model.ts +0 -3
  484. package/src/Operations.ts +0 -235
  485. package/src/OperationsRepo.ts +0 -16
  486. package/src/QueueMaker/service.ts +0 -17
  487. package/src/RequestContext.ts +0 -63
  488. package/src/Store/ContextMapContainer.ts +0 -20
  489. package/src/Store/service.ts +0 -184
  490. package/src/Store.ts +0 -1
  491. package/src/adapters/ServiceBus.ts +0 -209
  492. package/src/adapters/index.ts +0 -0
  493. package/src/adapters/logger.ts +0 -3
  494. package/src/api/internal/auth.ts +0 -68
  495. package/src/api/routing/middleware.ts +0 -6
  496. package/src/api/routing.ts +0 -598
  497. package/src/api/setupRequest.ts +0 -84
  498. /package/src/{adapters/SQL.ts → SQL.ts} +0 -0
  499. /package/src/{api/codec.ts → codec.ts} +0 -0
  500. /package/src/{api/internal → internal}/health.ts +0 -0
  501. /package/src/{api/middlewares.ts → middlewares.ts} +0 -0
  502. /package/src/{api/routing → routing}/tsort.ts +0 -0
  503. /package/src/{api/util.ts → util.ts} +0 -0
package/src/routing.ts ADDED
@@ -0,0 +1,768 @@
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 type { NonEmptyReadonlyArray } from "effect-app/Array"
6
+ import { getMeta } from "effect-app/client"
7
+ import * as Config from "effect-app/Config"
8
+ import * as Effect from "effect-app/Effect"
9
+ import { type HttpHeaders } from "effect-app/http"
10
+ import * as Layer from "effect-app/Layer"
11
+ import { Invalidation } from "effect-app/rpc"
12
+ import { type GetEffectContext, type GetEffectError, type RpcContextMap } from "effect-app/rpc/RpcContextMap"
13
+ import * as S from "effect-app/Schema"
14
+ import { type TypeTestId } from "effect-app/TypeTest"
15
+ import { typedKeysOf, typedValuesOf } from "effect-app/utils"
16
+ import * as Predicate from "effect/Predicate"
17
+ import * as Ref from "effect/Ref"
18
+ import type * as Scope from "effect/Scope"
19
+ import * as Stream from "effect/Stream"
20
+ import { Rpc, RpcGroup, type RpcSerialization, RpcServer } from "effect/unstable/rpc"
21
+ import { type LayerUtils } from "./layerUtils.js"
22
+ import { RequestType as RequestTypeAnnotation } from "./routing/middleware.js"
23
+
24
+ export * from "./routing/middleware.js"
25
+
26
+ export const applyRequestTypeInterruptibility = <A, E, R>(
27
+ requestType: "command" | "query",
28
+ effect: Effect.Effect<A, E, R>
29
+ ) => requestType === "command" ? Rpc.uninterruptible(effect) : effect
30
+
31
+ // it's the result of extending S.Req setting success, config
32
+ // it's a schema plus some metadata
33
+ export type AnyRequestModule = S.Top & {
34
+ _tag: string // unique identifier for the request module
35
+ type: "command" | "query"
36
+ stream: boolean
37
+ config: any // ?
38
+ success: S.Top // validates the success response
39
+ error: S.Top // validates the failure response
40
+ }
41
+
42
+ // builder pattern for adding actions to a router until all actions are added
43
+ export interface AddAction<Actions extends AnyRequestModule, Accum extends Record<string, any> = {}> {
44
+ accum: Accum
45
+ add<A extends Handler<Actions, any, any>>(
46
+ a: A
47
+ ): A extends Handler<infer M extends AnyRequestModule, any, any> ? Exclude<Actions, M> extends never ?
48
+ & Accum
49
+ & { [K in M["_tag"]]: A }
50
+ :
51
+ & AddAction<
52
+ Exclude<Actions, M>,
53
+ & Accum
54
+ & { [K in M["_tag"]]: A }
55
+ >
56
+ & Accum
57
+ & { [K in M["_tag"]]: A }
58
+ : never
59
+ }
60
+
61
+ // note:
62
+ // "d" stands for decoded i.e. the Type
63
+ // "raw" stands for encoded i.e. the Encoded
64
+ namespace RequestTypes {
65
+ export const DECODED = "d" as const
66
+ export type DECODED = typeof DECODED
67
+ export const RAW = "raw" as const
68
+ export type RAW = typeof RAW
69
+ }
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, 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, 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, RequestTypes.DECODED>
312
+
313
+ type HandlersRaw<Action extends AnyRequestModule> = Action extends { stream: true }
314
+ ? { raw: HandlerWithInputStream<Action, RequestTypes.RAW> }
315
+ :
316
+ | { raw: HandlerWithInputGen<Action, RequestTypes.RAW> }
317
+ | { raw: HandlerWithInputEff<Action, 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 } ? RequestTypes.RAW : 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
+ if (resource.stream) {
453
+ // Wrap stream items as { _tag: "value", value } and append a final
454
+ // { _tag: "done", metadata } chunk carrying accumulated invalidation keys.
455
+ // V2: on failure, convert to { _tag: "error", error, metadata } chunk so
456
+ // clients can invalidate queries even when the stream fails.
457
+ const keysRef = Ref.makeUnsafe<ReadonlyArray<Invalidation.InvalidationKey>>([])
458
+ const invalidationSet = Invalidation.makeInvalidationSet(keysRef)
459
+ return Stream.concat(
460
+ (result as Stream.Stream<any, any, any>).pipe(
461
+ Stream.map((item: any) => ({ _tag: "value" as const, value: item })),
462
+ Stream.provideService(Invalidation.InvalidationSet, invalidationSet),
463
+ // V3: after each value chunk, drain accumulated keys and emit a "metadata"
464
+ // chunk if any keys were collected since the last drain. This lets clients
465
+ // invalidate queries mid-stream without waiting for the "done" chunk.
466
+ Stream.flatMap((valueChunk: any) =>
467
+ Stream
468
+ .fromEffect(
469
+ Ref.getAndSet(keysRef, []).pipe(
470
+ Effect.map((keys) =>
471
+ keys.length > 0
472
+ ? [
473
+ valueChunk,
474
+ { _tag: "metadata" as const, metadata: { invalidateQueries: keys } }
475
+ ]
476
+ : [valueChunk]
477
+ )
478
+ )
479
+ )
480
+ .pipe(Stream.flatMap(Stream.fromIterable))
481
+ ),
482
+ // V2: catch stream failures and embed them in the stream as an error chunk
483
+ Stream.catch((err: any) =>
484
+ Stream.fromEffect(
485
+ Ref.get(keysRef).pipe(
486
+ Effect.flatMap((keys) =>
487
+ Effect.fail({
488
+ _tag: "error" as const,
489
+ error: err,
490
+ metadata: { invalidateQueries: keys }
491
+ })
492
+ )
493
+ )
494
+ )
495
+ )
496
+ ),
497
+ Stream.fromEffect(
498
+ Ref.get(keysRef).pipe(
499
+ Effect.map((keys) => ({ _tag: "done" as const, metadata: { invalidateQueries: keys } }))
500
+ )
501
+ )
502
+ )
503
+ }
504
+
505
+ let effect = Effect
506
+ .annotateCurrentSpan({
507
+ "rpc.system": "effect-app",
508
+ "rpc.service": meta.moduleName,
509
+ "rpc.method": resource._tag,
510
+ "code.function.name": resource._tag,
511
+ "code.namespace": meta.moduleName,
512
+ "app.rpc.type": resource.type
513
+ })
514
+ .pipe(Effect.andThen(result as Effect.Effect<unknown, unknown, unknown>))
515
+
516
+ // Commands: provide a request-scoped `InvalidationSet` and wrap both
517
+ // success (`CommandResponseWithMetaData`) and handler-thrown failure
518
+ // (`CommandFailureWithMetaData`) so the client receives accumulated
519
+ // invalidation keys on either path. Middleware-thrown errors bypass the
520
+ // wrap (they fail the outer effect before reaching this `.catch`) and
521
+ // flow raw on the Cause; client decodes them via the rpc's
522
+ // `middlewares[*].error` failure-union channel.
523
+ if (resource.type === "command") {
524
+ const keysRef = Ref.makeUnsafe<ReadonlyArray<Invalidation.InvalidationKey>>([])
525
+ const invalidationSet = Invalidation.makeInvalidationSet(keysRef)
526
+ effect = effect.pipe(
527
+ Effect.provideService(Invalidation.InvalidationSet, invalidationSet),
528
+ Effect.flatMap((value) =>
529
+ Ref.get(keysRef).pipe(
530
+ Effect.map((keys) => ({ payload: value, metadata: { invalidateQueries: keys } }) as any)
531
+ )
532
+ ),
533
+ Effect.catch((err: any) =>
534
+ Ref.get(keysRef).pipe(
535
+ Effect.flatMap((keys) =>
536
+ Effect.fail({
537
+ _tag: "CommandFailureWithMetaData" as const,
538
+ error: err,
539
+ metadata: { invalidateQueries: keys }
540
+ })
541
+ )
542
+ )
543
+ )
544
+ )
545
+ }
546
+
547
+ return applyRequestTypeInterruptibility(resource.type, effect)
548
+ }
549
+ ] as const
550
+ return acc
551
+ }, {} as any) as {
552
+ [K in keyof RequestModules]: [
553
+ Resource[K],
554
+ (
555
+ req: any,
556
+ headers: HttpHeaders.Headers
557
+ ) => Effect.Effect<
558
+ Effect.Success<ReturnType<THandlers[K]["handler"]>>,
559
+ | Effect.Error<ReturnType<THandlers[K]["handler"]>>
560
+ | SafeGetEffectError<ResourceRequestContextMap, Resource[K]["config"]>,
561
+ Exclude<
562
+ Effect.Services<ReturnType<THandlers[K]["handler"]>>,
563
+ ResourceContextProviderA | SafeGetEffectContext<ResourceRequestContextMap, Resource[K]["config"]>
564
+ >
565
+ >
566
+ ]
567
+ }
568
+
569
+ const rpcs = RpcGroup
570
+ .make(
571
+ ...typedValuesOf(mapped).map(([resource]) => {
572
+ const isStream = resource.stream
573
+ const isCommand = resource.type === "command"
574
+ return (isCommand
575
+ ? isStream
576
+ ? Invalidation.makeStreamRpc(resource._tag, {
577
+ payload: resource,
578
+ success: resource.success,
579
+ error: resource.error,
580
+ stream: true as const
581
+ })
582
+ : Invalidation.makeCommandRpc(resource._tag, {
583
+ payload: resource,
584
+ success: resource.success,
585
+ error: resource.error
586
+ })
587
+ : Rpc.make(resource._tag, {
588
+ payload: resource,
589
+ success: resource.success,
590
+ error: resource.error,
591
+ stream: isStream
592
+ }))
593
+ .annotate(mw.requestContext, resource.config ?? {})
594
+ .annotate(RequestTypeAnnotation, resource.type)
595
+ })
596
+ )
597
+ .prefix(`${meta.moduleName}.`)
598
+ .middleware(mw)
599
+
600
+ const rpc = rpcs
601
+ .toLayer(Effect.gen(function*() {
602
+ return typedValuesOf(mapped).reduce((acc, [resource, handler]) => {
603
+ acc[`${meta.moduleName}.${resource._tag}`] = handler
604
+ return acc
605
+ }, {} as Record<string, any>) as any // TODO
606
+ })) as unknown as Layer.Layer<
607
+ { [K in keyof RequestModules]: Rpc.Handler<K> },
608
+ MakeE,
609
+ RpcRouteR<typeof mapped[keyof typeof mapped]>
610
+ >
611
+
612
+ return RpcServer
613
+ .layerHttp({
614
+ group: rpcs,
615
+ path: ("/rpc/" + meta.moduleName) as `/${typeof meta.moduleName}`,
616
+ protocol: "http"
617
+ })
618
+ .pipe(Layer.provide(rpc))
619
+ })
620
+ .pipe(Layer.unwrap)
621
+
622
+ const routes = layer.pipe(
623
+ Layer.provide([
624
+ dependenciesL,
625
+ (middlewareLive ?? Layer.empty) as Layer.Layer<any, any, any>
626
+ ])
627
+ )
628
+
629
+ const check = options?.check
630
+ return check
631
+ ? Effect
632
+ .gen(function*() {
633
+ if (!(yield* check)) {
634
+ yield* Effect.logWarning(`Skipping router for module ${meta.moduleName}`)
635
+ return Layer.empty
636
+ }
637
+ return routes
638
+ })
639
+ .pipe(Layer.unwrap)
640
+ : routes
641
+ }
642
+
643
+ const effect: {
644
+ // Multiple times duplicated the "good" overload, so that errors will only mention the last overload when failing
645
+ <
646
+ const Make extends {
647
+ dependencies?: ReadonlyArray<Layer.Any>
648
+ effect: (match: typeof router3) => Generator<
649
+ Effect.Effect<
650
+ any,
651
+ any,
652
+ any
653
+ >,
654
+ { [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
655
+ >
656
+ /** @deprecated */
657
+ readonly ಠ_ಠ: never
658
+ }
659
+ >(
660
+ make: Make
661
+ ):
662
+ & Layer.Layer<
663
+ never,
664
+ | MakeErrors<Make>
665
+ | MakeDepsE<Make>
666
+ | Layer.Error<ResourceMWDefault>,
667
+ | MakeDepsIn<Make>
668
+ | Layer.Services<ResourceMWDefault>
669
+ | Exclude<
670
+ MakeContext<Make>,
671
+ MakeDepsOut<Make>
672
+ >
673
+ | RpcSerialization.RpcSerialization
674
+ >
675
+ & {
676
+ // just for type testing purposes
677
+ [TypeTestId]: Make
678
+ }
679
+ <
680
+ const Make extends {
681
+ dependencies?: ReadonlyArray<Layer.Any>
682
+ // v4: generators yield Yieldable with asEffect()
683
+ effect: (match: typeof router3) => Generator<
684
+ Effect.Effect<any, any, any>,
685
+ { [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
686
+ >
687
+ }
688
+ >(
689
+ make: Make
690
+ ):
691
+ & Layer.Layer<
692
+ never,
693
+ | MakeErrors<Make>
694
+ | MakeDepsE<Make>
695
+ | Layer.Error<ResourceMWDefault>,
696
+ | MakeDepsIn<Make>
697
+ | Layer.Services<ResourceMWDefault>
698
+ | Exclude<
699
+ MakeContext<Make>,
700
+ MakeDepsOut<Make>
701
+ >
702
+ | RpcSerialization.RpcSerialization
703
+ >
704
+ & {
705
+ // just for type testing purposes
706
+ readonly [TypeTestId]: Make
707
+ }
708
+ } =
709
+ ((make: { dependencies: any; effect: any }) =>
710
+ Object.assign(makeRoutes(make.dependencies, make.effect), { make })) as any
711
+
712
+ return effect
713
+ }
714
+
715
+ function matchAll<
716
+ T extends {
717
+ [key: string]: Layer.Layer<never, any, any>
718
+ }
719
+ >(
720
+ handlers: T
721
+ ) {
722
+ const routers = typedValuesOf(handlers)
723
+
724
+ return Layer.mergeAll(...routers as [any]) as unknown as Layer.Layer<
725
+ never,
726
+ Layer.Error<typeof handlers[keyof typeof handlers]>,
727
+ Layer.Services<typeof handlers[keyof typeof handlers]>
728
+ >
729
+ }
730
+
731
+ return {
732
+ matchAll,
733
+ Router: matchFor
734
+ }
735
+ }
736
+
737
+ export type MakeDeps<Make> = Make extends { readonly dependencies: ReadonlyArray<Layer.Any> }
738
+ ? Make["dependencies"][number]
739
+ : never
740
+
741
+ export type MakeErrors<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, infer E, any> } ? E
742
+ : Make extends { readonly effect: (_: any) => Effect.Effect<any, never, any> } ? never
743
+ : */
744
+ // v4: generators yield Effect values
745
+ Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, never, any>, any> } ? never
746
+ : Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, infer E, any>, any> } ? E
747
+ : never
748
+
749
+ export type MakeContext<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, any, infer R> } ? R
750
+ : Make extends { readonly effect: (_: any) => Effect.Effect<any, any, never> } ? never
751
+ : */
752
+ // v4: generators yield Effect values
753
+ Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, any, never>, any> } ? never
754
+ : Make extends { readonly effect: (_: any) => Generator<Effect.Effect<any, any, infer R>, any> } ? R
755
+ : never
756
+
757
+ export type MakeHandlers<Make, _Handlers extends Record<string, any>> = /*Make extends
758
+ { readonly effect: (_: any) => Effect.Effect<{ [K in keyof Handlers]: AnyHandler<Handlers[K]> }, any, any> }
759
+ ? Effect.Success<ReturnType<Make["effect"]>>
760
+ : */
761
+ Make extends { readonly effect: (_: any) => Generator<any, infer S> } ? S
762
+ : never
763
+
764
+ export type MakeDepsE<Make> = Layer.Error<MakeDeps<Make>>
765
+
766
+ export type MakeDepsIn<Make> = Layer.Services<MakeDeps<Make>>
767
+
768
+ export type MakeDepsOut<Make> = Layer.Success<MakeDeps<Make>>