@effect-app/infra 4.0.0-beta.32 → 4.0.0-beta.321

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 (480) hide show
  1. package/CHANGELOG.md +2469 -0
  2. package/_check.sh +1 -1
  3. package/dist/CUPS.d.ts +29 -10
  4. package/dist/CUPS.d.ts.map +1 -1
  5. package/dist/CUPS.js +36 -15
  6. package/dist/ClusterCosmos.d.ts +70 -0
  7. package/dist/ClusterCosmos.d.ts.map +1 -0
  8. package/dist/ClusterCosmos.js +576 -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/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 +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 +12 -8
  22. package/dist/MainFiberSet.d.ts.map +1 -1
  23. package/dist/MainFiberSet.js +23 -7
  24. package/dist/QueueMaker/errors.d.ts +4 -2
  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 +31 -42
  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 +392 -256
  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 +87 -42
  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 +346 -76
  44. package/dist/Store/SQL/Pg.d.ts +4 -0
  45. package/dist/Store/SQL/Pg.d.ts.map +1 -0
  46. package/dist/Store/SQL/Pg.js +257 -0
  47. package/dist/Store/SQL/query.d.ts +53 -0
  48. package/dist/Store/SQL/query.d.ts.map +1 -0
  49. package/dist/Store/SQL/query.js +656 -0
  50. package/dist/Store/SQL.d.ts +21 -0
  51. package/dist/Store/SQL.d.ts.map +1 -0
  52. package/dist/Store/SQL.js +478 -0
  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 +18 -5
  59. package/dist/Store/jsonDocument.d.ts +13 -0
  60. package/dist/Store/jsonDocument.d.ts.map +1 -0
  61. package/dist/Store/jsonDocument.js +31 -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 +29 -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 +16 -4
  74. package/dist/codec.d.ts.map +1 -0
  75. package/dist/codec.js +5 -0
  76. package/dist/{adapters/cosmos-client.d.ts → cosmos-client.d.ts} +4 -2
  77. package/dist/cosmos-client.d.ts.map +1 -0
  78. package/dist/cosmos-client.js +11 -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/internal/health.d.ts.map +1 -0
  98. package/dist/internal/health.js +5 -0
  99. package/dist/{api/layerUtils.d.ts → layerUtils.d.ts} +14 -6
  100. package/dist/layerUtils.d.ts.map +1 -0
  101. package/dist/layerUtils.js +17 -0
  102. package/dist/logger/jsonLogger.d.ts +1 -1
  103. package/dist/logger/jsonLogger.d.ts.map +1 -1
  104. package/dist/logger/jsonLogger.js +5 -3
  105. package/dist/logger/logFmtLogger.d.ts +1 -1
  106. package/dist/logger/logFmtLogger.d.ts.map +1 -1
  107. package/dist/logger/logFmtLogger.js +3 -3
  108. package/dist/logger/shared.d.ts +2 -2
  109. package/dist/logger/shared.d.ts.map +1 -1
  110. package/dist/logger/shared.js +6 -6
  111. package/dist/logger.d.ts +4 -4
  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} +3 -2
  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} +5 -2
  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 +4 -3
  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/routing/middleware/middleware.d.ts +48 -0
  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 +49 -41
  157. package/package.json +38 -352
  158. package/src/CUPS.ts +54 -15
  159. package/src/ClusterCosmos.ts +1154 -0
  160. package/src/ClusterServiceBus.ts +244 -0
  161. package/src/{api/ContextProvider.ts → ContextProvider.ts} +20 -17
  162. package/src/Emailer/Sendgrid.ts +83 -60
  163. package/src/Emailer/fake.ts +4 -4
  164. package/src/MainFiberSet.ts +32 -13
  165. package/src/QueueMaker/errors.ts +3 -1
  166. package/src/{adapters/SQL → SQL}/Model.ts +42 -41
  167. package/src/SQL.ts +1 -0
  168. package/src/Store/Cosmos/query.ts +275 -55
  169. package/src/Store/Cosmos.ts +537 -367
  170. package/src/Store/Disk.ts +137 -74
  171. package/src/Store/Memory.ts +402 -113
  172. package/src/Store/SQL/Pg.ts +402 -0
  173. package/src/Store/SQL/query.ts +748 -0
  174. package/src/Store/SQL.ts +786 -0
  175. package/src/Store/codeFilter.ts +78 -28
  176. package/src/Store/index.ts +25 -10
  177. package/src/Store/jsonDocument.ts +43 -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 +20 -5
  182. package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
  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 +22 -13
  189. package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
  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} +4 -2
  195. package/src/otel.ts +177 -0
  196. package/src/rateLimit.ts +35 -24
  197. package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
  198. package/src/{api/reportError.ts → reportError.ts} +3 -2
  199. package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
  200. package/src/routing/middleware/middleware.ts +196 -0
  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/auth.test.ts +101 -0
  208. package/test/cluster-cosmos.test.ts +612 -0
  209. package/test/cluster-servicebus.test.ts +180 -0
  210. package/test/cluster-sqlite.test.ts +207 -0
  211. package/test/contextProvider.test.ts +15 -12
  212. package/test/controller.test.ts +28 -32
  213. package/test/cosmos-query.test.ts +323 -0
  214. package/test/dist/auth.test.d.ts.map +1 -0
  215. package/test/dist/cluster-cosmos.test.d.ts.map +1 -0
  216. package/test/dist/cluster-servicebus.test.d.ts.map +1 -0
  217. package/test/dist/cluster-sqlite.test.d.ts.map +1 -0
  218. package/test/dist/contextProvider.test.d.ts.map +1 -1
  219. package/test/dist/controller.test.d.ts.map +1 -1
  220. package/test/dist/cosmos-query.test.d.ts.map +1 -0
  221. package/test/dist/fixtures.d.ts +29 -11
  222. package/test/dist/fixtures.d.ts.map +1 -1
  223. package/test/dist/fixtures.js +17 -10
  224. package/test/dist/json-lower.test.d.ts.map +1 -0
  225. package/test/dist/query.test.d.ts.map +1 -1
  226. package/test/dist/rawQuery.test.d.ts.map +1 -1
  227. package/test/dist/repository-ext.test.d.ts.map +1 -0
  228. package/test/dist/requires.test.d.ts.map +1 -1
  229. package/test/dist/router-generator.test.d.ts.map +1 -0
  230. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  231. package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
  232. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  233. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  234. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  235. package/test/dist/sql-store.test.d.ts.map +1 -0
  236. package/test/dist/workflow-engine-cosmos.test.d.ts.map +1 -0
  237. package/test/dist/workflow-engine-sqlite.test.d.ts.map +1 -0
  238. package/test/fixtures.ts +16 -9
  239. package/test/json-lower.test.ts +115 -0
  240. package/test/layerUtils.test.ts +2 -2
  241. package/test/query.test.ts +1384 -46
  242. package/test/rawQuery.test.ts +340 -22
  243. package/test/repository-ext.test.ts +456 -0
  244. package/test/requires.test.ts +10 -5
  245. package/test/router-generator.test.ts +187 -0
  246. package/test/routing-interruptibility.test.ts +66 -0
  247. package/test/rpc-context-map-streaming.test.ts +265 -0
  248. package/test/rpc-e2e-invalidation.test.ts +421 -0
  249. package/test/rpc-multi-middleware.test.ts +85 -10
  250. package/test/rpc-stream-fullstack.test.ts +307 -0
  251. package/test/sql-store.test.ts +1905 -0
  252. package/test/validateSample.test.ts +26 -14
  253. package/test/workflow-engine-cosmos.test.ts +345 -0
  254. package/test/workflow-engine-sqlite.test.ts +297 -0
  255. package/tsconfig.examples.json +1 -1
  256. package/tsconfig.json +9 -2
  257. package/tsconfig.src.json +35 -35
  258. package/tsconfig.test.json +2 -2
  259. package/dist/Emailer/service.d.ts +0 -55
  260. package/dist/Emailer/service.d.ts.map +0 -1
  261. package/dist/Emailer/service.js +0 -6
  262. package/dist/Emailer.d.ts +0 -2
  263. package/dist/Emailer.d.ts.map +0 -1
  264. package/dist/Emailer.js +0 -2
  265. package/dist/Model/Repository/ext.d.ts +0 -41
  266. package/dist/Model/Repository/ext.d.ts.map +0 -1
  267. package/dist/Model/Repository/ext.js +0 -65
  268. package/dist/Model/Repository/internal/internal.d.ts +0 -59
  269. package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
  270. package/dist/Model/Repository/internal/internal.js +0 -316
  271. package/dist/Model/Repository/legacy.d.ts +0 -19
  272. package/dist/Model/Repository/legacy.d.ts.map +0 -1
  273. package/dist/Model/Repository/legacy.js +0 -2
  274. package/dist/Model/Repository/makeRepo.d.ts +0 -49
  275. package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
  276. package/dist/Model/Repository/makeRepo.js +0 -24
  277. package/dist/Model/Repository/service.d.ts +0 -89
  278. package/dist/Model/Repository/service.d.ts.map +0 -1
  279. package/dist/Model/Repository/service.js +0 -2
  280. package/dist/Model/Repository/validation.d.ts +0 -42
  281. package/dist/Model/Repository/validation.d.ts.map +0 -1
  282. package/dist/Model/Repository/validation.js +0 -32
  283. package/dist/Model/Repository.d.ts +0 -6
  284. package/dist/Model/Repository.d.ts.map +0 -1
  285. package/dist/Model/Repository.js +0 -6
  286. package/dist/Model/dsl.d.ts +0 -32
  287. package/dist/Model/dsl.d.ts.map +0 -1
  288. package/dist/Model/dsl.js +0 -44
  289. package/dist/Model/filter/filterApi.d.ts +0 -30
  290. package/dist/Model/filter/filterApi.d.ts.map +0 -1
  291. package/dist/Model/filter/filterApi.js +0 -2
  292. package/dist/Model/filter/types/errors.d.ts +0 -29
  293. package/dist/Model/filter/types/errors.d.ts.map +0 -1
  294. package/dist/Model/filter/types/errors.js +0 -2
  295. package/dist/Model/filter/types/fields.d.ts +0 -15
  296. package/dist/Model/filter/types/fields.d.ts.map +0 -1
  297. package/dist/Model/filter/types/fields.js +0 -2
  298. package/dist/Model/filter/types/path/common.d.ts +0 -316
  299. package/dist/Model/filter/types/path/common.d.ts.map +0 -1
  300. package/dist/Model/filter/types/path/common.js +0 -2
  301. package/dist/Model/filter/types/path/eager.d.ts +0 -95
  302. package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
  303. package/dist/Model/filter/types/path/eager.js +0 -31
  304. package/dist/Model/filter/types/path/index.d.ts +0 -4
  305. package/dist/Model/filter/types/path/index.d.ts.map +0 -1
  306. package/dist/Model/filter/types/path/index.js +0 -3
  307. package/dist/Model/filter/types/utils.d.ts +0 -79
  308. package/dist/Model/filter/types/utils.d.ts.map +0 -1
  309. package/dist/Model/filter/types/utils.js +0 -2
  310. package/dist/Model/filter/types/validator.d.ts +0 -30
  311. package/dist/Model/filter/types/validator.d.ts.map +0 -1
  312. package/dist/Model/filter/types/validator.js +0 -2
  313. package/dist/Model/filter/types.d.ts +0 -5
  314. package/dist/Model/filter/types.d.ts.map +0 -1
  315. package/dist/Model/filter/types.js +0 -7
  316. package/dist/Model/query/dsl.d.ts +0 -248
  317. package/dist/Model/query/dsl.d.ts.map +0 -1
  318. package/dist/Model/query/dsl.js +0 -104
  319. package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
  320. package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
  321. package/dist/Model/query/new-kid-interpreter.js +0 -165
  322. package/dist/Model/query.d.ts +0 -15
  323. package/dist/Model/query.d.ts.map +0 -1
  324. package/dist/Model/query.js +0 -3
  325. package/dist/Model.d.ts +0 -4
  326. package/dist/Model.d.ts.map +0 -1
  327. package/dist/Model.js +0 -4
  328. package/dist/Operations.d.ts +0 -55
  329. package/dist/Operations.d.ts.map +0 -1
  330. package/dist/Operations.js +0 -102
  331. package/dist/OperationsRepo.d.ts +0 -41
  332. package/dist/OperationsRepo.d.ts.map +0 -1
  333. package/dist/OperationsRepo.js +0 -14
  334. package/dist/QueueMaker/SQLQueue.d.ts +0 -16
  335. package/dist/QueueMaker/SQLQueue.d.ts.map +0 -1
  336. package/dist/QueueMaker/SQLQueue.js +0 -130
  337. package/dist/QueueMaker/memQueue.d.ts +0 -11
  338. package/dist/QueueMaker/memQueue.d.ts.map +0 -1
  339. package/dist/QueueMaker/memQueue.js +0 -76
  340. package/dist/QueueMaker/sbqueue.d.ts +0 -12
  341. package/dist/QueueMaker/sbqueue.d.ts.map +0 -1
  342. package/dist/QueueMaker/sbqueue.js +0 -91
  343. package/dist/QueueMaker/service.d.ts +0 -11
  344. package/dist/QueueMaker/service.d.ts.map +0 -1
  345. package/dist/QueueMaker/service.js +0 -4
  346. package/dist/RequestContext.d.ts +0 -63
  347. package/dist/RequestContext.d.ts.map +0 -1
  348. package/dist/RequestContext.js +0 -49
  349. package/dist/RequestFiberSet.d.ts +0 -36
  350. package/dist/RequestFiberSet.d.ts.map +0 -1
  351. package/dist/RequestFiberSet.js +0 -78
  352. package/dist/Store/ContextMapContainer.d.ts +0 -14
  353. package/dist/Store/ContextMapContainer.d.ts.map +0 -1
  354. package/dist/Store/ContextMapContainer.js +0 -16
  355. package/dist/Store/service.d.ts +0 -108
  356. package/dist/Store/service.d.ts.map +0 -1
  357. package/dist/Store/service.js +0 -71
  358. package/dist/Store.d.ts +0 -2
  359. package/dist/Store.d.ts.map +0 -1
  360. package/dist/Store.js +0 -2
  361. package/dist/adapters/SQL/Model.d.ts.map +0 -1
  362. package/dist/adapters/SQL/Model.js +0 -478
  363. package/dist/adapters/SQL.d.ts.map +0 -1
  364. package/dist/adapters/ServiceBus.d.ts +0 -58
  365. package/dist/adapters/ServiceBus.d.ts.map +0 -1
  366. package/dist/adapters/ServiceBus.js +0 -99
  367. package/dist/adapters/cosmos-client.d.ts.map +0 -1
  368. package/dist/adapters/cosmos-client.js +0 -9
  369. package/dist/adapters/index.d.ts +0 -2
  370. package/dist/adapters/index.d.ts.map +0 -1
  371. package/dist/adapters/index.js +0 -2
  372. package/dist/adapters/logger.d.ts +0 -9
  373. package/dist/adapters/logger.d.ts.map +0 -1
  374. package/dist/adapters/logger.js +0 -3
  375. package/dist/adapters/memQueue.d.ts +0 -13
  376. package/dist/adapters/memQueue.d.ts.map +0 -1
  377. package/dist/adapters/memQueue.js +0 -20
  378. package/dist/adapters/mongo-client.d.ts.map +0 -1
  379. package/dist/adapters/mongo-client.js +0 -13
  380. package/dist/adapters/redis-client.d.ts.map +0 -1
  381. package/dist/adapters/redis-client.js +0 -94
  382. package/dist/api/ContextProvider.d.ts +0 -31
  383. package/dist/api/ContextProvider.d.ts.map +0 -1
  384. package/dist/api/ContextProvider.js +0 -38
  385. package/dist/api/codec.d.ts.map +0 -1
  386. package/dist/api/codec.js +0 -5
  387. package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
  388. package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
  389. package/dist/api/internal/RequestContextMiddleware.js +0 -35
  390. package/dist/api/internal/auth.d.ts +0 -15
  391. package/dist/api/internal/auth.d.ts.map +0 -1
  392. package/dist/api/internal/auth.js +0 -47
  393. package/dist/api/internal/events.d.ts +0 -9
  394. package/dist/api/internal/events.d.ts.map +0 -1
  395. package/dist/api/internal/events.js +0 -42
  396. package/dist/api/internal/health.d.ts.map +0 -1
  397. package/dist/api/internal/health.js +0 -5
  398. package/dist/api/layerUtils.d.ts.map +0 -1
  399. package/dist/api/layerUtils.js +0 -16
  400. package/dist/api/middlewares.d.ts.map +0 -1
  401. package/dist/api/reportError.d.ts.map +0 -1
  402. package/dist/api/reportError.js +0 -27
  403. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
  404. package/dist/api/routing/middleware/middleware.d.ts +0 -9
  405. package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
  406. package/dist/api/routing/middleware/middleware.js +0 -92
  407. package/dist/api/routing/middleware.d.ts.map +0 -1
  408. package/dist/api/routing/schema/jwt.d.ts.map +0 -1
  409. package/dist/api/routing/schema/jwt.js +0 -12
  410. package/dist/api/routing/tsort.d.ts.map +0 -1
  411. package/dist/api/routing/tsort.js +0 -51
  412. package/dist/api/routing/utils.d.ts.map +0 -1
  413. package/dist/api/routing/utils.js +0 -44
  414. package/dist/api/routing.d.ts +0 -138
  415. package/dist/api/routing.d.ts.map +0 -1
  416. package/dist/api/routing.js +0 -166
  417. package/dist/api/setupRequest.d.ts +0 -12
  418. package/dist/api/setupRequest.d.ts.map +0 -1
  419. package/dist/api/setupRequest.js +0 -44
  420. package/dist/api/util.d.ts.map +0 -1
  421. package/dist/api/util.js +0 -14
  422. package/eslint.config.mjs +0 -24
  423. package/src/Emailer/service.ts +0 -52
  424. package/src/Emailer.ts +0 -1
  425. package/src/Model/Repository/ext.ts +0 -283
  426. package/src/Model/Repository/internal/internal.ts +0 -577
  427. package/src/Model/Repository/legacy.ts +0 -27
  428. package/src/Model/Repository/makeRepo.ts +0 -139
  429. package/src/Model/Repository/service.ts +0 -627
  430. package/src/Model/Repository/validation.ts +0 -31
  431. package/src/Model/Repository.ts +0 -5
  432. package/src/Model/dsl.ts +0 -128
  433. package/src/Model/filter/filterApi.ts +0 -60
  434. package/src/Model/filter/types/errors.ts +0 -47
  435. package/src/Model/filter/types/fields.ts +0 -50
  436. package/src/Model/filter/types/path/common.ts +0 -404
  437. package/src/Model/filter/types/path/eager.ts +0 -298
  438. package/src/Model/filter/types/path/index.ts +0 -4
  439. package/src/Model/filter/types/utils.ts +0 -128
  440. package/src/Model/filter/types/validator.ts +0 -46
  441. package/src/Model/filter/types.ts +0 -6
  442. package/src/Model/query/dsl.ts +0 -2110
  443. package/src/Model/query/new-kid-interpreter.ts +0 -210
  444. package/src/Model/query.ts +0 -13
  445. package/src/Model.ts +0 -3
  446. package/src/Operations.ts +0 -235
  447. package/src/OperationsRepo.ts +0 -16
  448. package/src/QueueMaker/SQLQueue.ts +0 -189
  449. package/src/QueueMaker/memQueue.ts +0 -130
  450. package/src/QueueMaker/sbqueue.ts +0 -137
  451. package/src/QueueMaker/service.ts +0 -17
  452. package/src/RequestContext.ts +0 -63
  453. package/src/RequestFiberSet.ts +0 -105
  454. package/src/Store/ContextMapContainer.ts +0 -20
  455. package/src/Store/index.test.ts.bak +0 -112
  456. package/src/Store/service.ts +0 -184
  457. package/src/Store.ts +0 -1
  458. package/src/adapters/SQL.ts +0 -1
  459. package/src/adapters/ServiceBus.ts +0 -209
  460. package/src/adapters/index.ts +0 -0
  461. package/src/adapters/logger.ts +0 -3
  462. package/src/adapters/memQueue.ts +0 -21
  463. package/src/api/internal/auth.ts +0 -68
  464. package/src/api/middlewares.ts +0 -10
  465. package/src/api/routing/middleware/middleware.ts +0 -128
  466. package/src/api/routing/middleware.ts +0 -6
  467. package/src/api/routing.ts +0 -598
  468. package/src/api/setupRequest.ts +0 -84
  469. package/tsconfig.json.bak +0 -12
  470. /package/dist/{adapters/SQL.d.ts → SQL.d.ts} +0 -0
  471. /package/dist/{api/codec.d.ts → codec.d.ts} +0 -0
  472. /package/dist/{api/internal → internal}/health.d.ts +0 -0
  473. /package/dist/{api/middlewares.d.ts → middlewares.d.ts} +0 -0
  474. /package/dist/{api/routing → routing}/schema/jwt.d.ts +0 -0
  475. /package/dist/{api/routing → routing}/tsort.d.ts +0 -0
  476. /package/dist/{api/util.d.ts → util.d.ts} +0 -0
  477. /package/src/{api/codec.ts → codec.ts} +0 -0
  478. /package/src/{api/internal → internal}/health.ts +0 -0
  479. /package/src/{api/routing → routing}/tsort.ts +0 -0
  480. /package/src/{api/util.ts → util.ts} +0 -0
@@ -1,58 +1,107 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
- import { Array, Option } from "effect-app"
4
- import { assertUnreachable, get } from "effect-app/utils"
5
- import type { FilterR, FilterResult } from "../Model/filter/filterApi.js"
6
- import type { FieldValues } from "../Model/filter/types.js"
7
- import type { Filter } from "./service.js"
8
- import { compare, greaterThan, greaterThanExclusive, lowerThan, lowerThanExclusive } from "./utils.js"
3
+ import * as Array from "effect-app/Array"
4
+ import type { FilterR, FilterResult } from "effect-app/Model/filter/filterApi"
5
+ import type { FieldValues } from "effect-app/Model/filter/types"
6
+ import * as Option from "effect-app/Option"
7
+ import type { Filter } from "effect-app/Store"
8
+ import { assertUnreachable } from "effect-app/utils"
9
+ import { compare, get, greaterThan, greaterThanExclusive, lowerThan, lowerThanExclusive, toJsonQueryValue } from "./utils.ts"
9
10
 
10
- const vAsArr = (v: string) => v as unknown as any[]
11
+ const vAsArr = (v: unknown) => toJsonQueryValue(v) as any[]
12
+
13
+ const mapEntries = (value: unknown): readonly [unknown, unknown][] => {
14
+ const json = toJsonQueryValue(value)
15
+ if (!Array.isArray(json)) return []
16
+ return json.filter((entry): entry is [unknown, unknown] => Array.isArray(entry) && entry.length >= 2)
17
+ }
18
+
19
+ const pairEq = (entry: readonly [unknown, unknown], pair: unknown) => {
20
+ const json = toJsonQueryValue(pair)
21
+ return Array.isArray(json) && json.length >= 2 && compare(entry[0], json[0]) && compare(entry[1], json[1])
22
+ }
11
23
 
12
24
  const filterStatement = (x: any, p: FilterR) => {
13
- const k = get(x, p.path)
25
+ const k = toJsonQueryValue(get(x, p.path))
26
+ const v = toJsonQueryValue(p.value)
14
27
  switch (p.op) {
15
28
  case "in":
16
- return p.value.includes(k)
29
+ return (v as unknown[]).includes(k)
17
30
  case "notIn":
18
- return !p.value.includes(k)
31
+ return !(v as unknown[]).includes(k)
19
32
  case "lt":
20
- return lowerThan(k, p.value)
33
+ return lowerThan(k as any, v as any)
21
34
  case "lte":
22
- return lowerThanExclusive(k, p.value)
35
+ return lowerThanExclusive(k as any, v as any)
23
36
  case "gt":
24
- return greaterThan(k, p.value)
37
+ return greaterThan(k as any, v as any)
25
38
  case "gte":
26
- return greaterThanExclusive(k, p.value)
39
+ return greaterThanExclusive(k as any, v as any)
27
40
  case "includes":
28
- return (k as Array<string>).includes(p.value)
41
+ return (k as Array<unknown>).includes(v)
29
42
  case "notIncludes":
30
- return !(k as Array<string>).includes(p.value)
43
+ return !(k as Array<unknown>).includes(v)
31
44
  case "includes-any":
32
- return (vAsArr(p.value)).some((_) => (k as Array<string>)?.includes(_))
45
+ return (vAsArr(p.value)).some((_) => (k as Array<unknown>)?.includes(_))
33
46
  case "notIncludes-any":
34
- return !(vAsArr(p.value)).some((_) => (k as Array<string>)?.includes(_))
47
+ return !(vAsArr(p.value)).some((_) => (k as Array<unknown>)?.includes(_))
35
48
  case "includes-all":
36
- return (vAsArr(p.value)).every((_) => (k as Array<string>)?.includes(_))
49
+ return (vAsArr(p.value)).every((_) => (k as Array<unknown>)?.includes(_))
37
50
  case "notIncludes-all":
38
- return !(vAsArr(p.value)).every((_) => (k as Array<string>)?.includes(_))
51
+ return !(vAsArr(p.value)).every((_) => (k as Array<unknown>)?.includes(_))
52
+ case "hasKey":
53
+ return mapEntries(k).some(([key]) => compare(key, v))
54
+ case "notHasKey":
55
+ return !mapEntries(k).some(([key]) => compare(key, v))
56
+ case "hasValue":
57
+ return mapEntries(k).some(([, val]) => compare(val, v))
58
+ case "notHasValue":
59
+ return !mapEntries(k).some(([, val]) => compare(val, v))
60
+ case "hasKeyValue":
61
+ return mapEntries(k).some((entry) => pairEq(entry, v))
62
+ case "notHasKeyValue":
63
+ return !mapEntries(k).some((entry) => pairEq(entry, v))
64
+ case "hasKey-any":
65
+ return vAsArr(p.value).some((key) => mapEntries(k).some(([k0]) => compare(k0, key)))
66
+ case "notHasKey-any":
67
+ return !vAsArr(p.value).some((key) => mapEntries(k).some(([k0]) => compare(k0, key)))
68
+ case "hasKey-all":
69
+ return vAsArr(p.value).every((key) => mapEntries(k).some(([k0]) => compare(k0, key)))
70
+ case "notHasKey-all":
71
+ return !vAsArr(p.value).every((key) => mapEntries(k).some(([k0]) => compare(k0, key)))
72
+ case "hasValue-any":
73
+ return vAsArr(p.value).some((val) => mapEntries(k).some(([, v0]) => compare(v0, val)))
74
+ case "notHasValue-any":
75
+ return !vAsArr(p.value).some((val) => mapEntries(k).some(([, v0]) => compare(v0, val)))
76
+ case "hasValue-all":
77
+ return vAsArr(p.value).every((val) => mapEntries(k).some(([, v0]) => compare(v0, val)))
78
+ case "notHasValue-all":
79
+ return !vAsArr(p.value).every((val) => mapEntries(k).some(([, v0]) => compare(v0, val)))
80
+ case "hasKeyValue-any":
81
+ return vAsArr(p.value).some((pair) => mapEntries(k).some((entry) => pairEq(entry, pair)))
82
+ case "notHasKeyValue-any":
83
+ return !vAsArr(p.value).some((pair) => mapEntries(k).some((entry) => pairEq(entry, pair)))
84
+ case "hasKeyValue-all":
85
+ return vAsArr(p.value).every((pair) => mapEntries(k).some((entry) => pairEq(entry, pair)))
86
+ case "notHasKeyValue-all":
87
+ return !vAsArr(p.value).every((pair) => mapEntries(k).some((entry) => pairEq(entry, pair)))
39
88
  case "contains":
40
- return (k as string).toLowerCase().includes(p.value.toLowerCase())
89
+ return (k as string).toLowerCase().includes((v as string).toLowerCase())
41
90
  case "endsWith":
42
- return (k as string).toLowerCase().endsWith(p.value.toLowerCase())
91
+ return (k as string).toLowerCase().endsWith((v as string).toLowerCase())
43
92
  case "startsWith":
44
- return (k as string).toLowerCase().startsWith(p.value.toLowerCase())
93
+ return (k as string).toLowerCase().startsWith((v as string).toLowerCase())
45
94
  case "notContains":
46
- return !(k as string).toLowerCase().includes(p.value.toLowerCase())
95
+ return !(k as string).toLowerCase().includes((v as string).toLowerCase())
47
96
  case "notEndsWith":
48
- return !(k as string).toLowerCase().endsWith(p.value.toLowerCase())
97
+ return !(k as string).toLowerCase().endsWith((v as string).toLowerCase())
49
98
  case "notStartsWith":
50
- return !(k as string).toLowerCase().startsWith(p.value.toLowerCase())
99
+ return !(k as string).toLowerCase().startsWith((v as string).toLowerCase())
51
100
  case "neq":
52
- return !compare(k, p.value)
101
+ return !compare(k, v)
53
102
  case "eq":
54
103
  case undefined:
55
- return compare(k, p.value)
104
+ return compare(k, v)
56
105
  default: {
57
106
  return assertUnreachable(p.op)
58
107
  }
@@ -186,6 +235,7 @@ export const codeFilter3_ = <E>(state: readonly FilterResult[], sut: E): boolean
186
235
  const statements: any[] = [] // must be defined here to be used by eval.
187
236
  // always put everything inside a root scope.
188
237
  const s = codeFilter3__([{ t: "where-scope", result: state, relation: "some" }], sut, statements, null, false)
238
+ // oxlint-disable-next-line no-eval
189
239
  return eval(s)
190
240
  }
191
241
 
@@ -1,12 +1,21 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Effect, Layer, Redacted } from "effect-app"
3
- import { CosmosStoreLayer } from "./Cosmos.js"
4
- import { DiskStoreLayer } from "./Disk.js"
5
- import { MemoryStoreLive } from "./Memory.js"
6
- // import { RedisStoreLayer } from "./Redis.js"
7
- import type { StorageConfig } from "./service.js"
2
+ import * as Effect from "effect-app/Effect"
3
+ import * as Layer from "effect-app/Layer"
4
+ import { RepositoryRegistryLive } from "effect-app/Model"
5
+ import type { StorageConfig } from "effect-app/Store"
6
+ import * as Redacted from "effect/Redacted"
7
+ import type { SqlClient } from "effect/unstable/sql"
8
+ import { CosmosStoreLayer } from "./Cosmos.ts"
9
+ import { DiskStoreLayer } from "./Disk.ts"
10
+ import { MemoryStoreLive } from "./Memory.ts"
11
+ // import { RedisStoreLayer } from "./Redis.ts"
12
+ import { SQLiteStoreLayer } from "./SQL.ts"
13
+ import { PgStoreLayer } from "./SQL/Pg.ts"
8
14
 
9
- export function StoreMakerLayer(cfg: StorageConfig) {
15
+ export function StoreMakerLayer(
16
+ cfg: StorageConfig,
17
+ options?: { makeSqlClientLayer?: (namespace: string) => Layer.Layer<SqlClient.SqlClient> }
18
+ ) {
10
19
  return Effect
11
20
  .sync(() => {
12
21
  const storageUrl = Redacted.value(cfg.url)
@@ -19,6 +28,14 @@ export function StoreMakerLayer(cfg: StorageConfig) {
19
28
  console.log("Using disk store at " + dir)
20
29
  return DiskStoreLayer(cfg, dir)
21
30
  }
31
+ if (storageUrl.startsWith("sqlite://")) {
32
+ console.log("Using SQLite store")
33
+ return SQLiteStoreLayer(cfg, options)
34
+ }
35
+ if (storageUrl.startsWith("pg://")) {
36
+ console.log("Using PostgreSQL store")
37
+ return PgStoreLayer(cfg)
38
+ }
22
39
  // if (storageUrl.startsWith("redis://")) {
23
40
  // console.log("Using Redis store")
24
41
  // return RedisStoreLayer(cfg)
@@ -27,7 +44,5 @@ export function StoreMakerLayer(cfg: StorageConfig) {
27
44
  console.log("Using Cosmos DB store")
28
45
  return CosmosStoreLayer(cfg)
29
46
  })
30
- .pipe(Layer.unwrap)
47
+ .pipe(Layer.unwrap, Layer.merge(RepositoryRegistryLive))
31
48
  }
32
-
33
- export * from "./service.js"
@@ -0,0 +1,43 @@
1
+ import type { FieldValues } from "effect-app/Model/filter/types"
2
+ import * as S from "effect-app/Schema"
3
+ import type { PersistenceModelType } from "effect-app/Store"
4
+ import { toJsonQueryValue } from "./utils.ts"
5
+
6
+ export interface JsonDocumentCodec<E extends FieldValues> {
7
+ readonly encode: (doc: PersistenceModelType<E>) => PersistenceModelType<E>
8
+ readonly decode: (doc: PersistenceModelType<E>) => PersistenceModelType<E>
9
+ }
10
+
11
+ const splitEtag = <E extends FieldValues>(doc: PersistenceModelType<E>) => {
12
+ const { _etag, ...rest } = doc
13
+ return { rest: rest as E, _etag }
14
+ }
15
+
16
+ const joinEtag = <E extends FieldValues>(
17
+ rest: E,
18
+ _etag: string | undefined
19
+ ): PersistenceModelType<E> => (_etag === undefined ? rest : { ...rest, _etag })
20
+
21
+ /**
22
+ * Encoded document ↔ JSON document. Prefer `Schema.toCodecJson(toEncoded(schema))`
23
+ * when the store has a schema; otherwise lower Date/Map/Set structurally.
24
+ */
25
+ export const makeJsonDocumentCodec = <E extends FieldValues>(schema?: S.Top): JsonDocumentCodec<E> => {
26
+ if (schema) {
27
+ const codec = S.toCodecJson(S.toEncoded(schema)) as S.Codec<E, S.Json>
28
+ return {
29
+ encode: (doc) => {
30
+ const { rest, _etag } = splitEtag(doc)
31
+ return joinEtag(S.encodeSync(codec)(rest) as E, _etag)
32
+ },
33
+ decode: (doc) => {
34
+ const { rest, _etag } = splitEtag(doc)
35
+ return joinEtag(S.decodeSync(codec)(rest as S.Json), _etag)
36
+ }
37
+ }
38
+ }
39
+ return {
40
+ encode: (doc) => toJsonQueryValue(doc) as PersistenceModelType<E>,
41
+ decode: (doc) => doc
42
+ }
43
+ }
@@ -1,7 +1,283 @@
1
1
  import crypto from "crypto"
2
- import { Effect, Option } from "effect-app"
3
- import { OptimisticConcurrencyException } from "../errors.js"
4
- import type { PersistenceModelType, SupportedValues2 } from "./service.js"
2
+ import * as Effect from "effect-app/Effect"
3
+ import type { FilterResult, Ops } from "effect-app/Model/filter/filterApi"
4
+ import * as Option from "effect-app/Option"
5
+ import * as S from "effect-app/Schema"
6
+ import * as SchemaAST from "effect-app/SchemaAST"
7
+ import type { PersistenceModelType, SupportedValues2 } from "effect-app/Store"
8
+ import { OptimisticConcurrencyException } from "../errors.ts"
9
+
10
+ const dateJson = S.toCodecJson(S.Date)
11
+
12
+ const isPlainObject = (value: unknown): value is Record<string, unknown> => {
13
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false
14
+ if (value instanceof Date || value instanceof Map || value instanceof Set) return false
15
+ const proto = Object.getPrototypeOf(value)
16
+ return proto === Object.prototype || proto === null
17
+ }
18
+
19
+ const unwrapAst = (ast: SchemaAST.AST): SchemaAST.AST => SchemaAST.isSuspend(ast) ? unwrapAst(ast.thunk()) : ast
20
+
21
+ const unionAst = (hits: readonly SchemaAST.AST[]): SchemaAST.AST | undefined => {
22
+ if (hits.length === 0) return undefined
23
+ if (hits.length === 1) return hits[0]
24
+ return S.Union(hits.map((hit) => S.make(hit)) as [S.Top, S.Top, ...Array<S.Top>]).ast
25
+ }
26
+
27
+ const encodedObjects = (ast: SchemaAST.AST): SchemaAST.Objects | undefined => {
28
+ const current = unwrapAst(ast)
29
+ if (SchemaAST.isObjects(current)) return current
30
+ if (SchemaAST.isDeclaration(current)) {
31
+ const encoded = unwrapAst(SchemaAST.toEncoded(current))
32
+ if (SchemaAST.isObjects(encoded)) return encoded
33
+ }
34
+ return undefined
35
+ }
36
+
37
+ const astAtPath = (ast: SchemaAST.AST | undefined, path: readonly string[]): SchemaAST.AST | undefined => {
38
+ if (ast === undefined) return undefined
39
+ if (path.length === 0) return unwrapAst(ast)
40
+ const current = unwrapAst(ast)
41
+ const [head, ...tail] = path
42
+ if (head === undefined) return current
43
+ if (SchemaAST.isUnion(current)) {
44
+ return unionAst(
45
+ current.types.flatMap((member) => {
46
+ const hit = astAtPath(member, path)
47
+ return hit === undefined ? [] : [hit]
48
+ })
49
+ )
50
+ }
51
+ if (head === "-1" || /^\d+$/.test(head)) {
52
+ if (SchemaAST.isArrays(current)) {
53
+ const element = current.rest[0] ?? current.elements[Number(head)] ?? current.elements[0]
54
+ return astAtPath(element, tail)
55
+ }
56
+ if (SchemaAST.isDeclaration(current) && current.typeParameters.length === 1) {
57
+ return astAtPath(current.typeParameters[0], tail)
58
+ }
59
+ return undefined
60
+ }
61
+ const objects = encodedObjects(current)
62
+ if (objects !== undefined) {
63
+ const property = objects.propertySignatures.find((p) => p.name === head)
64
+ return property === undefined ? undefined : astAtPath(property.type, tail)
65
+ }
66
+ return undefined
67
+ }
68
+
69
+ const elementAst = (ast: SchemaAST.AST | undefined): SchemaAST.AST | undefined => {
70
+ if (ast === undefined) return undefined
71
+ const current = unwrapAst(ast)
72
+ if (SchemaAST.isUnion(current)) {
73
+ return unionAst(
74
+ current.types.flatMap((member) => {
75
+ const hit = elementAst(member)
76
+ return hit === undefined ? [] : [hit]
77
+ })
78
+ )
79
+ }
80
+ if (SchemaAST.isArrays(current)) return unwrapAst(current.rest[0] ?? current.elements[0] ?? current)
81
+ if (SchemaAST.isDeclaration(current) && current.typeParameters.length === 1) {
82
+ return unwrapAst(current.typeParameters[0]!)
83
+ }
84
+ return current
85
+ }
86
+
87
+ const mapKeyAst = (ast: SchemaAST.AST | undefined): SchemaAST.AST | undefined => {
88
+ if (ast === undefined) return undefined
89
+ const current = unwrapAst(ast)
90
+ if (SchemaAST.isUnion(current)) {
91
+ return unionAst(
92
+ current.types.flatMap((member) => {
93
+ const hit = mapKeyAst(member)
94
+ return hit === undefined ? [] : [hit]
95
+ })
96
+ )
97
+ }
98
+ if (SchemaAST.isDeclaration(current) && current.typeParameters.length >= 2) {
99
+ return unwrapAst(current.typeParameters[0]!)
100
+ }
101
+ return current
102
+ }
103
+
104
+ const mapValueAst = (ast: SchemaAST.AST | undefined): SchemaAST.AST | undefined => {
105
+ if (ast === undefined) return undefined
106
+ const current = unwrapAst(ast)
107
+ if (SchemaAST.isUnion(current)) {
108
+ return unionAst(
109
+ current.types.flatMap((member) => {
110
+ const hit = mapValueAst(member)
111
+ return hit === undefined ? [] : [hit]
112
+ })
113
+ )
114
+ }
115
+ if (SchemaAST.isDeclaration(current) && current.typeParameters.length >= 2) {
116
+ return unwrapAst(current.typeParameters[1]!)
117
+ }
118
+ return current
119
+ }
120
+
121
+ const asArray = (value: unknown): readonly unknown[] =>
122
+ Array.isArray(value) ? value : value instanceof Set ? [...value] : [value]
123
+
124
+ const encodeJson = (ast: SchemaAST.AST | undefined, value: unknown): unknown => {
125
+ if (ast === undefined) return toJsonQueryValue(value)
126
+ const current = unwrapAst(ast)
127
+ if (isPlainObject(value)) {
128
+ const out: Record<string, unknown> = {}
129
+ for (const [key, child] of Object.entries(value)) {
130
+ out[key] = encodeJson(astAtPath(current, [key]), child)
131
+ }
132
+ return out
133
+ }
134
+ if (Array.isArray(value)) {
135
+ const element = SchemaAST.isArrays(current) || SchemaAST.isUnion(current)
136
+ ? elementAst(current)
137
+ : current
138
+ return value.map((item) => encodeJson(element, item))
139
+ }
140
+ if (value instanceof Set) {
141
+ return [...value].map((item) => encodeJson(elementAst(current), item))
142
+ }
143
+ if (value instanceof Map) {
144
+ return [...value.entries()].map(([k, v]) => [
145
+ encodeJson(mapKeyAst(current), k),
146
+ encodeJson(mapValueAst(current), v)
147
+ ])
148
+ }
149
+ return Effect.runSync(
150
+ S.encodeUnknownEffect(S.toCodecJson(S.make(current)))(value) as Effect.Effect<S.Json>
151
+ )
152
+ }
153
+
154
+ const encodeFilterValue = (fieldAst: SchemaAST.AST | undefined, op: Ops, value: unknown): unknown => {
155
+ if (fieldAst === undefined) return toJsonQueryValue(value)
156
+ if (op === "in" || op === "notIn") {
157
+ return asArray(value).map((item) => encodeJson(fieldAst, item))
158
+ }
159
+ if (
160
+ op === "includes"
161
+ || op === "notIncludes"
162
+ || op === "includes-any"
163
+ || op === "notIncludes-any"
164
+ || op === "includes-all"
165
+ || op === "notIncludes-all"
166
+ ) {
167
+ const element = elementAst(fieldAst)
168
+ return op === "includes" || op === "notIncludes"
169
+ ? encodeJson(element, value)
170
+ : asArray(value).map((item) => encodeJson(element, item))
171
+ }
172
+ if (
173
+ op === "hasKeyValue"
174
+ || op === "notHasKeyValue"
175
+ || op === "hasKeyValue-any"
176
+ || op === "notHasKeyValue-any"
177
+ || op === "hasKeyValue-all"
178
+ || op === "notHasKeyValue-all"
179
+ ) {
180
+ const keyAst = mapKeyAst(fieldAst)
181
+ const valueAst = mapValueAst(fieldAst)
182
+ const pair = (item: unknown) =>
183
+ Array.isArray(item) && item.length >= 2
184
+ ? [encodeJson(keyAst, item[0]), encodeJson(valueAst, item[1])]
185
+ : toJsonQueryValue(item)
186
+ return op === "hasKeyValue" || op === "notHasKeyValue" ? pair(value) : asArray(value).map(pair)
187
+ }
188
+ if (
189
+ op === "hasKey"
190
+ || op === "notHasKey"
191
+ || op === "hasKey-any"
192
+ || op === "notHasKey-any"
193
+ || op === "hasKey-all"
194
+ || op === "notHasKey-all"
195
+ ) {
196
+ const keyAst = mapKeyAst(fieldAst)
197
+ return op === "hasKey" || op === "notHasKey"
198
+ ? encodeJson(keyAst, value)
199
+ : asArray(value).map((item) => encodeJson(keyAst, item))
200
+ }
201
+ if (
202
+ op === "hasValue"
203
+ || op === "notHasValue"
204
+ || op === "hasValue-any"
205
+ || op === "notHasValue-any"
206
+ || op === "hasValue-all"
207
+ || op === "notHasValue-all"
208
+ ) {
209
+ const valueAst = mapValueAst(fieldAst)
210
+ return op === "hasValue" || op === "notHasValue"
211
+ ? encodeJson(valueAst, value)
212
+ : asArray(value).map((item) => encodeJson(valueAst, item))
213
+ }
214
+ return encodeJson(fieldAst, value)
215
+ }
216
+
217
+ /**
218
+ * Lower Date / Map / Set to JSON when no field schema is available.
219
+ * Prefer {@link encodeWithSchema} / {@link jsonifyFilter} with the store schema.
220
+ */
221
+ export function toJsonQueryValue(value: unknown): unknown {
222
+ if (value instanceof Date) {
223
+ return S.encodeSync(dateJson)(value)
224
+ }
225
+ if (value instanceof Map) {
226
+ return [...value.entries()].map(([k, v]) => [toJsonQueryValue(k), toJsonQueryValue(v)])
227
+ }
228
+ if (value instanceof Set) {
229
+ return [...value].map((v) => toJsonQueryValue(v))
230
+ }
231
+ if (Array.isArray(value)) {
232
+ return value.map((v) => toJsonQueryValue(v))
233
+ }
234
+ if (isPlainObject(value)) {
235
+ const out: Record<string, unknown> = {}
236
+ for (const [k, v] of Object.entries(value)) {
237
+ out[k] = toJsonQueryValue(v)
238
+ }
239
+ return out
240
+ }
241
+ if (value !== null && typeof value === "object") {
242
+ const toJSON = (value as { toJSON?: () => unknown }).toJSON
243
+ if (typeof toJSON === "function") {
244
+ return toJsonQueryValue(toJSON.call(value))
245
+ }
246
+ }
247
+ return value
248
+ }
249
+
250
+ export function encodeWithSchema(schema: S.Top | undefined, value: unknown): unknown {
251
+ if (schema === undefined) return toJsonQueryValue(value)
252
+ return encodeJson(SchemaAST.toEncoded(schema.ast), value)
253
+ }
254
+
255
+ export function jsonifyFilter(
256
+ filter: readonly FilterResult[],
257
+ schema?: S.Top
258
+ ): FilterResult[] {
259
+ const ast = schema === undefined ? undefined : SchemaAST.toEncoded(schema.ast)
260
+ return filter.map((r) =>
261
+ r.t === "and-scope" || r.t === "or-scope" || r.t === "where-scope"
262
+ ? { ...r, result: jsonifyFilter(r.result, schema) }
263
+ : { ...r, value: encodeFilterValue(astAtPath(ast, r.path.split(".")), r.op, r.value) }
264
+ )
265
+ }
266
+
267
+ export type JsonLower = {
268
+ readonly toJson: (value: unknown) => unknown
269
+ readonly jsonifyFilter: (filter: readonly FilterResult[]) => FilterResult[]
270
+ }
271
+
272
+ export const makeJsonLower = (config?: { readonly schema?: S.Top }): JsonLower => ({
273
+ toJson: (value) => encodeWithSchema(config?.schema, value),
274
+ jsonifyFilter: (filter) => jsonifyFilter(filter, config?.schema)
275
+ })
276
+
277
+ /** Traverse an object by a dot-separated path string, e.g. `"a.b.c"`. */
278
+ export function get(obj: any, path: string): any {
279
+ return path.split(".").reduce((res: any, key: string) => (res != null ? res[key] : res), obj)
280
+ }
5
281
 
6
282
  export const makeETag = <E extends PersistenceModelType<{}>>(
7
283
  { _etag, ...e }: E
@@ -12,33 +288,34 @@ export const makeETag = <E extends PersistenceModelType<{}>>(
12
288
  _etag: crypto.createHash("sha256").update(JSON.stringify(e)).digest("hex")
13
289
  }) as any
14
290
 
15
- export const makeUpdateETag =
16
- (type: string) =>
17
- <IdKey extends keyof E, E extends PersistenceModelType<{}>>(e: E, idKey: IdKey, current: Option.Option<E>) =>
18
- Effect.gen(function*() {
19
- if (e._etag) {
20
- if (Option.isNone(current)) {
21
- return yield* new OptimisticConcurrencyException({
22
- type,
23
- id: e[idKey] as string,
24
- current: "",
25
- found: e._etag,
26
- code: 409
27
- })
28
- }
29
- }
30
- if (Option.isSome(current) && current.value._etag !== e._etag) {
291
+ export const makeUpdateETag = (type: string) =>
292
+ Effect.fnUntraced(function*<IdKey extends keyof E, E extends PersistenceModelType<{}>>(
293
+ e: E,
294
+ idKey: IdKey,
295
+ current: Option.Option<E>
296
+ ) {
297
+ if (e._etag) {
298
+ if (Option.isNone(current)) {
31
299
  return yield* new OptimisticConcurrencyException({
32
300
  type,
33
- id: current.value[idKey] as string,
34
- current: current.value._etag,
301
+ id: e[idKey] as string,
302
+ current: "",
35
303
  found: e._etag,
36
- code: 412
304
+ code: 409
37
305
  })
38
306
  }
39
- const newE = makeETag(e)
40
- return newE
41
- })
307
+ }
308
+ if (Option.isSome(current) && current.value._etag !== e._etag) {
309
+ return yield* new OptimisticConcurrencyException({
310
+ type,
311
+ id: current.value[idKey] as string,
312
+ current: current.value._etag,
313
+ found: e._etag,
314
+ code: 412
315
+ })
316
+ }
317
+ return makeETag(e)
318
+ })
42
319
 
43
320
  export function lowercaseIfString<T>(val: T) {
44
321
  if (typeof val === "string") {
@@ -48,21 +325,21 @@ export function lowercaseIfString<T>(val: T) {
48
325
  }
49
326
 
50
327
  export function compare(valA: unknown, valB: unknown) {
51
- return valA === valB
328
+ return toJsonQueryValue(valA) === toJsonQueryValue(valB)
52
329
  }
53
330
 
54
331
  export function lowerThan(valA: SupportedValues2, valB: SupportedValues2) {
55
- return valA < valB
332
+ return (toJsonQueryValue(valA) as SupportedValues2) < (toJsonQueryValue(valB) as SupportedValues2)
56
333
  }
57
334
 
58
335
  export function lowerThanExclusive(valA: SupportedValues2, valB: SupportedValues2) {
59
- return valA <= valB
336
+ return (toJsonQueryValue(valA) as SupportedValues2) <= (toJsonQueryValue(valB) as SupportedValues2)
60
337
  }
61
338
 
62
339
  export function greaterThan(valA: SupportedValues2, valB: SupportedValues2) {
63
- return valA > valB
340
+ return (toJsonQueryValue(valA) as SupportedValues2) > (toJsonQueryValue(valB) as SupportedValues2)
64
341
  }
65
342
 
66
343
  export function greaterThanExclusive(valA: SupportedValues2, valB: SupportedValues2) {
67
- return valA >= valB
344
+ return (toJsonQueryValue(valA) as SupportedValues2) >= (toJsonQueryValue(valB) as SupportedValues2)
68
345
  }