From 899b8c9940d8629d8d8f49c5c8e7293aed5d91ea Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 16 Nov 2021 15:12:25 -0500 Subject: [PATCH 1/7] Fix build[type]Result functions and remove operationgen notices --- x/mongo/driver/operation/abort_transaction.go | 2 - x/mongo/driver/operation/aggregate.go | 2 - x/mongo/driver/operation/command.go | 2 - .../driver/operation/commit_transaction.go | 2 - x/mongo/driver/operation/count.go | 15 +++----- x/mongo/driver/operation/create.go | 2 - x/mongo/driver/operation/createIndexes.go | 8 ++-- x/mongo/driver/operation/delete.go | 4 +- x/mongo/driver/operation/distinct.go | 2 - x/mongo/driver/operation/drop_collection.go | 6 +-- x/mongo/driver/operation/drop_database.go | 2 - x/mongo/driver/operation/drop_indexes.go | 4 +- x/mongo/driver/operation/end_sessions.go | 2 - x/mongo/driver/operation/find.go | 2 - x/mongo/driver/operation/find_and_modify.go | 10 ++--- x/mongo/driver/operation/hello.go | 6 +++ x/mongo/driver/operation/insert.go | 4 +- x/mongo/driver/operation/listDatabases.go | 38 ++++++------------- x/mongo/driver/operation/list_collections.go | 2 - x/mongo/driver/operation/list_indexes.go | 2 - x/mongo/driver/operation/update.go | 17 +++------ 21 files changed, 39 insertions(+), 95 deletions(-) diff --git a/x/mongo/driver/operation/abort_transaction.go b/x/mongo/driver/operation/abort_transaction.go index 515c539027..e8cf3b766c 100644 --- a/x/mongo/driver/operation/abort_transaction.go +++ b/x/mongo/driver/operation/abort_transaction.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/aggregate.go b/x/mongo/driver/operation/aggregate.go index 1d24fabc1b..9163fb7cae 100644 --- a/x/mongo/driver/operation/aggregate.go +++ b/x/mongo/driver/operation/aggregate.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/command.go b/x/mongo/driver/operation/command.go index e266fe1dbb..b94511c16e 100644 --- a/x/mongo/driver/operation/command.go +++ b/x/mongo/driver/operation/command.go @@ -1,5 +1,3 @@ -// NOTE: This file is maintained by hand because operationgen cannot generate it. - package operation import ( diff --git a/x/mongo/driver/operation/commit_transaction.go b/x/mongo/driver/operation/commit_transaction.go index f1ec99428c..7be5c7cb3d 100644 --- a/x/mongo/driver/operation/commit_transaction.go +++ b/x/mongo/driver/operation/commit_transaction.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/count.go b/x/mongo/driver/operation/count.go index 59cbe656df..8266fa5915 100644 --- a/x/mongo/driver/operation/count.go +++ b/x/mongo/driver/operation/count.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -52,41 +50,38 @@ func buildCountResult(response bsoncore.Document, srvr driver.Server) (CountResu return CountResult{}, err } cr := CountResult{} -elementLoop: for _, element := range elements { switch element.Key() { case "n": // for count using original command var ok bool cr.N, ok = element.Value().AsInt64OK() if !ok { - err = fmt.Errorf("response field 'n' is type int64, but received BSON type %s", + return cr, fmt.Errorf("response field 'n' is type int64, but received BSON type %s", element.Value().Type) - break elementLoop } case "cursor": // for count using aggregate with $collStats firstBatch, err := element.Value().Document().LookupErr("firstBatch") if err != nil { - break elementLoop + return cr, err } // get count value from first batch val := firstBatch.Array().Index(0) count, err := val.Document().LookupErr("n") if err != nil { - break elementLoop + return cr, err } // use count as Int64 for result var ok bool cr.N, ok = count.AsInt64OK() if !ok { - err = fmt.Errorf("response field 'n' is type int64, but received BSON type %s", + return cr, fmt.Errorf("response field 'n' is type int64, but received BSON type %s", element.Value().Type) - break elementLoop } } } - return cr, err + return cr, nil } // NewCount constructs and returns a new Count. diff --git a/x/mongo/driver/operation/create.go b/x/mongo/driver/operation/create.go index 9013812a7c..9a8b8bfccd 100644 --- a/x/mongo/driver/operation/create.go +++ b/x/mongo/driver/operation/create.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/createIndexes.go b/x/mongo/driver/operation/createIndexes.go index 218feb40b5..b9ceefe084 100644 --- a/x/mongo/driver/operation/createIndexes.go +++ b/x/mongo/driver/operation/createIndexes.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -61,19 +59,19 @@ func buildCreateIndexesResult(response bsoncore.Document, srvr driver.Server) (C var ok bool cir.CreatedCollectionAutomatically, ok = element.Value().BooleanOK() if !ok { - err = fmt.Errorf("response field 'createdCollectionAutomatically' is type bool, but received BSON type %s", element.Value().Type) + return cir, fmt.Errorf("response field 'createdCollectionAutomatically' is type bool, but received BSON type %s", element.Value().Type) } case "indexesAfter": var ok bool cir.IndexesAfter, ok = element.Value().AsInt32OK() if !ok { - err = fmt.Errorf("response field 'indexesAfter' is type int32, but received BSON type %s", element.Value().Type) + return cir, fmt.Errorf("response field 'indexesAfter' is type int32, but received BSON type %s", element.Value().Type) } case "indexesBefore": var ok bool cir.IndexesBefore, ok = element.Value().AsInt32OK() if !ok { - err = fmt.Errorf("response field 'indexesBefore' is type int32, but received BSON type %s", element.Value().Type) + return cir, fmt.Errorf("response field 'indexesBefore' is type int32, but received BSON type %s", element.Value().Type) } } } diff --git a/x/mongo/driver/operation/delete.go b/x/mongo/driver/operation/delete.go index 34ee616241..33976348ce 100644 --- a/x/mongo/driver/operation/delete.go +++ b/x/mongo/driver/operation/delete.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -57,7 +55,7 @@ func buildDeleteResult(response bsoncore.Document, srvr driver.Server) (DeleteRe var ok bool dr.N, ok = element.Value().AsInt32OK() if !ok { - err = fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type) + return dr, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type) } } } diff --git a/x/mongo/driver/operation/distinct.go b/x/mongo/driver/operation/distinct.go index b26ba4518b..0ac804af30 100644 --- a/x/mongo/driver/operation/distinct.go +++ b/x/mongo/driver/operation/distinct.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/drop_collection.go b/x/mongo/driver/operation/drop_collection.go index f97c1617ba..9f8f8c5208 100644 --- a/x/mongo/driver/operation/drop_collection.go +++ b/x/mongo/driver/operation/drop_collection.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -55,13 +53,13 @@ func buildDropCollectionResult(response bsoncore.Document, srvr driver.Server) ( var ok bool dcr.NIndexesWas, ok = element.Value().AsInt32OK() if !ok { - err = fmt.Errorf("response field 'nIndexesWas' is type int32, but received BSON type %s", element.Value().Type) + return dcr, fmt.Errorf("response field 'nIndexesWas' is type int32, but received BSON type %s", element.Value().Type) } case "ns": var ok bool dcr.Ns, ok = element.Value().StringValueOK() if !ok { - err = fmt.Errorf("response field 'ns' is type string, but received BSON type %s", element.Value().Type) + return dcr, fmt.Errorf("response field 'ns' is type string, but received BSON type %s", element.Value().Type) } } } diff --git a/x/mongo/driver/operation/drop_database.go b/x/mongo/driver/operation/drop_database.go index d59e48f95a..f2dc4ed70a 100644 --- a/x/mongo/driver/operation/drop_database.go +++ b/x/mongo/driver/operation/drop_database.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/drop_indexes.go b/x/mongo/driver/operation/drop_indexes.go index abe07d3a21..51aedc1cb7 100644 --- a/x/mongo/driver/operation/drop_indexes.go +++ b/x/mongo/driver/operation/drop_indexes.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -55,7 +53,7 @@ func buildDropIndexesResult(response bsoncore.Document, srvr driver.Server) (Dro var ok bool dir.NIndexesWas, ok = element.Value().AsInt32OK() if !ok { - err = fmt.Errorf("response field 'nIndexesWas' is type int32, but received BSON type %s", element.Value().Type) + return dir, fmt.Errorf("response field 'nIndexesWas' is type int32, but received BSON type %s", element.Value().Type) } } } diff --git a/x/mongo/driver/operation/end_sessions.go b/x/mongo/driver/operation/end_sessions.go index a0b7f9af42..0580c0ada3 100644 --- a/x/mongo/driver/operation/end_sessions.go +++ b/x/mongo/driver/operation/end_sessions.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/find.go b/x/mongo/driver/operation/find.go index 890d322e93..4d23d49434 100644 --- a/x/mongo/driver/operation/find.go +++ b/x/mongo/driver/operation/find.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/find_and_modify.go b/x/mongo/driver/operation/find_and_modify.go index 3bf879d102..247a8dc110 100644 --- a/x/mongo/driver/operation/find_and_modify.go +++ b/x/mongo/driver/operation/find_and_modify.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -74,23 +72,21 @@ func buildFindAndModifyResult(response bsoncore.Document, srvr driver.Server) (F famr := FindAndModifyResult{} for _, element := range elements { switch element.Key() { - case "value": var ok bool famr.Value, ok = element.Value().DocumentOK() if !ok { - err = fmt.Errorf("response field 'value' is type document, but received BSON type %s", element.Value().Type) + return famr, fmt.Errorf("response field 'value' is type document, but received BSON type %s", element.Value().Type) } case "lastErrorObject": valDoc, ok := element.Value().DocumentOK() if !ok { - err = fmt.Errorf("response field 'lastErrorObject' is type document, but received BSON type %s", element.Value().Type) - break + return famr, fmt.Errorf("response field 'lastErrorObject' is type document, but received BSON type %s", element.Value().Type) } var leo LastErrorObject if err = bson.Unmarshal(valDoc, &leo); err != nil { - break + return famr, err } famr.LastErrorObject = leo } diff --git a/x/mongo/driver/operation/hello.go b/x/mongo/driver/operation/hello.go index 52730af721..d222ada93d 100644 --- a/x/mongo/driver/operation/hello.go +++ b/x/mongo/driver/operation/hello.go @@ -1,3 +1,9 @@ +// Copyright (C) MongoDB, Inc. 2021-present. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + package operation import ( diff --git a/x/mongo/driver/operation/insert.go b/x/mongo/driver/operation/insert.go index e96e210d29..d422ba59d6 100644 --- a/x/mongo/driver/operation/insert.go +++ b/x/mongo/driver/operation/insert.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -57,7 +55,7 @@ func buildInsertResult(response bsoncore.Document, srvr driver.Server) (InsertRe var ok bool ir.N, ok = element.Value().AsInt32OK() if !ok { - err = fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type) + return ir, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type) } } } diff --git a/x/mongo/driver/operation/listDatabases.go b/x/mongo/driver/operation/listDatabases.go index f3ee1fad99..6f7d08ef7e 100644 --- a/x/mongo/driver/operation/listDatabases.go +++ b/x/mongo/driver/operation/listDatabases.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( @@ -62,76 +60,64 @@ func buildListDatabasesResult(response bsoncore.Document, srvr driver.Server) (L ir := ListDatabasesResult{} for _, element := range elements { switch element.Key() { - case "totalSize": var ok bool ir.TotalSize, ok = element.Value().AsInt64OK() if !ok { - err = fmt.Errorf("response field 'totalSize' is type int64, but received BSON type %s: %s", element.Value().Type, element.Value()) + return ir, fmt.Errorf("response field 'totalSize' is type int64, but received BSON type %s: %s", element.Value().Type, element.Value()) } - case "databases": - // TODO: Make operationgen handle array results. arr, ok := element.Value().ArrayOK() if !ok { - err = fmt.Errorf("response field 'databases' is type array, but received BSON type %s", element.Value().Type) - continue + return ir, fmt.Errorf("response field 'databases' is type array, but received BSON type %s", element.Value().Type) } var tmp bsoncore.Document marshalErr := bson.Unmarshal(arr, &tmp) if marshalErr != nil { - err = marshalErr - continue + return ir, marshalErr } + records, marshalErr := tmp.Elements() if marshalErr != nil { - err = marshalErr - continue + return ir, marshalErr } ir.Databases = make([]databaseRecord, len(records)) for i, val := range records { valueDoc, ok := val.Value().DocumentOK() if !ok { - err = fmt.Errorf("'databases' element is type document, but received BSON type %s", val.Value().Type) - continue + return ir, fmt.Errorf("'databases' element is type document, but received BSON type %s", val.Value().Type) } elems, marshalErr := valueDoc.Elements() if marshalErr != nil { - err = marshalErr - continue + return ir, marshalErr } + for _, elem := range elems { switch elem.Key() { - case "name": ir.Databases[i].Name, ok = elem.Value().StringValueOK() if !ok { - err = fmt.Errorf("response field 'name' is type string, but received BSON type %s", elem.Value().Type) - continue + return ir, fmt.Errorf("response field 'name' is type string, but received BSON type %s", elem.Value().Type) } - case "sizeOnDisk": ir.Databases[i].SizeOnDisk, ok = elem.Value().AsInt64OK() if !ok { - err = fmt.Errorf("response field 'sizeOnDisk' is type int64, but received BSON type %s", elem.Value().Type) - continue + return ir, fmt.Errorf("response field 'sizeOnDisk' is type int64, but received BSON type %s", elem.Value().Type) } - case "empty": ir.Databases[i].Empty, ok = elem.Value().BooleanOK() if !ok { - err = fmt.Errorf("response field 'empty' is type bool, but received BSON type %s", elem.Value().Type) - continue + return ir, fmt.Errorf("response field 'empty' is type bool, but received BSON type %s", elem.Value().Type) } } } } } } - return ir, err + return ir, nil } // NewListDatabases constructs and returns a new ListDatabases. diff --git a/x/mongo/driver/operation/list_collections.go b/x/mongo/driver/operation/list_collections.go index 929d8b4760..6c98a670a7 100644 --- a/x/mongo/driver/operation/list_collections.go +++ b/x/mongo/driver/operation/list_collections.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/list_indexes.go b/x/mongo/driver/operation/list_indexes.go index 159efea89f..99bc45b234 100644 --- a/x/mongo/driver/operation/list_indexes.go +++ b/x/mongo/driver/operation/list_indexes.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Code generated by operationgen. DO NOT EDIT. - package operation import ( diff --git a/x/mongo/driver/operation/update.go b/x/mongo/driver/operation/update.go index b57de7493e..3f22fc06f6 100644 --- a/x/mongo/driver/operation/update.go +++ b/x/mongo/driver/operation/update.go @@ -4,8 +4,6 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// NOTE: This file is maintained by hand because operationgen cannot generate it. - package operation import ( @@ -67,26 +65,22 @@ func buildUpdateResult(response bsoncore.Document, srvr driver.Server) (UpdateRe ur := UpdateResult{} for _, element := range elements { switch element.Key() { - case "nModified": var ok bool ur.NModified, ok = element.Value().Int32OK() if !ok { - err = fmt.Errorf("response field 'nModified' is type int32, but received BSON type %s", element.Value().Type) + return ur, fmt.Errorf("response field 'nModified' is type int32, but received BSON type %s", element.Value().Type) } - case "n": var ok bool ur.N, ok = element.Value().Int32OK() if !ok { - err = fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type) + return ur, fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type) } - case "upserted": arr, ok := element.Value().ArrayOK() if !ok { - err = fmt.Errorf("response field 'upserted' is type array, but received BSON type %s", element.Value().Type) - break + return ur, fmt.Errorf("response field 'upserted' is type array, but received BSON type %s", element.Value().Type) } var values []bsoncore.Value @@ -98,12 +92,11 @@ func buildUpdateResult(response bsoncore.Document, srvr driver.Server) (UpdateRe for _, val := range values { valDoc, ok := val.DocumentOK() if !ok { - err = fmt.Errorf("upserted value is type document, but received BSON type %s", val.Type) - break + return ur, fmt.Errorf("upserted value is type document, but received BSON type %s", val.Type) } var upsert Upsert if err = bson.Unmarshal(valDoc, &upsert); err != nil { - break + return ur, err } ur.Upserted = append(ur.Upserted, upsert) } From 0c2aee6d77bcd4e33e6fa06de1e11b3b80ded65a Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 16 Nov 2021 15:13:10 -0500 Subject: [PATCH 2/7] Remove toml configuration files --- .../driver/operation/abort_transaction.toml | 17 --- x/mongo/driver/operation/aggregate.toml | 48 -------- .../driver/operation/commit_transaction.toml | 22 ---- x/mongo/driver/operation/count.toml | 26 ----- x/mongo/driver/operation/create.toml | 62 ----------- x/mongo/driver/operation/createIndexes.toml | 42 ------- x/mongo/driver/operation/delete.toml | 47 -------- x/mongo/driver/operation/distinct.toml | 37 ------ x/mongo/driver/operation/drop_collection.toml | 21 ---- x/mongo/driver/operation/drop_database.toml | 18 --- x/mongo/driver/operation/drop_indexes.toml | 28 ----- x/mongo/driver/operation/end_sessions.toml | 16 --- x/mongo/driver/operation/find.toml | 105 ------------------ x/mongo/driver/operation/find_and_modify.toml | 73 ------------ x/mongo/driver/operation/insert.toml | 45 -------- x/mongo/driver/operation/listDatabases.toml | 37 ------ .../driver/operation/list_collections.toml | 23 ---- x/mongo/driver/operation/list_indexes.toml | 20 ---- x/mongo/driver/operation/update.toml | 58 ---------- 19 files changed, 745 deletions(-) delete mode 100644 x/mongo/driver/operation/abort_transaction.toml delete mode 100644 x/mongo/driver/operation/aggregate.toml delete mode 100644 x/mongo/driver/operation/commit_transaction.toml delete mode 100644 x/mongo/driver/operation/count.toml delete mode 100644 x/mongo/driver/operation/create.toml delete mode 100644 x/mongo/driver/operation/createIndexes.toml delete mode 100644 x/mongo/driver/operation/delete.toml delete mode 100644 x/mongo/driver/operation/distinct.toml delete mode 100644 x/mongo/driver/operation/drop_collection.toml delete mode 100644 x/mongo/driver/operation/drop_database.toml delete mode 100644 x/mongo/driver/operation/drop_indexes.toml delete mode 100644 x/mongo/driver/operation/end_sessions.toml delete mode 100644 x/mongo/driver/operation/find.toml delete mode 100644 x/mongo/driver/operation/find_and_modify.toml delete mode 100644 x/mongo/driver/operation/insert.toml delete mode 100644 x/mongo/driver/operation/listDatabases.toml delete mode 100644 x/mongo/driver/operation/list_collections.toml delete mode 100644 x/mongo/driver/operation/list_indexes.toml delete mode 100644 x/mongo/driver/operation/update.toml diff --git a/x/mongo/driver/operation/abort_transaction.toml b/x/mongo/driver/operation/abort_transaction.toml deleted file mode 100644 index d4789dd3ef..0000000000 --- a/x/mongo/driver/operation/abort_transaction.toml +++ /dev/null @@ -1,17 +0,0 @@ -version = 0 -name = "AbortTransaction" -documentation = "AbortTransaction performs an abortTransaction operation." - -[properties] -enabled = ["write concern"] -retryable = {mode = "once per command", type = "writes"} - -[command] -name = "abortTransaction" -parameter = "database" - -[request.recoveryToken] -type = "document" -documentation = """ -RecoveryToken sets the recovery token to use when committing or aborting a sharded transaction.\ -""" diff --git a/x/mongo/driver/operation/aggregate.toml b/x/mongo/driver/operation/aggregate.toml deleted file mode 100644 index fd397b9c8d..0000000000 --- a/x/mongo/driver/operation/aggregate.toml +++ /dev/null @@ -1,48 +0,0 @@ -version = 0 -name = "Aggregate" -documentation = "Performs an aggregate operation" -response.type = "batch cursor" - -[properties] -enabled = ["read concern", "read preference", "write concern"] -retryable = {mode = "once per command", type = "reads"} -MinimumWriteConcernWireVersion = 5 - -[command] -name = "aggregate" -parameter = "collection" -database = true - -[request.pipeline] -type = "array" -constructor = true -documentation = "Pipeline determines how data is transformed for an aggregation." - -[request.allowDiskUse] -type = "boolean" -documentation = "AllowDiskUse enables writing to temporary files. When true, aggregation stages can write to the dbPath/_tmp directory." - -[request.batchSize] -type = "int32" -documentation = "BatchSize specifies the number of documents to return in every batch." - -[request.bypassDocumentValidation] -type = "boolean" -documentation = "BypassDocumentValidation allows the write to opt-out of document level validation. This only applies when the $out stage is specified." - -[request.collation] -type = "document" -minWireVersionRequired = 5 -documentation = "Collation specifies a collation. This option is only valid for server versions 3.4 and above." - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." - -[request.comment] -type = "string" -documentation = "Comment specifies an arbitrary string to help trace the operation through the database profiler, currentOp, and logs." - -[request.hint] -type = "value" -documentation = "Hint specifies the index to use." diff --git a/x/mongo/driver/operation/commit_transaction.toml b/x/mongo/driver/operation/commit_transaction.toml deleted file mode 100644 index c49dbd80db..0000000000 --- a/x/mongo/driver/operation/commit_transaction.toml +++ /dev/null @@ -1,22 +0,0 @@ -version = 0 -name = "CommitTransaction" -documentation = "CommitTransaction attempts to commit a transaction." - -[properties] -enabled = ["write concern"] -disabled = ["collection"] -retryable = {mode = "once per command", type = "writes"} - -[command] -name = "commitTransaction" -parameter = "database" - -[request.recoveryToken] -type = "document" -documentation = """ -RecoveryToken sets the recovery token to use when committing or aborting a sharded transaction.\ -""" - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." diff --git a/x/mongo/driver/operation/count.toml b/x/mongo/driver/operation/count.toml deleted file mode 100644 index f5d5e0326c..0000000000 --- a/x/mongo/driver/operation/count.toml +++ /dev/null @@ -1,26 +0,0 @@ -version = 0 -name = "Count" -documentation = "Performs a count operation" - -[properties] -enabled = ["read concern", "read preference"] -retryable = {mode = "once per command", type = "reads"} - -[command] -name = "count" -parameter = "collection" - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." - -[request.query] -type = "document" -documentation = "Query determines what results are returned from find." - -[response] -name = "CountResult" - -[response.field.n] -type = "int64" -documentation = "The number of documents found" diff --git a/x/mongo/driver/operation/create.toml b/x/mongo/driver/operation/create.toml deleted file mode 100644 index c1e29cfc54..0000000000 --- a/x/mongo/driver/operation/create.toml +++ /dev/null @@ -1,62 +0,0 @@ -version = 0 -name = "Create" -documentation = "Create a create operation" - -[properties] -enabled = ["write concern"] -disabled = ["collection"] - -[command] -name = "create" -parameter = "collectionName" - -[request.collectionName] -type = "string" -documentation = "Specifies the name of the collection to create." -skip = true -constructor = true - -[request.capped] -type = "boolean" -documentation = "Specifies if the collection is capped." - -[request.collation] -type = "document" -minWireVersionRequired = 5 -documentation = "Collation specifies a collation. This option is only valid for server versions 3.4 and above." - -[request.indexOptionDefaults] -type = "document" -documentation = "Specifies a default configuration for indexes on the collection." - -[request.max] -type = "int64" -documentation = "Specifies the maximum number of documents allowed in a capped collection." - -[request.pipeline] -type = "array" -documentation = "Specifies the agggregtion pipeline to be run against the source to create the view." - -[request.size] -type = "int64" -documentation = "Specifies the maximum size in bytes for a capped collection." - -[request.storageEngine] -type = "document" -documentation = "Specifies the storage engine to use for the index." - -[request.validator] -type = "document" -documentation = "Specifies validation rules for the collection." - -[request.validationAction] -type = "string" -documentation = "Specifies what should happen if a document being inserted does not pass validation." - -[request.validationLevel] -type = "string" -documentation = "Specifies how strictly the server applies validation rules to existing documents in the collection during update operations." - -[request.viewOn] -type = "string" -documentation = "Specifies the name of the source collection or view on which the view will be created." diff --git a/x/mongo/driver/operation/createIndexes.toml b/x/mongo/driver/operation/createIndexes.toml deleted file mode 100644 index 43373030c0..0000000000 --- a/x/mongo/driver/operation/createIndexes.toml +++ /dev/null @@ -1,42 +0,0 @@ -version = 0 -name = "CreateIndexes" -documentation = "CreateIndexes performs a createIndexes operation." - -[properties] -enabled = ["write concern"] - -[command] -name = "createIndexes" -parameter = "collection" - -[request.indexes] -type = "array" -constructor = true -documentation = "An array containing index specification documents for the indexes being created." - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." - -[request.commitQuorum] -type = "value" -minWireVersionRequired = 9 -documentation = """ -The number of data-bearing members of a replica set, including the primary, that must complete the index builds -successfully before the primary marks the indexes as ready. This should either be a string or int32 value. -""" - -[response] -name = "CreateIndexesResult" - -[response.field.createdCollectionAutomatically] -type = "boolean" -documentation = "If the collection was created automatically." - -[response.field.indexesBefore] -type = "int32" -documentation = "The number of indexes existing before this command." - -[response.field.indexesAfter] -type = "int32" -documentation = "The number of indexes existing after this command." diff --git a/x/mongo/driver/operation/delete.toml b/x/mongo/driver/operation/delete.toml deleted file mode 100644 index dea0a71203..0000000000 --- a/x/mongo/driver/operation/delete.toml +++ /dev/null @@ -1,47 +0,0 @@ -version = 0 -name = "Delete" -documentation = "Delete performs a delete operation" - -[properties] -enabled = ["write concern"] -retryable = {mode = "once per command", type = "writes"} -batches = "deletes" - -[command] -name = "delete" -parameter = "collection" - -[request.deletes] -type = "document" -slice = true -constructor = true -variadic = true -required = true -documentation = """ -Deletes adds documents to this operation that will be used to determine what documents to delete when this operation -is executed. These documents should have the form {q: , limit: , collation: }. The -collation field is optional. If limit is 0, there will be no limit on the number of documents deleted.\ -""" - -[request.ordered] -type = "boolean" -documentation = """ -Ordered sets ordered. If true, when a write fails, the operation will return the error, when -false write failures do not stop execution of the operation.\ -""" - -[request.hint] -type = "boolean" -minWireVersionRequired = 5 -documentation = """ -Hint is a flag to indicate that the update document contains a hint. Hint is only supported by -servers >= 4.4. Older servers >= 3.4 will report an error for using the hint option. For servers < -3.4, the driver will return an error if the hint option is used.\ -""" - -[response] -name = "DeleteResult" - -[response.field.n] -type = "int32" -documentation = "Number of documents successfully deleted." diff --git a/x/mongo/driver/operation/distinct.toml b/x/mongo/driver/operation/distinct.toml deleted file mode 100644 index 81849d564f..0000000000 --- a/x/mongo/driver/operation/distinct.toml +++ /dev/null @@ -1,37 +0,0 @@ -version = 0 -name = "Distinct" -documentation = "Distinct performs a distinct operation." - -[properties] -enabled = ["read concern", "read preference"] -retryable = {mode = "once per command", type = "reads"} - -[command] -name = "distinct" -parameter = "collection" - -[request.key] -type = "string" -constructor = true -documentation = "Key specifies which field to return distinct values for." - -[request.query] -type = "document" -constructor = true -documentation = "Query specifies which documents to return distinct values from." - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." - -[request.collation] -type = "document" -minWireVersionRequired = 5 -documentation = "Collation specifies a collation to be used." - -[response] -name = "DistinctResult" - -[response.field.values] -type = "value" -documentation = "The distinct values for the field." \ No newline at end of file diff --git a/x/mongo/driver/operation/drop_collection.toml b/x/mongo/driver/operation/drop_collection.toml deleted file mode 100644 index b98db33ec6..0000000000 --- a/x/mongo/driver/operation/drop_collection.toml +++ /dev/null @@ -1,21 +0,0 @@ -version = 0 -name = "DropCollection" -documentation = "DropCollection performs a drop operation." - -[command] -name = "drop" -parameter = "collection" - -[properties] -enabled = ["write concern"] - -[response] -name = "DropCollectionResult" - -[response.field.ns] -type = "string" -documentation = "The namespace of the dropped collection." - -[response.field.nIndexesWas] -type = "int32" -documentation = "The number of indexes in the dropped collection." diff --git a/x/mongo/driver/operation/drop_database.toml b/x/mongo/driver/operation/drop_database.toml deleted file mode 100644 index 9c576ea0ad..0000000000 --- a/x/mongo/driver/operation/drop_database.toml +++ /dev/null @@ -1,18 +0,0 @@ -version = 0 -name = "DropDatabase" -documentation = "DropDatabase performs a dropDatabase operation" - -[properties] -enabled = ["write concern"] -disabled = ["collection"] - -[command] -name = "dropDatabase" -parameter = "database" - -[response] -name = "DropDatabaseResult" - -[response.field.dropped] -type = "string" -documentation = "The dropped database." \ No newline at end of file diff --git a/x/mongo/driver/operation/drop_indexes.toml b/x/mongo/driver/operation/drop_indexes.toml deleted file mode 100644 index 8eafe7db06..0000000000 --- a/x/mongo/driver/operation/drop_indexes.toml +++ /dev/null @@ -1,28 +0,0 @@ -version = 0 -name = "DropIndexes" -documentation = "DropIndexes performs an dropIndexes operation." - -[properties] -enabled = ["write concern"] - -[command] -name = "dropIndexes" -parameter = "collection" - -[request.index] -type = "string" -constructor = true -documentation = """ -Index specifies the name of the index to drop. If '*' is specified, all indexes will be dropped. -""" - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." - -[response] -name = "DropIndexesResult" - -[response.field.nIndexesWas] -type = "int32" -documentation = "Number of indexes that existed before the drop was executed." diff --git a/x/mongo/driver/operation/end_sessions.toml b/x/mongo/driver/operation/end_sessions.toml deleted file mode 100644 index 92910548bd..0000000000 --- a/x/mongo/driver/operation/end_sessions.toml +++ /dev/null @@ -1,16 +0,0 @@ -version = 0 -name = "EndSessions" -documentation = "EndSessions performs an endSessions operation." - -[properties] -disabled = ["collection"] - -[command] -name = "endSessions" -parameter = "sessionIDs" - -[request.sessionIDs] -type = "array" -documentation = "sessionIDs specify the sessions to be expired." -skip = true -constructor = true diff --git a/x/mongo/driver/operation/find.toml b/x/mongo/driver/operation/find.toml deleted file mode 100644 index dd52fd3db6..0000000000 --- a/x/mongo/driver/operation/find.toml +++ /dev/null @@ -1,105 +0,0 @@ -version = 0 -name = "Find" -documentation = "Find performs a find operation." -response.type = "batch cursor" - -[properties] -enabled = ["collection", "read concern", "read preference", "command monitor", "client session", "cluster clock"] -retryable = {mode = "once per command", type = "reads"} -legacy = "find" - -[command] -name = "find" -parameter = "collection" - -[request.filter] -type = "document" -constructor = true -documentation = "Filter determines what results are returned from find." - -[request.sort] -type = "document" -documentation = "Sort specifies the order in which to return results." - -[request.projection] -type = "document" -documentation = "Project limits the fields returned for all documents." - -[request.hint] -type = "value" -documentation = "Hint specifies the index to use." - -[request.skip] -type = "int64" -documentation = "Skip specifies the number of documents to skip before returning." - -[request.limit] -type = "int64" -documentation = "Limit sets a limit on the number of documents to return." - -[request.batchSize] -type = "int32" -documentation = "BatchSize specifies the number of documents to return in every batch." - -[request.singleBatch] -type = "boolean" -documentation = "SingleBatch specifies whether the results should be returned in a single batch." - -[request.comment] -type = "string" -documentation = "Comment sets a string to help trace an operation." - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." - -[request.max] -type = "document" -documentation = "Max sets an exclusive upper bound for a specific index." - -[request.min] -type = "document" -documentation = "Min sets an inclusive lower bound for a specific index." - -[request.returnKey] -type = "boolean" -documentation = "ReturnKey when true returns index keys for all result documents." - -[request.showRecordID] -type = "boolean" -documentation = "ShowRecordID when true adds a $recordId field with the record identifier to returned documents." -keyName = "showRecordId" - -[request.oplogReplay] -type = "boolean" -documentation = "OplogReplay when true replays a replica set's oplog." - -[request.noCursorTimeout] -type = "boolean" -documentation = "NoCursorTimeout when true prevents cursor from timing out after an inactivity period." - -[request.tailable] -type = "boolean" -documentation = "Tailable keeps a cursor open and resumable after the last data has been retrieved." - -[request.awaitData] -type = "boolean" -documentation = "AwaitData when true makes a cursor block before returning when no data is available." - -[request.allowPartialResults] -type = "boolean" -documentation = "AllowPartialResults when true allows partial results to be returned if some shards are down." - -[request.allowDiskUse] -type = "boolean" -minWireVersionRequired = 4 -documentation = "AllowDiskUse when true allows temporary data to be written to disk during the find command." - -[request.collation] -type = "document" -minWireVersionRequired = 5 -documentation = "Collation specifies a collation to be used." - -[request.snapshot] -type = "boolean" -documentation = "Snapshot prevents the cursor from returning a document more than once because of an intervening write operation." diff --git a/x/mongo/driver/operation/find_and_modify.toml b/x/mongo/driver/operation/find_and_modify.toml deleted file mode 100644 index 4f5edf260e..0000000000 --- a/x/mongo/driver/operation/find_and_modify.toml +++ /dev/null @@ -1,73 +0,0 @@ -version = 0 -name = "FindAndModify" -documentation = "FindAndModify performs a findAndModify operation." - -[properties] -enabled = ["write concern"] -retryable = {mode = "once", type = "writes"} - -[command] -name = "findAndModify" -parameter = "collection" - -[request.query] -type = "document" -constructor = true -documentation = "Query specifies the selection criteria for the modification." - -[request.sort] -type = "document" -documentation = """ -Sort determines which document the operation modifies if the query matches multiple documents.\ -The first document matched by the sort order will be modified. -""" - -[request.remove] -type = "boolean" -documentation = "Remove specifies that the matched document should be removed. Defaults to false." - -[request.update] -type = "value" -documentation = "Update specifies the update document to perform on the matched document." - -[request.newDocument] -type = "boolean" -documentation = "NewDocument specifies whether to return the modified document or the original. Defaults to false (return original)." - -[request.fields] -type = "document" -documentation = "Fields specifies a subset of fields to return." - -[request.upsert] -type = "boolean" -documentation = "Upsert specifies whether or not to create a new document if no documents match the query when doing an update. Defaults to false." - -[request.bypassDocumentValidation] -type = "boolean" -documentation = "BypassDocumentValidation specifies if document validation can be skipped when executing the operation." - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the operation to run." - -[request.collation] -type = "document" -minWireVersionRequired = 5 -documentation = "Collation specifies a collation to be used." - -[request.arrayFilters] -type = "array" -minWireVersionRequired = 6 -documentation = "ArrayFilters specifies an array of filter documents that determines which array elements to modify for an update operation on an array field." - -[request.hint] -type = "value" -minWireVersionRequired = 8 -documentation = "Hint specifies the index to use. This option is only valid for server versions >= 4.4. Server version 4.2 will error if this option is set. For server versions < 4.2, the driver will error if this option is set." - -[response] -name = "FindAndModifyResult" - -[response.field.value] -type = "document" -documentation = "Either the old or modified document, depending on the value of the new parameter." diff --git a/x/mongo/driver/operation/insert.toml b/x/mongo/driver/operation/insert.toml deleted file mode 100644 index 24fdd51c90..0000000000 --- a/x/mongo/driver/operation/insert.toml +++ /dev/null @@ -1,45 +0,0 @@ -version = 0 -name = "Insert" -documentation = "Insert performs an insert operation." - -[properties] -enabled = ["write concern"] -retryable = {mode = "once per command", type = "writes"} -batches = "documents" - -[command] -name = "insert" -parameter = "collection" - -[request.documents] -type = "document" -slice = true -constructor = true -variadic = true -required = true -documentation = """ -Documents adds documents to this operation that will be inserted when this operation is -executed.\ -""" - -[request.ordered] -type = "boolean" -documentation = """ -Ordered sets ordered. If true, when a write fails, the operation will return the error, when -false write failures do not stop execution of the operation.\ -""" - -[request.bypassDocumentValidation] -type = "boolean" -minWireVersion = 4 -documentation = """ -BypassDocumentValidation allows the operation to opt-out of document level validation. Valid -for server versions >= 3.2. For servers < 3.2, this setting is ignored.\ -""" - -[response] -name = "InsertResult" - -[response.field.n] -type = "int32" -documentation = "Number of documents successfully inserted." diff --git a/x/mongo/driver/operation/listDatabases.toml b/x/mongo/driver/operation/listDatabases.toml deleted file mode 100644 index 29d5a0218b..0000000000 --- a/x/mongo/driver/operation/listDatabases.toml +++ /dev/null @@ -1,37 +0,0 @@ -version = 0 -name = "ListDatabases" -documentation = "ListDatabases performs a listDatabases operation." - -[properties] -enabled = ["read preference"] -retryable = {mode = "once per command", type = "reads"} -disabled = ["collection"] - -[command] -name = "listDatabases" -parameter = "database" - -[request.filter] -type = "document" -constructor = true -documentation = "Filter determines what results are returned from listDatabases." - - -[request.nameOnly] -type = "boolean" -documentation = "NameOnly specifies whether to only return database names." - -[request.authorizedDatabases] -type = "boolean" -documentation = "AuthorizedDatabases specifies whether to only return databases which the user is authorized to use." - -[response] -name = "ListDatabasesResult" - -[response.field.totalSize] -type = "int64" -documentation = "The sum of the size of all the database files on disk in bytes." - -[response.field.databases] -type = "value" -documentation = "An array of documents, one document for each database" diff --git a/x/mongo/driver/operation/list_collections.toml b/x/mongo/driver/operation/list_collections.toml deleted file mode 100644 index 383dae11f8..0000000000 --- a/x/mongo/driver/operation/list_collections.toml +++ /dev/null @@ -1,23 +0,0 @@ -version = 0 -name = "ListCollections" -documentation = "ListCollections performs a listCollections operation." -response.type = "list collections batch cursor" - -[properties] -enabled = ["read preference"] -disabled = ["collection"] -retryable = {mode = "once per command", type = "reads"} -legacy = "listCollections" - -[command] -name = "listCollections" -parameter = "database" - -[request.filter] -type = "document" -constructor = true -documentation = "Filter determines what results are returned from listCollections." - -[request.nameOnly] -type = "boolean" -documentation = "NameOnly specifies whether to only return collection names." diff --git a/x/mongo/driver/operation/list_indexes.toml b/x/mongo/driver/operation/list_indexes.toml deleted file mode 100644 index 98d0f88624..0000000000 --- a/x/mongo/driver/operation/list_indexes.toml +++ /dev/null @@ -1,20 +0,0 @@ -version = 0 -name = "ListIndexes" -documentation = "ListIndexes performs a listIndexes operation." -response.type = "batch cursor" - -[properties] -legacy = "listIndexes" -retryable = {mode = "once per command", type = "reads"} - -[command] -name = "listIndexes" -parameter = "collection" - -[request.batchSize] -type = "int32" -documentation = "BatchSize specifies the number of documents to return in every batch." - -[request.maxTimeMS] -type = "int64" -documentation = "MaxTimeMS specifies the maximum amount of time to allow the query to run." diff --git a/x/mongo/driver/operation/update.toml b/x/mongo/driver/operation/update.toml deleted file mode 100644 index 6690c213e2..0000000000 --- a/x/mongo/driver/operation/update.toml +++ /dev/null @@ -1,58 +0,0 @@ -version = 0 -name = "Update" -documentation = "Update performs an update operation." - -[properties] -enabled = ["write concern"] -retryable = {mode = "once per command", type = "writes"} -batches = "updates" - -[command] -name = "update" -parameter = "collection" - -[request.updates] -type = "document" -slice = true -constructor = true -variadic = true -required = true -documentation = """ -Updates specifies an array of update statements to perform when this operation is executed. -Each update document must have the following structure: {q: , u: , multi: , collation: Optional, arrayFitlers: Optional, hint: Optional}.\ -""" - -[request.ordered] -type = "boolean" -documentation = """ -Ordered sets ordered. If true, when a write fails, the operation will return the error, when -false write failures do not stop execution of the operation.\ -""" - -[request.bypassDocumentValidation] -type = "boolean" -minWireVersion = 4 -documentation = """ -BypassDocumentValidation allows the operation to opt-out of document level validation. Valid -for server versions >= 3.2. For servers < 3.2, this setting is ignored.\ -""" - -[request.hint] -type = "boolean" -minWireVersionRequired = 5 -documentation = """ -Hint is a flag to indicate that the update document contains a hint. Hint is only supported by -servers >= 4.2. Older servers >= 3.4 will report an error for using the hint option. For servers < -3.4, the driver will return an error if the hint option is used.\ -""" - -[response] -name = "UpdateResult" - -[response.field.n] -type = "int32" -documentation = "Number of documents matched." - -[response.field.nModified] -type = "int32" -documentation = "Number of documents modified." From af28bd8d3a44fce0b665f9903c64ec9030a576e7 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 16 Nov 2021 15:15:11 -0500 Subject: [PATCH 3/7] Remove cmd/operation and x/mongo/driver/drivergen --- cmd/operationgen/README.md | 11 - cmd/operationgen/main.go | 80 -- x/mongo/driver/drivergen/drivergen.go | 757 ------------------ x/mongo/driver/drivergen/drivergen_test.go | 28 - .../driver/drivergen/example.operation.toml | 110 --- x/mongo/driver/drivergen/templates.go | 84 -- .../templates/command_parameter.tmpl | 83 -- .../driver/drivergen/templates/operation.tmpl | 249 ------ .../drivergen/templates/response_field.tmpl | 49 -- 9 files changed, 1451 deletions(-) delete mode 100644 cmd/operationgen/README.md delete mode 100644 cmd/operationgen/main.go delete mode 100644 x/mongo/driver/drivergen/drivergen.go delete mode 100644 x/mongo/driver/drivergen/drivergen_test.go delete mode 100644 x/mongo/driver/drivergen/example.operation.toml delete mode 100644 x/mongo/driver/drivergen/templates.go delete mode 100644 x/mongo/driver/drivergen/templates/command_parameter.tmpl delete mode 100644 x/mongo/driver/drivergen/templates/operation.tmpl delete mode 100644 x/mongo/driver/drivergen/templates/response_field.tmpl diff --git a/cmd/operationgen/README.md b/cmd/operationgen/README.md deleted file mode 100644 index 16154784c4..0000000000 --- a/cmd/operationgen/README.md +++ /dev/null @@ -1,11 +0,0 @@ -The `operationgen` tool -======================= -The `operationgen` tool is used to generate operations from the IDL accepted by the `drivergen` -package. Most of the documentation for code generation can be found in the `drivergen` package. - -Building --------- -Building `operationgen` requires a special library called -[packr](https://github.com/gobuffalo/packr). Make sure you call `packr2 install` to install -`operationgen`. Before committing, ensure you call `packr2 clean` to remove the generated files. -This will help avoid bloating the git repository with unnecessary files. diff --git a/cmd/operationgen/main.go b/cmd/operationgen/main.go deleted file mode 100644 index bd9fa7e239..0000000000 --- a/cmd/operationgen/main.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "bytes" - "flag" - "fmt" - "log" - "os" - - "go.mongodb.org/mongo-driver/x/mongo/driver/drivergen" - "golang.org/x/tools/imports" -) - -func main() { - fs := flag.NewFlagSet("", flag.ExitOnError) - fs.Usage = func() { - fmt.Fprintln(fs.Output(), "operationgen is used to generate operation implementations.") - fmt.Fprintln(fs.Output(), "usage: operationgen ") - fs.PrintDefaults() - } - var dryrun bool - fs.BoolVar(&dryrun, "dryrun", false, "prints the output to stdout instead of writing to a file.") - err := fs.Parse(os.Args[1:]) - if err == flag.ErrHelp { - fs.Usage() - os.Exit(0) - } - if err != nil { - log.Fatalf("Could not parse flags: %v", err) - } - args := fs.Args() - if len(args) < 3 { - log.Println("Insufficient arguments specified.") - fs.Usage() - os.Exit(1) - } - config := args[0] - pkg := args[1] - filename := args[2] - - err = drivergen.Initialize() - if err != nil { - log.Fatalf("Could not initialize drivergen: %v", err) - } - - op, err := drivergen.ParseFile(config, pkg) - if err != nil { - log.Fatalf("Could not parse configuration file '%s': %v", config, err) - } - var b bytes.Buffer - err = op.Generate(&b) - if err != nil { - log.Fatalf("Could not generate operation: %v", err) - } - wd, err := os.Getwd() - if err != nil { - log.Fatalf("Could not get the current working directory: %v", err) - } - buf, err := imports.Process(wd, b.Bytes(), nil) - if err != nil { - if dryrun { - fmt.Println(b.String()) - } - log.Fatalf("Could not run goimports on generated file: %v", err) - } - if dryrun { - os.Stdout.Write(buf) - os.Exit(0) - } - - file, err := os.Create(filename) - if err != nil { - log.Fatalf("Could not create %s: %v", filename, err) - } - - _, err = file.Write(buf) - if err != nil { - log.Fatalf("Could not write to %s: %v", filename, err) - } -} diff --git a/x/mongo/driver/drivergen/drivergen.go b/x/mongo/driver/drivergen/drivergen.go deleted file mode 100644 index e95b986f4b..0000000000 --- a/x/mongo/driver/drivergen/drivergen.go +++ /dev/null @@ -1,757 +0,0 @@ -package drivergen - -import ( - "bytes" - "fmt" - "io" - "sort" - "strings" - "text/template" - "unicode" - - "github.com/pelletier/go-toml" -) - -// Operation is the top-level configuration type. It's the direct representation of an operation -// TOML file. -type Operation struct { - Name string - Documentation string - Version int - DriverInternal bool - Properties Properties - Command Command - Request map[string]RequestField - Response Response - - pkg string -} - -// PackageName returns the package name to use when generating the operation. -func (op Operation) PackageName() string { return op.pkg } - -// Generate creates the operation type and associated response types and writes them to w. -func (op Operation) Generate(w io.Writer) error { - t, err := template.New(op.Name + " operation").Parse(typeTemplate) - if err != nil { - return err - } - return t.Execute(w, op) -} - -// ShortName returns the receiver used for this operation. -func (op Operation) ShortName() string { - name := op.Name - if len(name) == 0 { - return "" - } - short := strings.ToLower(string(name[0])) - idx := 1 - for { - i := strings.IndexFunc(name[idx:], unicode.IsUpper) - if i == -1 { - break - } - idx += i - short += strings.ToLower(string(name[idx])) - idx++ - } - return short -} - -// ResultType returns the type to use as the result of running this operation. -func (op Operation) ResultType() string { - return op.Response.Name -} - -// Title wraps strings.Title for use in templates. -func (op Operation) Title(name string) string { return strings.Title(name) } - -// EscapeDocumentation will add the required // in front of each line of documentation. -func (Operation) EscapeDocumentation(doc string) string { - var slc []string - for _, line := range strings.Split(doc, "\n") { - slc = append(slc, "// "+line) - } - return strings.Join(slc, "\n") -} - -// ConstructorParameters builds the parameter names and types for the operation constructor. -func (op Operation) ConstructorParameters() string { - var parameters []string - for name, field := range op.Request { - if !field.Constructor { - continue - } - parameters = append(parameters, name+" "+field.ParameterType()) - } - return strings.Join(parameters, ", ") -} - -// ConstructorFields returns a slice of name name pairs that set fields in a newly instantiated -// operation. -func (op Operation) ConstructorFields() []string { - var fields []string - for name, field := range op.Request { - if !field.Constructor { - continue - } - // either "name: name," or "name: &name," - fieldName := name - if field.PointerType() { - fieldName = "&" + name - } - fields = append(fields, name+": "+fieldName+",") - } - return fields -} - -// CommandMethod returns the code required to transform the operation into a command. This code only -// returns the contents of the command method, without the function definition and return. -func (op Operation) CommandMethod() (string, error) { - var buf bytes.Buffer - switch op.Command.Parameter { - case "collection": - tmpl := commandCollectionTmpl - if op.Command.Database { - tmpl = commandCollectionDatabaseTmpl - } - err := tmpl.Execute(&buf, op) - if err != nil { - return "", err - } - case "database": - tmpl := commandDatabaseTmpl - err := tmpl.Execute(&buf, op) - if err != nil { - return "", err - } - default: - var tmpl *template.Template - field, ok := op.Request[op.Command.Parameter] - if !ok { - return "", fmt.Errorf( - "no request field named '%s' but '%s' is specified as the command parameter", - op.Command.Parameter, op.Command.Parameter, - ) - } - switch field.Type { - case "double": - tmpl = commandParamDoubleTmpl - case "string": - tmpl = commandParamStringTmpl - case "document": - tmpl = commandParamDocumentTmpl - case "array": - tmpl = commandParamArrayTmpl - case "boolean": - tmpl = commandParamBooleanTmpl - case "int32": - tmpl = commandParamInt32Tmpl - case "int64": - tmpl = commandParamInt64Tmpl - default: - return "", fmt.Errorf("unknown request field type %s", field.Type) - } - var rf struct { - ShortName string - Name string - ParameterName string - MinWireVersion int - MinWireVersionRequired int - } - rf.ShortName = op.ShortName() - rf.Name = op.Command.Parameter - rf.ParameterName = op.Command.Name - rf.MinWireVersion = field.MinWireVersion - rf.MinWireVersionRequired = field.MinWireVersionRequired - err := tmpl.Execute(&buf, rf) - if err != nil { - return "", err - } - } - names := make([]string, 0, len(op.Request)) - for name := range op.Request { - names = append(names, name) - } - sort.Strings(names) - for _, name := range names { - field := op.Request[name] - if name == op.Properties.Batches || field.Skip { - continue - } - var tmpl *template.Template - switch field.Type { - case "double": - tmpl = commandParamDoubleTmpl - case "string": - tmpl = commandParamStringTmpl - case "document": - tmpl = commandParamDocumentTmpl - case "array": - tmpl = commandParamArrayTmpl - case "boolean": - tmpl = commandParamBooleanTmpl - case "int32": - tmpl = commandParamInt32Tmpl - case "int64": - tmpl = commandParamInt64Tmpl - case "value": - tmpl = commandParamValueTmpl - default: - return "", fmt.Errorf("unknown request field type %s", field.Type) - } - var rf struct { - ShortName string - Name string - ParameterName string - MinWireVersion int - MinWireVersionRequired int - } - rf.ShortName = op.ShortName() - rf.Name = name - rf.ParameterName = name - if field.KeyName != "" { - rf.ParameterName = field.KeyName - } - rf.MinWireVersion = field.MinWireVersion - rf.MinWireVersionRequired = field.MinWireVersionRequired - err := tmpl.Execute(&buf, rf) - if err != nil { - return "", err - } - - } - return buf.String(), nil -} - -// Properties represent general properties of the operation. -type Properties struct { - Disabled []Builtin - Enabled []Builtin - Retryable Retryable - Batches string - Legacy LegacyOperation - MinimumWriteConcernWireVersion int - MinimumReadConcernWireVersion int -} - -// Builtins returns a slice of built-ins that is the combination of the non-disabled default -// built-ins plus any enabled non-default built-ins. -func (p Properties) Builtins() []Builtin { - defaults := map[Builtin]struct{}{ - Deployment: {}, - Database: {}, - Selector: {}, - CommandMonitor: {}, - ClientSession: {}, - ClusterClock: {}, - Collection: {}, - Crypt: {}, - } - for _, builtin := range p.Disabled { - delete(defaults, builtin) - } - builtins := make([]Builtin, 0, len(defaults)+len(p.Enabled)) - // We don't do this in a loop because we want them to be in a stable order. - if _, ok := defaults[Deployment]; ok { - builtins = append(builtins, Deployment) - } - if _, ok := defaults[Database]; ok { - builtins = append(builtins, Database) - } - if _, ok := defaults[Selector]; ok { - builtins = append(builtins, Selector) - } - if _, ok := defaults[CommandMonitor]; ok { - builtins = append(builtins, CommandMonitor) - } - if _, ok := defaults[ClientSession]; ok { - builtins = append(builtins, ClientSession) - } - if _, ok := defaults[ClusterClock]; ok { - builtins = append(builtins, ClusterClock) - } - if _, ok := defaults[Collection]; ok { - builtins = append(builtins, Collection) - } - if _, ok := defaults[Crypt]; ok { - builtins = append(builtins, Crypt) - } - for _, builtin := range p.Enabled { - switch builtin { - case Deployment, Database, Selector, CommandMonitor, ClientSession, ClusterClock, Collection, Crypt: - continue // If someone added a default to enable, just ignore it. - } - builtins = append(builtins, builtin) - } - sort.Slice(builtins, func(i, j int) bool { return builtins[i] < builtins[j] }) - return builtins -} - -// ExecuteBuiltins returns the builtins that need to be set on the driver.Operation for the -// properties set. -func (p Properties) ExecuteBuiltins() []Builtin { - builtins := p.Builtins() - fields := make([]Builtin, 0, len(builtins)) - for _, builtin := range builtins { - if builtin == Collection { - continue // We don't include this in execute. - } - fields = append(fields, builtin) - } - return fields -} - -// IsEnabled returns a Builtin if the string that matches that built-in is enabled. If it's not, an -// empty string is returned. -func (p Properties) IsEnabled(builtin string) Builtin { - m := p.BuiltinsMap() - if b := m[Builtin(builtin)]; b { - return Builtin(builtin) - } - return "" -} - -// BuiltinsMap returns a map with the builtins that enabled. -func (p Properties) BuiltinsMap() map[Builtin]bool { - builtins := make(map[Builtin]bool) - for _, builtin := range p.Builtins() { - builtins[builtin] = true - } - return builtins -} - -// LegacyOperationKind returns the corresponding LegacyOperationKind value for an operation. -func (p Properties) LegacyOperationKind() string { - switch p.Legacy { - case LegacyFind: - return "driver.LegacyFind" - case LegacyGetMore: - return "driver.LegacyGetMore" - case LegacyKillCursors: - return "driver.LegacyKillCursors" - case LegacyListCollections: - return "driver.LegacyListCollections" - case LegacyListIndexes: - return "driver.LegacyListIndexes" - default: - return "driver.LegacyNone" - } -} - -// Retryable represents retryable information for an operation. -type Retryable struct { - Mode RetryableMode - Type RetryableType -} - -// RetryableMode are the configuration representations of the retryability modes. -type RetryableMode string - -// These constants are the various retryability modes. -const ( - RetryableOnce RetryableMode = "once" - RetryableOncePerCommand RetryableMode = "once per command" - RetryableContext RetryableMode = "context" -) - -// RetryableType instances are the configuration representation of a kind of retryability. -type RetryableType string - -// These constants are the various retryable types. -const ( - RetryableWrites RetryableType = "writes" - RetryableReads RetryableType = "reads" -) - -// LegacyOperation enables legacy versions of find, getMore, or killCursors operations. -type LegacyOperation string - -// These constants are the various legacy operations that can be generated. -const ( - LegacyFind LegacyOperation = "find" - LegacyGetMore LegacyOperation = "getMore" - LegacyKillCursors LegacyOperation = "killCursors" - LegacyListCollections LegacyOperation = "listCollections" - LegacyListIndexes LegacyOperation = "listIndexes" -) - -// Builtin represent types that are built into the IDL. -type Builtin string - -// These constants are the built in types. -const ( - Collection Builtin = "collection" - ReadPreference Builtin = "read preference" - ReadConcern Builtin = "read concern" - WriteConcern Builtin = "write concern" - CommandMonitor Builtin = "command monitor" - ClientSession Builtin = "client session" - ClusterClock Builtin = "cluster clock" - Selector Builtin = "selector" - Database Builtin = "database" - Deployment Builtin = "deployment" - Crypt Builtin = "crypt" -) - -// ExecuteName provides the name used when setting this built-in on a driver.Operation. -func (b Builtin) ExecuteName() string { - var execname string - switch b { - case ReadPreference: - execname = "ReadPreference" - case ReadConcern: - execname = "ReadConcern" - case WriteConcern: - execname = "WriteConcern" - case CommandMonitor: - execname = "CommandMonitor" - case ClientSession: - execname = "Client" - case ClusterClock: - execname = "Clock" - case Selector: - execname = "Selector" - case Database: - execname = "Database" - case Deployment: - execname = "Deployment" - case Crypt: - execname = "Crypt" - } - return execname -} - -// ReferenceName returns the short name used to refer to this built in. It is used as the field name -// in the struct and as the variable name for the setter. -func (b Builtin) ReferenceName() string { - var refname string - switch b { - case Collection: - refname = "collection" - case ReadPreference: - refname = "readPreference" - case ReadConcern: - refname = "readConcern" - case WriteConcern: - refname = "writeConcern" - case CommandMonitor: - refname = "monitor" - case ClientSession: - refname = "session" - case ClusterClock: - refname = "clock" - case Selector: - refname = "selector" - case Database: - refname = "database" - case Deployment: - refname = "deployment" - case Crypt: - refname = "crypt" - } - return refname -} - -// SetterName returns the name to be used when creating a setter for this built-in. -func (b Builtin) SetterName() string { - var setter string - switch b { - case Collection: - setter = "Collection" - case ReadPreference: - setter = "ReadPreference" - case ReadConcern: - setter = "ReadConcern" - case WriteConcern: - setter = "WriteConcern" - case CommandMonitor: - setter = "CommandMonitor" - case ClientSession: - setter = "Session" - case ClusterClock: - setter = "ClusterClock" - case Selector: - setter = "ServerSelector" - case Database: - setter = "Database" - case Deployment: - setter = "Deployment" - case Crypt: - setter = "Crypt" - } - return setter -} - -// Type returns the Go type for this built-in. -func (b Builtin) Type() string { - var t string - switch b { - case Collection: - t = "string" - case ReadPreference: - t = "*readpref.ReadPref" - case ReadConcern: - t = "*readconcern.ReadConcern" - case WriteConcern: - t = "*writeconcern.WriteConcern" - case CommandMonitor: - t = "*event.CommandMonitor" - case ClientSession: - t = "*session.Client" - case ClusterClock: - t = "*session.ClusterClock" - case Selector: - t = "description.ServerSelector" - case Database: - t = "string" - case Deployment: - t = "driver.Deployment" - case Crypt: - t = "driver.Crypt" - } - return t -} - -// Documentation returns the GoDoc documentation for this built-in. -func (b Builtin) Documentation() string { - var doc string - switch b { - case Collection: - doc = "Collection sets the collection that this command will run against." - case ReadPreference: - doc = "ReadPreference set the read prefernce used with this operation." - case ReadConcern: - doc = "ReadConcern specifies the read concern for this operation." - case WriteConcern: - doc = "WriteConcern sets the write concern for this operation." - case CommandMonitor: - doc = "CommandMonitor sets the monitor to use for APM events." - case ClientSession: - doc = "Session sets the session for this operation." - case ClusterClock: - doc = "ClusterClock sets the cluster clock for this operation." - case Selector: - doc = "ServerSelector sets the selector used to retrieve a server." - case Database: - doc = "Database sets the database to run this operation against." - case Deployment: - doc = "Deployment sets the deployment to use for this operation." - case Crypt: - doc = "Crypt sets the Crypt object to use for automatic encryption and decryption." - } - return doc -} - -// Command holds the command serialization specific information for an operation. -type Command struct { - Name string - Parameter string - Database bool -} - -// RequestField represents an individual operation field. -type RequestField struct { - Type string - Slice bool - Constructor bool - Variadic bool - Skip bool - Documentation string - MinWireVersion int - MinWireVersionRequired int - KeyName string -} - -// Command returns a string function that sets the key to name and value to the RequestField type. -// It uses accessor to access the parameter. The accessor parameter should be the shortname of the -// operation and the name of the field of the property used for the command name. For example, if -// the shortname is "eo" and the field is "collection" then accessor should be "eo.collection". -func (rf RequestField) Command(name, accessor string) string { - return "" -} - -// ParameterType returns this field's type for use as a parameter argument. -func (rf RequestField) ParameterType() string { - var param string - if rf.Slice && !rf.Variadic { - param = "[]" - } - if rf.Variadic { - param = "..." - } - switch rf.Type { - case "double": - param += "float64" - case "string": - param += "string" - case "document", "array": - param += "bsoncore.Document" - case "binary": - case "boolean": - param += "bool" - case "int32": - param += "int32" - case "int64": - param += "int64" - case "value": - param += "bsoncore.Value" - } - return param -} - -// DeclarationType returns this field's type for use in a struct type declaration. -func (rf RequestField) DeclarationType() string { - var decl string - switch rf.Type { - case "double", "string", "boolean", "int32", "int64": - decl = "*" - } - if rf.Slice { - decl = "[]" - } - switch rf.Type { - case "double": - decl += "float64" - case "string": - decl += "string" - case "document", "array": - decl += "bsoncore.Document" - case "binary": - case "boolean": - decl += "bool" - case "int32": - decl += "int32" - case "int64": - decl += "int64" - case "value": - decl += "bsoncore.Value" - } - return decl -} - -// PointerType returns true if the request field is a pointer type and the setter should take the -// address when setting via a setter method. -func (rf RequestField) PointerType() bool { - switch rf.Type { - case "double", "string", "boolean", "int32", "int64": - return true - default: - return false - } -} - -// Response represents a response type to generate. -type Response struct { - Name string - Type string - Field map[string]ResponseField -} - -// ResponseField is an individual field of a response. -type ResponseField struct { - Type string - Documentation string -} - -// DeclarationType returns the field's type for use in a struct type declaration. -func (rf ResponseField) DeclarationType() string { - switch rf.Type { - case "boolean": - return "bool" - case "value": - return "bsoncore.Value" - default: - return rf.Type - } -} - -// BuiltinResponseType is the type used to define built in response types. -type BuiltinResponseType string - -// These constants represents the different built in response types. -const ( - BatchCursor BuiltinResponseType = "batch cursor" -) - -// BuildMethod handles creating the body of a method to create a response from a BSON response -// document. -// -// TODO(GODRIVER-1094): This method is hacky because we're not using nested templates like we should -// be. Each template should be registered and we should be calling the template to create it. -func (r Response) BuildMethod() (string, error) { - var buf bytes.Buffer - names := make([]string, 0, len(r.Field)) - for name := range r.Field { - names = append(names, name) - } - sort.Strings(names) - for _, name := range names { - field := r.Field[name] - var tmpl *template.Template - switch field.Type { - case "boolean": - tmpl = responseFieldBooleanTmpl - case "int32": - tmpl = responseFieldInt32Tmpl - case "int64": - tmpl = responseFieldInt64Tmpl - case "string": - tmpl = responseFieldStringTmpl - case "value": - tmpl = responseFieldValueTmpl - case "document": - tmpl = responseFieldDocumentTmpl - default: - return "", fmt.Errorf("unknown response field type %s", field.Type) - } - var rf struct { - ResponseName string // Key of the BSON response. - ResponseShortName string // Receiver for the type being built. - Field string // Name of the Go response type field. - } - rf.ResponseShortName = r.ShortName() - rf.ResponseName = name - rf.Field = strings.Title(name) - err := tmpl.Execute(&buf, rf) - if err != nil { - return "", err - } - - } - return buf.String(), nil -} - -// ShortName returns the short name used when constructing a response. -func (r Response) ShortName() string { - name := r.Name - if len(name) == 0 { - return "" - } - short := strings.ToLower(string(name[0])) - idx := 1 - for { - i := strings.IndexFunc(name[idx:], unicode.IsUpper) - if i == -1 { - break - } - idx += i - short += strings.ToLower(string(name[idx])) - idx++ - } - return short -} - -// ParseFile will construct an Operation using the TOML in filename. The Operation will have the -// package name set to packagename. -func ParseFile(filename, packagename string) (Operation, error) { - tree, err := toml.LoadFile(filename) - if err != nil { - return Operation{}, err - } - var op Operation - err = tree.Unmarshal(&op) - op.pkg = packagename - return op, err -} diff --git a/x/mongo/driver/drivergen/drivergen_test.go b/x/mongo/driver/drivergen/drivergen_test.go deleted file mode 100644 index cac2b289ab..0000000000 --- a/x/mongo/driver/drivergen/drivergen_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package drivergen - -import ( - "bytes" - "testing" - - "golang.org/x/tools/imports" -) - -func TestParseFile(t *testing.T) { - err := Initialize() - if err != nil { - t.Fatalf("Unexpected error while initializing drivergen: %v", err) - } - op, err := ParseFile("example.operation.toml", "operation") - if err != nil { - t.Fatalf("Unexepcted error while parsing the operation file: %v", err) - } - var b bytes.Buffer - err = op.Generate(&b) - if err != nil { - t.Fatalf("Unexpected error while generating operation: %v", err) - } - _, err = imports.Process("~/src/x/mongo/driver/operation/operation.go", b.Bytes(), nil) - if err != nil { - t.Fatalf("Unexpected error while running imports: %v", err) - } -} diff --git a/x/mongo/driver/drivergen/example.operation.toml b/x/mongo/driver/drivergen/example.operation.toml deleted file mode 100644 index 07ec20a6cf..0000000000 --- a/x/mongo/driver/drivergen/example.operation.toml +++ /dev/null @@ -1,110 +0,0 @@ -# Version is the version of the idl. -version = 0 - -# Name is the type name of the operation to generate. -name = "ExampleOperation" - -[properties] -# Built-ins are fields that are built into the IDL language. Generators know how to create and -# document setters for them and transform them into BSON. A built-in can be default, in which case -# it can be explicitly disabled. If a built-in is not default, it must be explicitly enabled. - -# Disabled is an array of default built-ins to disable. The default fields are: database, -# deployment, selector, command monitor, client session, cluster clock, and collection. The database -# and deployment built-ins should not be disabled because removal will result in a command that will -# always error. -disabled = ["selector"] - -# Enabled is an array of non-default built-ins to enable. The available fields are: read preference, -# read concern, and write concern. -enabled = ["read preference", "read concern"] - -# Retryable is a table with two key/value pairs: Mode and Type. Mode specifies the default mode that -# will be used for retrying. The generator will add a setter for the mode so the user can override -# it. The mode can be one of: once, once per command, or context. Type is the kind of operation that -# is being retried. The type field can be either writes or reads. If the Mode field is set, the Type -# field must also be set. -retryable = {mode = "once per command", type = "writes"} - -# Batches enables batch splitting for this operation. It's value is the name of a request field that -# will be used for batch splitting. If a request field named "ordered" is defined, it will be used -# to determine ordering for batch commands. The type of the field must be "array". -batches = "examples" - -# Legacy specifies that this operation will execute a legacy command when the max wire version of -# the server is below a specific number. The three values for legacy are: find, getMore, and -# killCursors. -legacy = "none" - -# MinimumWriteConcernWireVersion specifies the minimum wire version required to add a write concern to -# this operation. -MinimumWriteConcernWireVersion = 4 - -# MinimumReadConcernWireVersion specifies the minimum wire version required to add a read concern to -# this operation. -MinimumReadConcernWireVersion = 4 - -# command defines specific information about the command that will be constructed. -[command] -# name is the command name, which will be the first field of the BSON document representing the -# command. -name = "example" - -# The parameter specifies which request field should be used to fill in this value. -parameter = "collection" - -# Database, when true, indicates that if the parameter field is empty, the command is being run on a -# database and should use the value 1 when running the command. -database = true - -# Request is a map of fields that are parameters for the operation. A setter will be generated for -# each and they will be added to the request command sent to the server. -[request] - -# The name of the table within the request table will be used internally in the generated command. -[request.examples] -# Type specifies the type to use. For now these map directly to BSON types. The currently supported -# types are: value, double, string, document, binary, boolean, int32, and int64. -type = "document" -# Slice, when true, indicates that the field is a slice of the type. -slice = true -# Constructor, when true, indicates that this field is a parameter of the constructor for the -# operation. -constructor = true -# Variadic only has an effect if constructor is also true. When true, variadic indicates that the -# parameter for this field should be last and should be variadic. -variadic = true -# MinWireVersion specifies the minimum wire version required to add this field to a command. -minWireVersion = 5 -# Documentation is the documentation comment that will be used for the setter. This is used verbatim -# so the first word should be a capitalized version of the field name. -documentation = """ -Examples adds example documents to this operation. They will be inserted into the -collection specified""" - -[request.ordered] -type = "boolean" -documentation = """ -Ordered sets ordered. If true, when a write fails, the operation will return the error, when -false write failures do not stop execution of the operation.""" - -# Response is a map of fields that form the structure of the expected response. Metadata, like the -# cluster and operation times, should not be included unless they are required to be provided to the -# caller. This table is used to generate a type that will be returned after running the command. If -# the operation supports batches, a single instance of the generated type will be created and -# updated with the responses from subsequent commands. -[response] -# Name is the name that is used for the generated type. -name = "ExampleResult" - -# Type indicates what type this response is. This can only be set if name is not set. The only valid -# value at this time is batch cursor. -# type = "batch cursor" - -# The name of the table within the response table will be the name of the field in the created type. -[response.field.n] -# Type specifies the type to use for the field. For now these map directly to BSON types. -type = "int64" -# Documentation is the documentation comment that will be added above the field in the generated -# type. This is used verbatim. -documentation = "Number of examples created." diff --git a/x/mongo/driver/drivergen/templates.go b/x/mongo/driver/drivergen/templates.go deleted file mode 100644 index a0ccbd3378..0000000000 --- a/x/mongo/driver/drivergen/templates.go +++ /dev/null @@ -1,84 +0,0 @@ -package drivergen - -import ( - "text/template" - - "github.com/gobuffalo/packr/v2" -) - -// commandCollectionDatabaseTmpl is the template used to set the command name when the command can -// apply to either a collection or a database. -var commandCollectionDatabaseTmpl *template.Template - -// commandCollectionTmpl is the template used to set the command name when the parameter will be a -// collection. -var commandCollectionTmpl *template.Template - -// commandDatabaseTmpl is the template used to set the command name when the parameter will be a database. -var commandDatabaseTmpl *template.Template - -var commandParamDocumentTmpl *template.Template -var commandParamArrayTmpl *template.Template -var commandParamValueTmpl *template.Template -var commandParamInt32Tmpl *template.Template -var commandParamInt64Tmpl *template.Template -var commandParamDoubleTmpl *template.Template -var commandParamBooleanTmpl *template.Template -var commandParamStringTmpl *template.Template - -var responseFieldInt64Tmpl *template.Template -var responseFieldInt32Tmpl *template.Template -var responseFieldBooleanTmpl *template.Template -var responseFieldStringTmpl *template.Template -var responseFieldValueTmpl *template.Template -var responseFieldDocumentTmpl *template.Template - -var typeTemplate string - -var templates = packr.New("templates", "./templates") - -// Initialize sets up drivergen for use. It must be called or all of the templates will be nil. -func Initialize() error { - commandParameters, err := templates.FindString("command_parameter.tmpl") - if err != nil { - return err - } - commandParametersTmpl, err := template.New("commandParameters").Parse(commandParameters) - if err != nil { - return err - } - responseFields, err := templates.FindString("response_field.tmpl") - if err != nil { - return err - } - responseFieldsTmpl, err := template.New("responseFields").Parse(responseFields) - if err != nil { - return err - } - typeTemplate, err = templates.FindString("operation.tmpl") - if err != nil { - return err - } - - commandCollectionDatabaseTmpl = commandParametersTmpl.Lookup("commandParamCollectionDatabase") - commandCollectionTmpl = commandParametersTmpl.Lookup("commandParamCollection") - commandDatabaseTmpl = commandParametersTmpl.Lookup("commandParamDatabase") - - commandParamDocumentTmpl = commandParametersTmpl.Lookup("commandParamDocument") - commandParamArrayTmpl = commandParametersTmpl.Lookup("commandParamArray") - commandParamBooleanTmpl = commandParametersTmpl.Lookup("commandParamBoolean") - commandParamValueTmpl = commandParametersTmpl.Lookup("commandParamValue") - commandParamInt32Tmpl = commandParametersTmpl.Lookup("commandParamInt32") - commandParamInt64Tmpl = commandParametersTmpl.Lookup("commandParamInt64") - commandParamDoubleTmpl = commandParametersTmpl.Lookup("commandParamDouble") - commandParamStringTmpl = commandParametersTmpl.Lookup("commandParamString") - - responseFieldInt64Tmpl = responseFieldsTmpl.Lookup("responseFieldInt64") - responseFieldInt32Tmpl = responseFieldsTmpl.Lookup("responseFieldInt32") - responseFieldBooleanTmpl = responseFieldsTmpl.Lookup("responseFieldBoolean") - responseFieldStringTmpl = responseFieldsTmpl.Lookup("responseFieldString") - responseFieldValueTmpl = responseFieldsTmpl.Lookup("responseFieldValue") - responseFieldDocumentTmpl = responseFieldsTmpl.Lookup("responseFieldDocument") - - return nil -} diff --git a/x/mongo/driver/drivergen/templates/command_parameter.tmpl b/x/mongo/driver/drivergen/templates/command_parameter.tmpl deleted file mode 100644 index 819253bacc..0000000000 --- a/x/mongo/driver/drivergen/templates/command_parameter.tmpl +++ /dev/null @@ -1,83 +0,0 @@ -{{define "minWireVersion" -}} -{{- if $.MinWireVersion -}} - && (desc.WireVersion != nil && desc.WireVersion.Includes({{$.MinWireVersion}})) -{{- end}}{{end}} - -{{define "minWireVersionRequired"}} -{{- if $.MinWireVersionRequired}} -if desc.WireVersion == nil || !desc.WireVersion.Includes({{$.MinWireVersionRequired}}) { - return nil, errors.New("the '{{$.ParameterName}}' command parameter requires a minimum server wire version of {{$.MinWireVersionRequired}}") -} -{{end}}{{end}} - -{{define "commandParamCollectionDatabase" -}} -header := bsoncore.Value{Type: bsontype.String, Data: bsoncore.AppendString(nil, {{$.ShortName}}.collection)} -if {{$.ShortName}}.collection == "" { - header = bsoncore.Value{Type: bsontype.Int32, Data: []byte{0x01, 0x00, 0x00, 0x00}} -} -dst = bsoncore.AppendValueElement(dst, "{{$.Command.Name}}", header) -{{end}} - -{{define "commandParamDatabase"}} -dst = bsoncore.AppendInt32Element(dst, "{{$.Command.Name}}", 1) -{{end}} - -{{define "commandParamCollection" -}} -dst = bsoncore.AppendStringElement(dst, "{{$.Command.Name}}", {{$.ShortName}}.collection) -{{end}} - -{{define "commandParamDocument" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendDocumentElement(dst, "{{$.ParameterName}}", {{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamArray" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendArrayElement(dst, "{{$.ParameterName}}", {{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamValue" -}} -if {{$.ShortName}}.{{$.Name}}.Type != bsontype.Type(0) {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendValueElement(dst, "{{$.ParameterName}}", {{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamInt32" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendInt32Element(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamInt64" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendInt64Element(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamDouble" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendDoubleElement(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamBoolean" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendBooleanElement(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) -} -{{end}} - -{{define "commandParamString" -}} -if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { - {{- template "minWireVersionRequired" $ -}} - dst = bsoncore.AppendStringElement(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) -} -{{end}} diff --git a/x/mongo/driver/drivergen/templates/operation.tmpl b/x/mongo/driver/drivergen/templates/operation.tmpl deleted file mode 100644 index 7d6fff977a..0000000000 --- a/x/mongo/driver/drivergen/templates/operation.tmpl +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (C) MongoDB, Inc. 2019-present. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. You may obtain -// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - -// Code generated by operationgen. DO NOT EDIT. - -package {{$.PackageName}} - -import "go.mongodb.org/mongo-driver/x/mongo/driver" - -{{$.EscapeDocumentation $.Documentation}} -type {{$.Name}} struct { - -{{- /* Request Parameter Fields */ -}} -{{- range $name, $field := $.Request}} - {{$name}} {{$field.DeclarationType}} -{{- end -}} - -{{- /* Built In Types */ -}} -{{- range $builtin := $.Properties.Builtins}} - {{$builtin.ReferenceName}} {{$builtin.Type}} -{{- end -}} - -{{- /* Retryability */ -}} -{{- if $.Properties.Retryable.Mode}} - retry *driver.RetryMode -{{- end -}} - -{{- /* Response field is below. It will be one of the following. */ -}} - -{{- /* Response Type */ -}} -{{- if $.Response.Name}} - result {{$.ResultType}} -{{- end -}} -{{- /* If we have a response type of batch cursor, we use this result instead */ -}} -{{- if or (eq $.Response.Type "batch cursor") (eq $.Response.Type "list collections batch cursor")}} - result driver.CursorResponse -{{- end -}} -} - -{{if $.Response.Name}} -type {{$.Response.Name}} struct { -{{- range $name, $field := $.Response.Field}} - {{$.EscapeDocumentation $field.Documentation}} - {{$.Title $name}} {{$field.DeclarationType}} -{{- end -}} -} - -func build{{$.Response.Name}}(response bsoncore.Document, srvr driver.Server) ({{$.Response.Name}}, error) { - elements, err := response.Elements() - if err != nil { - return {{$.Response.Name}}{}, err - } - {{$.Response.ShortName}} := {{$.Response.Name}}{} - for _, element := range elements { - switch element.Key() { - {{- $.Response.BuildMethod -}} - } - } - return {{$.Response.ShortName}}, nil -} -{{end}} - -// New{{$.Name}} constructs and returns a new {{$.Name}}. -func New{{$.Name}}({{$.ConstructorParameters}}) *{{$.Name}} { - return &{{$.Name}}{ - {{range $field := $.ConstructorFields -}} - {{$field}} - {{end -}} - } -} - -{{if $.Response.Name}} -// Result returns the result of executing this operation. -func ({{$.ShortName}} *{{$.Name}}) Result() {{$.ResultType}} { return {{$.ShortName}}.result } -{{- end}} - -{{- /* Batch Cursor Result */ -}} -{{if eq $.Response.Type "batch cursor" -}} -// Result returns the result of executing this operation. -func ({{$.ShortName}} *{{$.Name}}) Result(opts driver.CursorOptions) (*driver.BatchCursor, error) { -{{- /* - This is all done inline to avoid creating messy output. - We need to handle setting the client session and the cluster clock. If this operation has those - fields, we use the reference to them. If it doesn't have those fields then we set the parameter - to nil. -*/ -}} - return driver.NewBatchCursor( - {{- $.ShortName}}.result, - - {{- /* Client Session Parameter */ -}} - {{- if $builtin := $.Properties.IsEnabled "client session" -}} - {{$.ShortName}}.{{$builtin.ReferenceName}} - {{- else -}} - nil - {{- end -}}, - - {{- /* Cluster Clock Parameter */ -}} - {{- if $builtin := $.Properties.IsEnabled "cluster clock" -}} - {{$.ShortName}}.{{$builtin.ReferenceName}} - {{- else -}} - nil - {{- end -}}, opts) -}{{end}} - -{{- /* List Collections Batch Cursor Result */ -}} -{{if eq $.Response.Type "list collections batch cursor" -}} -// Result returns the result of executing this operation. -func ({{$.ShortName}} *{{$.Name}}) Result(opts driver.CursorOptions) (*driver.ListCollectionsBatchCursor, error) { -{{- /* - This is all done inline to avoid creating messy output. - We need to handle setting the client session and the cluster clock. If this operation has those - fields, we use the reference to them. If it doesn't have those fields then we set the parameter - to nil. -*/ -}} - bc, err := driver.NewBatchCursor( - {{- $.ShortName}}.result, - - {{- /* Client Session Parameter */ -}} - {{- if $builtin := $.Properties.IsEnabled "client session" -}} - {{$.ShortName}}.{{$builtin.ReferenceName}} - {{- else -}} - nil - {{- end -}}, - - {{- /* Cluster Clock Parameter */ -}} - {{- if $builtin := $.Properties.IsEnabled "cluster clock" -}} - {{$.ShortName}}.{{$builtin.ReferenceName}} - {{- else -}} - nil - {{- end -}}, opts) - if err != nil { - return nil, err - } - desc := {{$.ShortName}}.result.Desc - if desc.WireVersion == nil || desc.WireVersion.Max < 3 { - return driver.NewLegacyListCollectionsBatchCursor(bc) - } - return driver.NewListCollectionsBatchCursor(bc) -}{{end}} - -func ({{$.ShortName}} *{{$.Name}}) processResponse(response bsoncore.Document, srvr driver.Server, desc description.Server) error { - var err error - {{if $.Response.Name -}} - {{$.ShortName}}.result, err = build{{$.Response.Name}}(response, srvr) - {{end -}} - {{if or (eq $.Response.Type "batch cursor") (eq $.Response.Type "list collections batch cursor") -}} - {{$.ShortName}}.result, err = driver.NewCursorResponse(response, srvr, desc) - {{end -}} - return err -} - -// Execute runs this operations and returns an error if the operaiton did not execute successfully. -func ({{$.ShortName}} *{{$.Name}}) Execute(ctx context.Context) error { - if {{$.ShortName}}.deployment == nil { - return errors.New("the {{$.Name}} operation must have a Deployment set before Execute can be called") - } - {{if $.Properties.Batches -}} - batches := &driver.Batches{ - Identifier: "{{$.Properties.Batches}}", - Documents: {{$.ShortName}}.{{$.Properties.Batches}}, - {{if index $.Request "ordered" -}} - Ordered: {{$.ShortName}}.ordered, - {{- end}} - }{{end}} -{{with $builtins := $.Properties.BuiltinsMap}} - return driver.Operation{ - CommandFn: {{$.ShortName}}.command, - ProcessResponseFn: {{$.ShortName}}.processResponse, - - {{- if $.Properties.Batches}} - Batches: batches, - {{- end -}} - - {{- if $.Properties.Retryable.Mode}} - RetryMode: {{$.ShortName}}.retry, - {{- end -}} - - {{- if eq $.Properties.Retryable.Type "writes"}} - Type: driver.Write, - {{- end -}} - - {{- if eq $.Properties.Retryable.Type "reads"}} - Type: driver.Read, - {{- end -}} - - {{- range $b := $.Properties.ExecuteBuiltins}} - {{$b.ExecuteName}}: {{$.ShortName}}.{{$b.ReferenceName}}, - {{- end -}} - - {{- if $.Properties.MinimumWriteConcernWireVersion}} - MinimumWriteConcernWireVersion: {{$.Properties.MinimumWriteConcernWireVersion}}, - {{- end -}} - - {{- if $.Properties.MinimumReadConcernWireVersion}} - MinimumReadConcernWireVersion: {{$.Properties.MinimumReadConcernWireVersion}}, - {{- end -}} - - {{- if ne $.Properties.Legacy ""}} - Legacy: {{$.Properties.LegacyOperationKind}}, - {{- end}} - }.Execute(ctx, nil) -{{end}} -} - -func ({{$.ShortName}} *{{$.Name}}) command(dst []byte, desc description.SelectedServer) ([]byte, error) { - {{$.CommandMethod -}} - return dst, nil -} - -{{range $name, $field := $.Request}} -{{$.EscapeDocumentation $field.Documentation}} -func ({{$.ShortName}} *{{$.Name}}) {{$.Title $name}}({{$name}} {{$field.ParameterType}}) *{{$.Name}} { - if {{$.ShortName}} == nil { - {{$.ShortName}} = new({{$.Name}}) - } - - {{$.ShortName}}.{{$name}} = {{if $field.PointerType}}&{{end}}{{$name}} - return {{$.ShortName}} -} -{{end}} - -{{range $builtin := $.Properties.Builtins}} -{{$.EscapeDocumentation $builtin.Documentation}} -func ({{$.ShortName}} *{{$.Name}}) {{$builtin.SetterName}}({{$builtin.ReferenceName}} {{$builtin.Type}}) *{{$.Name}} { - if {{$.ShortName}} == nil { - {{$.ShortName}} = new({{$.Name}}) - } - - {{$.ShortName}}.{{$builtin.ReferenceName}} = {{$builtin.ReferenceName}} - return {{$.ShortName}} -} -{{end}} - -{{if $.Properties.Retryable.Mode}} -// Retry enables retryable mode for this operation. Retries are handled automatically in driver.Operation.Execute based -// on how the operation is set. -func ({{$.ShortName}} *{{$.Name}}) Retry(retry driver.RetryMode) *{{$.Name}} { - if {{$.ShortName}} == nil { - {{$.ShortName}} = new({{$.Name}}) - } - - {{$.ShortName}}.retry = &retry - return {{$.ShortName}} -} -{{end}} - diff --git a/x/mongo/driver/drivergen/templates/response_field.tmpl b/x/mongo/driver/drivergen/templates/response_field.tmpl deleted file mode 100644 index 1bb1873d2f..0000000000 --- a/x/mongo/driver/drivergen/templates/response_field.tmpl +++ /dev/null @@ -1,49 +0,0 @@ -{{define "responseFieldInt64"}} -case "{{$.ResponseName}}": - var ok bool - {{$.ResponseShortName}}.{{$.Field}}, ok = element.Value().AsInt64OK() - if !ok { - err = fmt.Errorf("response field '{{$.ResponseName}}' is type int64, but received BSON type %s", element.Value().Type) - } -{{- end}} - -{{define "responseFieldInt32"}} -case "{{$.ResponseName}}": - var ok bool - {{$.ResponseShortName}}.{{$.Field}}, ok = element.Value().AsInt32OK() - if !ok { - err = fmt.Errorf("response field '{{$.ResponseName}}' is type int32, but received BSON type %s", element.Value().Type) - } -{{- end}} - -{{define "responseFieldBoolean"}} -case "{{$.ResponseName}}": - var ok bool - {{$.ResponseShortName}}.{{$.Field}}, ok = element.Value().BooleanOK() - if !ok { - err = fmt.Errorf("response field '{{$.ResponseName}}' is type bool, but received BSON type %s", element.Value().Type) - } -{{- end}} - -{{define "responseFieldString"}} -case "{{$.ResponseName}}": - var ok bool - {{$.ResponseShortName}}.{{$.Field}}, ok = element.Value().StringValueOK() - if !ok { - err = fmt.Errorf("response field '{{$.ResponseName}}' is type string, but received BSON type %s", element.Value().Type) - } -{{- end}} - -{{define "responseFieldValue"}} -case "{{$.ResponseName}}": - {{$.ResponseShortName}}.{{$.Field}} = element.Value() -{{- end}} - -{{define "responseFieldDocument"}} -case "{{$.ResponseName}}": - var ok bool - {{$.ResponseShortName}}.{{$.Field}}, ok = element.Value().DocumentOK() - if !ok { - err = fmt.Errorf("response field '{{$.ResponseName}}' is type document, but received BSON type %s", element.Value().Type) - } -{{- end}} From 5f97aaa54a59d4e2157bf6c5d0cce5c96e740058 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 16 Nov 2021 15:16:09 -0500 Subject: [PATCH 4/7] Update linters --- .golangci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 07e8d804af..f7cf94e292 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -60,12 +60,6 @@ issues: linters: - revive - errcheck - # Ignore some linters for generated operation code. - # TODO: Re-enable once GODRIVER-2154 is done. - - path: x/mongo/driver/operation/ - linters: - - staticcheck - - ineffassign # Disable unused code linters for the copy/pasted "awsv4" package. - path: x/mongo/driver/auth/internal/awsv4 linters: From 5fa0ba353e2c6cbb8f508bc596e53938895b6bfa Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 16 Nov 2021 15:18:33 -0500 Subject: [PATCH 5/7] Remove references to operationgen --- x/mongo/driver/DESIGN.md | 4 ++-- x/mongo/driver/operation/operation.go | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 x/mongo/driver/operation/operation.go diff --git a/x/mongo/driver/DESIGN.md b/x/mongo/driver/DESIGN.md index 9342cb0731..2fde89f81f 100644 --- a/x/mongo/driver/DESIGN.md +++ b/x/mongo/driver/DESIGN.md @@ -19,5 +19,5 @@ The `Operation` type handles executing a series of commands using a `Deployment` batch split write commands, such as insert. The type itself is heavily documented, so reading the code and comments together should provide an understanding of how the type works. -This type is not meant to be used directly by callers. Instead an wrapping type should be defined -using the IDL and an implementation generated using `operationgen`. +This type is not meant to be used directly by callers. Instead a wrapping type should be defined +using the IDL. diff --git a/x/mongo/driver/operation/operation.go b/x/mongo/driver/operation/operation.go deleted file mode 100644 index 3a13b504b7..0000000000 --- a/x/mongo/driver/operation/operation.go +++ /dev/null @@ -1,15 +0,0 @@ -package operation - -//go:generate operationgen insert.toml operation insert.go -//go:generate operationgen find.toml operation find.go -//go:generate operationgen list_collections.toml operation list_collections.go -//go:generate operationgen createIndexes.toml operation createIndexes.go -//go:generate operationgen drop_collection.toml operation drop_collection.go -//go:generate operationgen distinct.toml operation distinct.go -//go:generate operationgen drop_indexes.toml operation drop_indexes.go -//go:generate operationgen drop_database.toml operation drop_database.go -//go:generate operationgen commit_transaction.toml operation commit_transaction.go -//go:generate operationgen abort_transaction.toml operation abort_transaction.go -//go:generate operationgen count.toml operation count.go -//go:generate operationgen end_sessions.toml operation end_sessions.go -//go:generate operationgen create.toml operation create.go From a11817c2b2003a9634bbd2adcc87845706348207 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 16 Nov 2021 15:35:45 -0500 Subject: [PATCH 6/7] Fix FindAndModify bug --- x/mongo/driver/operation/find_and_modify.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x/mongo/driver/operation/find_and_modify.go b/x/mongo/driver/operation/find_and_modify.go index 247a8dc110..71fa3e241c 100644 --- a/x/mongo/driver/operation/find_and_modify.go +++ b/x/mongo/driver/operation/find_and_modify.go @@ -75,8 +75,10 @@ func buildFindAndModifyResult(response bsoncore.Document, srvr driver.Server) (F case "value": var ok bool famr.Value, ok = element.Value().DocumentOK() - if !ok { - return famr, fmt.Errorf("response field 'value' is type document, but received BSON type %s", element.Value().Type) + + // The 'value' field returned by a FindAndModify can be null in the case that no document was found. + if famr.Value != nil && !ok { + return famr, fmt.Errorf("response field 'value' is type document or null, but received BSON type %s", element.Value().Type) } case "lastErrorObject": valDoc, ok := element.Value().DocumentOK() From c705aaacb0ed7b03166f28abaf47f7af85a955e7 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Wed, 17 Nov 2021 10:35:27 -0500 Subject: [PATCH 7/7] Matt comments --- x/mongo/driver/operation/command.go | 6 ++++++ x/mongo/driver/operation/find_and_modify.go | 2 +- x/mongo/driver/operation/listDatabases.go | 18 +++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/x/mongo/driver/operation/command.go b/x/mongo/driver/operation/command.go index b94511c16e..27d0272976 100644 --- a/x/mongo/driver/operation/command.go +++ b/x/mongo/driver/operation/command.go @@ -1,3 +1,9 @@ +// Copyright (C) MongoDB, Inc. 2021-present. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + package operation import ( diff --git a/x/mongo/driver/operation/find_and_modify.go b/x/mongo/driver/operation/find_and_modify.go index 71fa3e241c..656d56a854 100644 --- a/x/mongo/driver/operation/find_and_modify.go +++ b/x/mongo/driver/operation/find_and_modify.go @@ -77,7 +77,7 @@ func buildFindAndModifyResult(response bsoncore.Document, srvr driver.Server) (F famr.Value, ok = element.Value().DocumentOK() // The 'value' field returned by a FindAndModify can be null in the case that no document was found. - if famr.Value != nil && !ok { + if element.Value().Type != bsontype.Null && !ok { return famr, fmt.Errorf("response field 'value' is type document or null, but received BSON type %s", element.Value().Type) } case "lastErrorObject": diff --git a/x/mongo/driver/operation/listDatabases.go b/x/mongo/driver/operation/listDatabases.go index 6f7d08ef7e..d6b31e32a4 100644 --- a/x/mongo/driver/operation/listDatabases.go +++ b/x/mongo/driver/operation/listDatabases.go @@ -73,14 +73,14 @@ func buildListDatabasesResult(response bsoncore.Document, srvr driver.Server) (L } var tmp bsoncore.Document - marshalErr := bson.Unmarshal(arr, &tmp) - if marshalErr != nil { - return ir, marshalErr + err := bson.Unmarshal(arr, &tmp) + if err != nil { + return ir, err } - records, marshalErr := tmp.Elements() - if marshalErr != nil { - return ir, marshalErr + records, err := tmp.Elements() + if err != nil { + return ir, err } ir.Databases = make([]databaseRecord, len(records)) @@ -90,9 +90,9 @@ func buildListDatabasesResult(response bsoncore.Document, srvr driver.Server) (L return ir, fmt.Errorf("'databases' element is type document, but received BSON type %s", val.Value().Type) } - elems, marshalErr := valueDoc.Elements() - if marshalErr != nil { - return ir, marshalErr + elems, err := valueDoc.Elements() + if err != nil { + return ir, err } for _, elem := range elems {