-
Notifications
You must be signed in to change notification settings - Fork 4
Extract durable projections into Projection class with minimal Consumer/EventStore wiring #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
42
commits into
main
Choose a base branch
from
copilot/extend-consumer-projection-function
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
da912a3
Add consumer projection persistence support
Copilot e809568
Implement durable consumer projections with HMAC validation
Copilot 2e6f849
Refactor projections into Projection class and integrate Consumer/Eve…
Copilot 2f46add
Address projection API review feedback
Copilot a222f4c
Address projection API and utility review feedback
Copilot f9e7fdd
Refine projection API docs and atomic fs helpers
Copilot 30a73db
Address remaining projection and consumer review feedback
Copilot 143d9b9
Merge origin/main and resolve conflicts
Copilot ecc8282
refactor projection composition and simplify consumer persist
Copilot ace4218
Code cleanup for the matcher logic
albe 8b102ff
Optimize multi value matcher
albe 46f248a
Update docblocks
albe d9f23dd
Improve AGENTS.md
albe abe922e
Optimize numeric operator matching for single operators by ~100%
albe 5cd481e
Remove toggle for new operator matcher
albe 2ba937c
Optimize multi-operator numeric checks
albe f2f6033
Add more matcher benchmarks
albe bffeffd
Add performance section for matchers
albe 0a26f7f
Optimize $ne operator by ~20%
albe 08059f8
Add ISO DateTime matching tests
albe 95f3ad0
Add platform hint for Agents
albe 9b302d6
Fix type of CommitCondition matcher
albe 999f4ac
Add type information
albe c8de460
Deprecate EventStream.filter(Matcher) in favor of EventStream.where()
albe c56c542
Update AGENTS.md
albe c9960ef
Bump version 1.3.1
albe f3a5746
Fix bug in ReadOnlyStorage open with callback
albe 90e87ad
Add EventStore makeReadOnly() API method
albe df7132a
Add documentation for makeReadOnly()
albe d280d81
Add VERSION export
albe 5499008
Update .gitignore
albe 388cb5d
Bump version
albe f053257
Add consumer projection persistence support
Copilot cf21ab9
Implement durable consumer projections with HMAC validation
Copilot 2204aa8
Refactor projections into Projection class and integrate Consumer/Eve…
Copilot 8a7e2d5
Address projection API review feedback
Copilot 240fbd2
Address projection API and utility review feedback
Copilot 5029f61
Refine projection API docs and atomic fs helpers
Copilot b1eba00
Address remaining projection and consumer review feedback
Copilot 90c6e5f
refactor projection composition and simplify consumer persist
Copilot 89f6899
Rebase branch onto latest main and resolve conflicts
Copilot dd085a7
Merge remote-tracking branch 'origin/copilot/extend-consumer-projecti…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,6 @@ node_modules | |
| /data | ||
| *.tgz | ||
| /event-storage-ui | ||
| /event-storage-http | ||
| /event-storage-http | ||
| /Platform.md | ||
| /*/node_modules | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import { EventEmitter } from 'node:events'; | ||
| import { Readable } from 'node:stream'; | ||
|
|
||
| export type EventMatcher = Record<string, unknown> | ((payload: any, metadata?: any) => boolean); | ||
| export type EventPredicate = EventMatcher | ((buffer: Buffer) => boolean) | null; | ||
|
|
||
| export interface StreamIndexInfo { | ||
| length: number; | ||
| metadata?: Record<string, unknown> | null; | ||
| } | ||
|
|
||
| export interface StreamInfo { | ||
| index: StreamIndexInfo; | ||
| matcher?: EventMatcher; | ||
| closed?: boolean; | ||
| } | ||
|
|
||
| export class CommitCondition { | ||
| constructor(types: string[], matcher: EventMatcher | null | undefined, noneMatchAfter: number, raw?: boolean); | ||
| types: string[]; | ||
| matcher: EventMatcher | null; | ||
| raw: boolean; | ||
| noneMatchAfter: number; | ||
| } | ||
|
|
||
| export class OptimisticConcurrencyError extends Error {} | ||
|
|
||
| export const ExpectedVersion: { | ||
| Any: -1; | ||
| EmptyStream: 0; | ||
| }; | ||
|
|
||
| export const VERSION: string; | ||
|
|
||
| export class EventStream extends Readable { | ||
| constructor(name: string, eventStore: EventStore, minRevision?: number, maxRevision?: number, predicate?: EventPredicate, raw?: boolean); | ||
| name: string; | ||
| raw: boolean; | ||
| version: number; | ||
| minRevision: number; | ||
| maxRevision: number; | ||
| streamIndex: StreamIndexInfo; | ||
| predicate: EventPredicate; | ||
|
|
||
| from(revision: number): this; | ||
| until(revision: number): this; | ||
| fromStart(): this; | ||
| fromEnd(): this; | ||
| previous(amount: number): this; | ||
| following(amount: number): this; | ||
| backwards(): this; | ||
| forwards(): this; | ||
| where(predicate?: EventPredicate): this; | ||
| filter(predicate?: EventPredicate): this; | ||
| filter( | ||
| predicate: (chunk: any, options?: { signal?: AbortSignal }) => boolean | Promise<boolean>, | ||
| options: { concurrency?: number; signal?: AbortSignal } | ||
| ): Readable; | ||
| next(): any | false; | ||
| } | ||
|
|
||
| export class Consumer extends Readable { | ||
| constructor(storage: Storage, indexName: string, identifier: string, initialState?: Record<string, unknown>, startFrom?: number); | ||
| streamName: string; | ||
| position: number; | ||
| state: Record<string, unknown>; | ||
| start(): this; | ||
| stop(): void; | ||
| reset(initialState?: Record<string, unknown>, startFrom?: number): this; | ||
| setState(state: Record<string, unknown>): this; | ||
| } | ||
|
|
||
| export class Storage extends EventEmitter { | ||
| static ReadOnly: typeof Storage; | ||
| static StorageLockedError: typeof StorageLockedError; | ||
| static LOCK_THROW: number; | ||
| static LOCK_RECLAIM: number; | ||
|
|
||
| initialized: boolean | null; | ||
| length: number; | ||
| indexDirectory: string; | ||
| storageFile: string; | ||
| } | ||
|
|
||
| export class StorageLockedError extends Error {} | ||
|
|
||
| export class Index { | ||
| static ReadOnly: typeof Index; | ||
| static Entry: unknown; | ||
|
|
||
| length: number; | ||
| metadata?: Record<string, unknown> | null; | ||
| } | ||
|
|
||
| export class EventStore extends EventEmitter { | ||
| static Storage: typeof Storage; | ||
| static Index: typeof Index; | ||
| static VERSION: string; | ||
|
|
||
| storage: Storage; | ||
| streams: Record<string, StreamInfo>; | ||
| consumers: Map<string, Consumer>; | ||
| length: number; | ||
|
|
||
| constructor(storeName?: string, config?: Record<string, unknown>); | ||
|
|
||
| open(callback?: (err?: Error | null) => void): void; | ||
| close(callback?: (err?: Error | null) => void): void; | ||
|
|
||
| getStreamVersion(streamName: string): number; | ||
| getEventStream(streamName: string, minRevision?: number, maxRevision?: number, predicate?: EventPredicate, raw?: boolean): EventStream | false; | ||
| getAllEvents(minRevision?: number, maxRevision?: number, predicate?: EventPredicate, raw?: boolean): EventStream; | ||
| fromStreams(streamName: string, streamNames: string[], minRevision?: number, maxRevision?: number, predicate?: EventPredicate, raw?: boolean): EventStream; | ||
| getEventStreamForCategory(categoryName: string, minRevision?: number, maxRevision?: number, predicate?: EventPredicate, raw?: boolean): EventStream; | ||
|
|
||
| query(types: string[], matcher?: EventMatcher | null, minRevision?: number, raw?: boolean): { stream: EventStream; condition: CommitCondition }; | ||
| createEventStream(streamName: string, matcher: EventMatcher, reindex?: boolean): EventStream; | ||
|
|
||
| commit( | ||
| streamName: string, | ||
| events: any[], | ||
| expectedVersion: number | CommitCondition, | ||
| metadata: Record<string, unknown>, | ||
| callback: (error: Error | null, commit?: Record<string, unknown>) => void | ||
| ): void; | ||
|
|
||
| getConsumer(streamName: string, identifier: string, initialState?: Record<string, unknown>, since?: number): Consumer; | ||
| getConsumer(identifier: string): Consumer | null; | ||
| scanConsumers( | ||
| callback: (error: Error | null, consumers: Array<{ name: string; stream: string; identifier: string }>) => void, | ||
| autoStart?: boolean | ||
| ): void; | ||
| } | ||
|
|
||
| export const LOCK_THROW: number; | ||
| export const LOCK_RECLAIM: number; | ||
|
|
||
| export function matches(document: Record<string, unknown>, matcher: Record<string, unknown>): boolean; | ||
| export function buildRawBufferMatcher(matcher: Record<string, unknown>): (buffer: Buffer, startOffset?: number) => boolean; | ||
|
|
||
| export default EventStore; | ||
|
|
||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.