Skip to content

Commit bde95b7

Browse files
committed
fix: move tests to another directory to prevent mocha discovery and remove abstract cursor generic constraint
1 parent 19ea4c2 commit bde95b7

11 files changed

+40
-46
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ lib/
5656
*.tgz
5757
*.d.ts
5858
# type definition tests
59-
!test/unit/types
59+
!test/types
6060

6161
.vscode
6262
output

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@
115115
"test": "npm run check:lint && npm run check:test"
116116
},
117117
"tsd": {
118-
"directory": "test/unit/types"
118+
"directory": "test/types"
119119
}
120120
}

src/cursor/abstract_cursor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export type InternalAbstractCursorOptions = Omit<AbstractCursorOptions, 'readPre
7474
};
7575

7676
/** @public */
77-
export abstract class AbstractCursor<TSchema extends Document = any> extends EventEmitter {
77+
export abstract class AbstractCursor<TSchema = any> extends EventEmitter {
7878
/** @internal */
7979
[kId]?: Long;
8080
/** @internal */
@@ -303,15 +303,15 @@ export abstract class AbstractCursor<TSchema extends Document = any> extends Eve
303303
if (doc == null) return done();
304304

305305
// NOTE: no need to transform because `next` will do this automatically
306-
let result = iterator(doc as TSchema); // TODO_OPERATIONS_LAYER - We need to work with the transform return type somehow
306+
let result = iterator(doc as TSchema); // TODO_NODE_2648 - We need to work with the transform return type somehow
307307
if (result === false) return done();
308308

309309
// these do need to be transformed since they are copying the rest of the batch
310310
const internalDocs = this[kDocuments].splice(0, this[kDocuments].length);
311311
if (internalDocs) {
312312
for (let i = 0; i < internalDocs.length; ++i) {
313313
result = iterator(
314-
(transform ? transform(internalDocs[i]) : internalDocs[i]) as TSchema // TODO_OPERATIONS_LAYER - We need to work with the transform return type somehow
314+
(transform ? transform(internalDocs[i]) : internalDocs[i]) as TSchema // TODO_NODE_2648 - We need to work with the transform return type somehow
315315
);
316316
if (result === false) return done();
317317
}
@@ -401,7 +401,7 @@ export abstract class AbstractCursor<TSchema extends Document = any> extends Eve
401401
// these do need to be transformed since they are copying the rest of the batch
402402
const internalDocs = (transform
403403
? this[kDocuments].splice(0, this[kDocuments].length).map(transform)
404-
: this[kDocuments].splice(0, this[kDocuments].length)) as TSchema[]; // TODO_OPERATIONS_LAYER - We need to work with the transform return type somehow
404+
: this[kDocuments].splice(0, this[kDocuments].length)) as TSchema[]; // TODO_NODE_2648 - We need to work with the transform return type somehow
405405

406406
if (internalDocs) {
407407
docs.push(...internalDocs);
@@ -442,9 +442,9 @@ export abstract class AbstractCursor<TSchema extends Document = any> extends Eve
442442
*
443443
* @param transform - The mapping transformation method.
444444
*/
445-
map<TResult>(transform: (doc: TSchema) => TResult): this {
445+
map<TResult = any>(transform: (doc: TSchema) => TResult): this {
446446
assertUninitialized(this);
447-
const oldTransform = this[kTransform] as (doc: TSchema) => TSchema; // TODO_OPERATIONS_LAYER - We need to work with the transform return type somehow
447+
const oldTransform = this[kTransform] as (doc: TSchema) => TSchema; // TODO_NODE_2648 - We need to work with the transform return type somehow
448448
if (oldTransform) {
449449
this[kTransform] = doc => {
450450
return transform(oldTransform(doc));

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ export type {
352352
Query,
353353
Projection,
354354
InferIdType,
355-
WithId as ObjectWithId,
356355
ProjectionOperators,
357356
MetaProjectionOperators,
358357
MetaSortOperators

test/unit/types/basic_schema.test-d.ts renamed to test/types/basic_schema.test-d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { expectType } from 'tsd';
22

3-
import { Collection } from '../../.../../../src/collection';
4-
import type { ObjectId } from '../../../src/bson';
5-
import { Db } from '../../../src/db';
6-
import { MongoClient } from '../../../src/mongo_client';
7-
import type { InferIdType } from '../../../src/mongo_types';
3+
import { Collection } from '../../src/collection';
4+
import type { ObjectId } from '../../src/bson';
5+
import { Db } from '../../src/db';
6+
import { MongoClient } from '../../src/mongo_client';
7+
import type { InferIdType } from '../../src/mongo_types';
88

99
const db = new Db(new MongoClient(''), '');
1010

test/types/distinct.test-d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expectType } from 'tsd';
2+
3+
import { Db } from '../../src/db';
4+
import { MongoClient } from '../../src/mongo_client';
5+
import type { Movie } from './example_schemas';
6+
7+
const db = new Db(new MongoClient(''), '');
8+
const collection = db.collection<Movie>('');
9+
10+
// Ensure distinct takes all keys of the schema plus '_id'
11+
let x = (null as unknown) as Parameters<typeof collection.distinct>[0];
12+
expectType<'_id' | keyof Movie>(x);

test/unit/types/example_schemas.ts renamed to test/types/example_schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Double, Int32 } from '../../../src/bson';
1+
import type { Double, Int32 } from '../../src/bson';
22

33
export type MediaType = 'movie' | 'tv' | 'web series';
44

test/unit/types/indexed_schema.test-d.ts renamed to test/types/indexed_schema.test-d.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import { expectDeprecated, expectType, expectNotType, expectError, expectAssignable } from 'tsd';
1+
import { expectType, expectNotType, expectError, expectAssignable } from 'tsd';
22

3-
import { Collection } from '../../.../../../src/collection';
4-
import { ObjectId } from '../../../src/bson';
5-
import { Db } from '../../../src/db';
6-
import { MongoClient } from '../../../src/mongo_client';
7-
import type { InferIdType } from '../../../src/mongo_types';
8-
9-
expectDeprecated(Collection.prototype.insert);
10-
expectDeprecated(Collection.prototype.update);
11-
expectDeprecated(Collection.prototype.remove);
3+
import { Collection } from '../../src/collection';
4+
import { ObjectId } from '../../src/bson';
5+
import { Db } from '../../src/db';
6+
import { MongoClient } from '../../src/mongo_client';
127

138
const db = new Db(new MongoClient(''), '');
149

test/unit/types/mongodb.test-d.ts renamed to test/types/mongodb.test-d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { expectDeprecated, expectType, expectNotType, expectError, expectAssignable } from 'tsd';
22

3-
import { Collection } from '../../.../../../src/collection';
4-
import { AggregationCursor } from '../../../src/cursor/aggregation_cursor';
5-
import { Db } from '../../../src/db';
6-
import { MongoError } from '../../../src/error';
7-
import { MongoClient } from '../../../src/mongo_client';
3+
import { Collection } from '../../src//collection';
4+
import { AggregationCursor } from '../../src//cursor/aggregation_cursor';
5+
import { Db } from '../../src//db';
6+
import { MongoError } from '../../src//error';
7+
import { MongoClient } from '../../src//mongo_client';
88

99
expectDeprecated(Collection.prototype.insert);
1010
expectDeprecated(Collection.prototype.update);

test/unit/types/union_schema.test-d.ts renamed to test/types/union_schema.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { expectType, expectError, expectNotType } from 'tsd';
22

3-
import { Collection } from '../../.../../../src/collection';
4-
import { ObjectId } from '../../../src/bson';
5-
import { Db } from '../../../src/db';
6-
import { MongoClient } from '../../../src/mongo_client';
3+
import { Collection } from '../../src/collection';
4+
import { ObjectId } from '../../src/bson';
5+
import { Db } from '../../src//db';
6+
import { MongoClient } from '../../src//mongo_client';
77

88
type InsertRes<TId = ObjectId> = Promise<{ acknowledged: boolean; insertedId: TId }>;
99

test/unit/types/distinct.test-d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)