Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

Commit

Permalink
chore: format markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 21, 2020
1 parent 865da59 commit d9bee1f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 102 deletions.
10 changes: 7 additions & 3 deletions .github/COMMIT_CONVENTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
Using conventional commit messages, we can automate the process of generating the CHANGELOG file. All commits messages will automatically be validated against the following regex.

``` js
/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types|build|improvement)((.+))?: .{1,50}/
```js
;/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types|build|improvement)((.+))?: .{1,50}/
```
## Commit Message Format
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
> The **scope** is optional
Expand All @@ -26,6 +27,7 @@ Prefix makes it easier to append a path to a group of routes
5. The optional **footer** can be added after the body, followed by a blank line.

## Types

Only one type can be used at a time and only following types are allowed.

- feat
Expand All @@ -44,12 +46,15 @@ Only one type can be used at a time and only following types are allowed.
If a type is `feat`, `fix` or `perf`, then the commit will appear in the CHANGELOG.md file. However if there is any BREAKING CHANGE, the commit will always appear in the changelog.

### Revert

If the commit reverts a previous commit, it should begin with `revert:`, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>`., where the hash is the SHA of the commit being reverted.

## Scope

The scope could be anything specifying place of the commit change. For example: `router`, `view`, `querybuilder`, `database`, `model` and so on.

## Subject

The subject contains succinct description of the change:

- use the imperative, present tense: "change" not "changed" nor "changes".
Expand All @@ -67,4 +72,3 @@ The footer should contain any information about **Breaking Changes** and is also
reference GitHub issues that this commit **Closes**.

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ We do our best to reply to all the issues on time. If you will follow the given
- Ensure the issue isn't already reported.
- Ensure you are reporting the bug in the correct repo.

*Delete the above section and the instructions in the sections below before submitting*
_Delete the above section and the instructions in the sections below before submitting_

## Description

If this is a feature request, explain why it should be added. Specific use-cases are best.

For bug reports, please provide as much *relevant* info as possible.
For bug reports, please provide as much _relevant_ info as possible.

## Package version

<!-- YOUR ANSWER -->

## Error Message & Stack Trace
Expand Down
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
build
README.md
docs
*.md
config.json
.eslintrc.json
package.json
Expand Down
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"quoteProps": "consistent",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 100
"printWidth": 100,
"overrides": [
{
"files": "*.md",
"options": {
"useTabs": false
}
}
]
}
172 changes: 79 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
</div>

# Manager Pattern

> Implementation of the Manager pattern used by AdonisJS
[![circleci-image]][circleci-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![audit-report-image]][audit-report-url]
Expand Down Expand Up @@ -31,7 +32,6 @@ Manager pattern is a way to ease the construction of objects of similar nature.

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## Scanerio

Let's imagine we are creating a mailing library and it supports multiple drivers like: **SMTP**, **Mailgun**, **PostMark** and so on. Also, we want the users of our library to use each driver for multiple times using different configuration. For example:
Expand All @@ -57,7 +57,6 @@ The above approach works perfect, but has few drawbacks
- If the construction of the drivers needs more than one constructor arguments, then it will become cumbersome for the consumer to satisfy all those dependencies.
- They will have to manually manage the lifecycle of the constructed objects. Ie `promotional` and `transactional` in this case.


## Using a Manager Class

What we really need is a Manager to manage and construct these objects in the most ergonomic way.
Expand All @@ -68,17 +67,17 @@ First step is to move the mappings to a configuration file. The config mimics th

```ts
const mailersConfig = {
default: 'transactional',
list: {
transactional: {
driver: 'mailgun'
},

promotional: {
driver: 'mailgun'
},
}
default: 'transactional',

list: {
transactional: {
driver: 'mailgun',
},

promotional: {
driver: 'mailgun',
},
},
}
```

Expand All @@ -88,11 +87,11 @@ const mailersConfig = {
import { Manager } from '@poppinss/manager'

class MailManager implements Manager {
protected singleton = true
protected singleton = true

constructor (private config) {
super({})
}
constructor(private config) {
super({})
}
}
```

Expand All @@ -104,25 +103,25 @@ The **Base Manager** class will do all the heavy lifting for you. However, you w
import { Manager } from '@poppinss/manager'

class MailManager implements Manager {
protected singleton = true
protected singleton = true

protected getDefaultMappingName() {
return this.config.default
}
protected getDefaultMappingName() {
return this.config.default
}

protected getMappingConfig(mappingName: string) {
return this.config.list[mappingName]
}
protected getMappingConfig(mappingName: string) {
return this.config.list[mappingName]
}

protected getMappingDriver(mappingName: string) {
return this.config.list[mappingName].driver
}
protected getMappingDriver(mappingName: string) {
return this.config.list[mappingName].driver
}

constructor (private config) {
super({})
}
constructor(private config) {
super({})
}
}
```
```

### Step 4: Move drivers construction into the manager class

Expand All @@ -132,15 +131,15 @@ The final step is to write the code for constructing drivers. The **Base Manager
import { Manager } from '@poppinss/manager'

class MailManager implements Manager {
// ... The existing code
public createMailgun (mappingName, config) {
return new Mailgun(config)
}

public createSmtp (mappingName, config) {
return new Smtp(config)
}
// ... The existing code

public createMailgun(mappingName, config) {
return new Mailgun(config)
}

public createSmtp(mappingName, config) {
return new Smtp(config)
}
}
```

Expand All @@ -150,17 +149,17 @@ Once done, the consumer of the Mailer class just needs to define the mappings co

```ts
const mailersConfig = {
default: 'transactional',
list: {
transactional: {
driver: 'mailgun'
},

promotional: {
driver: 'mailgun'
},
}
default: 'transactional',

list: {
transactional: {
driver: 'mailgun',
},

promotional: {
driver: 'mailgun',
},
},
}

const mailer = new MailManager(mailersConfig)
Expand All @@ -171,7 +170,7 @@ mailer.use('promotional').send()

- The lifecycle of the mailers is now encapsulated within the manager class. The consumer can call `mailer.use()` as many times as they want, without worrying about creating too many un-used objects.
- They just need to define the mailers config once and get rid of any custom code required to construct individual drivers.

## Extending from outside-in

The Base Manager class comes with first class support for adding custom drivers from outside-in using the `extend` method.
Expand All @@ -180,7 +179,7 @@ The Base Manager class comes with first class support for adding custom drivers
const mailer = new MailManager(mailersConfig)

mailer.extend('postmark', (manager, mappingName, config) => {
return new PostMark(config)
return new PostMark(config)
})
```

Expand All @@ -201,21 +200,17 @@ Following is a dummy interface, we expect all drivers to adhere too

```ts
interface DriverContract {
send (): Promise<void>
send(): Promise<void>
}
```


### Passing interface to Manager

```ts
import { Manager } from '@poppinss/manager'
import { DriverContract } from './Contracts'

class MailManager implements Manager<
DriverContract
> {
}
class MailManager implements Manager<DriverContract> {}
```

## Mappings Type
Expand All @@ -226,31 +221,31 @@ In order to improve intellisense for the `use` method. You will have to define a

```ts
type MailerMappings = {
transactional: Mailgun,
promotional: Mailgun
transactional: Mailgun
promotional: Mailgun
}

type MailerConfig = {
default: keyof MailerMappings,
list: {
[K in keyof MailerMappings]: any
}
default: keyof MailerMappings
list: {
[K in keyof MailerMappings]: any
}
}

const mailerConfig: MailerConfig = {
default: 'transactional',

list: {
transactional: {
driver: 'mailgun',
// ...
},

promotional: {
driver: 'mailgun',
// ...
},
}
default: 'transactional',

list: {
transactional: {
driver: 'mailgun',
// ...
},

promotional: {
driver: 'mailgun',
// ...
},
},
}
```

Expand All @@ -259,12 +254,7 @@ Finally, pass the `MailerMappings` to the Base Manager class
```ts
import { DriverContract, MailerMappings } from './Contracts'

class MailManager implements Manager<
DriverContract,
DriverContract,
MailerMappings
> {
}
class MailManager implements Manager<DriverContract, DriverContract, MailerMappings> {}
```

Once mailer mappings have been defined, the `use` method will have proper return types.
Expand All @@ -278,16 +268,12 @@ Once mailer mappings have been defined, the `use` method will have proper return
![](assets/return-type.png)

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/manager/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/manager "circleci"

[circleci-url]: https://circleci.com/gh/poppinss/manager 'circleci'
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"

[typescript-url]: "typescript"
[npm-image]: https://img.shields.io/npm/v/@poppinss/manager.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@poppinss/manager "npm"

[npm-url]: https://npmjs.org/package/@poppinss/manager 'npm'
[license-image]: https://img.shields.io/npm/l/@poppinss/manager?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"

[license-url]: LICENSE.md 'license'
[audit-report-image]: https://img.shields.io/badge/-Audit%20Report-blueviolet?style=for-the-badge
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/poppinss/manager/blob/develop/npm-audit.html "audit-report"
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/poppinss/manager/blob/develop/npm-audit.html 'audit-report'
2 changes: 1 addition & 1 deletion npm-audit.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5 class="card-title">
<div class="card">
<div class="card-body">
<h5 class="card-title">
September 21st 2020, 7:08:48 am
September 21st 2020, 7:09:37 am
</h5>
<p class="card-text">Last updated</p>
</div>
Expand Down

0 comments on commit d9bee1f

Please sign in to comment.