Skip to content

Commit

Permalink
fix: fix package dependencies and prepare esm migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Feb 17, 2022
1 parent 9dc410a commit babd289
Show file tree
Hide file tree
Showing 60 changed files with 189 additions and 428 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
docs
docs-references
**/lib
**/dist
**/coverage
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged --relative
npx lint-staged $1
13 changes: 6 additions & 7 deletions docs/tutorials/snippets/mongoose/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint
import {Inject, Injectable} from "@tsed/di";
import {Model, MongooseModel, MongoosePlugin} from "@tsed/mongoose";
import * as findOrCreate from "mongoose-findorcreate";
Expand All @@ -13,12 +14,10 @@ class UserModel {
@Injectable()
class UserService {
constructor(@Inject(UserModel) userModel: MongooseModel<UserModel>) {
userModel
.findOrCreate({
// ...
})
.then((findOrCreateResult) => {
// ...
});
UserModel.findOrCreate({
// ...
}).then((findOrCreateResult) => {
// ...
});
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"lerna": "4.0.0",
"microbundle": "0.13.0",
"source-map-support": "0.5.19",
"uuid": "8.3.2"
"uuid": "8.3.2",
"rxjs": "^6.5.2"
},
"devDependencies": {
"@commitlint/cli": "^16.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/decorators/deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Type} from "../domain/Type";

import {deprecate} from "util";
/**
* The `@Deprecated()` decorators wraps the given method in such a way that it is marked as deprecated.
*
Expand Down Expand Up @@ -35,7 +35,7 @@ export function Deprecated(message: string): Function {
return (target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<any>) => {
const originalMethod = descriptor.value;

descriptor.value = require("util").deprecate(originalMethod, message);
descriptor.value = deprecate(originalMethod, message);

return descriptor;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/apollo/src/services/ApolloService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ApolloService {
this.logger.info(`Create server with Apollo for: ${id}`);
this.logger.debug(`options: ${JSON.stringify({path})}`);

const server = this.createInstance(
const server = await this.createInstance(
{
...config,
plugins: this.getPlugins(settings)
Expand Down Expand Up @@ -112,15 +112,15 @@ export class ApolloService {
return this.servers.has(id);
}

protected createInstance(options: Config, server?: ApolloCustomServerCB): ApolloServer | undefined {
protected async createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined> {
// istanbul ignore next
if (server) {
return server(options);
}

// istanbul ignore next
try {
const Server = require(`apollo-server-${this.platformName || "express"}`).ApolloServer;
const {ApolloServer: Server} = await import(`apollo-server-${this.platformName || "express"}`);

return new Server(options);
} catch (er) {
Expand Down
8 changes: 4 additions & 4 deletions packages/orm/mikro-orm/test/helpers/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {PlatformApplication} from "@tsed/common";
import {resolve} from "path";
import "@tsed/platform-express";

const cookieParser = require("cookie-parser"),
bodyParser = require("body-parser"),
compress = require("compression"),
methodOverride = require("method-override");
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import compress from "compression";
import methodOverride from "method-override";

const rootDir = resolve(__dirname);

Expand Down
9 changes: 4 additions & 5 deletions packages/orm/mongoose/test/helpers/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import {Configuration, Inject, PlatformApplication} from "@tsed/common";
import "@tsed/mongoose";
import "@tsed/platform-express";
import Path from "path";

const cookieParser = require("cookie-parser"),
bodyParser = require("body-parser"),
compress = require("compression"),
methodOverride = require("method-override");
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import compress from "compression";
import methodOverride from "method-override";

const rootDir = Path.resolve(__dirname);

Expand Down
8 changes: 4 additions & 4 deletions packages/orm/objection/test/helpers/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Path from "path";
import "@tsed/platform-express";
import "@tsed/objection";

const cookieParser = require("cookie-parser"),
bodyParser = require("body-parser"),
compress = require("compression"),
methodOverride = require("method-override");
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import compress from "compression";
import methodOverride from "method-override";

const rootDir = Path.resolve(__dirname);

Expand Down
9 changes: 4 additions & 5 deletions packages/orm/typeorm/test/helpers/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import Path from "path";
import "@tsed/platform-express";
import "@tsed/typeorm";
import "./connections/ConnectionProvider";

const cookieParser = require("cookie-parser"),
bodyParser = require("body-parser"),
compress = require("compression"),
methodOverride = require("method-override");
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import compress from "compression";
import methodOverride from "method-override";

const rootDir = Path.resolve(__dirname);

Expand Down
18 changes: 4 additions & 14 deletions packages/platform/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,11 @@
"@tsed/platform-views": "6.102.3",
"@tsed/schema": "6.102.3",
"@types/json-schema": "7.0.7",
"@types/on-finished": "2.3.1",
"on-finished": "2.3.0",
"tslib": "2.2.0",
"uuid": "8.3.2"
},
"devDependencies": {
"rxjs": "^6.5.2"
},
"peerDependencies": {
"@tsed/components-scan": ">=6.102.1",
"@tsed/core": ">=6.102.1",
"@tsed/di": ">=6.102.1",
"@tsed/exceptions": ">=6.102.1",
"@tsed/json-mapper": ">=6.102.1",
"@tsed/logger": ">=6.0.2",
"@tsed/logger-file": ">=6.0.0",
"@tsed/schema": ">=6.102.1"
}
}
"devDependencies": {},
"peerDependencies": {}
}
Original file line number Diff line number Diff line change
@@ -1,144 +1,13 @@
import {Request} from "express";
import {FileFilterCallback} from "multer";
import {Readable} from "stream";
import type {Express} from "express";
import type multer from "multer";

declare global {
namespace TsED {
export interface MulterFile {
/** Name of the form field associated with this file. */
fieldname: string;
/** Name of the file on the uploader's computer. */
originalname: string;
/** Value of the `Content-Type` header for this file. */
mimetype: string;
/** Size of the file in bytes. */
size: number;
/**
* A readable stream of this file. Only available to the `_handleFile`
* callback for custom `StorageEngine`s.
*/
stream: Readable;
/** `DiskStorage` only: Directory to which this file has been uploaded. */
destination: string;
/** `DiskStorage` only: Name of this file within `destination`. */
filename: string;
/** `DiskStorage` only: Full path to the uploaded file. */
path: string;
/** `MemoryStorage` only: A Buffer containing the entire file. */
buffer: Buffer;
}

export interface MulterStorageEngine {}

export interface MulterOptions {
/**
* A `StorageEngine` responsible for processing files uploaded via Multer.
* Takes precedence over `dest`.
*/
storage?: MulterStorageEngine;
/**
* The destination directory for uploaded files. If `storage` is not set
* and `dest` is, Multer will create a `DiskStorage` instance configured
* to store files at `dest` with random filenames.
*
* Ignored if `storage` is set.
*/
dest?: string;
/**
* An object specifying various limits on incoming data. This object is
* passed to Busboy directly, and the details of properties can be found
* at https://github.com/mscdex/busboy#busboy-methods.
*/
limits?: {
/** Maximum size of each form field name in bytes. (Default: 100) */
fieldNameSize?: number;
/** Maximum size of each form field value in bytes. (Default: 1048576) */
fieldSize?: number;
/** Maximum number of non-file form fields. (Default: Infinity) */
fields?: number;
/** Maximum size of each file in bytes. (Default: Infinity) */
fileSize?: number;
/** Maximum number of file fields. (Default: Infinity) */
files?: number;
/** Maximum number of parts (non-file fields + files). (Default: Infinity) */
parts?: number;
/** Maximum number of headers. (Default: 2000) */
headerPairs?: number;
};
/** Preserve the full path of the original filename rather than the basename. (Default: false) */
preservePath?: boolean;
/**
* Optional function to control which files are uploaded. This is called
* for every file that is processed.
*
* @param req The Express `Request` object.
* @param file Object containing information about the processed file.
* @param callback a function to control which files should be uploaded and which should be skipped.
*/
fileFilter?(req: Request, file: MulterFile, callback: FileFilterCallback): void;
}

export interface MulterField {
name: string;
maxCount?: number;
}

export type MulterHandler = (req: any, res: any) => Promise<any>;

export interface Multer {
/**
* Returns middleware that processes a single file associated with the
* given form field.
*
* The `Request` object will be populated with a `file` object containing
* information about the processed file.
*
* @param fieldName Name of the multipart form field to process.
*/
single(fieldName: string): MulterHandler;

/**
* Returns middleware that processes multiple files sharing the same field
* name.
*
* The `Request` object will be populated with a `files` array containing
* an information object for each processed file.
*
* @param fieldName Shared name of the multipart form fields to process.
* @param maxCount Optional. Maximum number of files to process. (default: Infinity)
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`
*/
array(fieldName: string, maxCount?: number): MulterHandler;

/**
* Returns middleware that processes multiple files associated with the
* given form fields.
*
* The `Request` object will be populated with a `files` object which
* maps each field name to an array of the associated file information
* objects.
*
* @param fields Array of `Field` objects describing multipart form fields to process.
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName` for any field.
*/
fields(fields: MulterField[]): MulterHandler;

/**
* Returns middleware that processes all files contained in the multipart
* request.
*
* The `Request` object will be populated with a `files` array containing
* an information object for each processed file.
*/
any(): MulterHandler;

/**
* Returns middleware that accepts only non-file multipart form fields.
*
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if any file is encountered.
*/
none(): MulterHandler;
}
export type MulterFile = Express.Multer.File;
export type MulterStorageEngine = multer.StorageEngine;
export type MulterOptions = multer.Options;
export type MulterField = multer.Field;
export type Multer = multer.Multer;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PlatformMulterMiddleware implements MiddlewareMethods {
delete settings.dest;
}

const middleware = this.app.multer(settings).fields(this.getFields({fields}));
const middleware: any = this.app.multer(settings).fields(this.getFields({fields}));

return await middleware(ctx.getRequest(), ctx.getResponse());
} catch (er) {
Expand Down
7 changes: 3 additions & 4 deletions packages/platform/common/src/services/PlatformResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {ServerResponse} from "http";
import {IncomingEvent} from "../interfaces/IncomingEvent";
import type {PlatformRequest} from "./PlatformRequest";
import type {PlatformContext} from "../domain/PlatformContext";

const onFinished = require("on-finished");
import onFinished from "on-finished";

declare global {
namespace TsED {
Expand Down Expand Up @@ -68,7 +67,7 @@ export class PlatformResponse<T extends Record<string, any> = any> {
return this.getRes();
}

static onFinished(res: any, cb: Function) {
static onFinished(res: any, cb: (er: Error | null, message: string) => void) {
onFinished(res, cb);
}

Expand Down Expand Up @@ -304,7 +303,7 @@ export class PlatformResponse<T extends Record<string, any> = any> {
* Add a listener to handler the end of the request/response.
* @param cb
*/
onEnd(cb: Function): this {
onEnd(cb: (er: Error | null, message: string) => void): this {
PlatformResponse.onFinished(this.getRes(), cb);

return this;
Expand Down
7 changes: 5 additions & 2 deletions packages/platform/common/src/services/PlatformRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {PlatformMulter, PlatformMulterSettings, PlatformStaticsOptions} from "..
import {PlatformRouteOptions, PlatformRouteWithoutHandlers} from "../interfaces";
import {createFakeRawDriver} from "./FakeRawDriver";
import {PlatformHandler} from "./PlatformHandler";

import type multer from "multer";
/**
* @ignore
*/
Expand Down Expand Up @@ -32,8 +32,11 @@ export class PlatformRouter<Router = TsED.Router> {
@Inject()
injector: InjectorService;

#multer: typeof multer;

constructor(protected platformHandler: PlatformHandler) {
this.rawRouter = this.raw = PlatformRouter.createRawRouter();
import("multer").then(({default: multer}) => (this.#multer = multer));
}

/**
Expand Down Expand Up @@ -113,7 +116,7 @@ export class PlatformRouter<Router = TsED.Router> {
}

multer(options: PlatformMulterSettings): PlatformMulter {
const m = require("multer")(options);
const m = this.#multer(options);

const makePromise = (multer: any, name: string) => {
// istanbul ignore next
Expand Down
Loading

0 comments on commit babd289

Please sign in to comment.