(
driverInfoList: DriverInfo[],
{ appName = '', runtime: { os } }: MakeClientMetadataOptions
)
| 106 | * 4. Truncate `platform`. -- special we do not truncate this field |
| 107 | */ |
| 108 | export async function makeClientMetadata( |
| 109 | driverInfoList: DriverInfo[], |
| 110 | { appName = '', runtime: { os } }: MakeClientMetadataOptions |
| 111 | ): Promise<ClientMetadata> { |
| 112 | const metadataDocument = new LimitedSizeDocument(512); |
| 113 | |
| 114 | // Add app name first, it must be sent |
| 115 | if (appName.length > 0) { |
| 116 | const name = |
| 117 | ByteUtils.utf8ByteLength(appName) <= 128 |
| 118 | ? appName |
| 119 | : ByteUtils.toUTF8(ByteUtils.fromUTF8(appName), 0, 128, false); |
| 120 | metadataDocument.ifItFitsItSits('application', { name }); |
| 121 | } |
| 122 | |
| 123 | const driverInfo = { |
| 124 | name: 'nodejs', |
| 125 | version: NODE_DRIVER_VERSION |
| 126 | }; |
| 127 | |
| 128 | // This is where we handle additional driver info added after client construction. |
| 129 | for (const { name: n = '', version: v = '' } of driverInfoList) { |
| 130 | if (n.length > 0) { |
| 131 | driverInfo.name = `${driverInfo.name}|${n}`; |
| 132 | } |
| 133 | if (v.length > 0) { |
| 134 | driverInfo.version = `${driverInfo.version}|${v}`; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if (!metadataDocument.ifItFitsItSits('driver', driverInfo)) { |
| 139 | throw new MongoInvalidArgumentError( |
| 140 | 'Unable to include driverInfo name and version, metadata cannot exceed 512 bytes' |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | let runtimeInfo = getRuntimeInfo(); |
| 145 | // This is where we handle additional driver info added after client construction. |
| 146 | for (const { platform = '' } of driverInfoList) { |
| 147 | if (platform.length > 0) { |
| 148 | runtimeInfo = `${runtimeInfo}|${platform}`; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (!metadataDocument.ifItFitsItSits('platform', runtimeInfo)) { |
| 153 | throw new MongoInvalidArgumentError( |
| 154 | 'Unable to include driverInfo platform, metadata cannot exceed 512 bytes' |
| 155 | ); |
| 156 | } |
| 157 | |
| 158 | // Note: order matters, os.type is last so it will be removed last if we're at maxSize |
| 159 | const osInfo = new Map() |
| 160 | .set('name', os.platform()) |
| 161 | .set('architecture', os.arch()) |
| 162 | .set('version', os.release()) |
| 163 | .set('type', os.type()); |
| 164 | |
| 165 | if (!metadataDocument.ifItFitsItSits('os', osInfo)) { |
no test coverage detected