Skip to content

Commit

Permalink
feat(mongoose): @tsed/mongoose need mongoose v6 as minimal version
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Apr 2, 2022
1 parent 0668c3d commit 85605e6
Show file tree
Hide file tree
Showing 24 changed files with 215 additions and 298 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@
"devDependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0",
"@tsed/monorepo-utils": "1.20.1",
"@tsed/monorepo-utils": "1.20.2",
"@tsed/ts-doc": "4.0.14",
"@types/axios": "0.14.0",
"@types/chai": "4.2.12",
"@types/chai-as-promised": "7.1.3",
"@types/faker": "5.5.9",
"@types/chai": "4.3.0",
"@types/chai-as-promised": "7.1.5",
"@types/faker": "6.6.9",
"@types/globby": "9.1.0",
"@types/jest": "27.4.1",
"@types/mocha": "8.2.2",
"@types/node": "14.14.34",
"@types/mocha": "9.1.0",
"@types/node": "17.0.23",
"@types/proxyquire": "1.3.28",
"@types/sinon": "10.0.11",
"@types/sinon-chai": "3.2.4",
"@types/superagent": "4.1.10",
"@types/supertest": "2.0.10",
"@types/sinon-chai": "3.2.8",
"@types/superagent": "4.1.15",
"@types/supertest": "2.0.12",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"chai": "4.2.0",
Expand Down Expand Up @@ -174,7 +174,7 @@
]
},
"resolutions": {
"mongoose": "6.1.7"
"mongoose": "6.2.9"
},
"collective": {
"type": "opencollective",
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"@tsed/core": "6.107.5",
"@types/ioredis": "4.17.11",
"@types/ioredis": "4.28.10",
"@types/ioredis-mock": "^5.6.0",
"ioredis": "4.19.4",
"ioredis-mock": "5.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@tsed/di": "6.107.5",
"@tsed/json-mapper": "6.107.5",
"@tsed/schema": "6.107.5",
"@types/fs-extra": "9.0.6"
"@types/fs-extra": "9.0.13"
},
"peerDependencies": {
"@tsed/ajv": "6.107.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/mongoose/src/decorators/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function Model(options: MongooseModelOptions = {}) {
schema,
collectionName,
options.collection,
options.skipInit,
options.overwriteModels,
connections.get(options.connection),
options.discriminatorValue
);
Expand Down
3 changes: 2 additions & 1 deletion packages/orm/mongoose/src/interfaces/MongooseModelOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {MongooseSchemaOptions} from "./MongooseSchemaOptions";
import {CompileModelOptions} from "mongoose";

export interface MongooseModelOptions extends MongooseSchemaOptions {
name?: string;
connection?: string;
collection?: string;
skipInit?: boolean;
overwriteModels?: boolean;
discriminatorValue?: string;
}
11 changes: 1 addition & 10 deletions packages/orm/mongoose/src/services/MongooseConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ registerProvider({
let isDefault = true;

for (const current of settings) {
await mongooseService.connect(
current.id,
current.url,
current.connectionOptions || {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true
},
isDefault
);
await mongooseService.connect(current.id, current.url, current.connectionOptions || {}, isDefault);

isDefault = false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/mongoose/src/utils/createModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("createModel()", () => {
});

it("should call mongoose.model", () => {
expect(mongoose.model).toHaveBeenCalledWith("name", schema, "collection", true);
expect(mongoose.model).toHaveBeenCalledWith("name", schema, "collection", {overwriteModels: true});
});
});

Expand Down
17 changes: 7 additions & 10 deletions packages/orm/mongoose/src/utils/createModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ancestorsOf, nameOf, Store, Type} from "@tsed/core";
import mongoose, {Connection, Model as MongooseModel} from "mongoose";
import mongoose, {CompileModelOptions, Connection, Model as MongooseModel} from "mongoose";
import {MONGOOSE_MODEL, MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA_OPTIONS} from "../constants/constants";
import {MongooseModels} from "../registries/MongooseModels";
import {getSchemaToken} from "./createSchema";
Expand All @@ -20,7 +20,7 @@ export function getModelToken(target: Type<any>, options: any) {
* @param {"mongoose".Schema} schema Schema that will be attached to the model.
* @param name model name
* @param collection (optional, induced from model name)
* @param skipInit whether to skip initialization (defaults to false)
* @param overwriteModels
* @param connection
* @param discriminatorValue
* @returns {Model<T extends Document>}
Expand All @@ -30,7 +30,7 @@ export function createModel<T>(
schema: mongoose.Schema,
name: string = nameOf(target),
collection?: string,
skipInit?: boolean,
overwriteModels?: boolean,
connection?: Connection,
discriminatorValue?: string
) {
Expand All @@ -52,14 +52,11 @@ export function createModel<T>(
}
}

/* istanbul ignore else */
if (connection) {
const model = connection.model(name, schema, collection);
Store.from(target).set(MONGOOSE_MODEL, model);
return model;
}
const opts = overwriteModels ? {overwriteModels} : undefined;
const c = connection || mongoose;

const model = mongoose.model(name, schema, collection, skipInit);
const model = c.model(name, schema, collection, opts);
Store.from(target).set(MONGOOSE_MODEL, model);

return model;
}
2 changes: 1 addition & 1 deletion packages/orm/mongoose/src/utils/createSchema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("createSchema", () => {
}

// WHEN
const result = getSchema(Test2);
const result: any = getSchema(Test2);

// THEN
expect(result.obj.test.required).toBeInstanceOf(Function);
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/mongoose/test/ref.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const baseUser = {

const baseProfile = {
image: faker.image.avatar(),
age: faker.random.number(2)
age: faker.datatype.number(2)
};

describe("Mongoose", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/orm/mongoose/test/subdocument.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe("Mongoose", () => {
afterEach(TestMongooseContext.reset);

it("should create model with sub document", () => {
const documentSchema = getSchema(TestModelDocument);
const subDocumentSchema = getSchema(TestSubDocument);
const documentSchema: any = getSchema(TestModelDocument);
const subDocumentSchema: any = getSchema(TestSubDocument);

expect(documentSchema.obj.sub.type.obj.prop.type).toBe(String);
expect(documentSchema.obj.sub.type).toBe(subDocumentSchema);
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/testing-mongoose/src/TestMongooseContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class TestMongooseContext extends PlatformTest {
await Promise.all(promises);
}

static async getMongooseOptions() {
static async getMongooseOptions(): Promise<any> {
const mongo = TestMongooseContext.getMongo();
try {
!["running", "starting"].includes(mongo.state) && (await mongo.start());
Expand Down
3 changes: 2 additions & 1 deletion packages/platform/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@
"@tsed/logger-file": {
"optional": false
}
}
},
"devDependencies": {}
}
12 changes: 6 additions & 6 deletions packages/platform/platform-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
"@tsed/common": "6.107.5",
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@tsed/platform-views": "6.107.5",
"@tsed/platform-test-utils": "6.107.5",
"@types/body-parser": "1.19.0",
"@types/compression": "1.7.0",
"@tsed/platform-views": "6.107.5",
"@types/body-parser": "1.19.2",
"@types/compression": "1.7.2",
"@types/cookie-parser": "1.4.2",
"@types/express": "^4.17.7",
"@types/express-session": "1.17.0",
"@types/method-override": "0.0.31",
"@types/express-session": "1.17.4",
"@types/method-override": "0.0.32",
"@types/multer": "^1.4.3",
"body-parser": "1.19.0",
"compression": "1.7.4",
Expand All @@ -85,10 +85,10 @@
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@tsed/json-mapper": "6.107.5",
"@tsed/logger": ">=6.1.1",
"@tsed/openspec": "6.107.5",
"@tsed/platform-views": "6.107.5",
"@tsed/schema": "6.107.5",
"@tsed/logger": ">=6.1.1",
"@types/multer": "^1.4.5",
"body-parser": "1.19.0"
},
Expand Down
18 changes: 9 additions & 9 deletions packages/platform/platform-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
"url": "git+https://github.com/tsedio/tsed.git"
},
"devDependencies": {
"@koa/cors": "3.1.0",
"@koa/cors": "3.3.0",
"@tsed/common": "6.107.5",
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@tsed/platform-test-utils": "6.107.5",
"@types/koa": "2.11.3",
"@types/koa-bodyparser": "4.3.0",
"@types/koa": "2.13.4",
"@types/koa-bodyparser": "4.3.7",
"@types/koa-compose": "3.2.5",
"@types/koa-compress": "4.0.0",
"@types/koa-json": "2.0.18",
"@types/koa-compress": "4.0.3",
"@types/koa-json": "2.0.20",
"@types/koa-mount": "4.0.1",
"@types/koa-send": "4.1.2",
"@types/koa-session": "5.10.2",
"@types/koa__router": "8.0.2",
"@types/koa-send": "4.1.3",
"@types/koa-session": "5.10.6",
"@types/koa__router": "8.0.11",
"koa": "2.13.0",
"koa-bodyparser": "4.3.0",
"koa-compress": "5.0.1",
Expand All @@ -88,9 +88,9 @@
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@tsed/json-mapper": "6.107.5",
"@tsed/logger": ">=6.1.1",
"@tsed/openspec": "6.107.5",
"@tsed/schema": "6.107.5",
"@tsed/logger": ">=6.1.1",
"koa": ">=2.13.0",
"koa-bodyparser": ">=4.3.0",
"koa-compress": ">=5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/platform-views/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@tsed/engines": "^1.1.5",
"@tsed/exceptions": "6.107.5",
"@tsed/schema": "6.107.5",
"@types/consolidate": "0.14.0",
"@types/consolidate": "0.14.1",
"@types/ejs": "3.1.0"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/security/oidc-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@tsed/exceptions": "6.107.5",
"@types/lowdb": "1.0.9",
"@types/lowdb": "1.0.11",
"@types/oidc-provider": "^7.1.1",
"@types/uuid": "8.3.0",
"@types/uuid": "8.3.4",
"oidc-provider": "7.10.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {Provider, Account} from "oidc-provider";
export type AuthorizationCode = InstanceType<Provider["AuthorizationCode"]>;
export type AccessToken = InstanceType<Provider["AccessToken"]>;
export type DeviceCode = InstanceType<Provider["DeviceCode"]>;
export type BackchannelAuthenticationRequest = InstanceType<Provider["BackchannelAuthenticationRequest"]>;

export interface OidcAccountsMethods {
findAccount(
id: string,
token: AuthorizationCode | AccessToken | DeviceCode | undefined,
token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined,
ctx: PlatformContext
): Promise<Account | undefined>;
}
4 changes: 2 additions & 2 deletions packages/security/passport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@tsed/common": "6.107.5",
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@types/passport": "1.0.4",
"@types/passport-http": "0.3.8",
"@types/passport": "1.0.7",
"@types/passport-http": "0.3.9",
"@types/passport-local": "1.0.34",
"@types/passport-strategy": "0.2.35",
"passport": "0.4.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/specs/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"tslib": "2.3.1"
},
"devDependencies": {
"@apidevtools/swagger-parser": "10.0.2",
"@apidevtools/swagger-parser": "10.0.3",
"@tsed/core": "6.107.5",
"@tsed/openspec": "6.107.5",
"@types/fs-extra": "9.0.6",
"@types/json-schema": "7.0.7",
"@types/micromatch": "4.0.1",
"@types/fs-extra": "9.0.13",
"@types/json-schema": "7.0.11",
"@types/micromatch": "4.0.2",
"@types/statuses": "2.0.0"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/third-parties/async-hook-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
"devDependencies": {
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5"
}
},
"peerDependencies": {}
}
4 changes: 2 additions & 2 deletions packages/third-parties/stripe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
"devDependencies": {
"@tsed/core": "6.107.5",
"@tsed/di": "6.107.5",
"@tsed/schema": "6.107.5",
"@tsed/exceptions": "6.107.5",
"@tsed/platform-middlewares": "6.107.5",
"@tsed/platform-params": "6.107.5",
"@tsed/schema": "6.107.5",
"stripe": "^8.129.0"
},
"peerDependencies": {
"@tsed/exceptions": "6.107.5",
"@tsed/platform-middlewares": "6.107.5",
"@tsed/platform-params": "6.107.5",
"@tsed/schema": "6.107.5",
"@tsed/exceptions": "6.107.5",
"@types/body-parser": "^1.19.0",
"body-parser": "^1.19.0",
"stripe": "^8.129.0"
Expand Down
4 changes: 2 additions & 2 deletions tools/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"wrk": "1.2.1"
},
"devDependencies": {
"@types/bytes": "3.1.0",
"@types/bytes": "3.1.1",
"@types/fancy-log": "1.3.1"
},
"scripts": {
Expand All @@ -21,4 +21,4 @@
"benchmarks": "yarn build && node ./lib/checkBenchmarks.js"
},
"peerDependencies": {}
}
}
Loading

0 comments on commit 85605e6

Please sign in to comment.