@@ -21,20 +21,24 @@ open Swensen.Unquote
2121/// DynamoDB Attribute identifier
2222type AttributeId =
2323 {
24- Path : string
2524 RootName : string
2625 RootId : string
26+ NestedPath : string list
2727 Type : AttributeType
2828 }
2929with
30+ member id.Id = String.concat " " ( id.RootId :: id.NestedPath)
31+ member id.Name = String.concat " " ( id.RootName :: id.NestedPath)
32+ member id.Tokens = id.RootName :: id.NestedPath
3033 member id.IsHashKey = id.Type = AttributeType.HashKey
3134 member id.IsRangeKey = id.Type = AttributeType.RangeKey
32- member id.Append ( suffix ) = { id with Path = sprintf " %s .%s " id.Path suffix }
35+ member id.AppendField ( suffix ) = { id with NestedPath = id.NestedPath @ [ " ." + suffix] }
36+ member id.AppendIndex ( index ) = { id with NestedPath = id.NestedPath @ [ sprintf " [%d ]" index] }
3337
3438 static member FromKeySchema ( schema : TableKeySchema ) =
3539 let rootId = " #HKEY"
3640 let hkName = schema.HashKey.AttributeName
37- { Path = rootId ; RootId = rootId ; RootName = hkName ; Type = AttributeType.HashKey }
41+ { RootId = rootId ; RootName = hkName ; NestedPath = [] ; Type = AttributeType.HashKey }
3842
3943type RecordPropertyInfo with
4044 /// Gets an attribute Id for given record property that
6771
6872 aux ap
6973
70- /// Gets a list of string tokens that identify the attribute path
71- member ap.Tokens =
72- let rec getTokens acc ap =
73- match ap with
74- | Root rp -> rp.Name :: acc
75- | Nested ( rp, p) -> getTokens ( " ." + rp.Name :: acc) p
76- | Item( i,_, p) -> getTokens ( sprintf " .[%d ]" i :: acc) p
77- | Optional(_, p) -> getTokens acc p
78-
79- getTokens [] ap
80-
8174 /// Gets an attribute identifier for given Quoted attribute instace
8275 member ap.Id =
8376 let rec getTokens acc ap =
8780 | Optional(_, p) -> getTokens acc p
8881 | Root rp ->
8982 {
90- Path = String.concat " " ( rp.AttrId :: acc)
9183 RootId = rp.AttrId
9284 RootName = rp.Name
85+ NestedPath = acc
9386 Type = rp.AttributeType
9487 }
9588
@@ -192,7 +185,7 @@ type AttributeWriter(names : Dictionary<string, string>, values : Dictionary<str
192185
193186 member __.WriteAttibute ( attr : AttributeId ) =
194187 names.[ attr.RootId] <- attr.RootName
195- attr.Path
188+ attr.Id
196189
197190/// Recognizes exprs of shape <@ fun p1 p2 ... -> body @>
198191let extractExprParams ( recordInfo : RecordInfo ) ( expr : Expr ) =
@@ -220,9 +213,9 @@ let extractExprParams (recordInfo : RecordInfo) (expr : Expr) =
220213// however 'r.Foo.Bar.[0]' and 'r.Foo.Bar.[1]' are not conflicting
221214type private AttributeNode = { Value : string ; Children : ResizeArray < AttributeNode > }
222215/// Detects conflicts in a collection of attribute paths
223- let tryFindConflictingPaths ( attrs : seq < QuotedAttribute >) =
216+ let tryFindConflictingPaths ( attrs : seq < AttributeId >) =
224217 let root = new ResizeArray< AttributeNode>()
225- let tryAppendPath ( attr : QuotedAttribute ) =
218+ let tryAppendPath ( attr : AttributeId ) =
226219 let tokens = attr.Tokens :> seq< string>
227220 let enum = tokens.GetEnumerator()
228221 let mutable ctx = root
0 commit comments