Skip to content

Commit 3e6e3ad

Browse files
committed
fix: flowtype definitions for [email protected]
1 parent 92644cc commit 3e6e3ad

File tree

8 files changed

+1068
-469
lines changed

8 files changed

+1068
-469
lines changed

.flowconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
.*/coverage/.*
33
.*/resources/.*
44
<PROJECT_ROOT>/lib/.*
5+
<PROJECT_ROOT>/es/.*
6+
<PROJECT_ROOT>/node8/.*
57
<PROJECT_ROOT>/dist/.*
68
.*/node_modules/ajv.*
79
.*/node_modules/acorn.*

flow-typed/npm/mongoose_v4.x.x.js

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
1-
import mongoose from "mongoose";
1+
// flow-typed signature: ff3cec7c93541c92294f76bebb0d2ee4
2+
// flow-typed version: 640b352228/mongoose_v4.x.x/flow_>=v0.50.x
3+
4+
/*** FIX broken globals import 'bson' (((( ***/
5+
// import 'bson';
6+
declare class bson$ObjectId {
7+
constructor(id?: string | number | bson$ObjectId): this;
8+
generationTime: number;
9+
static createFromHexString(hexString: string): bson$ObjectId;
10+
static createFromTime(time: number): bson$ObjectId;
11+
static isValid(id?: string | number | bson$ObjectId | null | void): boolean;
12+
equals(otherID: bson$ObjectId): boolean;
13+
generate(time?: number): string;
14+
getTimestamp(): Date;
15+
toHexString(): string;
16+
toString(): string;
17+
inspect(): string;
18+
toJSON(): string;
19+
}
20+
declare class bson$Decimal128 {
21+
constructor(bytes: Buffer): this;
22+
static fromString(string: string): bson$Decimal128;
23+
toString(): string;
24+
toJSON(): { $numberDecimal: string };
25+
}
26+
/*** end FIX broken globals import 'bson' (((( ***/
27+
28+
type MongoId = bson$ObjectId | string | number;
229

3-
type MongoId = BSONObjectId | string | number;
30+
type Mongoose$Types = {|
31+
ObjectId: Class<bson$ObjectId>,
32+
Mixed: Object,
33+
Embedded: Object,
34+
Document: Object,
35+
DocumentArray: Object,
36+
Subdocument: Object,
37+
Array: Object,
38+
Buffer: Object,
39+
Decimal128: Class<bson$Decimal128>
40+
|};
441

542
type SchemaFields = {
643
[fieldName: string]: any
@@ -34,13 +71,14 @@ type SchemaOpts<Doc> = {
3471
typeKey?: string,
3572
useNestedStrict?: boolean,
3673
validateBeforeSave?: boolean,
37-
versionKey?: string,
74+
versionKey?: string | false,
3875
timestamps?:
3976
| boolean
4077
| {
4178
createdAt?: string,
4279
updatedAt?: string
43-
}
80+
},
81+
discriminatorKey?: string
4482
};
4583

4684
type IndexFields = {
@@ -57,32 +95,6 @@ type IndexOpts = {|
5795
weights?: Object
5896
|};
5997

60-
declare class BSONObjectId {
61-
constructor(id?: string | number | BSONObjectId): BSONObjectId;
62-
toHexString(): string;
63-
toString(): string;
64-
toJSON(): string;
65-
inspect(): string;
66-
equals(otherId: string | number | BSONObjectId): boolean;
67-
getTimestamp(): Date;
68-
69-
static createFromTime(time: number): BSONObjectId;
70-
static createFromHexString(str: string): BSONObjectId;
71-
static isValid(id: string | number | BSONObjectId): boolean;
72-
}
73-
74-
type Mongoose$Types = {|
75-
ObjectId: Class<BSONObjectId>,
76-
Mixed: Object,
77-
Embedded: Object,
78-
Document: Object,
79-
DocumentArray: Object,
80-
Subdocument: Object,
81-
Array: Object,
82-
Buffer: Object,
83-
Decimal128: Object
84-
|};
85-
8698
type Mongoose$SchemaMethods = {
8799
[name: string]: Function
88100
};
@@ -170,7 +182,8 @@ type Mongoose$SchemaField<Schema> = {
170182
description: ?string
171183
},
172184
enumValues?: ?(string[]),
173-
schema?: Schema
185+
schema?: Schema,
186+
_index?: ?{ [optionName: string]: mixed }
174187
};
175188

176189
declare class Mongoose$SchemaVirtualField {
@@ -220,7 +233,7 @@ declare class Mongoose$Document {
220233
data: Object,
221234
options?: Object
222235
): Mongoose$Query<?this, this>;
223-
static count(criteria: Object): Promise<number>;
236+
static count(criteria?: Object): Promise<number>;
224237
static remove(criteria: Object): Promise<mixed>;
225238
static update(
226239
criteria: Object,
@@ -253,10 +266,12 @@ declare class Mongoose$Document {
253266
static modelName: string;
254267
static schema: Mongoose$Schema<this>;
255268
static on(type: string, cb: Function): void;
269+
static discriminator(name: string, schema: Mongoose$Schema<any>): Class<this>;
256270

271+
collection: Mongoose$Collection;
257272
constructor(data?: $Shape<this>): this;
258273
id: string | number;
259-
_id: MongoId;
274+
_id: bson$ObjectId | string | number;
260275
__v?: number;
261276
save(): Promise<this>;
262277
update(update: Object, options?: Object): Promise<UpdateResult>;
@@ -346,7 +361,7 @@ declare class Mongoose$Query<Result, Doc> extends Promise<Result> {
346361
batchSize(n: number): Mongoose$Query<Result, Doc>;
347362
collation(value: Object): Mongoose$Query<Result, Doc>;
348363
comment(val: string): Mongoose$Query<Result, Doc>;
349-
cursor(opts: Object): Mongoose$QueryCursor<Doc>;
364+
cursor(opts?: Object): Mongoose$QueryCursor<Doc>;
350365
deleteMany(criteria?: Object): Mongoose$Query<any, Doc>;
351366
deleteOne(criteria?: Object): Mongoose$Query<any, Doc>;
352367
distinct(field: string, criteria?: Object): Mongoose$Query<Result, Doc>;
@@ -407,7 +422,7 @@ declare class Mongoose$Query<Result, Doc> extends Promise<Result> {
407422

408423
declare class Mongoose$QueryCursor<Doc> {
409424
on(type: "data" | "end" | string, cb: Function): void;
410-
next(cb: (err: Error, doc: Doc) => void): void;
425+
next(cb?: (err: Error, doc: Doc) => void): Promise<?Doc>;
411426
}
412427

413428
declare class Mongoose$QueryStream {
@@ -483,14 +498,15 @@ declare class Mongoose$Connection {
483498
}
484499

485500
declare module "mongoose" {
486-
declare export type MongooseConnection = Mongoose$Connection;
487-
declare export type MongoId = MongoId;
488-
declare export type BSONObjectId = BSONObjectId;
489-
declare export type MongooseQuery<Result, Doc> = Mongoose$Query<Result, Doc>;
490-
declare export type MongooseDocument = Mongoose$Document;
491-
declare export type MongooseModel = typeof Mongoose$Document;
492-
declare export type MongooseSchema<Doc> = Mongoose$Schema<Doc>;
493-
declare export type MongooseSchemaField<Schema> = Mongoose$SchemaField<
501+
declare type MongooseConnection = Mongoose$Connection;
502+
declare type MongoId = MongoId;
503+
declare type BSONObjectId = bson$ObjectId;
504+
declare type ObjectId = bson$ObjectId;
505+
declare type MongooseQuery<Result, Doc> = Mongoose$Query<Result, Doc>;
506+
declare type MongooseDocument = Mongoose$Document;
507+
declare type MongooseModel = typeof Mongoose$Document;
508+
declare type MongooseSchema<Doc> = Mongoose$Schema<Doc>;
509+
declare type MongooseSchemaField<Schema> = Mongoose$SchemaField<
494510
Schema
495511
>;
496512

@@ -499,9 +515,9 @@ declare module "mongoose" {
499515
Types: Mongoose$Types,
500516
Promise: any,
501517
model: $PropertyType<Mongoose$Connection, "model">,
502-
createConnection(uri?: string): Mongoose$Connection,
518+
createConnection(uri?: string, options?: Object): Mongoose$Connection,
503519
set: (key: string, value: string | Function | boolean) => void,
504-
connect: Function,
520+
connect: (uri: string, options?: Object) => void,
505521
connection: Mongoose$Connection,
506522
connections: Mongoose$Connection[],
507523
Query: typeof Mongoose$Query,

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,30 @@
4040
"babel-cli": "^6.26.0",
4141
"babel-core": "^6.26.0",
4242
"babel-eslint": "^8.2.2",
43-
"babel-jest": "^22.4.0",
43+
"babel-jest": "^22.4.3",
4444
"babel-plugin-transform-flow-strip-types": "^6.22.0",
4545
"babel-plugin-transform-object-rest-spread": "^6.13.0",
4646
"babel-plugin-transform-runtime": "^6.23.0",
4747
"babel-preset-env": "^1.6.1",
4848
"cz-conventional-changelog": "^2.1.0",
49-
"eslint": "^4.18.0",
49+
"eslint": "^4.19.1",
5050
"eslint-config-airbnb-base": "^12.1.0",
5151
"eslint-config-prettier": "^2.9.0",
52-
"eslint-plugin-flowtype": "^2.45.0",
53-
"eslint-plugin-import": "^2.8.0",
52+
"eslint-plugin-flowtype": "^2.46.1",
53+
"eslint-plugin-import": "^2.10.0",
5454
"eslint-plugin-prettier": "^2.6.0",
55-
"flow-bin": "^0.65.0",
56-
"graphql": "0.13.1",
57-
"graphql-compose": "^3.0.5",
55+
"flow-bin": "^0.69.0",
56+
"graphql": "0.13.2",
57+
"graphql-compose": "^3.1.1",
5858
"graphql-compose-connection": ">=3.0.0",
5959
"graphql-compose-pagination": ">=3.0.0",
60-
"jest": "^22.4.0",
61-
"mongodb-memory-server": "^1.7.0",
62-
"mongoose": "^5.0.6",
63-
"prettier": "^1.10.2",
64-
"request": "^2.83.0",
60+
"jest": "^22.4.3",
61+
"mongodb-memory-server": "^1.7.3",
62+
"mongoose": "^5.0.12",
63+
"prettier": "^1.11.1",
64+
"request": "^2.85.0",
6565
"rimraf": "^2.6.2",
66-
"semantic-release": "^12.4.1"
66+
"semantic-release": "^15.1.4"
6767
},
6868
"config": {
6969
"commitizen": {

src/__mocks__/mongooseCommon.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mongoose.Promise = Promise;
99
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
1010

1111
const originalConnect = mongoose.connect;
12-
mongoose.connect = async () => {
12+
mongoose.connect = (async () => {
1313
const mongoServer = new MongodbMemoryServer();
1414

1515
const mongoUri = await mongoServer.getConnectionString(true);
@@ -33,6 +33,6 @@ mongoose.connect = async () => {
3333
// console.log('MongoDB disconnected!');
3434
mongoServer.stop();
3535
});
36-
};
36+
}: any);
3737

3838
export { mongoose, Schema };

src/__tests__/github-issues-test.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
11
/* @flow */
22

33
import mongoose from 'mongoose';
4-
import MongodbMemoryServer from 'mongodb-memory-server';
54
import { schemaComposer, graphql } from 'graphql-compose';
65
import { composeWithMongoose } from '../index';
76
import { UserModel } from '../__mocks__/userModel';
87

98
// May require additional time for downloading MongoDB binaries
109
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
1110

12-
let mongoServer;
13-
14-
// const opts = { useMongoClient: true }; // Mongoose 4
15-
const opts = {}; // Mongoose 5
16-
17-
beforeAll(async () => {
18-
mongoServer = new MongodbMemoryServer();
19-
const mongoUri = await mongoServer.getConnectionString();
20-
mongoose.connect(mongoUri, opts, err => {
21-
if (err) console.error(err);
22-
});
23-
});
24-
25-
afterAll(() => {
26-
mongoose.disconnect();
27-
mongoServer.stop();
28-
});
11+
beforeAll(() => UserModel.base.connect());
12+
afterAll(() => UserModel.base.disconnect());
2913

3014
const UserTC = composeWithMongoose(UserModel);
3115
schemaComposer.rootQuery().addFields({

src/fieldsConverter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ export function convertModelToGraphQL(
118118
const schemaComposer = sc || globalSchemaComposer;
119119

120120
// if model already has generated TypeComposer early, then return it
121-
if (model.schema && model.schema._gqcTypeComposer) {
122-
return (model.schema._gqcTypeComposer: any);
121+
const modelSchema: any = model.schema;
122+
if (modelSchema && modelSchema._gqcTypeComposer) {
123+
return modelSchema._gqcTypeComposer;
123124
}
124125

125126
if (!typeName) {
@@ -128,8 +129,7 @@ export function convertModelToGraphQL(
128129

129130
const typeComposer = schemaComposer.getOrCreateTC(typeName);
130131

131-
// $FlowFixMe
132-
model.schema._gqcTypeComposer = typeComposer; // eslint-disable-line no-param-reassign
132+
modelSchema._gqcTypeComposer = typeComposer; // eslint-disable-line no-param-reassign
133133

134134
const mongooseFields = getFieldsFromModel(model);
135135
const graphqlFields = {};

src/utils/getIndexesFromModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { MongooseModel } from 'mongoose';
44

55
export type getIndexesFromModelOpts = {
66
extractCompound?: boolean, // true by default
7-
skipSpecificIndeces?: boolean, // eg text, 2d, 2dsphere (true by default)
7+
skipSpecificIndexes?: boolean, // eg text, 2d, 2dsphere (true by default)
88
};
99

1010
export type IndexT = { [fieldName: string]: any };

0 commit comments

Comments
 (0)