This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: drop $ prefix from cacheMappings property
- Loading branch information
1 parent
aada504
commit fd4cc96
Showing
4 changed files
with
55 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,25 @@ | ||
import { ExtractImplementations, ExtractConfig } from '../src/Contracts' | ||
import { ManagerContract } from '../src/Contracts' | ||
|
||
import { Manager } from '../src/Manager' | ||
|
||
interface MailDriverContract { | ||
send(): void | ||
} | ||
|
||
type SmtpConfig = { | ||
driver: 'smtp' | ||
host: string | ||
user: string | ||
password: string | ||
port?: number | ||
} | ||
|
||
type MailchimpConfig = { | ||
driver: 'mailchimp' | ||
apiKey: string | ||
interface DriverContract { | ||
run(): string | ||
} | ||
|
||
type MappingsList = { | ||
transactional: { | ||
config: SmtpConfig | ||
implementation: SmtpDriver | ||
} | ||
promotional: { | ||
config: MailchimpConfig | ||
implementation: MailchimpDriver | ||
} | ||
} | ||
|
||
class SmtpDriver { | ||
constructor(public config: any) {} | ||
public send() {} | ||
} | ||
|
||
class MailchimpDriver { | ||
constructor(public config: any) {} | ||
public send() {} | ||
} | ||
|
||
class Mailer extends Manager<MailDriverContract, ExtractImplementations<MappingsList>> { | ||
constructor(container: any, private _config: any) { | ||
super(container) | ||
} | ||
|
||
protected $cacheMappings = true | ||
|
||
protected getDefaultMappingName(): string { | ||
return this._config.mailer | ||
} | ||
|
||
protected getMappingConfig(name: string): any { | ||
return this._config.mailers[name] | ||
} | ||
|
||
protected getMappingDriver(name: string): any { | ||
return this._config.mailers[name].driver | ||
} | ||
|
||
protected createSmtp(_name: string, config: any) { | ||
return new SmtpDriver(config) | ||
} | ||
|
||
protected createMailchimp(_name: string, config: any) { | ||
return new MailchimpDriver(config) | ||
} | ||
interface Smtp extends DriverContract { | ||
send(): void | ||
} | ||
|
||
type Config<Mailer extends keyof MappingsList> = { | ||
mailer: Mailer | ||
mailers: ExtractConfig<MappingsList> | ||
interface Mailgun extends DriverContract { | ||
verifyAndSend(): void | ||
} | ||
|
||
const config: Config<'transactional'> = { | ||
mailer: 'transactional', | ||
mailers: { | ||
transactional: { | ||
driver: 'smtp', | ||
host: '', | ||
user: '', | ||
password: '', | ||
}, | ||
|
||
promotional: { | ||
driver: 'mailchimp', | ||
apiKey: '', | ||
}, | ||
}, | ||
type Mappings = { | ||
smtp: Smtp | ||
mailgun: Mailgun | ||
} | ||
|
||
const mailer = new Mailer({}, config) | ||
class Postmark { | ||
constructor(public _config: any) {} | ||
public send() {} | ||
} | ||
type Mailer = ManagerContract<DriverContract, DriverContract, Mappings> | ||
|
||
mailer.extend('postmark', (_container, _name, driverConfig) => { | ||
return new Postmark(driverConfig) | ||
}) | ||
const a = {} as Mailer | ||
a.use() | ||
|
||
// mailer.use('') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters