@fncts/query 0.0.1

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 (303) hide show
  1. package/Cache/api.d.ts +28 -0
  2. package/Cache/definition.d.ts +15 -0
  3. package/Cache.d.ts +2 -0
  4. package/CompletedRequestMap.d.ts +17 -0
  5. package/DataSource/api.d.ts +38 -0
  6. package/DataSource/definition.d.ts +46 -0
  7. package/DataSource.d.ts +2 -0
  8. package/DataSourceAspect.d.ts +7 -0
  9. package/Described.d.ts +19 -0
  10. package/Query/api/bimap.d.ts +6 -0
  11. package/Query/api/catchAllCause.d.ts +12 -0
  12. package/Query/api/collectAll.d.ts +7 -0
  13. package/Query/api/collectAllBatched.d.ts +7 -0
  14. package/Query/api/collectAllConcurrent.d.ts +7 -0
  15. package/Query/api/defer.d.ts +7 -0
  16. package/Query/api/ensuring.d.ts +6 -0
  17. package/Query/api/environment.d.ts +47 -0
  18. package/Query/api/flatMap.d.ts +11 -0
  19. package/Query/api/foreach.d.ts +7 -0
  20. package/Query/api/foreachBatched.d.ts +7 -0
  21. package/Query/api/foreachConcurrent.d.ts +7 -0
  22. package/Query/api/fromRequest.d.ts +10 -0
  23. package/Query/api/map.d.ts +6 -0
  24. package/Query/api/mapDataSources.d.ts +7 -0
  25. package/Query/api/mapError.d.ts +6 -0
  26. package/Query/api/mapErrorCause.d.ts +7 -0
  27. package/Query/api/mapIO.d.ts +7 -0
  28. package/Query/api/match.d.ts +6 -0
  29. package/Query/api/matchCauseQuery.d.ts +7 -0
  30. package/Query/api/matchQuery.d.ts +6 -0
  31. package/Query/api/orHalt.d.ts +11 -0
  32. package/Query/api/race.d.ts +11 -0
  33. package/Query/api/run.d.ts +18 -0
  34. package/Query/api/timeout.d.ts +26 -0
  35. package/Query/api/zipWith.d.ts +7 -0
  36. package/Query/api/zipWithBatched.d.ts +6 -0
  37. package/Query/api/zipWithConcurrent.d.ts +6 -0
  38. package/Query/api.d.ts +66 -0
  39. package/Query/definition.d.ts +13 -0
  40. package/Query.d.ts +30 -0
  41. package/QueryFailure.d.ts +6 -0
  42. package/Request.d.ts +38 -0
  43. package/TestSpec.d.ts +6 -0
  44. package/_cjs/Cache/api.cjs +56 -0
  45. package/_cjs/Cache/api.cjs.map +1 -0
  46. package/_cjs/Cache/definition.cjs +13 -0
  47. package/_cjs/Cache/definition.cjs.map +1 -0
  48. package/_cjs/Cache.cjs +28 -0
  49. package/_cjs/Cache.cjs.map +1 -0
  50. package/_cjs/CompletedRequestMap.cjs +40 -0
  51. package/_cjs/CompletedRequestMap.cjs.map +1 -0
  52. package/_cjs/DataSource/api.cjs +111 -0
  53. package/_cjs/DataSource/api.cjs.map +1 -0
  54. package/_cjs/DataSource/definition.cjs +76 -0
  55. package/_cjs/DataSource/definition.cjs.map +1 -0
  56. package/_cjs/DataSource.cjs +28 -0
  57. package/_cjs/DataSource.cjs.map +1 -0
  58. package/_cjs/DataSourceAspect.cjs +17 -0
  59. package/_cjs/DataSourceAspect.cjs.map +1 -0
  60. package/_cjs/Described.cjs +32 -0
  61. package/_cjs/Described.cjs.map +1 -0
  62. package/_cjs/Query/api/bimap.cjs +19 -0
  63. package/_cjs/Query/api/bimap.cjs.map +1 -0
  64. package/_cjs/Query/api/catchAllCause.cjs +29 -0
  65. package/_cjs/Query/api/catchAllCause.cjs.map +1 -0
  66. package/_cjs/Query/api/collectAll.cjs +17 -0
  67. package/_cjs/Query/api/collectAll.cjs.map +1 -0
  68. package/_cjs/Query/api/collectAllBatched.cjs +17 -0
  69. package/_cjs/Query/api/collectAllBatched.cjs.map +1 -0
  70. package/_cjs/Query/api/collectAllConcurrent.cjs +17 -0
  71. package/_cjs/Query/api/collectAllConcurrent.cjs.map +1 -0
  72. package/_cjs/Query/api/defer.cjs +18 -0
  73. package/_cjs/Query/api/defer.cjs.map +1 -0
  74. package/_cjs/Query/api/ensuring.cjs +20 -0
  75. package/_cjs/Query/api/ensuring.cjs.map +1 -0
  76. package/_cjs/Query/api/environment.cjs +94 -0
  77. package/_cjs/Query/api/environment.cjs.map +1 -0
  78. package/_cjs/Query/api/flatMap.cjs +35 -0
  79. package/_cjs/Query/api/flatMap.cjs.map +1 -0
  80. package/_cjs/Query/api/foreach.cjs +26 -0
  81. package/_cjs/Query/api/foreach.cjs.map +1 -0
  82. package/_cjs/Query/api/foreachBatched.cjs +26 -0
  83. package/_cjs/Query/api/foreachBatched.cjs.map +1 -0
  84. package/_cjs/Query/api/foreachConcurrent.cjs +19 -0
  85. package/_cjs/Query/api/foreachConcurrent.cjs.map +1 -0
  86. package/_cjs/Query/api/fromRequest.cjs +38 -0
  87. package/_cjs/Query/api/fromRequest.cjs.map +1 -0
  88. package/_cjs/Query/api/map.cjs +21 -0
  89. package/_cjs/Query/api/map.cjs.map +1 -0
  90. package/_cjs/Query/api/mapDataSources.cjs +21 -0
  91. package/_cjs/Query/api/mapDataSources.cjs.map +1 -0
  92. package/_cjs/Query/api/mapError.cjs +19 -0
  93. package/_cjs/Query/api/mapError.cjs.map +1 -0
  94. package/_cjs/Query/api/mapErrorCause.cjs +19 -0
  95. package/_cjs/Query/api/mapErrorCause.cjs.map +1 -0
  96. package/_cjs/Query/api/mapIO.cjs +20 -0
  97. package/_cjs/Query/api/mapIO.cjs.map +1 -0
  98. package/_cjs/Query/api/match.cjs +20 -0
  99. package/_cjs/Query/api/match.cjs.map +1 -0
  100. package/_cjs/Query/api/matchCauseQuery.cjs +26 -0
  101. package/_cjs/Query/api/matchCauseQuery.cjs.map +1 -0
  102. package/_cjs/Query/api/matchQuery.cjs +21 -0
  103. package/_cjs/Query/api/matchQuery.cjs.map +1 -0
  104. package/_cjs/Query/api/orHalt.cjs +29 -0
  105. package/_cjs/Query/api/orHalt.cjs.map +1 -0
  106. package/_cjs/Query/api/race.cjs +41 -0
  107. package/_cjs/Query/api/race.cjs.map +1 -0
  108. package/_cjs/Query/api/run.cjs +49 -0
  109. package/_cjs/Query/api/run.cjs.map +1 -0
  110. package/_cjs/Query/api/timeout.cjs +71 -0
  111. package/_cjs/Query/api/timeout.cjs.map +1 -0
  112. package/_cjs/Query/api/zipWith.cjs +39 -0
  113. package/_cjs/Query/api/zipWith.cjs.map +1 -0
  114. package/_cjs/Query/api/zipWithBatched.cjs +39 -0
  115. package/_cjs/Query/api/zipWithBatched.cjs.map +1 -0
  116. package/_cjs/Query/api/zipWithConcurrent.cjs +39 -0
  117. package/_cjs/Query/api/zipWithConcurrent.cjs.map +1 -0
  118. package/_cjs/Query/api.cjs +99 -0
  119. package/_cjs/Query/api.cjs.map +1 -0
  120. package/_cjs/Query/definition.cjs +22 -0
  121. package/_cjs/Query/definition.cjs.map +1 -0
  122. package/_cjs/Query.cjs +336 -0
  123. package/_cjs/Query.cjs.map +1 -0
  124. package/_cjs/QueryFailure.cjs +15 -0
  125. package/_cjs/QueryFailure.cjs.map +1 -0
  126. package/_cjs/Request.cjs +54 -0
  127. package/_cjs/Request.cjs.map +1 -0
  128. package/_cjs/global.cjs +6 -0
  129. package/_cjs/global.cjs.map +1 -0
  130. package/_cjs/index.cjs +6 -0
  131. package/_cjs/index.cjs.map +1 -0
  132. package/_cjs/internal/BlockedRequest.cjs +30 -0
  133. package/_cjs/internal/BlockedRequest.cjs.map +1 -0
  134. package/_cjs/internal/BlockedRequests.cjs +367 -0
  135. package/_cjs/internal/BlockedRequests.cjs.map +1 -0
  136. package/_cjs/internal/Continue.cjs +292 -0
  137. package/_cjs/internal/Continue.cjs.map +1 -0
  138. package/_cjs/internal/Parallel.cjs +81 -0
  139. package/_cjs/internal/Parallel.cjs.map +1 -0
  140. package/_cjs/internal/Result.cjs +234 -0
  141. package/_cjs/internal/Result.cjs.map +1 -0
  142. package/_cjs/internal/Sequential.cjs +59 -0
  143. package/_cjs/internal/Sequential.cjs.map +1 -0
  144. package/_mjs/Cache/api.mjs +44 -0
  145. package/_mjs/Cache/api.mjs.map +1 -0
  146. package/_mjs/Cache/definition.mjs +6 -0
  147. package/_mjs/Cache/definition.mjs.map +1 -0
  148. package/_mjs/Cache.mjs +4 -0
  149. package/_mjs/Cache.mjs.map +1 -0
  150. package/_mjs/CompletedRequestMap.mjs +31 -0
  151. package/_mjs/CompletedRequestMap.mjs.map +1 -0
  152. package/_mjs/DataSource/api.mjs +98 -0
  153. package/_mjs/DataSource/api.mjs.map +1 -0
  154. package/_mjs/DataSource/definition.mjs +63 -0
  155. package/_mjs/DataSource/definition.mjs.map +1 -0
  156. package/_mjs/DataSource.mjs +4 -0
  157. package/_mjs/DataSource.mjs.map +1 -0
  158. package/_mjs/DataSourceAspect.mjs +9 -0
  159. package/_mjs/DataSourceAspect.mjs.map +1 -0
  160. package/_mjs/Described.mjs +24 -0
  161. package/_mjs/Described.mjs.map +1 -0
  162. package/_mjs/Query/api/bimap.mjs +11 -0
  163. package/_mjs/Query/api/bimap.mjs.map +1 -0
  164. package/_mjs/Query/api/catchAllCause.mjs +20 -0
  165. package/_mjs/Query/api/catchAllCause.mjs.map +1 -0
  166. package/_mjs/Query/api/collectAll.mjs +9 -0
  167. package/_mjs/Query/api/collectAll.mjs.map +1 -0
  168. package/_mjs/Query/api/collectAllBatched.mjs +9 -0
  169. package/_mjs/Query/api/collectAllBatched.mjs.map +1 -0
  170. package/_mjs/Query/api/collectAllConcurrent.mjs +9 -0
  171. package/_mjs/Query/api/collectAllConcurrent.mjs.map +1 -0
  172. package/_mjs/Query/api/defer.mjs +10 -0
  173. package/_mjs/Query/api/defer.mjs.map +1 -0
  174. package/_mjs/Query/api/ensuring.mjs +12 -0
  175. package/_mjs/Query/api/ensuring.mjs.map +1 -0
  176. package/_mjs/Query/api/environment.mjs +77 -0
  177. package/_mjs/Query/api/environment.mjs.map +1 -0
  178. package/_mjs/Query/api/flatMap.mjs +25 -0
  179. package/_mjs/Query/api/flatMap.mjs.map +1 -0
  180. package/_mjs/Query/api/foreach.mjs +18 -0
  181. package/_mjs/Query/api/foreach.mjs.map +1 -0
  182. package/_mjs/Query/api/foreachBatched.mjs +18 -0
  183. package/_mjs/Query/api/foreachBatched.mjs.map +1 -0
  184. package/_mjs/Query/api/foreachConcurrent.mjs +11 -0
  185. package/_mjs/Query/api/foreachConcurrent.mjs.map +1 -0
  186. package/_mjs/Query/api/fromRequest.mjs +30 -0
  187. package/_mjs/Query/api/fromRequest.mjs.map +1 -0
  188. package/_mjs/Query/api/map.mjs +13 -0
  189. package/_mjs/Query/api/map.mjs.map +1 -0
  190. package/_mjs/Query/api/mapDataSources.mjs +13 -0
  191. package/_mjs/Query/api/mapDataSources.mjs.map +1 -0
  192. package/_mjs/Query/api/mapError.mjs +11 -0
  193. package/_mjs/Query/api/mapError.mjs.map +1 -0
  194. package/_mjs/Query/api/mapErrorCause.mjs +11 -0
  195. package/_mjs/Query/api/mapErrorCause.mjs.map +1 -0
  196. package/_mjs/Query/api/mapIO.mjs +12 -0
  197. package/_mjs/Query/api/mapIO.mjs.map +1 -0
  198. package/_mjs/Query/api/match.mjs +12 -0
  199. package/_mjs/Query/api/match.mjs.map +1 -0
  200. package/_mjs/Query/api/matchCauseQuery.mjs +18 -0
  201. package/_mjs/Query/api/matchCauseQuery.mjs.map +1 -0
  202. package/_mjs/Query/api/matchQuery.mjs +13 -0
  203. package/_mjs/Query/api/matchQuery.mjs.map +1 -0
  204. package/_mjs/Query/api/orHalt.mjs +19 -0
  205. package/_mjs/Query/api/orHalt.mjs.map +1 -0
  206. package/_mjs/Query/api/race.mjs +33 -0
  207. package/_mjs/Query/api/race.mjs.map +1 -0
  208. package/_mjs/Query/api/run.mjs +38 -0
  209. package/_mjs/Query/api/run.mjs.map +1 -0
  210. package/_mjs/Query/api/timeout.mjs +59 -0
  211. package/_mjs/Query/api/timeout.mjs.map +1 -0
  212. package/_mjs/Query/api/zipWith.mjs +30 -0
  213. package/_mjs/Query/api/zipWith.mjs.map +1 -0
  214. package/_mjs/Query/api/zipWithBatched.mjs +31 -0
  215. package/_mjs/Query/api/zipWithBatched.mjs.map +1 -0
  216. package/_mjs/Query/api/zipWithConcurrent.mjs +31 -0
  217. package/_mjs/Query/api/zipWithConcurrent.mjs.map +1 -0
  218. package/_mjs/Query/api.mjs +77 -0
  219. package/_mjs/Query/api.mjs.map +1 -0
  220. package/_mjs/Query/definition.mjs +14 -0
  221. package/_mjs/Query/definition.mjs.map +1 -0
  222. package/_mjs/Query.mjs +34 -0
  223. package/_mjs/Query.mjs.map +1 -0
  224. package/_mjs/QueryFailure.mjs +8 -0
  225. package/_mjs/QueryFailure.mjs.map +1 -0
  226. package/_mjs/Request.mjs +43 -0
  227. package/_mjs/Request.mjs.map +1 -0
  228. package/_mjs/global.mjs +2 -0
  229. package/_mjs/global.mjs.map +1 -0
  230. package/_mjs/index.mjs +2 -0
  231. package/_mjs/index.mjs.map +1 -0
  232. package/_mjs/internal/BlockedRequest.mjs +21 -0
  233. package/_mjs/internal/BlockedRequest.mjs.map +1 -0
  234. package/_mjs/internal/BlockedRequests.mjs +341 -0
  235. package/_mjs/internal/BlockedRequests.mjs.map +1 -0
  236. package/_mjs/internal/Continue.mjs +262 -0
  237. package/_mjs/internal/Continue.mjs.map +1 -0
  238. package/_mjs/internal/Parallel.mjs +62 -0
  239. package/_mjs/internal/Parallel.mjs.map +1 -0
  240. package/_mjs/internal/Result.mjs +208 -0
  241. package/_mjs/internal/Result.mjs.map +1 -0
  242. package/_mjs/internal/Sequential.mjs +44 -0
  243. package/_mjs/internal/Sequential.mjs.map +1 -0
  244. package/_src/Cache/api.ts +49 -0
  245. package/_src/Cache/definition.ts +13 -0
  246. package/_src/Cache.ts +4 -0
  247. package/_src/CompletedRequestMap.ts +38 -0
  248. package/_src/DataSource/api.ts +97 -0
  249. package/_src/DataSource/definition.ts +77 -0
  250. package/_src/DataSource.ts +4 -0
  251. package/_src/DataSourceAspect.ts +7 -0
  252. package/_src/Described.ts +21 -0
  253. package/_src/Query/api/bimap.ts +11 -0
  254. package/_src/Query/api/catchAllCause.ts +17 -0
  255. package/_src/Query/api/collectAll.ts +6 -0
  256. package/_src/Query/api/collectAllBatched.ts +9 -0
  257. package/_src/Query/api/collectAllConcurrent.ts +6 -0
  258. package/_src/Query/api/defer.ts +6 -0
  259. package/_src/Query/api/ensuring.ts +19 -0
  260. package/_src/Query/api/environment.ts +82 -0
  261. package/_src/Query/api/flatMap.ts +26 -0
  262. package/_src/Query/api/foreach.ts +17 -0
  263. package/_src/Query/api/foreachBatched.ts +17 -0
  264. package/_src/Query/api/foreachConcurrent.ts +10 -0
  265. package/_src/Query/api/fromRequest.ts +49 -0
  266. package/_src/Query/api/map.ts +8 -0
  267. package/_src/Query/api/mapDataSources.ts +8 -0
  268. package/_src/Query/api/mapError.ts +8 -0
  269. package/_src/Query/api/mapErrorCause.ts +8 -0
  270. package/_src/Query/api/mapIO.ts +8 -0
  271. package/_src/Query/api/match.ts +11 -0
  272. package/_src/Query/api/matchCauseQuery.ts +21 -0
  273. package/_src/Query/api/matchQuery.ts +12 -0
  274. package/_src/Query/api/orHalt.ts +15 -0
  275. package/_src/Query/api/race.ts +34 -0
  276. package/_src/Query/api/run.ts +40 -0
  277. package/_src/Query/api/timeout.ts +58 -0
  278. package/_src/Query/api/zipWith.ts +44 -0
  279. package/_src/Query/api/zipWithBatched.ts +41 -0
  280. package/_src/Query/api/zipWithConcurrent.ts +45 -0
  281. package/_src/Query/api.ts +76 -0
  282. package/_src/Query/definition.ts +13 -0
  283. package/_src/Query.ts +35 -0
  284. package/_src/QueryFailure.ts +7 -0
  285. package/_src/Request.ts +52 -0
  286. package/_src/global.ts +45 -0
  287. package/_src/index.ts +3 -0
  288. package/_src/internal/BlockedRequest.ts +24 -0
  289. package/_src/internal/BlockedRequests.ts +331 -0
  290. package/_src/internal/Continue.ts +305 -0
  291. package/_src/internal/Parallel.ts +82 -0
  292. package/_src/internal/Result.ts +242 -0
  293. package/_src/internal/Sequential.ts +63 -0
  294. package/global.d.ts +45 -0
  295. package/index.d.ts +1 -0
  296. package/internal/BlockedRequest.d.ts +21 -0
  297. package/internal/BlockedRequests.d.ts +123 -0
  298. package/internal/Continue.d.ts +133 -0
  299. package/internal/Parallel.d.ts +56 -0
  300. package/internal/Result.d.ts +115 -0
  301. package/internal/Sequential.d.ts +40 -0
  302. package/package.json +22 -0
  303. package/runTests.d.ts +1 -0
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query catchAllCause
3
+ */
4
+ export function catchAllCause<E, R1, E1, B>(f: (cause: Cause<E>) => Query<R1, E1, B>, __tsplusTrace?: string) {
5
+ return <R, A>(self: Query<R, E, A>): Query<R | R1, E1, A | B> => {
6
+ return self.matchCauseQuery(f, Query.succeedNow);
7
+ };
8
+ }
9
+
10
+ /**
11
+ * @tsplus pipeable fncts.query.Query catchAll
12
+ */
13
+ export function catchAll<E, R1, E1, B>(f: (e: E) => Query<R1, E1, B>, __tsplusTrace?: string) {
14
+ return <R, A>(self: Query<R, E, A>): Query<R | R1, E1, A | B> => {
15
+ return self.matchQuery(f, Query.succeedNow);
16
+ };
17
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps collectAll
3
+ */
4
+ export function collectAll<R, E, A>(self: Iterable<Query<R, E, A>>, __tsplusTrace?: string): Query<R, E, Conc<A>> {
5
+ return Query.foreach(self, Function.identity);
6
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps collectAllBatched
3
+ */
4
+ export function collectAllBatched<R, E, A>(
5
+ self: Iterable<Query<R, E, A>>,
6
+ __tsplusTrace?: string,
7
+ ): Query<R, E, Conc<A>> {
8
+ return Query.foreachBatched(self, Function.identity);
9
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps collectAllConcurrent
3
+ */
4
+ export function collectAllConcurrent<R, E, A>(self: Iterable<Query<R, E, A>>, __tsplusTrace?: string): Query<R, E, Conc<A>> {
5
+ return Query.foreachConcurrent(self, Function.identity);
6
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps defer
3
+ */
4
+ export function defer<R, E, A>(query: Lazy<Query<R, E, A>>): Query<R, E, A> {
5
+ return Query.unit.flatMap(() => query())
6
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query ensuring
3
+ */
4
+ export function ensuring<R1>(finalizer: Query<R1, never, any>, __tsplusTrace?: string) {
5
+ return <R, E, A>(self: Query<R, E, A>): Query<R | R1, E, A> => {
6
+ return self.matchCauseQuery(
7
+ (cause1) =>
8
+ finalizer.matchCauseQuery(
9
+ (cause2) => Query.failCauseNow(Cause.then(cause1, cause2)),
10
+ () => Query.failCauseNow(cause1),
11
+ ),
12
+ (value) =>
13
+ finalizer.matchCauseQuery(
14
+ (cause) => Query.failCauseNow(cause),
15
+ () => Query.succeedNow(value),
16
+ ),
17
+ );
18
+ };
19
+ }
@@ -0,0 +1,82 @@
1
+ import { Described } from "@fncts/query/Described";
2
+
3
+ /**
4
+ * @tsplus static fncts.query.QueryOps environment
5
+ */
6
+ export function environment<R>(): Query<R, never, Environment<R>> {
7
+ return Query.fromIO(IO.environment<R>());
8
+ }
9
+
10
+ /**
11
+ * @tsplus static fncts.query.QueryOps environmentWith
12
+ */
13
+ export function environmentWith<R, A>(f: (environment: Environment<R>) => A): Query<R, never, A> {
14
+ return Query.environment<R>().map(f);
15
+ }
16
+
17
+ /**
18
+ * @tsplus static fncts.query.QueryOps environmentWithQuery
19
+ */
20
+ export function environmentWithQuery<R0, R, E, A>(
21
+ f: (environment: Environment<R0>) => Query<R, E, A>,
22
+ ): Query<R0 | R, E, A> {
23
+ return Query.environment<R0>().flatMap(f);
24
+ }
25
+
26
+ /**
27
+ * @tsplus static fncts.query.QueryOps environmentWithIO
28
+ */
29
+ export function environmentWithIO<R0, R, E, A>(f: (environment: Environment<R0>) => IO<R, E, A>): Query<R0 | R, E, A> {
30
+ return Query.environment<R0>().mapIO(f);
31
+ }
32
+
33
+ /**
34
+ * @tsplus pipeable fncts.query.Query contramapEnvironment
35
+ */
36
+ export function contramapEnvironment<R0, R>(
37
+ f: Described<(_: Environment<R0>) => Environment<R>>,
38
+ __tsplusTrace?: string,
39
+ ) {
40
+ return <E, A>(self: Query<R, E, A>): Query<R0, E, A> => {
41
+ return new Query(self.step.map((result) => result.contramapEnvironment(f)).contramapEnvironment((r) => f.value(r)));
42
+ };
43
+ }
44
+
45
+ /**
46
+ * @tsplus pipeable fncts.query.Query provideEnvironment
47
+ */
48
+ export function provideEnvironment<R>(environment: Described<Environment<R>>, __tsplusTrace?: string) {
49
+ return <E, A>(self: Query<R, E, A>): Query<never, E, A> => {
50
+ return self.contramapEnvironment(new Described(() => environment.value, `() => ${environment.description}`));
51
+ };
52
+ }
53
+
54
+ /**
55
+ * @tsplus pipeable fncts.query.Query provideSomeEnvironment
56
+ */
57
+ export function provideSomeEnvironment<R0>(environment: Described<Environment<R0>>, __tsplusTrace?: string) {
58
+ return <R, E, A>(self: Query<R, E, A>): Query<Exclude<R, R0>, E, A> => {
59
+ return self.contramapEnvironment(
60
+ new Described((r) => r.union(environment.value), "Environment<R> => Environment<R | R0>"),
61
+ );
62
+ };
63
+ }
64
+
65
+ /**
66
+ * @tsplus pipeable fncts.query.Query provideLayer
67
+ */
68
+ export function provideLayer<RIn, E1, ROut>(layer: Lazy<Described<Layer<RIn, E1, ROut>>>, __tsplusTrace?: string) {
69
+ return <R, E, A>(self: Query<R, E, A>): Query<RIn | Exclude<R, ROut>, E | E1, A> => {
70
+ return new Query(
71
+ IO.scoped(() => {
72
+ const layer0 = layer();
73
+ return layer0.value.build.result.flatMap((exit) =>
74
+ exit.match(
75
+ (cause) => IO.succeedNow(Result.fail(cause)),
76
+ (r) => self.provideSomeEnvironment(new Described(r, layer0.description)).step,
77
+ ),
78
+ );
79
+ }) as IO<RIn | Exclude<R, ROut>, never, Result<Exclude<R, ROut>, E | E1, A>>,
80
+ );
81
+ };
82
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query flatMap
3
+ */
4
+ export function flatMap<A, R1, E1, B>(f: (a: A) => Query<R1, E1, B>, __tsplusTrace?: string) {
5
+ return <R, E>(self: Query<R, E, A>): Query<R | R1, E | E1, B> => {
6
+ return new Query(
7
+ self.step.flatMap((result) =>
8
+ result.matchType({
9
+ Blocked: (br, c) => IO.succeedNow(Result.blocked(br, c.mapQuery(f))),
10
+ Done: (a) => f(a).step,
11
+ Fail: (e) => IO.succeedNow(Result.fail(e)),
12
+ }),
13
+ ),
14
+ );
15
+ };
16
+ }
17
+
18
+ /**
19
+ * @tsplus getter fncts.query.Query flatten
20
+ */
21
+ export function flatten<R, E, R1, E1, A>(
22
+ self: Query<R, E, Query<R1, E1, A>>,
23
+ __tsplusTrace?: string,
24
+ ): Query<R | R1, E | E1, A> {
25
+ return self.flatMap(Function.identity);
26
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps foreach
3
+ */
4
+ export function foreach<A, R, E, B>(
5
+ as: Iterable<A>,
6
+ f: (a: A) => Query<R, E, B>,
7
+ __tsplusTrace?: string,
8
+ ): Query<R, E, Conc<B>> {
9
+ const out: Array<B> = [];
10
+ let builder: Query<R, E, void> = Query.unit;
11
+ for (const a of as) {
12
+ builder = builder.zipWith(f(a), (_, b) => {
13
+ out.push(b);
14
+ });
15
+ }
16
+ return builder.map(() => Conc.fromArray(out));
17
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps foreachBatched
3
+ */
4
+ export function foreachBatched<A, R, E, B>(
5
+ as: Iterable<A>,
6
+ f: (a: A) => Query<R, E, B>,
7
+ __tsplusTrace?: string,
8
+ ): Query<R, E, Conc<B>> {
9
+ const out: Array<B> = [];
10
+ let builder: Query<R, E, void> = Query.unit;
11
+ for (const a of as) {
12
+ builder = builder.zipWithBatched(f(a), (_, b) => {
13
+ out.push(b);
14
+ });
15
+ }
16
+ return builder.map(() => Conc.fromArray(out));
17
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps foreachConcurrent
3
+ */
4
+ export function foreachConcurrent<A, R, E, B>(
5
+ self: Iterable<A>,
6
+ f: (a: A) => Query<R, E, B>,
7
+ __tsplusTrace?: string,
8
+ ): Query<R, E, Conc<B>> {
9
+ return new Query(IO.foreachConcurrent(self, (a) => f(a).step).map((results) => Result.collectAllConcurrent(results)));
10
+ }
@@ -0,0 +1,49 @@
1
+ import { BlockedRequest } from "@fncts/query/internal/BlockedRequest";
2
+ import { BlockedRequests } from "@fncts/query/internal/BlockedRequests";
3
+
4
+ /**
5
+ * @tsplus static fncts.query.QueryOps fromRequest
6
+ */
7
+ export function fromRequest<R, A extends Request<any, any>>(
8
+ request0: Lazy<A>,
9
+ dataSource0: Lazy<DataSource<R, A>>,
10
+ __tsplusTrace?: string,
11
+ ): Query<R, Request.ErrorOf<A>, Request.ValueOf<A>> {
12
+ return new Query(
13
+ IO.defer(() => {
14
+ const request = request0();
15
+ const dataSource = dataSource0();
16
+ return Query.cachingEnabled.get.flatMap((cachingEnabled) => {
17
+ if (cachingEnabled) {
18
+ return Query.currentCache.get.flatMap((cache) =>
19
+ cache.lookup(request).flatMap((r) =>
20
+ r.match(
21
+ (ref) =>
22
+ IO.succeedNow(
23
+ Result.blocked(
24
+ BlockedRequests.single(dataSource, BlockedRequest.make(request, ref)),
25
+ Continue(request, dataSource, ref),
26
+ ),
27
+ ),
28
+ (ref) =>
29
+ ref.get.map((r) =>
30
+ r.match(
31
+ () => Result.blocked(BlockedRequests.empty(), Continue(request, dataSource, ref)),
32
+ (b) => Result.fromEither(b),
33
+ ),
34
+ ),
35
+ ),
36
+ ),
37
+ );
38
+ } else {
39
+ return Ref.make(Nothing<Either<Request.ErrorOf<A>, Request.ValueOf<A>>>()).map((ref) =>
40
+ Result.blocked(
41
+ BlockedRequests.single(dataSource, BlockedRequest.make(request, ref)),
42
+ Continue(request, dataSource, ref),
43
+ ),
44
+ );
45
+ }
46
+ });
47
+ }),
48
+ );
49
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query map
3
+ */
4
+ export function map<A, B>(f: (a: A) => B) {
5
+ return <R, E>(self: Query<R, E, A>): Query<R, E, B> => {
6
+ return new Query(self.step.map((result) => result.map(f)));
7
+ };
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query mapDataSources
3
+ */
4
+ export function mapDataSources<R1>(f: DataSourceAspect<R1>) {
5
+ return <R, E, A>(self: Query<R, E, A>): Query<R | R1, E, A> => {
6
+ return new Query(self.step.map((result) => result.mapDataSources(f)))
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query mapError
3
+ */
4
+ export function mapError<E, E1>(f: (e: E) => E1, __tsplusTrace?: string) {
5
+ return <R, A>(self: Query<R, E, A>): Query<R, E1, A> => {
6
+ return self.bimap(f, Function.identity);
7
+ };
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query mapErrorCause
3
+ */
4
+ export function mapErrorCause<E, E1>(f: (cause: Cause<E>) => Cause<E1>, __tsplusTrace?: string) {
5
+ return <R, A>(self: Query<R, E, A>): Query<R, E1, A> => {
6
+ return self.matchCauseQuery((c) => Query.failCauseNow(f(c)), Query.succeedNow);
7
+ };
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query mapIO
3
+ */
4
+ export function mapIO<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>) {
5
+ return <R, E>(self: Query<R, E, A>): Query<R | R1, E | E1, B> => {
6
+ return self.flatMap(a => Query.fromIO(f(a)))
7
+ }
8
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query match
3
+ */
4
+ export function match<E, A, B, C>(failure: (e: E) => B, success: (a: A) => C) {
5
+ return <R>(self: Query<R, E, A>): Query<R, never, B | C> => {
6
+ return self.matchQuery(
7
+ (e) => Query.succeedNow(failure(e)),
8
+ (a) => Query.succeedNow(success(a)),
9
+ );
10
+ };
11
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query matchCauseQuery
3
+ */
4
+ export function matchCauseQuery<E, A, R1, E1, B, R2, E2, C>(
5
+ failure: (cause: Cause<E>) => Query<R1, E1, B>,
6
+ success: (a: A) => Query<R2, E2, C>,
7
+ ) {
8
+ return <R>(self: Query<R, E, A>): Query<R | R1 | R2, E1 | E2, B | C> => {
9
+ return new Query(
10
+ self.step.matchCauseIO(
11
+ (cause) => failure(cause).step,
12
+ (result) =>
13
+ result.matchType({
14
+ Blocked: (br, c) => IO.succeedNow(Result.blocked(br, c.matchCauseQuery(failure, success))),
15
+ Done: (value) => success(value).step,
16
+ Fail: (cause) => failure(cause).step,
17
+ }),
18
+ ),
19
+ );
20
+ };
21
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query matchQuery
3
+ */
4
+ export function matchQuery<E, A, R1, E1, B, R2, E2, C>(
5
+ failure: (e: E) => Query<R1, E1, B>,
6
+ success: (a: A) => Query<R2, E2, C>,
7
+ __tsplusTrace?: string,
8
+ ) {
9
+ return <R>(self: Query<R, E, A>): Query<R | R1 | R2, E1 | E2, B | C> => {
10
+ return self.matchCauseQuery((cause) => cause.failureOrCause.match(failure, Query.failCauseNow), success);
11
+ };
12
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query orHaltWith
3
+ */
4
+ export function orHaltWith<E>(f: (e: E) => unknown, __tsplusTrace?: string) {
5
+ return <R, A>(self: Query<R, E, A>): Query<R, never, A> => {
6
+ return self.matchQuery((e) => Query.haltNow(f(e)), Query.succeedNow);
7
+ };
8
+ }
9
+
10
+ /**
11
+ * @tsplus getter fncts.query.Query orHalt
12
+ */
13
+ export function orHalt<R, E, A>(self: Query<R, E, A>, __tsplusTrace?: string): Query<R, never, A> {
14
+ return self.orHaltWith(Function.identity);
15
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query race
3
+ */
4
+ export function race<R1, E1, A1>(that: Lazy<Query<R1, E1, A1>>, __tsplusTrace?: string) {
5
+ return <R, E, A>(self: Query<R, E, A>): Query<R | R1, E | E1, A | A1> => {
6
+ function race(
7
+ query: Query<R | R1, E | E1, A | A1>,
8
+ fiber: Fiber<never, Result<R | R1, E | E1, A | A1>>,
9
+ ): Query<R | R1, E | E1, A | A1> {
10
+ return new Query(query.step.raceWith(fiber.join, coordinate, coordinate));
11
+ }
12
+ function coordinate(
13
+ exit: Exit<never, Result<R | R1, E | E1, A | A1>>,
14
+ fiber: Fiber<never, Result<R | R1, E | E1, A | A1>>,
15
+ ): IO<R | R1, never, Result<R | R1, E | E1, A | A1>> {
16
+ return exit.match(
17
+ (cause) => fiber.join.map((result) => result.mapErrorCause((c0) => Cause.both(c0, cause))),
18
+ (result) =>
19
+ result.matchType({
20
+ Blocked: (blockedRequests, cont) =>
21
+ cont.matchType({
22
+ Effect: (query) => IO.succeedNow(Result.blocked(blockedRequests, Continue.effect(race(query, fiber)))),
23
+ Get: (io) =>
24
+ IO.succeedNow(Result.blocked(blockedRequests, Continue.effect(race(Query.fromIO(io), fiber)))),
25
+ }),
26
+ Done: (value) => fiber.interrupt > IO.succeed(Result.done(value)),
27
+ Fail: (cause) => fiber.join.map((result) => result.mapErrorCause((c0) => Cause.both(c0, cause))),
28
+ }),
29
+ );
30
+ }
31
+
32
+ return Query.defer(new Query(self.step.raceWith(that().step, coordinate, coordinate)));
33
+ };
34
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query runCache
3
+ */
4
+ export function runCache(cache: Cache, __tsplusTrace?: string) {
5
+ return <R, E, A>(self: Query<R, E, A>): IO<R, E, A> => {
6
+ return IO.defer(
7
+ Query.currentCache.locally(cache)(
8
+ self.step.flatMap((result) =>
9
+ result.matchType({
10
+ Blocked: (br, c) =>
11
+ c.matchType({
12
+ Effect: (c) => br.run > c.run,
13
+ Get: (io) => br.run > io,
14
+ }),
15
+ Done: (a) => IO.succeedNow(a),
16
+ Fail: (cause) => IO.failCauseNow(cause),
17
+ }),
18
+ ),
19
+ ),
20
+ );
21
+ };
22
+ }
23
+
24
+ /**
25
+ * @tsplus getter fncts.query.Query runLog
26
+ */
27
+ export function runLog<R, E, A>(self: Query<R, E, A>, __tsplusTrace?: string): IO<R, E, readonly [Cache, A]> {
28
+ return Do((Δ) => {
29
+ const cache = Δ(Cache.empty());
30
+ const a = Δ(self.runCache(cache));
31
+ return [cache, a] as const;
32
+ });
33
+ }
34
+
35
+ /**
36
+ * @tsplus getter fncts.query.Query run
37
+ */
38
+ export function run<R, E, A>(self: Query<R, E, A>, __tsplusTrace?: string): IO<R, E, A> {
39
+ return self.runLog.map(([, a]) => a);
40
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @tsplus pipeable fncts.query.Query timeoutTo
3
+ */
4
+ export function timeoutTo<A, B, B1>(duration: Lazy<Duration>, b: Lazy<B>, f: (a: A) => B1, __tsplusTrace?: string) {
5
+ return <R, E>(self: Query<R, E, A>): Query<R, E, B | B1> => {
6
+ function race(query: Query<R, E, B | B1>, fiber: Fiber<never, B | B1>): Query<R, E, B | B1> {
7
+ return new Query(
8
+ query.step.raceWith(
9
+ fiber.join,
10
+ (leftExit, rightFiber) =>
11
+ leftExit.match(
12
+ (cause) => rightFiber.interrupt > IO.succeedNow(Result.fail(cause)),
13
+ (result) =>
14
+ result.matchType({
15
+ Blocked: (br, c) =>
16
+ c.matchType({
17
+ Effect: (query) => IO.succeedNow(Result.blocked(br, Continue.effect(race(query, fiber)))),
18
+ Get: (io) => IO.succeedNow(Result.blocked(br, Continue.effect(race(Query.fromIO(io), fiber)))),
19
+ }),
20
+ Done: (value) => rightFiber.interrupt > IO.succeedNow(Result.done(value)),
21
+ Fail: (cause) => rightFiber.interrupt > IO.succeed(Result.fail(cause)),
22
+ }),
23
+ ),
24
+ (rightExit, leftFiber) => leftFiber.interrupt > IO.succeedNow(Result.fromExit(rightExit)),
25
+ ),
26
+ );
27
+ }
28
+
29
+ return Query.fromIO(IO.sleep(duration).interruptible.as(b).fork).flatMap((fiber) => race(self.map(f), fiber));
30
+ };
31
+ }
32
+
33
+ /**
34
+ * @tsplus pipeable fncts.query.Query timeout
35
+ */
36
+ export function timeout(duration: Lazy<Duration>, __tsplusTrace?: string) {
37
+ return <R, E, A>(self: Query<R, E, A>): Query<R, E, Maybe<A>> => {
38
+ return self.timeoutTo(duration, Nothing(), (a) => Just(a));
39
+ };
40
+ }
41
+
42
+ /**
43
+ * @tsplus pipeable fncts.query.Query timeoutFail
44
+ */
45
+ export function timeoutFail<E1>(duration: Lazy<Duration>, e: Lazy<E1>, __tsplusTrace?: string) {
46
+ return <R, E, A>(self: Query<R, E, A>): Query<R, E | E1, A> => {
47
+ return self.timeoutTo(duration, Query.fail(e), Query.succeedNow).flatten;
48
+ };
49
+ }
50
+
51
+ /**
52
+ * @tsplus pipeable fncts.query.Query timeoutFailCause
53
+ */
54
+ export function timeoutFailCause<E1>(duration: Lazy<Duration>, e: Lazy<Cause<E1>>, __tsplusTrace?: string) {
55
+ return <R, E, A>(self: Query<R, E, A>): Query<R, E | E1, A> => {
56
+ return self.timeoutTo(duration, Query.failCause(e), Query.succeedNow).flatten;
57
+ };
58
+ }
@@ -0,0 +1,44 @@
1
+ import { BlockedRequests } from "@fncts/query/internal/BlockedRequests";
2
+
3
+ /**
4
+ * @tsplus pipeable fncts.query.Query zipWith
5
+ */
6
+ export function zipWith<A, R1, E1, B, C>(that: Lazy<Query<R1, E1, B>>, f: (a: A, b: B) => C, __tsplusTrace?: string) {
7
+ return <R, E>(self: Query<R, E, A>): Query<R | R1, E | E1, C> => {
8
+ return new Query(
9
+ self.step.flatMap((result) =>
10
+ result.matchType({
11
+ Blocked: (br, cont) =>
12
+ cont.matchType({
13
+ Effect: (query) => IO.succeedNow(Result.blocked(br, Continue.effect(query.zipWith(that, f)))),
14
+ Get: () =>
15
+ that().step.map((result) =>
16
+ result.matchType({
17
+ Blocked: (br2, c2) => Result.blocked(BlockedRequests.then<R | R1>(br, br2), cont.zipWith(c2, f)),
18
+ Done: (b) =>
19
+ Result.blocked(
20
+ br,
21
+ cont.map((a) => f(a, b)),
22
+ ),
23
+ Fail: (cause) => Result.fail(cause),
24
+ }),
25
+ ),
26
+ }),
27
+ Done: (a) =>
28
+ that().step.map((result) =>
29
+ result.matchType({
30
+ Blocked: (br, c) =>
31
+ Result.blocked(
32
+ br,
33
+ c.map((b) => f(a, b)),
34
+ ),
35
+ Done: (b) => Result.done(f(a, b)),
36
+ Fail: (cause) => Result.fail(cause),
37
+ }),
38
+ ),
39
+ Fail: (cause) => Result.fail(cause),
40
+ }),
41
+ ),
42
+ );
43
+ };
44
+ }
@@ -0,0 +1,41 @@
1
+ import { BlockedRequests } from "@fncts/query/internal/BlockedRequests";
2
+
3
+ /**
4
+ * @tsplus pipeable fncts.query.Query zipWithBatched
5
+ */
6
+ export function zipWithBatched<A, R1, E1, B, C>(that: Query<R1, E1, B>, f: (a: A, b: B) => C, __tsplusTrace?: string) {
7
+ return <R, E>(self: Query<R, E, A>): Query<R | R1, E | E1, C> => {
8
+ return new Query(
9
+ self.step.zipWith(that.step, (r1, r2) =>
10
+ r1.matchType({
11
+ Blocked: (br1, c1) =>
12
+ r2.matchType({
13
+ Blocked: (br2, c2) => Result.blocked(BlockedRequests.both<R | R1>(br1, br2), c1.zipWithBatched(c2, f)),
14
+ Done: (b) =>
15
+ Result.blocked(
16
+ br1,
17
+ c1.map((a) => f(a, b)),
18
+ ),
19
+ Fail: (cause) => Result.fail(cause),
20
+ }),
21
+ Done: (a) =>
22
+ r2.matchType({
23
+ Blocked: (br, c) =>
24
+ Result.blocked(
25
+ br,
26
+ c.map((b) => f(a, b)),
27
+ ),
28
+ Done: (b) => Result.done(f(a, b)),
29
+ Fail: (cause) => Result.fail(cause),
30
+ }),
31
+ Fail: (cause) =>
32
+ r2.matchType({
33
+ Blocked: () => Result.fail(cause),
34
+ Done: () => Result.fail(cause),
35
+ Fail: (cause2) => Result.fail(Cause.both(cause, cause2)),
36
+ }),
37
+ }),
38
+ ),
39
+ );
40
+ };
41
+ }
@@ -0,0 +1,45 @@
1
+ import { BlockedRequests } from "@fncts/query/internal/BlockedRequests";
2
+
3
+ /**
4
+ * @tsplus pipeable fncts.query.Query zipWithConcurrent
5
+ */
6
+ export function zipWithConcurrent<A, R1, E1, B, C>(
7
+ that: Query<R1, E1, B>,
8
+ f: (a: A, b: B) => C,
9
+ __tsplusTrace?: string,
10
+ ) {
11
+ return <R, E>(self: Query<R, E, A>): Query<R | R1, E | E1, C> => {
12
+ return new Query(
13
+ self.step.zipWithConcurrent(that.step, (r1, r2) =>
14
+ r1.matchType({
15
+ Blocked: (br1, c1) =>
16
+ r2.matchType({
17
+ Blocked: (br2, c2) => Result.blocked(BlockedRequests.both<R | R1>(br1, br2), c1.zipWithConcurrent(c2, f)),
18
+ Done: (b) =>
19
+ Result.blocked(
20
+ br1,
21
+ c1.map((a) => f(a, b)),
22
+ ),
23
+ Fail: (cause) => Result.fail(cause),
24
+ }),
25
+ Done: (a) =>
26
+ r2.matchType({
27
+ Blocked: (br, c) =>
28
+ Result.blocked(
29
+ br,
30
+ c.map((b) => f(a, b)),
31
+ ),
32
+ Done: (b) => Result.done(f(a, b)),
33
+ Fail: (cause) => Result.fail(cause),
34
+ }),
35
+ Fail: (cause) =>
36
+ r2.matchType({
37
+ Blocked: () => Result.fail(cause),
38
+ Done: () => Result.fail(cause),
39
+ Fail: (cause2) => Result.fail(Cause.both(cause, cause2)),
40
+ }),
41
+ }),
42
+ ),
43
+ );
44
+ };
45
+ }