Skip to content

Commit

Permalink
ci: run prettier to lint all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Mar 11, 2024
1 parent 765c5b9 commit 4168e2b
Show file tree
Hide file tree
Showing 48 changed files with 8,344 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
"no-empty": "off",
"prefer-const": "off",
"no-fallthrough": "off",
"quotes": "double"
quotes: "double"
},
overrides: [
{
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/configuration/express.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Express.js

## express.bodyParser <Badge text="6.111.0+"/>

This option let you configure the default bodyParser used by Ts.ED to parse the body request:
Expand Down Expand Up @@ -28,4 +29,4 @@ express [documentation](http://expressjs.com/en/api.html#express.router).

Object to mount all directories under an endpoint.

[//]: # (<<< @/../packages/platform/platform-express/src/interfaces/PlatformExpressStaticsOptions.ts)
[//]: # "<<< @/../packages/platform/platform-express/src/interfaces/PlatformExpressStaticsOptions.ts"
30 changes: 15 additions & 15 deletions docs/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Ts.ED supports [ts-node](https://github.com/TypeStrong/ts-node). Ts extension wi
ts-node isn't the runtime.
:::



## Options

### rootDir
Expand Down Expand Up @@ -96,19 +94,19 @@ Port number for the [HTTPs.Server](https://nodejs.org/api/https.html#https_class
### httpsOptions

- type: [Https.ServerOptions](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
- `key` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)
| &lt;Object[]&gt;: The private key of the server in PEM format. To support multiple keys using different
algorithms, an array can be provided either as a plain array of key strings or an array of objects in the
format `{pem: key, passphrase: passphrase}`. This option is required for ciphers making use of private keys.
- `passphrase` &lt;string&gt; A string containing the passphrase for the private key or pfx.
- `cert` &lt;string&gt; | &lt;string[]&gt;
| [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)
| [&lt;Buffer[]&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings,
or array of Buffers containing the certificate key of the server in PEM format. (Required)
- `ca` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)
| [&lt;Buffer[]&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings,
or array of Buffers of trusted certificates in PEM format. If this is omitted, several well known "root" CAs (like
VeriSign) will be used. These are used to authorize connections.
- `key` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)
| &lt;Object[]&gt;: The private key of the server in PEM format. To support multiple keys using different
algorithms, an array can be provided either as a plain array of key strings or an array of objects in the
format `{pem: key, passphrase: passphrase}`. This option is required for ciphers making use of private keys.
- `passphrase` &lt;string&gt; A string containing the passphrase for the private key or pfx.
- `cert` &lt;string&gt; | &lt;string[]&gt;
| [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)
| [&lt;Buffer[]&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings,
or array of Buffers containing the certificate key of the server in PEM format. (Required)
- `ca` &lt;string&gt; | &lt;string[]&gt; | [&lt;Buffer&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)
| [&lt;Buffer[]&gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings,
or array of Buffers of trusted certificates in PEM format. If this is omitted, several well known "root" CAs (like
VeriSign) will be used. These are used to authorize connections.

See the [HTTPs project example](https://github.com/tsedio/example-ts-express-decorator/tree/2.0.0/example-https)

Expand Down Expand Up @@ -363,10 +361,12 @@ In v7 this option will be set to true by default.
## Platform Options

See specific platform options for:

- [Express.js](/docs/configuration/express)
- [Koa.js](/docs/configuration/koa)

## HTTP & HTTPs server

### Change address

It's possible to change the HTTP and HTTPS server address as follows:
Expand Down
1 change: 1 addition & 0 deletions docs/docs/configuration/koa.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Koa.js

## koa.bodyParser <Badge text="6.111.0+"/>

This option let you configure the default bodyParser used by Ts.ED to parse the body request:
Expand Down
11 changes: 4 additions & 7 deletions docs/docs/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ will map every `GET /calendars` request to this method.

Ts.ED provides a decorator for each HTTP verb which can be used to handle a request:

<ApiList query="tags:decorator AND tags:httpMethod" />
<ApiList query="tags.includes('decorator') && tags.includes('httpMethod')" />

Other decorators are provided to describe your route with OpenSpec, adding middlewares, adding some constraints or
adding headers:
Expand Down Expand Up @@ -117,7 +117,7 @@ In order to avoid such side effects, simply move `findAll()` method above `findO
Getting parameters from Request can be done by using the following decorators:

| Decorator | Validation | Json Mapper | Configurable |
|----------------|------------|-------------|--------------|
| -------------- | ---------- | ----------- | ------------ |
| HeaderParams | no | no | yes |
| BodyParams | yes | yes | yes |
| RawBodyParams | no | no | no |
Expand Down Expand Up @@ -315,6 +315,7 @@ pnpm add @tsed/ajv
```sh [bun]
bun add @tsed/ajv
```

:::

**Supported decorators:**
Expand Down Expand Up @@ -609,7 +610,7 @@ One controller can be added to multiple controllers, so you can easily reuse the
This example will produce these following routes:

| Verb | Route | Method |
|------|--------------------------|----------------------|
| ---- | ------------------------ | -------------------- |
| GET | `/rest` | `RestCtrl.get()` |
| GET | `/rest/calendars` | `CalendarCtrl.get()` |
| GET | `/rest/calendars/events` | `EventCtrl.get()` |
Expand All @@ -627,7 +628,3 @@ To do that just declare a parent controller without the @@Controller@@ decorator
Then, on your child controller:

<<< @/docs/snippets/controllers/inheritance-child-controller.ts

## Decorators

<ApiList query="tags: decorator AND operation OR controller"/>
1 change: 1 addition & 0 deletions docs/docs/koa.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Koa.js

## koa.bodyParser <Badge text="6.111.0+"/>

This option let you configure the default bodyParser used by Ts.ED to parse the body request:
Expand Down
24 changes: 12 additions & 12 deletions docs/docs/pipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Officially, Ts.ED has two way to declare a @@JsonShema@@ validation:
We'll take the model declaration to explain the Validation pipe use case. Let's focus on the `PersonModel`:

```typescript
import { MinLength, Required } from "@tsed/schema";
import {MinLength, Required} from "@tsed/schema";

class PersonModel {
@MinLength(3)
Expand Down Expand Up @@ -186,7 +186,7 @@ This is useful when you have to get data from **database** based on an input dat
Given this `PersonModel`:

```typescript
import { MinLength, Required, Property } from "@tsed/common";
import {MinLength, Required, Property} from "@tsed/common";

class PersonModel {
@Property()
Expand Down Expand Up @@ -225,9 +225,9 @@ To avoid future mistakes, it could be a good idea to summarize these two decorat
Now, we can use our custom decorator on parameter:

```typescript
import { Controller, Put, RawPathParams, UsePipe } from "@tsed/common";
import { PersonModel } from "../models/PersonModel";
import { PersonPipe } from "../services/PersonPipe";
import {Controller, Put, RawPathParams, UsePipe} from "@tsed/common";
import {PersonModel} from "../models/PersonModel";
import {PersonPipe} from "../services/PersonPipe";

@Controller("/persons")
export class PersonsController {
Expand Down Expand Up @@ -255,17 +255,17 @@ Now, we can retrieve the options by using the `metadata.store`:
And finally, we can use our new decorator on a parameter:

```typescript
import { Controller } from "@tsed/di";
import { UsePipe } from "@tsed/common";
import { Put } from "@tsed/schema";
import { RawPathParams, UsePipe } from "@tsed/platform-params";
import { PersonModel } from "../models/PersonModel";
import { PersonPipe } from "../services/PersonPipe";
import {Controller} from "@tsed/di";
import {UsePipe} from "@tsed/common";
import {Put} from "@tsed/schema";
import {RawPathParams, UsePipe} from "@tsed/platform-params";
import {PersonModel} from "../models/PersonModel";
import {PersonPipe} from "../services/PersonPipe";

@Controller("/persons")
export class PersonsController {
@Put("/:id")
async update(@UsePersonParam("id", { optional: true }) person: PersonModel) {
async update(@UsePersonParam("id", {optional: true}) person: PersonModel) {
// do something

return person;
Expand Down
16 changes: 8 additions & 8 deletions docs/docs/providers-lazy-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ To load a provider on-demand, Ts.ED provide decorators @@LazyInject@@ and @@Opti
with a @@PlatformExceptions@@:

```typescript
import { Injectable, LazyInject } from "@tsed/di";
import type { PlatformExceptions } from "@tsed/platform-exceptions";
import {Injectable, LazyInject} from "@tsed/di";
import type {PlatformExceptions} from "@tsed/platform-exceptions";

@Injectable()
class MyInjectable {
Expand Down Expand Up @@ -56,11 +56,11 @@ That means, each consecutive call will be very fast and will return a cached ins
Create you own lazy injectable doesn't require special things, just declare a module or an injectable service is enough:

```typescript
import { Module } from "@tsed/di";
import {Module} from "@tsed/di";

@Module({
// works also with @Injectable
imports: [], // Use the imports field if you have services to build
imports: [] // Use the imports field if you have services to build
})
export class MyModule {
$onInit() {
Expand All @@ -72,8 +72,8 @@ export class MyModule {
Then use it:

```typescript
import { Injectable, LazyInject } from "@tsed/di";
import type { MyModule } from "../MyModule.ts";
import {Injectable, LazyInject} from "@tsed/di";
import type {MyModule} from "../MyModule.ts";

@Injectable()
class MyInjectable {
Expand Down Expand Up @@ -108,15 +108,15 @@ If you use Webpack, make sure to update your `tsconfig.json` file - setting `com
Ts.ED provide also a way to lazy load a provider programmatically. You just need to inject the @@InjectorService@@ in service:

```typescript
import { Injectable, Inject, InjectorService } from "@tsed/di";
import {Injectable, Inject, InjectorService} from "@tsed/di";

@Injectable()
class MyService {
@Inject()
protected injector: InjectorService;

async load() {
const { MyModule } = await import("../lazy/my-module.ts");
const {MyModule} = await import("../lazy/my-module.ts");
const myModule = await this.injector.lazyInvoke(MyModule);

myModule.doSomething();
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Ts.ED is built around the **dependency injection** pattern. TypeScript emits typ
be exploited by the @@InjectorService@@ to resolve dependencies automatically.

```typescript
import { Injectable } from "@tsed/di";
import {Injectable} from "@tsed/di";

@Injectable()
class MyInjectable {
Expand All @@ -73,7 +73,7 @@ class MyInjectable {
It's also possible to inject a service on a property by using @@Inject@@ decorator:

```typescript
import { Injectable, Inject } from "@tsed/di";
import {Injectable, Inject} from "@tsed/di";

@Injectable()
class MyInjectable {
Expand Down Expand Up @@ -154,12 +154,12 @@ interface Bar {

const Bar: unique symbol = Symbol("Bar");

@Injectable({ type: Bar })
@Injectable({type: Bar})
class Foo implements Bar {
private readonly type = "foo";
}

@Injectable({ type: Bar })
@Injectable({type: Bar})
class Baz implements Bar {
private readonly type = "baz";
}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/snippets/controllers/async-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Calendar {
@Controller("/calendars")
export class CalendarCtrl {
@Get("/:id")
async get(@PathParams("id") id: string): Promise<Calendar> {
get(@PathParams("id") id: string): Calendar {
return {
id,
name: "test"
Expand Down
5 changes: 1 addition & 4 deletions docs/docs/snippets/controllers/axios-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export class ProxyCtrl {
responseType: "stream"
});

return $ctx.response
.setHeaders(response.headers)
.status(response.status)
.body(response.data);
return $ctx.response.setHeaders(response.headers).status(response.status).body(response.data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export abstract class BaseCtrl {
constructor(private someService: SomeService) {}

@Get("/list")
async list(@QueryParams("search") search: any) {
list(@QueryParams("search") search: any) {
return this.someService.list(search);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class CalendarCtrl {
@Get("/:id")
@Get("/alias/:id")
@Post("/:id/complexAlias")
async get(): Promise<any> {
get() {
return "Return something";
}
}
2 changes: 1 addition & 1 deletion docs/docs/snippets/controllers/params-advanced-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {BodyParams} from "@tsed/platform-params";

class MyController {
@Post()
async create(@BodyParams({expression: "user", useMapper: false}) body: T): Promise<T> {
create(@BodyParams({expression: "user", useMapper: false}) body: T): T {
console.log("payload", body);

return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ProductsCtrl {
@Returns(200, Document).Of(Product).Description("A product")
@Returns(404, NotFound).Description("Product not found")
@Summary("Return a product from the given Id")
async geProduct(@PathParams("id") id: string): Promise<Document<Product>> {
geProduct(@PathParams("id") id: string): Document<Product> {
if (id === "AGAC") {
const product = new Product({
id: "AGAC",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/snippets/pipes/async-transformer-pipe-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {PersonPipe} from "../services/PersonPipe";
@Controller("/persons")
export class PersonsController {
@Put("/:id")
async update(
update(
@RawPathParams("id")
@UsePipe(PersonPipe)
person: PersonModel
Expand All @@ -16,4 +16,4 @@ export class PersonsController {

return person;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export class PersonPipe implements PipeMethods<string, Promise<PersonModel>> {

return person;
}
}
}
2 changes: 1 addition & 1 deletion docs/docs/snippets/pipes/async-transformer-pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export class PersonPipe implements PipeMethods<string, Promise<PersonModel>> {

return person;
}
}
}
2 changes: 1 addition & 1 deletion docs/docs/snippets/pipes/body-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export function BodyParams(...args: any[]): ParameterDecorator {
useMapper,
useValidation
});
}
}
2 changes: 1 addition & 1 deletion docs/docs/snippets/pipes/controller-model-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export class PersonsController {
save(@BodyParams() person: PersonModel) {
return person;
}
}
}
2 changes: 1 addition & 1 deletion docs/docs/snippets/pipes/pipes-decorator-with-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export function UsePersonParam(expression: string, options: IUsePersonParamOptio
RawPathParams(expression),
UsePipe(PersonPipe, options) // UsePipe accept second parameter to store your options
);
}
}
2 changes: 1 addition & 1 deletion docs/docs/snippets/pipes/pipes-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import {PersonPipe} from "../services/PersonPipe";

export function UsePersonParam(expression: string): ParameterDecorator {
return useDecorators(RawPathParams(expression), UsePipe(PersonPipe));
}
}
Loading

0 comments on commit 4168e2b

Please sign in to comment.