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

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