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

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 (472) hide show
  1. package/CHANGELOG.md +1892 -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 +345 -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 +77 -37
  51. package/dist/Store/Memory.d.ts +9 -6
  52. package/dist/Store/Memory.d.ts.map +1 -1
  53. package/dist/Store/Memory.js +328 -63
  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 +233 -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 +450 -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 +46 -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 +4 -4
  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/setupRequest.d.ts +19 -0
  160. package/dist/setupRequest.d.ts.map +1 -0
  161. package/dist/setupRequest.js +70 -0
  162. package/dist/test.d.ts +3 -3
  163. package/dist/test.d.ts.map +1 -1
  164. package/dist/test.js +2 -2
  165. package/dist/util.d.ts +3 -0
  166. package/dist/util.d.ts.map +1 -0
  167. package/dist/util.js +14 -0
  168. package/dist/vitest.d.ts +1 -1
  169. package/examples/query.ts +47 -39
  170. package/package.json +123 -234
  171. package/src/CUPS.ts +52 -13
  172. package/src/{api/ContextProvider.ts → ContextProvider.ts} +19 -16
  173. package/src/Emailer/Sendgrid.ts +82 -59
  174. package/src/Emailer/fake.ts +3 -3
  175. package/src/MainFiberSet.ts +12 -10
  176. package/src/QueueMaker/SQLQueue.ts +153 -156
  177. package/src/QueueMaker/errors.ts +3 -1
  178. package/src/QueueMaker/memQueue.ts +113 -107
  179. package/src/QueueMaker/sbqueue.ts +78 -90
  180. package/src/RequestFiberSet.ts +13 -8
  181. package/src/{adapters/SQL → SQL}/Model.ts +42 -41
  182. package/src/ServiceBus.ts +219 -0
  183. package/src/Store/Cosmos/query.ts +216 -52
  184. package/src/Store/Cosmos.ts +494 -353
  185. package/src/Store/Disk.ts +108 -68
  186. package/src/Store/Memory.ts +367 -93
  187. package/src/Store/SQL/Pg.ts +364 -0
  188. package/src/Store/SQL/query.ts +603 -0
  189. package/src/Store/SQL.ts +736 -0
  190. package/src/Store/codeFilter.ts +8 -5
  191. package/src/Store/index.ts +21 -6
  192. package/src/Store/utils.ts +26 -24
  193. package/src/arbs.ts +5 -3
  194. package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
  195. package/src/errorReporter.ts +66 -76
  196. package/src/fileUtil.ts +1 -1
  197. package/src/index.ts +2 -1
  198. package/src/internal/RequestContextMiddleware.ts +60 -0
  199. package/src/internal/auth.ts +272 -0
  200. package/src/{api/internal → internal}/events.ts +22 -13
  201. package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
  202. package/src/logger/jsonLogger.ts +4 -2
  203. package/src/logger/logFmtLogger.ts +2 -2
  204. package/src/logger/shared.ts +4 -3
  205. package/src/{adapters/memQueue.ts → memQueue.ts} +5 -4
  206. package/src/{adapters/mongo-client.ts → mongo-client.ts} +4 -2
  207. package/src/otel.ts +152 -0
  208. package/src/rateLimit.ts +34 -23
  209. package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
  210. package/src/{api/reportError.ts → reportError.ts} +3 -2
  211. package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
  212. package/src/{api/routing → routing}/middleware/middleware.ts +62 -17
  213. package/src/routing/middleware.ts +4 -0
  214. package/src/{api/routing → routing}/schema/jwt.ts +2 -1
  215. package/src/{api/routing → routing}/utils.ts +2 -1
  216. package/src/routing.ts +768 -0
  217. package/src/setupRequest.ts +135 -0
  218. package/src/test.ts +2 -2
  219. package/test/auth.test.ts +101 -0
  220. package/test/contextProvider.test.ts +15 -12
  221. package/test/controller.test.ts +28 -32
  222. package/test/cosmos-query.test.ts +159 -0
  223. package/test/dist/auth.test.d.ts.map +1 -0
  224. package/test/dist/contextProvider.test.d.ts.map +1 -1
  225. package/test/dist/controller.test.d.ts.map +1 -1
  226. package/test/dist/cosmos-query.test.d.ts.map +1 -0
  227. package/test/dist/date-query.test.d.ts.map +1 -0
  228. package/test/dist/fixtures.d.ts +30 -12
  229. package/test/dist/fixtures.d.ts.map +1 -1
  230. package/test/dist/fixtures.js +17 -10
  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/requires.test.d.ts.map +1 -1
  235. package/test/dist/router-generator.test.d.ts.map +1 -0
  236. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  237. package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
  238. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  239. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  240. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  241. package/test/dist/sql-store.test.d.ts.map +1 -0
  242. package/test/fixtures.ts +16 -9
  243. package/test/layerUtils.test.ts +2 -2
  244. package/test/query.test.ts +903 -40
  245. package/test/rawQuery.test.ts +340 -22
  246. package/test/repository-ext.test.ts +62 -0
  247. package/test/requires.test.ts +10 -5
  248. package/test/router-generator.test.ts +187 -0
  249. package/test/routing-interruptibility.test.ts +66 -0
  250. package/test/rpc-context-map-streaming.test.ts +262 -0
  251. package/test/rpc-e2e-invalidation.test.ts +256 -0
  252. package/test/rpc-multi-middleware.test.ts +85 -10
  253. package/test/rpc-stream-fullstack.test.ts +304 -0
  254. package/test/sql-store.test.ts +1711 -0
  255. package/test/validateSample.test.ts +19 -14
  256. package/tsconfig.examples.json +1 -1
  257. package/tsconfig.json +2 -1
  258. package/tsconfig.json.bak +2 -2
  259. package/tsconfig.src.json +35 -35
  260. package/tsconfig.test.json +2 -2
  261. package/dist/Emailer/service.d.ts +0 -55
  262. package/dist/Emailer/service.d.ts.map +0 -1
  263. package/dist/Emailer/service.js +0 -6
  264. package/dist/Emailer.d.ts +0 -2
  265. package/dist/Emailer.d.ts.map +0 -1
  266. package/dist/Emailer.js +0 -2
  267. package/dist/Model/Repository/ext.d.ts +0 -41
  268. package/dist/Model/Repository/ext.d.ts.map +0 -1
  269. package/dist/Model/Repository/ext.js +0 -65
  270. package/dist/Model/Repository/internal/internal.d.ts +0 -59
  271. package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
  272. package/dist/Model/Repository/internal/internal.js +0 -316
  273. package/dist/Model/Repository/legacy.d.ts +0 -19
  274. package/dist/Model/Repository/legacy.d.ts.map +0 -1
  275. package/dist/Model/Repository/legacy.js +0 -2
  276. package/dist/Model/Repository/makeRepo.d.ts +0 -49
  277. package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
  278. package/dist/Model/Repository/makeRepo.js +0 -24
  279. package/dist/Model/Repository/service.d.ts +0 -89
  280. package/dist/Model/Repository/service.d.ts.map +0 -1
  281. package/dist/Model/Repository/service.js +0 -2
  282. package/dist/Model/Repository/validation.d.ts +0 -42
  283. package/dist/Model/Repository/validation.d.ts.map +0 -1
  284. package/dist/Model/Repository/validation.js +0 -32
  285. package/dist/Model/Repository.d.ts +0 -6
  286. package/dist/Model/Repository.d.ts.map +0 -1
  287. package/dist/Model/Repository.js +0 -6
  288. package/dist/Model/dsl.d.ts +0 -32
  289. package/dist/Model/dsl.d.ts.map +0 -1
  290. package/dist/Model/dsl.js +0 -44
  291. package/dist/Model/filter/filterApi.d.ts +0 -30
  292. package/dist/Model/filter/filterApi.d.ts.map +0 -1
  293. package/dist/Model/filter/filterApi.js +0 -2
  294. package/dist/Model/filter/types/errors.d.ts +0 -29
  295. package/dist/Model/filter/types/errors.d.ts.map +0 -1
  296. package/dist/Model/filter/types/errors.js +0 -2
  297. package/dist/Model/filter/types/fields.d.ts +0 -15
  298. package/dist/Model/filter/types/fields.d.ts.map +0 -1
  299. package/dist/Model/filter/types/fields.js +0 -2
  300. package/dist/Model/filter/types/path/common.d.ts +0 -316
  301. package/dist/Model/filter/types/path/common.d.ts.map +0 -1
  302. package/dist/Model/filter/types/path/common.js +0 -2
  303. package/dist/Model/filter/types/path/eager.d.ts +0 -95
  304. package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
  305. package/dist/Model/filter/types/path/eager.js +0 -31
  306. package/dist/Model/filter/types/path/index.d.ts +0 -4
  307. package/dist/Model/filter/types/path/index.d.ts.map +0 -1
  308. package/dist/Model/filter/types/path/index.js +0 -3
  309. package/dist/Model/filter/types/utils.d.ts +0 -79
  310. package/dist/Model/filter/types/utils.d.ts.map +0 -1
  311. package/dist/Model/filter/types/utils.js +0 -2
  312. package/dist/Model/filter/types/validator.d.ts +0 -30
  313. package/dist/Model/filter/types/validator.d.ts.map +0 -1
  314. package/dist/Model/filter/types/validator.js +0 -2
  315. package/dist/Model/filter/types.d.ts +0 -5
  316. package/dist/Model/filter/types.d.ts.map +0 -1
  317. package/dist/Model/filter/types.js +0 -7
  318. package/dist/Model/query/dsl.d.ts +0 -248
  319. package/dist/Model/query/dsl.d.ts.map +0 -1
  320. package/dist/Model/query/dsl.js +0 -104
  321. package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
  322. package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
  323. package/dist/Model/query/new-kid-interpreter.js +0 -165
  324. package/dist/Model/query.d.ts +0 -15
  325. package/dist/Model/query.d.ts.map +0 -1
  326. package/dist/Model/query.js +0 -3
  327. package/dist/Model.d.ts +0 -4
  328. package/dist/Model.d.ts.map +0 -1
  329. package/dist/Model.js +0 -4
  330. package/dist/Operations.d.ts +0 -55
  331. package/dist/Operations.d.ts.map +0 -1
  332. package/dist/Operations.js +0 -102
  333. package/dist/OperationsRepo.d.ts +0 -41
  334. package/dist/OperationsRepo.d.ts.map +0 -1
  335. package/dist/OperationsRepo.js +0 -14
  336. package/dist/QueueMaker/service.d.ts +0 -11
  337. package/dist/QueueMaker/service.d.ts.map +0 -1
  338. package/dist/QueueMaker/service.js +0 -4
  339. package/dist/RequestContext.d.ts +0 -63
  340. package/dist/RequestContext.d.ts.map +0 -1
  341. package/dist/RequestContext.js +0 -49
  342. package/dist/Store/ContextMapContainer.d.ts +0 -14
  343. package/dist/Store/ContextMapContainer.d.ts.map +0 -1
  344. package/dist/Store/ContextMapContainer.js +0 -16
  345. package/dist/Store/service.d.ts +0 -108
  346. package/dist/Store/service.d.ts.map +0 -1
  347. package/dist/Store/service.js +0 -71
  348. package/dist/Store.d.ts +0 -2
  349. package/dist/Store.d.ts.map +0 -1
  350. package/dist/Store.js +0 -2
  351. package/dist/adapters/SQL/Model.d.ts +0 -479
  352. package/dist/adapters/SQL/Model.d.ts.map +0 -1
  353. package/dist/adapters/SQL/Model.js +0 -478
  354. package/dist/adapters/SQL.d.ts +0 -2
  355. package/dist/adapters/SQL.d.ts.map +0 -1
  356. package/dist/adapters/ServiceBus.d.ts +0 -58
  357. package/dist/adapters/ServiceBus.d.ts.map +0 -1
  358. package/dist/adapters/ServiceBus.js +0 -99
  359. package/dist/adapters/cosmos-client.d.ts +0 -14
  360. package/dist/adapters/cosmos-client.d.ts.map +0 -1
  361. package/dist/adapters/cosmos-client.js +0 -9
  362. package/dist/adapters/index.d.ts +0 -2
  363. package/dist/adapters/index.d.ts.map +0 -1
  364. package/dist/adapters/index.js +0 -2
  365. package/dist/adapters/logger.d.ts +0 -9
  366. package/dist/adapters/logger.d.ts.map +0 -1
  367. package/dist/adapters/logger.js +0 -3
  368. package/dist/adapters/memQueue.d.ts +0 -13
  369. package/dist/adapters/memQueue.d.ts.map +0 -1
  370. package/dist/adapters/memQueue.js +0 -20
  371. package/dist/adapters/mongo-client.d.ts +0 -10
  372. package/dist/adapters/mongo-client.d.ts.map +0 -1
  373. package/dist/adapters/mongo-client.js +0 -13
  374. package/dist/adapters/redis-client.d.ts +0 -39
  375. package/dist/adapters/redis-client.d.ts.map +0 -1
  376. package/dist/adapters/redis-client.js +0 -94
  377. package/dist/api/ContextProvider.d.ts +0 -31
  378. package/dist/api/ContextProvider.d.ts.map +0 -1
  379. package/dist/api/ContextProvider.js +0 -38
  380. package/dist/api/codec.d.ts +0 -5
  381. package/dist/api/codec.d.ts.map +0 -1
  382. package/dist/api/codec.js +0 -5
  383. package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
  384. package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
  385. package/dist/api/internal/RequestContextMiddleware.js +0 -35
  386. package/dist/api/internal/auth.d.ts +0 -15
  387. package/dist/api/internal/auth.d.ts.map +0 -1
  388. package/dist/api/internal/auth.js +0 -47
  389. package/dist/api/internal/events.d.ts +0 -9
  390. package/dist/api/internal/events.d.ts.map +0 -1
  391. package/dist/api/internal/events.js +0 -42
  392. package/dist/api/internal/health.d.ts +0 -3
  393. package/dist/api/internal/health.d.ts.map +0 -1
  394. package/dist/api/internal/health.js +0 -5
  395. package/dist/api/layerUtils.d.ts +0 -24
  396. package/dist/api/layerUtils.d.ts.map +0 -1
  397. package/dist/api/layerUtils.js +0 -16
  398. package/dist/api/middlewares.d.ts +0 -10
  399. package/dist/api/middlewares.d.ts.map +0 -1
  400. package/dist/api/reportError.d.ts +0 -4
  401. package/dist/api/reportError.d.ts.map +0 -1
  402. package/dist/api/reportError.js +0 -27
  403. package/dist/api/routing/middleware/RouterMiddleware.d.ts +0 -15
  404. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
  405. package/dist/api/routing/middleware/middleware.d.ts +0 -9
  406. package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
  407. package/dist/api/routing/middleware/middleware.js +0 -92
  408. package/dist/api/routing/middleware.d.ts +0 -4
  409. package/dist/api/routing/middleware.d.ts.map +0 -1
  410. package/dist/api/routing/schema/jwt.d.ts +0 -4
  411. package/dist/api/routing/schema/jwt.d.ts.map +0 -1
  412. package/dist/api/routing/schema/jwt.js +0 -12
  413. package/dist/api/routing/tsort.d.ts +0 -8
  414. package/dist/api/routing/tsort.d.ts.map +0 -1
  415. package/dist/api/routing/tsort.js +0 -51
  416. package/dist/api/routing/utils.d.ts +0 -19
  417. package/dist/api/routing/utils.d.ts.map +0 -1
  418. package/dist/api/routing/utils.js +0 -44
  419. package/dist/api/routing.d.ts +0 -138
  420. package/dist/api/routing.d.ts.map +0 -1
  421. package/dist/api/routing.js +0 -166
  422. package/dist/api/setupRequest.d.ts +0 -12
  423. package/dist/api/setupRequest.d.ts.map +0 -1
  424. package/dist/api/setupRequest.js +0 -44
  425. package/dist/api/util.d.ts +0 -3
  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 -577
  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/service.ts +0 -17
  455. package/src/RequestContext.ts +0 -63
  456. package/src/Store/ContextMapContainer.ts +0 -20
  457. package/src/Store/service.ts +0 -184
  458. package/src/Store.ts +0 -1
  459. package/src/adapters/ServiceBus.ts +0 -209
  460. package/src/adapters/index.ts +0 -0
  461. package/src/adapters/logger.ts +0 -3
  462. package/src/api/internal/RequestContextMiddleware.ts +0 -42
  463. package/src/api/internal/auth.ts +0 -68
  464. package/src/api/routing/middleware.ts +0 -6
  465. package/src/api/routing.ts +0 -598
  466. package/src/api/setupRequest.ts +0 -84
  467. /package/src/{adapters/SQL.ts → SQL.ts} +0 -0
  468. /package/src/{api/codec.ts → codec.ts} +0 -0
  469. /package/src/{api/internal → internal}/health.ts +0 -0
  470. /package/src/{api/middlewares.ts → middlewares.ts} +0 -0
  471. /package/src/{api/routing → routing}/tsort.ts +0 -0
  472. /package/src/{api/util.ts → util.ts} +0 -0
@@ -1,34 +1,278 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
- import { Array, Effect, flow, type NonEmptyReadonlyArray, Option, Order, pipe, Ref, Result, Semaphore, ServiceMap, Struct } from "effect-app"
3
+ import * as Array from "effect-app/Array"
4
+ import type { NonEmptyReadonlyArray } from "effect-app/Array"
5
+ import * as Context from "effect-app/Context"
6
+ import * as Effect from "effect-app/Effect"
7
+ import type { FilterResult } from "effect-app/Model/filter/filterApi"
8
+ import type { FieldValues } from "effect-app/Model/filter/types"
9
+ import type { AggregateIrExpression, ComputedProjectionIrExpression, ComputedProjectionMathIrExpression } from "effect-app/Model/query"
10
+ import * as Option from "effect-app/Option"
4
11
  import { NonEmptyString255 } from "effect-app/Schema"
5
- import { get } from "effect-app/utils"
12
+ import { type FilterArgs, type PersistenceModelType, type Store, type StoreConfig, StoreMaker } from "effect-app/Store"
13
+ import { assertUnreachable } from "effect-app/utils"
14
+ import { flow, pipe } from "effect/Function"
15
+ import * as Order from "effect/Order"
16
+ import * as Ref from "effect/Ref"
17
+ import * as Result from "effect/Result"
18
+ import * as Semaphore from "effect/Semaphore"
19
+ import * as Struct from "effect/Struct"
6
20
  import { InfraLogger } from "../logger.js"
7
- import type { FieldValues } from "../Model/filter/types.js"
21
+ import { annotateDb } from "../otel.js"
8
22
  import { codeFilter, codeFilter3_ } from "./codeFilter.js"
9
- import { type FilterArgs, type PersistenceModelType, type Store, type StoreConfig, StoreMaker } from "./service.js"
10
23
  import { makeUpdateETag } from "./utils.js"
11
24
 
25
+ /** Traverse an object by a dot-separated path string, e.g. `"a.b.c"`. */
26
+ export function get(obj: any, path: string): any {
27
+ return path.split(".").reduce((res: any, key: string) => (res != null ? res[key] : res), obj)
28
+ }
29
+
30
+ const stripRelationFilterPaths = (state: readonly FilterResult[], relationPath: string): readonly FilterResult[] => {
31
+ const prefix = `${relationPath}.-1.`
32
+ return state.map((entry) =>
33
+ "path" in entry
34
+ ? {
35
+ ...entry,
36
+ path: entry.path.startsWith(prefix) ? entry.path.slice(prefix.length) : entry.path
37
+ }
38
+ : {
39
+ ...entry,
40
+ result: stripRelationFilterPaths(entry.result, relationPath)
41
+ }
42
+ )
43
+ }
44
+
45
+ const emptyValueFor = (tag: ComputedProjectionIrExpression["_tag"]) => {
46
+ switch (tag) {
47
+ case "relation-count":
48
+ case "relation-distinct-count":
49
+ case "relation-sum":
50
+ case "relation-sum-expr":
51
+ case "relation-sum-expr-normalized":
52
+ return 0
53
+ case "relation-sum-expr-by":
54
+ return [] as unknown[]
55
+ case "relation-any":
56
+ return false
57
+ case "relation-every":
58
+ return true
59
+ case "relation-collect":
60
+ return [] as unknown[]
61
+ case "relation-collect-fields":
62
+ return [] as unknown[]
63
+ case "relation-length":
64
+ return 0
65
+ default:
66
+ return assertUnreachable(tag)
67
+ }
68
+ }
69
+
70
+ const computeProjectionValue = (
71
+ row: FieldValues,
72
+ computed: ComputedProjectionIrExpression
73
+ ) => {
74
+ const relation = get(row, computed.path)
75
+ if (!Array.isArray(relation)) {
76
+ return emptyValueFor(computed._tag)
77
+ }
78
+ if (computed._tag === "relation-length") {
79
+ return relation.length
80
+ }
81
+ const filter = stripRelationFilterPaths(computed.filter, computed.path)
82
+ // empty filter = unconditional match (codeFilter3_ uses eval on a built
83
+ // string and chokes on `( )`, so short-circuit before invoking it).
84
+ const matches = filter.length === 0
85
+ ? (_value: unknown) => true
86
+ : (value: unknown) => codeFilter3_(filter, value)
87
+ const evalExpr = (value: unknown, expression: ComputedProjectionMathIrExpression): number => {
88
+ switch (expression._tag) {
89
+ case "field": {
90
+ const v = get(value, expression.field)
91
+ return typeof v === "number" ? v : Number(v) || 0
92
+ }
93
+ case "mul":
94
+ return evalExpr(value, expression.left) * evalExpr(value, expression.right)
95
+ default:
96
+ return assertUnreachable(expression)
97
+ }
98
+ }
99
+ switch (computed._tag) {
100
+ case "relation-count":
101
+ return relation.reduce<number>((acc, value) => matches(value) ? acc + 1 : acc, 0)
102
+ case "relation-any":
103
+ return relation.some(matches)
104
+ case "relation-every":
105
+ return relation.every(matches)
106
+ case "relation-distinct-count": {
107
+ const seen = new Set<unknown>()
108
+ for (const value of relation) {
109
+ if (matches(value)) seen.add(get(value, computed.field))
110
+ }
111
+ return seen.size
112
+ }
113
+ case "relation-sum":
114
+ return relation.reduce<number>((acc, value) => {
115
+ if (!matches(value)) return acc
116
+ const v = get(value, computed.field)
117
+ return acc + (typeof v === "number" ? v : Number(v) || 0)
118
+ }, 0)
119
+ case "relation-sum-expr":
120
+ return relation.reduce<number>((acc, value) => {
121
+ if (!matches(value)) return acc
122
+ return acc + evalExpr(value, computed.expression)
123
+ }, 0)
124
+ case "relation-sum-expr-by": {
125
+ const totals = new Map<unknown, number>()
126
+ for (const value of relation) {
127
+ if (!matches(value)) continue
128
+ const unit = get(value, computed.unit)
129
+ const current = totals.get(unit) ?? 0
130
+ totals.set(unit, current + evalExpr(value, computed.expression))
131
+ }
132
+ return [...totals.entries()].map(([unit, total]) => ({ unit, total }))
133
+ }
134
+ case "relation-sum-expr-normalized":
135
+ return relation.reduce<number>((acc, value) => {
136
+ if (!matches(value)) return acc
137
+ const unit = get(value, computed.unit)
138
+ const factor = unit === computed.toBase ? 1 : computed.factors[String(unit)]
139
+ if (factor === undefined || !Number.isFinite(factor)) return acc
140
+ return acc + evalExpr(value, computed.expression) * factor
141
+ }, 0)
142
+ case "relation-collect": {
143
+ const out: unknown[] = []
144
+ const seen = computed.distinct ? new Set<unknown>() : undefined
145
+ for (const value of relation) {
146
+ if (!matches(value)) continue
147
+ const v = get(value, computed.field)
148
+ if (seen) {
149
+ if (seen.has(v)) continue
150
+ seen.add(v)
151
+ }
152
+ out.push(v)
153
+ }
154
+ return out
155
+ }
156
+ case "relation-collect-fields": {
157
+ const out: unknown[] = []
158
+ const seen = computed.distinct ? new Set<unknown>() : undefined
159
+ for (const value of relation) {
160
+ if (!matches(value)) continue
161
+ for (const field of computed.fields) {
162
+ const v = get(value, field)
163
+ if (seen) {
164
+ if (seen.has(v)) continue
165
+ seen.add(v)
166
+ }
167
+ out.push(v)
168
+ }
169
+ }
170
+ return out
171
+ }
172
+ default:
173
+ return assertUnreachable(computed)
174
+ }
175
+ }
176
+
177
+ const computeAggregateValue = <T extends FieldValues>(rows: readonly T[], agg: AggregateIrExpression): unknown => {
178
+ switch (agg._tag) {
179
+ case "agg-count":
180
+ return rows.length
181
+ case "agg-count-when": {
182
+ const filter = agg.filter
183
+ const matches = filter.length === 0 ? () => true : (row: unknown) => codeFilter3_(filter, row)
184
+ return rows.filter((row) => matches(row)).length
185
+ }
186
+ case "agg-sum":
187
+ return rows.reduce<number>((acc, row) => {
188
+ const v = get(row, agg.field)
189
+ return acc + (typeof v === "number" ? v : Number(v) || 0)
190
+ }, 0)
191
+ case "agg-min": {
192
+ let min: unknown = undefined
193
+ for (const row of rows) {
194
+ const v = get(row, agg.field)
195
+ if (v == null) continue
196
+ if (min === undefined || v < (min as any)) min = v
197
+ }
198
+ return min ?? null
199
+ }
200
+ case "agg-max": {
201
+ let max: unknown = undefined
202
+ for (const row of rows) {
203
+ const v = get(row, agg.field)
204
+ if (v == null) continue
205
+ if (max === undefined || v > (max as any)) max = v
206
+ }
207
+ return max ?? null
208
+ }
209
+ default:
210
+ return assertUnreachable(agg)
211
+ }
212
+ }
213
+
12
214
  export function memFilter<T extends FieldValues, U extends keyof T = never>(f: FilterArgs<T, U>) {
13
215
  type M = U extends undefined ? T : Pick<T, U>
14
216
  return ((c: T[]): M[] => {
15
- const select = (r: T[]): M[] => {
16
- const sel = f.select
217
+ const sel = f.select
218
+
219
+ const selectPerRow = (r: T[]): M[] => {
17
220
  if (!sel) return r as M[]
221
+
222
+ // Detect aggregate mode: any select item has `aggregate` key
223
+ const hasAggregates = sel.some((s) => typeof s === "object" && s !== null && "aggregate" in s)
224
+ if (hasAggregates) {
225
+ // GROUP BY + aggregate
226
+ const fieldItems = sel.filter((s): s is { key: string; path: string } =>
227
+ typeof s === "object" && s !== null && "path" in s && !("aggregate" in s)
228
+ )
229
+ const aggregateItems = sel.filter((s): s is { key: string; aggregate: AggregateIrExpression } =>
230
+ typeof s === "object" && s !== null && "aggregate" in s
231
+ )
232
+ const groups = new Map<string, T[]>()
233
+ for (const row of r) {
234
+ const key = fieldItems.map((fi) => JSON.stringify(get(row, fi.path))).join("\0")
235
+ const existing = groups.get(key) ?? []
236
+ existing.push(row)
237
+ groups.set(key, existing)
238
+ }
239
+ return [...groups.values()].map((rows) => {
240
+ const result: Record<string, unknown> = {}
241
+ for (const fi of fieldItems) result[fi.key] = get(rows[0]!, fi.path)
242
+ for (const ai of aggregateItems) result[ai.key] = computeAggregateValue(rows, ai.aggregate)
243
+ return result as M
244
+ })
245
+ }
246
+
18
247
  return r.map((i) => {
19
- const [keys, subKeys] = pipe(
248
+ const [keys, entries] = pipe(
20
249
  sel,
21
- Array.partition((r) =>
22
- typeof r === "string" ? Result.fail(String(r)) : Result.succeed(r as { key: string; subKeys: string[] })
23
- )
250
+ Array.partition((entry) => typeof entry === "string" ? Result.fail(String(entry)) : Result.succeed(entry))
251
+ )
252
+ const subKeys = entries.filter((entry): entry is { key: string; subKeys: readonly string[] } =>
253
+ typeof entry === "object" && entry !== null && "subKeys" in entry
254
+ )
255
+ const computedKeys = entries.filter((entry): entry is {
256
+ key: string
257
+ computed: ComputedProjectionIrExpression
258
+ } => typeof entry === "object" && entry !== null && "computed" in entry)
259
+ const pathKeys = entries.filter((entry): entry is { key: string; path: string } =>
260
+ typeof entry === "object" && entry !== null && "path" in entry && !("aggregate" in entry)
24
261
  )
25
262
  const n = Struct.pick(i, keys)
26
263
  subKeys.forEach((subKey) => {
27
264
  n[subKey.key] = i[subKey.key]!.map(Struct.pick(subKey.subKeys as never[]))
28
265
  })
266
+ computedKeys.forEach((entry) => {
267
+ ;(n as Record<string, unknown>)[entry.key] = computeProjectionValue(i, entry.computed)
268
+ })
269
+ pathKeys.forEach((entry) => {
270
+ ;(n as Record<string, unknown>)[entry.key] = get(i, entry.path)
271
+ })
29
272
  return n as M
30
- }) as any
273
+ })
31
274
  }
275
+
32
276
  const skip = f?.skip
33
277
  const limit = f?.limit
34
278
  const ords = Option.map(Option.fromNullishOr(f.order), (_) =>
@@ -50,7 +294,7 @@ export function memFilter<T extends FieldValues, U extends keyof T = never>(f: F
50
294
  c = Array.sortBy(...ords.value)(c)
51
295
  }
52
296
  if (!skip && limit === 1) {
53
- return select(
297
+ return selectPerRow(
54
298
  Array.findFirst(c, f.filter ? codeFilter(f.filter) : (_) => Option.some(_)).pipe(
55
299
  Option.map(Array.make),
56
300
  Option.getOrElse(
@@ -67,12 +311,12 @@ export function memFilter<T extends FieldValues, U extends keyof T = never>(f: F
67
311
  r = Array.take(r, limit)
68
312
  }
69
313
 
70
- return select(r)
314
+ return selectPerRow(r)
71
315
  })
72
316
  }
73
317
 
74
318
  const defaultNs: NonEmptyString255 = NonEmptyString255("primary")
75
- export class storeId extends ServiceMap.Reference("StoreId", { defaultValue: (): NonEmptyString255 => defaultNs }) {}
319
+ export class storeId extends Context.Reference("StoreId", { defaultValue: (): NonEmptyString255 => defaultNs }) {}
76
320
 
77
321
  function logQuery(f: FilterArgs<any, any>, defaultValues?: any) {
78
322
  return InfraLogger
@@ -151,43 +395,55 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
151
395
  withPermit
152
396
  )
153
397
  const s: Store<IdKey, Encoded> = {
398
+ seedNamespace: () => Effect.void,
399
+
154
400
  queryRaw: (query) =>
155
401
  all
156
402
  .pipe(
157
403
  // Effect.tap(() => logQuery(query, defaultValues)),
158
404
  Effect.map(query.memory),
159
- Effect.withSpan("Memory.queryRaw [effect-app/infra/Store]", {
160
- attributes: { "repository.model_name": modelName, "repository.namespace": namespace }
161
- }, { captureStackTrace: false })
405
+ annotateDb({
406
+ operation: "queryRaw",
407
+ system: "memory",
408
+ collection: modelName,
409
+ namespace,
410
+ entity: modelName
411
+ })
162
412
  ),
163
413
 
164
- all: all.pipe(Effect.withSpan("Memory.all [effect-app/infra/Store]", {
165
- attributes: {
166
- modelName,
167
- namespace
168
- }
169
- }, { captureStackTrace: false })),
414
+ all: all.pipe(annotateDb({
415
+ operation: "all",
416
+ system: "memory",
417
+ collection: modelName,
418
+ namespace,
419
+ entity: modelName
420
+ })),
170
421
  find: (id) =>
171
422
  Ref
172
423
  .get(store)
173
424
  .pipe(
174
425
  Effect.map((_) => Option.fromNullishOr(_.get(id))),
175
- Effect
176
- .withSpan("Memory.find [effect-app/infra/Store]", {
177
- attributes: {
178
- modelName,
179
- namespace
180
- }
181
- }, { captureStackTrace: false })
426
+ annotateDb({
427
+ operation: "find",
428
+ system: "memory",
429
+ collection: modelName,
430
+ namespace,
431
+ entity: modelName,
432
+ extra: { "app.entity.id": id as unknown }
433
+ })
182
434
  ),
183
435
  filter: (f) =>
184
436
  all
185
437
  .pipe(
186
438
  Effect.tap(() => logQuery(f, defaultValues)),
187
439
  Effect.map(memFilter(f)),
188
- Effect.withSpan("Memory.filter [effect-app/infra/Store]", {
189
- attributes: { "repository.model_name": modelName, "repository.namespace": namespace }
190
- }, { captureStackTrace: false })
440
+ annotateDb({
441
+ operation: "filter",
442
+ system: "memory",
443
+ collection: modelName,
444
+ namespace,
445
+ entity: modelName
446
+ })
191
447
  ),
192
448
  set: (e) =>
193
449
  s
@@ -202,10 +458,14 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
202
458
  )
203
459
  ),
204
460
  withPermit,
205
- Effect
206
- .withSpan("Memory.set [effect-app/infra/Store]", {
207
- attributes: { "repository.model_name": modelName, "repository.namespace": namespace }
208
- }, { captureStackTrace: false })
461
+ annotateDb({
462
+ operation: "set",
463
+ system: "memory",
464
+ collection: modelName,
465
+ namespace,
466
+ entity: modelName,
467
+ extra: { "app.entity.id": e[idKey] as unknown }
468
+ })
209
469
  ),
210
470
  batchRemove: (items: NonEmptyReadonlyArray<Encoded[IdKey]>) =>
211
471
  pipe(
@@ -216,10 +476,13 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
216
476
  Effect.filterOrFail((_) => _.length <= 100, () => "BatchRemove: a batch may not exceed 100 items"),
217
477
  Effect.orDie,
218
478
  Effect.andThen(batchRemove),
219
- Effect
220
- .withSpan("Memory.batchRemove [effect-app/infra/Store]", {
221
- attributes: { "repository.model_name": modelName, "repository.namespace": namespace }
222
- }, { captureStackTrace: false })
479
+ annotateDb({
480
+ operation: "batchRemove",
481
+ system: "memory",
482
+ collection: modelName,
483
+ namespace,
484
+ entity: modelName
485
+ })
223
486
  )
224
487
  ),
225
488
  batchSet: (items: readonly [PM, ...PM[]]) =>
@@ -231,18 +494,25 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
231
494
  Effect.filterOrFail((_) => _.length <= 100, () => "BatchSet: a batch may not exceed 100 items"),
232
495
  Effect.orDie,
233
496
  Effect.andThen(batchSet),
234
- Effect
235
- .withSpan("Memory.batchSet [effect-app/infra/Store]", {
236
- attributes: { "repository.model_name": modelName, "repository.namespace": namespace }
237
- }, { captureStackTrace: false })
497
+ annotateDb({
498
+ operation: "batchSet",
499
+ system: "memory",
500
+ collection: modelName,
501
+ namespace,
502
+ entity: modelName
503
+ })
238
504
  )
239
505
  ),
240
506
  bulkSet: flow(
241
507
  batchSet,
242
508
  (_) =>
243
- _.pipe(Effect.withSpan("Memory.bulkSet [effect-app/infra/Store]", {
244
- attributes: { "repository.model_name": modelName, "repository.namespace": namespace }
245
- }, { captureStackTrace: false }))
509
+ _.pipe(annotateDb({
510
+ operation: "bulkSet",
511
+ system: "memory",
512
+ collection: modelName,
513
+ namespace,
514
+ entity: modelName
515
+ }))
246
516
  )
247
517
  }
248
518
  return s
@@ -250,56 +520,60 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
250
520
  }
251
521
 
252
522
  export const makeMemoryStore = () => ({
253
- make: <IdKey extends keyof Encoded, Encoded extends FieldValues, R, E>(
523
+ make: Effect.fnUntraced(function*<IdKey extends keyof Encoded, Encoded extends FieldValues, R, E>(
254
524
  modelName: string,
255
525
  idKey: IdKey,
256
526
  seed?: Effect.Effect<Iterable<Encoded>, E, R>,
257
527
  config?: StoreConfig<Encoded>
258
- ) =>
259
- Effect.gen(function*() {
260
- const storesSem = Semaphore.makeUnsafe(1)
261
- const primary = yield* makeMemoryStoreInt<IdKey, Encoded, R, E>(
262
- modelName,
263
- idKey,
264
- "primary",
265
- seed,
266
- config?.defaultValues
267
- )
268
- const ctx = yield* Effect.services<R>()
269
- const stores = new Map([["primary", primary]])
270
- const getStore = !config?.allowNamespace
271
- ? Effect.succeed(primary)
272
- : storeId.asEffect().pipe(Effect.flatMap((namespace) => {
273
- const store = stores.get(namespace)
274
- if (store) {
275
- return Effect.succeed(store)
276
- }
277
- if (!config.allowNamespace!(namespace)) {
278
- throw new Error(`Namespace ${namespace} not allowed!`)
279
- }
280
- return storesSem.withPermits(1)(Effect.suspend(() => {
281
- const store = stores.get(namespace)
282
- if (store) return Effect.sync(() => store)
283
- return makeMemoryStoreInt(modelName, idKey, namespace, seed, config?.defaultValues)
284
- .pipe(
285
- Effect.orDie,
286
- Effect.provide(ctx),
287
- Effect.tap((store) => Effect.sync(() => stores.set(namespace, store)))
288
- )
289
- }))
290
- }))
291
- const s: Store<IdKey, Encoded> = {
292
- all: Effect.flatMap(getStore, (_) => _.all),
293
- queryRaw: (...args) => Effect.flatMap(getStore, (_) => _.queryRaw(...args)),
294
- find: (...args) => Effect.flatMap(getStore, (_) => _.find(...args)),
295
- filter: (...args) => Effect.flatMap(getStore, (_) => _.filter(...args)),
296
- set: (...args) => Effect.flatMap(getStore, (_) => _.set(...args)),
297
- batchSet: (...args) => Effect.flatMap(getStore, (_) => _.batchSet(...args)),
298
- bulkSet: (...args) => Effect.flatMap(getStore, (_) => _.bulkSet(...args)),
299
- batchRemove: (...args) => Effect.flatMap(getStore, (_) => _.batchRemove(...args))
528
+ ) {
529
+ const primary = yield* makeMemoryStoreInt<IdKey, Encoded, R, E>(
530
+ modelName,
531
+ idKey,
532
+ "primary",
533
+ seed,
534
+ config?.defaultValues
535
+ )
536
+ const ctx = yield* Effect.context<R>()
537
+ const stores = new Map([["primary", primary]])
538
+ const semaphores = new Map<string, Semaphore.Semaphore>()
539
+ const getSem = (ns: string) => {
540
+ let sem = semaphores.get(ns)
541
+ if (!sem) {
542
+ sem = Semaphore.makeUnsafe(1)
543
+ semaphores.set(ns, sem)
300
544
  }
301
- return s
302
- })
545
+ return sem
546
+ }
547
+ const ensureStore = (namespace: string) =>
548
+ getSem(namespace).withPermits(1)(Effect.suspend(() => {
549
+ const store = stores.get(namespace)
550
+ if (store) return Effect.succeed(store)
551
+ if (config?.allowNamespace && !config.allowNamespace(namespace)) {
552
+ throw new Error(`Namespace ${namespace} not allowed!`)
553
+ }
554
+ return makeMemoryStoreInt(modelName, idKey, namespace, seed, config?.defaultValues)
555
+ .pipe(
556
+ Effect.orDie,
557
+ Effect.provide(ctx),
558
+ Effect.tap((store) => Effect.sync(() => stores.set(namespace, store)))
559
+ )
560
+ }))
561
+ const getStore = !config?.allowNamespace
562
+ ? Effect.succeed(primary)
563
+ : storeId.pipe(Effect.flatMap((namespace) => ensureStore(namespace)))
564
+ const s: Store<IdKey, Encoded> = {
565
+ seedNamespace: (namespace) => ensureStore(namespace).pipe(Effect.asVoid),
566
+ all: Effect.flatMap(getStore, (_) => _.all),
567
+ queryRaw: (...args) => Effect.flatMap(getStore, (_) => _.queryRaw(...args)),
568
+ find: (...args) => Effect.flatMap(getStore, (_) => _.find(...args)),
569
+ filter: (...args) => Effect.flatMap(getStore, (_) => _.filter(...args)),
570
+ set: (...args) => Effect.flatMap(getStore, (_) => _.set(...args)),
571
+ batchSet: (...args) => Effect.flatMap(getStore, (_) => _.batchSet(...args)),
572
+ bulkSet: (...args) => Effect.flatMap(getStore, (_) => _.bulkSet(...args)),
573
+ batchRemove: (...args) => Effect.flatMap(getStore, (_) => _.batchRemove(...args))
574
+ }
575
+ return s
576
+ })
303
577
  })
304
578
 
305
579
  export const MemoryStoreLive = StoreMaker.toLayer(Effect.sync(() => makeMemoryStore()))