obsidian-micropub/src/MicroPluginContainer.ts

47 lines
1.4 KiB
TypeScript

import MicroPlugin from "@base/MicroPlugin"
import { NetworkClient, NetworkClientInterface } from "@networking/NetworkClient"
import { StoredSettings } from "@stores/StoredSettings"
import { NetworkRequestFactory, NetworkRequestFactoryInterface } from "@networking/NetworkRequestFactory"
export interface MicroPluginContainerInterface {
// The stored plugin settings.
settings: StoredSettings
// The Micro.publish plugin.
plugin: MicroPlugin
// The network client used to perform network request.
networkClient: NetworkClientInterface
// The network request factory, used to build the
// requests which will be executed by the network client.
networkRequestFactory: NetworkRequestFactoryInterface
}
export class MicroPluginContainer implements MicroPluginContainerInterface {
// Properties
readonly settings: StoredSettings
readonly plugin: MicroPlugin
readonly networkClient: NetworkClientInterface
readonly networkRequestFactory: NetworkRequestFactoryInterface
// Life cycle
constructor(
settings: StoredSettings,
plugin: MicroPlugin
) {
this.settings = settings
this.plugin = plugin
this.networkRequestFactory = new NetworkRequestFactory(
() => this.settings.micropubEndpoint
)
this.networkClient = new NetworkClient(
() => this.settings.appToken
)
}
}