@effect-app/infra 4.0.0-beta.99 → 4.0.1

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