Skip to content

Commit 20379df

Browse files
committed
Put bsontypes to be nullable and removed unsupported bsonTypes
1 parent bd88e8b commit 20379df

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/MongoDB.Driver.Encryption/CsfleSchemaBuilder.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ public EncryptedCollectionBuilder<TDocument> EncryptMetadata(Guid? keyId = null,
9898
/// </summary>
9999
public EncryptedCollectionBuilder<TDocument> PatternProperty(
100100
string pattern,
101-
BsonType bsonType,
101+
BsonType? bsonType = null,
102102
EncryptionAlgorithm? algorithm = null,
103103
Guid? keyId = null)
104-
=> PatternProperty(pattern, [bsonType], algorithm, keyId);
104+
=> PatternProperty(pattern, bsonType is null? [] : [bsonType.Value], algorithm, keyId);
105105

106106
/// <summary>
107107
/// //TODO
108108
/// </summary>
109109
public EncryptedCollectionBuilder<TDocument> PatternProperty(
110110
string pattern,
111-
IEnumerable<BsonType> bsonTypes,
111+
IEnumerable<BsonType> bsonTypes = null,
112112
EncryptionAlgorithm? algorithm = null,
113113
Guid? keyId = null)
114114
{
@@ -145,17 +145,17 @@ public EncryptedCollectionBuilder<TDocument> PatternProperty<TField>(
145145
/// </summary>
146146
public EncryptedCollectionBuilder<TDocument> Property<TField>(
147147
Expression<Func<TDocument, TField>> path,
148-
BsonType bsonType,
148+
BsonType? bsonType = null,
149149
EncryptionAlgorithm? algorithm = null,
150150
Guid? keyId = null)
151-
=> Property(path, [bsonType], algorithm, keyId);
151+
=> Property(path, bsonType is null? null : [bsonType.Value], algorithm, keyId);
152152

153153
/// <summary>
154154
/// //TODO
155155
/// </summary>
156156
public EncryptedCollectionBuilder<TDocument> Property<TField>(
157157
Expression<Func<TDocument, TField>> path,
158-
IEnumerable<BsonType> bsonTypes,
158+
IEnumerable<BsonType> bsonTypes = null,
159159
EncryptionAlgorithm? algorithm = null,
160160
Guid? keyId = null)
161161
=> Property(new ExpressionFieldDefinition<TDocument, TField>(path), bsonTypes, algorithm, keyId);
@@ -165,17 +165,17 @@ public EncryptedCollectionBuilder<TDocument> Property<TField>(
165165
/// </summary>
166166
public EncryptedCollectionBuilder<TDocument> Property(
167167
FieldDefinition<TDocument> path,
168-
BsonType bsonType,
168+
BsonType? bsonType = null,
169169
EncryptionAlgorithm? algorithm = null,
170170
Guid? keyId = null)
171-
=> Property(path, [bsonType], algorithm, keyId);
171+
=> Property(path, bsonType is null? null : [bsonType.Value], algorithm, keyId);
172172

173173
/// <summary>
174174
/// //TODO
175175
/// </summary>
176176
public EncryptedCollectionBuilder<TDocument> Property(
177177
FieldDefinition<TDocument> path,
178-
IEnumerable<BsonType> bsonTypes,
178+
IEnumerable<BsonType> bsonTypes = null,
179179
EncryptionAlgorithm? algorithm = null,
180180
Guid? keyId = null)
181181
{
@@ -210,7 +210,7 @@ public EncryptedCollectionBuilder<TDocument> Property<TField>(
210210
internal BsonDocument Build() => _schema;
211211

212212
private static BsonDocument CreateEncryptDocument(
213-
IEnumerable<BsonType> bsonTypes,
213+
IEnumerable<BsonType> bsonTypes = null,
214214
EncryptionAlgorithm? algorithm = null,
215215
Guid? keyId = null)
216216
{
@@ -268,7 +268,7 @@ private void AddToProperties(string field, BsonDocument document)
268268
properties[field] = document;
269269
}
270270

271-
private static string MapBsonTypeToString(BsonType type) //TODO Taken from AstTypeFilterOperation, do we have a common place where this could go?
271+
private static string MapBsonTypeToString(BsonType type)
272272
{
273273
return type switch
274274
{
@@ -283,16 +283,12 @@ private void AddToProperties(string field, BsonDocument document)
283283
BsonType.Int64 => "long",
284284
BsonType.JavaScript => "javascript",
285285
BsonType.JavaScriptWithScope => "javascriptWithScope",
286-
BsonType.MaxKey => "maxKey",
287-
BsonType.MinKey => "minKey",
288-
BsonType.Null => "null",
289286
BsonType.ObjectId => "objectId",
290287
BsonType.RegularExpression => "regex",
291288
BsonType.String => "string",
292289
BsonType.Symbol => "symbol",
293290
BsonType.Timestamp => "timestamp",
294-
BsonType.Undefined => "undefined",
295-
_ => throw new ArgumentException($"Unexpected BSON type: {type}.", nameof(type))
291+
_ => throw new ArgumentException($"Unsupported BSON type: {type}.", nameof(type))
296292
};
297293
}
298294

0 commit comments

Comments
 (0)