@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,76 @@
1
+ /**
2
+ * @tsplus static fncts.query.QueryOps cachingEnabled
3
+ */
4
+ export const cachingEnabled: FiberRef<boolean> = FiberRef.unsafeMake(true);
5
+ /**
6
+ * @tsplus static fncts.query.QueryOps currentCache
7
+ */
8
+ export const currentCache: FiberRef<Cache> = FiberRef.unsafeMake(Cache.unsafeMake());
9
+
10
+ /**
11
+ * @tsplus static fncts.query.QueryOps fromIO
12
+ */
13
+ export function fromIO<R, E, A>(io: Lazy<IO<R, E, A>>): Query<R, E, A> {
14
+ return new Query(IO.defer(io).matchCause(Result.fail, Result.done));
15
+ }
16
+
17
+ /**
18
+ * @tsplus static fncts.query.QueryOps failCause
19
+ */
20
+ export function failCause<E>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): Query<never, E, never> {
21
+ return new Query(IO.succeed(Result.fail(cause())));
22
+ }
23
+
24
+ /**
25
+ * @tsplus static fncts.query.QueryOps failCauseNow
26
+ */
27
+ export function failCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): Query<never, E, never> {
28
+ return new Query(IO.succeedNow(Result.fail(cause)));
29
+ }
30
+
31
+ /**
32
+ * @tsplus static fncts.query.QueryOps fail
33
+ */
34
+ export function fail<E>(e: Lazy<E>, __tsplusTrace?: string): Query<never, E, never> {
35
+ return Query.failCause(Cause.fail(e()));
36
+ }
37
+
38
+ /**
39
+ * @tsplus static fncts.query.QueryOps failNow
40
+ */
41
+ export function failNow<E>(e: E, __tsplusTrace?: string): Query<never, E, never> {
42
+ return Query.failCauseNow(Cause.fail(e));
43
+ }
44
+
45
+ /**
46
+ * @tsplus static fncts.query.QueryOps halt
47
+ */
48
+ export function halt(t: Lazy<unknown>, __tsplusTrace?: string): Query<never, never, never> {
49
+ return new Query(IO.halt(t));
50
+ }
51
+
52
+ /**
53
+ * @tsplus static fncts.query.QueryOps haltNow
54
+ */
55
+ export function haltNow(t: unknown, __tsplusTrace?: string): Query<never, never, never> {
56
+ return new Query(IO.haltNow(t));
57
+ }
58
+
59
+ /**
60
+ * @tsplus static fncts.query.QueryOps succeed
61
+ */
62
+ export function succeed<A>(value: Lazy<A>): Query<never, never, A> {
63
+ return new Query(IO.succeed(Result.done(value())));
64
+ }
65
+
66
+ /**
67
+ * @tsplus static fncts.query.QueryOps succeedNow
68
+ */
69
+ export function succeedNow<A>(value: A): Query<never, never, A> {
70
+ return new Query(IO.succeedNow(Result.done(value)));
71
+ }
72
+
73
+ /**
74
+ * @tsplus static fncts.query.QueryOps unit
75
+ */
76
+ export const unit: Query<never, never, void> = Query.succeedNow(undefined);
@@ -0,0 +1,13 @@
1
+ import type { Result } from "@fncts/query/internal/Result";
2
+
3
+ export const QueryTypeId = Symbol.for("fncts.query.Query");
4
+ export type QueryTypeId = typeof QueryTypeId;
5
+
6
+ /**
7
+ * @tsplus type fncts.query.Query
8
+ * @tsplus companion fncts.query.QueryOps
9
+ */
10
+ export class Query<R, E, A> {
11
+ readonly [QueryTypeId]: QueryTypeId = QueryTypeId;
12
+ constructor(readonly step: IO<R, never, Result<R, E, A>>) {}
13
+ }
package/_src/Query.ts ADDED
@@ -0,0 +1,35 @@
1
+ // codegen:start { preset: barrel, include: ./Query/*.ts }
2
+ export * from "./Query/api.js";
3
+ export * from "./Query/definition.js";
4
+ // codegen:end
5
+
6
+ // codegen:start { preset: barrel, include: ./Query/api/*.ts }
7
+ export * from "./Query/api/bimap.js";
8
+ export * from "./Query/api/catchAllCause.js";
9
+ export * from "./Query/api/collectAll.js";
10
+ export * from "./Query/api/collectAllBatched.js";
11
+ export * from "./Query/api/collectAllConcurrent.js";
12
+ export * from "./Query/api/defer.js";
13
+ export * from "./Query/api/ensuring.js";
14
+ export * from "./Query/api/environment.js";
15
+ export * from "./Query/api/flatMap.js";
16
+ export * from "./Query/api/foreach.js";
17
+ export * from "./Query/api/foreachBatched.js";
18
+ export * from "./Query/api/foreachConcurrent.js";
19
+ export * from "./Query/api/fromRequest.js";
20
+ export * from "./Query/api/map.js";
21
+ export * from "./Query/api/mapDataSources.js";
22
+ export * from "./Query/api/mapError.js";
23
+ export * from "./Query/api/mapErrorCause.js";
24
+ export * from "./Query/api/mapIO.js";
25
+ export * from "./Query/api/match.js";
26
+ export * from "./Query/api/matchCauseQuery.js";
27
+ export * from "./Query/api/matchQuery.js";
28
+ export * from "./Query/api/orHalt.js";
29
+ export * from "./Query/api/race.js";
30
+ export * from "./Query/api/run.js";
31
+ export * from "./Query/api/timeout.js";
32
+ export * from "./Query/api/zipWith.js";
33
+ export * from "./Query/api/zipWithBatched.js";
34
+ export * from "./Query/api/zipWithConcurrent.js";
35
+ // codegen:end
@@ -0,0 +1,7 @@
1
+ import { show } from "@fncts/base/data/Showable";
2
+
3
+ export class QueryFailure extends Error {
4
+ constructor(readonly dataSource: DataSource<any, any>, request: Request<any, any>) {
5
+ super(`Data source ${dataSource.identifier} did not complete request ${show(request)}.`);
6
+ }
7
+ }
@@ -0,0 +1,52 @@
1
+ import type { ShowComputationExternal } from "@fncts/base/data/Showable";
2
+
3
+ import { CaseClassTypeId } from "@fncts/base/data/CaseClass";
4
+ import { showComputationComplex, showProperty } from "@fncts/base/data/Showable";
5
+
6
+ export const RequestTypeId = Symbol.for("fncts.query.Request");
7
+ export type RequestTypeId = typeof RequestTypeId;
8
+
9
+ export const RequestVariance = Symbol.for("fncts.query.Request.Variance");
10
+ export type RequestVariance = typeof RequestVariance;
11
+
12
+ export abstract class Request<E, A> {
13
+ readonly [RequestTypeId]: RequestTypeId = RequestTypeId;
14
+ declare [RequestVariance]: {
15
+ readonly _E: (_: never) => E;
16
+ readonly _A: (_: never) => A;
17
+ };
18
+ }
19
+
20
+ const simpleRequestHash = Hashable.string("fncts.query.Request.SimpleRequest");
21
+
22
+ // @ts-expect-error
23
+ export abstract class SimpleRequest<X extends Record<PropertyKey, any>, E, A> extends CaseClass<X> {
24
+ readonly [RequestTypeId]: RequestTypeId = RequestTypeId;
25
+ declare [RequestVariance]: {
26
+ readonly _E: (_: never) => E;
27
+ readonly _A: (_: never) => A;
28
+ };
29
+
30
+ get [Symbol.hash](): number {
31
+ return this[CaseClassTypeId].foldLeft(simpleRequestHash, (acc, k) =>
32
+ Hashable.combine(acc, Hashable.unknown(this[k])),
33
+ );
34
+ }
35
+
36
+ [Symbol.equals](that: unknown): boolean {
37
+ return Hashable.unknown(this) === Hashable.unknown(that);
38
+ }
39
+
40
+ get [Symbol.showable](): ShowComputationExternal {
41
+ return showComputationComplex({
42
+ base: Z.succeedNow(`Request (${this.constructor.name})`),
43
+ braces: ["{", "}"],
44
+ keys: this[CaseClassTypeId].traverse(Z.Applicative)((key) => showProperty(this, key, 0)).map(Conc.from),
45
+ });
46
+ }
47
+ }
48
+
49
+ export declare namespace Request {
50
+ type ErrorOf<X> = [X] extends [{ [RequestVariance]: { _E: (_: never) => infer E } }] ? E : never;
51
+ type ValueOf<X> = [X] extends [{ [RequestVariance]: { _A: (_: never) => infer A } }] ? A : never;
52
+ }
package/_src/global.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @tsplus global
3
+ */
4
+ import type {} from "@fncts/base/global";
5
+ /**
6
+ * @tsplus global
7
+ */
8
+ import type {} from "@fncts/io/global";
9
+ /**
10
+ * @tsplus global
11
+ */
12
+ import type {} from "@fncts/query";
13
+
14
+ /**
15
+ * @tsplus global
16
+ */
17
+ import { Left, Right } from "@fncts/base/data/Either";
18
+ /**
19
+ * @tsplus global
20
+ */
21
+ import { Cache } from "@fncts/query/Cache";
22
+ /**
23
+ * @tsplus global
24
+ */
25
+ import { DataSource } from "@fncts/query/DataSource";
26
+ /**
27
+ * @tsplus global
28
+ */
29
+ import { DataSourceAspect } from "@fncts/query/DataSourceAspect";
30
+ /**
31
+ * @tsplus global
32
+ */
33
+ import { Continue } from "@fncts/query/internal/Continue";
34
+ /**
35
+ * @tsplus global
36
+ */
37
+ import { Result } from "@fncts/query/internal/Result";
38
+ /**
39
+ * @tsplus global
40
+ */
41
+ import { Query } from "@fncts/query/Query/definition";
42
+ /**
43
+ * @tsplus global
44
+ */
45
+ import { Request } from "@fncts/query/Request";
package/_src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ // codegen:start { preset: type-barrel, include: ./*.ts }
2
+ export type {} from "./global.js";
3
+ // codegen:end
@@ -0,0 +1,24 @@
1
+ export const BlockedRequestTypeId = Symbol.for("fncts.query.BlockedRequest");
2
+ export type BlockedRequestTypeId = typeof BlockedRequestTypeId;
3
+
4
+ /**
5
+ * @tsplus type fncts.query.BlockedRequest
6
+ * @tsplus companion fncts.query.BlockedRequestOps
7
+ */
8
+ export class BlockedRequest<A> {
9
+ readonly [BlockedRequestTypeId]: BlockedRequestTypeId = BlockedRequestTypeId;
10
+ constructor(
11
+ readonly request: Request<Request.ErrorOf<A>, Request.ValueOf<A>>,
12
+ readonly result: Ref<Maybe<Either<Request.ErrorOf<A>, Request.ValueOf<A>>>>,
13
+ ) {}
14
+ }
15
+
16
+ /**
17
+ * @tsplus static fncts.query.BlockedRequestOps make
18
+ */
19
+ export function make<A extends Request<any, any>>(
20
+ request: A,
21
+ result: Ref<Maybe<Either<Request.ErrorOf<A>, Request.ValueOf<A>>>>,
22
+ ): BlockedRequest<A> {
23
+ return new BlockedRequest(request, result);
24
+ }
@@ -0,0 +1,331 @@
1
+ import type { Sequential } from "./Sequential.js";
2
+ import type { DataSource } from "@fncts/query/DataSource";
3
+ import type { Described } from "@fncts/query/Described";
4
+ import type { BlockedRequest } from "@fncts/query/internal/BlockedRequest";
5
+
6
+ import { Parallel } from "./Parallel.js";
7
+
8
+ export const BlockedRequestsTypeId = Symbol.for("fncts.query.BlockedRequests");
9
+ export type BlockedRequestsTypeId = typeof BlockedRequestsTypeId;
10
+
11
+ export const BlockedRequestsVariance = Symbol.for("fncts.query.BlockedRequests.Variance");
12
+ export type BlockedRequestsVariance = typeof BlockedRequestsVariance;
13
+
14
+ /**
15
+ * @tsplus type fncts.query.BlockedRequests
16
+ * @tsplus companion fncts.query.BlockedRequestsOps
17
+ */
18
+ export abstract class BlockedRequests<R> {
19
+ readonly [BlockedRequestsTypeId]: BlockedRequestsTypeId = BlockedRequestsTypeId;
20
+ declare [BlockedRequestsVariance]: {
21
+ readonly _R: (_: never) => R;
22
+ };
23
+ }
24
+
25
+ export const enum BlockedRequestsTag {
26
+ Empty,
27
+ Single,
28
+ Then,
29
+ Both,
30
+ }
31
+
32
+ export class Empty extends BlockedRequests<never> {
33
+ readonly _tag = BlockedRequestsTag.Empty;
34
+ }
35
+
36
+ export class Single<R, A> extends BlockedRequests<R> {
37
+ readonly _tag = BlockedRequestsTag.Single;
38
+ constructor(readonly dataSource: DataSource<R, A>, readonly blockedRequest: BlockedRequest<A>) {
39
+ super();
40
+ }
41
+ }
42
+
43
+ export class Then<R> extends BlockedRequests<R> {
44
+ readonly _tag = BlockedRequestsTag.Then;
45
+ constructor(readonly left: BlockedRequests<R>, readonly right: BlockedRequests<R>) {
46
+ super();
47
+ }
48
+ }
49
+
50
+ export class Both<R> extends BlockedRequests<R> {
51
+ readonly _tag = BlockedRequestsTag.Both;
52
+ constructor(readonly left: BlockedRequests<R>, readonly right: BlockedRequests<R>) {
53
+ super();
54
+ }
55
+ }
56
+
57
+ const _Empty = new Empty();
58
+
59
+ /**
60
+ * @tsplus static fncts.query.BlockedRequestsOps empty
61
+ */
62
+ export function empty<R>(): BlockedRequests<R> {
63
+ return _Empty;
64
+ }
65
+
66
+ /**
67
+ * @tsplus static fncts.query.BlockedRequestsOps single
68
+ */
69
+ export function single<R, A>(dataSource: DataSource<R, A>, blockedRequest: BlockedRequest<A>): BlockedRequests<R> {
70
+ return new Single(dataSource, blockedRequest);
71
+ }
72
+
73
+ /**
74
+ * @tsplus static fncts.query.BlockedRequestsOps then
75
+ */
76
+ export function then<R>(left: BlockedRequests<R>, right: BlockedRequests<R>): BlockedRequests<R> {
77
+ return new Then(left, right);
78
+ }
79
+
80
+ /**
81
+ * @tsplus static fncts.query.BlockedRequestsOps both
82
+ */
83
+ export function both<R>(left: BlockedRequests<R>, right: BlockedRequests<R>): BlockedRequests<R> {
84
+ return new Both(left, right);
85
+ }
86
+
87
+ type Concrete<R> = Empty | Single<R, any> | Then<R> | Both<R>;
88
+
89
+ function concrete<R>(_: BlockedRequests<R>): asserts _ is Concrete<R> {
90
+ //
91
+ }
92
+
93
+ export abstract class BlockedRequestsFolder<R, Z> {
94
+ abstract readonly emptyCase: Z;
95
+ abstract singleCase<A>(dataSource: DataSource<R, A>, blockedRequest: BlockedRequest<A>): Z;
96
+ abstract bothCase(left: Z, right: Z): Z;
97
+ abstract thenCase(left: Z, right: Z): Z;
98
+ }
99
+
100
+ /**
101
+ * @tsplus pipeable fncts.query.BlockedRequests fold
102
+ */
103
+ export function fold<R, Z>(folder: BlockedRequestsFolder<R, Z>) {
104
+ return (self: BlockedRequests<R>): Z => {
105
+ return foldLoop(folder, Cons(self), List.empty()).unsafeHead;
106
+ };
107
+ }
108
+
109
+ const enum BlockedRequestsCase {
110
+ BothCase,
111
+ ThenCase,
112
+ }
113
+ /**
114
+ * @tsplus tailRef
115
+ */
116
+ function foldLoop<R, Z>(
117
+ folder: BlockedRequestsFolder<R, Z>,
118
+ inp: List<BlockedRequests<R>>,
119
+ out: List<Either<BlockedRequestsCase, Z>>,
120
+ ): List<Z> {
121
+ if (inp.isEmpty()) {
122
+ return out.foldLeft(List.empty(), (acc, r) =>
123
+ r.match(
124
+ (c) => {
125
+ const left = acc.unsafeHead;
126
+ const right = acc.unsafeTail.unsafeHead;
127
+ const blockedRequests = acc.unsafeTail.unsafeTail;
128
+ switch (c) {
129
+ case BlockedRequestsCase.BothCase: {
130
+ return Cons(folder.bothCase(left, right), blockedRequests);
131
+ }
132
+ case BlockedRequestsCase.ThenCase: {
133
+ return Cons(folder.thenCase(left, right), blockedRequests);
134
+ }
135
+ }
136
+ },
137
+ (z) => Cons(z, acc),
138
+ ),
139
+ );
140
+ } else {
141
+ const head = inp.head;
142
+ concrete(head);
143
+ switch (head._tag) {
144
+ case BlockedRequestsTag.Empty: {
145
+ return foldLoop(folder, inp.tail, Cons(Right(folder.emptyCase), out));
146
+ }
147
+ case BlockedRequestsTag.Single: {
148
+ return foldLoop(folder, inp.tail, Cons(Right(folder.singleCase(head.dataSource, head.blockedRequest)), out));
149
+ }
150
+ case BlockedRequestsTag.Both: {
151
+ return foldLoop(
152
+ folder,
153
+ Cons(head.left, Cons(head.right, inp.tail)),
154
+ Cons(Left(BlockedRequestsCase.BothCase), out),
155
+ );
156
+ }
157
+ case BlockedRequestsTag.Then: {
158
+ return foldLoop(
159
+ folder,
160
+ Cons(head.left, Cons(head.right, inp.tail)),
161
+ Cons(Left(BlockedRequestsCase.ThenCase), out),
162
+ );
163
+ }
164
+ }
165
+ }
166
+ }
167
+
168
+ export class MapDataSources<R> extends BlockedRequestsFolder<R, BlockedRequests<R>> {
169
+ constructor(readonly f: DataSourceAspect<R>) {
170
+ super();
171
+ }
172
+ emptyCase: BlockedRequests<R> = new Empty();
173
+ singleCase<A>(dataSource: DataSource<R, A>, blockedRequest: BlockedRequest<A>): BlockedRequests<R> {
174
+ return new Single(this.f.apply(dataSource), blockedRequest);
175
+ }
176
+ bothCase(left: BlockedRequests<R>, right: BlockedRequests<R>): BlockedRequests<R> {
177
+ return new Both(left, right);
178
+ }
179
+ thenCase(left: BlockedRequests<R>, right: BlockedRequests<R>): BlockedRequests<R> {
180
+ return new Then(left, right);
181
+ }
182
+ }
183
+
184
+ /**
185
+ * @tsplus pipeable fncts.query.BlockedRequests mapDataSources
186
+ */
187
+ export function mapDataSources<R1>(f: DataSourceAspect<R1>) {
188
+ return <R>(self: BlockedRequests<R>): BlockedRequests<R | R1> => {
189
+ return self.fold(new MapDataSources<R | R1>(f));
190
+ };
191
+ }
192
+
193
+ export class ContramapEnvironment<R0, R> extends BlockedRequestsFolder<R, BlockedRequests<R0>> {
194
+ constructor(readonly f: Described<(_: Environment<R0>) => Environment<R>>) {
195
+ super();
196
+ }
197
+ emptyCase: BlockedRequests<R0> = new Empty();
198
+ singleCase<A>(dataSource: DataSource<R, A>, blockedRequest: BlockedRequest<A>): BlockedRequests<R0> {
199
+ return new Single(dataSource.contramapEnvironment(this.f), blockedRequest);
200
+ }
201
+ bothCase(left: BlockedRequests<R0>, right: BlockedRequests<R0>): BlockedRequests<R0> {
202
+ return new Both(left, right);
203
+ }
204
+ thenCase(left: BlockedRequests<R0>, right: BlockedRequests<R0>): BlockedRequests<R0> {
205
+ return new Then(left, right);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * @tsplus pipeable fncts.query.BlockedRequests contramapEnvironment
211
+ */
212
+ export function contramapEnvironment<R0, R>(
213
+ f: Described<(_: Environment<R0>) => Environment<R>>,
214
+ __tsplusTrace?: string,
215
+ ) {
216
+ return (self: BlockedRequests<R>): BlockedRequests<R0> => {
217
+ return self.fold(new ContramapEnvironment(f));
218
+ };
219
+ }
220
+
221
+ /**
222
+ * @tsplus getter fncts.query.BlockedRequests step
223
+ */
224
+ export function step<R>(c: BlockedRequests<R>): readonly [Parallel<R>, List<BlockedRequests<R>>] {
225
+ return stepLoop(c, List.empty(), Parallel.empty, List.empty());
226
+ }
227
+
228
+ /**
229
+ * @tsplus tailRec
230
+ */
231
+ function stepLoop<R>(
232
+ blockedRequests: BlockedRequests<R>,
233
+ stack: List<BlockedRequests<R>>,
234
+ parallel: Parallel<R>,
235
+ sequential: List<BlockedRequests<R>>,
236
+ ): readonly [Parallel<R>, List<BlockedRequests<R>>] {
237
+ concrete(blockedRequests);
238
+ switch (blockedRequests._tag) {
239
+ case BlockedRequestsTag.Empty: {
240
+ if (stack.isEmpty()) return [parallel, sequential];
241
+ else return stepLoop(stack.head, stack.tail, parallel, sequential);
242
+ }
243
+ case BlockedRequestsTag.Then: {
244
+ concrete(blockedRequests.left);
245
+ const { left, right } = blockedRequests;
246
+ switch (left._tag) {
247
+ case BlockedRequestsTag.Empty:
248
+ return stepLoop(right, stack, parallel, sequential);
249
+ case BlockedRequestsTag.Then:
250
+ return stepLoop(new Then(left.left, new Then(left.right, right)), stack, parallel, sequential);
251
+ case BlockedRequestsTag.Both:
252
+ return stepLoop(
253
+ new Both(new Then(left.left, right), new Then(left.right, right)),
254
+ stack,
255
+ parallel,
256
+ sequential,
257
+ );
258
+ case BlockedRequestsTag.Single:
259
+ return stepLoop(left, stack, parallel, Cons(right, sequential));
260
+ }
261
+ }
262
+ case BlockedRequestsTag.Both: {
263
+ return stepLoop(blockedRequests.left, Cons(blockedRequests.right, stack), parallel, sequential);
264
+ }
265
+ case BlockedRequestsTag.Single: {
266
+ if (stack.isEmpty())
267
+ return [parallel.concat(Parallel(blockedRequests.dataSource, blockedRequests.blockedRequest)), sequential];
268
+ else
269
+ return stepLoop(
270
+ stack.head,
271
+ stack.tail,
272
+ parallel.concat(Parallel(blockedRequests.dataSource, blockedRequests.blockedRequest)),
273
+ sequential,
274
+ );
275
+ }
276
+ }
277
+ }
278
+
279
+ /**
280
+ * @tsplus getter fncts.query.BlockedRequests flatten
281
+ */
282
+ export function flatten<R>(blockedRequests: BlockedRequests<R>): List<Sequential<R>> {
283
+ return flattenLoop(List(blockedRequests), List.empty());
284
+ }
285
+
286
+ function flattenLoop<R>(
287
+ blockedRequests: List<BlockedRequests<R>>,
288
+ flattened: List<Sequential<R>>,
289
+ ): List<Sequential<R>> {
290
+ const [parallel, sequential] = blockedRequests.foldLeft(
291
+ [Parallel.empty as Parallel<R>, List.empty<BlockedRequests<R>>()] as const,
292
+ ([parallel, sequential], blockedRequest) => {
293
+ const [par, seq] = blockedRequest.step;
294
+ return [parallel.concat(par), sequential.concat(seq)] as const;
295
+ },
296
+ );
297
+ const updated = merge(flattened, parallel);
298
+ if (sequential.isEmpty()) return updated.reverse;
299
+ else return flattenLoop(sequential, updated);
300
+ }
301
+
302
+ function merge<R>(sequential: List<Sequential<R>>, parallel: Parallel<R>): List<Sequential<R>> {
303
+ if (sequential.isEmpty()) return List(parallel.sequential);
304
+ else if (parallel.isEmpty) return sequential;
305
+ else if (sequential.head.keys.size === 1 && parallel.keys.size === 1 && sequential.head.keys == parallel.keys)
306
+ return Cons(sequential.head.concat(parallel.sequential), sequential.tail);
307
+ else return Cons(parallel.sequential, sequential);
308
+ }
309
+
310
+ /**
311
+ * @tsplus getter fncts.query.BlockedRequests run
312
+ */
313
+ export function run<R>(self: BlockedRequests<R>, __tsplusTrace?: string): IO<R, never, void> {
314
+ return Query.currentCache.get.flatMap((cache) =>
315
+ IO.foreachDiscard(self.flatten, (requestsByDataSource) =>
316
+ IO.foreachConcurrentDiscard(requestsByDataSource.toIterable, ([dataSource, sequential]) =>
317
+ Do((Δ) => {
318
+ const completedRequests = Δ(dataSource.runAll(sequential.map((br) => br.map((r) => r.request))));
319
+ const blockedRequests = sequential.flatten;
320
+ const leftovers = completedRequests.requests().removeMany(blockedRequests.map((br) => br.request));
321
+ Δ(IO.foreachDiscard(blockedRequests, (br) => br.result.set(completedRequests.lookup(br.request))));
322
+ Δ(
323
+ IO.foreachDiscard(leftovers, (request) =>
324
+ Ref.make(completedRequests.lookup(request)).flatMap((ref) => cache.put(request, ref)),
325
+ ),
326
+ );
327
+ }),
328
+ ),
329
+ ),
330
+ );
331
+ }