File size: 5,148 Bytes
ca30ad9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | diff --git a/test/types/lean.test.ts b/test/types/lean.test.ts
index 745999d3a..05f34d96f 100644
--- a/test/types/lean.test.ts
+++ b/test/types/lean.test.ts
@@ -1,4 +1,4 @@
-import { Schema, model, Types, InferSchemaType, FlattenMaps } from 'mongoose';
+import { Schema, model, Types, InferSchemaType, FlattenMaps, Require_id } from 'mongoose';
import { expectAssignable, expectError, expectType } from 'tsd';
function gh10345() {
@@ -206,3 +206,107 @@ async function gh13382() {
const res = await Test.updateOne({}, { name: 'bar' }).lean();
expectAssignable<{ matchedCount: number, modifiedCount: number }>(res);
}
+
+async function gh13702_findById_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findById('id', undefined, { lean: true });
+ const b = await UserModel.findById('id').lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+
+ const a2 = await UserModel.findById('id', null, { lean: true });
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a2);
+}
+
+async function gh13702_findById_no_lean_preserves_hydrated() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findById('id');
+ if (a) {
+
+ expectAssignable<Function>(a.save);
+ }
+}
+
+async function gh13702_findOne_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOne({}, undefined, { lean: true });
+ const b = await UserModel.findOne({}).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_find_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.find({}, undefined, { lean: true });
+ const b = await UserModel.find({}).lean();
+ expectType<typeof b>(a);
+ expectType<Array<FlattenMaps<User> & { _id: Types.ObjectId }>>(a);
+}
+
+async function gh13702_findOneAndDelete_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOneAndDelete({}, { lean: true });
+ const b = await UserModel.findOneAndDelete({}).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findOneAndUpdate_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOneAndUpdate({}, { name: 'x' }, { lean: true });
+ const b = await UserModel.findOneAndUpdate({}, { name: 'x' }).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findOneAndReplace_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOneAndReplace({}, { name: 'x' }, { lean: true });
+ const b = await UserModel.findOneAndReplace({}, { name: 'x' }).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findByIdAndDelete_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findByIdAndDelete('id', { lean: true });
+ const b = await UserModel.findByIdAndDelete('id').lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findByIdAndRemove_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findByIdAndRemove('id', { lean: true });
+ const b = await UserModel.findByIdAndRemove('id').lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findByIdAndUpdate_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findByIdAndUpdate('id', { name: 'x' }, { lean: true });
+ const b = await UserModel.findByIdAndUpdate('id', { name: 'x' }).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
diff --git a/test_commands.json b/test_commands.json
new file mode 100644
index 000000000..8fcadc25d
--- /dev/null
+++ b/test_commands.json
@@ -0,0 +1,3 @@
+{
+ "test_commands": ["./node_modules/.bin/tsd"]
+}
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+set -uo pipefail
+cd /testbed
+rc=0
+./node_modules/.bin/tsd
+rc=$(( rc | $? ))
+exit $rc
|