@internal
(document: NonNullable<TSchema>)
| 1070 | |
| 1071 | /** @internal */ |
| 1072 | private async transformDocument(document: NonNullable<TSchema>): Promise<NonNullable<TSchema>> { |
| 1073 | if (this.transform == null) return document; |
| 1074 | |
| 1075 | try { |
| 1076 | const transformedDocument = this.transform(document); |
| 1077 | // eslint-disable-next-line no-restricted-syntax |
| 1078 | if (transformedDocument === null) { |
| 1079 | const TRANSFORM_TO_NULL_ERROR = |
| 1080 | 'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.'; |
| 1081 | throw new MongoAPIError(TRANSFORM_TO_NULL_ERROR); |
| 1082 | } |
| 1083 | return transformedDocument; |
| 1084 | } catch (transformError) { |
| 1085 | try { |
| 1086 | await this.close(); |
| 1087 | } catch (closeError) { |
| 1088 | squashError(closeError); |
| 1089 | } |
| 1090 | throw transformError; |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | /** @internal */ |
| 1095 | protected throwIfInitialized() { |
nothing calls this directly
no test coverage detected