@quantform/core 0.6.6 → 0.7.0-beta.10

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 (521) hide show
  1. package/dist/as-readonly.d.ts +3 -0
  2. package/dist/as-readonly.d.ts.map +1 -0
  3. package/dist/as-readonly.js +8 -0
  4. package/dist/{domain → asset}/asset.d.ts +6 -1
  5. package/dist/asset/asset.d.ts.map +1 -0
  6. package/dist/{domain → asset}/asset.js +16 -7
  7. package/dist/asset/asset.spec.d.ts +2 -0
  8. package/dist/asset/asset.spec.d.ts.map +1 -0
  9. package/dist/asset/asset.spec.js +54 -0
  10. package/dist/asset/index.d.ts +2 -0
  11. package/dist/asset/index.d.ts.map +1 -0
  12. package/dist/{adapter/paper → asset}/index.js +1 -2
  13. package/dist/cli/build.js +1 -1
  14. package/dist/cli/dev.d.ts.map +1 -1
  15. package/dist/cli/dev.js +15 -11
  16. package/dist/cli/index.js +8 -8
  17. package/dist/cli/internal/workspace.js +1 -1
  18. package/dist/cli/pull.d.ts.map +1 -1
  19. package/dist/cli/pull.js +50 -20
  20. package/dist/cli/{test.d.ts → replay.d.ts} +1 -1
  21. package/dist/cli/replay.d.ts.map +1 -0
  22. package/dist/cli/{test.js → replay.js} +18 -20
  23. package/dist/cli/run.d.ts.map +1 -1
  24. package/dist/cli/run.js +16 -11
  25. package/dist/component/distinct-until-timesamp-changed.d.ts +5 -0
  26. package/dist/component/distinct-until-timesamp-changed.d.ts.map +1 -0
  27. package/dist/component/distinct-until-timesamp-changed.js +9 -0
  28. package/dist/component/error.d.ts +17 -0
  29. package/dist/component/error.d.ts.map +1 -0
  30. package/dist/component/error.js +33 -0
  31. package/dist/component/index.d.ts +8 -0
  32. package/dist/component/index.d.ts.map +1 -0
  33. package/dist/{store → component}/index.js +7 -9
  34. package/dist/{domain → component}/ohlc-operator.d.ts +1 -1
  35. package/dist/component/ohlc-operator.d.ts.map +1 -0
  36. package/dist/{domain → component}/ohlc-operator.js +4 -5
  37. package/dist/component/ohlc-operator.spec.d.ts +2 -0
  38. package/dist/component/ohlc-operator.spec.d.ts.map +1 -0
  39. package/dist/component/ohlc-operator.spec.js +110 -0
  40. package/dist/component/ohlc.d.ts.map +1 -0
  41. package/dist/component/ohlc.spec.d.ts +2 -0
  42. package/dist/component/ohlc.spec.d.ts.map +1 -0
  43. package/dist/component/ohlc.spec.js +25 -0
  44. package/dist/component/timeframe.d.ts.map +1 -0
  45. package/dist/core.d.ts +3 -0
  46. package/dist/core.d.ts.map +1 -0
  47. package/dist/core.js +15 -0
  48. package/dist/defined.d.ts +3 -0
  49. package/dist/defined.d.ts.map +1 -0
  50. package/dist/defined.js +8 -0
  51. package/dist/errored.d.ts +2 -0
  52. package/dist/errored.d.ts.map +1 -0
  53. package/dist/{domain/component.js → errored.js} +2 -0
  54. package/dist/exclude.d.ts +3 -0
  55. package/dist/exclude.d.ts.map +1 -0
  56. package/dist/exclude.js +8 -0
  57. package/dist/index.d.ts +25 -27
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +25 -66
  60. package/dist/{domain → instrument/commission}/commission.d.ts +1 -1
  61. package/dist/instrument/commission/commission.d.ts.map +1 -0
  62. package/dist/{domain → instrument/commission}/commission.js +2 -2
  63. package/dist/instrument/commission/commission.spec.d.ts +2 -0
  64. package/dist/instrument/commission/commission.spec.d.ts.map +1 -0
  65. package/dist/instrument/commission/commission.spec.js +30 -0
  66. package/dist/instrument/index.d.ts +3 -0
  67. package/dist/instrument/index.d.ts.map +1 -0
  68. package/dist/{adapter → instrument}/index.js +2 -4
  69. package/dist/{domain → instrument}/instrument.d.ts +4 -4
  70. package/dist/instrument/instrument.d.ts.map +1 -0
  71. package/dist/{domain → instrument}/instrument.js +8 -5
  72. package/dist/instrument/instrument.spec.d.ts +2 -0
  73. package/dist/instrument/instrument.spec.d.ts.map +1 -0
  74. package/dist/instrument/instrument.spec.js +51 -0
  75. package/dist/make-test-module.d.ts +13 -0
  76. package/dist/make-test-module.d.ts.map +1 -0
  77. package/dist/make-test-module.js +46 -0
  78. package/dist/module.d.ts +57 -0
  79. package/dist/module.d.ts.map +1 -0
  80. package/dist/module.js +136 -0
  81. package/dist/module.spec.d.ts +2 -0
  82. package/dist/module.spec.d.ts.map +1 -0
  83. package/dist/module.spec.js +86 -0
  84. package/dist/replay/index.d.ts +7 -0
  85. package/dist/replay/index.d.ts.map +1 -0
  86. package/dist/replay/index.js +22 -0
  87. package/dist/replay/use-replay-coordinator.d.ts +10 -0
  88. package/dist/replay/use-replay-coordinator.d.ts.map +1 -0
  89. package/dist/replay/use-replay-coordinator.js +119 -0
  90. package/dist/replay/use-replay-options.d.ts +15 -0
  91. package/dist/replay/use-replay-options.d.ts.map +1 -0
  92. package/dist/replay/use-replay-options.js +20 -0
  93. package/dist/replay/use-replay-reader.d.ts +7 -0
  94. package/dist/replay/use-replay-reader.d.ts.map +1 -0
  95. package/dist/replay/use-replay-reader.js +32 -0
  96. package/dist/replay/use-replay-reader.spec.d.ts +2 -0
  97. package/dist/replay/use-replay-reader.spec.d.ts.map +1 -0
  98. package/dist/replay/use-replay-reader.spec.js +58 -0
  99. package/dist/replay/use-replay-storage.d.ts +10 -0
  100. package/dist/replay/use-replay-storage.d.ts.map +1 -0
  101. package/dist/replay/use-replay-storage.js +10 -0
  102. package/dist/replay/use-replay-writer.d.ts +6 -0
  103. package/dist/replay/use-replay-writer.d.ts.map +1 -0
  104. package/dist/replay/use-replay-writer.js +14 -0
  105. package/dist/replay/use-replay-writer.spec.d.ts +2 -0
  106. package/dist/replay/use-replay-writer.spec.d.ts.map +1 -0
  107. package/dist/replay/use-replay-writer.spec.js +53 -0
  108. package/dist/replay/use-replay.d.ts +10 -0
  109. package/dist/replay/use-replay.d.ts.map +1 -0
  110. package/dist/replay/use-replay.js +32 -0
  111. package/dist/replay/use-replay.spec.d.ts +2 -0
  112. package/dist/replay/use-replay.spec.d.ts.map +1 -0
  113. package/dist/replay/use-replay.spec.js +106 -0
  114. package/dist/replay/with-replay.d.ts +4 -0
  115. package/dist/replay/with-replay.d.ts.map +1 -0
  116. package/dist/replay/with-replay.js +8 -0
  117. package/dist/session/index.d.ts +4 -0
  118. package/dist/session/index.d.ts.map +1 -0
  119. package/dist/session/index.js +19 -0
  120. package/dist/session/use-session-object.d.ts +18 -0
  121. package/dist/session/use-session-object.d.ts.map +1 -0
  122. package/dist/session/use-session-object.js +13 -0
  123. package/dist/session/use-session-storage.d.ts +2 -0
  124. package/dist/session/use-session-storage.d.ts.map +1 -0
  125. package/dist/session/use-session-storage.js +10 -0
  126. package/dist/session/use-session.d.ts +4 -0
  127. package/dist/session/use-session.d.ts.map +1 -0
  128. package/dist/session/use-session.js +7 -0
  129. package/dist/shared/datetime.d.ts +1 -1
  130. package/dist/shared/datetime.d.ts.map +1 -1
  131. package/dist/shared/decimals.d.ts.map +1 -1
  132. package/dist/shared/decimals.js +5 -0
  133. package/dist/shared/decimals.spec.d.ts +2 -0
  134. package/dist/shared/decimals.spec.d.ts.map +1 -0
  135. package/dist/shared/decimals.spec.js +28 -0
  136. package/dist/shared/index.d.ts +3 -7
  137. package/dist/shared/index.d.ts.map +1 -1
  138. package/dist/shared/index.js +3 -7
  139. package/dist/simulator/index.d.ts +2 -0
  140. package/dist/simulator/index.d.ts.map +1 -0
  141. package/dist/{adapter/backtester → simulator}/index.js +1 -2
  142. package/dist/simulator/use-simulator.d.ts +2 -0
  143. package/dist/simulator/use-simulator.d.ts.map +1 -0
  144. package/dist/simulator/use-simulator.js +9 -0
  145. package/dist/simulator/use-simulator.spec.d.ts +2 -0
  146. package/dist/simulator/use-simulator.spec.d.ts.map +1 -0
  147. package/dist/simulator/use-simulator.spec.js +49 -0
  148. package/dist/storage/in-memory/in-memory-storage.d.ts +9 -0
  149. package/dist/storage/in-memory/in-memory-storage.d.ts.map +1 -0
  150. package/dist/storage/in-memory/in-memory-storage.factory.d.ts +6 -0
  151. package/dist/storage/in-memory/in-memory-storage.factory.d.ts.map +1 -0
  152. package/dist/storage/in-memory/in-memory-storage.factory.js +23 -0
  153. package/dist/storage/in-memory/in-memory-storage.js +72 -0
  154. package/dist/storage/in-memory/in-memory-storage.spec.d.ts +2 -0
  155. package/dist/storage/in-memory/in-memory-storage.spec.d.ts.map +1 -0
  156. package/dist/storage/in-memory/in-memory-storage.spec.js +167 -0
  157. package/dist/storage/in-memory/index.d.ts +3 -0
  158. package/dist/storage/in-memory/index.d.ts.map +1 -0
  159. package/dist/storage/in-memory/index.js +18 -0
  160. package/dist/storage/index.d.ts +3 -3
  161. package/dist/storage/index.d.ts.map +1 -1
  162. package/dist/storage/index.js +3 -3
  163. package/dist/storage/storage.d.ts +51 -61
  164. package/dist/storage/storage.d.ts.map +1 -1
  165. package/dist/storage/storage.js +20 -85
  166. package/dist/storage/use-cache.d.ts +4 -0
  167. package/dist/storage/use-cache.d.ts.map +1 -0
  168. package/dist/storage/use-cache.js +34 -0
  169. package/dist/storage/use-cache.spec.d.ts +2 -0
  170. package/dist/storage/use-cache.spec.d.ts.map +1 -0
  171. package/dist/storage/use-cache.spec.js +36 -0
  172. package/dist/storage/use-storage-factory.d.ts +10 -0
  173. package/dist/storage/use-storage-factory.d.ts.map +1 -0
  174. package/dist/storage/use-storage-factory.js +14 -0
  175. package/dist/storage/use-storage.d.ts +3 -0
  176. package/dist/storage/use-storage.d.ts.map +1 -0
  177. package/dist/storage/use-storage.js +11 -0
  178. package/dist/strat.d.ts +7 -0
  179. package/dist/strat.d.ts.map +1 -0
  180. package/dist/strat.js +7 -0
  181. package/dist/use-execution-mode.d.ts +29 -0
  182. package/dist/use-execution-mode.d.ts.map +1 -0
  183. package/dist/use-execution-mode.js +37 -0
  184. package/dist/use-hash.d.ts +5 -0
  185. package/dist/use-hash.d.ts.map +1 -0
  186. package/dist/use-hash.js +7 -0
  187. package/dist/use-hash.spec.d.ts +2 -0
  188. package/dist/use-hash.spec.d.ts.map +1 -0
  189. package/dist/use-hash.spec.js +16 -0
  190. package/dist/use-lock.d.ts +9 -0
  191. package/dist/use-lock.d.ts.map +1 -0
  192. package/dist/use-lock.js +40 -0
  193. package/dist/use-logger.d.ts +10 -0
  194. package/dist/use-logger.d.ts.map +1 -0
  195. package/dist/use-logger.js +37 -0
  196. package/dist/use-memo.d.ts +21 -0
  197. package/dist/use-memo.d.ts.map +1 -0
  198. package/dist/use-memo.js +35 -0
  199. package/dist/use-memo.spec.d.ts +2 -0
  200. package/dist/use-memo.spec.d.ts.map +1 -0
  201. package/dist/use-memo.spec.js +35 -0
  202. package/dist/use-request.d.ts +16 -0
  203. package/dist/use-request.d.ts.map +1 -0
  204. package/dist/use-request.js +27 -0
  205. package/dist/use-socket.d.ts +6 -0
  206. package/dist/use-socket.d.ts.map +1 -0
  207. package/dist/use-socket.js +53 -0
  208. package/dist/use-state.d.ts +4 -0
  209. package/dist/use-state.d.ts.map +1 -0
  210. package/dist/use-state.js +24 -0
  211. package/dist/use-state.spec.d.ts +2 -0
  212. package/dist/use-state.spec.d.ts.map +1 -0
  213. package/dist/use-state.spec.js +36 -0
  214. package/dist/use-timestamp.d.ts +2 -0
  215. package/dist/use-timestamp.d.ts.map +1 -0
  216. package/dist/use-timestamp.js +13 -0
  217. package/dist/use.d.ts +5 -0
  218. package/dist/use.d.ts.map +1 -0
  219. package/dist/use.js +20 -0
  220. package/dist/use.spec.d.ts +2 -0
  221. package/dist/use.spec.d.ts.map +1 -0
  222. package/dist/use.spec.js +47 -0
  223. package/jest.config.ts +23 -2
  224. package/package.json +14 -11
  225. package/src/as-readonly.ts +5 -0
  226. package/src/{domain → asset}/asset.spec.ts +4 -4
  227. package/src/{domain → asset}/asset.ts +17 -6
  228. package/src/asset/index.ts +1 -0
  229. package/src/cli/build.ts +1 -1
  230. package/src/cli/dev.ts +18 -13
  231. package/src/cli/index.ts +7 -7
  232. package/src/cli/internal/workspace.ts +1 -1
  233. package/src/cli/pull.ts +22 -10
  234. package/src/cli/replay.ts +31 -0
  235. package/src/cli/run.ts +17 -13
  236. package/src/component/distinct-until-timesamp-changed.ts +11 -0
  237. package/src/component/error.ts +32 -0
  238. package/src/component/index.ts +7 -0
  239. package/src/{domain → component}/ohlc-operator.spec.ts +5 -6
  240. package/src/{domain → component}/ohlc-operator.ts +2 -3
  241. package/src/{domain → component}/ohlc.spec.ts +2 -2
  242. package/src/{domain → component}/ohlc.ts +2 -2
  243. package/src/core.ts +14 -0
  244. package/src/defined.ts +6 -0
  245. package/src/errored.ts +1 -0
  246. package/src/exclude.ts +9 -0
  247. package/src/index.ts +27 -80
  248. package/src/{domain → instrument/commission}/commission.spec.ts +4 -3
  249. package/src/{domain → instrument/commission}/commission.ts +1 -1
  250. package/src/instrument/index.ts +2 -0
  251. package/src/{domain → instrument}/instrument.spec.ts +11 -6
  252. package/src/{domain → instrument}/instrument.ts +12 -8
  253. package/src/make-test-module.ts +46 -0
  254. package/src/module.spec.ts +74 -0
  255. package/src/module.ts +156 -0
  256. package/src/replay/index.ts +6 -0
  257. package/src/replay/use-replay-coordinator.ts +142 -0
  258. package/src/replay/use-replay-options.ts +23 -0
  259. package/src/replay/use-replay-reader.spec.ts +64 -0
  260. package/src/replay/use-replay-reader.ts +23 -0
  261. package/src/replay/use-replay-storage.ts +8 -0
  262. package/src/replay/use-replay-writer.spec.ts +56 -0
  263. package/src/replay/use-replay-writer.ts +17 -0
  264. package/src/replay/use-replay.spec.ts +132 -0
  265. package/src/replay/use-replay.ts +34 -0
  266. package/src/replay/with-replay.ts +10 -0
  267. package/src/session/index.ts +3 -0
  268. package/src/session/use-session-object.ts +26 -0
  269. package/src/session/use-session-storage.ts +9 -0
  270. package/src/session/use-session.ts +5 -0
  271. package/src/shared/decimals.spec.ts +1 -1
  272. package/src/shared/decimals.ts +5 -0
  273. package/src/shared/index.ts +3 -7
  274. package/src/simulator/index.ts +1 -0
  275. package/src/simulator/use-simulator.spec.ts +54 -0
  276. package/src/simulator/use-simulator.ts +7 -0
  277. package/src/storage/in-memory/in-memory-storage.factory.ts +16 -0
  278. package/src/storage/in-memory/in-memory-storage.spec.ts +193 -0
  279. package/src/storage/in-memory/in-memory-storage.ts +80 -0
  280. package/src/storage/in-memory/index.ts +2 -0
  281. package/src/storage/index.ts +3 -3
  282. package/src/storage/storage.ts +63 -119
  283. package/src/storage/use-cache.spec.ts +31 -0
  284. package/src/storage/use-cache.ts +50 -0
  285. package/src/storage/use-storage-factory.ts +17 -0
  286. package/src/storage/use-storage.ts +11 -0
  287. package/src/strat.ts +7 -0
  288. package/src/use-execution-mode.ts +41 -0
  289. package/src/use-hash.spec.ts +16 -0
  290. package/src/use-hash.ts +5 -0
  291. package/src/use-lock.ts +52 -0
  292. package/src/use-logger.ts +47 -0
  293. package/src/use-memo.spec.ts +30 -0
  294. package/src/use-memo.ts +35 -0
  295. package/src/use-request.ts +47 -0
  296. package/src/use-socket.ts +60 -0
  297. package/src/use-state.spec.ts +31 -0
  298. package/src/use-state.ts +30 -0
  299. package/src/use-timestamp.ts +12 -0
  300. package/src/use.spec.ts +46 -0
  301. package/src/use.ts +33 -0
  302. package/tsconfig.json +7 -4
  303. package/dist/adapter/adapter-aggregate.d.ts +0 -57
  304. package/dist/adapter/adapter-aggregate.d.ts.map +0 -1
  305. package/dist/adapter/adapter-aggregate.js +0 -157
  306. package/dist/adapter/adapter.d.ts +0 -54
  307. package/dist/adapter/adapter.d.ts.map +0 -1
  308. package/dist/adapter/adapter.js +0 -20
  309. package/dist/adapter/backtester/backtester-adapter.d.ts +0 -30
  310. package/dist/adapter/backtester/backtester-adapter.d.ts.map +0 -1
  311. package/dist/adapter/backtester/backtester-adapter.js +0 -67
  312. package/dist/adapter/backtester/backtester-cursor.d.ts +0 -16
  313. package/dist/adapter/backtester/backtester-cursor.d.ts.map +0 -1
  314. package/dist/adapter/backtester/backtester-cursor.js +0 -52
  315. package/dist/adapter/backtester/backtester-streamer.d.ts +0 -50
  316. package/dist/adapter/backtester/backtester-streamer.d.ts.map +0 -1
  317. package/dist/adapter/backtester/backtester-streamer.js +0 -119
  318. package/dist/adapter/backtester/error.d.ts +0 -3
  319. package/dist/adapter/backtester/error.d.ts.map +0 -1
  320. package/dist/adapter/backtester/error.js +0 -11
  321. package/dist/adapter/backtester/index.d.ts +0 -3
  322. package/dist/adapter/backtester/index.d.ts.map +0 -1
  323. package/dist/adapter/error.d.ts +0 -4
  324. package/dist/adapter/error.d.ts.map +0 -1
  325. package/dist/adapter/error.js +0 -15
  326. package/dist/adapter/index.d.ts +0 -5
  327. package/dist/adapter/index.d.ts.map +0 -1
  328. package/dist/adapter/paper/engine/paper-engine.d.ts +0 -12
  329. package/dist/adapter/paper/engine/paper-engine.d.ts.map +0 -1
  330. package/dist/adapter/paper/engine/paper-engine.js +0 -109
  331. package/dist/adapter/paper/index.d.ts +0 -3
  332. package/dist/adapter/paper/index.d.ts.map +0 -1
  333. package/dist/adapter/paper/paper-adapter.d.ts +0 -30
  334. package/dist/adapter/paper/paper-adapter.d.ts.map +0 -1
  335. package/dist/adapter/paper/paper-adapter.js +0 -87
  336. package/dist/cli/error.d.ts +0 -2
  337. package/dist/cli/error.d.ts.map +0 -1
  338. package/dist/cli/error.js +0 -7
  339. package/dist/cli/test.d.ts.map +0 -1
  340. package/dist/domain/asset.d.ts.map +0 -1
  341. package/dist/domain/balance-operator.d.ts +0 -7
  342. package/dist/domain/balance-operator.d.ts.map +0 -1
  343. package/dist/domain/balance-operator.js +0 -9
  344. package/dist/domain/balance.d.ts +0 -47
  345. package/dist/domain/balance.d.ts.map +0 -1
  346. package/dist/domain/balance.js +0 -97
  347. package/dist/domain/commission.d.ts.map +0 -1
  348. package/dist/domain/component.d.ts +0 -6
  349. package/dist/domain/component.d.ts.map +0 -1
  350. package/dist/domain/error.d.ts +0 -7
  351. package/dist/domain/error.d.ts.map +0 -1
  352. package/dist/domain/error.js +0 -23
  353. package/dist/domain/index.d.ts +0 -22
  354. package/dist/domain/index.d.ts.map +0 -1
  355. package/dist/domain/index.js +0 -37
  356. package/dist/domain/instrument-operator.d.ts +0 -7
  357. package/dist/domain/instrument-operator.d.ts.map +0 -1
  358. package/dist/domain/instrument-operator.js +0 -13
  359. package/dist/domain/instrument.d.ts.map +0 -1
  360. package/dist/domain/ohlc-operator.d.ts.map +0 -1
  361. package/dist/domain/ohlc.d.ts.map +0 -1
  362. package/dist/domain/order-operator.d.ts +0 -8
  363. package/dist/domain/order-operator.d.ts.map +0 -1
  364. package/dist/domain/order-operator.js +0 -16
  365. package/dist/domain/order.d.ts +0 -24
  366. package/dist/domain/order.d.ts.map +0 -1
  367. package/dist/domain/order.js +0 -49
  368. package/dist/domain/orderbook-operator.d.ts +0 -7
  369. package/dist/domain/orderbook-operator.d.ts.map +0 -1
  370. package/dist/domain/orderbook-operator.js +0 -9
  371. package/dist/domain/orderbook.d.ts +0 -30
  372. package/dist/domain/orderbook.d.ts.map +0 -1
  373. package/dist/domain/orderbook.js +0 -20
  374. package/dist/domain/position-operator.d.ts +0 -13
  375. package/dist/domain/position-operator.d.ts.map +0 -1
  376. package/dist/domain/position-operator.js +0 -45
  377. package/dist/domain/position.d.ts +0 -18
  378. package/dist/domain/position.d.ts.map +0 -1
  379. package/dist/domain/position.js +0 -23
  380. package/dist/domain/session-builder.d.ts +0 -54
  381. package/dist/domain/session-builder.d.ts.map +0 -1
  382. package/dist/domain/session-builder.js +0 -106
  383. package/dist/domain/session.d.ts +0 -77
  384. package/dist/domain/session.d.ts.map +0 -1
  385. package/dist/domain/session.js +0 -162
  386. package/dist/domain/timeframe.d.ts.map +0 -1
  387. package/dist/domain/trade-operator.d.ts +0 -7
  388. package/dist/domain/trade-operator.d.ts.map +0 -1
  389. package/dist/domain/trade-operator.js +0 -9
  390. package/dist/domain/trade.d.ts +0 -16
  391. package/dist/domain/trade.d.ts.map +0 -1
  392. package/dist/domain/trade.js +0 -17
  393. package/dist/shared/collections.d.ts +0 -29
  394. package/dist/shared/collections.d.ts.map +0 -1
  395. package/dist/shared/collections.js +0 -123
  396. package/dist/shared/logger.d.ts +0 -8
  397. package/dist/shared/logger.d.ts.map +0 -1
  398. package/dist/shared/logger.js +0 -33
  399. package/dist/shared/pipe.d.ts +0 -5
  400. package/dist/shared/pipe.d.ts.map +0 -1
  401. package/dist/shared/pipe.js +0 -8
  402. package/dist/shared/policy.d.ts +0 -2
  403. package/dist/shared/policy.d.ts.map +0 -1
  404. package/dist/shared/policy.js +0 -8
  405. package/dist/storage/cache.d.ts +0 -10
  406. package/dist/storage/cache.d.ts.map +0 -1
  407. package/dist/storage/cache.js +0 -43
  408. package/dist/storage/feed.d.ts +0 -38
  409. package/dist/storage/feed.d.ts.map +0 -1
  410. package/dist/storage/feed.js +0 -108
  411. package/dist/storage/measurement.d.ts +0 -34
  412. package/dist/storage/measurement.d.ts.map +0 -1
  413. package/dist/storage/measurement.js +0 -59
  414. package/dist/store/error.d.ts +0 -9
  415. package/dist/store/error.d.ts.map +0 -1
  416. package/dist/store/error.js +0 -31
  417. package/dist/store/index.d.ts +0 -10
  418. package/dist/store/index.d.ts.map +0 -1
  419. package/dist/store/store-balance-event.d.ts +0 -46
  420. package/dist/store/store-balance-event.d.ts.map +0 -1
  421. package/dist/store/store-balance-event.js +0 -134
  422. package/dist/store/store-event.d.ts +0 -7
  423. package/dist/store/store-event.d.ts.map +0 -1
  424. package/dist/store/store-event.js +0 -2
  425. package/dist/store/store-instrument-event.d.ts +0 -22
  426. package/dist/store/store-instrument-event.d.ts.map +0 -1
  427. package/dist/store/store-instrument-event.js +0 -60
  428. package/dist/store/store-order-event.d.ts +0 -64
  429. package/dist/store/store-order-event.d.ts.map +0 -1
  430. package/dist/store/store-order-event.js +0 -185
  431. package/dist/store/store-orderbook-event.d.ts +0 -13
  432. package/dist/store/store-orderbook-event.d.ts.map +0 -1
  433. package/dist/store/store-orderbook-event.js +0 -43
  434. package/dist/store/store-position-event.d.ts +0 -22
  435. package/dist/store/store-position-event.d.ts.map +0 -1
  436. package/dist/store/store-position-event.js +0 -96
  437. package/dist/store/store-state.d.ts +0 -28
  438. package/dist/store/store-state.d.ts.map +0 -1
  439. package/dist/store/store-state.js +0 -29
  440. package/dist/store/store-trade-event.d.ts +0 -17
  441. package/dist/store/store-trade-event.d.ts.map +0 -1
  442. package/dist/store/store-trade-event.js +0 -34
  443. package/dist/store/store.d.ts +0 -15
  444. package/dist/store/store.d.ts.map +0 -1
  445. package/dist/store/store.js +0 -32
  446. package/src/adapter/adapter-aggregate.ts +0 -171
  447. package/src/adapter/adapter.ts +0 -83
  448. package/src/adapter/backtester/backtester-adapter.ts +0 -96
  449. package/src/adapter/backtester/backtester-cursor.spec.ts +0 -44
  450. package/src/adapter/backtester/backtester-cursor.ts +0 -47
  451. package/src/adapter/backtester/backtester-streamer.spec.ts +0 -60
  452. package/src/adapter/backtester/backtester-streamer.ts +0 -155
  453. package/src/adapter/backtester/error.ts +0 -7
  454. package/src/adapter/backtester/index.ts +0 -2
  455. package/src/adapter/error.ts +0 -13
  456. package/src/adapter/index.ts +0 -4
  457. package/src/adapter/paper/engine/paper-engine.spec.ts +0 -116
  458. package/src/adapter/paper/engine/paper-engine.ts +0 -151
  459. package/src/adapter/paper/index.ts +0 -2
  460. package/src/adapter/paper/paper-adapter.ts +0 -111
  461. package/src/cli/error.ts +0 -5
  462. package/src/cli/test.ts +0 -40
  463. package/src/domain/balance-operator.spec.ts +0 -26
  464. package/src/domain/balance-operator.ts +0 -15
  465. package/src/domain/balance.spec.ts +0 -116
  466. package/src/domain/balance.ts +0 -123
  467. package/src/domain/component.ts +0 -6
  468. package/src/domain/error.ts +0 -27
  469. package/src/domain/index.ts +0 -21
  470. package/src/domain/instrument-operator.spec.ts +0 -35
  471. package/src/domain/instrument-operator.ts +0 -25
  472. package/src/domain/order-operator.spec.ts +0 -85
  473. package/src/domain/order-operator.ts +0 -23
  474. package/src/domain/order.spec.ts +0 -43
  475. package/src/domain/order.ts +0 -68
  476. package/src/domain/orderbook-operator.spec.ts +0 -40
  477. package/src/domain/orderbook-operator.ts +0 -15
  478. package/src/domain/orderbook.spec.ts +0 -26
  479. package/src/domain/orderbook.ts +0 -30
  480. package/src/domain/position-operator.spec.ts +0 -64
  481. package/src/domain/position-operator.ts +0 -71
  482. package/src/domain/position.spec.ts +0 -43
  483. package/src/domain/position.ts +0 -31
  484. package/src/domain/session-builder.ts +0 -158
  485. package/src/domain/session.spec.ts +0 -33
  486. package/src/domain/session.ts +0 -256
  487. package/src/domain/trade-operator.spec.ts +0 -35
  488. package/src/domain/trade-operator.ts +0 -15
  489. package/src/domain/trade.spec.ts +0 -21
  490. package/src/domain/trade.ts +0 -20
  491. package/src/shared/collections.spec.ts +0 -34
  492. package/src/shared/collections.ts +0 -154
  493. package/src/shared/logger.ts +0 -39
  494. package/src/shared/pipe.ts +0 -12
  495. package/src/shared/policy.ts +0 -5
  496. package/src/storage/cache.spec.ts +0 -18
  497. package/src/storage/cache.ts +0 -37
  498. package/src/storage/feed.ts +0 -124
  499. package/src/storage/measurement.ts +0 -56
  500. package/src/store/error.ts +0 -36
  501. package/src/store/index.ts +0 -9
  502. package/src/store/store-balance-event.spec.ts +0 -30
  503. package/src/store/store-balance-event.ts +0 -167
  504. package/src/store/store-event.ts +0 -8
  505. package/src/store/store-instrument-event.spec.ts +0 -26
  506. package/src/store/store-instrument-event.ts +0 -83
  507. package/src/store/store-order-event.spec.ts +0 -32
  508. package/src/store/store-order-event.ts +0 -219
  509. package/src/store/store-orderbook-event.spec.ts +0 -39
  510. package/src/store/store-orderbook-event.ts +0 -56
  511. package/src/store/store-position-event.ts +0 -121
  512. package/src/store/store-state.ts +0 -48
  513. package/src/store/store-trade-event.spec.ts +0 -62
  514. package/src/store/store-trade-event.ts +0 -42
  515. package/src/store/store.spec.ts +0 -182
  516. package/src/store/store.ts +0 -37
  517. package/dist/{domain → component}/ohlc.d.ts +0 -0
  518. package/dist/{domain → component}/ohlc.js +0 -0
  519. package/dist/{domain → component}/timeframe.d.ts +0 -0
  520. package/dist/{domain → component}/timeframe.js +1 -1
  521. /package/src/{domain → component}/timeframe.ts +0 -0
@@ -0,0 +1,142 @@
1
+ import { defer, filter, map, Subject } from 'rxjs';
2
+
3
+ import { dependency } from '@lib/use-hash';
4
+ import { useMemo } from '@lib/use-memo';
5
+
6
+ import { between } from '..';
7
+ import { useReplayOptions } from './use-replay-options';
8
+ import { useReplayReader } from './use-replay-reader';
9
+
10
+ export function useReplayCoordinator() {
11
+ const options = useReplayOptions();
12
+
13
+ return useMemo(() => {
14
+ let timestamp = options.from;
15
+ let stopAcquire = 1;
16
+ let sequence = 0;
17
+ const subscriptions = Array.of<SampleCursor>();
18
+ const stream$ = new Subject<[SampleCursor, { timestamp: number }]>();
19
+
20
+ const subscribe = (dependencies: dependency[]) => {
21
+ const cursor = useSampleCursor(dependencies);
22
+
23
+ if (!subscriptions.includes(cursor)) {
24
+ subscriptions.push(cursor);
25
+ }
26
+
27
+ return defer(() => {
28
+ tryContinue();
29
+
30
+ return stream$.pipe(
31
+ filter(([cur]) => cur === cursor),
32
+ map(([, it]) => it)
33
+ );
34
+ });
35
+ };
36
+
37
+ const current = async () => {
38
+ let next: SampleCursor | undefined;
39
+
40
+ for (const cursor of subscriptions) {
41
+ if (cursor.size() == 0 && !cursor.completed) {
42
+ await cursor.fetchNextPage(timestamp, options.to + 1);
43
+ }
44
+
45
+ if (cursor.peek()) {
46
+ if (!next || next.peek().timestamp > cursor.peek().timestamp) {
47
+ next = cursor;
48
+ }
49
+ }
50
+ }
51
+
52
+ return next;
53
+ };
54
+
55
+ const processNext = async () => {
56
+ const cursor = await current();
57
+
58
+ if (!cursor || !cursor.peek()) {
59
+ stream$.complete();
60
+
61
+ return false;
62
+ }
63
+
64
+ const sample = cursor.dequeue();
65
+
66
+ timestamp = sample.timestamp;
67
+ sequence++;
68
+
69
+ stream$.next([cursor, sample]);
70
+
71
+ return true;
72
+ };
73
+
74
+ const next = async () => {
75
+ if (await processNext()) {
76
+ if (stopAcquire === 0) {
77
+ setImmediate(next);
78
+ }
79
+ }
80
+ };
81
+
82
+ const stop = () => stopAcquire++;
83
+ const tryContinue = () => {
84
+ if (stopAcquire == 0) {
85
+ return;
86
+ }
87
+
88
+ stopAcquire = Math.max(0, stopAcquire - 1);
89
+
90
+ if (stopAcquire != 0) {
91
+ return;
92
+ }
93
+
94
+ next();
95
+ };
96
+
97
+ return {
98
+ timestamp: () => timestamp,
99
+ stop,
100
+ tryContinue,
101
+ subscribe
102
+ };
103
+ }, [useReplayCoordinator.name]);
104
+ }
105
+
106
+ type SampleCursor = Awaited<ReturnType<typeof useSampleCursor>>;
107
+
108
+ function useSampleCursor<T>(dependencies: dependency[]) {
109
+ return useMemo(() => {
110
+ const read = useReplayReader<T>(dependencies);
111
+ let page = new Array<{ timestamp: number; payload: T }>();
112
+ let index = 0;
113
+ let completed = false;
114
+
115
+ const size = () => page.length - index;
116
+ const peek = () => page[index];
117
+ const dequeue = () => page[index++];
118
+ const fetchNextPage = async (from: number, to: number) => {
119
+ if (completed) {
120
+ return;
121
+ }
122
+
123
+ index = 0;
124
+
125
+ page = await read({
126
+ where: {
127
+ timestamp: between(from, to)
128
+ },
129
+ limit: 10000
130
+ });
131
+ completed = page.length == 0;
132
+ };
133
+
134
+ return {
135
+ size,
136
+ peek,
137
+ dequeue,
138
+ fetchNextPage,
139
+ completed
140
+ };
141
+ }, [useSampleCursor.name, ...dependencies]);
142
+ }
@@ -0,0 +1,23 @@
1
+ import { Dependency, useContext } from '@lib/module';
2
+
3
+ const injectionToken = Symbol('replay-options');
4
+
5
+ type ReplayOptions = {
6
+ from: number;
7
+ to: number;
8
+ };
9
+
10
+ /**
11
+ *
12
+ */
13
+ export function replayOptions(options: ReplayOptions): Dependency {
14
+ return {
15
+ provide: injectionToken,
16
+ useValue: options
17
+ };
18
+ }
19
+
20
+ /**
21
+ * Will return current replay execution options.
22
+ */
23
+ export const useReplayOptions = () => useContext<ReplayOptions>(injectionToken);
@@ -0,0 +1,64 @@
1
+ import { makeTestModule, mockedFunc } from '@lib/make-test-module';
2
+ import { gt, Storage } from '@lib/storage';
3
+
4
+ import { useReplayReader } from './use-replay-reader';
5
+ import { useReplayStorage } from './use-replay-storage';
6
+
7
+ jest.mock('./use-replay-storage', () => ({
8
+ ...jest.requireActual('./use-replay-storage'),
9
+ useReplayStorage: jest.fn()
10
+ }));
11
+
12
+ describe(useReplayReader.name, () => {
13
+ let fixtures: Awaited<ReturnType<typeof getFixtures>>;
14
+
15
+ beforeEach(async () => {
16
+ fixtures = await getFixtures();
17
+ });
18
+
19
+ test('read sample candle data from storage', async () => {
20
+ await fixtures.givenDataStored(fixtures.sample);
21
+ const data = await fixtures.whenDataRequested();
22
+
23
+ expect(data).toEqual(fixtures.sample);
24
+ });
25
+ });
26
+
27
+ async function getFixtures() {
28
+ const { act } = await makeTestModule([]);
29
+
30
+ const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
31
+ const query: jest.MockedFunction<Storage['query']> = jest.fn();
32
+
33
+ mockedFunc(useReplayStorage).mockReturnValue({ query } as any);
34
+
35
+ return {
36
+ sample: [
37
+ { timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
38
+ { timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
39
+ { timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
40
+ ],
41
+
42
+ givenDataStored<T>(data: { timestamp: number; payload: T }[]) {
43
+ return query.mockReturnValue(
44
+ Promise.resolve(
45
+ data.map(it => ({
46
+ kind: 'sample',
47
+ timestamp: it.timestamp,
48
+ json: JSON.stringify(it.payload)
49
+ }))
50
+ )
51
+ );
52
+ },
53
+
54
+ async whenDataRequested<T>() {
55
+ return await act(() =>
56
+ useReplayReader<T>(dependencies)({
57
+ where: {
58
+ timestamp: gt(0)
59
+ }
60
+ })
61
+ );
62
+ }
63
+ };
64
+ }
@@ -0,0 +1,23 @@
1
+ import { Query, QueryObject } from '@lib/storage';
2
+ import { dependency, useHash } from '@lib/use-hash';
3
+
4
+ import { replaySerializableObject, useReplayStorage } from './use-replay-storage';
5
+
6
+ export function useReplayReader<T>(dependencies: dependency[]) {
7
+ const storage = useReplayStorage();
8
+ const key = useHash(dependencies);
9
+
10
+ return async (query: Query<QueryObject>) =>
11
+ (
12
+ await storage.query(replaySerializableObject(key), {
13
+ where: {
14
+ timestamp: query.where?.timestamp
15
+ },
16
+ limit: query.limit,
17
+ orderBy: query.orderBy
18
+ })
19
+ ).map(it => ({
20
+ timestamp: it.timestamp,
21
+ payload: JSON.parse(it.json) as T
22
+ }));
23
+ }
@@ -0,0 +1,8 @@
1
+ import { Storage, useStorage } from '@lib/storage';
2
+
3
+ export const replaySerializableObject = (key: string) =>
4
+ Storage.createObject(key, { timestamp: 'number', json: 'string' });
5
+
6
+ export function useReplayStorage() {
7
+ return useStorage(['replay']);
8
+ }
@@ -0,0 +1,56 @@
1
+ import { makeTestModule, mockedFunc } from '@lib/make-test-module';
2
+ import { Storage } from '@lib/storage';
3
+ import { useHash } from '@lib/use-hash';
4
+
5
+ import { useReplayStorage } from './use-replay-storage';
6
+ import { useReplayWriter } from './use-replay-writer';
7
+
8
+ jest.mock('./use-replay-storage', () => ({
9
+ ...jest.requireActual('./use-replay-storage'),
10
+ useReplayStorage: jest.fn()
11
+ }));
12
+
13
+ describe.skip(useReplayWriter.name, () => {
14
+ let fixtures: Awaited<ReturnType<typeof getFixtures>>;
15
+
16
+ beforeEach(async () => {
17
+ fixtures = await getFixtures();
18
+ });
19
+
20
+ test('write sample candle data to storage', async () => {
21
+ await fixtures.whenReplayDataWritten(fixtures.sample);
22
+ await fixtures.thenReplayDataSaved(fixtures.sample);
23
+ });
24
+ });
25
+
26
+ async function getFixtures() {
27
+ const { act } = await makeTestModule([]);
28
+
29
+ const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
30
+ const save: Storage['save'] = jest.fn();
31
+
32
+ mockedFunc(useReplayStorage).mockReturnValue({ save } as any);
33
+
34
+ return {
35
+ sample: [
36
+ { timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
37
+ { timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
38
+ { timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
39
+ ],
40
+
41
+ whenReplayDataWritten<T>(data: { timestamp: number; payload: T }[]) {
42
+ return act(() => useReplayWriter(dependencies)(data));
43
+ },
44
+
45
+ async thenReplayDataSaved<T>(data: { timestamp: number; payload: T }[]) {
46
+ expect(save).toHaveBeenCalledWith(
47
+ useHash(dependencies),
48
+ data.map(it => ({
49
+ kind: 'sample',
50
+ timestamp: it.timestamp,
51
+ json: JSON.stringify(it.payload)
52
+ }))
53
+ );
54
+ }
55
+ };
56
+ }
@@ -0,0 +1,17 @@
1
+ import { dependency, useHash } from '@lib/use-hash';
2
+
3
+ import { replaySerializableObject, useReplayStorage } from './use-replay-storage';
4
+
5
+ export function useReplayWriter<T>(dependencies: dependency[]) {
6
+ const storage = useReplayStorage();
7
+ const key = useHash(dependencies);
8
+
9
+ return (samples: { timestamp: number; payload: T }[]) =>
10
+ storage.save(
11
+ replaySerializableObject(key),
12
+ samples.map(it => ({
13
+ timestamp: it.timestamp,
14
+ json: JSON.stringify(it.payload)
15
+ }))
16
+ );
17
+ }
@@ -0,0 +1,132 @@
1
+ import { from, lastValueFrom, tap } from 'rxjs';
2
+
3
+ import { makeTestModule } from '@lib/make-test-module';
4
+ import { useReplayCoordinator } from '@lib/replay/use-replay-coordinator';
5
+ import { replayExecutionMode } from '@lib/use-execution-mode';
6
+ import { dependency } from '@lib/use-hash';
7
+
8
+ import { between } from '..';
9
+ import { useReplay } from './use-replay';
10
+ import { replayOptions } from './use-replay-options';
11
+ import { useReplayReader } from './use-replay-reader';
12
+ import { useReplayWriter } from './use-replay-writer';
13
+
14
+ describe.skip(useReplayCoordinator.name, () => {
15
+ let fixtures: Awaited<ReturnType<typeof getFixtures>>;
16
+
17
+ beforeEach(async () => {
18
+ fixtures = await getFixtures();
19
+ });
20
+
21
+ test('return single data stream for single data source', async () => {
22
+ fixtures.givenRecordingEnabled(false);
23
+ await fixtures.givenSampleStored(fixtures.sample1, ['sample1']);
24
+
25
+ const sample1 = fixtures.whenUseReplayCalled(fixtures.sample1, ['sample']);
26
+ await fixtures.whenUseSampleStreamerStarted();
27
+
28
+ expect(await sample1).toEqual(fixtures.sample1);
29
+ });
30
+
31
+ test('return combined data stream for multiple data sources', async () => {
32
+ fixtures.givenRecordingEnabled(false);
33
+ await fixtures.givenSampleStored(fixtures.sample1, ['sample1']);
34
+ await fixtures.givenSampleStored(fixtures.sample2, ['sample2']);
35
+
36
+ const sample1 = fixtures.whenUseReplayCalled(fixtures.sample1, ['sample1']);
37
+ const sample2 = fixtures.whenUseReplayCalled(fixtures.sample2, ['sample2']);
38
+ await fixtures.whenUseSampleStreamerStarted();
39
+
40
+ expect(await sample1).toEqual(fixtures.sample1);
41
+ expect(await sample2).toEqual(fixtures.sample2);
42
+ });
43
+
44
+ test('record and write data stream into storage', async () => {
45
+ fixtures.givenRecordingEnabled(true);
46
+ const sample1 = await fixtures.whenUseReplayCalled(fixtures.sample1, ['sample1x']);
47
+ const sample2 = await fixtures.whenUseReplayCalled(fixtures.sample2, ['sample2x']);
48
+
49
+ fixtures.thenReplaySampleStored(sample1, ['sample1x']);
50
+ fixtures.thenReplaySampleStored(sample2, ['sample2x']);
51
+ });
52
+ });
53
+
54
+ async function getFixtures() {
55
+ const executionMode = replayExecutionMode();
56
+
57
+ const { act } = await makeTestModule([
58
+ executionMode,
59
+ replayOptions({ from: 0, to: Number.MAX_VALUE })
60
+ ]);
61
+
62
+ return {
63
+ sample1: [
64
+ { timestamp: 1, payload: { o: 111, h: 112, l: 113, c: 114 } },
65
+ { timestamp: 2, payload: { o: 121, h: 122, l: 123, c: 124 } },
66
+ { timestamp: 3, payload: { o: 131, h: 132, l: 133, c: 134 } }
67
+ ],
68
+ sample2: [
69
+ { timestamp: 1, payload: { o: 211, h: 212, l: 213, c: 214 } },
70
+ { timestamp: 2, payload: { o: 221, h: 222, l: 223, c: 224 } },
71
+ { timestamp: 3, payload: { o: 231, h: 232, l: 233, c: 234 } }
72
+ ],
73
+
74
+ givenRecordingEnabled(recording: boolean) {
75
+ executionMode.useValue.recording = recording;
76
+ },
77
+
78
+ givenSampleStored<T>(
79
+ sample: { timestamp: number; payload: T }[],
80
+ dependencies: dependency[]
81
+ ) {
82
+ return act(() => {
83
+ const writer = useReplayWriter(dependencies);
84
+
85
+ return writer(sample);
86
+ });
87
+ },
88
+
89
+ async whenUseReplayCalled<T>(
90
+ input: { timestamp: number; payload: T }[],
91
+ dependencies: dependency[]
92
+ ) {
93
+ const sample = Array.of<{ timestamp: number; payload: T }>();
94
+
95
+ await act(() =>
96
+ lastValueFrom(
97
+ useReplay<T>(from(input), dependencies).pipe(tap(it => sample.push(it)))
98
+ )
99
+ );
100
+
101
+ return sample;
102
+ },
103
+
104
+ whenUseSampleStreamerStarted() {
105
+ act(() => {
106
+ const { tryContinue } = useReplayCoordinator();
107
+
108
+ tryContinue();
109
+ });
110
+ },
111
+
112
+ async thenReplaySampleStored<T extends { timestamp: number }>(
113
+ sample: T[],
114
+ dependencies: dependency[]
115
+ ) {
116
+ const stored = await act(() => {
117
+ const reader = useReplayReader(dependencies);
118
+
119
+ return reader({
120
+ where: {
121
+ timestamp: between(
122
+ sample[0].timestamp,
123
+ sample[sample.length - 1].timestamp + 1
124
+ )
125
+ }
126
+ });
127
+ });
128
+
129
+ expect(stored).toEqual(sample);
130
+ }
131
+ };
132
+ }
@@ -0,0 +1,34 @@
1
+ import { concatMap, map, Observable } from 'rxjs';
2
+
3
+ import { useReplayCoordinator } from '@lib/replay/use-replay-coordinator';
4
+ import { useExecutionMode } from '@lib/use-execution-mode';
5
+ import { dependency } from '@lib/use-hash';
6
+
7
+ import { useReplayWriter } from './use-replay-writer';
8
+
9
+ export const useReplay = <T>(
10
+ input: Observable<{ timestamp: number; payload: T }>,
11
+ dependencies: dependency[]
12
+ ) => {
13
+ const { isReplay, recording } = useExecutionMode();
14
+
15
+ if (isReplay) {
16
+ const { subscribe } = useReplayCoordinator();
17
+
18
+ return subscribe(dependencies).pipe(
19
+ map(it => it as unknown as { timestamp: number; payload: T })
20
+ );
21
+ }
22
+
23
+ if (recording) {
24
+ const writer = useReplayWriter(dependencies);
25
+ return input.pipe(
26
+ concatMap(async it => {
27
+ await writer([it]);
28
+ return it;
29
+ })
30
+ );
31
+ }
32
+
33
+ return input;
34
+ };
@@ -0,0 +1,10 @@
1
+ import { Observable } from 'rxjs';
2
+
3
+ import { use } from '@lib/use';
4
+ import { dependency } from '@lib/use-hash';
5
+
6
+ export function withReplay<T extends Array<dependency>, U extends Observable<K>, K>(
7
+ fn: (...args: T) => U
8
+ ): (...args: T) => U {
9
+ return use(fn);
10
+ }
@@ -0,0 +1,3 @@
1
+ export * from './use-session';
2
+ export * from './use-session-object';
3
+ export * from './use-session-storage';
@@ -0,0 +1,26 @@
1
+ import { from } from 'rxjs';
2
+
3
+ import {
4
+ InferQueryObject,
5
+ Query,
6
+ QueryMappingType,
7
+ QueryObject,
8
+ Storage
9
+ } from '@lib/storage';
10
+
11
+ import { useSessionStorage } from './use-session-storage';
12
+
13
+ export const useSessionObject = <
14
+ K extends QueryObject,
15
+ T extends { [key in keyof K]: QueryMappingType }
16
+ >(
17
+ object: ReturnType<typeof Storage.createObject<K, T>>
18
+ ) => {
19
+ const storage = useSessionStorage();
20
+
21
+ return {
22
+ query: (query: Query<InferQueryObject<typeof object>>) =>
23
+ from(storage.query(object, query)),
24
+ save: (objects: InferQueryObject<typeof object>[]) => storage.save(object, objects)
25
+ };
26
+ };
@@ -0,0 +1,9 @@
1
+ import { useSession } from '@lib/session';
2
+ import { useStorage } from '@lib/storage';
3
+ import { use } from '@lib/use';
4
+
5
+ export const useSessionStorage = use(() => {
6
+ const { id } = useSession();
7
+
8
+ return useStorage(['session', id]);
9
+ });
@@ -0,0 +1,5 @@
1
+ import { use } from '@lib/use';
2
+
3
+ export const useSession = use(() => ({
4
+ id: 'ttt' //Date.now()
5
+ }));
@@ -1,4 +1,4 @@
1
- import { d } from './decimals';
1
+ import { d } from '@lib/shared';
2
2
 
3
3
  describe('decimals', () => {
4
4
  test('get precision tests', () => {
@@ -16,6 +16,11 @@ Decimal.prototype.toCeil = function (decimalPlaces: number) {
16
16
  };
17
17
 
18
18
  export class decimal extends Decimal {}
19
+ /*
20
+ decimal.prototype.toJSON = function () {
21
+ return '444';
22
+ };
23
+ */
19
24
 
20
25
  export function d(value: Decimal.Value) {
21
26
  return new decimal(value);
@@ -1,7 +1,3 @@
1
- export * from './datetime';
2
- export * from './decimals';
3
- export * from './environment';
4
- export * from './logger';
5
- export * from './policy';
6
- export * from './collections';
7
- export * from './pipe';
1
+ export * from '@lib/shared/datetime';
2
+ export * from '@lib/shared/decimals';
3
+ export * from '@lib/shared/environment';
@@ -0,0 +1 @@
1
+ export * from './use-simulator';
@@ -0,0 +1,54 @@
1
+ import { makeTestModule, mockedFunc } from '@lib/make-test-module';
2
+ import { useExecutionMode } from '@lib/use-execution-mode';
3
+
4
+ import { useSimulator } from './use-simulator';
5
+
6
+ jest.mock('@lib/use-execution-mode', () => ({
7
+ ...jest.requireActual('@lib/use-execution-mode'),
8
+ useExecutionMode: jest.fn()
9
+ }));
10
+
11
+ describe(useSimulator.name, () => {
12
+ let fixtures: Awaited<ReturnType<typeof getFixtures>>;
13
+
14
+ beforeEach(async () => {
15
+ fixtures = await getFixtures();
16
+ });
17
+
18
+ afterEach(() => fixtures.clear());
19
+
20
+ test('get real value when simulator mode disabled', () => {
21
+ const { act } = fixtures;
22
+
23
+ fixtures.givenSimulationEnabled(false);
24
+
25
+ const value = act(() => useSimulator('simulator', 'real'));
26
+
27
+ expect(value).toBe('real');
28
+ });
29
+
30
+ test('get simulation value when simulator mode enabled', () => {
31
+ const { act } = fixtures;
32
+
33
+ fixtures.givenSimulationEnabled(true);
34
+
35
+ const value = act(() => useSimulator('simulator', 'real'));
36
+
37
+ expect(value).toBe('simulator');
38
+ });
39
+ });
40
+
41
+ async function getFixtures() {
42
+ const { act } = await makeTestModule([]);
43
+
44
+ return {
45
+ act,
46
+ givenSimulationEnabled(isSimulation: boolean) {
47
+ mockedFunc(useExecutionMode).mockReturnValue({
48
+ isSimulation,
49
+ recording: false
50
+ } as any);
51
+ },
52
+ clear: jest.clearAllMocks
53
+ };
54
+ }
@@ -0,0 +1,7 @@
1
+ import { useExecutionMode } from '@lib/use-execution-mode';
2
+
3
+ export function useSimulator<T>(simulator: T, real: T) {
4
+ const { isSimulation } = useExecutionMode();
5
+
6
+ return isSimulation ? simulator : real;
7
+ }
@@ -0,0 +1,16 @@
1
+ import { provider } from '@lib/module';
2
+ import { Storage, StorageFactory } from '@lib/storage';
3
+
4
+ import { InMemoryStorage } from './in-memory-storage';
5
+
6
+ @provider()
7
+ export class InMemoryStorageFactory implements StorageFactory {
8
+ private static storage: Record<string, Storage> = {};
9
+
10
+ for(key: string): Storage {
11
+ return (
12
+ InMemoryStorageFactory.storage[key] ??
13
+ (InMemoryStorageFactory.storage[key] = new InMemoryStorage())
14
+ );
15
+ }
16
+ }