@effect-app/infra 4.0.0-beta.25 → 4.0.0-beta.251

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 (467) hide show
  1. package/CHANGELOG.md +1900 -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/ContextProvider.d.ts +34 -0
  7. package/dist/ContextProvider.d.ts.map +1 -0
  8. package/dist/ContextProvider.js +40 -0
  9. package/dist/Emailer/Sendgrid.d.ts +111 -147
  10. package/dist/Emailer/Sendgrid.d.ts.map +1 -1
  11. package/dist/Emailer/Sendgrid.js +24 -19
  12. package/dist/Emailer/fake.d.ts +2 -2
  13. package/dist/Emailer/fake.d.ts.map +1 -1
  14. package/dist/Emailer/fake.js +4 -4
  15. package/dist/MainFiberSet.d.ts +12 -9
  16. package/dist/MainFiberSet.d.ts.map +1 -1
  17. package/dist/MainFiberSet.js +10 -6
  18. package/dist/QueueMaker/SQLQueue.d.ts +8 -9
  19. package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
  20. package/dist/QueueMaker/SQLQueue.js +138 -120
  21. package/dist/QueueMaker/errors.d.ts +5 -3
  22. package/dist/QueueMaker/errors.d.ts.map +1 -1
  23. package/dist/QueueMaker/errors.js +4 -2
  24. package/dist/QueueMaker/memQueue.d.ts +10 -6
  25. package/dist/QueueMaker/memQueue.d.ts.map +1 -1
  26. package/dist/QueueMaker/memQueue.js +84 -68
  27. package/dist/QueueMaker/sbqueue.d.ts +9 -5
  28. package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
  29. package/dist/QueueMaker/sbqueue.js +60 -58
  30. package/dist/RequestFiberSet.d.ts +10 -7
  31. package/dist/RequestFiberSet.d.ts.map +1 -1
  32. package/dist/RequestFiberSet.js +13 -8
  33. package/dist/SQL/Model.d.ts +468 -0
  34. package/dist/SQL/Model.d.ts.map +1 -0
  35. package/dist/SQL/Model.js +469 -0
  36. package/dist/SQL.d.ts +2 -0
  37. package/dist/SQL.d.ts.map +1 -0
  38. package/dist/{adapters/SQL.js → SQL.js} +1 -1
  39. package/dist/ServiceBus.d.ts +61 -0
  40. package/dist/ServiceBus.d.ts.map +1 -0
  41. package/dist/ServiceBus.js +108 -0
  42. package/dist/Store/Cosmos/query.d.ts +15 -4
  43. package/dist/Store/Cosmos/query.d.ts.map +1 -1
  44. package/dist/Store/Cosmos/query.js +179 -41
  45. package/dist/Store/Cosmos.d.ts +3 -3
  46. package/dist/Store/Cosmos.d.ts.map +1 -1
  47. package/dist/Store/Cosmos.js +344 -246
  48. package/dist/Store/Disk.d.ts +5 -5
  49. package/dist/Store/Disk.d.ts.map +1 -1
  50. package/dist/Store/Disk.js +78 -38
  51. package/dist/Store/Memory.d.ts +7 -10
  52. package/dist/Store/Memory.d.ts.map +1 -1
  53. package/dist/Store/Memory.js +326 -66
  54. package/dist/Store/SQL/Pg.d.ts +4 -0
  55. package/dist/Store/SQL/Pg.d.ts.map +1 -0
  56. package/dist/Store/SQL/Pg.js +232 -0
  57. package/dist/Store/SQL/query.d.ts +49 -0
  58. package/dist/Store/SQL/query.d.ts.map +1 -0
  59. package/dist/Store/SQL/query.js +527 -0
  60. package/dist/Store/SQL.d.ts +21 -0
  61. package/dist/Store/SQL.d.ts.map +1 -0
  62. package/dist/Store/SQL.js +449 -0
  63. package/dist/Store/codeFilter.d.ts +5 -5
  64. package/dist/Store/codeFilter.d.ts.map +1 -1
  65. package/dist/Store/codeFilter.js +6 -3
  66. package/dist/Store/index.d.ts +7 -5
  67. package/dist/Store/index.d.ts.map +1 -1
  68. package/dist/Store/index.js +18 -5
  69. package/dist/Store/utils.d.ts +4 -3
  70. package/dist/Store/utils.d.ts.map +1 -1
  71. package/dist/Store/utils.js +5 -5
  72. package/dist/arbs.d.ts +2 -2
  73. package/dist/arbs.d.ts.map +1 -1
  74. package/dist/arbs.js +5 -3
  75. package/dist/codec.d.ts +5 -0
  76. package/dist/codec.d.ts.map +1 -0
  77. package/dist/codec.js +5 -0
  78. package/dist/cosmos-client.d.ts +16 -0
  79. package/dist/cosmos-client.d.ts.map +1 -0
  80. package/dist/cosmos-client.js +11 -0
  81. package/dist/errorReporter.d.ts +7 -5
  82. package/dist/errorReporter.d.ts.map +1 -1
  83. package/dist/errorReporter.js +23 -27
  84. package/dist/errors.d.ts +1 -1
  85. package/dist/fileUtil.d.ts +2 -2
  86. package/dist/fileUtil.d.ts.map +1 -1
  87. package/dist/fileUtil.js +2 -2
  88. package/dist/index.d.ts +3 -2
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +3 -2
  91. package/dist/internal/RequestContextMiddleware.d.ts +5 -0
  92. package/dist/internal/RequestContextMiddleware.d.ts.map +1 -0
  93. package/dist/internal/RequestContextMiddleware.js +45 -0
  94. package/dist/internal/auth.d.ts +53 -0
  95. package/dist/internal/auth.d.ts.map +1 -0
  96. package/dist/internal/auth.js +180 -0
  97. package/dist/internal/events.d.ts +11 -0
  98. package/dist/internal/events.d.ts.map +1 -0
  99. package/dist/internal/events.js +49 -0
  100. package/dist/internal/health.d.ts +3 -0
  101. package/dist/internal/health.d.ts.map +1 -0
  102. package/dist/internal/health.js +5 -0
  103. package/dist/layerUtils.d.ts +32 -0
  104. package/dist/layerUtils.d.ts.map +1 -0
  105. package/dist/layerUtils.js +17 -0
  106. package/dist/logger/jsonLogger.d.ts +2 -2
  107. package/dist/logger/jsonLogger.d.ts.map +1 -1
  108. package/dist/logger/jsonLogger.js +5 -3
  109. package/dist/logger/logFmtLogger.d.ts +2 -2
  110. package/dist/logger/logFmtLogger.d.ts.map +1 -1
  111. package/dist/logger/logFmtLogger.js +3 -3
  112. package/dist/logger/shared.d.ts +3 -3
  113. package/dist/logger/shared.d.ts.map +1 -1
  114. package/dist/logger/shared.js +5 -5
  115. package/dist/logger.d.ts +1 -1
  116. package/dist/logger.d.ts.map +1 -1
  117. package/dist/memQueue.d.ts +15 -0
  118. package/dist/memQueue.d.ts.map +1 -0
  119. package/dist/memQueue.js +21 -0
  120. package/dist/middlewares.d.ts +10 -0
  121. package/dist/middlewares.d.ts.map +1 -0
  122. package/dist/{api/middlewares.js → middlewares.js} +1 -1
  123. package/dist/mongo-client.d.ts +11 -0
  124. package/dist/mongo-client.d.ts.map +1 -0
  125. package/dist/mongo-client.js +15 -0
  126. package/dist/otel.d.ts +75 -0
  127. package/dist/otel.d.ts.map +1 -0
  128. package/dist/otel.js +65 -0
  129. package/dist/rateLimit.d.ts +12 -4
  130. package/dist/rateLimit.d.ts.map +1 -1
  131. package/dist/rateLimit.js +7 -12
  132. package/dist/redis-client.d.ts +42 -0
  133. package/dist/redis-client.d.ts.map +1 -0
  134. package/dist/redis-client.js +98 -0
  135. package/dist/reportError.d.ts +4 -0
  136. package/dist/reportError.d.ts.map +1 -0
  137. package/dist/reportError.js +28 -0
  138. package/dist/routing/middleware/RouterMiddleware.d.ts +16 -0
  139. package/dist/routing/middleware/RouterMiddleware.d.ts.map +1 -0
  140. package/dist/{api/routing → routing}/middleware/RouterMiddleware.js +1 -1
  141. package/dist/routing/middleware/middleware.d.ts +48 -0
  142. package/dist/routing/middleware/middleware.d.ts.map +1 -0
  143. package/dist/routing/middleware/middleware.js +128 -0
  144. package/dist/routing/middleware.d.ts +3 -0
  145. package/dist/routing/middleware.d.ts.map +1 -0
  146. package/dist/{api/routing → routing}/middleware.js +1 -2
  147. package/dist/routing/schema/jwt.d.ts +4 -0
  148. package/dist/routing/schema/jwt.d.ts.map +1 -0
  149. package/dist/routing/schema/jwt.js +13 -0
  150. package/dist/routing/tsort.d.ts +8 -0
  151. package/dist/routing/tsort.d.ts.map +1 -0
  152. package/dist/routing/tsort.js +51 -0
  153. package/dist/routing/utils.d.ts +19 -0
  154. package/dist/routing/utils.d.ts.map +1 -0
  155. package/dist/routing/utils.js +45 -0
  156. package/dist/routing.d.ts +184 -0
  157. package/dist/routing.d.ts.map +1 -0
  158. package/dist/routing.js +236 -0
  159. package/dist/test.d.ts +3 -3
  160. package/dist/test.d.ts.map +1 -1
  161. package/dist/test.js +2 -2
  162. package/dist/util.d.ts +3 -0
  163. package/dist/util.d.ts.map +1 -0
  164. package/dist/util.js +14 -0
  165. package/dist/vitest.d.ts +1 -1
  166. package/examples/query.ts +47 -39
  167. package/package.json +119 -234
  168. package/src/CUPS.ts +52 -13
  169. package/src/{api/ContextProvider.ts → ContextProvider.ts} +19 -16
  170. package/src/Emailer/Sendgrid.ts +82 -59
  171. package/src/Emailer/fake.ts +3 -3
  172. package/src/MainFiberSet.ts +12 -10
  173. package/src/QueueMaker/SQLQueue.ts +153 -156
  174. package/src/QueueMaker/errors.ts +3 -1
  175. package/src/QueueMaker/memQueue.ts +113 -107
  176. package/src/QueueMaker/sbqueue.ts +78 -90
  177. package/src/RequestFiberSet.ts +13 -8
  178. package/src/{adapters/SQL → SQL}/Model.ts +42 -41
  179. package/src/ServiceBus.ts +219 -0
  180. package/src/Store/Cosmos/query.ts +216 -52
  181. package/src/Store/Cosmos.ts +493 -353
  182. package/src/Store/Disk.ts +109 -69
  183. package/src/Store/Memory.ts +365 -96
  184. package/src/Store/SQL/Pg.ts +363 -0
  185. package/src/Store/SQL/query.ts +603 -0
  186. package/src/Store/SQL.ts +735 -0
  187. package/src/Store/codeFilter.ts +8 -5
  188. package/src/Store/index.ts +21 -6
  189. package/src/Store/utils.ts +26 -24
  190. package/src/arbs.ts +5 -3
  191. package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
  192. package/src/errorReporter.ts +66 -76
  193. package/src/fileUtil.ts +1 -1
  194. package/src/index.ts +2 -1
  195. package/src/{api/internal → internal}/RequestContextMiddleware.ts +23 -6
  196. package/src/internal/auth.ts +272 -0
  197. package/src/{api/internal → internal}/events.ts +22 -13
  198. package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
  199. package/src/logger/jsonLogger.ts +4 -2
  200. package/src/logger/logFmtLogger.ts +2 -2
  201. package/src/logger/shared.ts +5 -4
  202. package/src/{adapters/memQueue.ts → memQueue.ts} +5 -4
  203. package/src/{adapters/mongo-client.ts → mongo-client.ts} +4 -2
  204. package/src/otel.ts +152 -0
  205. package/src/rateLimit.ts +34 -23
  206. package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
  207. package/src/{api/reportError.ts → reportError.ts} +3 -2
  208. package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
  209. package/src/{api/routing → routing}/middleware/middleware.ts +62 -17
  210. package/src/routing/middleware.ts +4 -0
  211. package/src/{api/routing → routing}/schema/jwt.ts +2 -1
  212. package/src/{api/routing → routing}/utils.ts +2 -1
  213. package/src/routing.ts +768 -0
  214. package/src/test.ts +2 -2
  215. package/test/auth.test.ts +101 -0
  216. package/test/contextProvider.test.ts +15 -12
  217. package/test/controller.test.ts +28 -32
  218. package/test/cosmos-query.test.ts +159 -0
  219. package/test/dist/auth.test.d.ts.map +1 -0
  220. package/test/dist/contextProvider.test.d.ts.map +1 -1
  221. package/test/dist/controller.test.d.ts.map +1 -1
  222. package/test/dist/cosmos-query.test.d.ts.map +1 -0
  223. package/test/dist/date-query.test.d.ts.map +1 -0
  224. package/test/dist/fixtures.d.ts +30 -12
  225. package/test/dist/fixtures.d.ts.map +1 -1
  226. package/test/dist/fixtures.js +17 -10
  227. package/test/dist/query.test.d.ts.map +1 -1
  228. package/test/dist/rawQuery.test.d.ts.map +1 -1
  229. package/test/dist/repository-ext.test.d.ts.map +1 -0
  230. package/test/dist/requires.test.d.ts.map +1 -1
  231. package/test/dist/router-generator.test.d.ts.map +1 -0
  232. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  233. package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
  234. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  235. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  236. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  237. package/test/dist/sql-store.test.d.ts.map +1 -0
  238. package/test/fixtures.ts +16 -9
  239. package/test/layerUtils.test.ts +2 -2
  240. package/test/query.test.ts +903 -40
  241. package/test/rawQuery.test.ts +340 -22
  242. package/test/repository-ext.test.ts +62 -0
  243. package/test/requires.test.ts +10 -5
  244. package/test/router-generator.test.ts +187 -0
  245. package/test/routing-interruptibility.test.ts +66 -0
  246. package/test/rpc-context-map-streaming.test.ts +262 -0
  247. package/test/rpc-e2e-invalidation.test.ts +256 -0
  248. package/test/rpc-multi-middleware.test.ts +85 -10
  249. package/test/rpc-stream-fullstack.test.ts +304 -0
  250. package/test/sql-store.test.ts +1711 -0
  251. package/test/validateSample.test.ts +19 -14
  252. package/tsconfig.examples.json +1 -1
  253. package/tsconfig.json +2 -1
  254. package/tsconfig.json.bak +2 -2
  255. package/tsconfig.src.json +35 -35
  256. package/tsconfig.test.json +2 -2
  257. package/dist/Emailer/service.d.ts +0 -55
  258. package/dist/Emailer/service.d.ts.map +0 -1
  259. package/dist/Emailer/service.js +0 -6
  260. package/dist/Emailer.d.ts +0 -2
  261. package/dist/Emailer.d.ts.map +0 -1
  262. package/dist/Emailer.js +0 -2
  263. package/dist/Model/Repository/ext.d.ts +0 -41
  264. package/dist/Model/Repository/ext.d.ts.map +0 -1
  265. package/dist/Model/Repository/ext.js +0 -65
  266. package/dist/Model/Repository/internal/internal.d.ts +0 -59
  267. package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
  268. package/dist/Model/Repository/internal/internal.js +0 -316
  269. package/dist/Model/Repository/legacy.d.ts +0 -19
  270. package/dist/Model/Repository/legacy.d.ts.map +0 -1
  271. package/dist/Model/Repository/legacy.js +0 -2
  272. package/dist/Model/Repository/makeRepo.d.ts +0 -49
  273. package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
  274. package/dist/Model/Repository/makeRepo.js +0 -24
  275. package/dist/Model/Repository/service.d.ts +0 -89
  276. package/dist/Model/Repository/service.d.ts.map +0 -1
  277. package/dist/Model/Repository/service.js +0 -2
  278. package/dist/Model/Repository/validation.d.ts +0 -42
  279. package/dist/Model/Repository/validation.d.ts.map +0 -1
  280. package/dist/Model/Repository/validation.js +0 -32
  281. package/dist/Model/Repository.d.ts +0 -6
  282. package/dist/Model/Repository.d.ts.map +0 -1
  283. package/dist/Model/Repository.js +0 -6
  284. package/dist/Model/dsl.d.ts +0 -32
  285. package/dist/Model/dsl.d.ts.map +0 -1
  286. package/dist/Model/dsl.js +0 -44
  287. package/dist/Model/filter/filterApi.d.ts +0 -30
  288. package/dist/Model/filter/filterApi.d.ts.map +0 -1
  289. package/dist/Model/filter/filterApi.js +0 -2
  290. package/dist/Model/filter/types/errors.d.ts +0 -29
  291. package/dist/Model/filter/types/errors.d.ts.map +0 -1
  292. package/dist/Model/filter/types/errors.js +0 -2
  293. package/dist/Model/filter/types/fields.d.ts +0 -15
  294. package/dist/Model/filter/types/fields.d.ts.map +0 -1
  295. package/dist/Model/filter/types/fields.js +0 -2
  296. package/dist/Model/filter/types/path/common.d.ts +0 -316
  297. package/dist/Model/filter/types/path/common.d.ts.map +0 -1
  298. package/dist/Model/filter/types/path/common.js +0 -2
  299. package/dist/Model/filter/types/path/eager.d.ts +0 -95
  300. package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
  301. package/dist/Model/filter/types/path/eager.js +0 -31
  302. package/dist/Model/filter/types/path/index.d.ts +0 -4
  303. package/dist/Model/filter/types/path/index.d.ts.map +0 -1
  304. package/dist/Model/filter/types/path/index.js +0 -3
  305. package/dist/Model/filter/types/utils.d.ts +0 -79
  306. package/dist/Model/filter/types/utils.d.ts.map +0 -1
  307. package/dist/Model/filter/types/utils.js +0 -2
  308. package/dist/Model/filter/types/validator.d.ts +0 -30
  309. package/dist/Model/filter/types/validator.d.ts.map +0 -1
  310. package/dist/Model/filter/types/validator.js +0 -2
  311. package/dist/Model/filter/types.d.ts +0 -5
  312. package/dist/Model/filter/types.d.ts.map +0 -1
  313. package/dist/Model/filter/types.js +0 -7
  314. package/dist/Model/query/dsl.d.ts +0 -248
  315. package/dist/Model/query/dsl.d.ts.map +0 -1
  316. package/dist/Model/query/dsl.js +0 -104
  317. package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
  318. package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
  319. package/dist/Model/query/new-kid-interpreter.js +0 -165
  320. package/dist/Model/query.d.ts +0 -15
  321. package/dist/Model/query.d.ts.map +0 -1
  322. package/dist/Model/query.js +0 -3
  323. package/dist/Model.d.ts +0 -4
  324. package/dist/Model.d.ts.map +0 -1
  325. package/dist/Model.js +0 -4
  326. package/dist/Operations.d.ts +0 -55
  327. package/dist/Operations.d.ts.map +0 -1
  328. package/dist/Operations.js +0 -102
  329. package/dist/OperationsRepo.d.ts +0 -41
  330. package/dist/OperationsRepo.d.ts.map +0 -1
  331. package/dist/OperationsRepo.js +0 -14
  332. package/dist/QueueMaker/service.d.ts +0 -11
  333. package/dist/QueueMaker/service.d.ts.map +0 -1
  334. package/dist/QueueMaker/service.js +0 -4
  335. package/dist/RequestContext.d.ts +0 -63
  336. package/dist/RequestContext.d.ts.map +0 -1
  337. package/dist/RequestContext.js +0 -49
  338. package/dist/Store/ContextMapContainer.d.ts +0 -14
  339. package/dist/Store/ContextMapContainer.d.ts.map +0 -1
  340. package/dist/Store/ContextMapContainer.js +0 -16
  341. package/dist/Store/service.d.ts +0 -108
  342. package/dist/Store/service.d.ts.map +0 -1
  343. package/dist/Store/service.js +0 -71
  344. package/dist/Store.d.ts +0 -2
  345. package/dist/Store.d.ts.map +0 -1
  346. package/dist/Store.js +0 -2
  347. package/dist/adapters/SQL/Model.d.ts +0 -479
  348. package/dist/adapters/SQL/Model.d.ts.map +0 -1
  349. package/dist/adapters/SQL/Model.js +0 -478
  350. package/dist/adapters/SQL.d.ts +0 -2
  351. package/dist/adapters/SQL.d.ts.map +0 -1
  352. package/dist/adapters/ServiceBus.d.ts +0 -58
  353. package/dist/adapters/ServiceBus.d.ts.map +0 -1
  354. package/dist/adapters/ServiceBus.js +0 -99
  355. package/dist/adapters/cosmos-client.d.ts +0 -14
  356. package/dist/adapters/cosmos-client.d.ts.map +0 -1
  357. package/dist/adapters/cosmos-client.js +0 -9
  358. package/dist/adapters/index.d.ts +0 -2
  359. package/dist/adapters/index.d.ts.map +0 -1
  360. package/dist/adapters/index.js +0 -2
  361. package/dist/adapters/logger.d.ts +0 -9
  362. package/dist/adapters/logger.d.ts.map +0 -1
  363. package/dist/adapters/logger.js +0 -3
  364. package/dist/adapters/memQueue.d.ts +0 -13
  365. package/dist/adapters/memQueue.d.ts.map +0 -1
  366. package/dist/adapters/memQueue.js +0 -20
  367. package/dist/adapters/mongo-client.d.ts +0 -10
  368. package/dist/adapters/mongo-client.d.ts.map +0 -1
  369. package/dist/adapters/mongo-client.js +0 -13
  370. package/dist/adapters/redis-client.d.ts +0 -39
  371. package/dist/adapters/redis-client.d.ts.map +0 -1
  372. package/dist/adapters/redis-client.js +0 -94
  373. package/dist/api/ContextProvider.d.ts +0 -31
  374. package/dist/api/ContextProvider.d.ts.map +0 -1
  375. package/dist/api/ContextProvider.js +0 -38
  376. package/dist/api/codec.d.ts +0 -5
  377. package/dist/api/codec.d.ts.map +0 -1
  378. package/dist/api/codec.js +0 -5
  379. package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
  380. package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
  381. package/dist/api/internal/RequestContextMiddleware.js +0 -35
  382. package/dist/api/internal/auth.d.ts +0 -15
  383. package/dist/api/internal/auth.d.ts.map +0 -1
  384. package/dist/api/internal/auth.js +0 -47
  385. package/dist/api/internal/events.d.ts +0 -9
  386. package/dist/api/internal/events.d.ts.map +0 -1
  387. package/dist/api/internal/events.js +0 -42
  388. package/dist/api/internal/health.d.ts +0 -3
  389. package/dist/api/internal/health.d.ts.map +0 -1
  390. package/dist/api/internal/health.js +0 -5
  391. package/dist/api/layerUtils.d.ts +0 -24
  392. package/dist/api/layerUtils.d.ts.map +0 -1
  393. package/dist/api/layerUtils.js +0 -16
  394. package/dist/api/middlewares.d.ts +0 -10
  395. package/dist/api/middlewares.d.ts.map +0 -1
  396. package/dist/api/reportError.d.ts +0 -4
  397. package/dist/api/reportError.d.ts.map +0 -1
  398. package/dist/api/reportError.js +0 -27
  399. package/dist/api/routing/middleware/RouterMiddleware.d.ts +0 -15
  400. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
  401. package/dist/api/routing/middleware/middleware.d.ts +0 -9
  402. package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
  403. package/dist/api/routing/middleware/middleware.js +0 -92
  404. package/dist/api/routing/middleware.d.ts +0 -4
  405. package/dist/api/routing/middleware.d.ts.map +0 -1
  406. package/dist/api/routing/schema/jwt.d.ts +0 -4
  407. package/dist/api/routing/schema/jwt.d.ts.map +0 -1
  408. package/dist/api/routing/schema/jwt.js +0 -12
  409. package/dist/api/routing/tsort.d.ts +0 -8
  410. package/dist/api/routing/tsort.d.ts.map +0 -1
  411. package/dist/api/routing/tsort.js +0 -51
  412. package/dist/api/routing/utils.d.ts +0 -19
  413. package/dist/api/routing/utils.d.ts.map +0 -1
  414. package/dist/api/routing/utils.js +0 -44
  415. package/dist/api/routing.d.ts +0 -138
  416. package/dist/api/routing.d.ts.map +0 -1
  417. package/dist/api/routing.js +0 -166
  418. package/dist/api/setupRequest.d.ts +0 -12
  419. package/dist/api/setupRequest.d.ts.map +0 -1
  420. package/dist/api/setupRequest.js +0 -44
  421. package/dist/api/util.d.ts +0 -3
  422. package/dist/api/util.d.ts.map +0 -1
  423. package/dist/api/util.js +0 -14
  424. package/eslint.config.mjs +0 -24
  425. package/src/Emailer/service.ts +0 -52
  426. package/src/Emailer.ts +0 -1
  427. package/src/Model/Repository/ext.ts +0 -283
  428. package/src/Model/Repository/internal/internal.ts +0 -577
  429. package/src/Model/Repository/legacy.ts +0 -27
  430. package/src/Model/Repository/makeRepo.ts +0 -139
  431. package/src/Model/Repository/service.ts +0 -627
  432. package/src/Model/Repository/validation.ts +0 -31
  433. package/src/Model/Repository.ts +0 -5
  434. package/src/Model/dsl.ts +0 -128
  435. package/src/Model/filter/filterApi.ts +0 -60
  436. package/src/Model/filter/types/errors.ts +0 -47
  437. package/src/Model/filter/types/fields.ts +0 -50
  438. package/src/Model/filter/types/path/common.ts +0 -404
  439. package/src/Model/filter/types/path/eager.ts +0 -298
  440. package/src/Model/filter/types/path/index.ts +0 -4
  441. package/src/Model/filter/types/utils.ts +0 -128
  442. package/src/Model/filter/types/validator.ts +0 -46
  443. package/src/Model/filter/types.ts +0 -6
  444. package/src/Model/query/dsl.ts +0 -2110
  445. package/src/Model/query/new-kid-interpreter.ts +0 -210
  446. package/src/Model/query.ts +0 -13
  447. package/src/Model.ts +0 -3
  448. package/src/Operations.ts +0 -235
  449. package/src/OperationsRepo.ts +0 -16
  450. package/src/QueueMaker/service.ts +0 -17
  451. package/src/RequestContext.ts +0 -63
  452. package/src/Store/ContextMapContainer.ts +0 -20
  453. package/src/Store/service.ts +0 -184
  454. package/src/Store.ts +0 -1
  455. package/src/adapters/ServiceBus.ts +0 -209
  456. package/src/adapters/index.ts +0 -0
  457. package/src/adapters/logger.ts +0 -3
  458. package/src/api/internal/auth.ts +0 -68
  459. package/src/api/routing/middleware.ts +0 -6
  460. package/src/api/routing.ts +0 -598
  461. package/src/api/setupRequest.ts +0 -84
  462. /package/src/{adapters/SQL.ts → SQL.ts} +0 -0
  463. /package/src/{api/codec.ts → codec.ts} +0 -0
  464. /package/src/{api/internal → internal}/health.ts +0 -0
  465. /package/src/{api/middlewares.ts → middlewares.ts} +0 -0
  466. /package/src/{api/routing → routing}/tsort.ts +0 -0
  467. /package/src/{api/util.ts → util.ts} +0 -0
@@ -1,598 +0,0 @@
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 { Config, Effect, Layer, type NonEmptyReadonlyArray, Predicate, S, type Scope } from "effect-app"
6
- import { type HttpHeaders } from "effect-app/http"
7
- import { type GetEffectContext, type GetEffectError, type RpcContextMap } from "effect-app/rpc/RpcContextMap"
8
- import { type TypeTestId } from "effect-app/TypeTest"
9
- import { typedKeysOf, typedValuesOf } from "effect-app/utils"
10
- import { type Yieldable } from "effect/Effect"
11
- import { Rpc, RpcGroup, type RpcSerialization, RpcServer } from "effect/unstable/rpc"
12
- import { type LayerUtils } from "./layerUtils.js"
13
- import { type RouterMiddleware } from "./routing/middleware.js"
14
-
15
- export * from "./routing/middleware.js"
16
-
17
- // it's the result of extending S.Req setting success, config
18
- // it's a schema plus some metadata
19
- export type AnyRequestModule = S.Top & {
20
- _tag: string // unique identifier for the request module
21
- config: any // ?
22
- success: S.Top // validates the success response
23
- error: S.Top // validates the failure response
24
- }
25
-
26
- // builder pattern for adding actions to a router until all actions are added
27
- export interface AddAction<Actions extends AnyRequestModule, Accum extends Record<string, any> = {}> {
28
- accum: Accum
29
- add<A extends Handler<Actions, any, any>>(
30
- a: A
31
- ): A extends Handler<infer M extends AnyRequestModule, any, any> ? Exclude<Actions, M> extends never ?
32
- & Accum
33
- & { [K in M["_tag"]]: A }
34
- :
35
- & AddAction<
36
- Exclude<Actions, M>,
37
- & Accum
38
- & { [K in M["_tag"]]: A }
39
- >
40
- & Accum
41
- & { [K in M["_tag"]]: A }
42
- : never
43
- }
44
-
45
- // note:
46
- // "d" stands for decoded i.e. the Type
47
- // "raw" stands for encoded i.e. the Encoded
48
- namespace RequestTypes {
49
- export const DECODED = "d" as const
50
- export type DECODED = typeof DECODED
51
- export const RAW = "raw" as const
52
- export type RAW = typeof RAW
53
- }
54
- type RequestType = typeof RequestTypes[keyof typeof RequestTypes]
55
-
56
- type GetSuccess<T> = T extends { success: S.Top } ? T["success"] : typeof S.Void
57
- type GetFailure<T extends { error?: S.Top }> = T["error"] extends never ? typeof S.Never : T["error"]
58
-
59
- type GetSuccessShape<Action extends { success?: S.Top }, RT extends RequestType> = {
60
- d: S.Schema.Type<GetSuccess<Action>>
61
- raw: S.Codec.Encoded<GetSuccess<Action>>
62
- }[RT]
63
-
64
- interface HandlerBase<Action extends AnyRequestModule, RT extends RequestType, A, E, R> {
65
- new(): {}
66
- _tag: RT
67
- stack: string
68
- handler: (req: S.Schema.Type<Action>, headers: HttpHeaders.Headers) => Effect.Effect<A, E, R>
69
- }
70
-
71
- export interface Handler<Action extends AnyRequestModule, RT extends RequestType, R> extends
72
- HandlerBase<
73
- Action,
74
- RT,
75
- GetSuccessShape<Action, RT>,
76
- S.Schema.Type<GetFailure<Action>> | S.SchemaError,
77
- R
78
- >
79
- {}
80
-
81
- type AnyHandler<Action extends AnyRequestModule> = Handler<
82
- Action,
83
- RequestType,
84
- any // R
85
- >
86
-
87
- // a Resource is typically the whole module with all the exported sh*t
88
- // this helper retrieves only the entities (classes) which are built by extending S.Req
89
- type FilterRequestModules<T> = {
90
- [K in keyof T as T[K] extends AnyRequestModule ? K : never]: T[K]
91
- }
92
-
93
- type RpcRouteR<
94
- T extends [any, (req: any, headers: HttpHeaders.Headers) => Effect.Effect<any, any, any>]
95
- > = T extends [
96
- any,
97
- (...args: any[]) => Effect.Effect<any, any, infer R>
98
- ] ? R
99
- : never
100
-
101
- type Match<
102
- Resource extends Record<string, any>,
103
- RequestContextMap extends Record<string, any>,
104
- RT extends RequestType,
105
- Key extends keyof Resource
106
- > = {
107
- // note: the defaults of = never prevent the whole router to error (??)
108
- <A extends GetSuccessShape<Resource[Key], RT>, R2 = never, E = never>(
109
- f: Effect.Effect<A, E, R2>
110
- ): Handler<
111
- Resource[Key],
112
- RT,
113
- Exclude<
114
- Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
115
- Scope.Scope
116
- >
117
- >
118
-
119
- <A extends GetSuccessShape<Resource[Key], RT>, R2 = never, E = never>(
120
- f: (req: S.Schema.Type<Resource[Key]>) => Effect.Effect<A, E, R2>
121
- ): Handler<
122
- Resource[Key],
123
- RT,
124
- Exclude<
125
- Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
126
- Scope.Scope
127
- >
128
- >
129
- }
130
-
131
- export type RouteMatcher<
132
- RequestContextMap extends Record<string, any>,
133
- Resource extends Record<string, any>
134
- > = {
135
- // use Resource as Key over using Keys, so that the Go To on X.Action remain in tact in Controllers files
136
- /**
137
- * Requires the Type shape
138
- */
139
- [Key in keyof FilterRequestModules<Resource>]:
140
- & Match<Resource, RequestContextMap, RequestTypes.DECODED, Key>
141
- & {
142
- success: Resource[Key]["success"]
143
- successRaw: S.Codec<S.Codec.Encoded<Resource[Key]["success"]>>
144
- error: Resource[Key]["error"]
145
- /**
146
- * Requires the Encoded shape (e.g directly undecoded from DB, so that we don't do multiple Decode/Encode)
147
- */
148
- raw: Match<Resource, RequestContextMap, RequestTypes.RAW, Key>
149
- }
150
- }
151
-
152
- export const skipOnProd = Effect
153
- .gen(function*() {
154
- const env = yield* Config.string("env")
155
- return env !== "prod"
156
- })
157
- .pipe(Effect.orDie)
158
-
159
- export const makeRouter = <
160
- Self,
161
- RequestContextMap extends Record<string, RpcContextMap.Any>,
162
- MakeMiddlewareE,
163
- MakeMiddlewareR,
164
- ContextProviderA,
165
- ContextProviderE,
166
- ContextProviderR,
167
- RequestContextId
168
- >(
169
- middleware: RouterMiddleware<
170
- Self,
171
- RequestContextMap,
172
- MakeMiddlewareE,
173
- MakeMiddlewareR,
174
- ContextProviderA,
175
- ContextProviderE,
176
- ContextProviderR,
177
- RequestContextId
178
- >
179
- ) => {
180
- /**
181
- * Create a Router for specified resource
182
- * if `check` is provided, the router will only be created if the effect succeeds with true
183
- */
184
- function matchFor<
185
- const ModuleName extends string,
186
- const Resource extends Record<string, any>
187
- >(
188
- rsc: Resource & { meta: { moduleName: ModuleName } },
189
- options?: { check?: Effect.Effect<boolean> }
190
- ) {
191
- type HandlerWithInputGen<
192
- Action extends AnyRequestModule,
193
- RT extends RequestType
194
- > = (
195
- req: S.Schema.Type<Action>
196
- ) => Generator<
197
- Yieldable<
198
- any,
199
- any,
200
- S.Schema.Type<GetFailure<Action>> | S.SchemaError,
201
- // the actual implementation of the handler may just require the dynamic context provided by the middleware
202
- // and the per request context provided by the context provider
203
- GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
204
- >,
205
- GetSuccessShape<Action, RT>,
206
- never
207
- >
208
-
209
- type HandlerWithInputEff<
210
- Action extends AnyRequestModule,
211
- RT extends RequestType
212
- > = (
213
- req: S.Schema.Type<Action>
214
- ) => Effect.Effect<
215
- GetSuccessShape<Action, RT>,
216
- S.Schema.Type<GetFailure<Action>> | S.SchemaError,
217
- // the actual implementation of the handler may just require the dynamic context provided by the middleware
218
- // and the per request context provided by the context provider
219
- GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
220
- >
221
-
222
- type HandlerEff<
223
- Action extends AnyRequestModule,
224
- RT extends RequestType
225
- > = Effect.Effect<
226
- GetSuccessShape<Action, RT>,
227
- S.Schema.Type<GetFailure<Action>> | S.SchemaError,
228
- // the actual implementation of the handler may just require the dynamic context provided by the middleware
229
- // and the per request context provided by the context provider
230
- GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
231
- >
232
-
233
- type Handlers<Action extends AnyRequestModule, RT extends RequestType> =
234
- | HandlerWithInputGen<Action, RT>
235
- | HandlerWithInputEff<Action, RT>
236
- | HandlerEff<Action, RT>
237
-
238
- type HandlersDecoded<Action extends AnyRequestModule> = Handlers<Action, RequestTypes.DECODED>
239
-
240
- type HandlersRaw<Action extends AnyRequestModule> =
241
- | { raw: HandlerWithInputGen<Action, RequestTypes.RAW> }
242
- | { raw: HandlerWithInputEff<Action, RequestTypes.RAW> }
243
- | { raw: HandlerEff<Action, RequestTypes.RAW> }
244
-
245
- type AnyHandlers<Action extends AnyRequestModule> = HandlersRaw<Action> | HandlersDecoded<Action>
246
-
247
- const { meta } = rsc
248
-
249
- type RequestModules = FilterRequestModules<Resource>
250
- const requestModules = typedKeysOf(rsc).reduce((acc, cur) => {
251
- if (Predicate.isObjectKeyword(rsc[cur]) && rsc[cur]["success"]) {
252
- acc[cur as keyof RequestModules] = rsc[cur] as RequestModules[keyof RequestModules]
253
- }
254
- return acc
255
- }, {} as RequestModules)
256
-
257
- const routeMatcher = typedKeysOf(requestModules).reduce(
258
- (prev, cur) => {
259
- ;(prev as any)[cur] = Object.assign((handlerImpl: any) => {
260
- // handlerImpl is the actual handler implementation
261
- if (handlerImpl[Symbol.toStringTag] === "GeneratorFunction") handlerImpl = Effect.fnUntraced(handlerImpl)
262
- const stack = new Error().stack?.split("\n").slice(2).join("\n")
263
- return Effect.isEffect(handlerImpl)
264
- ? class {
265
- static request = rsc[cur]
266
- static stack = stack
267
- static _tag = RequestTypes.DECODED
268
- static handler = () => handlerImpl
269
- }
270
- : class {
271
- static request = rsc[cur]
272
- static stack = stack
273
- static _tag = RequestTypes.DECODED
274
- static handler = handlerImpl
275
- }
276
- }, {
277
- success: rsc[cur].success,
278
- successRaw: S.toEncoded(rsc[cur].success),
279
- error: rsc[cur].error,
280
- raw: // "Raw" variations are for when you don't want to decode just to encode it again on the response
281
- // e.g for direct projection from DB
282
- // but more importantly, to skip Effectful decoders, like to resolve relationships from the database or remote client.
283
- (handlerImpl: any) => {
284
- if (handlerImpl[Symbol.toStringTag] === "GeneratorFunction") handlerImpl = Effect.fnUntraced(handlerImpl)
285
- const stack = new Error().stack?.split("\n").slice(2).join("\n")
286
- return Effect.isEffect(handlerImpl)
287
- ? class {
288
- static request = rsc[cur]
289
- static stack = stack
290
- static _tag = RequestTypes.RAW
291
- static handler = () => handlerImpl
292
- }
293
- : class {
294
- static request = rsc[cur]
295
- static stack = stack
296
- static _tag = RequestTypes.RAW
297
- static handler = handlerImpl
298
- }
299
- }
300
- })
301
- return prev
302
- },
303
- {} as RouteMatcher<RequestContextMap, Resource>
304
- )
305
-
306
- const router3: <
307
- const Impl extends {
308
- [K in keyof FilterRequestModules<Resource>]: AnyHandlers<Resource[K]>
309
- }
310
- >(
311
- impl: Impl
312
- ) => {
313
- [K in keyof Impl & keyof FilterRequestModules<Resource>]: Handler<
314
- FilterRequestModules<Resource>[K],
315
- Impl[K] extends { raw: any } ? RequestTypes.RAW : RequestTypes.DECODED,
316
- Exclude<
317
- Exclude<
318
- // retrieves context R from the actual implementation of the handler
319
- Impl[K] extends { raw: any }
320
- ? Impl[K]["raw"] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
321
- : Impl[K]["raw"] extends Effect.Effect<any, any, infer R> ? R
322
- : Impl[K]["raw"] extends (...args: any[]) => Generator<
323
- Yieldable<any, any, any, infer R>,
324
- any,
325
- any
326
- > ? R
327
- : never
328
- : Impl[K] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
329
- : Impl[K] extends Effect.Effect<any, any, infer R> ? R
330
- : Impl[K] extends (...args: any[]) => Generator<
331
- Yieldable<any, any, any, infer R>,
332
- any,
333
- any
334
- > ? R
335
- : never,
336
- | GetEffectContext<RequestContextMap, Resource[K]["config"]>
337
- | ContextProviderA
338
- >,
339
- Scope.Scope
340
- >
341
- >
342
- } = (impl: Record<keyof RequestModules, any>) =>
343
- typedKeysOf(impl).reduce((acc, cur) => {
344
- acc[cur] = "raw" in impl[cur] ? routeMatcher[cur].raw(impl[cur].raw) : routeMatcher[cur](impl[cur])
345
- return acc
346
- }, {} as any)
347
-
348
- const makeRoutes = <
349
- MakeE,
350
- MakeR,
351
- THandlers extends {
352
- // important to keep them separate via | for type checking!!
353
- [K in keyof RequestModules]: AnyHandler<Resource[K]>
354
- },
355
- MakeDependencies extends NonEmptyReadonlyArray<Layer.Any> | never[]
356
- >(
357
- dependencies: MakeDependencies,
358
- make: (
359
- match: any
360
- ) =>
361
- | Effect.Effect<THandlers, MakeE, MakeR>
362
- | Generator<Yieldable<any, any, MakeE, MakeR>, THandlers, any>
363
- ) => {
364
- const dependenciesL = (dependencies ? Layer.mergeAll(...dependencies as any) : Layer.empty) as Layer.Layer<
365
- LayerUtils.GetLayersSuccess<MakeDependencies>,
366
- LayerUtils.GetLayersError<MakeDependencies>,
367
- LayerUtils.GetLayersContext<MakeDependencies>
368
- >
369
-
370
- const layer = Effect
371
- .gen(function*() {
372
- const finalMake = ((make as any)[Symbol.toStringTag] === "GeneratorFunction"
373
- ? Effect.fnUntraced(make as any)(router3) as any
374
- : make(router3) as any) as Effect.Effect<THandlers, MakeE, MakeR>
375
-
376
- const controllers = yield* finalMake
377
-
378
- // return make.pipe(Effect.map((c) => controllers(c, dependencies)))
379
- const mapped = typedKeysOf(requestModules).reduce((acc, cur) => {
380
- const handler = controllers[cur as keyof typeof controllers]
381
- const resource = rsc[cur]
382
-
383
- acc[cur] = [
384
- handler._tag === RequestTypes.RAW
385
- ? class extends (resource as any) {
386
- static success = S.toEncoded(resource.success)
387
- } as any
388
- : resource,
389
- (payload: any, headers: any) =>
390
- (handler.handler(payload, headers) as Effect.Effect<unknown, unknown, unknown>).pipe(
391
- Effect.withSpan(`Request.${meta.moduleName}.${resource._tag}`, {}, {
392
- captureStackTrace: () => handler.stack // capturing the handler stack is the main reason why we are doing the span here
393
- })
394
- )
395
- ] as const
396
- return acc
397
- }, {} as any) as {
398
- [K in keyof RequestModules]: [
399
- Resource[K],
400
- (
401
- req: any,
402
- headers: HttpHeaders.Headers
403
- ) => Effect.Effect<
404
- Effect.Success<ReturnType<THandlers[K]["handler"]>>,
405
- | Effect.Error<ReturnType<THandlers[K]["handler"]>>
406
- | GetEffectError<RequestContextMap, Resource[K]["config"]>,
407
- Exclude<
408
- Effect.Services<ReturnType<THandlers[K]["handler"]>>,
409
- ContextProviderA | GetEffectContext<RequestContextMap, Resource[K]["config"]>
410
- >
411
- >
412
- ]
413
- }
414
-
415
- const rpcs = RpcGroup
416
- .make(
417
- ...typedValuesOf(mapped).map(([resource]) => {
418
- return Rpc
419
- .make(resource._tag, { payload: resource, success: resource.success, error: resource.error })
420
- .annotate(middleware.requestContext, resource.config ?? {})
421
- })
422
- )
423
- .prefix(`${meta.moduleName}.`)
424
- .middleware(middleware as any)
425
-
426
- const rpc = rpcs
427
- .toLayer(Effect.gen(function*() {
428
- return typedValuesOf(mapped).reduce((acc, [resource, handler]) => {
429
- acc[`${meta.moduleName}.${resource._tag}`] = handler
430
- return acc
431
- }, {} as Record<string, any>) as any // TODO
432
- })) as unknown as Layer.Layer<
433
- { [K in keyof RequestModules]: Rpc.Handler<K> },
434
- MakeE,
435
- RpcRouteR<typeof mapped[keyof typeof mapped]>
436
- >
437
-
438
- return RpcServer
439
- .layerHttp({
440
- spanPrefix: "RpcServer." + meta.moduleName,
441
- group: rpcs,
442
- path: ("/rpc/" + meta.moduleName) as `/${typeof meta.moduleName}`,
443
- protocol: "http"
444
- })
445
- .pipe(Layer.provide(rpc))
446
- })
447
- .pipe(Layer.unwrap)
448
-
449
- const routes = layer.pipe(
450
- Layer.provide([
451
- dependenciesL,
452
- middleware.Default
453
- ])
454
- )
455
-
456
- const check = options?.check
457
- return check
458
- ? Effect
459
- .gen(function*() {
460
- if (!(yield* check)) {
461
- yield* Effect.logWarning(`Skipping router for module ${meta.moduleName}`)
462
- return Layer.empty
463
- }
464
- return routes
465
- })
466
- .pipe(Layer.unwrap)
467
- : routes
468
- }
469
-
470
- const effect: {
471
- // Multiple times duplicated the "good" overload, so that errors will only mention the last overload when failing
472
- <
473
- const Make extends {
474
- dependencies?: ReadonlyArray<Layer.Any>
475
- effect: (match: typeof router3) => Generator<
476
- Yieldable<
477
- any,
478
- any,
479
- any,
480
- any
481
- >,
482
- { [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
483
- any
484
- >
485
- /** @deprecated */
486
- readonly ಠ_ಠ: never
487
- }
488
- >(
489
- make: Make
490
- ):
491
- & Layer.Layer<
492
- never,
493
- | MakeErrors<Make>
494
- | MakeDepsE<Make>
495
- | Layer.Error<typeof middleware.Default>,
496
- | MakeDepsIn<Make>
497
- | Layer.Services<typeof middleware.Default>
498
- | Exclude<
499
- MakeContext<Make>,
500
- MakeDepsOut<Make>
501
- >
502
- | RpcSerialization.RpcSerialization
503
- >
504
- & {
505
- // just for type testing purposes
506
- [TypeTestId]: Make
507
- }
508
- <
509
- const Make extends {
510
- dependencies?: ReadonlyArray<Layer.Any>
511
- // v4: generators yield Yieldable with asEffect()
512
- effect: (match: typeof router3) => Generator<
513
- Yieldable<any, any, any, any>,
514
- { [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
515
- any
516
- >
517
- }
518
- >(
519
- make: Make
520
- ):
521
- & Layer.Layer<
522
- never,
523
- | MakeErrors<Make>
524
- | MakeDepsE<Make>
525
- | Layer.Error<typeof middleware.Default>,
526
- | MakeDepsIn<Make>
527
- | Layer.Services<typeof middleware.Default>
528
- | Exclude<
529
- MakeContext<Make>,
530
- MakeDepsOut<Make>
531
- >
532
- | RpcSerialization.RpcSerialization
533
- >
534
- & {
535
- // just for type testing purposes
536
- readonly [TypeTestId]: Make
537
- }
538
- } =
539
- ((make: { dependencies: any; effect: any }) =>
540
- Object.assign(makeRoutes(make.dependencies, make.effect), { make })) as any
541
-
542
- return effect
543
- }
544
-
545
- function matchAll<
546
- T extends {
547
- [key: string]: Layer.Layer<never, any, any>
548
- }
549
- >(
550
- handlers: T
551
- ) {
552
- const routers = typedValuesOf(handlers)
553
-
554
- return Layer.mergeAll(...routers as [any]) as unknown as Layer.Layer<
555
- never,
556
- Layer.Error<typeof handlers[keyof typeof handlers]>,
557
- Layer.Services<typeof handlers[keyof typeof handlers]>
558
- >
559
- }
560
-
561
- return {
562
- matchAll,
563
- Router: matchFor
564
- }
565
- }
566
-
567
- export type MakeDeps<Make> = Make extends { readonly dependencies: ReadonlyArray<Layer.Any> }
568
- ? Make["dependencies"][number]
569
- : never
570
-
571
- export type MakeErrors<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, infer E, any> } ? E
572
- : Make extends { readonly effect: (_: any) => Effect.Effect<any, never, any> } ? never
573
- : */
574
- // v4: generators yield Yieldable with asEffect()
575
- Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, never, any>, any, any> } ? never
576
- : Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, infer E, any>, any, any> } ? E
577
- : never
578
-
579
- export type MakeContext<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, any, infer R> } ? R
580
- : Make extends { readonly effect: (_: any) => Effect.Effect<any, any, never> } ? never
581
- : */
582
- // v4: generators yield Yieldable with asEffect()
583
- Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any, never>, any, any> } ? never
584
- : Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any, infer R>, any, any> } ? R
585
- : never
586
-
587
- export type MakeHandlers<Make, _Handlers extends Record<string, any>> = /*Make extends
588
- { readonly effect: (_: any) => Effect.Effect<{ [K in keyof Handlers]: AnyHandler<Handlers[K]> }, any, any> }
589
- ? Effect.Success<ReturnType<Make["effect"]>>
590
- : */
591
- Make extends { readonly effect: (_: any) => Generator<any, infer S, any> } ? S
592
- : never
593
-
594
- export type MakeDepsE<Make> = Layer.Error<MakeDeps<Make>>
595
-
596
- export type MakeDepsIn<Make> = Layer.Services<MakeDeps<Make>>
597
-
598
- export type MakeDepsOut<Make> = Layer.Success<MakeDeps<Make>>
@@ -1,84 +0,0 @@
1
- import { Effect, Layer, Tracer } from "effect-app"
2
- import { NonEmptyString255 } from "effect-app/Schema"
3
- import { LocaleRef, RequestContext, spanAttributes } from "../RequestContext.js"
4
- import { ContextMapContainer } from "../Store/ContextMapContainer.js"
5
- import { storeId } from "../Store/Memory.js"
6
-
7
- export const getRequestContext = Effect
8
- .all({
9
- span: Effect.currentSpan.pipe(Effect.orDie),
10
- locale: LocaleRef.asEffect(),
11
- namespace: storeId.asEffect()
12
- })
13
- .pipe(
14
- Effect.map(({ locale, namespace, span }) =>
15
- new RequestContext({
16
- span: Tracer.externalSpan(span),
17
- locale,
18
- namespace,
19
- name: NonEmptyString255(span.name)
20
- })
21
- )
22
- )
23
-
24
- export const getRC = Effect.all({
25
- locale: LocaleRef.asEffect(),
26
- namespace: storeId.asEffect()
27
- })
28
-
29
- const withRequestSpan = (name = "request", options?: Tracer.SpanOptions) => <R, E, A>(f: Effect.Effect<A, E, R>) =>
30
- Effect.andThen(
31
- getRC,
32
- (ctx) =>
33
- f.pipe(
34
- Effect.withSpan(name, {
35
- ...options,
36
- attributes: { ...spanAttributes({ ...ctx, name: NonEmptyString255(name) }), ...options?.attributes }
37
- }, {
38
- captureStackTrace: options?.captureStackTrace ?? false
39
- }),
40
- // TODO: false
41
- // request context info is picked up directly in the logger for annotations.
42
- Effect.withLogSpan(name)
43
- )
44
- )
45
-
46
- export const setupRequestContextFromCurrent =
47
- (name = "request", options?: Tracer.SpanOptions) => <R, E, A>(self: Effect.Effect<A, E, R>) =>
48
- self
49
- .pipe(
50
- withRequestSpan(name, options),
51
- Effect.provide(ContextMapContainer.layer)
52
- )
53
-
54
- // TODO: consider integrating Effect.withParentSpan
55
- export function setupRequestContext<R, E, A>(self: Effect.Effect<A, E, R>, requestContext: RequestContext) {
56
- const layer = Layer.mergeAll(
57
- ContextMapContainer.layer,
58
- Layer.succeed(LocaleRef, requestContext.locale),
59
- Layer.succeed(storeId, requestContext.namespace)
60
- )
61
- return self
62
- .pipe(
63
- withRequestSpan(requestContext.name),
64
- Effect.provide(layer)
65
- )
66
- }
67
-
68
- export function setupRequestContextWithCustomSpan<R, E, A>(
69
- self: Effect.Effect<A, E, R>,
70
- requestContext: RequestContext,
71
- name: string,
72
- options?: Tracer.SpanOptions
73
- ) {
74
- const layer = Layer.mergeAll(
75
- ContextMapContainer.layer,
76
- Layer.succeed(LocaleRef, requestContext.locale),
77
- Layer.succeed(storeId, requestContext.namespace)
78
- )
79
- return self
80
- .pipe(
81
- withRequestSpan(name, options),
82
- Effect.provide(layer)
83
- )
84
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes