@quantform/core 0.6.7 → 0.7.0-beta.5
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.
- package/dist/as-readonly.d.ts +3 -0
- package/dist/as-readonly.d.ts.map +1 -0
- package/dist/as-readonly.js +8 -0
- package/dist/{domain → asset}/asset.d.ts +1 -0
- package/dist/asset/asset.d.ts.map +1 -0
- package/dist/{domain → asset}/asset.js +8 -5
- package/dist/{domain → asset}/asset.spec.d.ts.map +1 -1
- package/dist/{domain → asset}/asset.spec.js +12 -12
- package/dist/asset/index.d.ts +2 -0
- package/dist/asset/index.d.ts.map +1 -0
- package/dist/{adapter/paper → asset}/index.js +1 -2
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dev.js +13 -9
- package/dist/cli/index.js +4 -4
- package/dist/cli/pull.d.ts.map +1 -1
- package/dist/cli/pull.js +48 -18
- package/dist/cli/{test.d.ts → replay.d.ts} +1 -1
- package/dist/cli/replay.d.ts.map +1 -0
- package/dist/cli/{test.js → replay.js} +16 -19
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +14 -9
- package/dist/component/distinct-until-timesamp-changed.d.ts +5 -0
- package/dist/component/distinct-until-timesamp-changed.d.ts.map +1 -0
- package/dist/component/distinct-until-timesamp-changed.js +9 -0
- package/dist/{domain → component}/error.d.ts +1 -1
- package/dist/component/error.d.ts.map +1 -0
- package/dist/component/index.d.ts +8 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/{store → component}/index.js +7 -10
- package/dist/{domain → component}/ohlc-operator.d.ts +1 -1
- package/dist/component/ohlc-operator.d.ts.map +1 -0
- package/dist/{domain → component}/ohlc-operator.js +4 -4
- package/dist/component/ohlc-operator.spec.d.ts.map +1 -0
- package/dist/component/ohlc-operator.spec.js +110 -0
- package/dist/component/ohlc.d.ts.map +1 -0
- package/dist/{domain → component}/ohlc.spec.d.ts.map +1 -1
- package/dist/{domain → component}/ohlc.spec.js +3 -3
- package/dist/component/timeframe.d.ts.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +15 -0
- package/dist/defined.d.ts +3 -0
- package/dist/defined.d.ts.map +1 -0
- package/dist/defined.js +8 -0
- package/dist/exclude.d.ts +3 -0
- package/dist/exclude.d.ts.map +1 -0
- package/dist/exclude.js +8 -0
- package/dist/index.d.ts +25 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -67
- package/dist/{domain → instrument/commission}/commission.d.ts +1 -1
- package/dist/instrument/commission/commission.d.ts.map +1 -0
- package/dist/{domain → instrument/commission}/commission.js +2 -2
- package/dist/instrument/commission/commission.spec.d.ts.map +1 -0
- package/dist/{domain → instrument/commission}/commission.spec.js +6 -6
- package/dist/instrument/index.d.ts +3 -0
- package/dist/instrument/index.d.ts.map +1 -0
- package/dist/{adapter → instrument}/index.js +2 -5
- package/dist/{domain → instrument}/instrument.d.ts +4 -4
- package/dist/instrument/instrument.d.ts.map +1 -0
- package/dist/{domain → instrument}/instrument.js +11 -10
- package/dist/instrument/instrument.spec.d.ts.map +1 -0
- package/dist/{domain → instrument}/instrument.spec.js +10 -10
- package/dist/make-test-module.d.ts +13 -0
- package/dist/make-test-module.d.ts.map +1 -0
- package/dist/make-test-module.js +46 -0
- package/dist/module.d.ts +57 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +136 -0
- package/dist/module.spec.d.ts +2 -0
- package/dist/module.spec.d.ts.map +1 -0
- package/dist/module.spec.js +86 -0
- package/dist/not-found.d.ts +2 -0
- package/dist/not-found.d.ts.map +1 -0
- package/dist/{domain/component.js → not-found.js} +2 -0
- package/dist/replay/index.d.ts +7 -0
- package/dist/replay/index.d.ts.map +1 -0
- package/dist/replay/index.js +22 -0
- package/dist/replay/use-replay-coordinator.d.ts +10 -0
- package/dist/replay/use-replay-coordinator.d.ts.map +1 -0
- package/dist/replay/use-replay-coordinator.js +119 -0
- package/dist/replay/use-replay-options.d.ts +15 -0
- package/dist/replay/use-replay-options.d.ts.map +1 -0
- package/dist/replay/use-replay-options.js +20 -0
- package/dist/replay/use-replay-reader.d.ts +7 -0
- package/dist/replay/use-replay-reader.d.ts.map +1 -0
- package/dist/replay/use-replay-reader.js +32 -0
- package/dist/replay/use-replay-reader.spec.d.ts +2 -0
- package/dist/replay/use-replay-reader.spec.d.ts.map +1 -0
- package/dist/replay/use-replay-reader.spec.js +58 -0
- package/dist/replay/use-replay-storage.d.ts +10 -0
- package/dist/replay/use-replay-storage.d.ts.map +1 -0
- package/dist/replay/use-replay-storage.js +10 -0
- package/dist/replay/use-replay-writer.d.ts +6 -0
- package/dist/replay/use-replay-writer.d.ts.map +1 -0
- package/dist/replay/use-replay-writer.js +14 -0
- package/dist/replay/use-replay-writer.spec.d.ts +2 -0
- package/dist/replay/use-replay-writer.spec.d.ts.map +1 -0
- package/dist/replay/use-replay-writer.spec.js +53 -0
- package/dist/replay/use-replay.d.ts +10 -0
- package/dist/replay/use-replay.d.ts.map +1 -0
- package/dist/replay/use-replay.js +32 -0
- package/dist/replay/use-replay.spec.d.ts +2 -0
- package/dist/replay/use-replay.spec.d.ts.map +1 -0
- package/dist/replay/use-replay.spec.js +106 -0
- package/dist/replay/with-replay.d.ts +4 -0
- package/dist/replay/with-replay.d.ts.map +1 -0
- package/dist/replay/with-replay.js +8 -0
- package/dist/session/index.d.ts +4 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/{adapter/backtester → session}/index.js +3 -4
- package/dist/session/use-session-object.d.ts +18 -0
- package/dist/session/use-session-object.d.ts.map +1 -0
- package/dist/session/use-session-object.js +13 -0
- package/dist/session/use-session-storage.d.ts +2 -0
- package/dist/session/use-session-storage.d.ts.map +1 -0
- package/dist/session/use-session-storage.js +10 -0
- package/dist/session/use-session.d.ts +4 -0
- package/dist/session/use-session.d.ts.map +1 -0
- package/dist/session/use-session.js +7 -0
- package/dist/shared/datetime.d.ts +1 -1
- package/dist/shared/datetime.d.ts.map +1 -1
- package/dist/shared/decimals.d.ts.map +1 -1
- package/dist/shared/decimals.js +5 -0
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +0 -4
- package/dist/simulator/index.d.ts +2 -0
- package/dist/simulator/index.d.ts.map +1 -0
- package/dist/simulator/index.js +17 -0
- package/dist/simulator/use-simulator.d.ts +2 -0
- package/dist/simulator/use-simulator.d.ts.map +1 -0
- package/dist/simulator/use-simulator.js +9 -0
- package/dist/simulator/use-simulator.spec.d.ts +2 -0
- package/dist/simulator/use-simulator.spec.d.ts.map +1 -0
- package/dist/simulator/use-simulator.spec.js +49 -0
- package/dist/storage/in-memory/in-memory-storage.d.ts +9 -0
- package/dist/storage/in-memory/in-memory-storage.d.ts.map +1 -0
- package/dist/storage/in-memory/in-memory-storage.factory.d.ts +6 -0
- package/dist/storage/in-memory/in-memory-storage.factory.d.ts.map +1 -0
- package/dist/storage/in-memory/in-memory-storage.factory.js +23 -0
- package/dist/storage/in-memory/in-memory-storage.js +72 -0
- package/dist/storage/in-memory/in-memory-storage.spec.d.ts +2 -0
- package/dist/storage/in-memory/in-memory-storage.spec.d.ts.map +1 -0
- package/dist/storage/in-memory/in-memory-storage.spec.js +167 -0
- package/dist/storage/in-memory/index.d.ts +3 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -0
- package/dist/storage/in-memory/index.js +18 -0
- package/dist/storage/index.d.ts +4 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +4 -4
- package/dist/storage/storage.d.ts +51 -61
- package/dist/storage/storage.d.ts.map +1 -1
- package/dist/storage/storage.js +20 -85
- package/dist/storage/use-cache.d.ts +4 -0
- package/dist/storage/use-cache.d.ts.map +1 -0
- package/dist/storage/use-cache.js +34 -0
- package/dist/storage/use-cache.spec.d.ts +2 -0
- package/dist/storage/use-cache.spec.d.ts.map +1 -0
- package/dist/storage/use-cache.spec.js +36 -0
- package/dist/storage/use-storage-factory.d.ts +10 -0
- package/dist/storage/use-storage-factory.d.ts.map +1 -0
- package/dist/storage/use-storage-factory.js +14 -0
- package/dist/storage/use-storage.d.ts +3 -0
- package/dist/storage/use-storage.d.ts.map +1 -0
- package/dist/storage/use-storage.js +11 -0
- package/dist/strat.d.ts +7 -0
- package/dist/strat.d.ts.map +1 -0
- package/dist/strat.js +7 -0
- package/dist/use-execution-mode.d.ts +29 -0
- package/dist/use-execution-mode.d.ts.map +1 -0
- package/dist/use-execution-mode.js +37 -0
- package/dist/use-hash.d.ts +5 -0
- package/dist/use-hash.d.ts.map +1 -0
- package/dist/use-hash.js +7 -0
- package/dist/use-hash.spec.d.ts +2 -0
- package/dist/use-hash.spec.d.ts.map +1 -0
- package/dist/use-hash.spec.js +16 -0
- package/dist/use-lock.d.ts +9 -0
- package/dist/use-lock.d.ts.map +1 -0
- package/dist/use-lock.js +40 -0
- package/dist/{shared/logger.d.ts → use-logger.d.ts} +6 -7
- package/dist/use-logger.d.ts.map +1 -0
- package/dist/use-logger.js +37 -0
- package/dist/use-memo.d.ts +21 -0
- package/dist/use-memo.d.ts.map +1 -0
- package/dist/use-memo.js +35 -0
- package/dist/use-memo.spec.d.ts +2 -0
- package/dist/use-memo.spec.d.ts.map +1 -0
- package/dist/use-memo.spec.js +35 -0
- package/dist/use-request.d.ts +16 -0
- package/dist/use-request.d.ts.map +1 -0
- package/dist/use-request.js +27 -0
- package/dist/use-socket.d.ts +6 -0
- package/dist/use-socket.d.ts.map +1 -0
- package/dist/use-socket.js +52 -0
- package/dist/use-state.d.ts +4 -0
- package/dist/use-state.d.ts.map +1 -0
- package/dist/use-state.js +24 -0
- package/dist/use-state.spec.d.ts +2 -0
- package/dist/use-state.spec.d.ts.map +1 -0
- package/dist/use-state.spec.js +36 -0
- package/dist/use-timestamp.d.ts +2 -0
- package/dist/use-timestamp.d.ts.map +1 -0
- package/dist/use-timestamp.js +13 -0
- package/dist/use.d.ts +5 -0
- package/dist/use.d.ts.map +1 -0
- package/dist/use.js +20 -0
- package/dist/use.spec.d.ts +2 -0
- package/dist/use.spec.d.ts.map +1 -0
- package/dist/use.spec.js +47 -0
- package/package.json +13 -10
- package/src/as-readonly.ts +5 -0
- package/src/{domain → asset}/asset.spec.ts +1 -1
- package/src/{domain → asset}/asset.ts +5 -1
- package/src/asset/index.ts +1 -0
- package/src/cli/dev.ts +16 -11
- package/src/cli/index.ts +3 -3
- package/src/cli/pull.ts +20 -8
- package/src/cli/replay.ts +31 -0
- package/src/cli/run.ts +15 -11
- package/src/component/distinct-until-timesamp-changed.ts +11 -0
- package/src/{domain → component}/error.ts +1 -1
- package/src/component/index.ts +7 -0
- package/src/{domain → component}/ohlc-operator.spec.ts +1 -1
- package/src/{domain → component}/ohlc-operator.ts +1 -1
- package/src/{domain → component}/ohlc.spec.ts +1 -1
- package/src/core.ts +14 -0
- package/src/defined.ts +6 -0
- package/src/exclude.ts +9 -0
- package/src/index.ts +25 -79
- package/src/{domain → instrument/commission}/commission.spec.ts +2 -1
- package/src/instrument/index.ts +2 -0
- package/src/{domain → instrument}/instrument.spec.ts +1 -1
- package/src/{domain → instrument}/instrument.ts +9 -14
- package/src/make-test-module.ts +46 -0
- package/src/module.spec.ts +74 -0
- package/src/module.ts +156 -0
- package/src/not-found.ts +1 -0
- package/src/replay/index.ts +6 -0
- package/src/replay/use-replay-coordinator.ts +142 -0
- package/src/replay/use-replay-options.ts +23 -0
- package/src/replay/use-replay-reader.spec.ts +64 -0
- package/src/replay/use-replay-reader.ts +23 -0
- package/src/replay/use-replay-storage.ts +8 -0
- package/src/replay/use-replay-writer.spec.ts +56 -0
- package/src/replay/use-replay-writer.ts +17 -0
- package/src/replay/use-replay.spec.ts +132 -0
- package/src/replay/use-replay.ts +34 -0
- package/src/replay/with-replay.ts +10 -0
- package/src/session/index.ts +3 -0
- package/src/session/use-session-object.ts +26 -0
- package/src/session/use-session-storage.ts +9 -0
- package/src/session/use-session.ts +5 -0
- package/src/shared/decimals.ts +5 -0
- package/src/shared/index.ts +0 -4
- package/src/simulator/index.ts +1 -0
- package/src/simulator/use-simulator.spec.ts +54 -0
- package/src/simulator/use-simulator.ts +7 -0
- package/src/storage/in-memory/in-memory-storage.factory.ts +16 -0
- package/src/storage/in-memory/in-memory-storage.spec.ts +193 -0
- package/src/storage/in-memory/in-memory-storage.ts +80 -0
- package/src/storage/in-memory/index.ts +2 -0
- package/src/storage/index.ts +4 -4
- package/src/storage/storage.ts +63 -119
- package/src/storage/use-cache.spec.ts +31 -0
- package/src/storage/use-cache.ts +50 -0
- package/src/storage/use-storage-factory.ts +17 -0
- package/src/storage/use-storage.ts +11 -0
- package/src/strat.ts +7 -0
- package/src/use-execution-mode.ts +41 -0
- package/src/use-hash.spec.ts +16 -0
- package/src/use-hash.ts +5 -0
- package/src/use-lock.ts +52 -0
- package/src/use-logger.ts +47 -0
- package/src/use-memo.spec.ts +30 -0
- package/src/use-memo.ts +35 -0
- package/src/use-request.ts +47 -0
- package/src/use-socket.ts +59 -0
- package/src/use-state.spec.ts +31 -0
- package/src/use-state.ts +30 -0
- package/src/use-timestamp.ts +12 -0
- package/src/use.spec.ts +46 -0
- package/src/use.ts +33 -0
- package/dist/adapter/adapter-aggregate.d.ts +0 -57
- package/dist/adapter/adapter-aggregate.d.ts.map +0 -1
- package/dist/adapter/adapter-aggregate.js +0 -158
- package/dist/adapter/adapter.d.ts +0 -53
- package/dist/adapter/adapter.d.ts.map +0 -1
- package/dist/adapter/adapter.js +0 -20
- package/dist/adapter/backtester/backtester-adapter.d.ts +0 -26
- package/dist/adapter/backtester/backtester-adapter.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-adapter.js +0 -67
- package/dist/adapter/backtester/backtester-cursor.d.ts +0 -16
- package/dist/adapter/backtester/backtester-cursor.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-cursor.js +0 -52
- package/dist/adapter/backtester/backtester-cursor.spec.d.ts +0 -2
- package/dist/adapter/backtester/backtester-cursor.spec.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-cursor.spec.js +0 -47
- package/dist/adapter/backtester/backtester-streamer.d.ts +0 -50
- package/dist/adapter/backtester/backtester-streamer.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-streamer.js +0 -118
- package/dist/adapter/backtester/backtester-streamer.spec.d.ts +0 -2
- package/dist/adapter/backtester/backtester-streamer.spec.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-streamer.spec.js +0 -45
- package/dist/adapter/backtester/error.d.ts +0 -7
- package/dist/adapter/backtester/error.d.ts.map +0 -1
- package/dist/adapter/backtester/error.js +0 -15
- package/dist/adapter/backtester/index.d.ts +0 -5
- package/dist/adapter/backtester/index.d.ts.map +0 -1
- package/dist/adapter/error.d.ts +0 -10
- package/dist/adapter/error.d.ts.map +0 -1
- package/dist/adapter/error.js +0 -21
- package/dist/adapter/index.d.ts +0 -6
- package/dist/adapter/index.d.ts.map +0 -1
- package/dist/adapter/paper/engine/paper-engine.d.ts +0 -12
- package/dist/adapter/paper/engine/paper-engine.d.ts.map +0 -1
- package/dist/adapter/paper/engine/paper-engine.js +0 -108
- package/dist/adapter/paper/engine/paper-engine.spec.d.ts +0 -2
- package/dist/adapter/paper/engine/paper-engine.spec.d.ts.map +0 -1
- package/dist/adapter/paper/engine/paper-engine.spec.js +0 -63
- package/dist/adapter/paper/index.d.ts +0 -3
- package/dist/adapter/paper/index.d.ts.map +0 -1
- package/dist/adapter/paper/paper-adapter.d.ts +0 -28
- package/dist/adapter/paper/paper-adapter.d.ts.map +0 -1
- package/dist/adapter/paper/paper-adapter.js +0 -88
- package/dist/cli/test.d.ts.map +0 -1
- package/dist/domain/asset.d.ts.map +0 -1
- package/dist/domain/balance-operator.d.ts +0 -5
- package/dist/domain/balance-operator.d.ts.map +0 -1
- package/dist/domain/balance-operator.js +0 -9
- package/dist/domain/balance-operator.spec.d.ts +0 -2
- package/dist/domain/balance-operator.spec.d.ts.map +0 -1
- package/dist/domain/balance-operator.spec.js +0 -21
- package/dist/domain/balance.d.ts +0 -46
- package/dist/domain/balance.d.ts.map +0 -1
- package/dist/domain/balance.js +0 -79
- package/dist/domain/balance.spec.d.ts +0 -2
- package/dist/domain/balance.spec.d.ts.map +0 -1
- package/dist/domain/balance.spec.js +0 -32
- package/dist/domain/commission.d.ts.map +0 -1
- package/dist/domain/commission.spec.d.ts.map +0 -1
- package/dist/domain/component.d.ts +0 -6
- package/dist/domain/component.d.ts.map +0 -1
- package/dist/domain/error.d.ts.map +0 -1
- package/dist/domain/index.d.ts +0 -22
- package/dist/domain/index.d.ts.map +0 -1
- package/dist/domain/index.js +0 -37
- package/dist/domain/instrument-operator.d.ts +0 -6
- package/dist/domain/instrument-operator.d.ts.map +0 -1
- package/dist/domain/instrument-operator.js +0 -13
- package/dist/domain/instrument-operator.spec.d.ts +0 -2
- package/dist/domain/instrument-operator.spec.d.ts.map +0 -1
- package/dist/domain/instrument-operator.spec.js +0 -21
- package/dist/domain/instrument.d.ts.map +0 -1
- package/dist/domain/instrument.spec.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.spec.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.spec.js +0 -110
- package/dist/domain/ohlc.d.ts.map +0 -1
- package/dist/domain/order-operator.d.ts +0 -6
- package/dist/domain/order-operator.d.ts.map +0 -1
- package/dist/domain/order-operator.js +0 -16
- package/dist/domain/order-operator.spec.d.ts +0 -2
- package/dist/domain/order-operator.spec.d.ts.map +0 -1
- package/dist/domain/order-operator.spec.js +0 -61
- package/dist/domain/order.d.ts +0 -21
- package/dist/domain/order.d.ts.map +0 -1
- package/dist/domain/order.js +0 -41
- package/dist/domain/order.spec.d.ts +0 -2
- package/dist/domain/order.spec.d.ts.map +0 -1
- package/dist/domain/order.spec.js +0 -27
- package/dist/domain/orderbook-operator.d.ts +0 -5
- package/dist/domain/orderbook-operator.d.ts.map +0 -1
- package/dist/domain/orderbook-operator.js +0 -9
- package/dist/domain/orderbook-operator.spec.d.ts +0 -2
- package/dist/domain/orderbook-operator.spec.d.ts.map +0 -1
- package/dist/domain/orderbook-operator.spec.js +0 -19
- package/dist/domain/orderbook.d.ts +0 -31
- package/dist/domain/orderbook.d.ts.map +0 -1
- package/dist/domain/orderbook.js +0 -23
- package/dist/domain/orderbook.spec.d.ts +0 -2
- package/dist/domain/orderbook.spec.d.ts.map +0 -1
- package/dist/domain/orderbook.spec.js +0 -11
- package/dist/domain/position-operator.d.ts +0 -11
- package/dist/domain/position-operator.d.ts.map +0 -1
- package/dist/domain/position-operator.js +0 -44
- package/dist/domain/position-operator.spec.d.ts +0 -2
- package/dist/domain/position-operator.spec.d.ts.map +0 -1
- package/dist/domain/position-operator.spec.js +0 -44
- package/dist/domain/position.d.ts +0 -19
- package/dist/domain/position.d.ts.map +0 -1
- package/dist/domain/position.js +0 -25
- package/dist/domain/position.spec.d.ts +0 -2
- package/dist/domain/position.spec.d.ts.map +0 -1
- package/dist/domain/position.spec.js +0 -28
- package/dist/domain/session-builder.d.ts +0 -58
- package/dist/domain/session-builder.d.ts.map +0 -1
- package/dist/domain/session-builder.js +0 -101
- package/dist/domain/session.d.ts +0 -77
- package/dist/domain/session.d.ts.map +0 -1
- package/dist/domain/session.js +0 -156
- package/dist/domain/session.spec.d.ts +0 -2
- package/dist/domain/session.spec.d.ts.map +0 -1
- package/dist/domain/session.spec.js +0 -17
- package/dist/domain/timeframe.d.ts.map +0 -1
- package/dist/domain/trade-operator.d.ts +0 -5
- package/dist/domain/trade-operator.d.ts.map +0 -1
- package/dist/domain/trade-operator.js +0 -9
- package/dist/domain/trade-operator.spec.d.ts +0 -2
- package/dist/domain/trade-operator.spec.d.ts.map +0 -1
- package/dist/domain/trade-operator.spec.js +0 -21
- package/dist/domain/trade.d.ts +0 -17
- package/dist/domain/trade.d.ts.map +0 -1
- package/dist/domain/trade.js +0 -20
- package/dist/domain/trade.spec.d.ts +0 -2
- package/dist/domain/trade.spec.d.ts.map +0 -1
- package/dist/domain/trade.spec.js +0 -11
- package/dist/shared/collections.d.ts +0 -29
- package/dist/shared/collections.d.ts.map +0 -1
- package/dist/shared/collections.js +0 -123
- package/dist/shared/collections.spec.d.ts +0 -2
- package/dist/shared/collections.spec.d.ts.map +0 -1
- package/dist/shared/collections.spec.js +0 -29
- package/dist/shared/hash.d.ts +0 -2
- package/dist/shared/hash.d.ts.map +0 -1
- package/dist/shared/hash.js +0 -12
- package/dist/shared/logger.d.ts.map +0 -1
- package/dist/shared/logger.js +0 -40
- package/dist/shared/policy.d.ts +0 -2
- package/dist/shared/policy.d.ts.map +0 -1
- package/dist/shared/policy.js +0 -8
- package/dist/storage/cache.d.ts +0 -10
- package/dist/storage/cache.d.ts.map +0 -1
- package/dist/storage/cache.js +0 -43
- package/dist/storage/cache.spec.d.ts +0 -2
- package/dist/storage/cache.spec.d.ts.map +0 -1
- package/dist/storage/cache.spec.js +0 -25
- package/dist/storage/feed.d.ts +0 -38
- package/dist/storage/feed.d.ts.map +0 -1
- package/dist/storage/feed.js +0 -108
- package/dist/storage/measurement.d.ts +0 -34
- package/dist/storage/measurement.d.ts.map +0 -1
- package/dist/storage/measurement.js +0 -59
- package/dist/store/error.d.ts +0 -23
- package/dist/store/error.d.ts.map +0 -1
- package/dist/store/error.js +0 -45
- package/dist/store/index.d.ts +0 -11
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/store-balance-event.d.ts +0 -26
- package/dist/store/store-balance-event.d.ts.map +0 -1
- package/dist/store/store-balance-event.js +0 -59
- package/dist/store/store-balance-event.spec.d.ts +0 -2
- package/dist/store/store-balance-event.spec.d.ts.map +0 -1
- package/dist/store/store-balance-event.spec.js +0 -24
- package/dist/store/store-event.d.ts +0 -7
- package/dist/store/store-event.d.ts.map +0 -1
- package/dist/store/store-event.js +0 -2
- package/dist/store/store-instrument-event.d.ts +0 -21
- package/dist/store/store-instrument-event.d.ts.map +0 -1
- package/dist/store/store-instrument-event.js +0 -59
- package/dist/store/store-instrument-event.spec.d.ts +0 -2
- package/dist/store/store-instrument-event.spec.d.ts.map +0 -1
- package/dist/store/store-instrument-event.spec.js +0 -22
- package/dist/store/store-order-event.d.ts +0 -63
- package/dist/store/store-order-event.d.ts.map +0 -1
- package/dist/store/store-order-event.js +0 -223
- package/dist/store/store-order-event.spec.d.ts +0 -2
- package/dist/store/store-order-event.spec.d.ts.map +0 -1
- package/dist/store/store-order-event.spec.js +0 -23
- package/dist/store/store-orderbook-event.d.ts +0 -12
- package/dist/store/store-orderbook-event.d.ts.map +0 -1
- package/dist/store/store-orderbook-event.js +0 -43
- package/dist/store/store-orderbook-event.spec.d.ts +0 -2
- package/dist/store/store-orderbook-event.spec.d.ts.map +0 -1
- package/dist/store/store-orderbook-event.spec.js +0 -27
- package/dist/store/store-position-event.d.ts +0 -21
- package/dist/store/store-position-event.d.ts.map +0 -1
- package/dist/store/store-position-event.js +0 -96
- package/dist/store/store-state.d.ts +0 -28
- package/dist/store/store-state.d.ts.map +0 -1
- package/dist/store/store-state.js +0 -29
- package/dist/store/store-trade-event.d.ts +0 -16
- package/dist/store/store-trade-event.d.ts.map +0 -1
- package/dist/store/store-trade-event.js +0 -34
- package/dist/store/store-trade-event.spec.d.ts +0 -2
- package/dist/store/store-trade-event.spec.d.ts.map +0 -1
- package/dist/store/store-trade-event.spec.js +0 -44
- package/dist/store/store.d.ts +0 -14
- package/dist/store/store.d.ts.map +0 -1
- package/dist/store/store.js +0 -35
- package/dist/store/store.spec.d.ts +0 -2
- package/dist/store/store.spec.d.ts.map +0 -1
- package/dist/store/store.spec.js +0 -122
- package/src/adapter/adapter-aggregate.ts +0 -185
- package/src/adapter/adapter.ts +0 -82
- package/src/adapter/backtester/backtester-adapter.ts +0 -100
- package/src/adapter/backtester/backtester-cursor.spec.ts +0 -44
- package/src/adapter/backtester/backtester-cursor.ts +0 -47
- package/src/adapter/backtester/backtester-streamer.spec.ts +0 -60
- package/src/adapter/backtester/backtester-streamer.ts +0 -158
- package/src/adapter/backtester/error.ts +0 -11
- package/src/adapter/backtester/index.ts +0 -4
- package/src/adapter/error.ts +0 -19
- package/src/adapter/index.ts +0 -5
- package/src/adapter/paper/engine/paper-engine.spec.ts +0 -110
- package/src/adapter/paper/engine/paper-engine.ts +0 -136
- package/src/adapter/paper/index.ts +0 -2
- package/src/adapter/paper/paper-adapter.ts +0 -118
- package/src/cli/test.ts +0 -41
- package/src/domain/balance-operator.spec.ts +0 -23
- package/src/domain/balance-operator.ts +0 -14
- package/src/domain/balance.spec.ts +0 -46
- package/src/domain/balance.ts +0 -110
- package/src/domain/component.ts +0 -6
- package/src/domain/index.ts +0 -21
- package/src/domain/instrument-operator.spec.ts +0 -38
- package/src/domain/instrument-operator.ts +0 -25
- package/src/domain/order-operator.spec.ts +0 -89
- package/src/domain/order-operator.ts +0 -24
- package/src/domain/order.spec.ts +0 -40
- package/src/domain/order.ts +0 -65
- package/src/domain/orderbook-operator.spec.ts +0 -42
- package/src/domain/orderbook-operator.ts +0 -14
- package/src/domain/orderbook.spec.ts +0 -23
- package/src/domain/orderbook.ts +0 -32
- package/src/domain/position-operator.spec.ts +0 -67
- package/src/domain/position-operator.ts +0 -74
- package/src/domain/position.spec.ts +0 -40
- package/src/domain/position.ts +0 -33
- package/src/domain/session-builder.ts +0 -158
- package/src/domain/session.spec.ts +0 -33
- package/src/domain/session.ts +0 -261
- package/src/domain/trade-operator.spec.ts +0 -30
- package/src/domain/trade-operator.ts +0 -14
- package/src/domain/trade.spec.ts +0 -18
- package/src/domain/trade.ts +0 -22
- package/src/shared/collections.spec.ts +0 -34
- package/src/shared/collections.ts +0 -154
- package/src/shared/hash.ts +0 -10
- package/src/shared/logger.ts +0 -46
- package/src/shared/policy.ts +0 -5
- package/src/storage/cache.spec.ts +0 -17
- package/src/storage/cache.ts +0 -37
- package/src/storage/feed.ts +0 -124
- package/src/storage/measurement.ts +0 -56
- package/src/store/error.ts +0 -47
- package/src/store/index.ts +0 -10
- package/src/store/store-balance-event.spec.ts +0 -28
- package/src/store/store-balance-event.ts +0 -72
- package/src/store/store-event.ts +0 -8
- package/src/store/store-instrument-event.spec.ts +0 -25
- package/src/store/store-instrument-event.ts +0 -87
- package/src/store/store-order-event.spec.ts +0 -33
- package/src/store/store-order-event.ts +0 -288
- package/src/store/store-orderbook-event.spec.ts +0 -38
- package/src/store/store-orderbook-event.ts +0 -60
- package/src/store/store-position-event.ts +0 -125
- package/src/store/store-state.ts +0 -48
- package/src/store/store-trade-event.spec.ts +0 -61
- package/src/store/store-trade-event.ts +0 -46
- package/src/store/store.spec.ts +0 -196
- package/src/store/store.ts +0 -40
- package/dist/{domain → asset}/asset.spec.d.ts +0 -0
- package/dist/{domain → component}/error.js +0 -0
- package/dist/{domain → component}/ohlc-operator.spec.d.ts +0 -0
- package/dist/{domain → component}/ohlc.d.ts +0 -0
- package/dist/{domain → component}/ohlc.js +0 -0
- package/dist/{domain → component}/ohlc.spec.d.ts +0 -0
- package/dist/{domain → component}/timeframe.d.ts +0 -0
- package/dist/{domain → component}/timeframe.js +1 -1
- /package/dist/{domain → instrument/commission}/commission.spec.d.ts +0 -0
- /package/dist/{domain → instrument}/instrument.spec.d.ts +0 -0
- /package/src/{domain → component}/ohlc.ts +0 -0
- /package/src/{domain → component}/timeframe.ts +0 -0
- /package/src/{domain → instrument/commission}/commission.ts +0 -0
|
@@ -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,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
|
+
};
|
package/src/shared/decimals.ts
CHANGED
|
@@ -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);
|
package/src/shared/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
export * from '@lib/shared/datetime';
|
|
2
2
|
export * from '@lib/shared/decimals';
|
|
3
3
|
export * from '@lib/shared/environment';
|
|
4
|
-
export * from '@lib/shared/logger';
|
|
5
|
-
export * from '@lib/shared/policy';
|
|
6
|
-
export * from '@lib/shared/collections';
|
|
7
|
-
export * from '@lib/shared/hash';
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { d } from '@lib/shared';
|
|
2
|
+
import { eq, gt, lt, Storage } from '@lib/storage';
|
|
3
|
+
|
|
4
|
+
import { InMemoryStorage } from './in-memory-storage';
|
|
5
|
+
|
|
6
|
+
describe(InMemoryStorage.name, () => {
|
|
7
|
+
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
fixtures = await getFixtures();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('read empty storage', async () => {
|
|
14
|
+
const { sut } = fixtures;
|
|
15
|
+
|
|
16
|
+
const pricing = Storage.createObject('pricing', {
|
|
17
|
+
timestamp: 'number',
|
|
18
|
+
rate: 'decimal'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const set = await sut.query(pricing, {});
|
|
22
|
+
|
|
23
|
+
expect(set).toEqual([]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('save and read full data', async () => {
|
|
27
|
+
const { sut } = fixtures;
|
|
28
|
+
|
|
29
|
+
const pricing = Storage.createObject('pricing', {
|
|
30
|
+
timestamp: 'number',
|
|
31
|
+
rate: 'decimal'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await sut.save(pricing, [
|
|
35
|
+
{ timestamp: 1, rate: d(1) },
|
|
36
|
+
{ timestamp: 2, rate: d(2) },
|
|
37
|
+
{ timestamp: 3, rate: d(3) },
|
|
38
|
+
{ timestamp: 4, rate: d(4) },
|
|
39
|
+
{ timestamp: 5, rate: d(5) }
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const set = await sut.query(pricing, {});
|
|
43
|
+
|
|
44
|
+
expect(set).toEqual([
|
|
45
|
+
{ timestamp: 1, rate: d(1) },
|
|
46
|
+
{ timestamp: 2, rate: d(2) },
|
|
47
|
+
{ timestamp: 3, rate: d(3) },
|
|
48
|
+
{ timestamp: 4, rate: d(4) },
|
|
49
|
+
{ timestamp: 5, rate: d(5) }
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('save and read limited data', async () => {
|
|
54
|
+
const { sut } = fixtures;
|
|
55
|
+
|
|
56
|
+
const pricing = Storage.createObject('pricing', {
|
|
57
|
+
timestamp: 'number',
|
|
58
|
+
rate: 'decimal'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await sut.save(pricing, [
|
|
62
|
+
{ timestamp: 1, rate: d(1) },
|
|
63
|
+
{ timestamp: 2, rate: d(2) },
|
|
64
|
+
{ timestamp: 3, rate: d(3) },
|
|
65
|
+
{ timestamp: 4, rate: d(4) },
|
|
66
|
+
{ timestamp: 5, rate: d(5) }
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
const set = await sut.query(pricing, { limit: 3 });
|
|
70
|
+
|
|
71
|
+
expect(set).toEqual([
|
|
72
|
+
{ timestamp: 1, rate: d(1) },
|
|
73
|
+
{ timestamp: 2, rate: d(2) },
|
|
74
|
+
{ timestamp: 3, rate: d(3) }
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('save and read desc ordered data', async () => {
|
|
79
|
+
const { sut } = fixtures;
|
|
80
|
+
|
|
81
|
+
const pricing = Storage.createObject('pricing', {
|
|
82
|
+
timestamp: 'number',
|
|
83
|
+
rate: 'decimal'
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await sut.save(pricing, [
|
|
87
|
+
{ timestamp: 1, rate: d(1) },
|
|
88
|
+
{ timestamp: 2, rate: d(2) },
|
|
89
|
+
{ timestamp: 3, rate: d(3) },
|
|
90
|
+
{ timestamp: 4, rate: d(4) },
|
|
91
|
+
{ timestamp: 5, rate: d(5) }
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const set = await sut.query(pricing, { orderBy: 'DESC' });
|
|
95
|
+
|
|
96
|
+
expect(set).toEqual([
|
|
97
|
+
{ timestamp: 5, rate: d(5) },
|
|
98
|
+
{ timestamp: 4, rate: d(4) },
|
|
99
|
+
{ timestamp: 3, rate: d(3) },
|
|
100
|
+
{ timestamp: 2, rate: d(2) },
|
|
101
|
+
{ timestamp: 1, rate: d(1) }
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('save and read filtered eq data', async () => {
|
|
106
|
+
const { sut } = fixtures;
|
|
107
|
+
|
|
108
|
+
const pricing = Storage.createObject('pricing', {
|
|
109
|
+
timestamp: 'number',
|
|
110
|
+
rate: 'decimal'
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
await sut.save(pricing, [
|
|
114
|
+
{ timestamp: 1, rate: d(1) },
|
|
115
|
+
{ timestamp: 2, rate: d(2) },
|
|
116
|
+
{ timestamp: 3, rate: d(3) },
|
|
117
|
+
{ timestamp: 4, rate: d(4) },
|
|
118
|
+
{ timestamp: 5, rate: d(5) }
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
const set = await sut.query(pricing, {
|
|
122
|
+
where: {
|
|
123
|
+
timestamp: eq(4)
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(set).toEqual([{ timestamp: 4, rate: d(4) }]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('save and read filtered lt data', async () => {
|
|
131
|
+
const { sut } = fixtures;
|
|
132
|
+
|
|
133
|
+
const pricing = Storage.createObject('pricing', {
|
|
134
|
+
timestamp: 'number',
|
|
135
|
+
rate: 'decimal'
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await sut.save(pricing, [
|
|
139
|
+
{ timestamp: 1, rate: d(1) },
|
|
140
|
+
{ timestamp: 2, rate: d(2) },
|
|
141
|
+
{ timestamp: 3, rate: d(3) },
|
|
142
|
+
{ timestamp: 4, rate: d(4) },
|
|
143
|
+
{ timestamp: 5, rate: d(5) }
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
const set = await sut.query(pricing, {
|
|
147
|
+
where: {
|
|
148
|
+
timestamp: lt(3)
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(set).toEqual([
|
|
153
|
+
{ timestamp: 1, rate: d(1) },
|
|
154
|
+
{ timestamp: 2, rate: d(2) }
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('save and read filtered gt data', async () => {
|
|
159
|
+
const { sut } = fixtures;
|
|
160
|
+
|
|
161
|
+
const pricing = Storage.createObject('pricing', {
|
|
162
|
+
timestamp: 'number',
|
|
163
|
+
rate: 'decimal'
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
await sut.save(pricing, [
|
|
167
|
+
{ timestamp: 1, rate: d(1) },
|
|
168
|
+
{ timestamp: 2, rate: d(2) },
|
|
169
|
+
{ timestamp: 3, rate: d(3) },
|
|
170
|
+
{ timestamp: 4, rate: d(4) },
|
|
171
|
+
{ timestamp: 5, rate: d(5) }
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
const set = await sut.query(pricing, {
|
|
175
|
+
where: {
|
|
176
|
+
timestamp: gt(3)
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
expect(set).toEqual([
|
|
181
|
+
{ timestamp: 4, rate: d(4) },
|
|
182
|
+
{ timestamp: 5, rate: d(5) }
|
|
183
|
+
]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
async function getFixtures() {
|
|
188
|
+
const sut = new InMemoryStorage();
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
sut
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InferQueryObject,
|
|
3
|
+
Query,
|
|
4
|
+
QueryObject,
|
|
5
|
+
QueryObjectType,
|
|
6
|
+
Storage
|
|
7
|
+
} from '@lib/storage';
|
|
8
|
+
|
|
9
|
+
export class InMemoryStorage implements Storage {
|
|
10
|
+
private tables: Record<string, QueryObject[]> = {};
|
|
11
|
+
|
|
12
|
+
async index(): Promise<Array<string>> {
|
|
13
|
+
return Object.keys(this.tables);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async query<T extends QueryObjectType<K>, K extends QueryObject>(
|
|
17
|
+
type: T,
|
|
18
|
+
query: Query<InferQueryObject<T>>
|
|
19
|
+
): Promise<InferQueryObject<T>[]> {
|
|
20
|
+
if (!this.tables[type.discriminator]) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let set = this.tables[type.discriminator];
|
|
25
|
+
|
|
26
|
+
if (query.where) {
|
|
27
|
+
for (const prop of Object.keys(query.where)) {
|
|
28
|
+
const expression = query.where[prop];
|
|
29
|
+
|
|
30
|
+
switch (expression?.type) {
|
|
31
|
+
case 'eq':
|
|
32
|
+
set = set.filter(it => it[prop] === expression.value);
|
|
33
|
+
break;
|
|
34
|
+
case 'gt':
|
|
35
|
+
set = set.filter(it => +it[prop] > expression.value);
|
|
36
|
+
break;
|
|
37
|
+
case 'lt':
|
|
38
|
+
set = set.filter(it => +it[prop] < expression.value);
|
|
39
|
+
break;
|
|
40
|
+
case 'between':
|
|
41
|
+
set = set.filter(
|
|
42
|
+
it => +it[prop] > expression.min && +it[prop] < expression.max
|
|
43
|
+
);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (query.limit) {
|
|
50
|
+
set = set.slice(0, query.limit);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (query.orderBy === 'DESC') {
|
|
54
|
+
set = set.reverse();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return set as InferQueryObject<T>[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async save<T extends QueryObjectType<K>, K extends QueryObject>(
|
|
61
|
+
type: T,
|
|
62
|
+
objects: InferQueryObject<T>[]
|
|
63
|
+
): Promise<void> {
|
|
64
|
+
if (!this.tables[type.discriminator]) {
|
|
65
|
+
this.tables[type.discriminator] = [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const buffer = this.tables[type.discriminator];
|
|
69
|
+
|
|
70
|
+
for (const document of objects) {
|
|
71
|
+
buffer.push(document);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
buffer.sort((lhs, rhs) => lhs.timestamp - rhs.timestamp);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
clear() {
|
|
78
|
+
this.tables = {};
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/storage/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
1
|
+
export * from './storage';
|
|
2
|
+
export * from './use-storage';
|
|
3
|
+
export * from './use-storage-factory';
|
|
4
|
+
export * from './in-memory';
|