Skip to content

Commit 88e3574

Browse files
authored
SWIFT-985 Add client metadata support for wrapping libraries (#608)
1 parent cc43297 commit 88e3574

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

Sources/CLibMongoC/include/CLibMongoC_bson-version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@
3131
*
3232
* BSON minor version component (e.g. 2 if %BSON_VERSION is 1.2.3)
3333
*/
34-
#define BSON_MINOR_VERSION (16)
34+
#define BSON_MINOR_VERSION (17)
3535

3636

3737
/**
3838
* BSON_MICRO_VERSION:
3939
*
4040
* BSON micro version component (e.g. 3 if %BSON_VERSION is 1.2.3)
4141
*/
42-
#define BSON_MICRO_VERSION (0)
42+
#define BSON_MICRO_VERSION (4)
4343

4444

4545
/**
4646
* BSON_PRERELEASE_VERSION:
4747
*
4848
* BSON prerelease version component (e.g. pre if %BSON_VERSION is 1.2.3-pre)
4949
*/
50-
#define BSON_PRERELEASE_VERSION (pre)
50+
#define BSON_PRERELEASE_VERSION ()
5151

5252
/**
5353
* BSON_VERSION:
5454
*
5555
* BSON version.
5656
*/
57-
#define BSON_VERSION (1.16.0-pre)
57+
#define BSON_VERSION (1.17.4)
5858

5959

6060
/**
@@ -63,7 +63,7 @@
6363
* BSON version, encoded as a string, useful for printing and
6464
* concatenation.
6565
*/
66-
#define BSON_VERSION_S "1.16.0-pre"
66+
#define BSON_VERSION_S "1.17.4"
6767

6868

6969
/**

Sources/CLibMongoC/include/CLibMongoC_mongoc-version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,31 @@
3131
*
3232
* MONGOC minor version component (e.g. 2 if %MONGOC_VERSION is 1.2.3)
3333
*/
34-
#define MONGOC_MINOR_VERSION (16)
34+
#define MONGOC_MINOR_VERSION (17)
3535

3636

3737
/**
3838
* MONGOC_MICRO_VERSION:
3939
*
4040
* MONGOC micro version component (e.g. 3 if %MONGOC_VERSION is 1.2.3)
4141
*/
42-
#define MONGOC_MICRO_VERSION (0)
42+
#define MONGOC_MICRO_VERSION (4)
4343

4444

4545
/**
4646
* MONGOC_PRERELEASE_VERSION:
4747
*
4848
* MONGOC prerelease version component (e.g. pre if %MONGOC_VERSION is 1.2.3-pre)
4949
*/
50-
#define MONGOC_PRERELEASE_VERSION (pre)
50+
#define MONGOC_PRERELEASE_VERSION ()
5151

5252

5353
/**
5454
* MONGOC_VERSION:
5555
*
5656
* MONGOC version.
5757
*/
58-
#define MONGOC_VERSION (1.16.0-pre)
58+
#define MONGOC_VERSION (1.17.4)
5959

6060

6161
/**
@@ -64,7 +64,7 @@
6464
* MONGOC version, encoded as a string, useful for printing and
6565
* concatenation.
6666
*/
67-
#define MONGOC_VERSION_S "1.16.0-pre"
67+
#define MONGOC_VERSION_S "1.17.4"
6868

6969

7070
/**

Sources/MongoSwift/MongoSwift.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,34 @@ import CLibMongoC
33
/// MongoSwift only supports MongoDB 3.6+.
44
internal let MIN_SUPPORTED_WIRE_VERSION = 6
55

6+
/// Store optionally provided metadata about a library wrapping the driver.
7+
private var clientMetadataLibraryName: String?
8+
private var clientMetadataLibraryVersion: String?
9+
10+
/// Adds metadata to include the in the handshake performed with the MongoDB server. This is intended for use by
11+
/// libraries wrapping the driver e.g. MongoDBVapor or an ODM. If used, this method should be called exactly once.
12+
/// This method will only have an effect if called before any `MongoClient`s are initialized.
13+
public func addWrappingLibraryMetadata(name: String, version: String) {
14+
clientMetadataLibraryName = name
15+
clientMetadataLibraryVersion = version
16+
}
17+
618
private final class MongocInitializer {
719
internal static let shared = MongocInitializer()
820

921
private init() {
1022
mongoc_init()
11-
mongoc_handshake_data_append("MongoSwift", MongoSwiftVersionString, nil)
23+
var libraryName = "MongoSwift"
24+
if let additionalName = clientMetadataLibraryName {
25+
libraryName += " / \(additionalName)"
26+
}
27+
28+
var libraryVersion = MongoSwiftVersionString
29+
if let additionalVersion = clientMetadataLibraryVersion {
30+
libraryVersion += " / \(additionalVersion)"
31+
}
32+
33+
mongoc_handshake_data_append(libraryName, libraryVersion, nil)
1234
}
1335
}
1436

etc/generated_headers/bson-version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@
3131
*
3232
* BSON minor version component (e.g. 2 if %BSON_VERSION is 1.2.3)
3333
*/
34-
#define BSON_MINOR_VERSION (16)
34+
#define BSON_MINOR_VERSION (17)
3535

3636

3737
/**
3838
* BSON_MICRO_VERSION:
3939
*
4040
* BSON micro version component (e.g. 3 if %BSON_VERSION is 1.2.3)
4141
*/
42-
#define BSON_MICRO_VERSION (0)
42+
#define BSON_MICRO_VERSION (4)
4343

4444

4545
/**
4646
* BSON_PRERELEASE_VERSION:
4747
*
4848
* BSON prerelease version component (e.g. pre if %BSON_VERSION is 1.2.3-pre)
4949
*/
50-
#define BSON_PRERELEASE_VERSION (pre)
50+
#define BSON_PRERELEASE_VERSION ()
5151

5252
/**
5353
* BSON_VERSION:
5454
*
5555
* BSON version.
5656
*/
57-
#define BSON_VERSION (1.16.0-pre)
57+
#define BSON_VERSION (1.17.4)
5858

5959

6060
/**
@@ -63,7 +63,7 @@
6363
* BSON version, encoded as a string, useful for printing and
6464
* concatenation.
6565
*/
66-
#define BSON_VERSION_S "1.16.0-pre"
66+
#define BSON_VERSION_S "1.17.4"
6767

6868

6969
/**

etc/generated_headers/mongoc-version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,31 @@
3131
*
3232
* MONGOC minor version component (e.g. 2 if %MONGOC_VERSION is 1.2.3)
3333
*/
34-
#define MONGOC_MINOR_VERSION (16)
34+
#define MONGOC_MINOR_VERSION (17)
3535

3636

3737
/**
3838
* MONGOC_MICRO_VERSION:
3939
*
4040
* MONGOC micro version component (e.g. 3 if %MONGOC_VERSION is 1.2.3)
4141
*/
42-
#define MONGOC_MICRO_VERSION (0)
42+
#define MONGOC_MICRO_VERSION (4)
4343

4444

4545
/**
4646
* MONGOC_PRERELEASE_VERSION:
4747
*
4848
* MONGOC prerelease version component (e.g. pre if %MONGOC_VERSION is 1.2.3-pre)
4949
*/
50-
#define MONGOC_PRERELEASE_VERSION (pre)
50+
#define MONGOC_PRERELEASE_VERSION ()
5151

5252

5353
/**
5454
* MONGOC_VERSION:
5555
*
5656
* MONGOC version.
5757
*/
58-
#define MONGOC_VERSION (1.16.0-pre)
58+
#define MONGOC_VERSION (1.17.4)
5959

6060

6161
/**
@@ -64,7 +64,7 @@
6464
* MONGOC version, encoded as a string, useful for printing and
6565
* concatenation.
6666
*/
67-
#define MONGOC_VERSION_S "1.16.0-pre"
67+
#define MONGOC_VERSION_S "1.17.4"
6868

6969

7070
/**

0 commit comments

Comments
 (0)