|
| 1 | +import { EventWithId } from "./batch_event_processor"; |
| 2 | +import { AsyncPrefixStore, OpStore, Store, SyncPrefixStore } from "../utils/cache/store"; |
| 3 | +import { Maybe, OpType, OpValue } from "../utils/type"; |
| 4 | + |
| 5 | +type StoredEvent = EventWithId & { |
| 6 | + storedAt?: number; |
| 7 | +}; |
| 8 | + |
| 9 | +export class EventStore<OP extends OpType> implements OpStore<OP, EventWithId> { |
| 10 | + private store: OpStore<OP, StoredEvent>; |
| 11 | + readonly operation: OP; |
| 12 | + private keysSet?: Set<string>; |
| 13 | + |
| 14 | + constructor(store: OpStore<OP, EventWithId>) { |
| 15 | + if (store.operation === 'sync') { |
| 16 | + this.store = new SyncPrefixStore(store as OpStore<'sync', EventWithId>, 'optly_event:', a => a, a => a) as unknown as OpStore<OP, StoredEvent>; |
| 17 | + } else { |
| 18 | + this.store = new AsyncPrefixStore(store as OpStore<'async', EventWithId>, 'optly_event:', a => a, a => a) as unknown as OpStore<OP, StoredEvent>; |
| 19 | + } |
| 20 | + |
| 21 | + this.operation = store.operation; |
| 22 | + } |
| 23 | + |
| 24 | + set(key: string, value: EventWithId): OpValue<OP, unknown> { |
| 25 | + throw new Error("Method not implemented."); |
| 26 | + } |
| 27 | + |
| 28 | + get(key: string): OpValue<OP, Maybe<EventWithId>> { |
| 29 | + throw new Error("Method not implemented."); |
| 30 | + } |
| 31 | + |
| 32 | + remove(key: string): OpValue<OP, unknown> { |
| 33 | + throw new Error("Method not implemented."); |
| 34 | + } |
| 35 | + |
| 36 | + getKeys(): OpValue<OP, string[]> { |
| 37 | + throw new Error("Method not implemented."); |
| 38 | + } |
| 39 | +} |
0 commit comments