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

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 (505) hide show
  1. package/CHANGELOG.md +1973 -0
  2. package/_check.sh +1 -1
  3. package/dist/CUPS.d.ts +30 -11
  4. package/dist/CUPS.d.ts.map +1 -1
  5. package/dist/CUPS.js +35 -14
  6. package/dist/ClusterCosmos.d.ts +64 -0
  7. package/dist/ClusterCosmos.d.ts.map +1 -0
  8. package/dist/ClusterCosmos.js +501 -0
  9. package/dist/ClusterServiceBus.d.ts +67 -0
  10. package/dist/ClusterServiceBus.d.ts.map +1 -0
  11. package/dist/ClusterServiceBus.js +82 -0
  12. package/dist/ContextProvider.d.ts +34 -0
  13. package/dist/ContextProvider.d.ts.map +1 -0
  14. package/dist/ContextProvider.js +40 -0
  15. package/dist/Emailer/Sendgrid.d.ts +111 -147
  16. package/dist/Emailer/Sendgrid.d.ts.map +1 -1
  17. package/dist/Emailer/Sendgrid.js +24 -19
  18. package/dist/Emailer/fake.d.ts +2 -2
  19. package/dist/Emailer/fake.d.ts.map +1 -1
  20. package/dist/Emailer/fake.js +4 -4
  21. package/dist/MainFiberSet.d.ts +12 -9
  22. package/dist/MainFiberSet.d.ts.map +1 -1
  23. package/dist/MainFiberSet.js +10 -6
  24. package/dist/QueueMaker/SQLQueue.d.ts +8 -9
  25. package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
  26. package/dist/QueueMaker/SQLQueue.js +138 -120
  27. package/dist/QueueMaker/errors.d.ts +5 -3
  28. package/dist/QueueMaker/errors.d.ts.map +1 -1
  29. package/dist/QueueMaker/errors.js +4 -2
  30. package/dist/QueueMaker/memQueue.d.ts +10 -6
  31. package/dist/QueueMaker/memQueue.d.ts.map +1 -1
  32. package/dist/QueueMaker/memQueue.js +84 -68
  33. package/dist/QueueMaker/sbqueue.d.ts +9 -5
  34. package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
  35. package/dist/QueueMaker/sbqueue.js +60 -58
  36. package/dist/RequestFiberSet.d.ts +10 -7
  37. package/dist/RequestFiberSet.d.ts.map +1 -1
  38. package/dist/RequestFiberSet.js +13 -8
  39. package/dist/SQL/Model.d.ts +468 -0
  40. package/dist/SQL/Model.d.ts.map +1 -0
  41. package/dist/SQL/Model.js +469 -0
  42. package/dist/SQL.d.ts +2 -0
  43. package/dist/SQL.d.ts.map +1 -0
  44. package/dist/{adapters/SQL.js → SQL.js} +1 -1
  45. package/dist/ServiceBus.d.ts +61 -0
  46. package/dist/ServiceBus.d.ts.map +1 -0
  47. package/dist/ServiceBus.js +108 -0
  48. package/dist/Store/Cosmos/query.d.ts +15 -4
  49. package/dist/Store/Cosmos/query.d.ts.map +1 -1
  50. package/dist/Store/Cosmos/query.js +179 -41
  51. package/dist/Store/Cosmos.d.ts +3 -3
  52. package/dist/Store/Cosmos.d.ts.map +1 -1
  53. package/dist/Store/Cosmos.js +344 -246
  54. package/dist/Store/Disk.d.ts +5 -5
  55. package/dist/Store/Disk.d.ts.map +1 -1
  56. package/dist/Store/Disk.js +78 -38
  57. package/dist/Store/Memory.d.ts +7 -10
  58. package/dist/Store/Memory.d.ts.map +1 -1
  59. package/dist/Store/Memory.js +326 -66
  60. package/dist/Store/SQL/Pg.d.ts +4 -0
  61. package/dist/Store/SQL/Pg.d.ts.map +1 -0
  62. package/dist/Store/SQL/Pg.js +232 -0
  63. package/dist/Store/SQL/query.d.ts +49 -0
  64. package/dist/Store/SQL/query.d.ts.map +1 -0
  65. package/dist/Store/SQL/query.js +527 -0
  66. package/dist/Store/SQL.d.ts +21 -0
  67. package/dist/Store/SQL.d.ts.map +1 -0
  68. package/dist/Store/SQL.js +449 -0
  69. package/dist/Store/codeFilter.d.ts +5 -5
  70. package/dist/Store/codeFilter.d.ts.map +1 -1
  71. package/dist/Store/codeFilter.js +6 -3
  72. package/dist/Store/index.d.ts +7 -5
  73. package/dist/Store/index.d.ts.map +1 -1
  74. package/dist/Store/index.js +18 -5
  75. package/dist/Store/utils.d.ts +4 -3
  76. package/dist/Store/utils.d.ts.map +1 -1
  77. package/dist/Store/utils.js +5 -5
  78. package/dist/WorkflowEngineCosmos.d.ts +29 -0
  79. package/dist/WorkflowEngineCosmos.d.ts.map +1 -0
  80. package/dist/WorkflowEngineCosmos.js +521 -0
  81. package/dist/WorkflowEngineSqlite.d.ts +24 -0
  82. package/dist/WorkflowEngineSqlite.d.ts.map +1 -0
  83. package/dist/WorkflowEngineSqlite.js +550 -0
  84. package/dist/arbs.d.ts +2 -2
  85. package/dist/arbs.d.ts.map +1 -1
  86. package/dist/arbs.js +5 -3
  87. package/dist/codec.d.ts +5 -0
  88. package/dist/codec.d.ts.map +1 -0
  89. package/dist/codec.js +5 -0
  90. package/dist/cosmos-client.d.ts +16 -0
  91. package/dist/cosmos-client.d.ts.map +1 -0
  92. package/dist/cosmos-client.js +11 -0
  93. package/dist/errorReporter.d.ts +7 -5
  94. package/dist/errorReporter.d.ts.map +1 -1
  95. package/dist/errorReporter.js +23 -27
  96. package/dist/errors.d.ts +1 -1
  97. package/dist/fileUtil.d.ts +2 -2
  98. package/dist/fileUtil.d.ts.map +1 -1
  99. package/dist/fileUtil.js +2 -2
  100. package/dist/index.d.ts +3 -2
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +3 -2
  103. package/dist/internal/RequestContextMiddleware.d.ts +5 -0
  104. package/dist/internal/RequestContextMiddleware.d.ts.map +1 -0
  105. package/dist/internal/RequestContextMiddleware.js +45 -0
  106. package/dist/internal/auth.d.ts +53 -0
  107. package/dist/internal/auth.d.ts.map +1 -0
  108. package/dist/internal/auth.js +180 -0
  109. package/dist/internal/events.d.ts +11 -0
  110. package/dist/internal/events.d.ts.map +1 -0
  111. package/dist/internal/events.js +49 -0
  112. package/dist/internal/health.d.ts +3 -0
  113. package/dist/internal/health.d.ts.map +1 -0
  114. package/dist/internal/health.js +5 -0
  115. package/dist/layerUtils.d.ts +32 -0
  116. package/dist/layerUtils.d.ts.map +1 -0
  117. package/dist/layerUtils.js +17 -0
  118. package/dist/logger/jsonLogger.d.ts +2 -2
  119. package/dist/logger/jsonLogger.d.ts.map +1 -1
  120. package/dist/logger/jsonLogger.js +5 -3
  121. package/dist/logger/logFmtLogger.d.ts +2 -2
  122. package/dist/logger/logFmtLogger.d.ts.map +1 -1
  123. package/dist/logger/logFmtLogger.js +3 -3
  124. package/dist/logger/shared.d.ts +3 -3
  125. package/dist/logger/shared.d.ts.map +1 -1
  126. package/dist/logger/shared.js +5 -5
  127. package/dist/logger.d.ts +1 -1
  128. package/dist/logger.d.ts.map +1 -1
  129. package/dist/memQueue.d.ts +15 -0
  130. package/dist/memQueue.d.ts.map +1 -0
  131. package/dist/memQueue.js +21 -0
  132. package/dist/middlewares.d.ts +10 -0
  133. package/dist/middlewares.d.ts.map +1 -0
  134. package/dist/{api/middlewares.js → middlewares.js} +1 -1
  135. package/dist/mongo-client.d.ts +11 -0
  136. package/dist/mongo-client.d.ts.map +1 -0
  137. package/dist/mongo-client.js +15 -0
  138. package/dist/otel.d.ts +75 -0
  139. package/dist/otel.d.ts.map +1 -0
  140. package/dist/otel.js +65 -0
  141. package/dist/rateLimit.d.ts +12 -4
  142. package/dist/rateLimit.d.ts.map +1 -1
  143. package/dist/rateLimit.js +7 -12
  144. package/dist/redis-client.d.ts +42 -0
  145. package/dist/redis-client.d.ts.map +1 -0
  146. package/dist/redis-client.js +98 -0
  147. package/dist/reportError.d.ts +4 -0
  148. package/dist/reportError.d.ts.map +1 -0
  149. package/dist/reportError.js +28 -0
  150. package/dist/routing/middleware/RouterMiddleware.d.ts +16 -0
  151. package/dist/routing/middleware/RouterMiddleware.d.ts.map +1 -0
  152. package/dist/{api/routing → routing}/middleware/RouterMiddleware.js +1 -1
  153. package/dist/routing/middleware/middleware.d.ts +48 -0
  154. package/dist/routing/middleware/middleware.d.ts.map +1 -0
  155. package/dist/routing/middleware/middleware.js +128 -0
  156. package/dist/routing/middleware.d.ts +3 -0
  157. package/dist/routing/middleware.d.ts.map +1 -0
  158. package/dist/{api/routing → routing}/middleware.js +1 -2
  159. package/dist/routing/schema/jwt.d.ts +4 -0
  160. package/dist/routing/schema/jwt.d.ts.map +1 -0
  161. package/dist/routing/schema/jwt.js +13 -0
  162. package/dist/routing/tsort.d.ts +8 -0
  163. package/dist/routing/tsort.d.ts.map +1 -0
  164. package/dist/routing/tsort.js +51 -0
  165. package/dist/routing/utils.d.ts +19 -0
  166. package/dist/routing/utils.d.ts.map +1 -0
  167. package/dist/routing/utils.js +45 -0
  168. package/dist/routing.d.ts +184 -0
  169. package/dist/routing.d.ts.map +1 -0
  170. package/dist/routing.js +236 -0
  171. package/dist/test.d.ts +3 -3
  172. package/dist/test.d.ts.map +1 -1
  173. package/dist/test.js +2 -2
  174. package/dist/util.d.ts +3 -0
  175. package/dist/util.d.ts.map +1 -0
  176. package/dist/util.js +14 -0
  177. package/dist/vitest.d.ts +1 -1
  178. package/docs/cluster-storage.md +26 -0
  179. package/docs/workflow-engine.md +262 -0
  180. package/examples/query.ts +47 -39
  181. package/package.json +31 -345
  182. package/run.sh +1 -0
  183. package/src/CUPS.ts +52 -13
  184. package/src/ClusterCosmos.ts +984 -0
  185. package/src/ClusterServiceBus.ts +242 -0
  186. package/src/{api/ContextProvider.ts → ContextProvider.ts} +19 -16
  187. package/src/Emailer/Sendgrid.ts +82 -59
  188. package/src/Emailer/fake.ts +3 -3
  189. package/src/MainFiberSet.ts +12 -10
  190. package/src/QueueMaker/SQLQueue.ts +153 -156
  191. package/src/QueueMaker/errors.ts +3 -1
  192. package/src/QueueMaker/memQueue.ts +113 -107
  193. package/src/QueueMaker/sbqueue.ts +78 -90
  194. package/src/RequestFiberSet.ts +13 -8
  195. package/src/{adapters/SQL → SQL}/Model.ts +42 -41
  196. package/src/ServiceBus.ts +219 -0
  197. package/src/Store/Cosmos/query.ts +216 -52
  198. package/src/Store/Cosmos.ts +493 -353
  199. package/src/Store/Disk.ts +109 -69
  200. package/src/Store/Memory.ts +365 -96
  201. package/src/Store/SQL/Pg.ts +363 -0
  202. package/src/Store/SQL/query.ts +603 -0
  203. package/src/Store/SQL.ts +735 -0
  204. package/src/Store/codeFilter.ts +8 -5
  205. package/src/Store/index.ts +21 -6
  206. package/src/Store/utils.ts +26 -24
  207. package/src/WorkflowEngineCosmos.ts +719 -0
  208. package/src/WorkflowEngineSqlite.ts +813 -0
  209. package/src/arbs.ts +5 -3
  210. package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
  211. package/src/errorReporter.ts +66 -76
  212. package/src/fileUtil.ts +1 -1
  213. package/src/index.ts +2 -1
  214. package/src/{api/internal → internal}/RequestContextMiddleware.ts +23 -6
  215. package/src/internal/auth.ts +272 -0
  216. package/src/{api/internal → internal}/events.ts +22 -13
  217. package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
  218. package/src/logger/jsonLogger.ts +4 -2
  219. package/src/logger/logFmtLogger.ts +2 -2
  220. package/src/logger/shared.ts +5 -4
  221. package/src/{adapters/memQueue.ts → memQueue.ts} +5 -4
  222. package/src/{adapters/mongo-client.ts → mongo-client.ts} +4 -2
  223. package/src/otel.ts +152 -0
  224. package/src/rateLimit.ts +34 -23
  225. package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
  226. package/src/{api/reportError.ts → reportError.ts} +3 -2
  227. package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
  228. package/src/{api/routing → routing}/middleware/middleware.ts +62 -17
  229. package/src/routing/middleware.ts +4 -0
  230. package/src/{api/routing → routing}/schema/jwt.ts +2 -1
  231. package/src/{api/routing → routing}/utils.ts +2 -1
  232. package/src/routing.ts +768 -0
  233. package/src/test.ts +2 -2
  234. package/test/auth.test.ts +101 -0
  235. package/test/cluster-cosmos.test.ts +590 -0
  236. package/test/cluster-servicebus.test.ts +180 -0
  237. package/test/cluster-sqlite.test.ts +207 -0
  238. package/test/contextProvider.test.ts +15 -12
  239. package/test/controller.test.ts +28 -32
  240. package/test/cosmos-query.test.ts +159 -0
  241. package/test/dist/_check-agg-infer.test-d.d.ts +2 -0
  242. package/test/dist/_check-agg-infer.test-d.d.ts.map +1 -0
  243. package/test/dist/_check-agg-infer.test-d.js +19 -0
  244. package/test/dist/_check-proj-infer.test-d.d.ts +2 -0
  245. package/test/dist/_check-proj-infer.test-d.d.ts.map +1 -0
  246. package/test/dist/_check-proj-infer.test-d.js +16 -0
  247. package/test/dist/_check-tighten.test-d.d.ts +2 -0
  248. package/test/dist/_check-tighten.test-d.d.ts.map +1 -0
  249. package/test/dist/_check-tighten.test-d.js +21 -0
  250. package/test/dist/auth.test.d.ts.map +1 -0
  251. package/test/dist/cluster-cosmos.test.d.ts.map +1 -0
  252. package/test/dist/cluster-servicebus.test.d.ts.map +1 -0
  253. package/test/dist/cluster-sqlite.test.d.ts.map +1 -0
  254. package/test/dist/contextProvider.test.d.ts.map +1 -1
  255. package/test/dist/controller.test.d.ts.map +1 -1
  256. package/test/dist/cosmos-query.test.d.ts.map +1 -0
  257. package/test/dist/date-query.test.d.ts.map +1 -0
  258. package/test/dist/fixtures.d.ts +30 -12
  259. package/test/dist/fixtures.d.ts.map +1 -1
  260. package/test/dist/fixtures.js +17 -10
  261. package/test/dist/query.test.d.ts.map +1 -1
  262. package/test/dist/rawQuery.test.d.ts.map +1 -1
  263. package/test/dist/repository-ext.test.d.ts.map +1 -0
  264. package/test/dist/requires.test.d.ts.map +1 -1
  265. package/test/dist/router-generator.test.d.ts.map +1 -0
  266. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  267. package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
  268. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  269. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  270. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  271. package/test/dist/sql-store.test.d.ts.map +1 -0
  272. package/test/dist/workflow-engine-cosmos.test.d.ts.map +1 -0
  273. package/test/dist/workflow-engine-sqlite.test.d.ts.map +1 -0
  274. package/test/fixtures.ts +16 -9
  275. package/test/layerUtils.test.ts +2 -2
  276. package/test/query.test.ts +905 -40
  277. package/test/rawQuery.test.ts +340 -22
  278. package/test/repository-ext.test.ts +62 -0
  279. package/test/requires.test.ts +10 -5
  280. package/test/router-generator.test.ts +187 -0
  281. package/test/routing-interruptibility.test.ts +66 -0
  282. package/test/rpc-context-map-streaming.test.ts +262 -0
  283. package/test/rpc-e2e-invalidation.test.ts +256 -0
  284. package/test/rpc-multi-middleware.test.ts +85 -10
  285. package/test/rpc-stream-fullstack.test.ts +304 -0
  286. package/test/sql-store.test.ts +1711 -0
  287. package/test/validateSample.test.ts +26 -14
  288. package/test/workflow-engine-cosmos.test.ts +354 -0
  289. package/test/workflow-engine-sqlite.test.ts +299 -0
  290. package/tsconfig.examples.json +1 -1
  291. package/tsconfig.json +2 -1
  292. package/tsconfig.json.bak +2 -2
  293. package/tsconfig.src.json +35 -35
  294. package/tsconfig.test.json +2 -2
  295. package/dist/Emailer/service.d.ts +0 -55
  296. package/dist/Emailer/service.d.ts.map +0 -1
  297. package/dist/Emailer/service.js +0 -6
  298. package/dist/Emailer.d.ts +0 -2
  299. package/dist/Emailer.d.ts.map +0 -1
  300. package/dist/Emailer.js +0 -2
  301. package/dist/Model/Repository/ext.d.ts +0 -41
  302. package/dist/Model/Repository/ext.d.ts.map +0 -1
  303. package/dist/Model/Repository/ext.js +0 -65
  304. package/dist/Model/Repository/internal/internal.d.ts +0 -59
  305. package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
  306. package/dist/Model/Repository/internal/internal.js +0 -316
  307. package/dist/Model/Repository/legacy.d.ts +0 -19
  308. package/dist/Model/Repository/legacy.d.ts.map +0 -1
  309. package/dist/Model/Repository/legacy.js +0 -2
  310. package/dist/Model/Repository/makeRepo.d.ts +0 -49
  311. package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
  312. package/dist/Model/Repository/makeRepo.js +0 -24
  313. package/dist/Model/Repository/service.d.ts +0 -89
  314. package/dist/Model/Repository/service.d.ts.map +0 -1
  315. package/dist/Model/Repository/service.js +0 -2
  316. package/dist/Model/Repository/validation.d.ts +0 -42
  317. package/dist/Model/Repository/validation.d.ts.map +0 -1
  318. package/dist/Model/Repository/validation.js +0 -32
  319. package/dist/Model/Repository.d.ts +0 -6
  320. package/dist/Model/Repository.d.ts.map +0 -1
  321. package/dist/Model/Repository.js +0 -6
  322. package/dist/Model/dsl.d.ts +0 -32
  323. package/dist/Model/dsl.d.ts.map +0 -1
  324. package/dist/Model/dsl.js +0 -44
  325. package/dist/Model/filter/filterApi.d.ts +0 -30
  326. package/dist/Model/filter/filterApi.d.ts.map +0 -1
  327. package/dist/Model/filter/filterApi.js +0 -2
  328. package/dist/Model/filter/types/errors.d.ts +0 -29
  329. package/dist/Model/filter/types/errors.d.ts.map +0 -1
  330. package/dist/Model/filter/types/errors.js +0 -2
  331. package/dist/Model/filter/types/fields.d.ts +0 -15
  332. package/dist/Model/filter/types/fields.d.ts.map +0 -1
  333. package/dist/Model/filter/types/fields.js +0 -2
  334. package/dist/Model/filter/types/path/common.d.ts +0 -316
  335. package/dist/Model/filter/types/path/common.d.ts.map +0 -1
  336. package/dist/Model/filter/types/path/common.js +0 -2
  337. package/dist/Model/filter/types/path/eager.d.ts +0 -95
  338. package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
  339. package/dist/Model/filter/types/path/eager.js +0 -31
  340. package/dist/Model/filter/types/path/index.d.ts +0 -4
  341. package/dist/Model/filter/types/path/index.d.ts.map +0 -1
  342. package/dist/Model/filter/types/path/index.js +0 -3
  343. package/dist/Model/filter/types/utils.d.ts +0 -79
  344. package/dist/Model/filter/types/utils.d.ts.map +0 -1
  345. package/dist/Model/filter/types/utils.js +0 -2
  346. package/dist/Model/filter/types/validator.d.ts +0 -30
  347. package/dist/Model/filter/types/validator.d.ts.map +0 -1
  348. package/dist/Model/filter/types/validator.js +0 -2
  349. package/dist/Model/filter/types.d.ts +0 -5
  350. package/dist/Model/filter/types.d.ts.map +0 -1
  351. package/dist/Model/filter/types.js +0 -7
  352. package/dist/Model/query/dsl.d.ts +0 -248
  353. package/dist/Model/query/dsl.d.ts.map +0 -1
  354. package/dist/Model/query/dsl.js +0 -104
  355. package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
  356. package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
  357. package/dist/Model/query/new-kid-interpreter.js +0 -165
  358. package/dist/Model/query.d.ts +0 -15
  359. package/dist/Model/query.d.ts.map +0 -1
  360. package/dist/Model/query.js +0 -3
  361. package/dist/Model.d.ts +0 -4
  362. package/dist/Model.d.ts.map +0 -1
  363. package/dist/Model.js +0 -4
  364. package/dist/Operations.d.ts +0 -55
  365. package/dist/Operations.d.ts.map +0 -1
  366. package/dist/Operations.js +0 -102
  367. package/dist/OperationsRepo.d.ts +0 -41
  368. package/dist/OperationsRepo.d.ts.map +0 -1
  369. package/dist/OperationsRepo.js +0 -14
  370. package/dist/QueueMaker/service.d.ts +0 -11
  371. package/dist/QueueMaker/service.d.ts.map +0 -1
  372. package/dist/QueueMaker/service.js +0 -4
  373. package/dist/RequestContext.d.ts +0 -63
  374. package/dist/RequestContext.d.ts.map +0 -1
  375. package/dist/RequestContext.js +0 -49
  376. package/dist/Store/ContextMapContainer.d.ts +0 -14
  377. package/dist/Store/ContextMapContainer.d.ts.map +0 -1
  378. package/dist/Store/ContextMapContainer.js +0 -16
  379. package/dist/Store/service.d.ts +0 -108
  380. package/dist/Store/service.d.ts.map +0 -1
  381. package/dist/Store/service.js +0 -71
  382. package/dist/Store.d.ts +0 -2
  383. package/dist/Store.d.ts.map +0 -1
  384. package/dist/Store.js +0 -2
  385. package/dist/adapters/SQL/Model.d.ts +0 -479
  386. package/dist/adapters/SQL/Model.d.ts.map +0 -1
  387. package/dist/adapters/SQL/Model.js +0 -478
  388. package/dist/adapters/SQL.d.ts +0 -2
  389. package/dist/adapters/SQL.d.ts.map +0 -1
  390. package/dist/adapters/ServiceBus.d.ts +0 -58
  391. package/dist/adapters/ServiceBus.d.ts.map +0 -1
  392. package/dist/adapters/ServiceBus.js +0 -99
  393. package/dist/adapters/cosmos-client.d.ts +0 -14
  394. package/dist/adapters/cosmos-client.d.ts.map +0 -1
  395. package/dist/adapters/cosmos-client.js +0 -9
  396. package/dist/adapters/index.d.ts +0 -2
  397. package/dist/adapters/index.d.ts.map +0 -1
  398. package/dist/adapters/index.js +0 -2
  399. package/dist/adapters/logger.d.ts +0 -9
  400. package/dist/adapters/logger.d.ts.map +0 -1
  401. package/dist/adapters/logger.js +0 -3
  402. package/dist/adapters/memQueue.d.ts +0 -13
  403. package/dist/adapters/memQueue.d.ts.map +0 -1
  404. package/dist/adapters/memQueue.js +0 -20
  405. package/dist/adapters/mongo-client.d.ts +0 -10
  406. package/dist/adapters/mongo-client.d.ts.map +0 -1
  407. package/dist/adapters/mongo-client.js +0 -13
  408. package/dist/adapters/redis-client.d.ts +0 -39
  409. package/dist/adapters/redis-client.d.ts.map +0 -1
  410. package/dist/adapters/redis-client.js +0 -94
  411. package/dist/api/ContextProvider.d.ts +0 -31
  412. package/dist/api/ContextProvider.d.ts.map +0 -1
  413. package/dist/api/ContextProvider.js +0 -38
  414. package/dist/api/codec.d.ts +0 -5
  415. package/dist/api/codec.d.ts.map +0 -1
  416. package/dist/api/codec.js +0 -5
  417. package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
  418. package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
  419. package/dist/api/internal/RequestContextMiddleware.js +0 -35
  420. package/dist/api/internal/auth.d.ts +0 -15
  421. package/dist/api/internal/auth.d.ts.map +0 -1
  422. package/dist/api/internal/auth.js +0 -47
  423. package/dist/api/internal/events.d.ts +0 -9
  424. package/dist/api/internal/events.d.ts.map +0 -1
  425. package/dist/api/internal/events.js +0 -42
  426. package/dist/api/internal/health.d.ts +0 -3
  427. package/dist/api/internal/health.d.ts.map +0 -1
  428. package/dist/api/internal/health.js +0 -5
  429. package/dist/api/layerUtils.d.ts +0 -24
  430. package/dist/api/layerUtils.d.ts.map +0 -1
  431. package/dist/api/layerUtils.js +0 -16
  432. package/dist/api/middlewares.d.ts +0 -10
  433. package/dist/api/middlewares.d.ts.map +0 -1
  434. package/dist/api/reportError.d.ts +0 -4
  435. package/dist/api/reportError.d.ts.map +0 -1
  436. package/dist/api/reportError.js +0 -27
  437. package/dist/api/routing/middleware/RouterMiddleware.d.ts +0 -15
  438. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
  439. package/dist/api/routing/middleware/middleware.d.ts +0 -9
  440. package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
  441. package/dist/api/routing/middleware/middleware.js +0 -92
  442. package/dist/api/routing/middleware.d.ts +0 -4
  443. package/dist/api/routing/middleware.d.ts.map +0 -1
  444. package/dist/api/routing/schema/jwt.d.ts +0 -4
  445. package/dist/api/routing/schema/jwt.d.ts.map +0 -1
  446. package/dist/api/routing/schema/jwt.js +0 -12
  447. package/dist/api/routing/tsort.d.ts +0 -8
  448. package/dist/api/routing/tsort.d.ts.map +0 -1
  449. package/dist/api/routing/tsort.js +0 -51
  450. package/dist/api/routing/utils.d.ts +0 -19
  451. package/dist/api/routing/utils.d.ts.map +0 -1
  452. package/dist/api/routing/utils.js +0 -44
  453. package/dist/api/routing.d.ts +0 -138
  454. package/dist/api/routing.d.ts.map +0 -1
  455. package/dist/api/routing.js +0 -166
  456. package/dist/api/setupRequest.d.ts +0 -12
  457. package/dist/api/setupRequest.d.ts.map +0 -1
  458. package/dist/api/setupRequest.js +0 -44
  459. package/dist/api/util.d.ts +0 -3
  460. package/dist/api/util.d.ts.map +0 -1
  461. package/dist/api/util.js +0 -14
  462. package/eslint.config.mjs +0 -24
  463. package/src/Emailer/service.ts +0 -52
  464. package/src/Emailer.ts +0 -1
  465. package/src/Model/Repository/ext.ts +0 -283
  466. package/src/Model/Repository/internal/internal.ts +0 -577
  467. package/src/Model/Repository/legacy.ts +0 -27
  468. package/src/Model/Repository/makeRepo.ts +0 -139
  469. package/src/Model/Repository/service.ts +0 -627
  470. package/src/Model/Repository/validation.ts +0 -31
  471. package/src/Model/Repository.ts +0 -5
  472. package/src/Model/dsl.ts +0 -128
  473. package/src/Model/filter/filterApi.ts +0 -60
  474. package/src/Model/filter/types/errors.ts +0 -47
  475. package/src/Model/filter/types/fields.ts +0 -50
  476. package/src/Model/filter/types/path/common.ts +0 -404
  477. package/src/Model/filter/types/path/eager.ts +0 -298
  478. package/src/Model/filter/types/path/index.ts +0 -4
  479. package/src/Model/filter/types/utils.ts +0 -128
  480. package/src/Model/filter/types/validator.ts +0 -46
  481. package/src/Model/filter/types.ts +0 -6
  482. package/src/Model/query/dsl.ts +0 -2110
  483. package/src/Model/query/new-kid-interpreter.ts +0 -210
  484. package/src/Model/query.ts +0 -13
  485. package/src/Model.ts +0 -3
  486. package/src/Operations.ts +0 -235
  487. package/src/OperationsRepo.ts +0 -16
  488. package/src/QueueMaker/service.ts +0 -17
  489. package/src/RequestContext.ts +0 -63
  490. package/src/Store/ContextMapContainer.ts +0 -20
  491. package/src/Store/service.ts +0 -184
  492. package/src/Store.ts +0 -1
  493. package/src/adapters/ServiceBus.ts +0 -209
  494. package/src/adapters/index.ts +0 -0
  495. package/src/adapters/logger.ts +0 -3
  496. package/src/api/internal/auth.ts +0 -68
  497. package/src/api/routing/middleware.ts +0 -6
  498. package/src/api/routing.ts +0 -598
  499. package/src/api/setupRequest.ts +0 -84
  500. /package/src/{adapters/SQL.ts → SQL.ts} +0 -0
  501. /package/src/{api/codec.ts → codec.ts} +0 -0
  502. /package/src/{api/internal → internal}/health.ts +0 -0
  503. /package/src/{api/middlewares.ts → middlewares.ts} +0 -0
  504. /package/src/{api/routing → routing}/tsort.ts +0 -0
  505. /package/src/{api/util.ts → util.ts} +0 -0
@@ -1,577 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import type {} from "effect/Equal"
3
- import type {} from "effect/Hash"
4
- import { Array, Chunk, Effect, Equivalence, flow, type NonEmptyReadonlyArray, Option, pipe, Pipeable, PubSub, Result, S, SchemaAST, ServiceMap, Unify } from "effect-app"
5
- import { toNonEmptyArray } from "effect-app/Array"
6
- import { NotFoundError } from "effect-app/client/errors"
7
- import { flatMapOption } from "effect-app/Effect"
8
- import { type Codec, NonNegativeInt } from "effect-app/Schema"
9
- import { setupRequestContextFromCurrent } from "../../../api/setupRequest.js"
10
- import { type FilterArgs, type PersistenceModelType, type StoreConfig, StoreMaker } from "../../../Store.js"
11
- import { getContextMap } from "../../../Store/ContextMapContainer.js"
12
- import type { FieldValues } from "../../filter/types.js"
13
- import * as Q from "../../query.js"
14
- import type { Repository } from "../service.js"
15
- import { ValidationError, ValidationResult } from "../validation.js"
16
-
17
- const dedupe = Array.dedupeWith(Equivalence.String)
18
-
19
- /**
20
- * A base implementation to create a repository.
21
- */
22
- export function makeRepoInternal<
23
- Evt = never
24
- >() {
25
- return <
26
- ItemType extends string,
27
- R,
28
- Encoded extends FieldValues,
29
- T,
30
- IdKey extends keyof T & keyof Encoded
31
- >(
32
- name: ItemType,
33
- schema: S.Codec<T, Encoded, R>,
34
- mapFrom: (pm: Encoded) => Encoded,
35
- mapTo: (e: Encoded, etag: string | undefined) => PersistenceModelType<Encoded>,
36
- idKey: IdKey
37
- ) => {
38
- type PM = PersistenceModelType<Encoded>
39
- function mapToPersistenceModel(
40
- e: Encoded,
41
- getEtag: (id: string) => string | undefined
42
- ): PM {
43
- return mapTo(e, getEtag(e[idKey]))
44
- }
45
-
46
- function mapReverse(
47
- { _etag, ...e }: PM,
48
- setEtag: (id: string, eTag: string | undefined) => void
49
- ): Encoded {
50
- setEtag((e as any)[idKey], _etag)
51
- return mapFrom(e as unknown as Encoded)
52
- }
53
-
54
- const mkStore = makeStore<Encoded>()(name, schema, mapTo, idKey)
55
-
56
- function make<RInitial = never, E = never, RPublish = never, RCtx = never>(
57
- args: [Evt] extends [never] ? {
58
- schemaContext?: ServiceMap.ServiceMap<RCtx>
59
- makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
60
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
61
- partitionValue?: (e?: Encoded) => string
62
- }
63
- }
64
- : {
65
- schemaContext?: ServiceMap.ServiceMap<RCtx>
66
- publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
67
- makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
68
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
69
- partitionValue?: (e?: Encoded) => string
70
- }
71
- }
72
- ) {
73
- return Effect
74
- .gen(function*() {
75
- const rctx: ServiceMap.ServiceMap<RCtx> = args.schemaContext ?? ServiceMap.empty() as any
76
- const provideRctx = Effect.provide(rctx)
77
- const encodeMany = flow(
78
- S.encodeEffect(S.Array(schema)),
79
- provideRctx,
80
- Effect.withSpan("encodeMany", {}, { captureStackTrace: false })
81
- )
82
- const decode = flow(S.decodeEffect(schema), provideRctx)
83
- const decodeMany = flow(
84
- S.decodeEffect(S.Array(schema)),
85
- provideRctx
86
- )
87
-
88
- const store = yield* mkStore(args.makeInitial, args.config)
89
- const cms = Effect.map(getContextMap.pipe(Effect.orDie), (_) => ({
90
- get: (id: string) => _.get(`${name}.${id}`),
91
- set: (id: string, etag: string | undefined) => _.set(`${name}.${id}`, etag)
92
- }))
93
-
94
- const pub = "publishEvents" in args
95
- ? args.publishEvents
96
- : () => Effect.void
97
- const changeFeed = yield* PubSub.unbounded<[T[], "save" | "remove"]>()
98
-
99
- const allE = cms
100
- .pipe(Effect.flatMap((cm) => Effect.map(store.all, (_) => _.map((_) => mapReverse(_, cm.set)))))
101
-
102
- const all = Effect
103
- .flatMap(
104
- allE,
105
- (_) => decodeMany(_).pipe(Effect.orDie)
106
- )
107
- .pipe(Effect.map((_) => _ as T[]))
108
-
109
- const fieldsSchema = schema as unknown as { fields: any }
110
- // assumes the id field never needs a service...
111
- const i = ("fields" in fieldsSchema ? S.Struct(fieldsSchema["fields"]) as unknown as typeof schema : schema)
112
- .pipe((_) => {
113
- let ast = _.ast
114
- if (ast._tag === "Declaration") ast = ast.typeParameters[0]!
115
-
116
- // In v4, to get the encoded (from) side of a schema, use SchemaAST.toEncoded
117
- const pickIdFromAst = (a: SchemaAST.AST) => {
118
- const encoded = SchemaAST.toEncoded(a)
119
- if (SchemaAST.isObjects(encoded)) {
120
- const field = encoded.propertySignatures.find((_) => _.name === idKey)
121
- if (field) {
122
- return S.Struct({ [idKey]: S.make(field.type) }) as unknown as Codec<T, Encoded>
123
- }
124
- }
125
- return S.make(a) as unknown as Codec<T, Encoded>
126
- }
127
-
128
- return ast._tag === "Union"
129
- // we need to get the Objects (TypeLiteral), in case of class it has encoding chain...
130
- ? S.Union(
131
- ast.types.map((_) => pickIdFromAst(_))
132
- )
133
- : pickIdFromAst(ast)
134
- })
135
- const encodeId = flow(S.encodeEffect(i), provideRctx)
136
- const encodeIdOnly = (id: string) =>
137
- encodeId({ [idKey]: id } as any).pipe(
138
- Effect.map((_: Record<string, unknown>) => _[idKey as string] as Encoded[IdKey])
139
- )
140
- const findEId = Effect.fnUntraced(function*(id: Encoded[IdKey]) {
141
- yield* Effect.annotateCurrentSpan({ itemId: id })
142
-
143
- return yield* Effect.flatMap(
144
- store.find(id),
145
- (item) =>
146
- Effect.gen(function*() {
147
- const { set } = yield* cms
148
- return item.pipe(Option.map((_) => mapReverse(_, set)))
149
- })
150
- )
151
- })
152
- // TODO: select the particular field, instead of as struct
153
- const findE = Effect.fnUntraced(function*(id: T[IdKey]) {
154
- yield* Effect.annotateCurrentSpan({ itemId: id })
155
-
156
- return yield* pipe(
157
- encodeId({ [idKey]: id } as any),
158
- Effect.orDie,
159
- Effect.map((_) => (_ as any)[idKey]),
160
- Effect.flatMap(findEId)
161
- )
162
- })
163
-
164
- const find = Effect.fn("find")(function*(id: T[IdKey]) {
165
- yield* Effect.annotateCurrentSpan({ itemId: id })
166
-
167
- return yield* flatMapOption(findE(id), (_) => Effect.orDie(decode(_)))
168
- })
169
-
170
- const saveAllE = (a: Iterable<Encoded>) =>
171
- flatMapOption(
172
- Effect
173
- .sync(() => toNonEmptyArray([...a])),
174
- (a) =>
175
- Effect.gen(function*() {
176
- const { get, set } = yield* cms
177
- const items = a.map((_) => mapToPersistenceModel(_, get))
178
- const ret = yield* store.batchSet(items)
179
- ret.forEach((_) => set(_[idKey], _._etag))
180
- })
181
- )
182
- .pipe(Effect.asVoid)
183
-
184
- const saveAll = (a: Iterable<T>) =>
185
- encodeMany(Array.fromIterable(a))
186
- .pipe(
187
- Effect.orDie,
188
- Effect.andThen(saveAllE)
189
- )
190
-
191
- const saveAndPublish = Effect.fn("saveAndPublish")(function*(items: Iterable<T>, events: Iterable<Evt> = []) {
192
- const it = Chunk.fromIterable(items)
193
- const evts = [...events]
194
- yield* Effect.annotateCurrentSpan({ itemIds: [...Chunk.map(it, (_) => _[idKey])], events: evts.length })
195
- return yield* saveAll(it)
196
- .pipe(
197
- Effect.andThen(Effect.sync(() => toNonEmptyArray(evts))),
198
- // TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
199
- (_) => flatMapOption(_, pub),
200
- Effect.andThen(PubSub.publish(changeFeed, [Chunk.toArray(it), "save"] as [T[], "save" | "remove"])),
201
- Effect.asVoid
202
- )
203
- })
204
-
205
- const removeAndPublish = Effect.fn("removeAndPublish")(function*(a: Iterable<T>, events: Iterable<Evt> = []) {
206
- const { set } = yield* cms
207
- const it = [...a]
208
- const evts = [...events]
209
- yield* Effect.annotateCurrentSpan({ itemIds: it.map((_) => _[idKey]), eventCount: evts.length })
210
- const items = yield* encodeMany(it).pipe(Effect.orDie)
211
- if (Array.isReadonlyArrayNonEmpty(items)) {
212
- yield* store.batchRemove(
213
- items.map((_) => (_[idKey])),
214
- args.config?.partitionValue?.(items[0])
215
- )
216
- for (const e of items) {
217
- set(e[idKey], undefined)
218
- }
219
- yield* Effect
220
- .sync(() => toNonEmptyArray(evts))
221
- // TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
222
- .pipe((_) => flatMapOption(_, pub))
223
-
224
- yield* PubSub.publish(changeFeed, [it, "remove"] as [T[], "save" | "remove"])
225
- }
226
- })
227
-
228
- const removeById = Effect.fn("removeById")(function*(...ids: readonly T[IdKey][]) {
229
- if (!Array.isReadonlyArrayNonEmpty(ids)) {
230
- return
231
- }
232
- const { set } = yield* cms
233
- const eids = yield* Effect.forEach(ids, (_) => encodeIdOnly(_ as any)).pipe(Effect.orDie)
234
- yield* Effect.annotateCurrentSpan({ itemIds: eids })
235
- yield* store.batchRemove(eids)
236
- for (const id of eids) {
237
- set(id, undefined)
238
- }
239
- yield* PubSub.publish(changeFeed, [[], "remove"] as [T[], "save" | "remove"])
240
- })
241
-
242
- const parseMany = (items: readonly PM[]) =>
243
- Effect
244
- .flatMap(cms, (cm) =>
245
- decodeMany(items.map((_) => mapReverse(_, cm.set)))
246
- .pipe(Effect.orDie, Effect.withSpan("parseMany", {}, { captureStackTrace: false })))
247
- const parseMany2 = <A, R>(
248
- items: readonly PM[],
249
- schema: S.Codec<A, Encoded, R>
250
- ) =>
251
- Effect
252
- .flatMap(cms, (cm) =>
253
- S
254
- .decodeEffect(S.Array(schema))(
255
- items.map((_) => mapReverse(_, cm.set))
256
- )
257
- .pipe(Effect.orDie, Effect.withSpan("parseMany2", {}, { captureStackTrace: false })))
258
- const filter = <U extends keyof Encoded = keyof Encoded>(args: FilterArgs<Encoded, U>) =>
259
- store
260
- .filter(
261
- // always enforce id and _etag because they are system fields, required for etag tracking etc
262
- {
263
- ...args,
264
- select: args.select
265
- ? dedupe([...args.select, idKey, "_etag" as any])
266
- : undefined
267
- } as typeof args
268
- )
269
- .pipe(
270
- Effect.tap((items) =>
271
- Effect.map(cms, ({ set }) => items.forEach((_) => set((_ as Encoded)[idKey], (_ as PM)._etag)))
272
- )
273
- )
274
-
275
- // TODO: For raw we should use S.from, and drop the R...
276
- const query: {
277
- <A, R, From extends FieldValues>(
278
- q: Q.QueryProjection<Encoded extends From ? From : never, A, R>
279
- ): Effect.Effect<readonly A[], S.SchemaError, R>
280
- <A, R, EncodedRefined extends Encoded = Encoded>(
281
- q: Q.QAll<NoInfer<Encoded>, NoInfer<EncodedRefined>, A, R>
282
- ): Effect.Effect<readonly A[], never, R>
283
- } = (<A, R, EncodedRefined extends Encoded = Encoded>(q: Q.QAll<Encoded, EncodedRefined, A, R>) => {
284
- const a = Q.toFilter(q)
285
- const eff = a.mode === "project"
286
- ? filter(a)
287
- // TODO: mapFrom but need to support per field and dependencies
288
- .pipe(
289
- Effect.andThen(flow(S.decodeEffect(S.Array(a.schema ?? schema)), provideRctx))
290
- )
291
- : a.mode === "collect"
292
- ? filter(a)
293
- // TODO: mapFrom but need to support per field and dependencies
294
- .pipe(
295
- Effect.flatMap(flow(
296
- S.decodeEffect(S.Array(a.schema)),
297
- Effect.map(Array.getSomes),
298
- provideRctx
299
- ))
300
- )
301
- : Effect.flatMap(
302
- filter(a),
303
- (_) =>
304
- Unify.unify(
305
- a.schema
306
- // TODO: partial may not match?
307
- ? parseMany2(_ as any, a.schema as any)
308
- : parseMany(_ as any)
309
- )
310
- )
311
- return pipe(
312
- a.ttype === "one"
313
- ? Effect.flatMap(
314
- eff,
315
- flow(
316
- Array.head,
317
- Option.match({
318
- onNone: () => Effect.fail(new NotFoundError({ id: "query", /* TODO */ type: name })),
319
- onSome: Effect.succeed
320
- })
321
- )
322
- )
323
- : a.ttype === "count"
324
- ? Effect
325
- .map(eff, (_) => NonNegativeInt(_.length))
326
- .pipe(Effect.catchTag("SchemaError", (e) => Effect.die(e)))
327
- : eff,
328
- Effect.withSpan("Repository.query [effect-app/infra]", {
329
- attributes: {
330
- "repository.model_name": name,
331
- query: { ...a, schema: a.schema ? "__SCHEMA__" : a.schema, filter: a.filter }
332
- }
333
- }, { captureStackTrace: false })
334
- )
335
- }) as any
336
-
337
- const validateSample = Effect.fn("validateSample")(function*(options?: {
338
- percentage?: number
339
- maxItems?: number
340
- }) {
341
- const percentage = options?.percentage ?? 0.1 // default 10%
342
- const maxItems = options?.maxItems
343
-
344
- // 1. get all IDs with projection (bypasses main schema decode)
345
- const allIds = yield* store.filter({
346
- t: null as unknown as Encoded,
347
- select: [idKey as keyof Encoded]
348
- })
349
-
350
- // 2. random subset
351
- const shuffled = [...allIds].sort(() => Math.random() - 0.5)
352
- const sampleSize = Math.min(
353
- maxItems ?? Infinity,
354
- Math.ceil(allIds.length * percentage)
355
- )
356
- const sample = shuffled.slice(0, sampleSize)
357
-
358
- // 3. validate each item
359
- const errors: ValidationError[] = []
360
-
361
- for (const item of sample) {
362
- const id = item[idKey]
363
- const rawResult = yield* store.find(id)
364
-
365
- if (Option.isNone(rawResult)) continue
366
-
367
- const rawData = rawResult.value as Encoded
368
- const jitMResult = mapFrom(rawData) // apply jitM
369
-
370
- const decodeResult = yield* S.decodeEffect(schema)(jitMResult).pipe(
371
- Effect.result,
372
- provideRctx
373
- )
374
-
375
- if (Result.isFailure(decodeResult)) {
376
- errors.push(
377
- new ValidationError({
378
- id,
379
- rawData,
380
- jitMResult,
381
- error: decodeResult.failure
382
- })
383
- )
384
- }
385
- }
386
-
387
- return new ValidationResult({
388
- total: NonNegativeInt(allIds.length),
389
- sampled: NonNegativeInt(sample.length),
390
- valid: NonNegativeInt(sample.length - errors.length),
391
- errors
392
- })
393
- })
394
-
395
- const r = {
396
- changeFeed,
397
- itemType: name,
398
- idKey,
399
- find,
400
- all,
401
- saveAndPublish,
402
- removeAndPublish,
403
- removeById,
404
- validateSample,
405
- queryRaw<A, Out, QR>(schema: S.Codec<A, Out, QR>, q: Q.RawQuery<Encoded, Out>) {
406
- const dec = S.decodeEffect(S.Array(schema))
407
- return store.queryRaw(q).pipe(Effect.flatMap(dec))
408
- },
409
- query(q: any) {
410
- // eslint-disable-next-line prefer-rest-params
411
- return query(typeof q === "function" ? Pipeable.pipeArguments(Q.make(), arguments) : q) as any
412
- },
413
- /**
414
- * @internal
415
- */
416
- mapped: <A, R>(schema: S.Codec<A, any, R>) => {
417
- const dec = S.decodeEffect(schema)
418
- const encMany = S.encodeEffect(S.Array(schema))
419
- const decMany = S.decodeEffect(S.Array(schema))
420
- return {
421
- all: allE.pipe(
422
- Effect.flatMap(decMany),
423
- Effect.map((_) => _ as any[])
424
- ),
425
- find: (id: T[IdKey]) => flatMapOption(findE(id), dec),
426
- // query: (q: any) => {
427
- // const a = Q.toFilter(q)
428
-
429
- // return filter(a)
430
- // .pipe(
431
- // Effect.flatMap(decMany),
432
- // Effect.map((_) => _ as any[]),
433
- // Effect.withSpan("Repository.mapped.query [effect-app/infra]", {
434
- // captureStackTrace: false,
435
- // attributes: {
436
- // "repository.model_name": name,
437
- // query: { ...a, schema: a.schema ? "__SCHEMA__" : a.schema, filter: a.filter.build() }
438
- // }
439
- // })
440
- // )
441
- // },
442
- save: (...xes: any[]) =>
443
- Effect.flatMap(encMany(xes), (_) => saveAllE(_)).pipe(
444
- Effect.withSpan("mapped.save", {}, { captureStackTrace: false })
445
- )
446
- }
447
- }
448
- }
449
- return r as Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<R, RCtx>, RPublish>
450
- })
451
- .pipe(Effect
452
- // .withSpan("Repository.make [effect-app/infra]", { attributes: { "repository.model_name": name } })
453
- .withLogSpan("Repository.make: " + name))
454
- }
455
-
456
- return {
457
- make,
458
- Q: Q.make<Encoded>()
459
- }
460
- }
461
- }
462
-
463
- const pluralize = (s: string) =>
464
- s.endsWith("s")
465
- ? s + "es"
466
- : s.endsWith("y")
467
- ? s.substring(0, s.length - 1) + "ies"
468
- : s + "s"
469
-
470
- export function makeStore<Encoded extends FieldValues>() {
471
- return <
472
- ItemType extends string,
473
- R,
474
- E,
475
- T,
476
- IdKey extends keyof Encoded
477
- >(
478
- name: ItemType,
479
- schema: S.Codec<T, E, R>,
480
- mapTo: (e: E, etag: string | undefined) => Encoded,
481
- idKey: IdKey
482
- ) => {
483
- function makeStore<RInitial = never, EInitial = never>(
484
- makeInitial?: Effect.Effect<readonly T[], EInitial, RInitial>,
485
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
486
- partitionValue?: (e?: Encoded) => string
487
- }
488
- ) {
489
- function encodeToEncoded() {
490
- const getEtag = () => undefined
491
- return (t: T) =>
492
- S.encodeEffect(schema)(t).pipe(
493
- Effect.orDie,
494
- Effect.map((_) => mapToPersistenceModel(_, getEtag))
495
- )
496
- }
497
-
498
- function mapToPersistenceModel(
499
- e: E,
500
- getEtag: (id: string) => string | undefined
501
- ): Encoded {
502
- return mapTo(e, getEtag((e as any)[idKey] as string))
503
- }
504
-
505
- return Effect.gen(function*() {
506
- const { make } = yield* StoreMaker
507
-
508
- const store = yield* make<IdKey, Encoded, RInitial | R, EInitial>(
509
- pluralize(name),
510
- idKey,
511
- makeInitial
512
- ? makeInitial
513
- .pipe(
514
- Effect.flatMap(Effect.forEach(encodeToEncoded())),
515
- setupRequestContextFromCurrent("Repository.makeInitial [effect-app/infra]", {
516
- attributes: { "repository.model_name": name }
517
- })
518
- )
519
- : undefined,
520
- {
521
- ...config,
522
- partitionValue: config?.partitionValue
523
- ?? ((_) => "primary") /*(isIntegrationEvent(r) ? r.companyId : r.id*/
524
- }
525
- )
526
-
527
- return store
528
- })
529
- }
530
-
531
- return makeStore
532
- }
533
- }
534
-
535
- export interface Repos<
536
- T,
537
- Encoded extends { id: string },
538
- RSchema,
539
- Evt,
540
- ItemType extends string,
541
- IdKey extends keyof T,
542
- RPublish
543
- > {
544
- make<RInitial = never, E = never, R2 = never>(
545
- args: [Evt] extends [never] ? {
546
- makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
547
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
548
- partitionValue?: (e?: Encoded) => string
549
- }
550
- }
551
- : {
552
- publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, R2>
553
- makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
554
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
555
- partitionValue?: (e?: Encoded) => string
556
- }
557
- }
558
- ): Effect.Effect<Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish>, E, StoreMaker | RInitial | R2>
559
- makeWith<Out, RInitial = never, E = never, R2 = never>(
560
- args: [Evt] extends [never] ? {
561
- makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
562
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
563
- partitionValue?: (e?: Encoded) => string
564
- }
565
- }
566
- : {
567
- publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, R2>
568
- makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
569
- config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
570
- partitionValue?: (e?: Encoded) => string
571
- }
572
- },
573
- f: (r: Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish>) => Out
574
- ): Effect.Effect<Out, E, StoreMaker | RInitial | R2>
575
- readonly Q: ReturnType<typeof Q.make<Encoded>>
576
- readonly type: Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish>
577
- }
@@ -1,27 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
- import type { Effect, Option, S } from "effect-app"
4
- import type { OptimisticConcurrencyException } from "effect-app/client/errors"
5
-
6
- export interface Mapped1<A, IdKey extends keyof A, R> {
7
- all: Effect.Effect<A[], S.SchemaError, R>
8
- save: (...xes: readonly A[]) => Effect.Effect<void, OptimisticConcurrencyException | S.SchemaError, R>
9
- find: (id: A[IdKey]) => Effect.Effect<Option.Option<A>, S.SchemaError, R>
10
- }
11
-
12
- // TODO: auto use project, and select fields from the From side of schema only
13
- export interface Mapped2<A, R> {
14
- all: Effect.Effect<A[], S.SchemaError, R>
15
- }
16
-
17
- export interface Mapped<Encoded> {
18
- <A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Mapped1<A, IdKey, R>
19
- // TODO: constrain on Encoded2 having to contain only fields that fit Encoded
20
- <A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Mapped2<A, R>
21
- }
22
-
23
- export interface MM<Repo, Encoded> {
24
- <A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Effect.Effect<Mapped1<A, IdKey, R>, never, Repo>
25
- // TODO: constrain on Encoded2 having to contain only fields that fit Encoded
26
- <A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Effect.Effect<Mapped2<A, R>, never, Repo>
27
- }