-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
40 additions
and
29 deletions.
There are no files selected for viewing
33 changes: 19 additions & 14 deletions
33
src/Propulsion.Cosmos/DocumentParser.fs → src/Propulsion.Cosmos/EquinoxCosmosParser.fs
This file contains 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 |
---|---|---|
@@ -1,33 +1,38 @@ | ||
namespace Propulsion.Cosmos | ||
|
||
open Microsoft.Azure.Documents | ||
open Propulsion.Streams | ||
|
||
/// Maps fields in an Event within an Equinox.Cosmos V1+ Event (in a Batch or Tip) to the interface defined by Propulsion.Streams | ||
/// <remarks> | ||
/// NOTE until `tip-isa-batch` gets merged, this causes a null-traversal of `-1`-index pages that presently do not contain data. | ||
/// This is intentional in the name of forward compatibility for projectors - enabling us to upgrade the data format without necessitating | ||
/// updates of all projectors (even if there can potentially be significant at-least-once-ness to the delivery).</remarks> | ||
[<RequireQualifiedAccess>] | ||
module DocumentParser = | ||
module EquinoxCosmosParser = | ||
type Document with | ||
member document.Cast<'T>() = | ||
let tmp = new Document() | ||
tmp.SetPropertyValue("content", document) | ||
tmp.GetPropertyValue<'T>("content") | ||
/// Sanity check to determine whether the Document represents an `Equinox.Cosmos` >= 1.0 based batch | ||
let isEquinoxBatch (d : Document) = | ||
d.GetPropertyValue "p" <> null && d.GetPropertyValue "i" <> null | ||
&& d.GetPropertyValue "n" <> null && d.GetPropertyValue "e" <> null | ||
/// Maps fields in an Event within an Equinox.Cosmos V1+ Event (in a Batch or Tip) to the interface defined by the default Codec | ||
let (|CodecEvent|) (x: Equinox.Cosmos.Store.Event) = | ||
{ new Propulsion.Streams.IEvent<_> with | ||
|
||
let (|PropulsionEvent|) (x: Equinox.Cosmos.Store.Event) = | ||
{ new IEvent<_> with | ||
member __.EventType = x.c | ||
member __.Data = x.d | ||
member __.Meta = x.m | ||
member __.Timestamp = x.t } | ||
|
||
/// Sanity check to determine whether the Document represents an `Equinox.Cosmos` >= 1.0 based batch | ||
let isEquinoxBatch (d : Document) = | ||
d.GetPropertyValue "p" <> null && d.GetPropertyValue "i" <> null | ||
&& d.GetPropertyValue "n" <> null && d.GetPropertyValue "e" <> null | ||
|
||
/// Enumerates the events represented within a batch | ||
// NOTE until `tip-isa-batch` gets merged, this causes a null-traversal of `-1`-index pages which presently do not contain data | ||
// This is intentional in the name of forward compatibility for projectors - enabling us to upgrade the data format without necessitating | ||
// updates of all projectors (even if there can potentially be significant at-least-once-ness to the delivery) | ||
let enumEquinoxCosmosEvents (batch : Equinox.Cosmos.Store.Batch) = | ||
batch.e |> Seq.mapi (fun offset (CodecEvent x) -> { stream = batch.p; index = batch.i + int64 offset; event = x } : Propulsion.Streams.StreamEvent<_>) | ||
let enumEquinoxCosmosEvents (batch : Equinox.Cosmos.Store.Batch) : StreamEvent<_> seq = | ||
batch.e |> Seq.mapi (fun offset (PropulsionEvent x) -> { stream = batch.p; index = batch.i + int64 offset; event = x }) | ||
|
||
/// Collects all events with a Document [typically obtained via the CosmosDb ChangeFeed] that potentially represents an Equinox.Cosmos event-batch | ||
let enumEvents (d : Document) : Propulsion.Streams.StreamEvent<_> seq = | ||
let enumStreamEvents (d : Document) : StreamEvent<_> seq = | ||
if isEquinoxBatch d then d.Cast<Equinox.Cosmos.Store.Batch>() |> enumEquinoxCosmosEvents | ||
else Seq.empty |
This file contains 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 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 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 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