@poppinss/manager
Advanced tools
Comparing version 3.0.5 to 3.0.6
{ | ||
"name": "@poppinss/manager", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"description": "The builder (Manager) pattern implementation", | ||
@@ -35,3 +35,3 @@ "main": "build/index.js", | ||
"@adonisjs/require-ts": "^1.0.0", | ||
"@types/node": "^14.6.2", | ||
"@types/node": "^14.11.1", | ||
"commitizen": "^4.2.1", | ||
@@ -41,3 +41,3 @@ "cz-conventional-changelog": "^3.3.0", | ||
"doctoc": "^1.4.0", | ||
"eslint": "^7.7.0", | ||
"eslint": "^7.9.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
@@ -47,9 +47,9 @@ "eslint-plugin-adonis": "^1.0.15", | ||
"github-label-sync": "^2.0.0", | ||
"husky": "^4.2.5", | ||
"husky": "^4.3.0", | ||
"japa": "^3.1.1", | ||
"mrm": "^2.3.5", | ||
"mrm": "^2.5.0", | ||
"np": "^6.5.0", | ||
"npm-audit-html": "^1.4.3", | ||
"prettier": "^2.1.1", | ||
"typescript": "^4.0.2" | ||
"prettier": "^2.1.2", | ||
"typescript": "^4.0.3" | ||
}, | ||
@@ -56,0 +56,0 @@ "nyc": { |
162
README.md
@@ -6,2 +6,3 @@ <div align="center"> | ||
# Manager Pattern | ||
> Implementation of the Manager pattern used by AdonisJS | ||
@@ -35,3 +36,2 @@ | ||
## Scanerio | ||
@@ -62,3 +62,2 @@ | ||
## Using a Manager Class | ||
@@ -74,13 +73,13 @@ | ||
const mailersConfig = { | ||
default: 'transactional', | ||
list: { | ||
transactional: { | ||
driver: 'mailgun' | ||
}, | ||
default: 'transactional', | ||
promotional: { | ||
driver: 'mailgun' | ||
}, | ||
} | ||
list: { | ||
transactional: { | ||
driver: 'mailgun', | ||
}, | ||
promotional: { | ||
driver: 'mailgun', | ||
}, | ||
}, | ||
} | ||
@@ -95,7 +94,7 @@ ``` | ||
class MailManager implements Manager { | ||
protected singleton = true | ||
protected singleton = true | ||
constructor (private config) { | ||
super({}) | ||
} | ||
constructor(private config) { | ||
super({}) | ||
} | ||
} | ||
@@ -112,21 +111,21 @@ ``` | ||
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({}) | ||
} | ||
} | ||
``` | ||
``` | ||
@@ -141,11 +140,11 @@ ### Step 4: Move drivers construction into the manager class | ||
class MailManager implements Manager { | ||
// ... The existing code | ||
public createMailgun (mappingName, config) { | ||
return new Mailgun(config) | ||
} | ||
// ... The existing code | ||
public createSmtp (mappingName, config) { | ||
return new Smtp(config) | ||
} | ||
public createMailgun(mappingName, config) { | ||
return new Mailgun(config) | ||
} | ||
public createSmtp(mappingName, config) { | ||
return new Smtp(config) | ||
} | ||
} | ||
@@ -160,13 +159,13 @@ ``` | ||
const mailersConfig = { | ||
default: 'transactional', | ||
list: { | ||
transactional: { | ||
driver: 'mailgun' | ||
}, | ||
default: 'transactional', | ||
promotional: { | ||
driver: 'mailgun' | ||
}, | ||
} | ||
list: { | ||
transactional: { | ||
driver: 'mailgun', | ||
}, | ||
promotional: { | ||
driver: 'mailgun', | ||
}, | ||
}, | ||
} | ||
@@ -182,3 +181,3 @@ | ||
- 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 | ||
@@ -192,3 +191,3 @@ | ||
mailer.extend('postmark', (manager, mappingName, config) => { | ||
return new PostMark(config) | ||
return new PostMark(config) | ||
}) | ||
@@ -214,7 +213,6 @@ ``` | ||
interface DriverContract { | ||
send (): Promise<void> | ||
send(): Promise<void> | ||
} | ||
``` | ||
### Passing interface to Manager | ||
@@ -226,6 +224,3 @@ | ||
class MailManager implements Manager< | ||
DriverContract | ||
> { | ||
} | ||
class MailManager implements Manager<DriverContract> {} | ||
``` | ||
@@ -241,27 +236,27 @@ | ||
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', | ||
default: 'transactional', | ||
list: { | ||
transactional: { | ||
driver: 'mailgun', | ||
// ... | ||
}, | ||
list: { | ||
transactional: { | ||
driver: 'mailgun', | ||
// ... | ||
}, | ||
promotional: { | ||
driver: 'mailgun', | ||
// ... | ||
}, | ||
} | ||
promotional: { | ||
driver: 'mailgun', | ||
// ... | ||
}, | ||
}, | ||
} | ||
@@ -275,8 +270,3 @@ ``` | ||
class MailManager implements Manager< | ||
DriverContract, | ||
DriverContract, | ||
MailerMappings | ||
> { | ||
} | ||
class MailManager implements Manager<DriverContract, DriverContract, MailerMappings> {} | ||
``` | ||
@@ -295,14 +285,10 @@ | ||
[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' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22787
280