@quantform/core 0.6.6 → 0.7.0-beta.4
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 +6 -1
- package/dist/asset/asset.d.ts.map +1 -0
- package/dist/{domain → asset}/asset.js +16 -7
- package/dist/asset/asset.spec.d.ts +2 -0
- package/dist/asset/asset.spec.d.ts.map +1 -0
- package/dist/asset/asset.spec.js +54 -0
- 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/build.js +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dev.js +15 -11
- package/dist/cli/index.js +8 -8
- package/dist/cli/internal/workspace.js +1 -1
- package/dist/cli/pull.d.ts.map +1 -1
- package/dist/cli/pull.js +50 -20
- 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} +18 -20
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +16 -11
- 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/component/error.d.ts +17 -0
- package/dist/component/error.d.ts.map +1 -0
- package/dist/component/error.js +33 -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 -9
- 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 -5
- package/dist/component/ohlc-operator.spec.d.ts +2 -0
- 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/component/ohlc.spec.d.ts +2 -0
- package/dist/component/ohlc.spec.d.ts.map +1 -0
- package/dist/component/ohlc.spec.js +25 -0
- 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 -66
- 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 +2 -0
- package/dist/instrument/commission/commission.spec.d.ts.map +1 -0
- package/dist/instrument/commission/commission.spec.js +30 -0
- package/dist/instrument/index.d.ts +3 -0
- package/dist/instrument/index.d.ts.map +1 -0
- package/dist/{adapter → instrument}/index.js +2 -4
- package/dist/{domain → instrument}/instrument.d.ts +4 -4
- package/dist/instrument/instrument.d.ts.map +1 -0
- package/dist/{domain → instrument}/instrument.js +8 -5
- package/dist/instrument/instrument.spec.d.ts +2 -0
- package/dist/instrument/instrument.spec.d.ts.map +1 -0
- package/dist/instrument/instrument.spec.js +51 -0
- 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/session/index.js +19 -0
- 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/decimals.spec.d.ts +2 -0
- package/dist/shared/decimals.spec.d.ts.map +1 -0
- package/dist/shared/decimals.spec.js +28 -0
- package/dist/shared/index.d.ts +3 -7
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +3 -7
- package/dist/simulator/index.d.ts +2 -0
- package/dist/simulator/index.d.ts.map +1 -0
- package/dist/{adapter/backtester → simulator}/index.js +1 -2
- 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 +3 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +3 -3
- 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/use-logger.d.ts +10 -0
- 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/jest.config.ts +23 -2
- package/package.json +14 -11
- package/src/as-readonly.ts +5 -0
- package/src/{domain → asset}/asset.spec.ts +4 -4
- package/src/{domain → asset}/asset.ts +17 -6
- package/src/asset/index.ts +1 -0
- package/src/cli/build.ts +1 -1
- package/src/cli/dev.ts +18 -13
- package/src/cli/index.ts +7 -7
- package/src/cli/internal/workspace.ts +1 -1
- package/src/cli/pull.ts +22 -10
- package/src/cli/replay.ts +31 -0
- package/src/cli/run.ts +17 -13
- package/src/component/distinct-until-timesamp-changed.ts +11 -0
- package/src/component/error.ts +32 -0
- package/src/component/index.ts +7 -0
- package/src/{domain → component}/ohlc-operator.spec.ts +5 -6
- package/src/{domain → component}/ohlc-operator.ts +2 -3
- package/src/{domain → component}/ohlc.spec.ts +2 -2
- package/src/{domain → component}/ohlc.ts +2 -2
- package/src/core.ts +14 -0
- package/src/defined.ts +6 -0
- package/src/exclude.ts +9 -0
- package/src/index.ts +27 -80
- package/src/{domain → instrument/commission}/commission.spec.ts +4 -3
- package/src/{domain → instrument/commission}/commission.ts +1 -1
- package/src/instrument/index.ts +2 -0
- package/src/{domain → instrument}/instrument.spec.ts +11 -6
- package/src/{domain → instrument}/instrument.ts +12 -8
- 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.spec.ts +1 -1
- package/src/shared/decimals.ts +5 -0
- package/src/shared/index.ts +3 -7
- 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 +3 -3
- 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/tsconfig.json +7 -4
- 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 -157
- package/dist/adapter/adapter.d.ts +0 -54
- 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 -30
- 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-streamer.d.ts +0 -50
- package/dist/adapter/backtester/backtester-streamer.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-streamer.js +0 -119
- package/dist/adapter/backtester/error.d.ts +0 -3
- package/dist/adapter/backtester/error.d.ts.map +0 -1
- package/dist/adapter/backtester/error.js +0 -11
- package/dist/adapter/backtester/index.d.ts +0 -3
- package/dist/adapter/backtester/index.d.ts.map +0 -1
- package/dist/adapter/error.d.ts +0 -4
- package/dist/adapter/error.d.ts.map +0 -1
- package/dist/adapter/error.js +0 -15
- package/dist/adapter/index.d.ts +0 -5
- 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 -109
- 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 -30
- package/dist/adapter/paper/paper-adapter.d.ts.map +0 -1
- package/dist/adapter/paper/paper-adapter.js +0 -87
- package/dist/cli/error.d.ts +0 -2
- package/dist/cli/error.d.ts.map +0 -1
- package/dist/cli/error.js +0 -7
- 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 -7
- package/dist/domain/balance-operator.d.ts.map +0 -1
- package/dist/domain/balance-operator.js +0 -9
- package/dist/domain/balance.d.ts +0 -47
- package/dist/domain/balance.d.ts.map +0 -1
- package/dist/domain/balance.js +0 -97
- package/dist/domain/commission.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 +0 -7
- package/dist/domain/error.d.ts.map +0 -1
- package/dist/domain/error.js +0 -23
- 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 -7
- package/dist/domain/instrument-operator.d.ts.map +0 -1
- package/dist/domain/instrument-operator.js +0 -13
- package/dist/domain/instrument.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.d.ts.map +0 -1
- package/dist/domain/ohlc.d.ts.map +0 -1
- package/dist/domain/order-operator.d.ts +0 -8
- package/dist/domain/order-operator.d.ts.map +0 -1
- package/dist/domain/order-operator.js +0 -16
- package/dist/domain/order.d.ts +0 -24
- package/dist/domain/order.d.ts.map +0 -1
- package/dist/domain/order.js +0 -49
- package/dist/domain/orderbook-operator.d.ts +0 -7
- package/dist/domain/orderbook-operator.d.ts.map +0 -1
- package/dist/domain/orderbook-operator.js +0 -9
- package/dist/domain/orderbook.d.ts +0 -30
- package/dist/domain/orderbook.d.ts.map +0 -1
- package/dist/domain/orderbook.js +0 -20
- package/dist/domain/position-operator.d.ts +0 -13
- package/dist/domain/position-operator.d.ts.map +0 -1
- package/dist/domain/position-operator.js +0 -45
- package/dist/domain/position.d.ts +0 -18
- package/dist/domain/position.d.ts.map +0 -1
- package/dist/domain/position.js +0 -23
- package/dist/domain/session-builder.d.ts +0 -54
- package/dist/domain/session-builder.d.ts.map +0 -1
- package/dist/domain/session-builder.js +0 -106
- package/dist/domain/session.d.ts +0 -77
- package/dist/domain/session.d.ts.map +0 -1
- package/dist/domain/session.js +0 -162
- package/dist/domain/timeframe.d.ts.map +0 -1
- package/dist/domain/trade-operator.d.ts +0 -7
- package/dist/domain/trade-operator.d.ts.map +0 -1
- package/dist/domain/trade-operator.js +0 -9
- package/dist/domain/trade.d.ts +0 -16
- package/dist/domain/trade.d.ts.map +0 -1
- package/dist/domain/trade.js +0 -17
- 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/logger.d.ts +0 -8
- package/dist/shared/logger.d.ts.map +0 -1
- package/dist/shared/logger.js +0 -33
- package/dist/shared/pipe.d.ts +0 -5
- package/dist/shared/pipe.d.ts.map +0 -1
- package/dist/shared/pipe.js +0 -8
- 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/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 -9
- package/dist/store/error.d.ts.map +0 -1
- package/dist/store/error.js +0 -31
- package/dist/store/index.d.ts +0 -10
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/store-balance-event.d.ts +0 -46
- package/dist/store/store-balance-event.d.ts.map +0 -1
- package/dist/store/store-balance-event.js +0 -134
- 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 -22
- package/dist/store/store-instrument-event.d.ts.map +0 -1
- package/dist/store/store-instrument-event.js +0 -60
- package/dist/store/store-order-event.d.ts +0 -64
- package/dist/store/store-order-event.d.ts.map +0 -1
- package/dist/store/store-order-event.js +0 -185
- package/dist/store/store-orderbook-event.d.ts +0 -13
- package/dist/store/store-orderbook-event.d.ts.map +0 -1
- package/dist/store/store-orderbook-event.js +0 -43
- package/dist/store/store-position-event.d.ts +0 -22
- 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 -17
- package/dist/store/store-trade-event.d.ts.map +0 -1
- package/dist/store/store-trade-event.js +0 -34
- package/dist/store/store.d.ts +0 -15
- package/dist/store/store.d.ts.map +0 -1
- package/dist/store/store.js +0 -32
- package/src/adapter/adapter-aggregate.ts +0 -171
- package/src/adapter/adapter.ts +0 -83
- package/src/adapter/backtester/backtester-adapter.ts +0 -96
- 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 -155
- package/src/adapter/backtester/error.ts +0 -7
- package/src/adapter/backtester/index.ts +0 -2
- package/src/adapter/error.ts +0 -13
- package/src/adapter/index.ts +0 -4
- package/src/adapter/paper/engine/paper-engine.spec.ts +0 -116
- package/src/adapter/paper/engine/paper-engine.ts +0 -151
- package/src/adapter/paper/index.ts +0 -2
- package/src/adapter/paper/paper-adapter.ts +0 -111
- package/src/cli/error.ts +0 -5
- package/src/cli/test.ts +0 -40
- package/src/domain/balance-operator.spec.ts +0 -26
- package/src/domain/balance-operator.ts +0 -15
- package/src/domain/balance.spec.ts +0 -116
- package/src/domain/balance.ts +0 -123
- package/src/domain/component.ts +0 -6
- package/src/domain/error.ts +0 -27
- package/src/domain/index.ts +0 -21
- package/src/domain/instrument-operator.spec.ts +0 -35
- package/src/domain/instrument-operator.ts +0 -25
- package/src/domain/order-operator.spec.ts +0 -85
- package/src/domain/order-operator.ts +0 -23
- package/src/domain/order.spec.ts +0 -43
- package/src/domain/order.ts +0 -68
- package/src/domain/orderbook-operator.spec.ts +0 -40
- package/src/domain/orderbook-operator.ts +0 -15
- package/src/domain/orderbook.spec.ts +0 -26
- package/src/domain/orderbook.ts +0 -30
- package/src/domain/position-operator.spec.ts +0 -64
- package/src/domain/position-operator.ts +0 -71
- package/src/domain/position.spec.ts +0 -43
- package/src/domain/position.ts +0 -31
- package/src/domain/session-builder.ts +0 -158
- package/src/domain/session.spec.ts +0 -33
- package/src/domain/session.ts +0 -256
- package/src/domain/trade-operator.spec.ts +0 -35
- package/src/domain/trade-operator.ts +0 -15
- package/src/domain/trade.spec.ts +0 -21
- package/src/domain/trade.ts +0 -20
- package/src/shared/collections.spec.ts +0 -34
- package/src/shared/collections.ts +0 -154
- package/src/shared/logger.ts +0 -39
- package/src/shared/pipe.ts +0 -12
- package/src/shared/policy.ts +0 -5
- package/src/storage/cache.spec.ts +0 -18
- 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 -36
- package/src/store/index.ts +0 -9
- package/src/store/store-balance-event.spec.ts +0 -30
- package/src/store/store-balance-event.ts +0 -167
- package/src/store/store-event.ts +0 -8
- package/src/store/store-instrument-event.spec.ts +0 -26
- package/src/store/store-instrument-event.ts +0 -83
- package/src/store/store-order-event.spec.ts +0 -32
- package/src/store/store-order-event.ts +0 -219
- package/src/store/store-orderbook-event.spec.ts +0 -39
- package/src/store/store-orderbook-event.ts +0 -56
- package/src/store/store-position-event.ts +0 -121
- package/src/store/store-state.ts +0 -48
- package/src/store/store-trade-event.spec.ts +0 -62
- package/src/store/store-trade-event.ts +0 -42
- package/src/store/store.spec.ts +0 -182
- package/src/store/store.ts +0 -37
- package/dist/{domain → component}/ohlc.d.ts +0 -0
- package/dist/{domain → component}/ohlc.js +0 -0
- package/dist/{domain → component}/timeframe.d.ts +0 -0
- package/dist/{domain → component}/timeframe.js +1 -1
- /package/src/{domain → component}/timeframe.ts +0 -0
|
@@ -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
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
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,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
package/src/storage/storage.ts
CHANGED
|
@@ -1,126 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { decimal } from '@lib/shared';
|
|
2
|
+
|
|
3
|
+
type Types = string | number | decimal;
|
|
4
|
+
|
|
5
|
+
export const eq = <T extends Types>(value: T) => ({ type: 'eq' as const, value });
|
|
6
|
+
export const gt = <T extends number>(value: T) => ({ type: 'gt' as const, value });
|
|
7
|
+
export const lt = <T extends number>(value: T) => ({ type: 'lt' as const, value });
|
|
8
|
+
export const between = <T extends number>(min: T, max: T) => ({
|
|
9
|
+
type: 'between' as const,
|
|
10
|
+
min,
|
|
11
|
+
max
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type QueryObject = Record<string, Types> & { timestamp: number };
|
|
15
|
+
export type QueryObjectType<T extends QueryObject> = {
|
|
16
|
+
discriminator: string;
|
|
17
|
+
type: {
|
|
18
|
+
[key in keyof T]: QueryMappingType;
|
|
19
|
+
};
|
|
5
20
|
};
|
|
6
21
|
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
22
|
+
export type QueryWhere =
|
|
23
|
+
| ReturnType<typeof eq>
|
|
24
|
+
| ReturnType<typeof gt>
|
|
25
|
+
| ReturnType<typeof lt>
|
|
26
|
+
| ReturnType<typeof between>;
|
|
27
|
+
|
|
28
|
+
export type Query<T extends QueryObject> = {
|
|
29
|
+
where?: Partial<{
|
|
30
|
+
[key in keyof T]: QueryWhere;
|
|
31
|
+
}>;
|
|
32
|
+
orderBy?: 'ASC' | 'DESC';
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
12
35
|
};
|
|
13
36
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* @param library
|
|
38
|
-
* @param options
|
|
39
|
-
*/
|
|
40
|
-
query(library: string, options: StorageQueryOptions): Promise<StorageDocument[]>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function inMemoryStorageFactory(): StorageFactory {
|
|
44
|
-
const storage: Record<string, Storage> = {};
|
|
45
|
-
|
|
46
|
-
return (type: string) => storage[type] ?? (storage[type] = new InMemoryStorage());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
export class InMemoryStorage implements Storage {
|
|
53
|
-
private tables: Record<string, StorageDocument[]> = {};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
async index(): Promise<Array<string>> {
|
|
60
|
-
return Object.keys(this.tables);
|
|
37
|
+
export type QueryMappingType = 'number' | 'string' | 'decimal';
|
|
38
|
+
export type InferQueryObject<T> = T extends QueryObjectType<infer U>
|
|
39
|
+
? {
|
|
40
|
+
[key in keyof T['type']]: T['type'][key] extends 'number'
|
|
41
|
+
? number
|
|
42
|
+
: T['type'][key] extends 'string'
|
|
43
|
+
? string
|
|
44
|
+
: T['type'][key] extends 'decimal'
|
|
45
|
+
? decimal
|
|
46
|
+
: never;
|
|
47
|
+
} & { timestamp: number }
|
|
48
|
+
: never;
|
|
49
|
+
|
|
50
|
+
export abstract class Storage {
|
|
51
|
+
static createObject<
|
|
52
|
+
K extends QueryObject,
|
|
53
|
+
T extends { [key in keyof K]: QueryMappingType }
|
|
54
|
+
>(discriminator: string, type: T) {
|
|
55
|
+
return {
|
|
56
|
+
discriminator,
|
|
57
|
+
type
|
|
58
|
+
};
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let query = this.tables[library];
|
|
75
|
-
|
|
76
|
-
const { from, to, kind, count } = options;
|
|
77
|
-
|
|
78
|
-
if (from) {
|
|
79
|
-
query = query.filter(it => it.timestamp > from);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (to) {
|
|
83
|
-
query = query.filter(it => it.timestamp < to);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (kind) {
|
|
87
|
-
query = query.filter(it => it.kind == kind);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (from == undefined && to) {
|
|
91
|
-
query = query.reverse();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (count) {
|
|
95
|
-
query = query.slice(0, options.count);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return query;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
*
|
|
103
|
-
* @param library
|
|
104
|
-
* @param documents
|
|
105
|
-
*/
|
|
106
|
-
async save(library: string, documents: StorageDocument[]): Promise<void> {
|
|
107
|
-
if (!this.tables[library]) {
|
|
108
|
-
this.tables[library] = [];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const buffer = this.tables[library];
|
|
112
|
-
|
|
113
|
-
for (const document of documents) {
|
|
114
|
-
buffer.push(document);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
buffer.sort((lhs, rhs) => lhs.timestamp - rhs.timestamp);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
*/
|
|
123
|
-
clear() {
|
|
124
|
-
this.tables = {};
|
|
125
|
-
}
|
|
61
|
+
abstract index(): Promise<Array<string>>;
|
|
62
|
+
abstract save<T extends QueryObjectType<K>, K extends QueryObject>(
|
|
63
|
+
type: T,
|
|
64
|
+
objects: InferQueryObject<T>[]
|
|
65
|
+
): Promise<void>;
|
|
66
|
+
abstract query<T extends QueryObjectType<K>, K extends QueryObject>(
|
|
67
|
+
type: T,
|
|
68
|
+
query: Query<InferQueryObject<T>>
|
|
69
|
+
): Promise<InferQueryObject<T>[]>;
|
|
126
70
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { firstValueFrom, Observable, of } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
import { makeTestModule } from '@lib/make-test-module';
|
|
4
|
+
import { useCache } from '@lib/storage/use-cache';
|
|
5
|
+
import { dependency } from '@lib/use-hash';
|
|
6
|
+
|
|
7
|
+
describe(useCache.name, () => {
|
|
8
|
+
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
9
|
+
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
fixtures = await getFixtures();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('cache value for dependencies', async () => {
|
|
15
|
+
const value1 = await firstValueFrom(fixtures.givenCacheValue(of(1), ['val']));
|
|
16
|
+
const value2 = await firstValueFrom(fixtures.givenCacheValue(of(2), ['val']));
|
|
17
|
+
|
|
18
|
+
expect(value1).toEqual(1);
|
|
19
|
+
expect(value2).toEqual(1);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
async function getFixtures() {
|
|
24
|
+
const { act } = await makeTestModule([]);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
givenCacheValue<T>(value: Observable<T>, dependencies: dependency[]) {
|
|
28
|
+
return act(() => useCache(value, dependencies));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|